Skip to content

Instantly share code, notes, and snippets.

@mikbe
Created March 8, 2011 16:17
Show Gist options
  • Save mikbe/860473 to your computer and use it in GitHub Desktop.
Save mikbe/860473 to your computer and use it in GitHub Desktop.
Bash: Change to a directory given a full or partial name
#!/bin/bash
# Change to a directory given a full or partial name
# You don't have to wrap directory names in quotes either
chd() {
if [ -n "$@" ]; then
if [ -n "`ls "$@"* 2>/dev/null`" ]; then
cd "$@"*
else
echo "-bash: chd: "$@": No directory could be extrapolated from partial name"
fi
fi
}
# Here's an example of wrapping the chd
# function for a commonly used shortcut
dev() {
cd "$HOME/development"
chd $@
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment