From c8be9458dddb986dc17a3f5a00aaf29cd60b1b5f Mon Sep 17 00:00:00 2001 From: Phil Runninger Date: Sat, 30 Jan 2021 23:45:56 -0500 Subject: [PATCH] New menu command: Run a system command in this directory. (#1214) * New menu command: Run system command in this directory. * Echo the output from the system command. * Update version number in change log. * Address Vim linter message: change "\n" to nr2char(10) * Use single quoted strings. * Use system() instead of systemlist() for greater version compatibility. systemlist() was introduced sometime in Vim 8+, so I switched to system() for 7.4 compatibility. --- CHANGELOG.md | 1 + nerdtree_plugin/fs_menu.vim | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8d8eef9..1192d48 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ - **.PATCH**: Pull Request Title (PR Author) [PR Number](Link to PR) --> #### 6.10 +- **.2**: New menu command: Run a system command in this directory. (PhilRunninger) [#1214](https://github.com/preservim/nerdtree/pull/1214) - **.1**: Escape quotation marks so they can be used in key mappings. (PhilRunninger) [#1213](https://github.com/preservim/nerdtree/pull/1213) - **.0**: Enable full path specifications for NERDTreeIgnore (PhilRunninger) [#1207](https://github.com/preservim/nerdtree/pull/1207) #### 6.9 diff --git a/nerdtree_plugin/fs_menu.vim b/nerdtree_plugin/fs_menu.vim index b3ef42e..09cb69b 100644 --- a/nerdtree_plugin/fs_menu.vim +++ b/nerdtree_plugin/fs_menu.vim @@ -49,6 +49,10 @@ else call NERDTreeAddMenuItem({'text': '(l)ist the current node', 'shortcut': 'l', 'callback': 'NERDTreeListNodeWin32'}) endif +if exists('*system') + call NERDTreeAddMenuItem({'text': 'Run (s)ystem command in this directory', 'shortcut':'s', 'callback': 'NERDTreeSystemCommand'}) +endif + "FUNCTION: s:inputPrompt(action){{{1 "returns the string that should be prompted to the user for the given action " @@ -460,4 +464,21 @@ function! NERDTreeExecuteFileWindows() call system('cmd.exe /c start "" ' . shellescape(l:node.path.str())) endfunction +" FUNCTION: NERDTreeSystemCommand() {{{1 +function! NERDTreeSystemCommand() + let l:node = g:NERDTreeFileNode.GetSelected() + + if empty(l:node) + return + endif + + let l:cwd = getcwd() + let l:directory = l:node.path.isDirectory ? l:node.path.str() : l:node.parent.path.str() + execute 'cd '.l:directory + + let l:nl = nr2char(10) + echo l:nl . system(input(l:directory . (nerdtree#runningWindows() ? '> ' : ' $ '))) + execute 'cd '.l:cwd +endfunction + " vim: set sw=4 sts=4 et fdm=marker: