Skip to content

Instantly share code, notes, and snippets.

@git2samus
Created February 18, 2011 21:02
Show Gist options
  • Select an option

  • Save git2samus/834399 to your computer and use it in GitHub Desktop.

Select an option

Save git2samus/834399 to your computer and use it in GitHub Desktop.
cdgem
# # cd into matching gem directory
# cdgem() {
# local gempath=$(gem env gemdir)/gems
# if [[ $1 == "" ]]; then
# cd $gempath
# return
# fi
#
# local gem=$(ls $gempath | g $1 | sort | tail -1)
# if [[ $gem != "" ]]; then
# cd $gempath/$gem
# fi
# }
# _cdgem() {
# COMPREPLY=($(compgen -W '$(ls `gem env gemdir`/gems)' -- ${COMP_WORDS[COMP_CWORD]}))
# return 0;
# }
# complete -o default -o nospace -F _cdgem cdgem;
cdgem() {
# figure out if we're using Isolate, Bundler or system gems
local project_root="$PWD" bundler isolate
while true; do
[[ -f "$project_root"/Gemfile ]] && bundler=y
[[ -f "$project_root"/Isolate ]] && isolate=y
[[ "$bundler" && "$isolate" ]] && { echo "ERROR: ambiguous configuration found at '$project_root'" >&2 && return 1; }
[[ "$bundler" || "$isolate" ]] && break
[[ "$project_root" ]] && project_root="${project_root%/*}" || break
done
if [[ "$bundler" ]]; then
echo "Bundler: $project_root"
else
[[ "$isolate" ]] && echo "Isolate: $project_root"
# get the list of paths for system gems
local hasIFS
declare -p IFS >/dev/null 2>&1 && hasIFS=y oldIFS="$IFS"
IFS=: gem_paths=($GEM_PATH)
[[ "$hasIFS" ]] && IFS="$oldIFS" || unset IFS
echo "System: ${gem_paths[@]}"
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment