d76258ff554ea58d9865b9864f5fff1dd8d2e4bb
- Author
- Marc Cornellà <marc.cornella@live.com>
- Committer
- Marc Cornellà <marc.cornella@live.com>
- Date
Message
avit: add years since last commit if appropriate
Diff
1diff --git a/themes/avit.zsh-theme b/themes/avit.zsh-theme
2index 4f82f34140d8152340767bee5764f609a334d096..51701572bbb2ac8fcdfaa3bfb404c0cf59cf4460 100644
3--- a/themes/avit.zsh-theme
4+++ b/themes/avit.zsh-theme
5@@ -29,7 +29,7 @@ function _user_host() {
6 # use a neutral color, otherwise colors will vary according to time.
7 function _git_time_since_commit() {
8 local last_commit now seconds_since_last_commit
9- local minutes hours commit_age
10+ local minutes hours days years commit_age
11 # Only proceed if there is actually a commit.
12 if last_commit=$(git log --pretty=format:'%at' -1 2> /dev/null); then
13 now=$(date +%s)
14@@ -37,12 +37,16 @@ function _git_time_since_commit() {
15
16 # Totals
17 minutes=$((seconds_since_last_commit / 60))
18- hours=$((seconds_since_last_commit / 3600))
19+ hours=$((minutes / 60))
20+ days=$((hours / 24))
21+ years=$((days / 365))
22
23- if [[ $hours -ge 24 ]]; then
24- commit_age="$(( hours / 24 ))d"
25+ if [[ $years -gt 0 ]]; then
26+ commit_age="${years}y$((days % 365 ))d"
27+ elif [[ $days -gt 0 ]]; then
28+ commit_age="${days}d$((hours % 24))h"
29 elif [[ $hours -gt 0 ]]; then
30- commit_age+="$(( hours % 24 ))h$(( minutes % 60 ))m"
31+ commit_age+="${hours}h$(( minutes % 60 ))m"
32 else
33 commit_age="${minutes}m"
34 fi