From 53481dc14a2d49d590db125b26b77750cb14f048 Mon Sep 17 00:00:00 2001 From: Jack Nagel Date: Fri, 23 Mar 2012 22:42:43 -0500 Subject: [PATCH] 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 --- Library/Contributions/brew_bash_completion.sh | 35 +++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/Library/Contributions/brew_bash_completion.sh b/Library/Contributions/brew_bash_completion.sh index a9a689ae6d..7faaf9e936 100644 --- a/Library/Contributions/brew_bash_completion.sh +++ b/Library/Contributions/brew_bash_completion.sh @@ -107,11 +107,41 @@ __brew_complete_outdated () COMPREPLY=($(compgen -W "$od" -- "$cur")) } -__brew_complete_taps () +__brew_complete_tapped () { __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 () { local cur="${COMP_WORDS[COMP_CWORD]}" @@ -431,8 +461,9 @@ _brew () options) _brew_options ;; outdated) _brew_outdated ;; search|-S) _brew_search ;; + tap) __brew_complete_taps ;; uninstall|remove|rm) _brew_uninstall ;; - untap) __brew_complete_taps ;; + untap) __brew_complete_tapped ;; update) _brew_update ;; uses) _brew_uses ;; versions) _brew_versions ;;