Skip to content

Instantly share code, notes, and snippets.

@mrkskwsnck
Last active May 2, 2024 13:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrkskwsnck/e87bec2e13e1543e25bb531cf04590aa to your computer and use it in GitHub Desktop.
Save mrkskwsnck/e87bec2e13e1543e25bb531cf04590aa to your computer and use it in GitHub Desktop.
Customized bash prompt for Git's sake
source ~/.profile
# Customized terminal prompt to reflect current git branches. Based on Debian's default PS1 variable, which was
# e.g. '\[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
# at the time beeing of Debian 12 Bookworm. The original prompt was broken in two parts (left and right)
# and it can get flavoured with the middle part, to your very linking.
#
# Left part: ${PS1:0:-3}
# Right part: ${PS1:${#ps1_left_part}:${#PS1}}
#
# That way the original prompt keeps its existance.
#
# See also this issue for IntelliJ platform IDEs not sourcing the users .bash_profile file at
# https://intellij-support.jetbrains.com/hc/en-us/community/posts/205437150/comments/360000167679
ps1_left_part='\[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]'
ps1_middle_part='$(git branch 2>/dev/null 1>&2 && printf ":")\033[00;31m\]$(git branch --show-current 2>/dev/null)\033[00m\]'
ps1_right_part='\$ '
export PS1=$ps1_left_part$ps1_middle_part$ps1_right_part
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment