commit c8be9458dddb986dc17a3f5a00aaf29cd60b1b5f
parent 628098fff1d75ad104934009b4ce60c4e23204ec
Author: Phil Runninger <PhilRunninger@users.noreply.github.com>
Date: Sat, 30 Jan 2021 23:45:56 -0500
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.
Diffstat:
2 files changed, 22 insertions(+), 0 deletions(-)
diff --git 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
@@ -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: