76e541a3fe71075c8ef75ecf44cd60f17b5292bb
- Author
- Felipe Gallois <gallois@users.noreply.github.com>
- Committer
- GitHub <noreply@github.com>
- Date
Message
Diff
This diff is truncated to protect this page.
1diff --git a/themes/gallois.zsh-theme b/themes/gallois.zsh-theme
2index bb97bfb1782cc47f6faaf97cfbb5c0485a907b33..3fc349072bd4670d81132696584557dec1e16e4d 100644
3--- a/themes/gallois.zsh-theme
4+++ b/themes/gallois.zsh-theme
5@@ -1,24 +1,140 @@
6 # Depends on the git plugin for work_in_progress()
7 (( $+functions[work_in_progress] )) || work_in_progress() {}
8
9-ZSH_THEME_GIT_PROMPT_PREFIX="%{$reset_color%}%{$fg[green]%}["
10-ZSH_THEME_GIT_PROMPT_SUFFIX="]%{$reset_color%}"
11-ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[red]%}*%{$reset_color%}"
12+ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg[cyan]%}[%{$fg[green]%}"
13+ZSH_THEME_GIT_PROMPT_SUFFIX="%{$fg[cyan]%}]"
14+ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[red]%}"
15 ZSH_THEME_GIT_PROMPT_CLEAN=""
16
17 # Customized git status, oh-my-zsh currently does not allow render dirty status before branch
18 git_custom_status() {
19 local branch=$(git_current_branch)
20 [[ -n "$branch" ]] || return 0
21- echo "$(parse_git_dirty)\
22-%{${fg_bold[yellow]}%}$(work_in_progress)%{$reset_color%}\
23-${ZSH_THEME_GIT_PROMPT_PREFIX}${branch}${ZSH_THEME_GIT_PROMPT_SUFFIX}"
24+ print "%{${fg_bold[yellow]}%}$(work_in_progress)%{$reset_color%}\
25+${ZSH_THEME_GIT_PROMPT_PREFIX}$(parse_git_dirty)${branch}\
26+${ZSH_THEME_GIT_PROMPT_SUFFIX}"
27+}
28+autoload -U colors && colors
29+
30+#export VCS_PROMPT=hg_prompt_info
31+export VCS_PROMPT=git_custom_status
32+
33+base_prompt="%{$fg[cyan]%}[%~% ]%(?.%{$fg[green]%}.%{$fg[red]%})%B$%b "
34+custom_prompt=""
35+last_run_time=""
36+last_vcs_info=""
37+
38+
39+function pipestatus_parse {
40+ PIPESTATUS="$pipestatus"
41+ ERROR=0
42+ for i in "${(z)PIPESTATUS}"; do
43+ if [[ "$i" -ne 0 ]]; then
44+ ERROR=1
45+ fi
46+ done
47+
48+ if [[ "$ERROR" -ne 0 ]]; then
49+ print "[%{$fg[red]%}$PIPESTATUS%{$fg[cyan]%}]"
50+ fi
51 }
52
53-# RVM component of prompt
54-ZSH_THEME_RUBY_PROMPT_PREFIX="%{$fg[red]%}["
55-ZSH_THEME_RUBY_PROMPT_SUFFIX="]%{$reset_color%}"
56
57 # Combine it all into a final right-side prompt
58-RPS1="\$(git_custom_status)\$(ruby_prompt_info)${RPS1:+ $RPS1}"
59 PROMPT='%{$fg[cyan]%}[%~% ]%(?.%{$fg[green]%}.%{$fg[red]%})%B$%b '
60+function preexec() {
61+ last_run_time=$(perl -MTime::HiRes=time -e 'printf "%.9f\n", time')
62+}
63+
64+function duration() {
65+ local duration
66+ local now=$(perl -MTime::HiRes=time -e 'printf "%.9f\n", time')
67+ local last=$1
68+ local last_split=("${(@s/./)last}")
69+ local now_split=("${(@s/./)now}")
70+ local T=$((now_split[1] - last_split[1]))
71+ local D=$((T/60/60/24))
72+ local H=$((T/60/60%24))
73+ local M=$((T/60%60))
74+ local S=$((T%60))
75+ local s=$(((now_split[2] - last_split[2]) / 1000000000.))
76+ local m=$(((now_split[2] - last_split[2]) / 1000000.))
77+
78+ (( $D > 0 )) && duration+="${D}d"
79+ (( $H > 0 )) && duration+="${H}h"
80+ (( $M > 0 )) && duration+="${M}m"
81+
82+ if [[ $S -le 0 ]]; then
83+ printf "%ims" "$m"
84+ else
85+ if ! [[ -z $duration ]] && printf "%s" "$duration"
86+ local sec_milli=$((S + s))
87+ printf "%.3fs" "$sec_milli"
88+ fi
89+}
90+
91+function precmd() {
92+ RETVAL=$(pipestatus_parse)
93+ local info=""
94+
95+ if [ ! -z "$last_run_time" ]; then
96+ local elapsed=$(duration $last_run_time)
97+ last_run_time=$(print $last_run_time | tr -d ".")
98+ if [ $(( $(perl -MTime::HiRes=time -e 'printf "%.9f\n", time' | tr -d ".") - $last_run_time )) -gt $(( 120 * 1000 * 1000 * 1000 )) ]; then
99+ local elapsed_color="%{$fg[magenta]%}"
100+ elif [ $(( $(perl -MTime::HiRes=time -e 'printf "%.9f\n", time' | tr -d ".") - $last_run_time )) -gt $(( 60 * 1000 * 1000 * 1000 )) ]; then
101+ local elapsed_color="%{$fg[red]%}"
102+ elif [ $(( $(perl -MTime::HiRes=time -e 'printf "%.9f\n", time' | tr -d ".") - $last_run_time )) -gt $(( 10 * 1000 * 1000 * 1000 )) ]; then
103+ local elapsed_color="%{$fg[yellow]%}"
104+ else