Last active
January 2, 2019 23:30
-
-
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
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
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