I want to display my current git branch in the prompt in ksh88.
I'm working on a legacy project, when the backend run on IBM's AIX, with a mandatory ksh88 shell. I can switch to say, bash, for some operations, but I'm compelled to use ksh88 for most of the daily work. (we are working on changing the shell but it's a very long shot, nigh impossible)
So I'm using this (simplified) kind of variation. all of them work (they display the current branch), but none are dynamic: If I switch branch, they still display the same branch.
export GIT_BRANCH=$(git branch 2>/dev/null | grep '^*' | colrm 1 2)
export PS1="\$GIT_BRANCH - $ "
as well as
get_git_branch(){
print -- git branch 2>/dev/null | grep '^*' | colrm 1 2
}
export PS1="$(get_git_branch) - $"
In both cases, to update it, I need to reload my .profile (running . ~/.profile
), but that's not practical.
When I'm adding the $PWD (in my full version of the export PS1
), it does change when I'm changing the current directory
I've read here (How to set the command(s) that get run before every single prompt?) that there could be some tricks to expand some expressions, but only numerical ones.
I've seen this (my biggest hope at the moment) Solaris KSH setting up PS1 with dynamic line but didn't quite understood how to apply it to my problem.
Is there any other tricks I could use ?