mirror of
https://github.com/dcarrillo/prezto.git
synced 2026-04-18 14:24:06 +00:00
general: Escapes a string for safe use in parameter expansion
This commit is contained in:
committed by
Indrajit Raychaudhuri
parent
371aaa254a
commit
5464030f6a
@@ -246,7 +246,7 @@ function git-info {
|
||||
fi
|
||||
|
||||
# Get the branch.
|
||||
branch="${$(command git symbolic-ref HEAD 2> /dev/null)#refs/heads/}"
|
||||
branch="$(escape-eval "${$(command git symbolic-ref HEAD 2> /dev/null)#refs/heads/}")"
|
||||
|
||||
# Format branch.
|
||||
zstyle -s ':prezto:module:git:info:branch' format 'branch_format'
|
||||
@@ -257,7 +257,7 @@ function git-info {
|
||||
# Format position.
|
||||
zstyle -s ':prezto:module:git:info:position' format 'position_format'
|
||||
if [[ -z "$branch" && -n "$position_format" ]]; then
|
||||
position="$(command git describe --contains --all HEAD 2> /dev/null)"
|
||||
position="$(escape-eval "$(command git describe --contains --all HEAD 2> /dev/null)")"
|
||||
if [[ -n "$position" ]]; then
|
||||
zformat -f position_formatted "$position_format" "p:$position"
|
||||
fi
|
||||
@@ -268,7 +268,7 @@ function git-info {
|
||||
if [[ -n "$branch" && -n "$remote_format" ]]; then
|
||||
# Gets the remote name.
|
||||
remote_cmd='command git rev-parse --symbolic-full-name --verify HEAD@{upstream}'
|
||||
remote="${$(${(z)remote_cmd} 2> /dev/null)##refs/remotes/}"
|
||||
remote="$(escape-eval "${$(${(z)remote_cmd} 2> /dev/null)##refs/remotes/}")"
|
||||
if [[ -n "$remote" ]]; then
|
||||
zformat -f remote_formatted "$remote_format" "R:$remote"
|
||||
fi
|
||||
|
||||
13
modules/helper/functions/escape-eval
Normal file
13
modules/helper/functions/escape-eval
Normal file
@@ -0,0 +1,13 @@
|
||||
#
|
||||
# Escapes a string for safe use in ${(e)...} parameter expansion.
|
||||
#
|
||||
# Authors:
|
||||
# Trey Keown <trey@crystalpeaksecurity.com>
|
||||
#
|
||||
|
||||
# function escape-eval {
|
||||
|
||||
setopt LOCAL_OPTIONS EXTENDED_GLOB
|
||||
print -r -- "${1//(#m)[\\\$\`]/\\$MATCH}"
|
||||
|
||||
# }
|
||||
@@ -117,7 +117,7 @@ function prompt_cloud_setup {
|
||||
'rprompt' ''
|
||||
|
||||
# Define prompts.
|
||||
PROMPT='%B%F{$primary_color}${prefix}%f%b %B%F{$secondary_color}%c%f%b ${git_info:+${(e)git_info[prompt]}} '
|
||||
PROMPT='%B%F{$primary_color}${prefix}%f%b %B%F{$secondary_color}%c%f%b ${git_info:+$(escape-eval ${(e)git_info[prompt]})} '
|
||||
RPROMPT=''
|
||||
}
|
||||
|
||||
|
||||
@@ -62,7 +62,7 @@ function prompt_damoekri_setup {
|
||||
|
||||
# Define prompts.
|
||||
PROMPT='%F{cyan}${_prompt_damoekri_pwd}%f${editor_info[keymap]} '
|
||||
RPROMPT='${git_info:+${(e)git_info[rprompt]}}${ruby_info:+${ruby_info[version]}}'
|
||||
RPROMPT='${git_info:+$(escape-eval "${(e)git_info[rprompt]}")}${ruby_info:+$(escape-eval "${(e)ruby_info[version]}")}'
|
||||
}
|
||||
|
||||
prompt_damoekri_setup "$@"
|
||||
|
||||
@@ -61,7 +61,7 @@ function prompt_kylewest_setup {
|
||||
zstyle ':prezto:module:ruby:info:version' format '%F{blue}[%v]%f'
|
||||
|
||||
# Define prompts.
|
||||
PROMPT='%F{cyan}%c%f ${git_info:+${(e)git_info[prompt]}}${editor_info[keymap]} '
|
||||
PROMPT='%F{cyan}%c%f ${git_info:+$(escape-eval ${(e)git_info[prompt]})}${editor_info[keymap]} '
|
||||
RPROMPT='${ruby_info[version]}'
|
||||
}
|
||||
|
||||
|
||||
@@ -50,11 +50,11 @@ function prompt_paradox_build_prompt {
|
||||
prompt_paradox_start_segment blue black '$_prompt_paradox_pwd'
|
||||
|
||||
if [[ -n "$git_info" ]]; then
|
||||
prompt_paradox_start_segment green black '${(e)git_info[ref]}${(e)git_info[status]}'
|
||||
prompt_paradox_start_segment green black '$(escape-eval "${(e)git_info[ref]}${(e)git_info[status]}")'
|
||||
fi
|
||||
|
||||
if [[ -n "$python_info" ]]; then
|
||||
prompt_paradox_start_segment white black '${(e)python_info[virtualenv]}'
|
||||
prompt_paradox_start_segment white black '$(escape-eval "${(e)python_info[virtualenv]}")'
|
||||
fi
|
||||
|
||||
prompt_paradox_end_segment
|
||||
|
||||
@@ -71,7 +71,7 @@ function prompt_skwp_setup {
|
||||
zstyle ':prezto:module:ruby:info:version' format '[%v]'
|
||||
|
||||
# Define prompts.
|
||||
PROMPT="${_prompt_skwp_colors[3]}%n%f@${_prompt_skwp_colors[2]}%m%f ${_prompt_skwp_colors[5]}%~%f "'${git_info:+${(e)git_info[prompt]}}'"$ "
|
||||
PROMPT="${_prompt_skwp_colors[3]}%n%f@${_prompt_skwp_colors[2]}%m%f ${_prompt_skwp_colors[5]}%~%f "'${git_info:+$(escape-eval "${(e)git_info[prompt]}")}'"$ "
|
||||
RPROMPT='%F{blue}${ruby_info[version]}'
|
||||
}
|
||||
|
||||
|
||||
@@ -60,7 +60,7 @@ function prompt_smiley_setup {
|
||||
zstyle ':prezto:module:git:info:keys' format 'prompt' '(%b%D)'
|
||||
|
||||
# Define prompts.
|
||||
PROMPT='$python_info[virtualenv]$ruby_info[version]${git_info:+${(e)git_info[prompt]}} %B%c%b %(?:%F{green}ツ%f:%F{red}✖%f) '
|
||||
PROMPT='$python_info[virtualenv]$ruby_info[version]${git_info:+$(escape-eval ${(e)git_info[prompt]})} %B%c%b %(?:%F{green}ツ%f:%F{red}✖%f) '
|
||||
RPROMPT='${editor_info[overwrite]}${VIM:+" %B%F{green}V%f%b"}'
|
||||
SPROMPT='zsh: correct %F{red}%R%f to %F{green}%r%f [nyae]? '
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user