projects
/
grml-etc-core.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Add `grml_theme_has_token' guard function
[grml-etc-core.git]
/
etc
/
zsh
/
zshrc
diff --git
a/etc/zsh/zshrc
b/etc/zsh/zshrc
index
e475070
..
6a6f1e6
100644
(file)
--- a/
etc/zsh/zshrc
+++ b/
etc/zsh/zshrc
@@
-1195,10
+1195,10
@@
help_zle_parse_keybindings()
if [[ "$cline" == (#s)[[:space:]]#\#k\#[[:space:]]##(#b)(*)[[:space:]]#(#e) ]]; then
lastkeybind_desc="$match[*]"
num_lines_elapsed=0
if [[ "$cline" == (#s)[[:space:]]#\#k\#[[:space:]]##(#b)(*)[[:space:]]#(#e) ]]; then
lastkeybind_desc="$match[*]"
num_lines_elapsed=0
- #zsh pattern: matches lines that set a keybinding using bindkey or compdef -k
+ #zsh pattern: matches lines that set a keybinding using bind
2map, bind
key or compdef -k
# ignores lines that are commentend out
# grabs first in '' or "" enclosed string with length between 1 and 6 characters
# ignores lines that are commentend out
# grabs first in '' or "" enclosed string with length between 1 and 6 characters
- elif [[ "$cline" == [^#]#(bindkey|compdef -k)[[:space:]](*)(#b)(\"((?)(#c1,6))\"|\'((?)(#c1,6))\')(#B)(*) ]]; then
+ elif [[ "$cline" == [^#]#(bind
2maps[[:space:]](*)-s|bind
key|compdef -k)[[:space:]](*)(#b)(\"((?)(#c1,6))\"|\'((?)(#c1,6))\')(#B)(*) ]]; then
#description prevously found ? description not more than 2 lines away ? keybinding not empty ?
if [[ -n $lastkeybind_desc && $num_lines_elapsed -lt 2 && -n $match[1] ]]; then
#substitute keybinding string with something readable
#description prevously found ? description not more than 2 lines away ? keybinding not empty ?
if [[ -n $lastkeybind_desc && $num_lines_elapsed -lt 2 && -n $match[1] ]]; then
#substitute keybinding string with something readable
@@
-1342,9
+1342,11
@@
function bind2maps () {
if (( ${+terminfo[smkx]} )) && (( ${+terminfo[rmkx]} )); then
function zle-smkx () {
if (( ${+terminfo[smkx]} )) && (( ${+terminfo[rmkx]} )); then
function zle-smkx () {
+ emulate -L zsh
printf '%s' ${terminfo[smkx]}
}
function zle-rmkx () {
printf '%s' ${terminfo[smkx]}
}
function zle-rmkx () {
+ emulate -L zsh
printf '%s' ${terminfo[rmkx]}
}
function zle-line-init () {
printf '%s' ${terminfo[rmkx]}
}
function zle-line-init () {
@@
-1853,7
+1855,7
@@
grml_prompt_pre_default=(
newline ''
path '%B'
percent ''
newline ''
path '%B'
percent ''
- rc '%F{red}'
+ rc '%
B%
F{red}'
rc-always ''
sad-smiley ''
shell-level '%F{red}'
rc-always ''
sad-smiley ''
shell-level '%F{red}'
@@
-1874,7
+1876,7
@@
grml_prompt_post_default=(
newline ''
path '%b'
percent ''
newline ''
path '%b'
percent ''
- rc '%f'
+ rc '%f
%b
'
rc-always ''
sad-smiley ''
shell-level '%f'
rc-always ''
sad-smiley ''
shell-level '%f'
@@
-1904,6
+1906,14
@@
grml_prompt_token_default=(
vcs '0'
)
vcs '0'
)
+function grml_theme_has_token () {
+ if (( ARGC != 1 )); then
+ printf 'usage: grml_theme_has_token <name>\n'
+ return 1
+ fi
+ (( ${+grml_prompt_token_default[$1]} ))
+}
+
function GRML_theme_add_token_usage () {
cat <<__EOF__
Usage: grml_theme_add_token <name> [-f|-i] <token/function> [<pre> <post>]
function GRML_theme_add_token_usage () {
cat <<__EOF__
Usage: grml_theme_add_token <name> [-f|-i] <token/function> [<pre> <post>]
@@
-1925,6
+1935,11
@@
function GRML_theme_add_token_usage () {
return value is expected in the \$REPLY parameter. The use of these
options is mutually exclusive.
return value is expected in the \$REPLY parameter. The use of these
options is mutually exclusive.
+ There is a utility function \`grml_theme_has_token', which you can use
+ to test if a token exists before trying to add it. This can be a guard
+ for situations in which a \`grml_theme_add_token' call may happen more
+ than once.
+
Example:
To add a new token \`day' that expands to the current weekday in the
Example:
To add a new token \`day' that expands to the current weekday in the
@@
-1988,7
+2003,7
@@
grml_theme_add_token: <pre> and <post> need to by specified _both_!\n\n'
shift 2
fi
shift 2
fi
- if
(( ${+grml_prompt_token_default[$name]} ))
; then
+ if
grml_theme_has_token $name
; then
printf '
grml_theme_add_token: Token `%s'\'' exists! Giving up!\n\n' $name
GRML_theme_add_token_usage
printf '
grml_theme_add_token: Token `%s'\'' exists! Giving up!\n\n' $name
GRML_theme_add_token_usage
@@
-2033,7
+2048,7
@@
function grml_prompt_addto () {
for it in "${items[@]}"; do
zstyle -s ":prompt:${grmltheme}:${lr}:items:$it" pre apre \
|| apre=${grml_prompt_pre_default[$it]}
for it in "${items[@]}"; do
zstyle -s ":prompt:${grmltheme}:${lr}:items:$it" pre apre \
|| apre=${grml_prompt_pre_default[$it]}
- zstyle -s ":prompt:
grml:${grmltheme}:${lr}
:$it" post apost \
+ zstyle -s ":prompt:
${grmltheme}:${lr}:items
:$it" post apost \
|| apost=${grml_prompt_post_default[$it]}
zstyle -s ":prompt:${grmltheme}:${lr}:items:$it" token new \
|| new=${grml_prompt_token_default[$it]}
|| apost=${grml_prompt_post_default[$it]}
zstyle -s ":prompt:${grmltheme}:${lr}:items:$it" token new \
|| new=${grml_prompt_token_default[$it]}
@@
-2157,7
+2172,7
@@
if is437; then
unset i
zstyle ':prompt:grml(|-large|-chroot):right:setup' use-rprompt false
elif (( EUID == 0 )); then
unset i
zstyle ':prompt:grml(|-large|-chroot):right:setup' use-rprompt false
elif (( EUID == 0 )); then
- zstyle ':prompt:grml(|-large|-chroot):*:items:user' pre '%F{red}'
+ zstyle ':prompt:grml(|-large|-chroot):*:items:user' pre '%
B%
F{red}'
fi
# Finally enable one of the prompts.
fi
# Finally enable one of the prompts.