Wednesday, 16 March 2022

More fun with Git and ZSH, this time branch naming ...

Following on from my earlier post: -

ZSH and Git and auto-complete

I wanted to add the capability to display the name of the current GitHub repository branch in my Terminal.

Thankfully, GitHub already allows this, and I had their repository cloned to my Mac.

A quick update: -

cd ~/Documents/GitHub/

git fetch origin

git rebase origin/master

and then I copied a pair of scripts: -

cp ~/Documents/GitHub/ ~/.zsh/_git

cp ~/Documents/GitHub/ ~

noting that git-completion.zsh goes into ~/.zsh/_git as per this: -

# The recommended way to install this script is to make a copy of it as a
# file named '_git' inside any directory in your fpath.
# For example, create a directory '~/.zsh/', copy this file to '~/.zsh/_git',
# and then add the following to your ~/.zshrc file:
#  fpath=(~/.zsh $fpath)

( source: git-completion.zsh )

This is now my ~/.zshrc file: -

if type brew &>/dev/null; then
    FPATH=$(brew --prefix)/share/zsh-completions:$FPATH

    autoload -Uz compinit
    compinit -u

setopt prompt_subst
. ~/
export RPROMPT=$'$(__git_ps1 "%s")'

and, having restarted my Terminal, this is what I see: -

noting that the branch name appears/changes on the right-hand side of the screen

Which is nice

No comments:

Grokking grep

A colleague was tinkering with grep  and, thanks to him, I discovered a bit more about the trusty little utility. I had not really explored ...