exec_menuitem.vim 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. " ============================================================================
  2. " File: exec_menuitem.vim
  3. " Description: plugin for NERD Tree that provides an execute file menu item
  4. " Maintainer: Martin Grenfell <martin.grenfell at gmail dot com>
  5. " License: This program is free software. It comes without any warranty,
  6. " to the extent permitted by applicable law. You can redistribute
  7. " it and/or modify it under the terms of the Do What The Fuck You
  8. " Want To Public License, Version 2, as published by Sam Hocevar.
  9. " See http://sam.zoy.org/wtfpl/COPYING for more details.
  10. "
  11. " ============================================================================
  12. if exists('g:loaded_nerdtree_exec_menuitem')
  13. finish
  14. endif
  15. let g:loaded_nerdtree_exec_menuitem = 1
  16. call NERDTreeAddMenuItem({
  17. \ 'text': '(!)Execute file',
  18. \ 'shortcut': '!',
  19. \ 'callback': 'NERDTreeExecFile',
  20. \ 'isActiveCallback': 'NERDTreeExecFileActive' })
  21. function! NERDTreeExecFileActive()
  22. let node = g:NERDTreeFileNode.GetSelected()
  23. return !node.path.isDirectory && node.path.isExecutable
  24. endfunction
  25. function! NERDTreeExecFile()
  26. let treenode = g:NERDTreeFileNode.GetSelected()
  27. echo "==========================================================\n"
  28. echo "Complete the command to execute (add arguments etc):\n"
  29. let cmd = treenode.path.str({'escape': 1})
  30. let cmd = input(':!', cmd . ' ')
  31. if cmd !=# ''
  32. exec ':!' . cmd
  33. else
  34. echo 'Aborted'
  35. endif
  36. endfunction