aboutsummaryrefslogtreecommitdiff
path: root/vim.dot.link/plugin/startshell_mapping.vim.disabled
blob: e9704f43bc365f049a044497bc4c31abf65e1632 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
"plugin from http://got-ravings.blogspot.com/2010/07/vim-pr0n-sample-nerd-tree-plugins.html
"guard against sourcing the script twice
if exists("g:loaded_nerdtree_start_shell_mapping")
    finish
endif
let g:loaded_nerdtree_start_shell_mapping = 1

"bind 'S' to NERDTreeStartShell()
call NERDTreeAddKeyMap({
    \ 'key': 'S',
    \ 'callback': 'NERDTreeStartShell',
    \ 'quickhelpText': 'start a :shell in this dir' })

"change to the dir of the current node and start a :shell
function! NERDTreeStartShell()

    "grab the currently selected dir node (returns 
    "the parent dir if a file is selected)
    let n = g:NERDTreeDirNode.GetSelected()

    "save the cwd so we can restore it after the :shell exits
    let oldCWD = getcwd()

    try

        ":lcd to to the selected dir and :shell out
        exec 'lcd ' . n.path.str({'format': 'Cd'})
        redraw!
        shell

    "make sure we restore the cwd to its original state
    finally
        exec 'lcd ' . oldCWD
    endtry

endfunction