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
Update fish completions #15174
Update fish completions #15174
Conversation
3a0716b
to
0c22938
Compare
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.
This generally seems to be the approach taken with the Bash completions so seems like the right approach. It'd be nice to have some benchmarks though.
Lines 54 to 66 in c516870
__brew_complete_installed_formulae() { | |
local cur="${COMP_WORDS[COMP_CWORD]}" | |
local installed_formulae | |
installed_formulae="$(command ls "${HOMEBREW_CELLAR:-$(brew --cellar)}" 2>/dev/null)" | |
while read -r line; do COMPREPLY+=("${line}"); done < <(compgen -W "${installed_formulae}" -- "${cur}") | |
} | |
__brew_complete_installed_casks() { | |
local cur="${COMP_WORDS[COMP_CWORD]}" | |
local installed_casks | |
installed_casks="$(command ls "$(brew --caskroom)" 2>/dev/null)" | |
while read -r line; do COMPREPLY+=("${line}"); done < <(compgen -W "${installed_casks}" -- "${cur}") | |
} |
else if test -n "$HOMEBREW_NO_INSTALL_FROM_API" | ||
command ls -1 (brew --prefix)/Library/Taps/homebrew/homebrew-core | ||
else if test -f "$__brew_cache_path/api/formula_names.txt" | ||
command cat $__brew_cache_path/api/formula_names.txt | ||
else | ||
# fallback on brew formulae if homebrew-core is not tapped |
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.
Will this ignore non-core formulae after this change?
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 question.
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.
It would. brew formulae
is actually decently fast so no need for this.
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.
Great work so far!
else if test -n "$HOMEBREW_NO_INSTALL_FROM_API" | ||
command ls -1 (brew --prefix)/Library/Taps/homebrew/homebrew-core | ||
else if test -f "$__brew_cache_path/api/formula_names.txt" | ||
command cat $__brew_cache_path/api/formula_names.txt | ||
else | ||
# fallback on brew formulae if homebrew-core is not tapped |
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 question.
end | ||
|
||
function __fish_brew_suggest_formulae_installed | ||
brew list --formula | ||
command ls -1 (brew --cellar) |
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.
❯ hyperfine 'brew list --formula' 'command ls -1 (brew --cellar)' --shell fish
Benchmark 1: brew list --formula
Time (mean ± σ): 473.1 ms ± 26.9 ms [User: 248.4 ms, System: 107.8 ms]
Range (min … max): 443.6 ms … 542.5 ms 10 runs
Benchmark 2: command ls -1 (brew --cellar)
Time (mean ± σ): 10.0 ms ± 0.9 ms [User: 3.4 ms, System: 4.3 ms]
Range (min … max): 8.7 ms … 14.2 ms 112 runs
Summary
'command ls -1 (brew --cellar)' ran
47.16 ± 5.01 times faster than 'brew list --formula'
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.
@razvanazamfirei Is this a strategy that could be used in bash/zsh completions too? May want to split it out into a command like brew formulae
if so.
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'll have to check if it leads to any performance improvements since zsh
caches some completions.
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.
@razvanazamfirei Thanks! That could be a follow-up PR, doesn't need to block this one.
command find (brew --prefix)/Library/Taps -mindepth 2 -maxdepth 2 -type d \ | ||
| string replace homebrew- "" \ | ||
| string replace (brew --prefix)/Library/Taps/ "" |
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.
❯ hyperfine 'brew tap' 'command find (brew --prefix)/Library/Taps -mindepth 2 -maxdepth 2 -type d | string replace homebrew- "" | string replace (brew --prefix)/Library/Taps/ ""' --shell fish --warmup 1
Benchmark 1: brew tap
Time (mean ± σ): 455.4 ms ± 11.8 ms [User: 240.9 ms, System: 102.5 ms]
Range (min … max): 441.5 ms … 474.4 ms 10 runs
Benchmark 2: command find (brew --prefix)/Library/Taps -mindepth 2 -maxdepth 2 -type d | string replace homebrew- "" | string replace (brew --prefix)/Library/Taps/ ""
Time (mean ± σ): 18.7 ms ± 1.2 ms [User: 6.1 ms, System: 8.3 ms]
Range (min … max): 16.7 ms … 23.0 ms 94 runs
Summary
'command find (brew --prefix)/Library/Taps -mindepth 2 -maxdepth 2 -type d | string replace homebrew- "" | string replace (brew --prefix)/Library/Taps/ ""' ran
24.40 ± 1.72 times faster than 'brew tap'
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.
@razvanazamfirei Is this a strategy that could be used in bash/zsh completions too? May want to split it out into a command like brew formulae
if so.
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.
The path for the find command seems to be broken for me locally when I run brew tap c
and try to autocomplete.
/u/l/Homebrew (fish-completions|✔) $ brew tap cfind: /usr/local/Library/Taps: No such file or directory
find: /usr/local/Library/Taps: No such file or directory
find: /usr/local/Library/Taps: No such file or directory
find: /usr/local/Library/Taps: No such file or directory
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 think maybe you should use brew --repo
instead of brew --prefix
here.
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.
@apainintheneck, I made the change. Let me know if this fixes it and if you think I should add 2>/dev/null
to the find command.
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.
Yep, this fixed it. Thanks. I'm not sure if we need to redirect stderr to /dev/null right now. It shouldn't print to stderr at all right?
@@ -104,22 +104,14 @@ function __fish_brew_ruby_parse_json -a file parser -d 'Parses given JSON file w | |||
end |
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.
This function becomes redundant if changes below are made.
end | ||
|
||
function __fish_brew_suggest_formulae_installed | ||
brew list --formula | ||
command ls -1 (brew --cellar) |
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.
@razvanazamfirei Is this a strategy that could be used in bash/zsh completions too? May want to split it out into a command like brew formulae
if so.
command find (brew --prefix)/Library/Taps -mindepth 2 -maxdepth 2 -type d \ | ||
| string replace homebrew- "" \ | ||
| string replace (brew --prefix)/Library/Taps/ "" |
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.
@razvanazamfirei Is this a strategy that could be used in bash/zsh completions too? May want to split it out into a command like brew formulae
if so.
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.
Looking good so far. The installed formulas and casks complete much faster with these changes.
command find (brew --prefix)/Library/Taps -mindepth 2 -maxdepth 2 -type d \ | ||
| string replace homebrew- "" \ | ||
| string replace (brew --prefix)/Library/Taps/ "" |
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.
The path for the find command seems to be broken for me locally when I run brew tap c
and try to autocomplete.
/u/l/Homebrew (fish-completions|✔) $ brew tap cfind: /usr/local/Library/Taps: No such file or directory
find: /usr/local/Library/Taps: No such file or directory
find: /usr/local/Library/Taps: No such file or directory
find: /usr/local/Library/Taps: No such file or directory
command find (brew --prefix)/Library/Taps -mindepth 2 -maxdepth 2 -type d \ | ||
| string replace homebrew- "" \ | ||
| string replace (brew --prefix)/Library/Taps/ "" |
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 think maybe you should use brew --repo
instead of brew --prefix
here.
# store the brew cache path in a var (because calling (brew --cache) is slow) | ||
set -q __brew_cache_path | ||
or set -gx __brew_cache_path (brew --cache) | ||
|
||
if test -f "$__brew_cache_path/descriptions.json" | ||
__fish_brew_ruby_parse_json "$__brew_cache_path/descriptions.json" \ | ||
'.each{ |k, v| puts([k, v].reject(&:nil?).join("\t")) }' | ||
else | ||
brew formulae | ||
end | ||
brew formulae |
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.
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 think the descriptions came from $__brew_cache_path/descriptions.json
. I don't have that file locally and haven't been able to figure out where it gets generated from.
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.
Yeh, that file isn't generated by default. IMO the new behaviour makes more sense and the performance benefits are worth it.
798a85d
to
5080010
Compare
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.
Great work @razvanazamfirei!
# store the brew cache path in a var (because calling (brew --cache) is slow) | ||
set -q __brew_cache_path | ||
or set -gx __brew_cache_path (brew --cache) | ||
|
||
if test -f "$__brew_cache_path/descriptions.json" | ||
__fish_brew_ruby_parse_json "$__brew_cache_path/descriptions.json" \ | ||
'.each{ |k, v| puts([k, v].reject(&:nil?).join("\t")) }' | ||
else | ||
brew formulae | ||
end | ||
brew formulae |
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.
Yeh, that file isn't generated by default. IMO the new behaviour makes more sense and the performance benefits are worth it.
end | ||
|
||
function __fish_brew_suggest_formulae_installed | ||
brew list --formula | ||
command ls -1 (brew --cellar) |
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.
@razvanazamfirei Thanks! That could be a follow-up PR, doesn't need to block this one.
@@ -143,7 +130,7 @@ function __fish_brew_suggest_casks_all -d "Lists locally available casks" | |||
end | |||
|
|||
function __fish_brew_suggest_casks_installed -d "Lists installed casks" | |||
brew list --cask -1 | |||
command ls -1 (brew --caskroom) |
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.
Same deal here: in a future PR this would be nice to make a command implemented in Bash I think if it provides speedups to either Bash and/or ZSH.
@@ -153,7 +140,9 @@ function __fish_brew_suggest_casks_outdated -d "Lists outdated casks with the in | |||
end | |||
|
|||
function __fish_brew_suggest_taps_installed -d "List all available taps" | |||
brew tap | |||
command find (brew --repo)/Library/Taps -mindepth 2 -maxdepth 2 -type d \ |
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.
Same deal here: in a future PR this would be nice to make a command implemented in Bash I think if it provides speedups to either Bash and/or ZSH.
brew style
with your changes locally?brew typecheck
with your changes locally?brew tests
with your changes locally?Updating fish completions to remove expensive
brew list
calls