From 97433edd43f3a4a95c84389bcaafbe7a047cf756 Mon Sep 17 00:00:00 2001 From: Phil Runninger Date: Thu, 2 Nov 2017 08:36:07 -0400 Subject: [PATCH] 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. --- nerdtree_plugin/fs_menu.vim | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/nerdtree_plugin/fs_menu.vim b/nerdtree_plugin/fs_menu.vim index e48bd81..3bb11db 100644 --- a/nerdtree_plugin/fs_menu.vim +++ b/nerdtree_plugin/fs_menu.vim @@ -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