Tab completion for brew tap
Using an inline Ruby script we can hit the GitHub API and look for repositories that match the tap naming scheme. The results are cached for the duration of the current shell session, so going over the network is a once-per-shell-session cost. There are a few false positives, but not much we can do about that at this point, as taps do not have to be in the fork network of any specific repository. Signed-off-by: Jack Nagel <jacknagel@gmail.com>
This commit is contained in:
parent
8c4e7ca5b5
commit
53481dc14a
@ -107,11 +107,41 @@ __brew_complete_outdated ()
|
|||||||
COMPREPLY=($(compgen -W "$od" -- "$cur"))
|
COMPREPLY=($(compgen -W "$od" -- "$cur"))
|
||||||
}
|
}
|
||||||
|
|
||||||
__brew_complete_taps ()
|
__brew_complete_tapped ()
|
||||||
{
|
{
|
||||||
__brewcomp "$(\ls $(brew --repository)/Library/Taps 2>/dev/null | sed 's/-/\//g')"
|
__brewcomp "$(\ls $(brew --repository)/Library/Taps 2>/dev/null | sed 's/-/\//g')"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
__brew_complete_taps ()
|
||||||
|
{
|
||||||
|
if [[ -z "$__brew_cached_taps" ]]; then
|
||||||
|
__brew_cached_taps="$(/usr/bin/ruby -e '
|
||||||
|
require "open-uri"
|
||||||
|
require "yaml"
|
||||||
|
|
||||||
|
begin
|
||||||
|
uri = URI.parse("http://github.com/api/v2/yaml/repos/search/homebrew")
|
||||||
|
|
||||||
|
open uri do |f|
|
||||||
|
YAML::load(f.read)["repositories"].each do |repo|
|
||||||
|
if repo[:name] =~ /^homebrew-(\w+)$/
|
||||||
|
puts tap = if repo[:username] == "Homebrew"
|
||||||
|
"homebrew/#{$1}"
|
||||||
|
else
|
||||||
|
repo[:username]+"/"+$1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
rescue
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
' 2>/dev/null)"
|
||||||
|
fi
|
||||||
|
|
||||||
|
__brewcomp "$__brew_cached_taps"
|
||||||
|
}
|
||||||
|
|
||||||
_brew_cleanup ()
|
_brew_cleanup ()
|
||||||
{
|
{
|
||||||
local cur="${COMP_WORDS[COMP_CWORD]}"
|
local cur="${COMP_WORDS[COMP_CWORD]}"
|
||||||
@ -431,8 +461,9 @@ _brew ()
|
|||||||
options) _brew_options ;;
|
options) _brew_options ;;
|
||||||
outdated) _brew_outdated ;;
|
outdated) _brew_outdated ;;
|
||||||
search|-S) _brew_search ;;
|
search|-S) _brew_search ;;
|
||||||
|
tap) __brew_complete_taps ;;
|
||||||
uninstall|remove|rm) _brew_uninstall ;;
|
uninstall|remove|rm) _brew_uninstall ;;
|
||||||
untap) __brew_complete_taps ;;
|
untap) __brew_complete_tapped ;;
|
||||||
update) _brew_update ;;
|
update) _brew_update ;;
|
||||||
uses) _brew_uses ;;
|
uses) _brew_uses ;;
|
||||||
versions) _brew_versions ;;
|
versions) _brew_versions ;;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user