From 2e7d0f14d2a355427609e93c32fd9f8b219db7f3 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Mon, 21 Sep 2015 18:34:43 +0200 Subject: [PATCH 1/6] Shellcheck-support for vi_mode segment & alphabetical order of prompts. --- powerlevel9k.zsh-theme | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 86fc2c42..19a8bbb3 100644 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -576,16 +576,6 @@ prompt_context() { fi } -# Vi Mode: show editing mode (NORMAL|INSERT) -prompt_vi_mode() { - local mode="${${KEYMAP/vicmd/NORMAL}/(main|viins)/INSERT}" - if [[ "$mode" == "NORMAL" ]]; then - $1_prompt_segment "$0_NORMAL" "$DEFAULT_COLOR" "default" "$mode" - else - $1_prompt_segment "$0_INSERT" "$DEFAULT_COLOR" "blue" "$mode" - fi -} - # Dir: current working directory prompt_dir() { local current_path='%~' @@ -821,6 +811,16 @@ prompt_time() { "$1_prompt_segment" "$0" "$DEFAULT_COLOR_INVERTED" "$DEFAULT_COLOR" "$time_format" } +# Vi Mode: show editing mode (NORMAL|INSERT) +prompt_vi_mode() { + local mode="${${KEYMAP/vicmd/NORMAL}/(main|viins)/INSERT}" + if [[ "$mode" == "NORMAL" ]]; then + "$1_prompt_segment" "$0_NORMAL" "$DEFAULT_COLOR" "default" "$mode" + else + "$1_prompt_segment" "$0_INSERT" "$DEFAULT_COLOR" "blue" "$mode" + fi +} + # Virtualenv: current working virtualenv # More information on virtualenv (Python): # https://virtualenv.pypa.io/en/latest/ From b31d0ff3950c091cb5f0aa34abc664a4790affc8 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Tue, 22 Sep 2015 18:30:59 +0200 Subject: [PATCH 2/6] Made VI-Mode plugin working again. --- powerlevel9k.zsh-theme | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 19a8bbb3..479c6880 100644 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -880,6 +880,11 @@ $(print_icon 'MULTILINE_SECOND_PROMPT_PREFIX')" fi } +function zle-line-init zle-keymap-select { + powerlevel9k_prepare_prompts + zle reset-prompt +} + powerlevel9k_init() { # Display a warning if the terminal does not support 256 colors local term_colors @@ -902,6 +907,9 @@ powerlevel9k_init() { # prepare prompts add-zsh-hook precmd powerlevel9k_prepare_prompts + + zle -N zle-line-init + zle -N zle-keymap-select } powerlevel9k_init "$@" From fc59f06f39628ddffbad89907988551bd86f7d19 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Tue, 22 Sep 2015 18:35:42 +0200 Subject: [PATCH 3/6] code more readable. --- powerlevel9k.zsh-theme | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 479c6880..7fb283dd 100644 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -813,12 +813,14 @@ prompt_time() { # Vi Mode: show editing mode (NORMAL|INSERT) prompt_vi_mode() { - local mode="${${KEYMAP/vicmd/NORMAL}/(main|viins)/INSERT}" - if [[ "$mode" == "NORMAL" ]]; then - "$1_prompt_segment" "$0_NORMAL" "$DEFAULT_COLOR" "default" "$mode" - else - "$1_prompt_segment" "$0_INSERT" "$DEFAULT_COLOR" "blue" "$mode" - fi + case ${KEYMAP} in + main) + "$1_prompt_segment" "$0_INSERT" "$DEFAULT_COLOR" "blue" "INSERT" + ;; + *) + "$1_prompt_segment" "$0_NORMAL" "$DEFAULT_COLOR" "default" "NORMAL" + ;; + esac } # Virtualenv: current working virtualenv From 0b37ca2869577426cebca6a7d15cc92f5ab51b91 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Tue, 22 Sep 2015 18:43:06 +0200 Subject: [PATCH 4/6] Added documentation. --- README.md | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 98033e79..07e16992 100644 --- a/README.md +++ b/README.md @@ -233,7 +233,6 @@ currently available are: * **aws** - The current AWS profile, if active (more info below) * **context** - Your username and host (more info below) -* **vi_mode** - Vi editing mode (NORMAL|INSERT). * **dir** - Your current working directory. * **history** - The command number for the current line. * **ip** - Shows the current IP address. @@ -248,6 +247,7 @@ currently available are: * **symfony2_tests** - Show a ratio of test classes vs code classes for Symfony2. * **symfony2_version** - Show the current Symfony2 version, if you are in a Symfony2-Project dir. * **time** - System time. +* **vi_mode** - Vi editing mode (NORMAL|INSERT). * **virtualenv** - Your Python [VirtualEnv](https://virtualenv.pypa.io/en/latest/). * **vcs** - Information about this `git` or `hg` repository (if you are in one). @@ -330,6 +330,26 @@ is count your source files and test files, and calculate the ratio between them. Just enough to give you a quick overview about the test situation of the project you are dealing with. +#### VI-Mode Indicator + +This Segment shows the current mode of your ZSH. If you want to use your ZSH in +VI-Mode, you need to configure it separatly in your `~/.zshrc`: + + # VI-Mode + # general activation + bindkey -v + + # set some nice hotkeys + bindkey '^P' up-history + bindkey '^N' down-history + bindkey '^?' backward-delete-char + bindkey '^h' backward-delete-char + bindkey '^w' backward-kill-word + bindkey '^r' history-incremental-search-backward + + # make it more responsive + export KEYTIMEOUT=1 + #### The 'vcs' Segment By default, the `vcs` segment will provide quite a bit of information. If you From ffc0d9e162e8e80b7554a33a863e57911813c68d Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Wed, 23 Sep 2015 18:26:27 +0200 Subject: [PATCH 5/6] KEYMAP may be "main" or "viins" in VI-Mode. --- powerlevel9k.zsh-theme | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 7fb283dd..9e3a034b 100644 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -814,10 +814,10 @@ prompt_time() { # Vi Mode: show editing mode (NORMAL|INSERT) prompt_vi_mode() { case ${KEYMAP} in - main) + main|viins) "$1_prompt_segment" "$0_INSERT" "$DEFAULT_COLOR" "blue" "INSERT" ;; - *) + vicmd) "$1_prompt_segment" "$0_NORMAL" "$DEFAULT_COLOR" "default" "NORMAL" ;; esac From c760d3a5057698cd220caec1334403fc028f46f6 Mon Sep 17 00:00:00 2001 From: Dominik Ritter Date: Wed, 23 Sep 2015 18:29:42 +0200 Subject: [PATCH 6/6] Better compatibility with shellcheck.net. --- powerlevel9k.zsh-theme | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 9e3a034b..84e7cb87 100644 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -882,7 +882,12 @@ $(print_icon 'MULTILINE_SECOND_PROMPT_PREFIX')" fi } -function zle-line-init zle-keymap-select { +function zle-line-init { + powerlevel9k_prepare_prompts + zle reset-prompt +} + +function zle-keymap-select { powerlevel9k_prepare_prompts zle reset-prompt }