Created
March 26, 2015 09:10
-
-
Save alepore/10a8662905ca6442b36b to your computer and use it in GitHub Desktop.
better bundler completion
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! bash | |
# bash completion for the `bundle` command. | |
# | |
# Copyright (c) 2011-2013 Daniel Luz <dev at mernen dot com>. | |
# Distributed under the MIT license. | |
# http://mernen.com/projects/completion-ruby | |
# | |
# To use, source this file on bash: | |
# . completion-bundle | |
__bundle() { | |
local cur=$2 | |
local prev=$3 | |
local bundle_command | |
__bundle_get_command | |
COMPREPLY=() | |
local options | |
commands="install update package exec config check list show outdated | |
console open viz init gem platform clean" | |
common_opts="--no-color --verbose -V" | |
if [[ -z $bundle_command ]]; then | |
options="help --version --help $commands" | |
elif [[ -n $bundle_command ]]; then | |
case $bundle_command in | |
help) | |
options=$commands | |
;; | |
install) | |
options="$common_opts --gemfile --path --system --without --local | |
--deployment --binstubs --standalone --trust-policy --jobs | |
--retry --no-cache --quiet --clean --full-index --no-prune | |
--shebang" | |
;; | |
update) | |
# sed command may only work OSX | |
gems=$(bundle show | sed -E 's/(\*|\(.*\)|Gems included by the bundle:)//g') | |
options="$common_opts --source --local $gems" | |
;; | |
exec) | |
local bundle_path | |
local bundle_config_path=$(bundle config path) | |
local config_path=$(echo $bundle_config_path | egrep -e '\(([^)]*)\)' -o | tr -d '()') | |
local relative_bundle_path=$(echo $bundle_config_path | egrep -o -e '"[^"]*"' | tr -d '"') | |
# TODO: handle empty config path properly | |
if [[ -z config_path ]]; then | |
bundle_path="$GEM_HOME" | |
else | |
bundle_path="${config_path%/.bundle/config}/$relative_bundle_path" | |
fi | |
local bin_path="${bundle_path}/ruby/*/bin/" | |
if [[ $(test -d ${bin_path}) -eq 0 ]]; then | |
options=$(ls -1 $bin_path) | |
else | |
return 0 | |
fi | |
;; | |
config) | |
options="--global --local --delete path frozen without bin | |
ssl_ca_cert ssl_client_cert " | |
;; | |
check) | |
options="$common_opts --gemfile --path --dry-run --retry -r" | |
;; | |
show) | |
gems=$(bundle show | sed -E 's/(\*|\(.*\)|Gems included by the bundle:)//g') | |
options="$common_opts --paths --retry -r $gems" | |
;; | |
list) | |
options="$common_opts --paths --retry -r" | |
;; | |
outdated) | |
options="$common_opts --pre --source --local --strict --retry -r" | |
;; | |
console) | |
options="$common_opts --retry -r" | |
;; | |
open) | |
gems=$(bundle show | sed -E 's/(\*|\(.*\)|Gems included by the bundle:)//g') | |
options="$common_opts --retry -r $gems" | |
;; | |
viz) | |
options="$common_opts -f --file -v --version -r --requirements -F | |
--format -r --retry" | |
;; | |
init) | |
options="$common_opts --gemspec --retry -r" | |
;; | |
gem) | |
options="$common_opts -b --bin -t --test -e --edit --ext --retry -r" | |
;; | |
platform) | |
options="--ruby" | |
;; | |
clean) | |
options="$common_opts --dry-run --force --retry -r" | |
;; | |
esac | |
fi | |
COMPREPLY=($(compgen -W "$options" -- "$cur")) | |
} | |
__bundle_get_command() { | |
local i | |
for ((i=1; i < $COMP_CWORD; ++i)); do | |
local arg=${COMP_WORDS[$i]} | |
case $arg in | |
[^-]*) | |
bundle_command=$arg | |
return;; | |
--version) | |
# command-killer | |
bundle_command=- | |
return;; | |
--help) | |
bundle_command=help | |
return;; | |
esac | |
done | |
} | |
complete -F __bundle -o bashdefault -o default bundle | |
# vim: ai ft=sh sw=4 sts=2 et |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment