Unverified Commit 58969b20 authored by Mark Vander Stel's avatar Mark Vander Stel
Browse files

Stop squashing Zsh prompt options

Based on the work done in ecdde384, the
prompt_bang and prompt_subst options, which handle '!' and '$'/'`'
characters respectively, can be left untouched. When running
__lp_escape(), those options are checked, and if set, their characters
are escaped.

prompt_percent however, must still be enabled always. The shell sequence
escapes, '%{' and '%}' only work when the option is enabled. Maybe
someday we can detect when the option is off and disable all terminal
formatting, but it doesn't seem worth the effort.

Backslashes must be escaped even on Zsh to prevent confusion with a
backslash directly preceding a character that would give is special
meaning.
parent a1d0a540
......@@ -75,7 +75,15 @@ elif test -n "${ZSH_VERSION-}" ; then
_LP_CLEAN_ESC='%\{([^%]+|%[^}])*%\}'
__lp_escape() {
ret="${1//\%/%%}"
ret="${1//\\/\\\\}"
ret="${ret//\%/%%}"
if [[ -o promptbang ]]; then
ret="${ret//!/!!}"
fi
if [[ -o promptsubst ]]; then
ret="${ret//\$/\\\$}"
ret="${ret//\`/\\\`}"
fi
}
else
echo "liquidprompt: shell not supported" >&2
......@@ -3040,7 +3048,7 @@ prompt_on() {
fi
_LP_OLD_SETOPT=()
# Dump option names: echo ${(ko)options}
for o in promptpercent promptbang promptsubst
for o in promptpercent
do
if [[ "${options[$o]}" = on ]]; then
_LP_OLD_SETOPT+=("$o")
......@@ -3065,9 +3073,8 @@ prompt_on() {
(( LP_DEBUG_TIME )) && PROMPT_COMMAND="time $PROMPT_COMMAND" || true
else # zsh
[[ -n "${_LP_ZSH_HOOK-}" ]] && add-zsh-hook -d precmd "$_LP_ZSH_HOOK"
# Set options that affect PS1 evaluation
# Disable parameter/command expansion; enable percent expansion
setopt promptpercent nopromptbang nopromptsubst
# Set options that affect PS1 evaluation; enable percent expansion
setopt promptpercent
# 'time' doesn't seem to work on shell functions: no time output
#if (( LP_DEBUG_TIME )); then
# _lp_main_precmd() {
......@@ -3101,7 +3108,7 @@ prompt_OFF() {
PROMPT_COMMAND="$LP_OLD_PROMPT_COMMAND"
else # zsh
add-zsh-hook -d precmd "$_LP_ZSH_HOOK"
setopt promptpercent nopromptbang nopromptsubst
setopt promptpercent
fi
}
......
......@@ -315,7 +315,7 @@ function test_path_format_from_path_left() {
_lp_path_format ''
if (( _LP_SHELL_zsh )); then
assertEquals "shell escapes" $'/a_fake_\\n_newline/and_%100_fresh/and_a_real_\n_newline' "$lp_path"
assertEquals "shell escapes format" $'/a_fake_\\n_newline/and_%%100_fresh/and_a_real_\n_newline' "$lp_path_format"
assertEquals "shell escapes format" $'/a_fake_\\\\n_newline/and_%%100_fresh/and_a_real_\n_newline' "$lp_path_format"
else
assertEquals "shell escapes" $'/a_fake_\\n_newline/and_%100_fresh/and_a_real_\n_newline' "$lp_path"
assertEquals "shell escapes format" $'/a_fake_\\\\n_newline/and_%100_fresh/and_a_real_\n_newline' "$lp_path_format"
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment