dotfiles/activate_proj
Dan Buch a8cd5a2fe9 Attempting to carve out a sensible chunk of stuff for a dotfiles repo.
Sure hope I didn't miss any super secret crap :-P
2012-02-26 14:38:01 -05:00

68 lines
1.8 KiB
Bash

#!/bin/bash
USAGE="Usage: $HOME/.activate_proj <proj>"
function __run_activate(){
if [ -n "${1}" ] ; then
PROJ=${1}
local PROJDIR="${HOME}/src/${PROJ}"
if [[ -d "$PROJDIR" ]] ; then
export PROJ
export PROJSRC="$PROJDIR/src"
export PROJBIN="${PROJDIR}/bin"
cd "${PROJSRC}"
_HAS_GIT=""
if [[ -d "$PWD/.git" ]]
then
_HAS_GIT="yup"
fi
_HG_BRANCH=""
_HAS_HG=""
if [[ -d "$PWD/.hg" ]]
then
_HG_BRANCH="$PWD/.hg/branch"
_HAS_HG="yup"
fi
echo "Changed to ${PROJSRC}"
if [[ -e "${PROJBIN}/activate" ]]
then
source "${PROJBIN}/activate"
fi
echo "${PROJ} activated"
PROMPT_COMMAND='precmd; PS1="(\[\033[33m\]\${PROJ}\[\033[00m\]) _VCS_BRANCH_$PS1"'
export PROMPT_COMMAND
if [[ -n "$_HAS_HG" ]]
then
if [[ -n "$(/bin/ls $(hg root)/.hg/branches 2>/dev/null)" ]]
then
PROMPT_COMMAND=$(echo $PROMPT_COMMAND | sed "s@_VCS_BRANCH_@(lb:\`hg lbranch 2>/dev/null\`) @")
else
PROMPT_COMMAND=$(echo $PROMPT_COMMAND | sed "s@_VCS_BRANCH_@(b:\`cat ${PROJSRC}/.hg/branch 2>/dev/null\`) @")
fi
else
PROMPT_COMMAND=$(echo $PROMPT_COMMAND | sed "s/_VCS_BRANCH_//" )
fi
export PS2=""
else
echo "Hey! '${1}' is not a valid project."
echo "Pick from these:"
echo
for p in $( ls -1 -I "*.egg" "${HOME}/src" ) ; do
echo " $p"
done
fi
else
echo ${USAGE}
fi
}
__run_activate "$@"
unset __run_activate
# vim:ft=sh