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
git prompt: faster count of untracked files #3294
Conversation
Test/demo:
|
Minor nit: You can pipe to |
@faho Good point, done. |
@@ -478,7 +478,7 @@ function __fish_git_prompt_informative_status | |||
set -l dirtystate (math (count $changedFiles) - (count (echo $changedFiles | grep "U"))) | |||
set -l invalidstate (count (echo $stagedFiles | grep "U")) | |||
set -l stagedstate (math (count $stagedFiles) - $invalidstate) | |||
set -l untrackedfiles (count (command git ls-files --others --exclude-standard)) | |||
set -l untrackedfiles (command git ls-files --others --exclude-standard | wc -l | string trim) |
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.
Why is | string trim
required? The wc -l
portion of that command will return a single line that the fish sub-command will turn into a single value since it strips (i.e., ignores) a trailing newline.
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.
@faho commented about it, so I made the change
#3294 (comment)
Edit: I thought at first that you were talking about why piping instead of using a string trim
with a sub-command. As @floam wrote, the reason is exactly that there are leading spaces that are saved and the string needs to be trimmed.
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.
Right. I forgot that there are brain-dead wc
implementations (e.g., the BSD one) that left-pad the value with spaces.
@krader1961 The spaces will not be ignored: > set -l foo (command git ls-files --others --exclude-standard | wc -l)
> echo $foo
102 |
Thanks. Merged as dc02587. |
In a repository with 18k untracked files (by accident, node_modules not in .gitignore), counting them using
count (git ls-files)
was causing a considerable lag with prompt generation.After changing it to
git ls-files | wc -l
, the count process is at least twice as fast. Not ideal, but it avoids caching the entiregit ls-files
result as a string to count the number of lines by piping the result throughwc -l
directly.