diff options
-rw-r--r-- | runtime/doc/various.txt | 1 | ||||
-rw-r--r-- | src/nvim/ex_cmds.c | 6 | ||||
-rw-r--r-- | test/old/testdir/test_shell.vim | 31 |
3 files changed, 38 insertions, 0 deletions
diff --git a/runtime/doc/various.txt b/runtime/doc/various.txt index 7b0e724e31..84449cdae6 100644 --- a/runtime/doc/various.txt +++ b/runtime/doc/various.txt @@ -248,6 +248,7 @@ g8 Print the hex values of the bytes used in the < *:!cmd* *:!* :!{cmd} Execute {cmd} with 'shell'. See also |:terminal|. + `:!` without a {cmd} is a no-op, it does nothing. The command runs in a non-interactive shell connected to a pipe (not a terminal). Use |:terminal| to run an diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index a1b43113a6..cc8c4aeca8 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -1012,6 +1012,12 @@ void do_bang(int addr_count, exarg_T *eap, bool forceit, bool do_in, bool do_out } } 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; + } + xfree(prevcmd); prevcmd = newcmd; diff --git a/test/old/testdir/test_shell.vim b/test/old/testdir/test_shell.vim index 3d0056bfc1..b65752dbf2 100644 --- a/test/old/testdir/test_shell.vim +++ b/test/old/testdir/test_shell.vim @@ -206,4 +206,35 @@ func Test_set_shell() 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 |