2009-07-19 13:21:57 +08:00
" ============================================================================
2009-08-21 21:54:28 +08:00
" File: fs_menu.vim
2009-07-19 13:21:57 +08:00
" Description: plugin for the NERD Tree that provides a file system menu
2009-10-09 09:46:40 +08:00
" Maintainer: Martin Grenfell <martin.grenfell at gmail dot com>
2009-07-19 13:21:57 +08:00
" License: This program is free software. It comes without any warranty,
" to the extent permitted by applicable law. You can redistribute
" it and/or modify it under the terms of the Do What The Fuck You
" Want To Public License, Version 2, as published by Sam Hocevar.
" See http://sam.zoy.org/wtfpl/COPYING for more details.
"
" ============================================================================
2019-12-31 13:50:25 +08:00
if exists ( 'g:loaded_nerdtree_fs_menu' )
2009-07-19 13:21:57 +08:00
finish
endif
let g :loaded_nerdtree_fs_menu = 1
2012-08-26 16:51:26 +08:00
"Automatically delete the buffer after deleting or renaming a file
2019-12-31 13:50:25 +08:00
if ! exists ( 'g:NERDTreeAutoDeleteBuffer' )
2012-08-26 16:51:26 +08:00
let g :NERDTreeAutoDeleteBuffer = 0
endif
2009-07-21 15:26:48 +08:00
call NERDTreeAddMenuItem ( {'text' : '(a)dd a childnode' , 'shortcut' : 'a' , 'callback' : 'NERDTreeAddNode' })
2011-02-08 12:16:30 +08:00
call NERDTreeAddMenuItem ( {'text' : '(m)ove the current node' , 'shortcut' : 'm' , 'callback' : 'NERDTreeMoveNode' })
call NERDTreeAddMenuItem ( {'text' : '(d)elete the current node' , 'shortcut' : 'd' , 'callback' : 'NERDTreeDeleteNode' })
2011-09-07 08:01:57 +08:00
2023-10-22 20:17:01 +08:00
if nerdtree #runningMac ( )
2023-10-23 23:36:13 +08:00
call NERDTreeAddMenuItem ( {'text' : '(r)eveal the current node in the Finder' , 'shortcut' : 'r' , 'callback' : 'NERDTreeRevealInFinder' })
2011-09-07 08:01:57 +08:00
call NERDTreeAddMenuItem ( {'text' : '(o)pen the current node with system editor' , 'shortcut' : 'o' , 'callback' : 'NERDTreeExecuteFile' })
call NERDTreeAddMenuItem ( {'text' : '(q)uicklook the current node' , 'shortcut' : 'q' , 'callback' : 'NERDTreeQuickLook' })
endif
2019-12-31 13:50:25 +08:00
if executable ( 'xdg-open' )
2018-04-10 01:08:09 +08:00
call NERDTreeAddMenuItem ( {'text' : '(r)eveal the current node in file manager' , 'shortcut' : 'r' , 'callback' : 'NERDTreeRevealFileLinux' })
call NERDTreeAddMenuItem ( {'text' : '(o)pen the current node with system editor' , 'shortcut' : 'o' , 'callback' : 'NERDTreeExecuteFileLinux' })
endif
2020-05-22 20:57:19 +08:00
if nerdtree #runningWindows ( )
2023-10-23 23:36:13 +08:00
call NERDTreeAddMenuItem ( {'text' : '(r)eveal the current node in the Explorer' , 'shortcut' : 'r' , 'callback' : 'NERDTreeRevealInExplorer' })
2020-05-22 20:57:19 +08:00
call NERDTreeAddMenuItem ( {'text' : '(o)pen the current node with system editor' , 'shortcut' : 'o' , 'callback' : 'NERDTreeExecuteFileWindows' })
endif
2009-07-19 13:34:28 +08:00
if g :NERDTreePath .CopyingSupported ( )
2012-10-04 03:39:56 +08:00
call NERDTreeAddMenuItem ( {'text' : '(c)opy the current node' , 'shortcut' : 'c' , 'callback' : 'NERDTreeCopyNode' })
2009-07-19 13:34:28 +08:00
endif
2019-12-31 13:50:25 +08:00
call NERDTreeAddMenuItem ( {'text' : ( has ( 'clipboard' ) ?'copy (p)ath to clipboard' :'print (p)ath to screen' ) , 'shortcut' : 'p' , 'callback' : 'NERDTreeCopyPath' })
2009-07-19 13:21:57 +08:00
2019-12-31 13:50:25 +08:00
if has ( 'unix' ) | | has ( 'osx' )
2015-11-03 03:30:16 +08:00
call NERDTreeAddMenuItem ( {'text' : '(l)ist the current node' , 'shortcut' : 'l' , 'callback' : 'NERDTreeListNode' })
2023-10-19 20:33:38 +08:00
call NERDTreeAddMenuItem ( {'text' : '(C)hange node permissions' , 'shortcut' :'C' , 'callback' : 'NERDTreeChangePermissions' })
2015-11-13 05:20:20 +08:00
else
call NERDTreeAddMenuItem ( {'text' : '(l)ist the current node' , 'shortcut' : 'l' , 'callback' : 'NERDTreeListNodeWin32' })
2015-11-03 03:30:16 +08:00
endif
2021-01-31 12:45:56 +08:00
if exists ( '*system' )
call NERDTreeAddMenuItem ( {'text' : 'Run (s)ystem command in this directory' , 'shortcut' :'s' , 'callback' : 'NERDTreeSystemCommand' })
endif
2019-02-25 07:01:12 +08:00
"FUNCTION: s:inputPrompt(action){{{1
"returns the string that should be prompted to the user for the given action
"
"Args:
"action: the action that is being performed, e.g. 'delete'
function ! s :inputPrompt ( action )
2019-12-31 14:29:58 +08:00
if a :action = = # 'add'
2019-12-31 13:50:25 +08:00
let title = 'Add a childnode'
2019-02-25 07:01:12 +08:00
let info = "Enter the dir/file name to be created. Dirs end with a '/'"
2019-12-31 13:50:25 +08:00
let minimal = 'Add node:'
2019-02-25 07:01:12 +08:00
2019-12-31 14:29:58 +08:00
elseif a :action = = # 'copy'
2019-12-31 13:50:25 +08:00
let title = 'Copy the current node'
let info = 'Enter the new path to copy the node to:'
let minimal = 'Copy to:'
2019-02-25 07:01:12 +08:00
2019-12-31 14:29:58 +08:00
elseif a :action = = # 'delete'
2019-12-31 13:50:25 +08:00
let title = 'Delete the current node'
let info = 'Are you sure you wish to delete the node:'
let minimal = 'Delete?'
2019-02-25 07:01:12 +08:00
2019-12-31 14:29:58 +08:00
elseif a :action = = # 'deleteNonEmpty'
2019-12-31 13:50:25 +08:00
let title = 'Delete the current node'
2019-02-25 07:01:12 +08:00
let info = "STOP! Directory is not empty! To delete, type 'yes'"
2019-12-31 13:50:25 +08:00
let minimal = 'Delete directory?'
2019-02-25 07:01:12 +08:00
2019-12-31 14:29:58 +08:00
elseif a :action = = # 'move'
2019-12-31 13:50:25 +08:00
let title = 'Rename the current node'
let info = 'Enter the new path for the node:'
let minimal = 'Move to:'
2019-02-25 07:01:12 +08:00
endif
if g :NERDTreeMenuController .isMinimal ( )
2019-07-15 03:17:56 +08:00
redraw ! " Clear the menu
2019-12-31 13:50:25 +08:00
return minimal . ' '
2019-02-25 07:01:12 +08:00
else
2019-12-31 13:50:25 +08:00
let divider = '=========================================================='
2019-02-25 07:01:12 +08:00
return title . "\n" . divider . "\n" . info . "\n"
end
endfunction
2009-07-19 13:21:57 +08:00
"FUNCTION: s:promptToDelBuffer(bufnum, msg){{{1
"prints out the given msg and, if the user responds by pushing 'y' then the
"buffer with the given bufnum is deleted
"
"Args:
"bufnum: the buffer that may be deleted
"msg: a message that will be echoed to the user asking them if they wish to
" del the buffer
function ! s :promptToDelBuffer ( bufnum , msg )
echo a :msg
2012-08-26 16:51:26 +08:00
if g :NERDTreeAutoDeleteBuffer | | nr2char ( getchar ( ) ) = = # 'y'
2012-08-26 21:19:52 +08:00
" 1. ensure that all windows which display the just deleted filename
" now display an empty buffer (so a layout is preserved).
" Is not it better to close single tabs with this file only ?
let s :originalTabNumber = tabpagenr ( )
let s :originalWindowNumber = winnr ( )
2017-11-02 20:26:48 +08:00
" Go to the next buffer in buffer list if at least one extra buffer is listed
" Otherwise open a new empty buffer
if v :version > = 800
let l :listedBufferCount = len ( getbufinfo ( {'buflisted' :1 }) )
elseif v :version > = 702
let l :listedBufferCount = len ( filter ( range ( 1 , bufnr ( '$' ) ) , 'buflisted(v:val)' ) )
else
" Ignore buffer count in this case to make sure we keep the old
" behavior
let l :listedBufferCount = 0
endif
if l :listedBufferCount > 1
2019-12-31 14:29:58 +08:00
call nerdtree #exec ( 'tabdo windo if winbufnr(0) ==# ' . a :bufnum . " | exec ':bnext! ' | endif" , 1 )
2017-11-02 20:26:48 +08:00
else
2019-12-31 14:29:58 +08:00
call nerdtree #exec ( 'tabdo windo if winbufnr(0) ==# ' . a :bufnum . " | exec ':enew! ' | endif" , 1 )
2017-11-02 20:26:48 +08:00
endif
2019-12-31 13:50:25 +08:00
call nerdtree #exec ( 'tabnext ' . s :originalTabNumber , 1 )
call nerdtree #exec ( s :originalWindowNumber . 'wincmd w' , 1 )
2012-08-26 21:19:52 +08:00
" 3. We don't need a previous buffer anymore
2019-12-31 13:50:25 +08:00
call nerdtree #exec ( 'bwipeout! ' . a :bufnum , 0 )
2009-07-19 13:21:57 +08:00
endif
endfunction
2018-10-25 10:20:59 +08:00
"FUNCTION: s:renameBuffer(bufNum, newNodeName, isDirectory){{{1
"The buffer with the given bufNum is replaced with a new one
2012-08-26 21:19:52 +08:00
"
"Args:
2018-10-25 10:20:59 +08:00
"bufNum: the buffer that may be deleted
"newNodeName: the name given to the renamed node
"isDirectory: determines how to do the create the new filenames
function ! s :renameBuffer ( bufNum , newNodeName , isDirectory )
if a :isDirectory
let quotedFileName = fnameescape ( a :newNodeName . '/' . fnamemodify ( bufname ( a :bufNum ) , ':t' ) )
let editStr = g :NERDTreePath .New ( a :newNodeName . '/' . fnamemodify ( bufname ( a :bufNum ) , ':t' ) ) .str ( {'format' : 'Edit' })
else
let quotedFileName = fnameescape ( a :newNodeName )
let editStr = g :NERDTreePath .New ( a :newNodeName ) .str ( {'format' : 'Edit' })
2009-07-19 13:21:57 +08:00
endif
2018-10-25 10:20:59 +08:00
let s :originalTabNumber = tabpagenr ( )
let s :originalWindowNumber = winnr ( )
2023-10-22 20:17:01 +08:00
let l :tempBufferName = 'NERDTreeRenameTempBuffer'
" 1. swap deleted file buffer with a temporary one
" this step is needed to compensate for case insensitive filesystems
" 1.1. create an intermediate(temporary) buffer
call nerdtree #exec ( 'badd ' . l :tempBufferName , 0 )
let l :tempBufNum = bufnr ( l :tempBufferName )
" 1.2. ensure that all windows which display the just deleted filename
" display the new temp buffer.
call nerdtree #exec ( 'tabdo windo if winbufnr(0) ==# ' . a :bufNum . " | exec ':e! " . l :tempBufferName . "' | endif" , 0 )
" 1.3. We don't need the deleted file buffer anymore
try
call nerdtree #exec ( 'confirm bwipeout ' . a :bufNum , 0 )
catch
" This happens when answering Cancel if confirmation is needed. Do nothing.
endtry
" 2. swap temporary buffer with the new filename buffer
" 2.1. create the actual new file buffer
call nerdtree #exec ( 'badd ' . quotedFileName , 0 )
" 2.2. ensure that all windows which display the temporary buffer
" display a buffer for the new filename.
call nerdtree #exec ( 'tabdo windo if winbufnr(0) ==# ' . l :tempBufNum . " | exec ':e! " . editStr . "' | endif" , 0 )
2019-12-31 13:50:25 +08:00
call nerdtree #exec ( 'tabnext ' . s :originalTabNumber , 1 )
call nerdtree #exec ( s :originalWindowNumber . 'wincmd w' , 1 )
2023-10-22 20:17:01 +08:00
" 2.3. We don't need the temporary buffer anymore
2019-02-15 06:44:31 +08:00
try
2023-10-22 20:17:01 +08:00
call nerdtree #exec ( 'confirm bwipeout ' . l :tempBufNum , 0 )
2019-02-15 06:44:31 +08:00
catch
" This happens when answering Cancel if confirmation is needed. Do nothing.
endtry
2009-07-19 13:21:57 +08:00
endfunction
2019-02-25 07:01:12 +08:00
2009-07-19 13:34:28 +08:00
"FUNCTION: NERDTreeAddNode(){{{1
function ! NERDTreeAddNode ( )
2009-07-19 13:21:57 +08:00
let curDirNode = g :NERDTreeDirNode .GetSelected ( )
2019-12-31 13:50:25 +08:00
let prompt = s :inputPrompt ( 'add' )
2021-09-15 10:34:57 +08:00
let newNodeName = substitute ( input ( prompt , curDirNode .path .str ( ) . nerdtree #slash ( ) , 'file' ) , '\(^\s*\|\s*$\)' , '' , 'g' )
2009-07-19 13:21:57 +08:00
if newNodeName = = # ''
2019-12-31 13:50:25 +08:00
call nerdtree #echo ( 'Node Creation Aborted.' )
2009-07-19 13:21:57 +08:00
return
endif
try
let newPath = g :NERDTreePath .Create ( newNodeName )
2015-11-16 19:28:24 +08:00
let parentNode = b :NERDTree .root .findNode ( newPath .getParent ( ) )
2009-07-19 13:21:57 +08:00
2015-11-20 09:44:12 +08:00
let newTreeNode = g :NERDTreeFileNode .New ( newPath , b :NERDTree )
2018-10-19 04:13:15 +08:00
" Emptying g:NERDTreeOldSortOrder forces the sort to
" recalculate the cached sortKey so nodes sort correctly.
let g :NERDTreeOldSortOrder = []
2013-10-08 12:25:27 +08:00
if empty ( parentNode )
2015-11-16 19:28:24 +08:00
call b :NERDTree .root .refresh ( )
2014-07-08 05:59:28 +08:00
call b :NERDTree .render ( )
2013-10-08 12:25:27 +08:00
elseif parentNode .isOpen | | ! empty ( parentNode .children )
2009-07-19 13:21:57 +08:00
call parentNode .addChild ( newTreeNode , 1 )
call NERDTreeRender ( )
call newTreeNode .putCursorHere ( 1 , 0 )
endif
2019-02-25 07:01:12 +08:00
2019-07-15 03:17:56 +08:00
redraw !
2009-07-19 13:21:57 +08:00
catch /^NERDTree/
2019-12-31 13:50:25 +08:00
call nerdtree #echoWarning ( 'Node Not Created.' )
2009-07-19 13:21:57 +08:00
endtry
endfunction
2009-07-19 13:34:28 +08:00
"FUNCTION: NERDTreeMoveNode(){{{1
function ! NERDTreeMoveNode ( )
2009-07-19 13:21:57 +08:00
let curNode = g :NERDTreeFileNode .GetSelected ( )
2019-12-31 13:50:25 +08:00
let prompt = s :inputPrompt ( 'move' )
let newNodePath = input ( prompt , curNode .path .str ( ) , 'file' )
2020-01-16 08:51:39 +08:00
while filereadable ( newNodePath )
2023-10-22 20:17:01 +08:00
" allow renames with different casing when g:NERDTreeCaseSensitiveFS
" is set to either 0 or 3 and the 2 paths are equal
if ( g :NERDTreeCaseSensitiveFS = = 0 | | g :NERDTreeCaseSensitiveFS = = 3 ) &&
\nerdtree #pathEquals ( curNode .path .str ( ) , newNodePath )
break
endif
call nerdtree #echoWarning ( 'This destination already exists, Try again.' )
" inform the user about the flag if we think it is a false positive
" when g:NERDTreeCaseSensitiveFS is set to 2
if g :NERDTreeCaseSensitiveFS = = 2 &&
\! nerdtree #osDefaultCaseSensitiveFS ( ) &&
\nerdtree #pathEquals ( curNode .path .str ( ) , newNodePath )
echon "\n(If it is a false positive please consider assigning NERDTreeCaseSensitiveFS's value)"
endif
" prompt the user again
2021-09-15 10:34:57 +08:00
let newNodePath = substitute ( input ( prompt , curNode .path .str ( ) , 'file' ) , '\(^\s*\|\s*$\)' , '' , 'g' )
2020-01-16 08:51:39 +08:00
endwhile
2009-07-19 13:21:57 +08:00
if newNodePath = = # ''
2019-12-31 13:50:25 +08:00
call nerdtree #echo ( 'Node Renaming Aborted.' )
2009-07-19 13:21:57 +08:00
return
endif
try
2018-10-25 10:20:59 +08:00
if curNode .path .isDirectory
2020-03-25 03:08:06 +08:00
let l :curPath = escape ( curNode .path .str ( ) , '\' ) . ( nerdtree #runningWindows ( ) ?'\\' :'/' ) . '.*'
let l :openBuffers = filter ( range ( 1 , bufnr ( '$' ) ) , 'bufexists(v:val) && fnamemodify(bufname(v:val),":p") =~# "' .escape ( l :curPath , '\' ) .'"' )
2018-10-25 10:20:59 +08:00
else
2019-12-31 13:50:25 +08:00
let l :openBuffers = filter ( range ( 1 , bufnr ( '$' ) ) , 'bufexists(v:val) && fnamemodify(bufname(v:val),":p") ==# curNode.path.str()' )
2018-10-25 10:20:59 +08:00
endif
2009-07-19 13:21:57 +08:00
call curNode .rename ( newNodePath )
2018-10-19 04:13:15 +08:00
" Emptying g:NERDTreeOldSortOrder forces the sort to
" recalculate the cached sortKey so nodes sort correctly.
let g :NERDTreeOldSortOrder = []
2018-05-17 01:09:20 +08:00
call b :NERDTree .root .refresh ( )
2009-07-19 13:21:57 +08:00
call NERDTreeRender ( )
2018-10-25 10:20:59 +08:00
" If the file node is open, or files under the directory node are
" open, ask the user if they want to replace the file(s) with the
" renamed files.
if ! empty ( l :openBuffers )
if curNode .path .isDirectory
2019-12-31 13:50:25 +08:00
echo "\nDirectory renamed.\n\nFiles with the old directory name are open in buffers " . join ( l :openBuffers , ', ' ) . '. Replace these buffers with the new files? (yN)'
2018-10-25 10:20:59 +08:00
else
2019-12-31 13:50:25 +08:00
echo "\nFile renamed.\n\nThe old file is open in buffer " . l :openBuffers [0 ] . '. Replace this buffer with the new file? (yN)'
2018-10-25 10:20:59 +08:00
endif
if g :NERDTreeAutoDeleteBuffer | | nr2char ( getchar ( ) ) = = # 'y'
for bufNum in l :openBuffers
call s :renameBuffer ( bufNum , newNodePath , curNode .path .isDirectory )
endfor
endif
2009-07-19 13:21:57 +08:00
endif
call curNode .putCursorHere ( 1 , 0 )
2019-07-15 03:17:56 +08:00
redraw !
2009-07-19 13:21:57 +08:00
catch /^NERDTree/
2019-12-31 13:50:25 +08:00
call nerdtree #echoWarning ( 'Node Not Renamed.' )
2009-07-19 13:21:57 +08:00
endtry
endfunction
2009-07-19 13:34:28 +08:00
" FUNCTION: NERDTreeDeleteNode() {{{1
function ! NERDTreeDeleteNode ( )
2009-07-19 13:21:57 +08:00
let currentNode = g :NERDTreeFileNode .GetSelected ( )
let confirmed = 0
2018-04-02 21:26:34 +08:00
if currentNode .path .isDirectory && ( ( currentNode .isOpen && currentNode .getChildCount ( ) > 0 ) | |
\ ( len ( currentNode ._glob ( '*' , 1 ) ) > 0 ) )
2019-12-31 13:50:25 +08:00
let prompt = s :inputPrompt ( 'deleteNonEmpty' ) . currentNode .path .str ( ) . ': '
2019-02-25 07:01:12 +08:00
let choice = input ( prompt )
2009-07-19 13:21:57 +08:00
let confirmed = choice = = # 'yes'
else
2019-12-31 13:50:25 +08:00
let prompt = s :inputPrompt ( 'delete' ) . currentNode .path .str ( ) . ' (yN): '
2019-02-25 07:01:12 +08:00
echo prompt
2009-07-19 13:21:57 +08:00
let choice = nr2char ( getchar ( ) )
let confirmed = choice = = # 'y'
endif
if confirmed
try
call currentNode .delete ( )
call NERDTreeRender ( )
"if the node is open in a buffer, ask the user if they want to
"close that buffer
2019-12-31 13:50:25 +08:00
let bufnum = bufnr ( '^' .currentNode .path .str ( ) .'$' )
2009-07-19 13:21:57 +08:00
if buflisted ( bufnum )
2019-12-31 13:50:25 +08:00
let prompt = "\nNode deleted.\n\nThe file is open in buffer " . bufnum . ( bufwinnr ( bufnum ) = = # -1 ? ' (hidden)' : '' ) .'. Delete this buffer? (yN)'
2009-07-19 13:21:57 +08:00
call s :promptToDelBuffer ( bufnum , prompt )
endif
2019-07-15 03:17:56 +08:00
redraw !
2009-07-19 13:21:57 +08:00
catch /^NERDTree/
2019-12-31 13:50:25 +08:00
call nerdtree #echoWarning ( 'Could not remove node' )
2009-07-19 13:21:57 +08:00
endtry
else
2019-12-31 13:50:25 +08:00
call nerdtree #echo ( 'delete aborted' )
2009-07-19 13:21:57 +08:00
endif
endfunction
2015-11-13 18:44:27 +08:00
" FUNCTION: NERDTreeListNode() {{{1
function ! NERDTreeListNode ( )
let treenode = g :NERDTreeFileNode .GetSelected ( )
2017-11-02 20:36:07 +08:00
if ! empty ( treenode )
2019-12-31 13:50:25 +08:00
let s :uname = system ( 'uname' )
2018-10-11 10:19:18 +08:00
let stat_cmd = 'stat -c "%s" '
2019-12-31 13:50:25 +08:00
if s :uname = ~ ? 'Darwin'
2018-06-16 00:02:58 +08:00
let stat_cmd = 'stat -f "%z" '
2017-11-02 20:36:07 +08:00
endif
let cmd = 'size=$(' . stat_cmd . shellescape ( treenode .path .str ( ) ) . ') && ' .
\ 'size_with_commas=$(echo $size | sed -e :a -e "s/\(.*[0-9]\)\([0-9]\{3\}\)/\1,\2/;ta") && ' .
\ 'ls -ld ' . shellescape ( treenode .path .str ( ) ) . ' | sed -e "s/ $size / $size_with_commas /"'
let metadata = split ( system ( cmd ) , '\n' )
2015-11-13 18:53:42 +08:00
call nerdtree #echo ( metadata [0 ])
2015-11-13 18:44:27 +08:00
else
2019-12-31 13:50:25 +08:00
call nerdtree #echo ( 'No information available' )
2015-11-13 18:44:27 +08:00
endif
endfunction
2015-11-13 05:20:20 +08:00
" FUNCTION: NERDTreeListNodeWin32() {{{1
2015-11-13 10:29:34 +08:00
function ! NERDTreeListNodeWin32 ( )
2017-08-19 20:58:57 +08:00
let l :node = g :NERDTreeFileNode .GetSelected ( )
if ! empty ( l :node )
2018-10-11 10:19:18 +08:00
let l :path = l :node .path .str ( )
2019-12-31 13:50:25 +08:00
call nerdtree #echo ( printf ( '%s:%s MOD:%s BYTES:%d PERMISSIONS:%s' ,
2018-10-11 10:19:18 +08:00
\ toupper ( getftype ( l :path ) ) ,
\ fnamemodify ( l :path , ':t' ) ,
2019-12-31 13:50:25 +08:00
\ strftime ( '%c' , getftime ( l :path ) ) ,
2018-10-11 10:19:18 +08:00
\ getfsize ( l :path ) ,
\ getfperm ( l :path ) ) )
2017-08-19 20:58:57 +08:00
return
2015-11-13 10:29:34 +08:00
endif
2017-08-19 20:58:57 +08:00
call nerdtree #echo ( 'node not recognized' )
2014-09-15 23:14:44 +08:00
endfunction
2023-10-19 20:33:38 +08:00
" FUNCTION: NERDTreeChangePermissions() {{{1
function ! NERDTreeChangePermissions ( )
let l :node = g :NERDTreeFileNode .GetSelected ( )
2023-10-25 03:43:24 +08:00
let l :prompt = "change node permissions (chmod args): "
2023-10-19 20:33:38 +08:00
let l :newNodePerm = input ( l :prompt )
if ! empty ( l :node )
let l :path = l :node .path .str ( )
let l :cmd = 'chmod ' .. newNodePerm .. ' ' .. path
let l :error = split ( system ( l :cmd ) , '\n' )
if ! empty ( l :error )
call nerdtree #echo ( l :error [0 ])
endif
call b :NERDTree .root .refresh ( )
call b :NERDTree .render ( )
return
endif
call nerdtree #echo ( 'node not recognized' )
endfunction
2009-07-19 13:34:28 +08:00
" FUNCTION: NERDTreeCopyNode() {{{1
function ! NERDTreeCopyNode ( )
2009-07-19 13:21:57 +08:00
let currentNode = g :NERDTreeFileNode .GetSelected ( )
2019-12-31 13:50:25 +08:00
let prompt = s :inputPrompt ( 'copy' )
2021-09-15 10:34:57 +08:00
let newNodePath = substitute ( input ( prompt , currentNode .path .str ( ) , 'file' ) , '\(^\s*\|\s*$\)' , '' , 'g' )
2009-07-19 13:21:57 +08:00
2019-12-31 14:29:58 +08:00
if newNodePath ! = # ''
2009-07-19 13:21:57 +08:00
"strip trailing slash
let newNodePath = substitute ( newNodePath , '\/$' , '' , '' )
let confirmed = 1
if currentNode .path .copyingWillOverwrite ( newNodePath )
2019-12-31 13:50:25 +08:00
call nerdtree #echo ( 'Warning: copying may overwrite files! Continue? (yN)' )
2009-07-19 13:21:57 +08:00
let choice = nr2char ( getchar ( ) )
let confirmed = choice = = # 'y'
endif
if confirmed
try
let newNode = currentNode .copy ( newNodePath )
2018-10-19 04:13:15 +08:00
" Emptying g:NERDTreeOldSortOrder forces the sort to
" recalculate the cached sortKey so nodes sort correctly.
let g :NERDTreeOldSortOrder = []
2013-10-08 12:25:27 +08:00
if empty ( newNode )
2015-11-16 19:28:24 +08:00
call b :NERDTree .root .refresh ( )
2014-07-08 05:59:28 +08:00
call b :NERDTree .render ( )
2013-10-08 12:25:27 +08:00
else
2011-07-09 14:44:03 +08:00
call NERDTreeRender ( )
call newNode .putCursorHere ( 0 , 0 )
endif
2009-07-19 13:21:57 +08:00
catch /^NERDTree/
2019-12-31 13:50:25 +08:00
call nerdtree #echoWarning ( 'Could not copy node' )
2009-07-19 13:21:57 +08:00
endtry
endif
else
2019-12-31 13:50:25 +08:00
call nerdtree #echo ( 'Copy aborted.' )
2009-07-19 13:21:57 +08:00
endif
2019-07-15 03:17:56 +08:00
redraw !
2009-07-19 13:21:57 +08:00
endfunction
2019-06-13 21:17:19 +08:00
" FUNCTION: NERDTreeCopyPath() {{{1
function ! NERDTreeCopyPath ( )
let l :nodePath = g :NERDTreeFileNode .GetSelected ( ) .path .str ( )
2019-12-31 13:50:25 +08:00
if has ( 'clipboard' )
2019-12-31 14:29:58 +08:00
if &clipboard = = # 'unnamedplus'
2019-11-13 21:58:42 +08:00
let @+ = l :nodePath
else
let @* = l :nodePath
endif
2019-12-31 13:50:25 +08:00
call nerdtree #echo ( 'The path [' . l :nodePath . '] was copied to your clipboard.' )
2019-06-13 21:17:19 +08:00
else
2019-12-31 13:50:25 +08:00
call nerdtree #echo ( 'The full path is: ' . l :nodePath )
2019-06-13 21:17:19 +08:00
endif
endfunction
2015-11-13 10:29:34 +08:00
" FUNCTION: NERDTreeQuickLook() {{{1
2011-09-07 08:01:57 +08:00
function ! NERDTreeQuickLook ( )
2020-04-10 09:37:55 +08:00
let l :node = g :NERDTreeFileNode .GetSelected ( )
if empty ( l :node )
return
2011-09-07 08:01:57 +08:00
endif
2020-04-10 09:37:55 +08:00
call system ( 'qlmanage -p 2>/dev/null ' . shellescape ( l :node .path .str ( ) ) )
2011-09-07 08:01:57 +08:00
endfunction
2015-11-13 10:29:34 +08:00
" FUNCTION: NERDTreeRevealInFinder() {{{1
2011-09-07 08:01:57 +08:00
function ! NERDTreeRevealInFinder ( )
2020-04-10 09:37:55 +08:00
let l :node = g :NERDTreeFileNode .GetSelected ( )
if empty ( l :node )
return
2011-09-07 08:01:57 +08:00
endif
2020-04-10 09:37:55 +08:00
call system ( 'open -R ' . shellescape ( l :node .path .str ( ) ) )
2011-09-07 08:01:57 +08:00
endfunction
2015-11-13 10:29:34 +08:00
" FUNCTION: NERDTreeExecuteFile() {{{1
2011-09-07 08:01:57 +08:00
function ! NERDTreeExecuteFile ( )
2020-04-10 09:37:55 +08:00
let l :node = g :NERDTreeFileNode .GetSelected ( )
if empty ( l :node )
return
2011-09-07 08:01:57 +08:00
endif
2020-04-10 09:37:55 +08:00
call system ( 'open ' . shellescape ( l :node .path .str ( ) ) )
2011-09-07 08:01:57 +08:00
endfunction
2017-12-17 21:42:49 +08:00
2018-04-10 01:08:09 +08:00
" FUNCTION: NERDTreeRevealFileLinux() {{{1
function ! NERDTreeRevealFileLinux ( )
2020-04-10 09:37:55 +08:00
let l :node = g :NERDTreeFileNode .GetSelected ( )
if empty ( l :node )
return
endif
" Handle the edge case of "/", which has no parent.
if l :node .path .str ( ) = = # '/'
call system ( 'xdg-open /' )
return
endif
if empty ( l :node .parent )
return
2018-04-10 01:08:09 +08:00
endif
2020-04-10 09:37:55 +08:00
call system ( 'xdg-open ' . shellescape ( l :node .parent .path .str ( ) ) )
2018-04-10 01:08:09 +08:00
endfunction
" FUNCTION: NERDTreeExecuteFileLinux() {{{1
function ! NERDTreeExecuteFileLinux ( )
2020-04-10 09:37:55 +08:00
let l :node = g :NERDTreeFileNode .GetSelected ( )
if empty ( l :node )
return
2018-04-10 01:08:09 +08:00
endif
2020-04-10 09:37:55 +08:00
call system ( 'xdg-open ' . shellescape ( l :node .path .str ( ) ) )
2018-04-10 01:08:09 +08:00
endfunction
2023-10-23 23:36:13 +08:00
" FUNCTION: NERDTreeRevealInExplorer() {{{1
function ! NERDTreeRevealInExplorer ( )
let l :node = g :NERDTreeFileNode .GetSelected ( )
if empty ( l :node )
return
endif
call system ( 'cmd.exe /c explorer /select, ' . shellescape ( l :node .path .str ( ) ) )
endfunction
2020-05-22 20:57:19 +08:00
" FUNCTION: NERDTreeExecuteFileWindows() {{{1
function ! NERDTreeExecuteFileWindows ( )
let l :node = g :NERDTreeFileNode .GetSelected ( )
if empty ( l :node )
return
endif
call system ( 'cmd.exe /c start "" ' . shellescape ( l :node .path .str ( ) ) )
endfunction
2021-01-31 12:45:56 +08:00
" 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
2009-07-19 13:21:57 +08:00
" vim: set sw=4 sts=4 et fdm=marker: