Skip to content

Instantly share code, notes, and snippets.

@mikbe
Created February 15, 2013 21:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikbe/4963820 to your computer and use it in GitHub Desktop.
Save mikbe/4963820 to your computer and use it in GitHub Desktop.
A friendlier change directory for Bash and OS X.
# Change to a directory given a full or partial name
# You don't have to wrap directory names in quotes either
function chd() {
friendlyChgDirOptions
if [ -n "$1" ]; then
if [ -n "`ls "$@"* 2>/dev/null`" ]; then
cd "$1"*
else
echo "-bash: chd: "$1": No directory found from partial name"
fi
fi
}
function friendlyChgDirOptions() {
shopt -s cdspell
shopt -s nocaseglob
}
function dev() {
cd "$HOME/development"
chd "$@"
}
function sites() {
cd "$HOME/sites"
chd "$@"
}
function home() {
cd "$HOME"
chd "$@"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment