72 lines
1.6 KiB
Bash
72 lines
1.6 KiB
Bash
#!/bin/bash
|
|
# This file is meant to be *sourced*, not executed.
|
|
|
|
USAGE="Usage: source $HOME/.activate_proj <proj>"
|
|
|
|
function __run_activate(){
|
|
if [[ ! -n "${1}" ]] ; then
|
|
echo $USAGE
|
|
return 1
|
|
fi
|
|
|
|
PROJ=${1}
|
|
local PROJDIR="${HOME}/src/${PROJ}"
|
|
|
|
if [[ ! -d "$PROJDIR" ]] ; then
|
|
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
|
|
return 2
|
|
fi
|
|
|
|
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=""
|
|
}
|
|
|
|
__run_activate "$@"
|
|
unset __run_activate
|
|
|
|
# vim:ft=sh
|