Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add time since last Git commit to prompt.
- Loading branch information
Showing
3 changed files
with
61 additions
and
1 deletion.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# Combine Git branch name and time since last commit. | ||
# Taken from https://gist.github.com/926846 with some modifications. | ||
# | ||
# Example: | ||
# PS1="(\h • ${YELLOW}\W${NORMAL}\$(srb_git_prompt))${BRIGHT_BLUE}\$${NORMAL} " | ||
# | ||
function relative_time_since_last_commit { | ||
last_commit=`git log --pretty=format:'%ar' -1` | ||
echo ${last_commit} | ||
} | ||
|
||
function format_unit { | ||
local UNIT=$1 | ||
case "$UNIT" in | ||
seconds) UNIT="s" ;; | ||
minutes) UNIT="m" ;; | ||
hours) UNIT="h" ;; | ||
days) UNIT="d" ;; | ||
weeks) UNIT="w" ;; | ||
months) UNIT="mo" ;; | ||
years) UNIT="yr" ;; | ||
*);; | ||
esac | ||
echo ${UNIT} | ||
} | ||
|
||
function color_based_on_unit { | ||
local UNIT=$1 | ||
if [ "$UNIT" == "s" ] || [ "$UNIT" == "m" ]; then | ||
local COLOR=${TXTBLU} | ||
elif [ "$UNIT" == "h" ]; then | ||
local COLOR=${TXTYLW} | ||
else | ||
local COLOR=${TXTRED} | ||
fi | ||
echo ${COLOR} | ||
} | ||
|
||
srb_git_prompt() { | ||
local g="$(__gitdir)" | ||
if [ -n "$g" ]; then | ||
local SINCE_LAST_COMMIT=$(relative_time_since_last_commit) | ||
SINCE_LAST_COMMIT=(${SINCE_LAST_COMMIT// / }) | ||
local VALUE=${SINCE_LAST_COMMIT[0]} | ||
local UNIT=$(format_unit ${SINCE_LAST_COMMIT[1]/,/}) | ||
|
||
# for old projects, git reports years and months | ||
if [ ${SINCE_LAST_COMMIT[2]} != "ago" ]; then | ||
local EXTRA_VALUE=${SINCE_LAST_COMMIT[2]} | ||
local EXTRA_UNIT=$(format_unit ${SINCE_LAST_COMMIT[3]/,/}) | ||
fi | ||
|
||
local COLOR=$(color_based_on_unit $UNIT) | ||
local DELTA="${VALUE}${UNIT}${EXTRA_VALUE}${EXTRA_UNIT}" | ||
|
||
# The __git_ps1 function inserts the current git branch where %s is | ||
echo `__git_ps1 "%s ${COLOR}∆${DELTA}"` | ||
fi | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
. ~/bin/dotfiles/bash/env | ||
. ~/bin/dotfiles/bash/git-completion | ||
. ~/bin/dotfiles/bash/git-prompt | ||
. ~/bin/dotfiles/bash/config | ||
. ~/bin/dotfiles/bash/aliases | ||
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" |