Last active
June 10, 2024 15:20
-
-
Save DavideViolante/2c20e71680989c1a26fb4107dd3bbbf3 to your computer and use it in GitHub Desktop.
Show current git branch in Ubuntu bash
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Add these lines to your .bashrc file located in ~/ | |
# Show date in terminal | |
function show_date() { | |
local current_time="[$(date '+%T')]" | |
local green='\[\033[01;32m\]' | |
local blue='\[\033[01;34m\]' | |
local reset='\[\033[0m\]' | |
PS1="$current_time ${green}\u${reset}${green}@${reset}${green}\h${reset}:${blue}\w${reset}\$ " | |
} | |
export PROMPT_COMMAND="show_date" | |
# Show current git branch in terminal | |
parse_git_branch() { | |
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/' | |
} | |
export PS1="\[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$(parse_git_branch) $ " |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment