Skip to content

Commit

Permalink
Add support for VI-mode indicator
Browse files Browse the repository at this point in the history
When merged, we can remove the VI-mode references from the Wiki.

Related: sindresorhus#308, sindresorhus#208, sindresorhus#184 and sindresorhus#98.
  • Loading branch information
mafredri committed May 8, 2018
1 parent d472db9 commit 498e423
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
30 changes: 28 additions & 2 deletions pure.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,9 @@ prompt_pure_precmd() {
export VIRTUAL_ENV_DISABLE_PROMPT=12
fi

# Make sure VIM prompt is reset.
prompt_pure_reset_vim_prompt

# print the preprompt
prompt_pure_preprompt_render "precmd"
}
Expand Down Expand Up @@ -481,6 +484,18 @@ prompt_pure_async_callback() {
unset prompt_pure_async_render_requested
}

prompt_pure_update_vim_prompt() {
setopt localoptions noshwordsplit
prompt_pure_state[prompt]=${${KEYMAP/vicmd/${PURE_PROMPT_VICMD_SYMBOL:-❮}}/(main|viins)/${PURE_PROMPT_SYMBOL:-❯}}
zle && zle .reset-prompt
}

prompt_pure_reset_vim_prompt() {
setopt localoptions noshwordsplit
prompt_pure_state[prompt]=${PURE_PROMPT_SYMBOL:-❯}
zle && zle .reset-prompt
}

prompt_pure_state_setup() {
setopt localoptions noshwordsplit

Expand All @@ -501,7 +516,10 @@ prompt_pure_state_setup() {
[[ $UID -eq 0 ]] && username='%F{white}%n%f%F{242}@%m%f'

typeset -gA prompt_pure_state
prompt_pure_state=(username "$username")
prompt_pure_state=(
username "$username"
prompt "${PURE_PROMPT_SYMBOL:-❯}"
)
}

prompt_pure_setup() {
Expand All @@ -524,6 +542,7 @@ prompt_pure_setup() {
zmodload zsh/parameter

autoload -Uz add-zsh-hook
autoload -Uz add-zle-hook-widget
autoload -Uz vcs_info
autoload -Uz async && async

Expand All @@ -532,11 +551,18 @@ prompt_pure_setup() {

prompt_pure_state_setup

zle -N prompt_pure_update_vim_prompt
zle -N prompt_pure_reset_vim_prompt
if (( $+functions[add-zle-hook-widget] )); then
add-zle-hook-widget zle-line-finish prompt_pure_reset_vim_prompt
add-zle-hook-widget zle-keymap-select prompt_pure_update_vim_prompt
fi

# if a virtualenv is activated, display it in grey
PROMPT='%(12V.%F{242}%12v%f .)'

# prompt turns red if the previous command didn't exit with 0
PROMPT+='%(?.%F{magenta}.%F{red})${PURE_PROMPT_SYMBOL:-❯}%f '
PROMPT+='%(?.%F{magenta}.%F{red})${prompt_pure_state[prompt]}%f '

# Store prompt expansion symbols for in-place expansion via (%). For
# some reason it does not work without storing them in a variable first.
Expand Down
2 changes: 2 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Most prompts are cluttered, ugly and slow. I wanted something visually pleasing
- Command execution time will be displayed if it exceeds the set threshold.
- Username and host only displayed when in an SSH session.
- Shows the current path in the title and the [current folder & command](screenshot-title-cmd.png) when a process is running.
- Support VI-mode indication by reverse prompt symbol.
- Makes an excellent starting point for your own custom prompt.


Expand Down Expand Up @@ -88,6 +89,7 @@ prompt pure
| **`PURE_GIT_UNTRACKED_DIRTY=0`** | Do not include untracked files in dirtiness check. Mostly useful on large repos (like WebKit). | |
| **`PURE_GIT_DELAY_DIRTY_CHECK`** | Time in seconds to delay git dirty checking when `git status` takes > 5 seconds. | `1800` seconds |
| **`PURE_PROMPT_SYMBOL`** | Defines the prompt symbol. | `` |
| **`PURE_PROMPT_VICMD_SYMBOL`** | Defines the prompt symbol used when the `vicmd` keymap is active (VI-mode). | `` |
| **`PURE_GIT_DOWN_ARROW`** | Defines the git down arrow symbol. | `` |
| **`PURE_GIT_UP_ARROW`** | Defines the git up arrow symbol. | `` |

Expand Down

0 comments on commit 498e423

Please sign in to comment.