I tried to set PS1
in the bash_profile as,
.bash_profile
#!/bin/bash
# .....
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
parse_pwd() {
basename $PWD
}
PS1=''$(parse_pwd)''$(parse_git_branch)' $ '
Got the expected output: <project-directory-name> (git-branch-name) $
Problem:
When I change the branch or change project then PS1
details are not updating (i.e. neither the branch name nor the project-directory-name). I had to manually run source ~/.bash_profile
to see those changes in the terminal.
I googled and tried few suggestions like,
Not sure, but is it something to do with my bash? I am currently using zsh,
$ echo $SHELL
/bin/zsh
If you want to change the prompt for Zsh:
PROMPT="⚡️%{$fg[red]%} ☣︎☯︎⚰︎☤⚚♱♚☨☥☥☨♚♱⚚☤⚰︎☯︎☣︎ %{$fg[red]%}⚡%{$fg[green]%}%T⚡️%{$fg[green]%}%{$fg[yellow]%}%d%{$fg[yellow]%} ⚡️"
^This is just an example of the difference between bash and zsh when setting prompt.^
for your case check this link:
https://www.themoderncoder.com/add-git-branch-information-to-your-zsh-prompt/
or change to bash using:
chsh -s /bin/sh