From 84a21f8cfb1256011a6986de1191a6a81c4bdb4b Mon Sep 17 00:00:00 2001 From: Frank LENORMAND Date: Tue, 15 Mar 2016 13:25:47 +0200 Subject: [PATCH] Replace non POSIX calls to `echo` with `printf %s` --- rc/base/ctags.kak | 6 +++--- rc/base/lua.kak | 12 ++++++------ rc/base/spell.kak | 10 +++++----- rc/core/c-family.kak | 10 +++++----- rc/core/commenting.kak | 10 +++++----- rc/core/doc.kak | 12 ++++++------ rc/core/formatter.kak | 4 ++-- rc/core/grep.kak | 2 +- rc/core/make.kak | 2 +- rc/core/man.kak | 10 +++++----- rc/core/tmux.kak | 10 +++++----- rc/core/x11.kak | 6 +++--- rc/extra/autorestore.kak | 6 +++--- rc/extra/clang.kak | 29 ++++++++++++++++++++--------- rc/extra/editorconfig.kak | 2 +- rc/extra/git-tools.kak | 32 ++++++++++++++++---------------- rc/extra/jedi.kak | 6 +++--- rc/extra/modeline.kak | 14 +++++++------- rc/extra/moon.kak | 12 ++++++------ rc/extra/tmux-repl.kak | 6 +++--- rc/extra/x11-repl.kak | 4 ++-- 21 files changed, 108 insertions(+), 97 deletions(-) diff --git a/rc/base/ctags.kak b/rc/base/ctags.kak index ca31cbab..8c970553 100644 --- a/rc/base/ctags.kak +++ b/rc/base/ctags.kak @@ -34,7 +34,7 @@ def tag-complete -docstring "Insert completion candidates for the current select %sh{ ( compl=$(readtags -p "$kak_selection" | cut -f 1 | sort | uniq | sed -e 's/:/\\:/g' | sed -e 's/\n/:/g' ) compl="${kak_cursor_line}.${kak_cursor_column}+${#kak_selection}@${kak_timestamp}:${compl}" - echo "set buffer=$kak_bufname ctags_completions '${compl}'" | kak -p ${kak_session} + printf %s "set buffer=$kak_bufname ctags_completions '${compl}'" | kak -p ${kak_session} ) > /dev/null 2>&1 < /dev/null & } }} @@ -45,7 +45,7 @@ def ctags-funcinfo -docstring "Display ctags information about a selected functi %sh{ sigs=$(readtags -e ${kak_selection%(} | grep kind:f | sed -re 's/^(\S+).*((class|struct|namespace):(\S+))?.*signature:(.*)$/\5 [\4::\1]/') if [ -n "$sigs" ]; then - echo "eval -client ${kak_client} %{info -anchor $kak_cursor_line.$kak_cursor_column -placement above '$sigs'}" + printf %s "eval -client ${kak_client} %{info -anchor $kak_cursor_line.$kak_cursor_column -placement above '$sigs'}" fi } } @@ -75,7 +75,7 @@ def ctags-generate -docstring 'Generate tag file asynchronously' %{ msg="tags generation failed" fi - echo "eval -client $kak_client echo -color Information '${msg}'" | kak -p ${kak_session} + printf %s "eval -client $kak_client echo -color Information '${msg}'" | kak -p ${kak_session} ) > /dev/null 2>&1 < /dev/null & } } diff --git a/rc/base/lua.kak b/rc/base/lua.kak index 7a30c4e0..83c861dc 100644 --- a/rc/base/lua.kak +++ b/rc/base/lua.kak @@ -35,12 +35,12 @@ addhl -group /lua/code regex \b(and|break|do|else|elseif|end|false|for|function| def lua-alternative-file -docstring 'Jump to the alternate file (implementation ↔ test)' %{ %sh{ case $kak_buffile in *spec/*_spec.lua) - altfile=$(eval echo $(echo $kak_buffile | sed s+spec/+'*'/+';'s/_spec//)) - [ ! -f $altfile ] && echo "echo -color Error 'implementation file not found'" && exit + altfile=$(eval printf %s $(printf %s $kak_buffile | sed s+spec/+'*'/+';'s/_spec//)) + [ ! -f $altfile ] && printf %s "echo -color Error 'implementation file not found'" && exit ;; *.lua) path=$kak_buffile - dirs=$(while [ $path ]; do echo $path; path=${path%/*}; done | tail -n +2) + dirs=$(while [ $path ]; do printf %s $path; path=${path%/*}; done | tail -n +2) for dir in $dirs; do altdir=$dir/spec if [ -d $altdir ]; then @@ -48,13 +48,13 @@ def lua-alternative-file -docstring 'Jump to the alternate file (implementation break fi done - [ ! -d $altdir ] && echo "echo -color Error 'spec/ not found'" && exit + [ ! -d $altdir ] && printf %s "echo -color Error 'spec/ not found'" && exit ;; *) - echo "echo -color Error 'alternative file not found'" && exit + printf %s "echo -color Error 'alternative file not found'" && exit ;; esac - echo "edit $altfile" + printf %s "edit $altfile" }} def -hidden _lua_filter_around_selections %{ diff --git a/rc/base/spell.kak b/rc/base/spell.kak index 270237cd..bacff0c7 100644 --- a/rc/base/spell.kak +++ b/rc/base/spell.kak @@ -5,13 +5,13 @@ def -params ..1 spell -docstring "Check spelling of the current buffer with aspe try %{ addhl ranges 'spell_regions' } %sh{ file=$(mktemp -d -t kak-spell.XXXXXXXX)/buffer - echo "write ${file}" - echo "set buffer spell_tmp_file ${file}" + printf %s "write ${file}" + printf %s "set buffer spell_tmp_file ${file}" } %sh{ if [ $# -ge 1 ]; then if [ ${#1} -ne 2 -a ${#1} -ne 5 ]; then - echo "echo -color Error Invalid language code (examples of expected format: en, en_US, en-US)" + printf %s "echo -color Error Invalid language code (examples of expected format: en, en_US, en-US)" rm -r $(dirname $kak_opt_spell_tmp_file) exit 1 else @@ -31,14 +31,14 @@ def -params ..1 spell -docstring "Check spelling of the current buffer with aspe word=$(printf %s "$line" | cut -d ' ' -f 2) begin=${begin:-$(printf %s "$line" | cut -d ' ' -f 3)} end=$((begin + ${#word})) - # echo "echo -debug -- line: $line_num, word: $word, begin: $begin, end: $end" + # printf %s "echo -debug -- line: $line_num, word: $word, begin: $begin, end: $end" regions="$regions:$line_num.$begin,$line_num.$end|Error" ;; '') ((++line_num)) ;; *) ;; esac done - echo "set buffer spell_regions %{$regions}" + printf %s "set buffer spell_regions %{$regions}" } rm -r $(dirname $kak_opt_spell_tmp_file) } diff --git a/rc/core/c-family.kak b/rc/core/c-family.kak index aa5e933c..b2ad69fb 100644 --- a/rc/core/c-family.kak +++ b/rc/core/c-family.kak @@ -218,10 +218,10 @@ def -hidden _c-family-insert-include-guards %{ %sh{ case "${kak_opt_c_include_guard_style,,}" in ifdef) - echo "exec ggi%ggxs\.c_A_INCLUDEDggxyppI#ifndefjI#definejI#endif//O" + printf %s "exec ggi%ggxs\.c_A_INCLUDEDggxyppI#ifndefjI#definejI#endif//O" ;; pragma) - echo "exec ggi#pragmaonce" + printf %s "exec ggi#pragmaonce" ;; *);; esac @@ -257,13 +257,13 @@ def c-family-alternative-file -docstring "Jump to the alternate file (header/imp done ;; *) - echo "echo -color Error 'extension not recognized'" + printf %s "echo -color Error 'extension not recognized'" exit ;; esac if [ -f ${altname} ]; then - echo "edit '${altname}'" + printf %s "edit '${altname}'" else - echo "echo -color Error 'alternative file not found'" + printf %s "echo -color Error 'alternative file not found'" fi }} diff --git a/rc/core/commenting.kak b/rc/core/commenting.kak index 7d917c43..0335f261 100644 --- a/rc/core/commenting.kak +++ b/rc/core/commenting.kak @@ -8,18 +8,18 @@ def comment-selection -docstring "Comment/uncomment the current selection" %{ %sh{ function exec_proof { ## Replace the '<' sign that is interpreted differently in `exec` - echo "$@" | sed -r 's,<,,g' + printf %s "$@" | sed -r 's,<,,g' } readonly opening=$(exec_proof "${kak_opt_comment_selection_chars%%:*}") readonly closing=$(exec_proof "${kak_opt_comment_selection_chars##*:}") if [ -z "${opening}" -o -z "${closing}" ]; then - echo "The \`comment_selection_chars\` variable is empty, couldn't comment the selection" >&2 + printf %s "The \`comment_selection_chars\` variable is empty, couldn't comment the selection" >&2 exit fi - echo "try %{ + printf %s "try %{ ## The selection is empty exec -draft %{\A[\h\v\n]*\z} @@ -43,11 +43,11 @@ def comment-line -docstring "Comment/uncomment the current line" %{ readonly opening_escaped="\Q${opening}\E" if [ -z "${opening}" ]; then - echo "The \`comment_line_chars\` variable is empty, couldn't comment the line" >&2 + printf %s "The \`comment_line_chars\` variable is empty, couldn't comment the line" >&2 exit fi - echo " + printf %s " ## Select the content of the line, without indentation exec %{I} diff --git a/rc/core/doc.kak b/rc/core/doc.kak index 01477116..26c404ae 100644 --- a/rc/core/doc.kak +++ b/rc/core/doc.kak @@ -10,7 +10,7 @@ def -hidden -params 1..2 _doc-open %{ rm ${manout} if [ "${retval}" -eq 0 ]; then - echo " + printf %s " edit! -scratch '*doc*' exec |cat${colout}gg nop %sh{rm ${colout}} @@ -19,10 +19,10 @@ def -hidden -params 1..2 _doc-open %{ if [ $# -gt 1 ]; then needle=$(printf %s "$2" | sed 's,<,,g') - echo "try %{ exec '%(?i)^\h+[^\n]*?\Q${needle}\E\'' } catch %{ exec gg }" + printf %s "try %{ exec '%(?i)^\h+[^\n]*?\Q${needle}\E\'' } catch %{ exec gg }" fi else - echo "echo -color Error %{doc '$@' failed: see *debug* buffer for details}" + printf %s "echo -color Error %{doc '$@' failed: see *debug* buffer for details}" rm ${colout} fi } @@ -31,7 +31,7 @@ def -hidden -params 1..2 _doc-open %{ def -params 1..2 \ -shell-completion %{ find "${kak_runtime}/../doc/kak/manpages/" -type f -iname "*$@*.gz" -printf '%f\n' | while read l; do - echo "${l%.*}" + printf %s "${l%.*}" done } \ doc -docstring "Open a buffer containing the documentation about a given subject" %{ @@ -40,10 +40,10 @@ def -params 1..2 \ shift if [ ! -f "${PATH_DOC}" ]; then - echo "echo -color Error No such doc file: ${PATH_DOC}" + printf %s "echo -color Error No such doc file: ${PATH_DOC}" exit fi - echo "eval -try-client %opt{docsclient} _doc-open ${PATH_DOC} $@" + printf %s "eval -try-client %opt{docsclient} _doc-open ${PATH_DOC} $@" } } diff --git a/rc/core/formatter.kak b/rc/core/formatter.kak index d6075fe6..38985dc4 100644 --- a/rc/core/formatter.kak +++ b/rc/core/formatter.kak @@ -6,9 +6,9 @@ def format -docstring "Format the entire buffer with an external utility" %{ readonly x=$((kak_cursor_column - 1)) readonly y="${kak_cursor_line}" - echo "exec -draft %{%|${kak_opt_formatcmd// /}}" + printf %s "exec -draft %{%|${kak_opt_formatcmd// /}}" ## Try to restore the position of the cursor as it was prior to formatting - echo "exec gg ${y}g ${x}l" + printf %s "exec gg ${y}g ${x}l" fi } } diff --git a/rc/core/grep.kak b/rc/core/grep.kak index 312ff67d..0745a7bf 100644 --- a/rc/core/grep.kak +++ b/rc/core/grep.kak @@ -12,7 +12,7 @@ def -params .. -file-completion \ ( ${kak_opt_grepcmd} "${kak_selection}" | tr -d '\r' > ${output} 2>&1 ) > /dev/null 2>&1 < /dev/null & fi - echo "eval -try-client '$kak_opt_toolsclient' %{ + printf %s "eval -try-client '$kak_opt_toolsclient' %{ edit! -fifo ${output} -scroll *grep* set buffer filetype grep set buffer _grep_current_line 0 diff --git a/rc/core/make.kak b/rc/core/make.kak index ff796f19..9f6fdc2c 100644 --- a/rc/core/make.kak +++ b/rc/core/make.kak @@ -7,7 +7,7 @@ def -params .. make -docstring "Make utility wrapper" %{ %sh{ mkfifo ${output} ( eval ${kak_opt_makecmd} "$@" > ${output} 2>&1 ) > /dev/null 2>&1 < /dev/null & - echo "eval -try-client '$kak_opt_toolsclient' %{ + printf %s "eval -try-client '$kak_opt_toolsclient' %{ edit! -fifo ${output} -scroll *make* set buffer filetype make set buffer _make_current_error_line 0 diff --git a/rc/core/man.kak b/rc/core/man.kak index bb314788..d3545003 100644 --- a/rc/core/man.kak +++ b/rc/core/man.kak @@ -25,25 +25,25 @@ def -hidden -params .. _man %{ %sh{ col -b -x > ${colout} < ${manout} rm ${manout} if [ "${retval}" -eq 0 ]; then - echo "edit! -scratch '*man*' + printf %s "edit! -scratch '*man*' exec |cat${colout}gk nop %sh{rm ${colout}} set buffer filetype man" else - echo "echo -color Error %{man '$@' failed: see *debug* buffer for details }" + printf %s "echo -color Error %{man '$@' failed: see *debug* buffer for details }" rm ${colout} fi } } def -params .. \ -shell-completion %{ - prefix=$(echo "$1" | cut -c1-${kak_pos_in_token} 2>/dev/null) + prefix=$(printf %s "$1" | cut -c1-${kak_pos_in_token} 2>/dev/null) for page in /usr/share/man/*/${prefix}*.[1-8]*; do candidate=$(basename ${page%%.[1-8]*}) pagenum=$(printf %s "$page" | sed -r 's,^.+/.+\.([1-8][^.]*)\..+$,\1,') case $candidate in *\*) ;; - *) echo $candidate\($pagenum\);; + *) printf %s $candidate\($pagenum\);; esac done } \ @@ -56,5 +56,5 @@ def -params .. \ subject=${subject%%\(*} fi - echo "eval -collapse-jumps -try-client %opt{docsclient} _man $pagenum $subject" + printf %s "eval -collapse-jumps -try-client %opt{docsclient} _man $pagenum $subject" } } diff --git a/rc/core/tmux.kak b/rc/core/tmux.kak index 48525db6..7e4aa1b7 100644 --- a/rc/core/tmux.kak +++ b/rc/core/tmux.kak @@ -5,8 +5,8 @@ hook global KakBegin .* %{ %sh{ if [ -n "$TMUX" ]; then - echo "alias global focus tmux-focus" - echo "alias global new tmux-new-horizontal" + printf %s "alias global focus tmux-focus" + printf %s "alias global new tmux-new-horizontal" fi } } @@ -15,7 +15,7 @@ hook global KakBegin .* %{ def -hidden -params 1.. tmux-new-impl %{ %sh{ if [ -z "$TMUX" ]; then - echo "echo -color Error This command is only available in a tmux session" + printf %s "echo -color Error This command is only available in a tmux session" exit fi tmux_args="$1" @@ -41,9 +41,9 @@ def -docstring "focus given client" \ -params 0..1 -client-completion \ tmux-focus %{ %sh{ if [ $# -gt 1 ]; then - echo "echo -color Error 'too many arguments, use focus [client]'" + printf %s "echo -color Error 'too many arguments, use focus [client]'" elif [ $# -eq 1 ]; then - echo "eval -client '$1' focus" + printf %s "eval -client '$1' focus" elif [ -n "${kak_client_env_TMUX}" ]; then TMUX="${kak_client_env_TMUX}" tmux select-pane -t "${kak_client_env_TMUX_PANE}" > /dev/null fi diff --git a/rc/core/x11.kak b/rc/core/x11.kak index f485a416..7d1ea77f 100644 --- a/rc/core/x11.kak +++ b/rc/core/x11.kak @@ -23,7 +23,7 @@ def -docstring 'create a new kak client for current session' \ -command-completion \ x11-new %{ %sh{ if [ -z "${kak_opt_termcmd}" ]; then - echo "echo -color Error 'termcmd option is not set'" + printf %s "echo -color Error 'termcmd option is not set'" exit fi if [ $# -ne 0 ]; then kakoune_params="-e '$@'"; fi @@ -34,9 +34,9 @@ def -docstring 'focus given client\'s window' \ -params 0..1 -client-completion \ x11-focus %{ %sh{ if [ $# -gt 1 ]; then - echo "echo -color Error 'too many arguments, use focus [client]'" + printf %s "echo -color Error 'too many arguments, use focus [client]'" elif [ $# -eq 1 ]; then - echo "eval -client '$1' focus" + printf %s "eval -client '$1' focus" else xdotool windowactivate $kak_client_env_WINDOWID > /dev/null fi diff --git a/rc/extra/autorestore.kak b/rc/extra/autorestore.kak index d310887b..a809f15d 100644 --- a/rc/extra/autorestore.kak +++ b/rc/extra/autorestore.kak @@ -14,12 +14,12 @@ def autorestore-restore-buffer -docstring "Restore the backup for the current fi latest_backup_path=$(find "${buffer_dirname}" -maxdepth 1 -type f -readable -newer "${kak_bufname}" -name "\.${buffer_basename}\.kak\.*" -printf '%A@/%p\n' 2>/dev/null \ | sort -n -t. -k1 | sed -nr 's/^[^\/]+\///;$p') if [ -z "${latest_backup_path}" ]; then - echo "eval -draft %{ autorestore-purge-backups }"; + printf %s "eval -draft %{ autorestore-purge-backups }"; exit; fi ## Replace the content of the buffer with the content of the backup file - echo " + printf %s " exec -draft %{ %d!cat${latest_backup_path}d } echo -color Information 'Backup restored' " @@ -28,7 +28,7 @@ def autorestore-restore-buffer -docstring "Restore the backup for the current fi ## the current buffer has been saved ## If the autorestore_purge_restored option has been unset right after the ## buffer was restored, do not remove the backup - echo " + printf %s " hook -group autorestore global BufWritePost (.+/)?${kak_bufname} %{ nop %sh{ if [ \"\${kak_opt_autorestore_purge_restored}\" = true ]; then diff --git a/rc/extra/clang.kak b/rc/extra/clang.kak index 198c31ad..6658fa33 100644 --- a/rc/extra/clang.kak +++ b/rc/extra/clang.kak @@ -9,14 +9,14 @@ def clang-parse -params 0..1 -docstring "Parse the contents of the current buffe %sh{ dir=$(mktemp -d -t kak-clang.XXXXXXXX) mkfifo ${dir}/fifo - echo "set buffer clang_tmp_dir ${dir}" - echo "write ${dir}/buf" + printf %s "set buffer clang_tmp_dir ${dir}" + printf %s "write ${dir}/buf" } # end the previous %sh{} so that its output gets interpreted by kakoune # before launching the following as a background task. %sh{ dir=${kak_opt_clang_tmp_dir} - echo "eval -draft %{ + printf %s "eval -draft %{ edit! -fifo ${dir}/fifo *clang-output* set buffer filetype make set buffer _make_current_error_line 0 @@ -72,11 +72,11 @@ def clang-parse -params 0..1 -docstring "Parse the contents of the current buffe print id "|" docstrings[id] "|" menu } }' | paste -s -d ':' | sed -e "s/\\\\n/\\n/g; s/'/\\\\'/g") - echo "eval -client ${kak_client} echo 'clang completion done' + printf %s "eval -client ${kak_client} echo 'clang completion done' set 'buffer=${kak_buffile}' clang_completions '${header}:${compl}'" | kak -p ${kak_session} else clang++ -x ${ft} -fsyntax-only ${kak_opt_clang_options} - < ${dir}/buf 2> ${dir}/stderr - echo "eval -client ${kak_client} echo 'clang parsing done'" | kak -p ${kak_session} + printf %s "eval -client ${kak_client} echo 'clang parsing done'" | kak -p ${kak_session} fi flags=$(cat ${dir}/stderr | sed -rne " @@ -90,7 +90,7 @@ def clang-parse -params 0..1 -docstring "Parse the contents of the current buffe sed -e "s||${kak_bufname}|g" < ${dir}/stderr > ${dir}/fifo - echo "set 'buffer=${kak_buffile}' clang_flags %{${kak_timestamp}:${flags}} + printf %s "set 'buffer=${kak_buffile}' clang_flags %{${kak_timestamp}:${flags}} set 'buffer=${kak_buffile}' clang_errors '${errors}'" | kak -p ${kak_session} ) > /dev/null 2>&1 < /dev/null & } @@ -102,9 +102,14 @@ def -hidden clang-show-completion-info %[ try %[ eval -draft %[ exec '{(^\(b' %sh[ +<<<<<<< f877c388fea0e794f663d62e3508c5d11832601e desc=$(echo "${kak_opt_clang_completions}" | sed -ne "{ s/\([^\\]\):/\1\n/g }; /^${kak_selection}@/ { s/^[^@]\+@//; s/@.*$//; s/\\\:/:/g; P }; D") +======= + # desc=$(printf %s "${kak_opt_clang_completions}" | sed -e 's/\([^\\]\):/\1\n/g;' | sed -ne "/^${kak_selection}@/ { s/^[^@]\+@//; s/@.*$//; s/\\:/:/g; p }") + desc=$(printf %s "${kak_opt_clang_completions}" | sed -ne "{ s/\([^\\]\):/\1\n/g }; /^${kak_selection}@/ { s/^[^@]\+@//; s/@.*$//; s/\\\:/:/g; P }; D") +>>>>>>> Replace non POSIX calls to `echo` with `printf %s` if [ -n "$desc" ]; then - echo "eval -client $kak_client %{info -anchor ${kak_cursor_line}.${kak_cursor_column} -placement above %{${desc}}}" + printf %s "eval -client $kak_client %{info -anchor ${kak_cursor_line}.${kak_cursor_column} -placement above %{${desc}}}" fi ] ] ] ] @@ -129,9 +134,15 @@ def clang-disable-autocomplete -docstring "Disable automatic clang completion" % } def -hidden clang-show-error-info %{ %sh{ +<<<<<<< f877c388fea0e794f663d62e3508c5d11832601e desc=$(printf %s "${kak_opt_clang_errors}" | sed -ne "/^${kak_cursor_line},.*/ { s/^[[:digit:]]\+,//g; s/'/\\\\'/g; p }") if [ -n "$desc" ]; then echo "info -anchor ${kak_cursor_line}.${kak_cursor_column} '${desc}'" +======= + printf %s "${kak_opt_clang_errors}" | grep "^${kak_cursor_line},.*" | if read line; then + desc=$(printf %s "${line}" | sed -e "s/^[[:digit:]]\+,//g; s/'/\\\\'/g") + printf %s "info -anchor ${kak_cursor_line}.${kak_cursor_column} '${desc}'" +>>>>>>> Replace non POSIX calls to `echo` with `printf %s` fi } } @@ -158,9 +169,9 @@ def clang-diagnostics-next -docstring "Jump to the next line that contains an er done line=$((line == -1 ? first_line : line)) if [ ${line} -ne -1 ]; then - echo "exec ${line} g" + printf %s "exec ${line} g" else - echo 'echo -color Error no next clang diagnostic' + printf %s 'echo -color Error no next clang diagnostic' fi ) } } diff --git a/rc/extra/editorconfig.kak b/rc/extra/editorconfig.kak index 7f042d01..b7734d99 100644 --- a/rc/extra/editorconfig.kak +++ b/rc/extra/editorconfig.kak @@ -1,6 +1,6 @@ def editorconfig-load -docstring "Set indentation options according to editorconfig file" %{ %sh{ - command -v editorconfig >/dev/null 2>&1 || { echo "echo -color Error The editorconfig tool could not be found"; exit 1; } + command -v editorconfig >/dev/null 2>&1 || { printf %s "echo -color Error The editorconfig tool could not be found"; exit 1; } editorconfig $kak_buffile | awk -F= -- \ '{ if ($1 == "indent_style" && $2 == "tab") { diff --git a/rc/extra/git-tools.kak b/rc/extra/git-tools.kak index 080530c7..d3948ee7 100644 --- a/rc/extra/git-tools.kak +++ b/rc/extra/git-tools.kak @@ -29,7 +29,7 @@ def -params 1.. \ -docstring %sh{printf "%%{Git wrapping helper\navailable commands:\n add\n rm\n blame\n commit\n checkout\n diff\n hide-blame\n log\n show\n show-diff\n status\n update-diff}"} \ -shell-completion %{ shift $(expr ${kak_token_to_complete}) - prefix=$(echo "${1}" | cut -c1-${kak_pos_in_token} 2>/dev/null) + prefix=$(printf %s "${1}" | cut -c1-${kak_pos_in_token} 2>/dev/null) ( for cmd in add rm blame commit checkout diff hide-blame log show show-diff status update-diff; do expr "${cmd}" : "^\(${prefix}.*\)$" @@ -48,7 +48,7 @@ def -params 1.. \ mkfifo ${output} ( git "$@" > ${output} 2>&1 ) > /dev/null 2>&1 < /dev/null & - echo "eval -try-client '$kak_opt_docsclient' %{ + printf %s "eval -try-client '$kak_opt_docsclient' %{ edit! -fifo ${output} *git* set buffer filetype '${filetype}' hook -group fifo buffer BufCloseFifo .* %{ @@ -60,7 +60,7 @@ def -params 1.. \ run_git_blame() { ( - echo "eval -client '$kak_client' %{ + printf %s "eval -client '$kak_client' %{ try %{ addhl flag_lines GitBlame git_blame_flags } set buffer=$kak_bufname git_blame_flags '$kak_timestamp' }" | kak -p ${kak_session} @@ -120,9 +120,9 @@ def -params 1.. \ # Handle case where message needs not to be edited if grep -E -q -e "-m|-F|-C|--message=.*|--file=.*|--reuse-message=.*|--no-edit"; then if git commit "$@" > /dev/null 2>&1; then - echo 'echo -color Information Commit succeeded' + printf %s 'echo -color Information Commit succeeded' else - echo 'echo -color Error Commit failed' + printf %s 'echo -color Error Commit failed' fi exit fi <<-EOF @@ -132,13 +132,13 @@ def -params 1.. \ # fails, and generate COMMIT_EDITMSG GIT_EDITOR='' EDITOR='' git commit > /dev/null 2>&1 msgfile="$(git rev-parse --git-dir)/COMMIT_EDITMSG" - echo "edit '$msgfile' + printf %s "edit '$msgfile' hook buffer BufWritePost '.*\Q$msgfile\E' %{ %sh{ if git commit -F '$msgfile' --cleanup=strip $@ > /dev/null; then - echo 'eval -client $kak_client echo -color Information Commit succeeded' - echo 'delbuf' + printf %s 'eval -client $kak_client echo -color Information Commit succeeded' + printf %s 'delbuf' else - echo 'eval -client $kak_client echo -color Error Commit failed' + printf %s 'eval -client $kak_client echo -color Error Commit failed' fi } }" } @@ -147,13 +147,13 @@ def -params 1.. \ show|log|diff|status) show_git_cmd_output "$@" ;; blame) shift; run_git_blame "$@" ;; hide-blame) - echo "try %{ + printf %s "try %{ set buffer=$kak_bufname git_blame_flags '' rmhl hlflags_git_blame_flags }" ;; show-diff) - echo "try %{ addhl flag_lines default,black git_diff_flags }" + printf %s "try %{ addhl flag_lines default,black git_diff_flags }" update_diff ;; update-diff) update_diff ;; @@ -165,19 +165,19 @@ def -params 1.. \ add) name="${2:-${kak_buffile}}" if git add -- "${name}" > /dev/null 2>&1; then - echo "echo -color Information 'git: added ${name}'" + printf %s "echo -color Information 'git: added ${name}'" else - echo "echo -color Error 'git: unable to add ${name}'" + printf %s "echo -color Error 'git: unable to add ${name}'" fi ;; rm) name="${2:-${kak_buffile}}" if git rm -- "${name}" > /dev/null 2>&1; then - echo "echo -color Information 'git: removed ${name}'" + printf %s "echo -color Information 'git: removed ${name}'" else - echo "echo -color Error 'git: unable to remove ${name}'" + printf %s "echo -color Error 'git: unable to remove ${name}'" fi ;; - *) echo "echo -color Error %{unknown git command '$1'}"; exit ;; + *) printf %s "echo -color Error %{unknown git command '$1'}"; exit ;; esac }} diff --git a/rc/extra/jedi.kak b/rc/extra/jedi.kak index 65bc1ec4..3e1d98ed 100644 --- a/rc/extra/jedi.kak +++ b/rc/extra/jedi.kak @@ -6,12 +6,12 @@ def jedi-complete -docstring "Complete the current selection with jedi" %{ %sh{ dir=$(mktemp -d -t kak-jedi.XXXXXXXX) mkfifo ${dir}/fifo - echo "set buffer jedi_tmp_dir ${dir}" - echo "write ${dir}/buf" + printf %s "set buffer jedi_tmp_dir ${dir}" + printf %s "write ${dir}/buf" } %sh{ dir=${kak_opt_jedi_tmp_dir} - echo "eval -draft %{ edit! -fifo ${dir}/fifo *jedi-output* }" + printf %s "eval -draft %{ edit! -fifo ${dir}/fifo *jedi-output* }" ( cd $(dirname ${kak_buffile}) header="${kak_cursor_line}.${kak_cursor_column}@${kak_timestamp}" diff --git a/rc/extra/modeline.kak b/rc/extra/modeline.kak index 25ea58c9..a7d644dc 100644 --- a/rc/extra/modeline.kak +++ b/rc/extra/modeline.kak @@ -35,17 +35,17 @@ def -hidden _modeline-parse %{ case "${value}" in unix) tr="eolformat lf";; dos) tr="eolformat crlf";; - *) echo "Unsupported file format: ${value}" >&2;; + *) printf %s "Unsupported file format: ${value}" >&2;; esac ;; ft) ;& filetype) tr="filetype ${value}";; bomb) tr="BOM utf8";; nobomb) tr="BOM none";; - *) echo "Unsupported vim variable: ${key}" >&2;; + *) printf %s "Unsupported vim variable: ${key}" >&2;; esac - [ -n "${tr}" ] && echo "set buffer ${tr}" + [ -n "${tr}" ] && printf %s "set buffer ${tr}" } # Pass a few whitelisted options to kakoune directly @@ -64,11 +64,11 @@ def -hidden _modeline-parse %{ ) grep -qw "${key}" <<< "${OPTS_ALLOWED[@]}" || { - echo "Unsupported kakoune variable: ${key}" >&2; + printf %s "Unsupported kakoune variable: ${key}" >&2; return; } - echo "set buffer ${key} ${value}" + printf %s "set buffer ${key} ${value}" } # The following subshell will keep the actual options of the modeline, and strip: @@ -87,7 +87,7 @@ def -hidden _modeline-parse %{ *vim:*) type_selection="vim";; *kak:*) ;& *kakoune:*) type_selection="kakoune";; - *) echo "echo -debug Unsupported modeline format";; + *) printf %s "echo -debug Unsupported modeline format";; esac [ -n "${type_selection}" ] || exit 1 @@ -100,7 +100,7 @@ def -hidden _modeline-parse %{ kakoune) tr=$(translate_opt_kakoune "${name_option}" "${value_option}");; esac - [ -n "${tr}" ] && echo "${tr}" + [ -n "${tr}" ] && printf %s "${tr}" done } } diff --git a/rc/extra/moon.kak b/rc/extra/moon.kak index 703604b5..b18e91e0 100644 --- a/rc/extra/moon.kak +++ b/rc/extra/moon.kak @@ -39,12 +39,12 @@ addhl -group /moon/code regex \b(and|break|catch|class|continue|do|else(if)?|exp def moon-alternative-file -docstring 'Jump to the alternate file (implementation ↔ test)' %{ %sh{ case $kak_buffile in *spec/*_spec.moon) - altfile=$(eval echo $(echo $kak_buffile | sed s+spec/+'*'/+';'s/_spec//)) - [ ! -f $altfile ] && echo "echo -color Error 'implementation file not found'" && exit + altfile=$(eval printf %s $(printf %s $kak_buffile | sed s+spec/+'*'/+';'s/_spec//)) + [ ! -f $altfile ] && printf %s "echo -color Error 'implementation file not found'" && exit ;; *.moon) path=$kak_buffile - dirs=$(while [ $path ]; do echo $path; path=${path%/*}; done | tail -n +2) + dirs=$(while [ $path ]; do printf %s $path; path=${path%/*}; done | tail -n +2) for dir in $dirs; do altdir=$dir/spec if [ -d $altdir ]; then @@ -52,13 +52,13 @@ def moon-alternative-file -docstring 'Jump to the alternate file (implementation break fi done - [ ! -d $altdir ] && echo "echo -color Error 'spec/ not found'" && exit + [ ! -d $altdir ] && printf %s "echo -color Error 'spec/ not found'" && exit ;; *) - echo "echo -color Error 'alternative file not found'" && exit + printf %s "echo -color Error 'alternative file not found'" && exit ;; esac - echo "edit $altfile" + printf %s "edit $altfile" }} def -hidden _moon_filter_around_selections %{ diff --git a/rc/extra/tmux-repl.kak b/rc/extra/tmux-repl.kak index 3c28af23..7d5b36d6 100644 --- a/rc/extra/tmux-repl.kak +++ b/rc/extra/tmux-repl.kak @@ -4,8 +4,8 @@ hook global KakBegin .* %{ %sh{ if [ -n "$TMUX" ]; then - echo "alias global repl tmux-repl-horizontal" - echo "alias global send-text tmux-send-text" + printf %s "alias global repl tmux-repl-horizontal" + printf %s "alias global send-text tmux-send-text" fi } } @@ -13,7 +13,7 @@ hook global KakBegin .* %{ def -hidden -params 1..2 tmux-repl-impl %{ %sh{ if [ -z "$TMUX" ]; then - echo "echo -color Error This command is only available in a tmux session" + printf %s "echo -color Error This command is only available in a tmux session" exit fi tmux_args="$1" diff --git a/rc/extra/x11-repl.kak b/rc/extra/x11-repl.kak index 369b1a62..0d03ecd1 100644 --- a/rc/extra/x11-repl.kak +++ b/rc/extra/x11-repl.kak @@ -4,7 +4,7 @@ def -docstring 'create a new window for repl interaction' \ -command-completion \ x11-repl %{ %sh{ if [ -z "${kak_opt_termcmd}" ]; then - echo "echo -color Error 'termcmd option is not set'" + printf %s "echo -color Error 'termcmd option is not set'" exit fi if [ $# -eq 0 ]; then cmd="bash"; else cmd="$1"; fi @@ -13,7 +13,7 @@ def -docstring 'create a new window for repl interaction' \ def x11-send-text -docstring "send selected text to the repl window" %{ nop %sh{ - echo "${kak_selection}" | xsel -i + printf %s "${kak_selection}" | xsel -i wid=$(xdotool getactivewindow) xdotool search --name kak_repl_window windowactivate xdotool key --clearmodifiers "Shift+Insert"