Created
July 10, 2012 16:51
-
-
Save mloberg/3084643 to your computer and use it in GitHub Desktop.
Find and cd to projects.
This file contains 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
#!/usr/bin/env bash | |
# Add or source this from .bash_profile/.bashrc | |
# usage: project project_name | |
PROJECT_DIR="~/Code" | |
project() { | |
PROJECTS=( $(find $PROJECT_DIR -type d -iname "$1") ) | |
if [[ "${#PROJECTS[@]}" -gt 1 ]]; then | |
echo "Not sure which project you're talking about." | |
i=0 | |
for proj in "${PROJECTS[@]}"; do | |
echo "$i: ${proj}" | |
i=$(expr $i + 1) | |
done | |
read -p "Project: " p | |
cd "${PROJECTS[$p]}" | |
elif [[ "${#PROJECTS[@]}" -le 0 ]]; then | |
echo "Unknown project." | |
return 1 | |
else | |
cd "${PROJECTS[0]}" | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment