├── .travis.yml ├── README.md ├── appveyor.yml ├── autoload └── shellutils.vim ├── doc ├── shellutils.txt └── shellutils_old.gif ├── plugin └── shellutils.vim └── test ├── ls.vim ├── mkdir.vim ├── rm.vim └── touch.vim /.travis.yml: -------------------------------------------------------------------------------- 1 | language: generic 2 | 3 | env: 4 | - PPA=yes 5 | - PPA=no 6 | 7 | install: 8 | #- if [ x"$PPA" = "xyes" ] ; then sudo add-apt-repository ppa:pi-rho/dev -y; fi 9 | - sudo apt-get update -q 10 | - sudo apt-get install vim-gtk 11 | - git clone https://github.com/thinca/vim-themis 12 | 13 | script: 14 | - vim --version 15 | - vim-themis/bin/themis --reporter spec 16 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 |

4 | 5 |

6 | 7 |

8 | About 9 | | 10 | Description 11 | | 12 | Usage 13 | | 14 | Installation 15 | | 16 | License 17 |

18 | 19 |
20 | 21 | vim-shellutils 22 | === 23 | 24 | [![](https://img.shields.io/travis/b4b4r07/vim-shellutils.svg?style=flat-square)][travis] 25 | [![](https://img.shields.io/appveyor/ci/b4b4r07/vim-shellutils.svg?style=flat-square)][appveyor] 26 | [![](http://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)][license] 27 | 28 | `vim-shellutils` is a simple, UNIX Shell commands (e.g., `/bin/ls`) emulator written in Vim script. 29 | 30 | ***DEMO:*** 31 | 32 | ![vim-shellutils](https://raw.githubusercontent.com/b4b4r07/screenshots/master/vim-shellutils/demo.gif) 33 | 34 | ## Description 35 | 36 | `vim-shellutils` is a simple Vim plugin that provides UNIX shell-like commands such as `rm`, `ls`, and so on. The fact that written in Vim script independently of the external command or other tools will bring numerous benefits to your Vim life. 37 | 38 | For example, when you want to run the command from the command line, it is troublesome to have to exit Vim. Thanks to this plugin, you can run the shell command without quit Vim. With further say, this fact shows that does not depend on the platform you want to run. Thus, it means that Windows is OK, too. 39 | 40 | If only you had Vim and this plugin, you will be able to reproduce the shell command. 41 | 42 |

:arrow_up:

43 | 44 | ## Usage 45 | 46 | - **What is the command you want to use?:** `ls` 47 | - **Capitalize:** `Ls` 48 | - **Run from the Vim command line:** `:Ls` 49 | - Please `:h :Ls` if you have any questions 50 | 51 | 52 | ```vim 53 | :Ls some_directory 54 | ``` 55 | 56 | Other commands that are available: 57 | 58 | | Shell | Vim | 59 | |---|---| 60 | | `ls` | `:Ls` | 61 | | `mv` | `:Mv` | 62 | | `cp` | `:Cp` | 63 | | `file` | `:File` | 64 | | `cat` | `:Cat` | 65 | | `head` | `:Head` | 66 | | `tail` | `:Tail` | 67 | | `touch` | `:Touch` | 68 | | `mkdir` | `:Mkdir` | 69 | 70 | For more usage and details, see [docmentation](./doc/vim-shellutils.txt). 71 | 72 |

:arrow_up:

73 | 74 | ## Advantage 75 | 76 | Unlike a complete UNIX shell command, the command is emulated by `vim-shellutils` is optimized for Vim. In other words, the synopsis of the commands that are provided by this plugin band shell command is not the same at all. It is when the argument is less than the original. The emulated command interpret the current buffer as an argument in the automatic when the argument is omitted. 77 | 78 | - Example (when you're editing the `~/.vimrc`): 79 | 80 | `:Cp ~/test` and `:Cp ~/.vimrc ~/test` are the same 81 | 82 | `:Rm ` and `:Rm ~/.vimrc` are the same 83 | 84 | This means that it is possible to perform more easily shell command mock. Again, for more detailed description, please refer to the plugin's [help](./doc/vim-shellutils.txt). 85 | 86 |

:arrow_up:

87 | 88 | ## Installation 89 | 90 | [Neobundle](https://github.com/Shougo/neobundle.vim) | [Vundle](https://github.com/VundleVim/Vundle.vim) | [vim-plug](https://github.com/junegunn/vim-plug) 91 | 92 | ```vim 93 | NeoBundle 'b4b4r07/vim-shellutils' 94 | Plugin 'b4b4r07/vim-shellutils' 95 | Plug 'b4b4r07/vim-shellutils' 96 | ``` 97 | 98 |

:arrow_up:

99 | 100 | ## Licence 101 | 102 | [MIT][license] © [b4b4r07](http://b4b4r07.com) 103 | 104 | [travis]: https://travis-ci.org/b4b4r07/vim-shellutils 105 | [appveyor]: https://ci.appveyor.com/project/b4b4r07/vim-shellutils 106 | [license]: https://raw.githubusercontent.com/b4b4r07/dotfiles/master/doc/LICENSE-MIT.txt 107 | 108 |

:arrow_up:

109 | -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | version: '{build}' 2 | clone_depth: 1 3 | environment: 4 | VIM_URL: http://files.kaoriya.net/vim/vim74-kaoriya-win64.zip 5 | install: 6 | - ps: | 7 | $zip = $Env:APPVEYOR_BUILD_FOLDER + '\vim.zip' 8 | $vim = $Env:APPVEYOR_BUILD_FOLDER + '\vim\' 9 | 10 | (New-Object Net.WebClient).DownloadFile($Env:VIM_URL, $zip) 11 | 12 | [Reflection.Assembly]::LoadWithPartialName('System.IO.Compression.FileSystem') > $null 13 | [System.IO.Compression.ZipFile]::ExtractToDirectory($zip, $vim) 14 | 15 | $Env:THEMIS_VIM = $vim + (Get-ChildItem $vim).Name + '\vim.exe' 16 | 17 | git -c advice.detachedHead=false clone https://github.com/thinca/vim-themis --quiet --branch v1.4 --single-branch --depth 1 $Env:TEMP\vim-themis 18 | build: off 19 | test_script: 20 | - ps: | 21 | & $Env:THEMIS_VIM --version 22 | & $Env:TEMP\vim-themis\bin\themis.bat --reporter dot 23 | deploy: off 24 | -------------------------------------------------------------------------------- /autoload/shellutils.vim: -------------------------------------------------------------------------------- 1 | " shellutils.vim 2 | 3 | let s:save_cpo = &cpo 4 | set cpo&vim 5 | 6 | function! shellutils#ls(path, bang) "{{{1 7 | let path = empty(a:path) ? getcwd() : substitute(expand(a:path), '/$', '', 'g') 8 | if filereadable(path) 9 | call shellutils#file(path, '') 10 | return 1 11 | endif 12 | if !isdirectory(path) 13 | echohl ErrorMsg | echo path . ": No such file or directory" | echohl NONE 14 | return 0 15 | endif 16 | 17 | let save_ignore = &wildignore 18 | set wildignore= 19 | let filelist = glob(path . "/*") 20 | if !empty(a:bang) 21 | let filelist .= "\n".glob(path . "/.*[^.]") 22 | endif 23 | let &wildignore = save_ignore 24 | let filelist = substitute(filelist, ' ', '^M', 'g') 25 | 26 | if empty(filelist) 27 | echo "no file" 28 | return 0 29 | endif 30 | 31 | let lists = [] 32 | for file in split(filelist, "\n") 33 | if isdirectory(file) 34 | call add(lists, fnamemodify(file, ":t") . "/") 35 | else 36 | if executable(file) 37 | call add(lists, fnamemodify(file, ":t") . "*") 38 | elseif getftype(file) == 'link' 39 | call add(lists, fnamemodify(file, ":t") . "@") 40 | else 41 | call add(lists, fnamemodify(file, ":t")) 42 | endif 43 | endif 44 | endfor 45 | 46 | echon "[" . len(lists) . "] " 47 | highlight LsDirectory cterm=bold ctermfg=NONE ctermfg=26 gui=bold guifg=#0096FF guibg=NONE 48 | highlight LsExecutable cterm=NONE ctermfg=NONE ctermfg=Green gui=NONE guifg=Green guibg=NONE 49 | highlight LsSymbolick cterm=NONE ctermfg=NONE ctermfg=LightBlue gui=NONE guifg=LightBlue guibg=NONE 50 | 51 | for item in lists 52 | if item =~ '/' 53 | echohl LsDirectory | echon item[:-2] | echohl NONE 54 | echon item[-1:-1] . " " 55 | elseif item =~ '*' 56 | echohl LsExecutable | echon item[:-2] | echohl NONE 57 | echon item[-1:-1] . " " 58 | elseif item =~ '@' 59 | echohl LsSymbolick | echon item[:-2] | echohl NONE 60 | echon item[-1:-1] . " " 61 | else 62 | echon item . " " 63 | endif 64 | endfor 65 | return 1 66 | endfunction 67 | 68 | function! shellutils#file(file, bang) "{{{1 69 | let file = empty(a:file) ? expand('%') : a:file 70 | 71 | let ftype = getftype(file) 72 | let fpath = fnamemodify(file, ":p") 73 | let fname = simplify(file) 74 | let fsize = getfsize(file) 75 | let ftime = strftime("%Y-%m-%d %T", getftime(file)) 76 | let fperm = getfperm(file) 77 | echon "[". ftype ."] " 78 | echon fperm . " " 79 | echon ftime . " " 80 | echon "(" 81 | if ftype ==# 'dir' 82 | echon len(split(glob(fpath. "/*") . string(empty(a:bang) ? '' : glob(fpath . "/.*[^.]")), "\n")) 83 | else 84 | let size = fsize 85 | if size < 0 86 | let size = 0 87 | endif 88 | for unit in ['B', 'KB', 'MB'] 89 | if size < 1024 90 | echon size . unit 91 | break 92 | endif 93 | let size = size / 1024 94 | endfor 95 | endif 96 | echon ") " 97 | echon fname 98 | 99 | return 1 100 | endfunction 101 | 102 | function! shellutils#cat(type, bang, ...) "{{{1 103 | for file in a:000 104 | " Black file 105 | if filereadable(file) && getfsize(file) == 0 106 | if !empty(a:bang) | continue | endif 107 | echohl WarningMsg | echo file . " is blank file" | echohl NONE 108 | continue 109 | endif 110 | " Directory 111 | if isdirectory(file) 112 | if !empty(a:bang) | continue | endif 113 | echohl WarningMsg | echo file . " is directory" | echohl NONE 114 | continue 115 | endif 116 | " No existing 117 | if !isdirectory(file) && !filereadable(file) 118 | if !empty(a:bang) | continue | endif 119 | echohl WarningMsg | echo file . " :No such file or directory" | echohl NONE 120 | continue 121 | endif 122 | 123 | for line in empty(a:type) ? readfile(file) : readfile(file, '', a:type) 124 | echo line == '' ? "\n" : line 125 | endfor 126 | endfor 127 | endfunction 128 | 129 | function! shellutils#mkdir(...) "{{{1 130 | let mkdired = [] 131 | for dir in map(copy(a:000), 'expand(v:val)') 132 | try 133 | call mkdir(dir, 'p') 134 | catch /^Vim\%((\a\+)\)\=:E739/ 135 | echohl WarningMsg 136 | echo printf('Mkdir: %s: File exists', dir) 137 | echohl None 138 | continue 139 | endtry 140 | call add(mkdired, dir) 141 | endfor 142 | if len(mkdired) >= 1 143 | echo "Make directory" string(mkdired) "successfully!" 144 | return 1 145 | endif 146 | endfunction 147 | 148 | function! shellutils#touch(...) "{{{1 149 | let touched = [] 150 | for file in map(copy(a:000), 'expand(v:val)') 151 | if getftype(file) != '' 152 | echohl WarningMsg 153 | echo printf('Touch: %s: File exists', file) 154 | echohl None 155 | continue 156 | endif 157 | call writefile([], file) 158 | call add(touched, file) 159 | endfor 160 | if len(touched) >= 1 161 | echo "Make file" string(touched) "successfully!" 162 | return 1 163 | endif 164 | endfunction 165 | 166 | function! shellutils#cptool(mv, bang, ...) "{{{1 167 | let src = [] 168 | let mv = a:mv ? 'mv' : 'cp' 169 | let bang = empty(a:bang) ? 1 : 0 170 | 171 | " Split the arguments into src and dest {{{2 172 | if a:0 == 1 173 | call add(src, expand('%')) 174 | let dst = expand(simplify(a:1)) 175 | 176 | elseif a:0 == 2 177 | " If the src file is a directory. 178 | if !filereadable(expand(a:1)) 179 | "echo printf("%s: %s: Is a directory", mv, a:1) 180 | echo printf("%s: %s: cannot read", mv, a:1) 181 | return 0 182 | endif 183 | 184 | call add(src, expand(simplify(a:1))) 185 | let dst = expand(simplify(a:2)) 186 | 187 | " a:0 >= 3 188 | else 189 | " The last argument must be a directory. 190 | if !isdirectory(a:000[-1]) 191 | echo printf("%s: target `%s' is not a directory", mv, a:000[-1]) 192 | return 0 193 | endif 194 | 195 | for file in a:000[0:-2] 196 | if filereadable(file) 197 | call add(src, expand(simplify(file))) 198 | endif 199 | endfor 200 | let dst = expand(simplify(a:000[-1])) 201 | endif 202 | 203 | " Coping or moving {{{2 204 | let dst_success = [] 205 | let reopen_stack = [] 206 | for file in src 207 | " Get the pull path of a src file 208 | let src_file = fnamemodify(file, ':p') 209 | " If the dest is a directory or file. 210 | let dst_file = isdirectory(dst) 211 | \ ? substitute(fnamemodify(dst, ':p'), '/$', '', '') . '/' . fnamemodify(file, ':t') 212 | \ : fnamemodify(dst, ':p') 213 | 214 | " Overwrite? 215 | if filereadable(dst_file) && bang 216 | echo '"' . dst_file . '" is exists. Overwrite? [y/N]' 217 | if nr2char(getchar()) !=? 'y' 218 | echo 'Cancelled.' 219 | continue 220 | endif 221 | endif 222 | 223 | " Part to actually run 224 | if writefile(readfile(src_file, "b"), dst_file, "b") != 0 225 | echo 'cp miss!' 226 | continue 227 | else 228 | call add(dst_success, fnamemodify(dst_file, ':.:~')) 229 | " Delete the file and wipeout from a buffer-list, if has a:mv 230 | if a:mv 231 | call delete(src_file) 232 | if bufexists(file) && buflisted(file) 233 | execute 'bwipeout' bufnr(file) 234 | " Add reopen_stack 235 | call add(reopen_stack, dst_file) 236 | endif 237 | endif 238 | endif 239 | endfor 240 | "}}}2 241 | 242 | " Reopen 243 | if a:mv 244 | for file in reopen_stack 245 | execute 'silent edit' file 246 | endfor 247 | endif 248 | 249 | " Display the results when copying or moving one or more files. 250 | if len(dst_success) >= 1 251 | echo a:mv ? "Move" : "Copy" string(src) . " to " . string(dst_success) . " successfully!" 252 | endif 253 | endfunction 254 | 255 | function! shellutils#rm(bang, ...) "{{{1 256 | let files = [] 257 | for file in a:0 ? map(copy(a:000), 'expand(v:val)') : split(simplify(expand('%:p'))) 258 | if empty(a:bang) 259 | redraw | echo 'Delete "' . file . '"? [y/N]: ' 260 | endif 261 | 262 | let file = fnamemodify(file, ":p") 263 | if !empty(a:bang) || nr2char(getchar()) ==? 'y' 264 | if isdirectory(file) 265 | "let l:tmp = "/tmp/shellutils_rm" 266 | "execute "cd" fnamemodify(l:tmp, ":h") 267 | "let dest = "shellutils_rm/" . fnamemodify(file, ":t") 268 | 269 | "let dest = "/tmp/".sha256(reltimestr(reltime()))[:7] 270 | let dest = "/tmp/".s:random_string(10) 271 | "if !isdirectory(dest) 272 | " silent! call shellutils#mkdir(dest) 273 | "endif 274 | 275 | if rename(file, dest) == 0 276 | call add(files, file) 277 | else 278 | echo "This shellutils#rm does not support the removing directory." 279 | endif 280 | elseif filereadable(file) 281 | if delete(file) == 0 282 | call add(files, file) 283 | let bufname = bufname(fnamemodify(file, ':p')) 284 | if bufexists(bufname) && buflisted(bufname) 285 | execute "bwipeout" bufname 286 | endif 287 | endif 288 | else 289 | echohl WarningMsg | echo "The '" . file . "' does not exist" | echohl NONE 290 | endif 291 | endif 292 | endfor 293 | 294 | echo len(files) ? "Removed " . string(files) . "!" : "Removed nothing" 295 | return 1 296 | endfunction 297 | 298 | "__END__ {{{1 299 | 300 | function! s:rand(n) 301 | " http://vim-users.jp/2009/11/hack98/ 302 | let match_end = matchend(reltimestr(reltime()), '\d\+\.') + 1 303 | return reltimestr(reltime())[match_end : ] % (a:n + 1) 304 | endfunction 305 | 306 | function! s:random_string(n) 307 | let s = [] 308 | let chars = split('0123456789abcdefghijklmnopqrstuvwxyz', '\ze') 309 | let max = len(chars) - 1 310 | for x in range(a:n) 311 | call add(s, (chars[s:rand(max)])) 312 | endfor 313 | let @+ = join(s, '') 314 | return join(s, '') 315 | endfunction 316 | 317 | function! shellutils#scope() 318 | return s: 319 | endfunction 320 | 321 | function! shellutils#sid() 322 | return maparg('', 'n') 323 | endfunction 324 | nnoremap 325 | 326 | let &cpo = s:save_cpo 327 | unlet s:save_cpo 328 | 329 | " vim:set et fdm=marker ft=vim ts=2 sw=2 sts=2: 330 | -------------------------------------------------------------------------------- /doc/shellutils.txt: -------------------------------------------------------------------------------- 1 | *shellutils.txt* Provides shell-like commands from cmd-line 2 | 3 | Version: 1.1 4 | Author: b4b4r07 (https://github.com/b4b4r07) 5 | License: MIT License 6 | Repository: https://github.com/b4b4r07/vim-shellutils 7 | Last Change: 2014/10/07 8 | 9 | *CONTENTS* 10 | *shellutils-contents* 11 | 12 | Introduction |shellutils-introduction| 13 | Interface |shellutils-interface| 14 | Commands |shellutils-commands| 15 | Keymappings |shellutils-keymappings| 16 | Variables |shellutils-variables| 17 | License |shellutils-license| 18 | Changelog |shellutils-changelog| 19 | 20 | ============================================================================== 21 | *INTRODUCTION* 22 | *shellutils-introduction* 23 | 24 | The |shellutils.vim| is a plugin that provides user-defined commands have 25 | the shell-like functions from the cmd-line of Vim. We think the command line 26 | of the shell as command line of Vim. Do not you think that's useful if you can 27 | execute shell commands without changing the current buffer and also without 28 | exiting Vim? 29 | 30 | ============================================================================== 31 | *INTERFACE* 32 | *shellutils-interface* 33 | ------------------------------------------------------------------------------ 34 | *COMMANDS* 35 | *shellutils-commands* 36 | 37 | *:Ls* 38 | :Ls[!] [{path}] 39 | Show up some files in the {path} directory to cmd-line. 40 | If you want to show up all the files, including the files that begin 41 | with a dot in the {path} directory, then please put a bang. (|:Ls!|) 42 | If you omit the {path}, the current directory is specified as {path}. 43 | 44 | *:File* 45 | :File [{path}] 46 | Display {path} file information to cmd-line.If the {path} argument is 47 | omitted, set current buffer as {path}. The |:File| display many file 48 | information such as 'ls -l' of shell. For example, 49 | 50 | < 51 | \[file] rw-r--r-- 2014-08-15 17:02:58 (5KB) shellutils.txt 52 | < 53 | *:Rm* 54 | :Rm[!] [{path}] 55 | Remove the {path} file. If the {path} argument is omitted, remove the 56 | current buffer. The |:Rm| inquires whether you really delete the {path} 57 | file. If you don't do this, then please put a bang. (|:Rm!|) 58 | 59 | *:Mkdir* 60 | :Mkdir {path} 61 | Create the {path} directory(ies), if they do not already exist. 62 | Unlike 'mkdir' of shell, The |:Mkdir| always set '-p' option, thus 63 | create directory(ies) when parent directory if no existing. 64 | 65 | *:Touch* 66 | :Touch {path} 67 | Create blank files. Unlike that of the shell, do not edit its last 68 | modified time. 69 | 70 | *:Cat* 71 | :Cat {path} 72 | Concatenate FILE(s), to cmd-line. 73 | 74 | *:Head* 75 | :Head {path} 76 | Print the first 10 lines of each FILE to cmd-line. With no FILE, 77 | read current buffer. 78 | 79 | *:Tail* 80 | :Tail {path} 81 | Print the last 10 lines of each FILE to cmd-line. With no FILE, 82 | read current buffer. 83 | 84 | *:Cp* 85 | :Cp[!] {src} {dest} 86 | :Cp[!] {src}... {directory} 87 | Copy {src} to {dest}, or multiple {src}s to {directory}. Prompt 88 | whether to overwrite existing regular destination files. If you 89 | don't do this, then please put a bang. (|:Cp!|) 90 | 91 | *:Mv* 92 | :Mv[!] {src} {dest} 93 | :Mv[!] {src}... {directory} 94 | Rename {src} to {dest}, or move {src}s to {directory}. Prompt 95 | whether to overwrite existing regular destination files. If you 96 | don't do this, then please put a bang. (|:Mv!|) 97 | 98 | ------------------------------------------------------------------------------ 99 | *KEYMAPPING* 100 | *shellutils-keymappings* 101 | 102 | The keymappings is not supported. 103 | 104 | ============================================================================== 105 | *VARIABLES* 106 | *shellutils-variables* 107 | 108 | g:shellutils_disable_commands 109 | *g:shellutils_disable_commands* 110 | (default: []) 111 | Disable optional user-defined commands. For example, |:Ls| and so on. 112 | 113 | ============================================================================== 114 | *LICENSE* 115 | *shellutils-license* 116 | 117 | The MIT License (MIT) 118 | 119 | Copyright (c) 2014 b4b4r07 120 | 121 | Permission is hereby granted, free of charge, to any person obtaining a copy 122 | of this software and associated documentation files (the "Software"), to deal 123 | in the Software without restriction, including without limitation the rights 124 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 125 | copies of the Software, and to permit persons to whom the Software is 126 | furnished to do so, subject to the following conditions: 127 | 128 | The above copyright notice and this permission notice shall be included in all 129 | copies or substantial portions of the Software. 130 | 131 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 132 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 133 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 134 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 135 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 136 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 137 | SOFTWARE. 138 | 139 | ============================================================================== 140 | *CHANGELOG* 141 | *shellutils-changelog* 142 | 143 | 0.1 2014-08-15 144 | - Initial version. 145 | 146 | 0.2 2014-09-10 147 | - Fixed some bugs. 148 | 149 | 1.0 2014-10-05 150 | - Upload www.vim.org 151 | 152 | 1.1 2014-11-07 153 | - Support autoload 154 | 155 | ============================================================================== 156 | vim:tw=78:et:ft=help:norl: 157 | -------------------------------------------------------------------------------- /doc/shellutils_old.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/babarot/vim-shellutils/1d4a8ff9d0cb66a065af5674a8053cc059167584/doc/shellutils_old.gif -------------------------------------------------------------------------------- /plugin/shellutils.vim: -------------------------------------------------------------------------------- 1 | " shellutils.vim 2 | 3 | if exists("g:loaded_shellutils") 4 | finish 5 | endif 6 | let g:loaded_shellutils = 1 7 | 8 | let s:save_cpo = &cpo 9 | set cpo&vim 10 | 11 | " Commands: {{{1 12 | 13 | " Do NOT overwritten the same name commands 14 | " 15 | " example: 16 | " let g:shellutils_disable_commands = ['Ls', 'Mkdir'] 17 | " 18 | " By doing so, :Ls and :Mkdir commands in other plugin are used preferentially. 19 | if !exists('g:shellutils_disable_commands') 20 | let g:shellutils_disable_commands = [''] 21 | endif 22 | 23 | let g:shellutils_shell_commands = [ 24 | \ 'command! -nargs=+ -complete=dir Mkdir call shellutils#mkdir()', 25 | \ 'command! -nargs=+ -complete=file Touch call shellutils#touch()', 26 | \ 'command! -nargs=+ -bang -complete=file Cp call shellutils#cptool(0, , )', 27 | \ 'command! -nargs=+ -bang -complete=file Mv call shellutils#cptool(1, , )', 28 | \ 'command! -nargs=+ -bang -complete=file Cat call shellutils#cat("", , )', 29 | \ 'command! -nargs=+ -bang -complete=file Head call shellutils#cat(10, , )', 30 | \ 'command! -nargs=+ -bang -complete=file Tail call shellutils#cat(-10, , )', 31 | \ 'command! -nargs=? -bang -complete=file Ls call shellutils#ls(, )', 32 | \ 'command! -nargs=? -bang -complete=file File call shellutils#file(, )', 33 | \ 'command! -nargs=* -bang -complete=file Rm call shellutils#rm(, )', 34 | \ ] 35 | 36 | for commands in g:shellutils_shell_commands 37 | if match(g:shellutils_disable_commands, substitute(commands, '^.*\(\u\l\+\).*$', '\1', 'g')) == -1 38 | execute commands 39 | endif 40 | endfor 41 | "}}} 42 | 43 | let &cpo = s:save_cpo 44 | unlet s:save_cpo 45 | 46 | " vim:set et fdm=marker ft=vim ts=2 sw=2 sts=2: 47 | -------------------------------------------------------------------------------- /test/ls.vim: -------------------------------------------------------------------------------- 1 | let s:is_windows = has('win16') || has('win32') || has('win64') 2 | let s:is_cygwin = has('win32unix') 3 | let s:is_win = s:is_cygwin || s:is_windows 4 | let s:is_mac = !s:is_windows && !s:is_cygwin 5 | \ && (has('mac') || has('macunix') || has('gui_macvim') || 6 | \ (!executable('xdg-open') && 7 | \ system('uname') =~? '^darwin')) 8 | 9 | let s:suite = themis#suite('ls') 10 | let s:assert = themis#helper('assert') 11 | 12 | function! s:suite.ls_basically_check() 13 | let w = expand('~/ls_test') 14 | if !isdirectory(w) 15 | call mkdir(w) 16 | endif 17 | execute 'cd' w 18 | for f in ['a', 'b', 'c'] 19 | call shellutils#touch(f) 20 | endfor 21 | 22 | call s:assert.true(shellutils#ls(w, '')) 23 | redir => result 24 | silent! call shellutils#ls(w, '') 25 | redir END 26 | 27 | let list_result = split(result, ' ') 28 | call s:assert.equals(len(list_result), 4) 29 | call s:assert.equals(list_result, ["[3]", "a", "b", "c"]) 30 | endfunction 31 | 32 | function! s:suite.ls_spaced_filename() 33 | let w = expand('~/ls_test2') 34 | if !isdirectory(w) 35 | call mkdir(w) 36 | endif 37 | execute 'cd' w 38 | call shellutils#touch('spaced filename') 39 | 40 | call s:assert.true(shellutils#ls(w, '')) 41 | redir => result 42 | silent! call shellutils#ls(w, '') 43 | redir END 44 | 45 | let list_result = split(result, ' ') 46 | call s:assert.equals(len(list_result), 3) 47 | call s:assert.not_equals(list_result, ["[2]", "spaced", "filename"]) 48 | endfunction 49 | 50 | function! s:suite.ls_non_existing() 51 | let res = shellutils#ls('~/non_existing', '') 52 | call s:assert.false(res) 53 | endfunction 54 | 55 | function! s:suite.ls_no_file() 56 | let w = expand('~/ls_test3') 57 | if !isdirectory(w) 58 | call mkdir(w) 59 | endif 60 | execute 'cd' w 61 | 62 | call s:assert.false(shellutils#ls(w, '')) 63 | redir => result 64 | silent! call shellutils#ls(w, '') 65 | redir END 66 | call s:assert.match(result, 'no file') 67 | endfunction 68 | 69 | function! s:suite.ls_bang() 70 | let w = expand('~/ls_test4') 71 | if !isdirectory(w) 72 | call mkdir(w) 73 | endif 74 | execute 'cd' w 75 | for f in ['a', 'b', 'c', '.d', '.e'] 76 | call shellutils#touch(f) 77 | endfor 78 | 79 | call s:assert.true(shellutils#ls(w, '!')) 80 | redir => result 81 | silent! call shellutils#ls(w, '!') 82 | redir END 83 | 84 | let list_result = split(result, ' ') 85 | call s:assert.equals(len(list_result), 6) 86 | if s:is_win 87 | call s:assert.equals(list_result, ["[5]", "a", "b", "c", ".d*", ".e*"]) 88 | else 89 | call s:assert.equals(list_result, ["[5]", "a", "b", "c", ".d", ".e"]) 90 | endif 91 | endfunction 92 | 93 | function! s:suite.ls_file() 94 | let w = expand('~/ls_test5') 95 | if !isdirectory(w) 96 | call mkdir(w) 97 | endif 98 | execute 'cd' w 99 | call shellutils#touch('file') 100 | 101 | if s:is_win 102 | let f = w . '\file' 103 | else 104 | let f = w . '/file' 105 | endif 106 | call s:assert.true(shellutils#ls(f, '')) 107 | call s:assert.true(shellutils#file(f, '')) 108 | 109 | "redir => result 110 | " call shellutils#ls(f, '') 111 | "redir END 112 | "call s:assert.match(substitute(result, '^ *', '', ''), 113 | " \ 'rw-r--r-- ' . strftime("%Y-%m-%d %T", getftime(f)) . ' (0B) ' . f) 114 | endfunction 115 | -------------------------------------------------------------------------------- /test/mkdir.vim: -------------------------------------------------------------------------------- 1 | let s:suite = themis#suite('mkdir') 2 | let s:assert = themis#helper('assert') 3 | 4 | function! s:suite.mkdir_basically_check() 5 | let dir = expand('~/mkdir_test') 6 | call s:assert.true(shellutils#mkdir(dir)) 7 | endfunction 8 | 9 | function! s:suite.mkdir_check_if_success() 10 | let dir = expand('~/mkdir_test2') 11 | redir => result 12 | silent! call shellutils#mkdir(dir) 13 | redir END 14 | 15 | call s:assert.match(result, "Make directory") 16 | endfunction 17 | 18 | function! s:suite.mkdir_already_exists() 19 | let dir = expand('~/mkdir_test') 20 | call s:assert.false(shellutils#mkdir(dir)) 21 | endfunction 22 | 23 | function! s:suite.mkdir_expand_path() 24 | call s:assert.true(shellutils#mkdir('~/mkdir_test3')) 25 | call s:assert.true(isdirectory(expand('~/mkdir_test3'))) 26 | endfunction 27 | -------------------------------------------------------------------------------- /test/rm.vim: -------------------------------------------------------------------------------- 1 | let s:is_windows = has('win16') || has('win32') || has('win64') 2 | let s:is_cygwin = has('win32unix') 3 | let s:is_win = s:is_cygwin || s:is_windows 4 | let s:is_mac = !s:is_windows && !s:is_cygwin 5 | \ && (has('mac') || has('macunix') || has('gui_macvim') || 6 | \ (!executable('xdg-open') && 7 | \ system('uname') =~? '^darwin')) 8 | 9 | let s:suite = themis#suite('rm') 10 | let s:assert = themis#helper('assert') 11 | let s:file = expand('~/rm_test') 12 | 13 | function! s:before_each() 14 | call shellutils#touch(s:file) 15 | endfunction 16 | 17 | function! s:suite.rm_basically_check() 18 | call s:assert.true(shellutils#rm('!', s:file)) 19 | endfunction 20 | 21 | function! s:suite.rm_check_if_success() 22 | redir => result 23 | silent! call shellutils#rm('!', s:file) 24 | redir END 25 | call s:assert.match(result, "Removed") 26 | endfunction 27 | 28 | function! s:suite.rm_more_arguments() 29 | call shellutils#touch('~/rm_test.1', '~/rm_test.2', '~/rm_test.3') 30 | call s:assert.true(shellutils#rm('!', '~/rm_test.1', '~/rm_test.2', '~/rm_test.3')) 31 | endfunction 32 | 33 | function! s:suite.rm_if_no_argument() 34 | new 35 | w rm_test2 36 | call s:assert.equals(getfsize(expand('%')), 0) 37 | call shellutils#rm('!') 38 | call s:assert.equals(getfsize(expand('%')), -1) 39 | endfunction 40 | 41 | function! s:suite.vim_has_cryptv() 42 | call exists("+cryptv") 43 | call has('patch-7.3.816') 44 | endfunction 45 | 46 | function! s:suite.rm_if_directory() 47 | ""call shellutils#mkdir('~/rm_test3') 48 | """call s:assert.true(!isdirectory('/tmp/shellutils_rm/rm_test3')) 49 | ""call shellutils#rm('!', '~/rm_test3') 50 | ""call s:assert.true(isdirectory('/tmp/shellutils_rm/rm_test3')) 51 | ""if exists("+cryptv") 52 | "" call s:assert.skip("no cryptv") 53 | ""endif 54 | if s:is_win 55 | call s:assert.skip("windows") 56 | endif 57 | 58 | call shellutils#mkdir('~/rm_test') 59 | call s:assert.true(isdirectory(expand('~/rm_test'))) 60 | redir => result 61 | silent! call shellutils#rm('!', '~/rm_test') 62 | redir END 63 | call s:assert.match(result, "Removed") 64 | call s:assert.true(!isdirectory(expand('~/rm_test'))) 65 | endfunction 66 | 67 | ""function! s:suite.rm_dir() 68 | "" call shellutils#mkdir('~/dir') 69 | "" "call s:assert.true(isdirectory(expand('~/dir'))) 70 | "" call s:assert.false(isdirectory('/tmp/shellutils_rm/dir')) 71 | "" 72 | "" call shellutils#rm('!', '~/dir') 73 | "" "call s:assert.false(isdirectory(expand('~/dir'))) 74 | "" call s:assert.true(isdirectory('/tmp/shellutils_rm/dir')) 75 | ""endfunction 76 | "" 77 | ""function! s:suite.rm_dir2() 78 | "" call shellutils#mkdir('~/dir2') 79 | "" "call s:assert.true(isdirectory(expand('~/dir2'))) 80 | "" call s:assert.false(isdirectory('/tmp/shellutils_rm/dir2')) 81 | "" 82 | "" call shellutils#rm('!', '~/dir2') 83 | "" "call s:assert.false(isdirectory(expand('~/dir2'))) 84 | "" call s:assert.true(isdirectory('/tmp/shellutils_rm/dir2')) 85 | ""endfunction 86 | -------------------------------------------------------------------------------- /test/touch.vim: -------------------------------------------------------------------------------- 1 | let s:suite = themis#suite('touch') 2 | let s:assert = themis#helper('assert') 3 | 4 | function! s:suite.touch_basically_check() 5 | let file = expand('~/touch_test') 6 | call s:assert.true(shellutils#touch(file)) 7 | endfunction 8 | 9 | function! s:suite.touch_check_if_success() 10 | let file = expand('~/touch_test2') 11 | redir => result 12 | silent! call shellutils#touch(file) 13 | redir END 14 | 15 | call s:assert.match(result, "Make file") 16 | endfunction 17 | 18 | function! s:suite.touch_already_exists() 19 | let file = expand('~/touch_test') 20 | call s:assert.false(shellutils#touch(file)) 21 | endfunction 22 | 23 | function! s:suite.touch_expand_path() 24 | call s:assert.true(shellutils#touch('~/touch_test3')) 25 | call s:assert.true(filereadable(expand('~/touch_test3'))) 26 | endfunction 27 | 28 | function! s:suite.touch_file_is_blank() 29 | call s:assert.equals(getfsize(expand('~/touch_test')), 0) 30 | endfunction 31 | --------------------------------------------------------------------------------