Created
April 25, 2012 12:11
-
-
Save foca/2489279 to your computer and use it in GitHub Desktop.
cdgem is a small bash utility function to cd into a rubygem's directory
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
# cd into matching gem directory ("cd -" friendly) | |
# | |
# cdgem noko # will cd into the first gem matching noko | |
# cdgem ^rails- # will cd into the first gem starting with "rails-" | |
# vim $(cdgem noko) # will open the gem's directory in vim | |
cdgem() { | |
local gempath=$(gem env gemdir)/gems; | |
local gem=$(ls "$gempath" | grep "$1" | sort | tail -1); | |
if [ -z "$1" ]; then | |
[ -t 1 ] && cd "$gempath" || echo "$gempath"; | |
elif [ -n "$gem" ]; then | |
[ -t 1 ] && cd "$gempath/$gem" || echo "$gempath/$gem"; | |
else | |
echo "Could not find gem \"$1\" in \"$gempath\"" 1>&2; | |
return 1; | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Very useful. Thanks.