From 37e8c5cfb76d35d66fafd0c85bcf3b5d9735dd13 Mon Sep 17 00:00:00 2001 From: Jack Nagel Date: Fri, 23 Mar 2012 22:42:43 -0500 Subject: 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(-) (limited to 'Library') 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 ;; -- cgit v1.2.3