Bram, This updated patch includes a test that currently fails. It fixes the problem of including subdirectories from items in the path, and the fix makes the test pass.
I'm not sure what the best way is to make this test portable to, say, Windows... I'm currently not set up to run tests on Windows. Let me know what you think. Thanks, Jason -- -- You received this message from the "vim_dev" maillist. Do not top-post! Type your reply below the text you are replying to. For more information, visit http://www.vim.org/maillist.php --- You received this message because you are subscribed to the Google Groups "vim_dev" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
>From f3d1e0e838409efd4bb3d51977e30c7e1fad6d33 Mon Sep 17 00:00:00 2001 From: Jason Franklin <[email protected]> Date: Sat, 28 Jul 2018 12:10:14 -0400 Subject: [PATCH] Fix shellcmd completion --- src/ex_getln.c | 13 ++++++++++++- src/testdir/test_cmdline.vim | 22 ++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/ex_getln.c b/src/ex_getln.c index 063900a38..99f034ece 100644 --- a/src/ex_getln.c +++ b/src/ex_getln.c @@ -5193,15 +5193,26 @@ expand_shellcmd( hash_init(&found_ht); for (s = path; ; s = e) { + + // Note that we only match directories if we are searching the current + // directory. Matching sub-directories of items in the PATH is not + // helpful. if (*s == NUL) { if (did_curdir) break; - /* Find directories in the current directory, path is empty. */ + + // Find directories in the current directory; path is empty. did_curdir = TRUE; + flags |= EW_DIR; } else if (*s == '.') + { did_curdir = TRUE; + flags |= EW_DIR; + } + else + flags &= ~EW_DIR; #if defined(MSWIN) e = vim_strchr(s, ';'); diff --git a/src/testdir/test_cmdline.vim b/src/testdir/test_cmdline.vim index 26d33d838..dbcc996b0 100644 --- a/src/testdir/test_cmdline.vim +++ b/src/testdir/test_cmdline.vim @@ -290,6 +290,28 @@ func Test_getcompletion() call assert_fails('call getcompletion("", "burp")', 'E475:') endfunc +func Test_shellcmd_completion() + let save_path = $PATH + + call mkdir('Xpathdir/Xpathsubdir', 'p') + call writefile([''], 'Xpathdir/Xfile.exe') + call setfperm('Xpathdir/Xfile.exe', 'rwx------') + + " Set PATH to exaple directory with trailing slash removed. + let $PATH = fnamemodify('./Xpathdir', ':p')[:-2] + + " Test for the ":!<TAB>" case. Previously, this would include subdirs of + " dirs in the PATH. This is not helpful. We check that only subdirs of the + " PWD and executables from the PATH are included in the suggestions. + let actual = getcompletion('', 'shellcmd') + let expected = map(filter(glob('*', 0, 1), 'isdirectory(v:val)'), 'v:val . "/"') + call insert(expected, 'Xfile.exe') + call assert_equal(expected, actual) + + call delete('Xpathdir', 'rf') + let $PATH = save_path +endfunc + func Test_expand_star_star() call mkdir('a/b', 'p') call writefile(['asdfasdf'], 'a/b/fileXname') -- 2.17.1
