dc87b81b1b70d528643aece33dcb0f4c25621e72

Author
Dieter Plaetinck <dieter@plaetinck.be>
Committer
Dieter Plaetinck <dieter@plaetinck.be>
Date

Message

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

Diff

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