Skip to content

Commit

Permalink
Restore prompt_subst setopt when rendering prompt (#231)
Browse files Browse the repository at this point in the history
We store the user setting for `prompt_subst` before changing it in the
local scope of `prompt_pure_preprompt_render`. This allows us to restore
it when we render the real prompt (`PS1`) through `zle .redraw-prompt`.

Fixes #230.
  • Loading branch information
mafredri committed Sep 20, 2016
1 parent d826130 commit 5ccc336
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion pure.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,10 @@ prompt_pure_string_length_to_var() {
}

prompt_pure_preprompt_render() {
# make sure prompt_subst is unset to prevent parameter expansion in prompt
# store the current prompt_subst setting so that it can be restored later
local prompt_subst_status=$options[prompt_subst]

# make sure prompt_subst is unset to prevent parameter expansion in preprompt
setopt local_options no_prompt_subst

# check that no command is currently running, the preprompt will otherwise be rendered in the wrong place
Expand Down Expand Up @@ -192,6 +195,11 @@ prompt_pure_preprompt_render() {
# modify previous preprompt
print -Pn "${clr_prev_preprompt}\e[${lines}A\e[${COLUMNS}D${preprompt}${clr}\n"

if [[ $prompt_subst_status = 'on' ]]; then
# re-eanble prompt_subst for expansion on PS1
setopt prompt_subst
fi

# redraw prompt (also resets cursor position)
zle && zle .reset-prompt
fi
Expand Down Expand Up @@ -324,6 +332,8 @@ prompt_pure_setup() {

zmodload zsh/datetime
zmodload zsh/zle
zmodload zsh/parameter

autoload -Uz add-zsh-hook
autoload -Uz vcs_info
autoload -Uz async && async
Expand Down

0 comments on commit 5ccc336

Please sign in to comment.