mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2025-12-26 02:12:33 +01:00
Added untracked marker for git. Changed colors for my theme.
This commit is contained in:
parent
4c8f589314
commit
1b17d97fb4
2 changed files with 50 additions and 14 deletions
17
lib/git.zsh
17
lib/git.zsh
|
|
@ -4,11 +4,20 @@ function git_prompt_info() {
|
|||
echo "$ZSH_THEME_GIT_PROMPT_PREFIX${ref#refs/heads/}$(parse_git_dirty)$ZSH_THEME_GIT_PROMPT_SUFFIX"
|
||||
}
|
||||
|
||||
# Taken from https://github.com/sjl/oh-my-zsh/blob/master/lib/git.zsh
|
||||
parse_git_dirty () {
|
||||
if [[ -n $(git status -s 2> /dev/null) ]]; then
|
||||
echo "$ZSH_THEME_GIT_PROMPT_DIRTY"
|
||||
else
|
||||
echo "$ZSH_THEME_GIT_PROMPT_CLEAN"
|
||||
gitstat=$(git status 2>/dev/null | grep '\(# Untracked\|# Changes\|# Changed but not updated:\)')
|
||||
|
||||
if [[ $(echo ${gitstat} | grep -c "^# Changes to be committed:$") > 0 ]]; then
|
||||
echo -n "$ZSH_THEME_GIT_PROMPT_DIRTY"
|
||||
fi
|
||||
|
||||
if [[ $(echo ${gitstat} | grep -c "^\(# Untracked files:\|# Changed but not updated:\)$") > 0 ]]; then
|
||||
echo -n "$ZSH_THEME_GIT_PROMPT_UNTRACKED"
|
||||
fi
|
||||
|
||||
if [[ $(echo ${gitstat} | grep -v '^$' | wc -l | tr -d ' ') == 0 ]]; then
|
||||
echo -n "$ZSH_THEME_GIT_PROMPT_CLEAN"
|
||||
fi
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,29 +1,56 @@
|
|||
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[white]%}"
|
||||
ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%})"
|
||||
|
||||
# Text to display if the branch is dirty
|
||||
ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[red]%}*%{$reset_color%}"
|
||||
|
||||
# Text to display if the branch has untracked files
|
||||
ZSH_THEME_GIT_PROMPT_UNTRACKED="%{$fg[red]%}?%{$reset_color%}"
|
||||
|
||||
# Text to display if the branch is clean
|
||||
ZSH_THEME_GIT_PROMPT_CLEAN=""
|
||||
|
||||
|
||||
# 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_TIME_SINCE_COMMIT_NEUTRAL="%{$fg[cyan]%}"
|
||||
|
||||
ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg[red]%}"
|
||||
ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%})"
|
||||
|
||||
# Determine the time since last commit. If branch is clean,
|
||||
# use a neutral color, otherwise colors will vary according to time.
|
||||
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))
|
||||
# Total minutes
|
||||
MINUTES=$((seconds_since_last_commit / 60))
|
||||
|
||||
# Hours and minutes
|
||||
HOURS=$((seconds_since_last_commit/3600))
|
||||
SUB_MINUTES=$((seconds_since_last_commit % 3600 / 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"
|
||||
if [[ -n $(git status -s 2> /dev/null) ]]; then
|
||||
if [ "$MINUTES" -gt 30 ]; then
|
||||
COLOR="$ZSH_THEME_GIT_TIME_SINCE_COMMIT_LONG"
|
||||
elif [ "$MINUTES" -gt 10 ]; then
|
||||
COLOR="$ZSH_THEME_GIT_TIME_SHORT_COMMIT_MEDIUM"
|
||||
else
|
||||
COLOR="$ZSH_THEME_GIT_TIME_SINCE_COMMIT_SHORT"
|
||||
fi
|
||||
else
|
||||
COLOR="$ZSH_THEME_GIT_TIME_SINCE_COMMIT_SHORT"
|
||||
COLOR="$ZSH_THEME_GIT_TIME_SINCE_COMMIT_NEUTRAL"
|
||||
fi
|
||||
|
||||
if [ "$MINUTES" -gt 60 ]; then
|
||||
echo "($COLOR${HOURS}h${SUB_MINUTES}m%{$reset_color%}|"
|
||||
else
|
||||
echo "($COLOR${MINUTES}m%{$reset_color%}|"
|
||||
fi
|
||||
echo "($COLOR${MINUTES_SINCE_LAST_COMMIT}m%{$reset_color%}|"
|
||||
fi
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue