From 5ebbadb45d8fa31fde887a63f2b258c2989326e6 Mon Sep 17 00:00:00 2001 From: Dmytro Meleshko Date: Tue, 30 Mar 2021 15:15:33 +0300 Subject: [PATCH] [zsh] carefully rewrite all prints to not produce escape sequences --- install.zsh | 4 ++-- zsh/aliases.zsh | 2 +- zsh/completion.zsh | 4 ++-- zsh/functions.zsh | 10 +++++----- zsh/path.zsh | 2 +- zsh/plugins.zsh | 4 ++-- zsh/prompt.zsh | 4 ++-- zsh/zle.zsh | 8 ++++---- zsh/zplg.zsh | 4 ++-- 9 files changed, 21 insertions(+), 21 deletions(-) diff --git a/install.zsh b/install.zsh index 7968da3..f816480 100755 --- a/install.zsh +++ b/install.zsh @@ -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 diff --git a/zsh/aliases.zsh b/zsh/aliases.zsh index e75e872..c82c197 100644 --- a/zsh/aliases.zsh +++ b/zsh/aliases.zsh @@ -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 diff --git a/zsh/completion.zsh b/zsh/completion.zsh index faa7748..b9fcf35 100644 --- a/zsh/completion.zsh +++ b/zsh/completion.zsh @@ -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 } diff --git a/zsh/functions.zsh b/zsh/functions.zsh index e008988..f7775a7 100644 --- a/zsh/functions.zsh +++ b/zsh/functions.zsh @@ -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=( diff --git a/zsh/path.zsh b/zsh/path.zsh index 110644a..be0077b 100644 --- a/zsh/path.zsh +++ b/zsh/path.zsh @@ -9,7 +9,7 @@ export -T LD_LIBRARY_PATH ld_library_path ':' path_prepend() { if (( $# < 1 )); then - print >&2 "usage: $0 " + print >&2 -r -- "usage: $0 " return 1 fi local var_name="$1"; shift diff --git a/zsh/plugins.zsh b/zsh/plugins.zsh index 322707d..df70f1d 100644 --- a/zsh/plugins.zsh +++ b/zsh/plugins.zsh @@ -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 diff --git a/zsh/prompt.zsh b/zsh/prompt.zsh index aa79b0e..a47c2dc 100644 --- a/zsh/prompt.zsh +++ b/zsh/prompt.zsh @@ -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 diff --git a/zsh/zle.zsh b/zsh/zle.zsh index fd96c33..2d0ee56 100644 --- a/zsh/zle.zsh +++ b/zsh/zle.zsh @@ -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 } diff --git a/zsh/zplg.zsh b/zsh/zplg.zsh index f6a16bf..f087602 100644 --- a/zsh/zplg.zsh +++ b/zsh/zplg.zsh @@ -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