touchup of embarrassingly old crap
This commit is contained in:
parent
3caea636b3
commit
094441961b
108
activate_proj
108
activate_proj
@ -1,64 +1,68 @@
|
||||
#!/bin/bash
|
||||
# This file is meant to be *sourced*, not executed.
|
||||
|
||||
USAGE="Usage: $HOME/.activate_proj <proj>"
|
||||
USAGE="Usage: source $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}"
|
||||
if [[ ! -n "${1}" ]] ; then
|
||||
echo $USAGE
|
||||
return 1
|
||||
fi
|
||||
|
||||
_HAS_GIT=""
|
||||
if [[ -d "$PWD/.git" ]]
|
||||
then
|
||||
_HAS_GIT="yup"
|
||||
fi
|
||||
PROJ=${1}
|
||||
local PROJDIR="${HOME}/src/${PROJ}"
|
||||
|
||||
_HG_BRANCH=""
|
||||
_HAS_HG=""
|
||||
if [[ -d "$PWD/.hg" ]]
|
||||
then
|
||||
_HG_BRANCH="$PWD/.hg/branch"
|
||||
_HAS_HG="yup"
|
||||
fi
|
||||
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
|
||||
|
||||
echo "Changed to ${PROJSRC}"
|
||||
if [[ -e "${PROJBIN}/activate" ]]
|
||||
then
|
||||
source "${PROJBIN}/activate"
|
||||
fi
|
||||
echo "${PROJ} activated"
|
||||
export PROJ
|
||||
export PROJSRC="$PROJDIR/src"
|
||||
export PROJBIN="${PROJDIR}/bin"
|
||||
cd "${PROJSRC}"
|
||||
|
||||
PROMPT_COMMAND='precmd; PS1="(\[\033[33m\]\${PROJ}\[\033[00m\]) _VCS_BRANCH_$PS1"'
|
||||
export PROMPT_COMMAND
|
||||
_HAS_GIT=""
|
||||
if [[ -d "$PWD/.git" ]]
|
||||
then
|
||||
_HAS_GIT="yup"
|
||||
fi
|
||||
|
||||
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
|
||||
_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 "$@"
|
||||
|
Loading…
Reference in New Issue
Block a user