Skip to content
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

Merged
merged 4 commits into from
Nov 2, 2017

Conversation

PhilRunninger
Copy link
Member

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.

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.
\ 'unset size && ' .
\ 'unset size_with_commas'

let metadata = split(system(cmd),'\n')
Copy link
Contributor

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.

@@ -203,10 +203,22 @@ endfunction
function! NERDTreeListNode()
let treenode = g:NERDTreeFileNode.GetSelected()
if treenode != {}
Copy link
Contributor

@lifecrisis lifecrisis Oct 30, 2017

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")
Copy link
Contributor

@lifecrisis lifecrisis Oct 30, 2017

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!

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 && ' .
Copy link
Contributor

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.

Copy link
Member Author

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.

@lifecrisis
Copy link
Contributor

This looks somewhat brittle. I wish I had more to offer in terms of suggestions. Perhaps some alternative using a Vim builtin function like getfsize() is in order.

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.

@PhilRunninger
Copy link
Member Author

Yeah, I don't use this function much either. I'm just cleaning up an old PR that's gone stale.

@PhilRunninger
Copy link
Member Author

PhilRunninger commented Oct 31, 2017

I think Martin considers this file and exec_menuitem.vim to be plugins already - not necessarily part of the core NERDTree, but bundled with it. It's kinda like netrw is with respect to Vim.

@lifecrisis
Copy link
Contributor

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.

@lifecrisis lifecrisis merged commit 97433ed into master Nov 2, 2017
@lifecrisis lifecrisis deleted the comma-separated-file-size branch November 20, 2017 12:52
alexanderscott added a commit to alexanderscott/nerdtree that referenced this pull request Nov 21, 2017
* '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
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants