Merge pull request #754 from branch comma-separated-file-size

This change will display the file size (printed with the "ml"
command) in an easy-to-read format, while still displaying its
precise value.  It uses the "stat" command (with the correct
switches for Unix and OSX) to get the file size, "sed" to add the
commas, and "sed" again to replace the original size with the
modified number.
This commit is contained in:
Phil Runninger 2017-11-02 08:36:07 -04:00 committed by Jason Franklin
parent a8c6245057
commit 97433edd43

View File

@ -217,11 +217,21 @@ endfunction
" FUNCTION: NERDTreeListNode() {{{1
function! NERDTreeListNode()
let treenode = g:NERDTreeFileNode.GetSelected()
if treenode != {}
let metadata = split(system('ls -ld ' . shellescape(treenode.path.str())), '\n')
if !empty(treenode)
if has("osx")
let stat_cmd = 'stat -f "%z" '
else
let stat_cmd = 'stat -c "%s" '
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')
call nerdtree#echo(metadata[0])
else
call nerdtree#echo("No information avaialable")
call nerdtree#echo("No information available")
endif
endfunction