From 9a7d8df44732b684255acd151c4104bf95aeebd5 Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Sun, 23 Aug 2020 18:55:50 +0200 Subject: [PATCH] Avoid accidentally using environment variables in sh scopes On the instances with altfile this was already the case, but this makes it more obvious. Closes #3673 --- rc/detection/modeline.kak | 4 ++-- rc/filetype/lua.kak | 4 +++- rc/filetype/ruby.kak | 4 +++- rc/tools/autorestore.kak | 2 +- rc/tools/clang.kak | 2 ++ rc/tools/doc.kak | 2 ++ rc/tools/git.kak | 1 + rc/tools/go/go-tools.kak | 1 + rc/tools/man.kak | 3 +++ rc/tools/spell.kak | 2 ++ share/kak/kakrc | 1 + 11 files changed, 21 insertions(+), 5 deletions(-) diff --git a/rc/detection/modeline.kak b/rc/detection/modeline.kak index 3784a081..1a343448 100644 --- a/rc/detection/modeline.kak +++ b/rc/detection/modeline.kak @@ -58,9 +58,8 @@ define-command -hidden modeline-parse-impl %{ case "${kak_selection}" in *vi:*|*vim:*) type_selection="vim";; *kak:*|*kakoune:*) type_selection="kakoune";; - *) echo "echo -debug Unsupported modeline format";; + *) echo "echo -debug Unsupported modeline format"; exit 1 ;; esac - [ -n "${type_selection}" ] || exit 1 # The following subshell will keep the actual options of the modeline, and strip: # - the text that leads the first option, according to the official vim modeline format @@ -82,6 +81,7 @@ define-command -hidden modeline-parse-impl %{ case "${type_selection}" in vim) tr=$(translate_opt_vim "${name_option}" "${value_option}");; kakoune) tr=$(translate_opt_kakoune "${name_option}" "${value_option}");; + *) tr="";; esac [ -n "${tr}" ] && printf %s\\n "${tr}" diff --git a/rc/filetype/lua.kak b/rc/filetype/lua.kak index 995bd7b4..9328bc02 100644 --- a/rc/filetype/lua.kak +++ b/rc/filetype/lua.kak @@ -65,6 +65,8 @@ define-command lua-alternative-file -docstring 'Jump to the alternate file (impl [ ! -f $altfile ] && echo "fail 'implementation file not found'" && exit ;; *.lua) + altfile="" + altdir="" path=$kak_buffile dirs=$(while [ $path ]; do printf %s\\n $path; path=${path%/*}; done | tail -n +2) for dir in $dirs; do @@ -74,7 +76,7 @@ define-command lua-alternative-file -docstring 'Jump to the alternate file (impl break fi done - [ ! -d $altdir ] && echo "fail 'spec/ not found'" && exit + [ ! -d "$altdir" ] && echo "fail 'spec/ not found'" && exit ;; *) echo "fail 'alternative file not found'" && exit diff --git a/rc/filetype/ruby.kak b/rc/filetype/ruby.kak index ea4b2279..06b0f781 100644 --- a/rc/filetype/ruby.kak +++ b/rc/filetype/ruby.kak @@ -120,6 +120,8 @@ define-command ruby-alternative-file -docstring 'Jump to the alternate file (imp [ ! -f $altfile ] && echo "fail 'implementation file not found'" && exit ;; *.rb) + altfile="" + altdir="" path=$kak_buffile dirs=$(while [ $path ]; do echo $path; path=${path%/*}; done | tail -n +2) for dir in $dirs; do @@ -130,7 +132,7 @@ define-command ruby-alternative-file -docstring 'Jump to the alternate file (imp break fi done - [ ! -d $altdir ] && echo "fail 'spec/ and test/ not found'" && exit + [ ! -d "$altdir" ] && echo "fail 'spec/ and test/ not found'" && exit ;; *) echo "fail 'alternative file not found'" && exit diff --git a/rc/tools/autorestore.kak b/rc/tools/autorestore.kak index 329a45b0..a59ce850 100644 --- a/rc/tools/autorestore.kak +++ b/rc/tools/autorestore.kak @@ -9,11 +9,11 @@ define-command autorestore-restore-buffer -docstring "Restore the backup for the if [ -f "${kak_buffile}" ]; then newer=$(find "${buffer_dirname}"/".${buffer_basename}.kak."* -newer "${kak_buffile}" -exec ls -1t {} + 2>/dev/null | head -n 1) - older=$(find "${buffer_dirname}"/".${buffer_basename}.kak."* \! -newer "${kak_buffile}" -exec ls -1t {} + 2>/dev/null | head -n 1) else # New buffers that were never written to disk. newer=$(ls -1t "${buffer_dirname}"/".${buffer_basename}.kak."* 2>/dev/null | head -n 1) + older="" fi if [ -z "${newer}" ]; then diff --git a/rc/tools/clang.kak b/rc/tools/clang.kak index 56a32f2c..586a97f5 100644 --- a/rc/tools/clang.kak +++ b/rc/tools/clang.kak @@ -173,6 +173,8 @@ define-command clang-diagnostics-next -docstring "Jump to the next line that con evaluate-commands %sh{ eval "set -- ${kak_quoted_opt_clang_errors}" shift # skip timestamp + unset line + unset first_line for error in "$@"; do candidate=${error%%|*} first_line=${first_line-$candidate} diff --git a/rc/tools/doc.kak b/rc/tools/doc.kak index 0fa7ad32..6e0cf74e 100644 --- a/rc/tools/doc.kak +++ b/rc/tools/doc.kak @@ -14,6 +14,7 @@ define-command -hidden -params 4 doc-render-regex %{ evaluate-commands %sh{ face="$4" eval "set -- $kak_quoted_selections_desc" + ranges="" for desc in "$@"; do ranges="$ranges '$desc|$face'"; done echo "update-option buffer doc_render_ranges" echo "set-option -add buffer doc_render_ranges $ranges" @@ -154,6 +155,7 @@ define-command -params 1..2 \ evaluate-commands %sh{ readonly page="${kak_runtime}/doc/${1}.asciidoc" if [ -f "${page}" ]; then + jump_cmd="" if [ $# -eq 2 ]; then jump_cmd="doc-jump-to-anchor '$2'" fi diff --git a/rc/tools/git.kak b/rc/tools/git.kak index e355370d..fa705215 100644 --- a/rc/tools/git.kak +++ b/rc/tools/git.kak @@ -229,6 +229,7 @@ define-command -params 1.. \ fi done + wrapped=false if [ "$direction" = "next" ]; then if [ -z "$next_hunk" ]; then next_hunk=${hunks%% *} diff --git a/rc/tools/go/go-tools.kak b/rc/tools/go/go-tools.kak index 7e1241b9..af1cacbb 100644 --- a/rc/tools/go/go-tools.kak +++ b/rc/tools/go/go-tools.kak @@ -116,6 +116,7 @@ define-command -hidden -params 1..2 gogetdoc-cmd %{ cat ${dir}/buf | wc -c >> ${dir}/modified cat ${dir}/buf >> ${dir}/modified + args="" if [ "$2" = "1" ]; then args="-json" fi diff --git a/rc/tools/man.kak b/rc/tools/man.kak index 54960a23..730bc29d 100644 --- a/rc/tools/man.kak +++ b/rc/tools/man.kak @@ -74,6 +74,9 @@ define-command -params ..1 \ pagenum="${pagenum%\)}" subject="${subject%%\(*}" ;; + *) + pagenum="" + ;; esac printf %s\\n "evaluate-commands -try-client %opt{docsclient} man-impl man $pagenum $subject" diff --git a/rc/tools/spell.kak b/rc/tools/spell.kak index ca231ee5..135b53df 100644 --- a/rc/tools/spell.kak +++ b/rc/tools/spell.kak @@ -143,6 +143,7 @@ define-command spell-next %{ evaluate-commands %sh{ define-command \ -docstring "Suggest replacement words for the current selection, against the last language used by the spell-check command" \ spell-replace %{ evaluate-commands %sh{ + options="" if [ -n "$kak_opt_spell_last_lang" ]; then options="-l '$kak_opt_spell_last_lang'" fi @@ -159,6 +160,7 @@ define-command \ define-command -params 0.. \ -docstring "Add the current selection to the dictionary" \ spell-add %{ evaluate-commands %sh{ + options="" if [ -n "$kak_opt_spell_last_lang" ]; then options="-l '$kak_opt_spell_last_lang'" fi diff --git a/share/kak/kakrc b/share/kak/kakrc index d01224e3..6c322ec4 100644 --- a/share/kak/kakrc +++ b/share/kak/kakrc @@ -11,6 +11,7 @@ def -params 1 -docstring "colorscheme : enable named colorscheme" \ find -L "${1}" -type f -name "${2}".kak | head -n 1 } + filename="" if [ -d "${kak_config}/colors" ]; then filename=$(find_colorscheme "${kak_config}/colors" "${1}") fi