I have several projects I work on. Instead of setting aliases for each project's location, I would rather set it when I navigate to that specific directory. Each project is a git repo and I already have a mechanism that appends the current branch name to $PS1 when I navigate to it.
In my .bashrc, I call a function: parse_git_branch to append to command prompt:
case "$TERM" in
xterm*|rxvt*)
PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h:\w\a\]$PS1\$(parse_git_branch) "
;;
*)
;;
esac
parse_git_branch is defined at the end of my .basrhc:
function parse_git_branch {
GIT_BRANCH=$(git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ \[\1\]/')
if [[ -n $GIT_BRANCH ]];then
source $HOME/bin/cur
fi
echo $GIT_BRANCH
}
if GIT_BRANCH isn't empty, I source a simple script ~/bin/cur which sets an alias for the pwd:
#!/bin/bash
echo "got here!"
shopt -s expand_aliases
alias current="cd $(pwd)"
When cur is sourced, the alias is not set. The debug message does display correctly however.
I believe this is because shell scripts run "outside" of my current environment. The alias is set when call source cur from the command line.
So, why is the alias not being set when called from "parse_git_branch" inside my .bashrc?
Thanks!