Browse code

reset exit code visual cues (not exit code itself) after showing once

Dieter Plaetinck authored on 24/11/2010 at 18:58:03
Showing 1 changed files
... ...
@@ -2,21 +2,25 @@
2 2
 # and colorcoding, which bring useful visual cues.  While limiting the amount of colors and such to keep
3 3
 # it easy on the eyes
4 4
 # exact return code (when >0) is on the right, so it stays out of the way
5
-
6
-# TODO: reset exit code visual cues (not exit code itself) after showing once
7
-# TODO: compress hostname in window title
5
+# The visual cues for >0 exit codes will only display once
6
+# (i.e. they will be reset, even if you hit enter a few times on empty command prompts)
8 7
 
9 8
 typeset -A host_repr
10 9
 host_repr=('dieter-ws-a7n8x-arch' "%{$fg_bold[green]%}ws" 'dieter-p4sci-arch' "%{$fg_bold[blue]%}p4")
11 10
 
12 11
 
13 12
 # local time, color coded after last return code
14
-local time="%(?.%{$fg[green]%}.%{$fg[red]%})%*%{$reset_color%}"
13
+time_enabled="%(?.%{$fg[green]%}.%{$fg[red]%})%*%{$reset_color%}"
14
+time_disabled="%{$fg[green]%}%*%{$reset_color%}"
15
+time=$time_enabled
16
+
15 17
 # user part, color coded after privileges
16 18
 local user="%(!.%{$fg[blue]%}.%{$fg[blue]%})%n%{$reset_color%}"
19
+
17 20
 # Hostname part.  compressed and colorcoded per host_repr array
18 21
 # if not found, regular hostname in default color
19 22
 local host="@${host_repr[$(hostname)]:-$(hostname)}%{$reset_color%}"
23
+
20 24
 # Compacted $PWD
21 25
 local pwd="%{$fg[blue]%}%c%{$reset_color%}"
22 26
 
... ...
@@ -29,5 +33,21 @@ ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[green]%} %{$fg[yellow]%}?%{$fg[green]%}%{$rese
29 29
 ZSH_THEME_GIT_PROMPT_CLEAN="%{$fg[green]%}"
30 30
 
31 31
 # elaborate exitcode on the right when >0
32
-local return_code="%(?..%{$fg[red]%}%? ↵%{$reset_color%})"
33
-RPS1="${return_code}"
32
+return_code_enabled="%(?..%{$fg[red]%}%? ↵%{$reset_color%})"
33
+return_code_disabled=
34
+return_code=$return_code_enabled
35
+
36
+RPS1='${return_code}'
37
+
38
+function accept-line-or-clear-warning () {
39
+	if [[ -z $BUFFER ]]; then
40
+		time=$time_disabled
41
+		return_code=$return_code_disabled
42
+	else
43
+		time=$time_enabled
44
+		return_code=$return_code_enabled
45
+	fi
46
+	zle accept-line
47
+}
48
+zle -N accept-line-or-clear-warning
49
+bindkey '^M' accept-line-or-clear-warning