]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.0.0783: ":!" doesn't do anything but does update the previous command v9.0.0783
authorBram Moolenaar <Bram@vim.org>
Mon, 17 Oct 2022 17:00:23 +0000 (18:00 +0100)
committerBram Moolenaar <Bram@vim.org>
Mon, 17 Oct 2022 17:00:23 +0000 (18:00 +0100)
Problem:    ":!" doesn't do anything but does update the previous command.
Solution:   Do not have ":!" change the previous command. (Martin Tournoij,
            closes #11372)

.gitignore
runtime/doc/various.txt
src/ex_cmds.c
src/testdir/test_shell.vim
src/version.c

index 72486f0ff28a15225f5330a6ea6605a021541a3b..4a2874928bb1fd2cba184519e714bdaf721d402b 100644 (file)
@@ -85,6 +85,7 @@ src/testdir/messages
 src/testdir/viminfo
 src/testdir/opt_test.vim
 src/testdir/failed
+src/testdir/starttime
 runtime/indent/testdir/*.out
 runtime/indent/testdir/*.fail
 src/memfile_test
index 6f24515d7d21f1756ce3391e80acb57b691bb3f9..1d21e1a9edd8c940588e1ede54bb19a9c54561e1 100644 (file)
@@ -249,7 +249,8 @@ g8                  Print the hex values of the bytes used in the
 
                                                        *:!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
index 7f41c7915a425421351a7bf79e54c26192d0c453..f5271ea426652bfe9f2a38e59e79ba9878be322a 100644 (file)
@@ -957,6 +957,11 @@ do_bang(
        }
     } 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;
 
index cacb02b1b8d8311bff3374897203d4c49213ba28..1b4b1f98095a2787ec0eb623995af25b35dd91a4 100644 (file)
@@ -251,4 +251,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
index 433152ecf6a8249e2cf2ce9499cd20643cc2f67c..0f6b59aa8686fc0a03ea57022ad5fb41bbad6703 100644 (file)
@@ -695,6 +695,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    783,
 /**/
     782,
 /**/