Skip to content

Instantly share code, notes, and snippets.

@mloberg
Created July 10, 2012 16:51
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 mloberg/3084643 to your computer and use it in GitHub Desktop.
Save mloberg/3084643 to your computer and use it in GitHub Desktop.
Find and cd to projects.
#!/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