Skip to content

Instantly share code, notes, and snippets.

@alternative-rvb
Last active March 19, 2022 20:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alternative-rvb/c9fb815495ae52e016cfb99b26fb18db to your computer and use it in GitHub Desktop.
Save alternative-rvb/c9fb815495ae52e016cfb99b26fb18db to your computer and use it in GitHub Desktop.
Custom WSL1 Bashrc script to display git branch name
## Git prompt
force_color_prompt=yes
color_prompt=yes
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}
parse_tty_bg(){
# $1 will be replace by \l (tty number)
tty_number=$(sed 's/tty//' <<< $1)
if [ "$tty_number" -lt 7 ]; then
echo $tty_number
else
echo $tty_number=0
fi
}
parse_tty_font(){
tty_number2=$(sed 's/tty//' <<< $1)
if [ "$tty_number2" -lt 7 ]; then
echo 30
fi
}
if [ "$color_prompt" = yes ]; then
PS1='${debian_chroot:+($debian_chroot)}\n\[\033[$(parse_tty_font \l);4$(parse_tty_bg \l)m\]  \l - \D{%d.%m.%Y} - \t \[\033[00m\] \[\033[01;34m\]\w\[\033[01;31m\] $(parse_git_branch)\[\033[00m\]\n\$ '
else
PS1='${debian_chroot:+($debian_chroot)}\l - \D{%d.%m.%Y} - \t > \w$ (parse_git_branch)\$ '
fi
unset color_prompt force_color_prompt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment