aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJack Nagel2012-03-23 22:42:43 -0500
committerJack Nagel2012-03-23 22:42:43 -0500
commit53481dc14a2d49d590db125b26b77750cb14f048 (patch)
tree52f55030a09137423609d4580a1eff769e229387
parent8c4e7ca5b57a60e1ba002a0e949b920a6583c9aa (diff)
downloadbrew-53481dc14a2d49d590db125b26b77750cb14f048.tar.bz2
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>
-rw-r--r--Library/Contributions/brew_bash_completion.sh35
1 files changed, 33 insertions, 2 deletions
diff --git a/Library/Contributions/brew_bash_completion.sh b/Library/Contributions/brew_bash_completion.sh
index a9a689ae6..7faaf9e93 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 ;;