Created
March 8, 2011 16:17
-
-
Save mikbe/860473 to your computer and use it in GitHub Desktop.
Bash: Change to a directory given a full or partial name
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
#!/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