*:!cmd* *:!*
:!{cmd} Execute {cmd} with the shell. See also the 'shell'
- and 'shelltype' option.
+ and 'shelltype' option. `:!` without a {cmd} is a no-op,
+ it does nothing.
*E34*
Any '!' in {cmd} is replaced with the previous
external command (see also 'cpoptions'). But not when
}
} while (trailarg != NULL);
+ // Don't do anything if there is no command as there isn't really anything
+ // useful in running "sh -c ''". Avoids changing "prevcmd".
+ if (STRLEN(newcmd) == 0)
+ return;
+
vim_free(prevcmd);
prevcmd = newcmd;
call delete('Xtestout')
endfunc
+func Test_shell_repeat()
+ CheckUnix
+
+ let save_shell = &shell
+
+ call writefile(['#!/bin/sh', 'echo "Cmd: [$*]" > Xlog'], 'Xtestshell', 'D')
+ call setfperm('Xtestshell', "r-x------")
+ set shell=./Xtestshell
+ defer delete('Xlog')
+
+ call feedkeys(":!echo coconut\<CR>", 'xt') " Run command
+ call assert_equal(['Cmd: [-c echo coconut]'], readfile('Xlog'))
+
+ call feedkeys(":!!\<CR>", 'xt') " Re-run previous
+ call assert_equal(['Cmd: [-c echo coconut]'], readfile('Xlog'))
+
+ call writefile(['empty'], 'Xlog')
+ call feedkeys(":!\<CR>", 'xt') " :! is a no-op
+ call assert_equal(['empty'], readfile('Xlog'))
+
+ call feedkeys(":!!\<CR>", 'xt') " :! doesn't clear previous command
+ call assert_equal(['Cmd: [-c echo coconut]'], readfile('Xlog'))
+
+ call feedkeys(":!echo banana\<CR>", 'xt') " Make sure setting previous command keeps working after a :! no-op
+ call assert_equal(['Cmd: [-c echo banana]'], readfile('Xlog'))
+ call feedkeys(":!!\<CR>", 'xt')
+ call assert_equal(['Cmd: [-c echo banana]'], readfile('Xlog'))
+
+ let &shell = save_shell
+endfunc
+
" vim: shiftwidth=2 sts=2 expandtab