mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2025-12-26 02:12:33 +01:00
Added time since last commit to my theme.
This commit is contained in:
parent
9346d86c9d
commit
d1b113f616
1 changed files with 26 additions and 2 deletions
|
|
@ -1,5 +1,29 @@
|
||||||
PROMPT='%{$fg[blue]%}%n%{$reset_color%} on %{$fg[red]%}%M%{$reset_color%} in %{$fg[blue]%}%~%b%{$reset_color%}$(git_prompt_info)
|
PROMPT='%{$fg[blue]%}%n%{$reset_color%} on %{$fg[red]%}%M%{$reset_color%} in %{$fg[blue]%}%~%b%{$reset_color%}$(git_time_since_commit)$(git_prompt_info)
|
||||||
$ '
|
$ '
|
||||||
|
|
||||||
ZSH_THEME_GIT_PROMPT_PREFIX="(%{$fg[green]%}"
|
# Colors vary depending on time lapsed.
|
||||||
|
ZSH_THEME_GIT_TIME_SINCE_COMMIT_SHORT="%{$fg[green]%}"
|
||||||
|
ZSH_THEME_GIT_TIME_SHORT_COMMIT_MEDIUM="%{$fg[yellow]%}"
|
||||||
|
ZSH_THEME_GIT_TIME_SINCE_COMMIT_LONG="%{$fg[red]%}"
|
||||||
|
|
||||||
|
ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg[green]%}"
|
||||||
ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%})"
|
ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%})"
|
||||||
|
|
||||||
|
function git_time_since_commit() {
|
||||||
|
if git rev-parse --git-dir > /dev/null 2>&1; then
|
||||||
|
now=`date +%s`
|
||||||
|
last_commit=`git log --pretty=format:'%at' -1 2> /dev/null`
|
||||||
|
seconds_since_last_commit=$((now-last_commit))
|
||||||
|
|
||||||
|
MINUTES_SINCE_LAST_COMMIT=$((seconds_since_last_commit/60))
|
||||||
|
|
||||||
|
if [ "$MINUTES_SINCE_LAST_COMMIT" -gt 30 ]; then
|
||||||
|
COLOR="$ZSH_THEME_GIT_TIME_SINCE_COMMIT_LONG"
|
||||||
|
elif [ "$MINUTES_SINCE_LAST_COMMIT" -gt 10 ]; then
|
||||||
|
COLOR="$ZSH_THEME_GIT_TIME_SHORT_COMMIT_MEDIUM"
|
||||||
|
else
|
||||||
|
COLOR="$ZSH_THEME_GIT_TIME_SINCE_COMMIT_SHORT"
|
||||||
|
fi
|
||||||
|
echo "($COLOR${MINUTES_SINCE_LAST_COMMIT}m%{$reset_color%}|"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue