Skip to content

Commit

Permalink
Merge pull request #15174 from razvanazamfirei/fish-completions
Browse files Browse the repository at this point in the history
Update fish completions
  • Loading branch information
MikeMcQuaid committed Apr 12, 2023
2 parents 14ff148 + 5080010 commit 92d68e3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 36 deletions.
25 changes: 7 additions & 18 deletions Library/Homebrew/completions/fish.erb
Original file line number Diff line number Diff line change
Expand Up @@ -98,28 +98,15 @@ end
######################
# These functions return lists of suggestions for arguments completion

function __fish_brew_ruby_parse_json -a file parser -d 'Parses given JSON file with Ruby'
# parser is any chain of methods to call on the parsed JSON
ruby -e "require('json'); JSON.parse(File.read('$file'))$parser"
end

function __fish_brew_suggest_formulae_all -d 'Lists all available formulae with their descriptions'
# 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
end

function __fish_brew_suggest_formulae_installed
brew list --formula
command ls -1 (brew --cellar)
end


function __fish_brew_suggest_formulae_outdated -d "List of outdated formulae with the information about potential upgrade"
brew outdated --formula --verbose \
# replace first space with tab to make the following a description in the completions list:
Expand All @@ -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)
end

function __fish_brew_suggest_casks_outdated -d "Lists outdated casks with the information about potential upgrade"
Expand All @@ -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 \
| string replace homebrew- "" \
| string replace (brew --repo)/Library/Taps/ ""
end

function __fish_brew_suggest_commands -d "Lists all commands names, including aliases"
Expand Down
25 changes: 7 additions & 18 deletions completions/fish/brew.fish
Original file line number Diff line number Diff line change
Expand Up @@ -85,28 +85,15 @@ end
######################
# These functions return lists of suggestions for arguments completion

function __fish_brew_ruby_parse_json -a file parser -d 'Parses given JSON file with Ruby'
# parser is any chain of methods to call on the parsed JSON
ruby -e "require('json'); JSON.parse(File.read('$file'))$parser"
end

function __fish_brew_suggest_formulae_all -d 'Lists all available formulae with their descriptions'
# 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
end

function __fish_brew_suggest_formulae_installed
brew list --formula
command ls -1 (brew --cellar)
end


function __fish_brew_suggest_formulae_outdated -d "List of outdated formulae with the information about potential upgrade"
brew outdated --formula --verbose \
# replace first space with tab to make the following a description in the completions list:
Expand All @@ -130,7 +117,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)
end

function __fish_brew_suggest_casks_outdated -d "Lists outdated casks with the information about potential upgrade"
Expand All @@ -140,7 +127,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 \
| string replace homebrew- "" \
| string replace (brew --repo)/Library/Taps/ ""
end

function __fish_brew_suggest_commands -d "Lists all commands names, including aliases"
Expand Down

0 comments on commit 92d68e3

Please sign in to comment.