Showing worktree information in the shell prompt
Recently, I’ve made a small change to Sapling to show export the current worktree in the filesystem.
This allows to make another small test of changes to scm-prompt.sh which shows general information about source control in the shell prompt. That script is compatible with both sapling and git.
Today, I have the following in my ~/.bashrc:
if [ -f $HOME/scripts/scm-prompt.sh ]; then
source $HOME/scripts/scm-prompt.sh
fi
Then I have my PS1 be something like:
export PS1='$?|[\[\033[36m\]\u\[\033[m\]@\[\033[95m\]\h\[\033[m\]]:\[\033[33;1m\]\w\[\033[m\]$(_scm_prompt)\$ '
This means that my shell looks something like this:
0|[noamler@noamler-mbp]:~/sources/blog (main)$
But with this recent change, I can turn on worktree information in the prompt. If I export SCM_PROMPT_SHOW_WORKTREE=1, I get something like this:
0|[noamler@noamler-mbp]:~/worktrees$ cd ~/sources/test_repo/
0|[noamler@noamler-mbp]:~/sources/test_repo (main)$ git worktree add -b my-feature ~/worktrees/worktree1
No possible source branch, inferring '--orphan'
Preparing worktree (new branch 'my-feature')
0|[noamler@noamler-mbp]:~/sources/test_repo (main)$ cd ~/worktrees/worktree1
0|[noamler@noamler-mbp]:~/worktrees/worktree1 (my-feature|worktree1)$ cd subdir/
0|[noamler@noamler-mbp]:~/worktrees/worktree1/subdir (my-feature|worktree1)$