Skip to content

Instantly share code, notes, and snippets.

@crast
Last active January 31, 2018 05:36
Show Gist options
  • Save crast/0e1fcadfdae814d47439dda8b0926e37 to your computer and use it in GitHub Desktop.
Save crast/0e1fcadfdae814d47439dda8b0926e37 to your computer and use it in GitHub Desktop.
_chpwd() {
if [[ "$PWD" == */src/* || "$PWD" == */src ]]; then
GPNEW=$(echo $PWD | sed -e 's#/src.*##')
elif [ -d src ]; then
GPNEW=`pwd`
fi
if [[ "$GPNEW" != "" && "$GPNEW" != "$GOPATH" ]]; then
export GOPATH="$GPNEW"
echo "GOPATH=$GOPATH"
fi
}
_chpwd
cd() { builtin cd "$@" && _chpwd; }
pushd() { builtin pushd "$@" && _chpwd; }
popd() { builtin popd "$@" && _chpwd; }
export PS1='\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*)
PS1="\[\e]0;\u@\h: \w\a\]$PS1"
;;
*)
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment