aboutsummaryrefslogtreecommitdiff
path: root/zsh
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2017-07-05 12:51:01 +1200
committerTom Ryder <tom@sanctum.geek.nz>2017-07-05 13:00:20 +1200
commitba883a5f183edaaa440eb1a41cb6dbd595d55a87 (patch)
tree23f3c3d8e937ef6b2dd045c1d2dfc9cd1194fd48 /zsh
parentfd2b6fd3bbe4919a1d4560e788fc66db742c0c6d (diff)
downloaddotfiles-ba883a5f183edaaa440eb1a41cb6dbd595d55a87.tar.gz
Escape % signs in prompt command output
The Zsh analogue of fd2b6fd. This one matters a bit more, as e.g. "%test" is a legal Git branch name. A generic fix for this for Korn shell will be tough, as some of them seem to use backslash escape sequences and others don't. None of the prompt commands *should* emit backslashes, and it doesn't allow remote execution, so I might just leave that.
Diffstat (limited to 'zsh')
-rw-r--r--zsh/zshrc.d/prompt.zsh14
1 files changed, 10 insertions, 4 deletions
diff --git a/zsh/zshrc.d/prompt.zsh b/zsh/zshrc.d/prompt.zsh
index 7c695e25..b612c704 100644
--- a/zsh/zshrc.d/prompt.zsh
+++ b/zsh/zshrc.d/prompt.zsh
@@ -125,7 +125,10 @@ prompt() {
# Print the status in brackets; add a git: prefix only if there
# might be another VCS prompt (because PROMPT_VCS is set)
printf '(%s%s%s%s)' \
- "${PROMPT_VCS:+git:}" "$name" "${proc:+:"$proc"}" "$state"
+ "${PROMPT_VCS:+git:}" \
+ "${name//\%/%%}" \
+ "${proc:+:"${proc//\%/%%}"}" \
+ "${state//\%/%%}"
;;
# Subversion prompt function
@@ -151,6 +154,7 @@ prompt() {
branch=${branch#/}
branch=${branch#branches/}
branch=${branch%%/*}
+ [[ -n $branch ]] || branch=unknown
# Parse the output of svn status to determine working copy state
local symbol
@@ -168,7 +172,9 @@ prompt() {
((untracked)) && state=${state}'?'
# Print the state in brackets with an svn: prefix
- printf '(svn:%s%s)' "${branch:-unknown}" "$state"
+ printf '(svn:%s%s)' \
+ "${branch//\%/%%}" \
+ "${state//\%/%%}"
;;
# VCS wrapper prompt function; print the first relevant prompt, if any
@@ -182,7 +188,7 @@ prompt() {
# Show return status of previous command in angle brackets, if not zero
ret)
# shellcheck disable=SC2154
- ((ret)) && printf '<%u>' "$ret"
+ ((ret)) && printf '<%u>' "${ret//\%/%%}"
;;
# Show the count of background jobs in curly brackets, if not zero
@@ -191,7 +197,7 @@ prompt() {
while read -r ; do
((jobc++))
done < <(jobs -p)
- ((jobc)) && printf '{%u}' "$jobc"
+ ((jobc)) && printf '{%u}' "${jobc//\%/%%}"
;;
# No argument given, print prompt strings and vars