diff options
| author | Samuel Parkinson <sam.parkinson@graze.com> | 2014-07-02 18:22:32 +0100 | 
|---|---|---|
| committer | ncanceill <nicolas.canceill@ens-cachan.org> | 2015-06-10 14:36:53 +0200 | 
| commit | de56943a0ee120fdc0ba9f2c3929f8bb1742e3b4 (patch) | |
| tree | d2da7882bdb68c49c20df8d39123a808b5700e5a /themes | |
| parent | 729b19c0852b7efe7d9c63e08b676883794b90ec (diff) | |
| download | zsh-de56943a0ee120fdc0ba9f2c3929f8bb1742e3b4.tar.gz zsh-de56943a0ee120fdc0ba9f2c3929f8bb1742e3b4.tar.bz2 zsh-de56943a0ee120fdc0ba9f2c3929f8bb1742e3b4.zip | |
Improved the `_git_time_since_commit` function.
Check for at least one commit using a `git log` limit of one.
Improves the performance inside git repos with a large history.
Diffstat (limited to 'themes')
| -rw-r--r-- | themes/avit.zsh-theme | 53 | 
1 files changed, 25 insertions, 28 deletions
| diff --git a/themes/avit.zsh-theme b/themes/avit.zsh-theme index a21a9c8c4..65466b82f 100644 --- a/themes/avit.zsh-theme +++ b/themes/avit.zsh-theme @@ -38,34 +38,32 @@ function _ruby_version() {  # 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 -    # Only proceed if there is actually a commit. -    if [[ $(git log 2>&1 > /dev/null | grep -c "^fatal: bad default revision") == 0 ]]; then -      # Get the last commit. -      last_commit=$(git log --pretty=format:'%at' -1 2> /dev/null) -      now=$(date +%s) -      seconds_since_last_commit=$((now-last_commit)) - -      # Totals -      minutes=$((seconds_since_last_commit / 60)) -      hours=$((seconds_since_last_commit/3600)) - -      # Sub-hours and sub-minutes -      days=$((seconds_since_last_commit / 86400)) -      sub_hours=$((hours % 24)) -      sub_minutes=$((minutes % 60)) - -      if [ $hours -gt 24 ]; then -          commit_age="${days}d" -      elif [ $minutes -gt 60 ]; then -          commit_age="${sub_hours}h${sub_minutes}m" -      else -          commit_age="${minutes}m" -      fi - -      color=$ZSH_THEME_GIT_TIME_SINCE_COMMIT_NEUTRAL -      echo "$color$commit_age%{$reset_color%}" +# Only proceed if there is actually a commit. +  if git log -1 > /dev/null 2>&1; then +    # Get the last commit. +    last_commit=$(git log --pretty=format:'%at' -1 2> /dev/null) +    now=$(date +%s) +    seconds_since_last_commit=$((now-last_commit)) + +    # Totals +    minutes=$((seconds_since_last_commit / 60)) +    hours=$((seconds_since_last_commit/3600)) + +    # Sub-hours and sub-minutes +    days=$((seconds_since_last_commit / 86400)) +    sub_hours=$((hours % 24)) +    sub_minutes=$((minutes % 60)) + +    if [ $hours -gt 24 ]; then +      commit_age="${days}d" +    elif [ $minutes -gt 60 ]; then +      commit_age="${sub_hours}h${sub_minutes}m" +    else +      commit_age="${minutes}m"      fi + +    color=$ZSH_THEME_GIT_TIME_SINCE_COMMIT_NEUTRAL +    echo "$color$commit_age%{$reset_color%}"    fi  } @@ -99,4 +97,3 @@ ZSH_THEME_GIT_TIME_SINCE_COMMIT_NEUTRAL="%{$fg[grey]%}"  export LSCOLORS="exfxcxdxbxegedabagacad"  export LS_COLORS='di=34;40:ln=35;40:so=32;40:pi=33;40:ex=31;40:bd=34;46:cd=34;43:su=0;41:sg=0;46:tw=0;42:ow=0;43:'  export GREP_COLOR='1;33' - | 
