Skip to content

Instantly share code, notes, and snippets.

@agargiulo
Last active January 2, 2019 23:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save agargiulo/9bfd39cc32ef370d79924c3973c64fed to your computer and use it in GitHub Desktop.
Save agargiulo/9bfd39cc32ef370d79924c3973c64fed to your computer and use it in GitHub Desktop.
Wanted a way to navigate between different projects using only zsh. Feedback welcome
setopt extendedglob
unset CURRENT_PROJECT_NAME
typeset -a project_dirs
find "${HOME}/projects" -maxdepth 1 -type d | while read project; do
project_dirs+=("${project:t}")
done
function proj() {
name=$1
base=${2-projects}
proj_path="${HOME}/${base}/${name}"
export ORIG_PROMPT=${ORIG_PROMPT-$PROMPT}
if [[ -n $CURRENT_PROJECT_NAME && $CURRENT_PROJECT_NAME == "${name}" ]]; then
return
elif [[ -z $name || ! -d ${proj_path} ]]; then
echo "Invalid project: \`${base}/${name}'" >&2
echo 'Usage proj PROJECT' >&2
export PROMPT=$ORIG_PROMPT
unset CURRENT_PROJECT_NAME
return 69
elif [[ -n $CURRENT_PROJECT_NAME ]]; then
echo "Changing project from ${CURRENT_PROJECT_NAME} to ${name}"
fi
export PROMPT="${MAGENTA}( ${YELLOW}${(C)base}::${(C)name} ${MAGENTA}) ${ORIG_PROMPT}"
pushd "${proj_path}"
export CURRENT_PROJECT_NAME=${name}
}
compctl -k project_dirs proj
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment