From 2a1a3cd45af8235a262dcf72a67b65f8de2b6d5c Mon Sep 17 00:00:00 2001 From: Colin Jamison Date: Sat, 21 Jan 2017 18:00:14 +0100 Subject: [PATCH 1/3] Implement keymode indicator --- modules/prompt/themes/eriner.zsh-theme | 10 +++++++++- modules/prompt/themes/gitster.zsh-theme | 8 ++++++++ modules/prompt/themes/magicmace.zsh-theme | 9 +++++++-- modules/prompt/themes/steeef.zsh-theme | 7 +++++++ 4 files changed, 31 insertions(+), 3 deletions(-) diff --git a/modules/prompt/themes/eriner.zsh-theme b/modules/prompt/themes/eriner.zsh-theme index 134a81c..b3a4d18 100644 --- a/modules/prompt/themes/eriner.zsh-theme +++ b/modules/prompt/themes/eriner.zsh-theme @@ -141,6 +141,12 @@ prompt_eriner_main() { prompt_eriner_precmd() { vcs_info PROMPT='%{%f%b%k%}$(prompt_eriner_main) ' + RPROMPT="${${KEYMAP/vicmd/[NORMAL]}/(main|viins)/}" +} + +zle-keymap-slect() { + prompt_eriner_precmd + zle reset-prompt } prompt_eriner_setup() { @@ -149,7 +155,9 @@ prompt_eriner_setup() { prompt_opts=(cr subst percent) - add-zsh-hook precmd prompt_eriner_precmd + add-zsh-hook prompt_eriner_precmd + + zle -N zle-keymap-select zstyle ':vcs_info:*' enable git zstyle ':vcs_info:*' check-for-changes false diff --git a/modules/prompt/themes/gitster.zsh-theme b/modules/prompt/themes/gitster.zsh-theme index e7eacb7..8b9a870 100644 --- a/modules/prompt/themes/gitster.zsh-theme +++ b/modules/prompt/themes/gitster.zsh-theme @@ -15,6 +15,12 @@ prompt_gitster_get_pwd() { prompt_gitster_precmd() { [[ ${+functions[git-info]} ]] && git-info + RPROMPT="${${KEYMAP/vicmd/[NORMAL]}/(main|viins)/}" +} + +zle-keymap-select() { + prompt_gitster_precmd + zle reset-prompt } prompt_gitster_setup() { @@ -24,6 +30,8 @@ prompt_gitster_setup() { prompt_opts=(cr percent subst) add-zsh-hook precmd prompt_gitster_precmd + + zle -N zle-keymap-select zstyle ':zim:git-info:branch' format '%b' zstyle ':zim:git-info:commit' format '%c' diff --git a/modules/prompt/themes/magicmace.zsh-theme b/modules/prompt/themes/magicmace.zsh-theme index bce1a87..ea495e7 100644 --- a/modules/prompt/themes/magicmace.zsh-theme +++ b/modules/prompt/themes/magicmace.zsh-theme @@ -44,6 +44,13 @@ prompt_magicmace_precmd() { if [[ ${+functions[git-info]} ]]; then git-info fi + PROMPT='${COLOR_USER_LEVEL}$(prompt_magicmace_status)[${COLOR_NORMAL}$(short_pwd)${COLOR_USER_LEVEL}]${(e)git_info[prompt]}── ─%f ' + RPROMPT="${${KEYMAP/vicmd/[NORMAL]}/(main|viins)/}" +} + +zle-keymap-select() { + prompt_magicmace_precmd + zle reset-prompt } prompt_magicmace_setup() { @@ -63,8 +70,6 @@ prompt_magicmace_setup() { 'prompt' '─[${COLOR_NORMAL}%b%c%D%A%B${COLOR_USER_LEVEL}]' # Call git directly, ignoring aliases under the same name. - PROMPT='${COLOR_USER_LEVEL}$(prompt_magicmace_status)[${COLOR_NORMAL}$(short_pwd)${COLOR_USER_LEVEL}]${(e)git_info[prompt]}── ─%f ' - RPROMPT='' } prompt_magicmace_setup "$@" diff --git a/modules/prompt/themes/steeef.zsh-theme b/modules/prompt/themes/steeef.zsh-theme index 0d44159..34400bb 100644 --- a/modules/prompt/themes/steeef.zsh-theme +++ b/modules/prompt/themes/steeef.zsh-theme @@ -40,11 +40,17 @@ prompt_steeef_precmd() { vcs_info 'prompt' fi + RPROMPT="${${KEYMAP/vicmd/[NORMAL]}/(main|viins)/}" PROMPT=' %{$purple%}%n${${reset_color}%} at %{$orange%}%m${${reset_color}%} in %{$limegreen%}%~${${reset_color}%} $vcs_info_msg_0_$(virtualenv_info)%{${reset_color}%} %(!.#.$) ' } +zle-keymap-select() { + prompt_steeef_precmd + zle reset-prompt +} + prompt_steeef_setup() { #use extended color pallete if available if [[ ${TERM} == *256* || ${TERM} == *rxvt* ]]; then @@ -96,6 +102,7 @@ prompt_steeef_setup() { add-zsh-hook preexec steeef_preexec add-zsh-hook chpwd steeef_chpwd add-zsh-hook precmd prompt_steeef_precmd + zle -N zle-keymap-select prompt_opts=(cr subst percent) } From 4a373bca4a992a0a34c515da34a149356397cdfb Mon Sep 17 00:00:00 2001 From: Colin Jamison Date: Sat, 21 Jan 2017 18:10:32 +0100 Subject: [PATCH 2/3] Implement config variable This allows for an env variable of ZIM_PROMPT_INSERTMODE to be set to determine if an indicator is shown. --- modules/prompt/themes/eriner.zsh-theme | 2 +- modules/prompt/themes/gitster.zsh-theme | 6 ++---- modules/prompt/themes/magicmace.zsh-theme | 2 +- modules/prompt/themes/steeef.zsh-theme | 2 +- 4 files changed, 5 insertions(+), 7 deletions(-) diff --git a/modules/prompt/themes/eriner.zsh-theme b/modules/prompt/themes/eriner.zsh-theme index b3a4d18..3215eda 100644 --- a/modules/prompt/themes/eriner.zsh-theme +++ b/modules/prompt/themes/eriner.zsh-theme @@ -141,7 +141,7 @@ prompt_eriner_main() { prompt_eriner_precmd() { vcs_info PROMPT='%{%f%b%k%}$(prompt_eriner_main) ' - RPROMPT="${${KEYMAP/vicmd/[NORMAL]}/(main|viins)/}" + RPROMPT="${ZIM_PROMPT_INSERTMODE:+${${KEYMAP/vicmd/[NORMAL]}/(main|viins)/}}" } zle-keymap-slect() { diff --git a/modules/prompt/themes/gitster.zsh-theme b/modules/prompt/themes/gitster.zsh-theme index 8b9a870..ba88fd2 100644 --- a/modules/prompt/themes/gitster.zsh-theme +++ b/modules/prompt/themes/gitster.zsh-theme @@ -15,7 +15,8 @@ prompt_gitster_get_pwd() { prompt_gitster_precmd() { [[ ${+functions[git-info]} ]] && git-info - RPROMPT="${${KEYMAP/vicmd/[NORMAL]}/(main|viins)/}" + PROMPT='$(prompt_gitster_get_status)%F{white}$(prompt_gitster_get_pwd)${(e)git_info[prompt]}%f ' + RPROMPT="${ZIM_PROMPT_INSERTMODE:+${${KEYMAP/vicmd/[NORMAL]}/(main|viins)/}}" } zle-keymap-select() { @@ -39,9 +40,6 @@ prompt_gitster_setup() { zstyle ':zim:git-info:dirty' format '%F{yellow}✗' zstyle ':zim:git-info:keys' format \ 'prompt' ' %F{cyan}%b%c %C%D' - - PROMPT='$(prompt_gitster_get_status)%F{white}$(prompt_gitster_get_pwd)${(e)git_info[prompt]}%f ' - RPROMPT='' } prompt_gitster_setup "$@" diff --git a/modules/prompt/themes/magicmace.zsh-theme b/modules/prompt/themes/magicmace.zsh-theme index ea495e7..b58e908 100644 --- a/modules/prompt/themes/magicmace.zsh-theme +++ b/modules/prompt/themes/magicmace.zsh-theme @@ -45,7 +45,7 @@ prompt_magicmace_precmd() { git-info fi PROMPT='${COLOR_USER_LEVEL}$(prompt_magicmace_status)[${COLOR_NORMAL}$(short_pwd)${COLOR_USER_LEVEL}]${(e)git_info[prompt]}── ─%f ' - RPROMPT="${${KEYMAP/vicmd/[NORMAL]}/(main|viins)/}" + RPROMPT="${ZIM_PROMPT_INSERTMODE:+${${KEYMAP/vicmd/[NORMAL]}/(main|viins)/}}" } zle-keymap-select() { diff --git a/modules/prompt/themes/steeef.zsh-theme b/modules/prompt/themes/steeef.zsh-theme index 34400bb..496ec6c 100644 --- a/modules/prompt/themes/steeef.zsh-theme +++ b/modules/prompt/themes/steeef.zsh-theme @@ -40,7 +40,7 @@ prompt_steeef_precmd() { vcs_info 'prompt' fi - RPROMPT="${${KEYMAP/vicmd/[NORMAL]}/(main|viins)/}" + RPROMPT="${ZIM_PROMPT_INSERTMODE:+${${KEYMAP/vicmd/[NORMAL]}/(main|viins)/}}" PROMPT=' %{$purple%}%n${${reset_color}%} at %{$orange%}%m${${reset_color}%} in %{$limegreen%}%~${${reset_color}%} $vcs_info_msg_0_$(virtualenv_info)%{${reset_color}%} %(!.#.$) ' From 772ed865015a30f38bbd20795acc75484c4b63f2 Mon Sep 17 00:00:00 2001 From: Colin Jamison Date: Sat, 21 Jan 2017 18:15:25 +0100 Subject: [PATCH 3/3] Conditionally bind zle widget --- modules/prompt/themes/eriner.zsh-theme | 2 +- modules/prompt/themes/gitster.zsh-theme | 2 +- modules/prompt/themes/magicmace.zsh-theme | 2 ++ modules/prompt/themes/steeef.zsh-theme | 2 +- 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/modules/prompt/themes/eriner.zsh-theme b/modules/prompt/themes/eriner.zsh-theme index 3215eda..b67e286 100644 --- a/modules/prompt/themes/eriner.zsh-theme +++ b/modules/prompt/themes/eriner.zsh-theme @@ -157,7 +157,7 @@ prompt_eriner_setup() { add-zsh-hook prompt_eriner_precmd - zle -N zle-keymap-select + [[ "$ZIM_PROMPT_INSERTMODE" != '' ]] && zle -N zle-keymap-select zstyle ':vcs_info:*' enable git zstyle ':vcs_info:*' check-for-changes false diff --git a/modules/prompt/themes/gitster.zsh-theme b/modules/prompt/themes/gitster.zsh-theme index ba88fd2..4a1086a 100644 --- a/modules/prompt/themes/gitster.zsh-theme +++ b/modules/prompt/themes/gitster.zsh-theme @@ -32,7 +32,7 @@ prompt_gitster_setup() { add-zsh-hook precmd prompt_gitster_precmd - zle -N zle-keymap-select + [[ "$ZIM_PROMPT_INSERTMODE" != '' ]] && zle -N zle-keymap-select zstyle ':zim:git-info:branch' format '%b' zstyle ':zim:git-info:commit' format '%c' diff --git a/modules/prompt/themes/magicmace.zsh-theme b/modules/prompt/themes/magicmace.zsh-theme index b58e908..426cf90 100644 --- a/modules/prompt/themes/magicmace.zsh-theme +++ b/modules/prompt/themes/magicmace.zsh-theme @@ -61,6 +61,8 @@ prompt_magicmace_setup() { add-zsh-hook precmd prompt_magicmace_precmd + [[ "$ZIM_PROMPT_INSERTMODE" != '' ]] && zle -N zle-keymap-select + zstyle ':zim:git-info:branch' format '%b' zstyle ':zim:git-info:commit' format '%c...' zstyle ':zim:git-info:dirty' format '*' diff --git a/modules/prompt/themes/steeef.zsh-theme b/modules/prompt/themes/steeef.zsh-theme index 496ec6c..d711499 100644 --- a/modules/prompt/themes/steeef.zsh-theme +++ b/modules/prompt/themes/steeef.zsh-theme @@ -102,7 +102,7 @@ prompt_steeef_setup() { add-zsh-hook preexec steeef_preexec add-zsh-hook chpwd steeef_chpwd add-zsh-hook precmd prompt_steeef_precmd - zle -N zle-keymap-select + [[ "$ZIM_PROMPT_INSERTMODE" != '' ]] && zle -N zle-keymap-select prompt_opts=(cr subst percent) }