-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Display file size with commas as thousands separators. #754
Conversation
This change will display the file size in an easier to read format, and still display its exact value. It uses the stat command (with different switches and formats between Unix and OSX) to get the file size, sed to add the commas to it, and sed again to replace the original size with the modified number.
nerdtree_plugin/fs_menu.vim
Outdated
\ 'unset size && ' . | ||
\ 'unset size_with_commas' | ||
|
||
let metadata = split(system(cmd),'\n') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would use systemlist()
here.
nerdtree_plugin/fs_menu.vim
Outdated
@@ -203,10 +203,22 @@ endfunction | |||
function! NERDTreeListNode() | |||
let treenode = g:NERDTreeFileNode.GetSelected() | |||
if treenode != {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would use empty()
here.
call nerdtree#echo(metadata[0]) | ||
else | ||
call nerdtree#echo("No information avaialable") | ||
call nerdtree#echo("No information available") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch... I never noticed this!
nerdtree_plugin/fs_menu.vim
Outdated
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 /" && ' . | ||
\ 'unset size && ' . |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you need to unset size
and size_with_commas
here? Note that this command is run within a subshell.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope. Those are leftover from my tweaking the command line in the shell.
This looks somewhat brittle. I wish I had more to offer in terms of suggestions. Perhaps some alternative using a Vim builtin function like This doesn't change things for me since I rarely use this feature. However, I would try to work this into a plugin if I could. Your call. |
Yeah, I don't use this function much either. I'm just cleaning up an old PR that's gone stale. |
I think Martin considers this file and |
That's all okay! It's good to bundle these plugins, too. It gives users examples to follow. Can't test right now. Will do soon, though. |
* 'master' of https://github.com/scrooloose/nerdtree: (181 commits) Make the "o" mapping consistent with "x" Fix a problem with the "x" handler (preservim#768) Clean up the handler for the "x" mapping (preservim#767) Revert change to tab opening method (preservim#766) Add back support for "b:NERDTreeRoot" (preservim#765) Update the CHANGELOG Have new tabs open as the last tab (with '$') Add a note/warning to "TreeDirNode.activate()" Document "t" and "T" mappings in the quick help Silence messages when opening a file with "T" Fix handlers for "t" and "T" on bookmarks Explicitly call open() in "ui_glue.vim" callbacks Remove an unnecessary assignment Clean up the Creator.createTabTree() function Clean up the commentary in "creator.vim" Extract a common line to the top of a function Remove an unnecessary "else" clause Clean up the NERDTreeOpener constructor Merge pull request preservim#754 from branch comma-separated-file-size Merge pull request preservim#756 from mboughaba/master ...
This change will display the file size in an easier to read format, and
still display its exact value. It uses the stat command (with different
switches and formats between Unix and OSX) to get the file size, sed to
add the commas to it, and sed again to replace the original size with
the modified number.