├── README.md ├── LICENSE ├── doc └── molder-operations.txt └── autoload └── molder └── extension └── operations.vim /README.md: -------------------------------------------------------------------------------- 1 | # vim-molder-operations 2 | 3 | Operation plugin for [vim-molder](https://github.com/mattn/vim-molder/) 4 | 5 | ## Installation 6 | 7 | For [vim-plug](https://github.com/junegunn/vim-plug) plugin manager: 8 | 9 | ``` 10 | Plug 'mattn/vim-molder' 11 | Plug 'mattn/vim-molder-operations' 12 | ``` 13 | 14 | ## License 15 | 16 | MIT 17 | 18 | ## Author 19 | 20 | Yasuhiro Matsumoto 21 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2020 Yasuhiro Matsumoto 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /doc/molder-operations.txt: -------------------------------------------------------------------------------- 1 | *molder-operations.txt* molder-operations: Operation plugin for molder 2 | 3 | ============================================================================== 4 | INSTALLATION *molder-operations-installation* 5 | 6 | Manual installation: 7 | Copy the files to your .vim directory (_vimfiles on Windows). 8 | 9 | Pathogen: > 10 | cd ~/.vim/bundle && \ 11 | git clone git://github.com/mattn/vim-molder-operations.git 12 | 13 | Vundle: add below to .vimrc 14 | > 15 | Plugin 'mattn/vim-molder-operations' 16 | < 17 | Run :PluginInstall 18 | 19 | NeoBundle: add below to .vimrc 20 | > 21 | NeoBundle 'mattn/vim-molder-operations' 22 | < 23 | Run :NeoBundleInstall 24 | 25 | vim-plug: add below to .vimrc 26 | > 27 | Plug 'mattn/vim-molder-operations' to .vimrc 28 | < 29 | Run :PlugInstall 30 | 31 | ============================================================================== 32 | KEYMAPPINGS *molder-operations-keymappings* 33 | 34 | * "n": create directory. (molder-operations-newdir) 35 | * "d": delete. (molder-operations-delete) 36 | * "r": rename. (molder-operations-rename) 37 | * "!": edit command line for making command. 38 | (molder-operations-command) 39 | * "s": run shell. (molder-operations-shell) 40 | 41 | ============================================================================== 42 | vim:tw=78:ts=8:ft=help:norl:noet:fen:fdl=0: 43 | -------------------------------------------------------------------------------- /autoload/molder/extension/operations.vim: -------------------------------------------------------------------------------- 1 | function! molder#extension#operations#init() abort 2 | nnoremap (molder-operations-newdir) :call molder#extension#operations#newdir() 3 | nnoremap (molder-operations-delete) :call molder#extension#operations#delete() 4 | nnoremap (molder-operations-rename) :call molder#extension#operations#rename() 5 | nnoremap (molder-operations-command) :call molder#extension#operations#command() 6 | nnoremap (molder-operations-shell) :call molder#extension#operations#shell() 7 | 8 | if !hasmapto('(molder-operations-newdir)') 9 | nmap n (molder-operations-newdir) 10 | endif 11 | if !hasmapto('(molder-operations-delete)') 12 | nmap d (molder-operations-delete) 13 | endif 14 | if !hasmapto('(molder-operations-rename)') 15 | nmap r (molder-operations-rename) 16 | endif 17 | if !hasmapto('(molder-operations-command)') 18 | nmap ! (molder-operations-command) 19 | endif 20 | if !hasmapto('(molder-operations-shell)') 21 | nmap s (molder-operations-shell) 22 | endif 23 | endfunction 24 | 25 | function! molder#extension#operations#newdir() abort 26 | let l:name = input('Create directory: ') 27 | if empty(l:name) 28 | return 29 | endif 30 | 31 | if l:name == '.' || l:name == '..' || l:name =~# '[/\\]' 32 | call molder#error('Invalid directory name: ' .. l:name) 33 | return 34 | endif 35 | try 36 | if mkdir(molder#curdir() .. l:name) ==# 0 37 | throw 'failed' 38 | endif 39 | catch 40 | call molder#error('Create directory failed') 41 | return 42 | endtry 43 | call molder#reload() 44 | endfunction 45 | 46 | function! molder#extension#operations#delete() abort 47 | let l:name = molder#current() 48 | if confirm('Delete?: ' .. l:name, "&Yes\n&No\n&Force", 2) =~# '^[02]$' 49 | return 50 | endif 51 | let l:path = molder#curdir() .. l:name 52 | if isdirectory(l:path) 53 | try 54 | if delete(l:path, 'rf') == -1 55 | throw 'failed' 56 | endif 57 | catch 58 | call molder#error('Delete directory failed') 59 | return 60 | endtry 61 | else 62 | try 63 | if delete(l:path) == -1 64 | throw 'failed' 65 | endif 66 | catch 67 | call molder#error('Delete file failed') 68 | return 69 | endtry 70 | endif 71 | call molder#reload() 72 | endfunction 73 | 74 | function! molder#extension#operations#rename() abort 75 | let l:old = substitute(molder#current(), '/$', '', '') 76 | let l:new = input('Rename: ', l:old) 77 | if empty(l:new) || l:new ==# l:old 78 | return 79 | endif 80 | 81 | if l:new == '.' || l:new == '..' || l:new =~# '[/\\]' 82 | call molder#error('Invalid name: ' .. l:new) 83 | return 84 | endif 85 | try 86 | if rename(molder#curdir() .. l:old, molder#curdir() .. l:new) !=# 0 87 | throw 'failed' 88 | endif 89 | catch 90 | call molder#error('Rename failed') 91 | return 92 | endtry 93 | call molder#reload() 94 | endfunction 95 | 96 | function! molder#extension#operations#command() abort 97 | let l:path = molder#curdir() .. molder#current() 98 | call feedkeys(':! ' .. shellescape(l:path) .. "\\", 'n') 99 | endfunction 100 | 101 | function! molder#extension#operations#shell() abort 102 | call term_start(&shell, {'cwd': molder#curdir()}) 103 | endfunction 104 | 105 | --------------------------------------------------------------------------------