git prompt: faster count of untracked files#3294
git prompt: faster count of untracked files#3294nomaed wants to merge 3 commits intofish-shell:masterfrom nomaed:master
Conversation
|
Test/demo: |
|
Minor nit: You can pipe to |
|
@faho Good point, done. |
| 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.
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.
@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.
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-filesresult as a string to count the number of lines by piping the result throughwc -ldirectly.