Last active
June 23, 2021 05:21
-
-
Save uWayLu/edcf9fb07ec116a2e3a416357dbe4ffc to your computer and use it in GitHub Desktop.
Show git branch info in PS1
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
# ~/.bashrc_git_ps1 | |
# echo . ~/.bashrc_git_ps1 >> ~/.bashrc | |
# | |
# show git branch and time since last commit with color | |
# see: https://ihower.tw/blog/archives/5436 | |
function git_branch { | |
ref=$(git symbolic-ref HEAD 2> /dev/null) || return; | |
echo "("${ref#refs/heads/}") "; | |
} | |
function git_since_last_commit { | |
now=`date +%s`; | |
last_commit=$(git log --pretty=format:%at -1 2> /dev/null) || return; | |
seconds_since_last_commit=$((now-last_commit)); | |
minutes_since_last_commit=$((seconds_since_last_commit/60)); | |
hours_since_last_commit=$((minutes_since_last_commit/60)); | |
minutes_since_last_commit=$((minutes_since_last_commit%60)); | |
echo "${hours_since_last_commit}h${minutes_since_last_commit}m "; | |
} | |
PS1="\[\033[38;5;11m\]\u\[$(tput sgr0)\]@\h:[\[\033[1;32m\]\w\[\033[0m\]] \[\033[0m\]\[\033[1;36m\]\$(git_branch)\[\033[0;33m\]\$(git_since_last_commit)\[\033[0m\]$ " |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment