[zsh] carefully rewrite all prints to not produce escape sequences

This commit is contained in:
Dmytro Meleshko 2021-03-30 15:15:33 +03:00
parent 3d34200ac6
commit 5ebbadb45d
9 changed files with 21 additions and 21 deletions

View File

@ -11,8 +11,8 @@ install_dotfile() {
fi
mkdir -pv "${dest:h}"
echo "installing dotfile '$dest'"
echo "$contents" > "$dest"
print -r -- "installing dotfile '$dest'"
print -r -- "$contents" > "$dest"
}
# ZSH

View File

@ -77,7 +77,7 @@ alias free='free -h'
if command_exists apt && command_exists apt-get; then
apt_get_message="use 'apt' instead of 'apt-get'
if you really want to use 'apt-get', type '\\apt-get'"
alias apt-get="echo -E ${(qqq)apt_get_message} #"
alias apt-get="print -r -- ${(qqq)apt_get_message} #"
unset apt_get_message
fi

View File

@ -39,11 +39,11 @@ zstyle ':completion:*:processes-names' command "ps xho comm="
zstyle ':completion:*:processes' force-list always
_completion_get_hosts() {
print localhost
print -r -- localhost
local line
< ~/.ssh/config while IFS= read -r line; do
if [[ "$line" =~ '^Host[[:blank:]]+(.*)[[:blank:]]*' ]]; then
print -- "${match[1]}"
print -r -- "${match[1]}"
fi
done
}

View File

@ -1,6 +1,6 @@
#!/usr/bin/env zsh
count() { echo "$#"; }
count() { print -r -- "$#"; }
bytecount() { wc -c "$@" | numfmt --to=iec-i; }
@ -39,7 +39,7 @@ if (( ! _is_macos )); then
elif command_exists xdg-open; then
open_cmd='nohup xdg-open &> /dev/null'
else
open_cmd='print >&2 "open: Platform $OSTYPE is not supported"; return 1'
open_cmd='print >&2 -r -- "open: Platform $OSTYPE is not supported"; return 1'
fi
eval "open(){local f; for f in \"\$@\"; do $open_cmd \"\$f\"; done;}"
unset open_cmd
@ -55,8 +55,8 @@ elif command_exists termux-clipboard-set && command_exists termux-clipboard-get;
copy_cmd='termux-clipboard-set' paste_cmd='termux-clipboard-get'
else
error_msg='Platform $OSTYPE is not supported'
copy_cmd='print >&2 "clipcopy: '"$error_msg"'"; return 1'
paste_cmd='print >&2 "clippaste: '"$error_msg"'"; return 1'
copy_cmd='print >&2 -r -- "clipcopy: '"$error_msg"'"; return 1'
paste_cmd='print >&2 -r -- "clippaste: '"$error_msg"'"; return 1'
unset error_msg
fi
eval "clipcopy() { $copy_cmd; }; clippaste() { $paste_cmd; }"
@ -74,7 +74,7 @@ git_current_branch() {
command git symbolic-ref --quiet HEAD 2> /dev/null ||
command git rev-parse --short HEAD 2> /dev/null
)" || return
echo "${ref#refs/heads/}"
print -r -- "${ref#refs/heads/}"
}
declare -A date_formats=(

View File

@ -9,7 +9,7 @@ export -T LD_LIBRARY_PATH ld_library_path ':'
path_prepend() {
if (( $# < 1 )); then
print >&2 "usage: $0 <var_name> <value...>"
print >&2 -r -- "usage: $0 <var_name> <value...>"
return 1
fi
local var_name="$1"; shift

View File

@ -34,7 +34,7 @@ _plugin completions 'zsh-users/zsh-completions' "$_checkout_latest_version"
done; unset match
if (( $run_compdump )); then
echo "$0: rebuilding zsh completion dump"
print -r -- "$0: rebuilding zsh completion dump"
# -D flag turns off compdump loading
compinit -D
compdump
@ -98,7 +98,7 @@ _plugin completions 'zsh-users/zsh-completions' "$_checkout_latest_version"
if [[ -d "$_fasd_ret" ]]; then
cd -- "$_fasd_ret"
elif [[ -n "$_fasd_ret" ]]; then
print -- "$_fasd_ret"
print -r -- "$_fasd_ret"
fi
}
fi

View File

@ -3,7 +3,7 @@
# Escapes `%` in all arguments by replacing it with `%%`. Escaping is needed so
# that untrusted input (e.g. git branch names) doesn't affect prompt rendering.
prompt_escape() {
print -n "${@//\%/%%}"
print -rn -- "${@//\%/%%}"
}
prompt_preexec_hook() {
@ -51,7 +51,7 @@ prompt_vcs_info() {
fi
done
print -n ' %F{blue}git:%F{magenta}'"$(prompt_escape "$branch")"'%f'
print -rn -- ' %F{blue}git:%F{magenta}'"$(prompt_escape "$branch")"'%f'
}
# configure prompt expansion

View File

@ -60,9 +60,9 @@
_palette_widget() {
# download "TLDR pages" if we don't have them
if [[ ! -d "$PALETTE_TLDR_PAGES_DIR" ]]; then
echo
print -r
_palette_download_tldr_pages
echo
print -r
fi
# try to fill in a placeholder if there're any, otherwise pick a snippet
@ -118,12 +118,12 @@
# This function downloads the "TLDR pages"
_palette_download_tldr_pages() {
mkdir -pv "$PALETTE_TLDR_PAGES_DIR"
echo "Downloading tldr pages..."
print -r -- "Downloading tldr pages..."
if curl -Lf https://github.com/tldr-pages/tldr/archive/master.tar.gz |
tar -C "$PALETTE_TLDR_PAGES_DIR" --gzip --strip-components 2 --extract tldr-master/pages
then
echo "Done!"
print -r -- "Done!"
fi
}

View File

@ -51,7 +51,7 @@ _ZPLG_PLUGINS_DIR="$ZPLG_HOME/plugins"
# basic logging {{{
_zplg_log() {
print >&2 "${fg_bold[blue]}[zplg]${reset_color} $@"
print >&2 -r -- "${fg_bold[blue]}[zplg]${reset_color} $@"
}
_zplg_debug() {
@ -455,7 +455,7 @@ _zplg_is_plugin_loaded() {
# Prints IDs of all loaded plugins.
zplg-list() {
# (F) modifier joins an array with newlines
print "${(F)ZPLG_LOADED_PLUGINS}"
print -r -- "${(F)ZPLG_LOADED_PLUGINS}"
}
# Upgrades all plugins if no arguments are given, otherwise upgrades plugins by