From a8765bb03d4993c6f64b16d0d34edb5f16473bd5 Mon Sep 17 00:00:00 2001 From: Andrey Listopadov Date: Sat, 20 Mar 2021 22:44:19 +0300 Subject: [PATCH] fix some shellcheck warnings --- rc/fzf.kak | 64 +++++++++++++++++++------------------- rc/modules/VCS/fzf-bzr.kak | 2 +- rc/modules/fzf-buffer.kak | 16 +++++----- rc/modules/fzf-cd.kak | 7 ++--- rc/modules/fzf-ctags.kak | 18 +++++------ rc/modules/fzf-file.kak | 14 ++++----- rc/modules/fzf-grep.kak | 12 +++---- rc/modules/fzf-project.kak | 28 ++++++++--------- rc/modules/fzf-search.kak | 2 +- rc/modules/fzf-vcs.kak | 10 +++--- rc/modules/sk-grep.kak | 12 +++---- 11 files changed, 92 insertions(+), 93 deletions(-) diff --git a/rc/fzf.kak b/rc/fzf.kak index 7c2811a..7f12c55 100644 --- a/rc/fzf.kak +++ b/rc/fzf.kak @@ -104,10 +104,10 @@ fzf-horizontal -params .. %{ evaluate-commands %{ define-command -hidden -docstring "wrapper command to create new terminal" \ fzf-window -params .. %{ evaluate-commands %sh{ - if [ -n "$kak_client_env_TMUX" ]; then + if [ -n "${kak_client_env_TMUX:-}" ]; then printf "%s\n" 'tmux-terminal-window kak -c %val{session} -e "%arg{@}"' else - printf "%s\n" "$kak_opt_fzf_terminal_command" + printf "%s\n" "${kak_opt_fzf_terminal_command:?}" fi }} @@ -136,12 +136,12 @@ Switches: -post-action" } \ fzf -params .. %{ evaluate-commands %sh{ - fzf_impl="${kak_opt_fzf_implementation}" + fzf_impl="${kak_opt_fzf_implementation:?}" - [ "${kak_opt_fzf_use_main_selection}" = "true" ] && \ - [ $(printf "%s" "${kak_selection}" | wc -m) -gt 1 ] && \ - [ $(printf "%s" "${kak_selection}" | wc -l) -eq 1 ] && \ - default_query="-i -q ${kak_selection}" + [ "${kak_opt_fzf_use_main_selection:-}" = "true" ] && \ + [ "$(printf "%s" "${kak_selection:-}" | wc -m)" -gt 1 ] && \ + [ "$(printf "%s" "${kak_selection:-}" | wc -l)" -eq 1 ] && \ + default_query="-i -q ${kak_selection:-}" while [ $# -gt 0 ]; do case $1 in @@ -162,29 +162,29 @@ fzf -params .. %{ evaluate-commands %sh{ if [ "${preview}" = "true" ]; then # bake position option to define them at runtime - [ -n "${kak_client_env_TMUX}" ] && tmux_height="${kak_opt_fzf_preview_tmux_height}" - case ${kak_opt_fzf_preview_pos} in - (top|up) preview_position="pos=top:${kak_opt_fzf_preview_height};" ;; - (bottom|down) preview_position="pos=down:${kak_opt_fzf_preview_height};" ;; - (right) preview_position="pos=right:${kak_opt_fzf_preview_width};" ;; - (left) preview_position="pos=left:${kak_opt_fzf_preview_width};" ;; - (auto|*) preview_position="sleep 0.1; [ \$(tput cols) -gt \$(expr \$(tput lines) \* 2) ] && pos=right:${kak_opt_fzf_preview_width} || pos=top:${kak_opt_fzf_preview_height};" + [ -n "${kak_client_env_TMUX:-}" ] && tmux_height="${kak_opt_fzf_preview_tmux_height:-}" + case ${kak_opt_fzf_preview_pos:-} in + (top|up) preview_position="pos=top:${kak_opt_fzf_preview_height:-};" ;; + (bottom|down) preview_position="pos=down:${kak_opt_fzf_preview_height:-};" ;; + (right) preview_position="pos=right:${kak_opt_fzf_preview_width:-};" ;; + (left) preview_position="pos=left:${kak_opt_fzf_preview_width:-};" ;; + (auto|*) preview_position="sleep 0.1; [ \$(tput cols) -gt \$(expr \$(tput lines) \* 2) ] && pos=right:${kak_opt_fzf_preview_width:-} || pos=top:${kak_opt_fzf_preview_height:-};" esac # handle preview if not defined explicitly with `-preview-cmd' - if [ ${kak_opt_fzf_preview} = "true" ] && [ -z "${preview_cmd}" ]; then - case ${kak_opt_fzf_highlight_command} in + if [ "${kak_opt_fzf_preview:-}" = "true" ] && [ -z "${preview_cmd}" ]; then + case ${kak_opt_fzf_highlight_command:-} in (bat) highlight_cmd="bat --color=always --style=plain {}" ;; (coderay) highlight_cmd="coderay {}" ;; (highlight) highlight_cmd="highlight --failsafe -O ansi {}" ;; (rouge) highlight_cmd="rougify {}" ;; (*) highlight_cmd="${kak_opt_fzf_highlight_command}" ;; esac - preview_cmd="--preview '(${highlight_cmd} || cat {}) 2>/dev/null | head -n ${kak_opt_fzf_preview_lines}' --preview-window=\${pos}" + preview_cmd="--preview '(${highlight_cmd} || cat {}) 2>/dev/null | head -n ${kak_opt_fzf_preview_lines:-}' --preview-window=\${pos}" fi fi - fzf_tmp=$(mktemp -d ${TMPDIR:-/tmp}/fzf.kak.XXXXXX) + fzf_tmp=$(mktemp -d "${TMPDIR:-/tmp}"/fzf.kak.XXXXXX) fzfcmd="${fzf_tmp}/fzfcmd" result="${fzf_tmp}/result" @@ -197,19 +197,19 @@ fzf -params .. %{ evaluate-commands %sh{ printf "%s\n" "SHELL=${shell_path}" fi # compose entire fzf command with all args into single file which will be executed later - printf "%s\n" "export FZF_DEFAULT_OPTS=\"$kak_opt_fzf_default_opts\"" + printf "%s\n" "export FZF_DEFAULT_OPTS=\"${kak_opt_fzf_default_opts:-}\"" printf "%s\n" "cd \"${PWD}\" && ${preview_position} ${items_cmd} ${fzf_impl} ${default_query} ${fzf_args} ${preview_cmd} ${filter} > ${result}" printf "%s\n" "rm ${fzfcmd}" - ) >> ${fzfcmd} - chmod 755 ${fzfcmd} + ) >> "${fzfcmd}" + chmod 755 "${fzfcmd}" if [ -n "${kak_client_env_TMUX}" ]; then # set default height if not set already - [ -z "${tmux_height}" ] && tmux_height=${kak_opt_fzf_tmux_height} + [ -z "${tmux_height}" ] && tmux_height=${kak_opt_fzf_tmux_height:-} # if height contains `%' then `-p' will be used [ -n "${tmux_height%%*%}" ] && measure="-l" || measure="-p" # `terminal' doesn't support any kind of width and height parameters, so tmux panes are created by tmux itself - cmd="nop %sh{ command tmux split-window -t '${kak_client_env_TMUX_PANE}' ${measure} ${tmux_height%%%*} env ${fzfcmd} < /dev/null > /dev/null 2>&1 }" + cmd="nop %sh{ command tmux split-window -t '${kak_client_env_TMUX_PANE:-}' ${measure} ${tmux_height%%%*} env ${fzfcmd} < /dev/null > /dev/null 2>&1 }" else cmd="${kak_opt_fzf_terminal_command%% *} %{${fzfcmd}}" fi @@ -217,20 +217,20 @@ fzf -params .. %{ evaluate-commands %sh{ printf "%s\n" "${cmd}" # main loop - ( while [ -e ${fzfcmd} ]; do sleep 0.1; done - if [ -s ${result} ]; then + ( while [ -e "${fzfcmd}" ]; do sleep 0.1; done + if [ -s "${result}" ]; then ( while read -r line; do case ${line} in - (${kak_opt_fzf_window_map}) wincmd="fzf-window" ;; - (${kak_opt_fzf_vertical_map}) wincmd="fzf-vertical" ;; - (${kak_opt_fzf_horizontal_map}) wincmd="fzf-horizontal" ;; - (*) item=${line} ;; + ("${kak_opt_fzf_window_map:-}") wincmd="fzf-window" ;; + ("${kak_opt_fzf_vertical_map:-}") wincmd="fzf-vertical" ;; + ("${kak_opt_fzf_horizontal_map:-}") wincmd="fzf-horizontal" ;; + (*) item=${line} ;; esac if [ -n "${item}" ]; then item=$(printf "%s\n" "${item}" | sed "s/@/@@/g;s/&/&&/g") kakoune_cmd=$(printf "%s\n" "${kakoune_cmd}" | sed "s/&/&&/g") - printf "%s\n" "evaluate-commands -client ${kak_client} ${wincmd} %&${kakoune_cmd} %@${item}@&" + printf "%s\n" "evaluate-commands -client ${kak_client:?} ${wincmd} %&${kakoune_cmd} %@${item}@&" break fi done @@ -243,9 +243,9 @@ fzf -params .. %{ evaluate-commands %sh{ post_action=$(printf "%s\n" "${post_action}" | sed "s/&/&&/g") printf "%s\n" "evaluate-commands -client ${kak_client} %&${post_action}&" fi - ) < ${result} | kak -p ${kak_session} + ) < "${result}" | kak -p "${kak_session:?}" fi - rm -rf ${fzf_tmp} + rm -rf "${fzf_tmp}" ) > /dev/null 2>&1 < /dev/null & }} diff --git a/rc/modules/VCS/fzf-bzr.kak b/rc/modules/VCS/fzf-bzr.kak index cdd10f8..a25c8fa 100644 --- a/rc/modules/VCS/fzf-bzr.kak +++ b/rc/modules/VCS/fzf-bzr.kak @@ -24,7 +24,7 @@ define-command -hidden fzf-bzr %{ evaluate-commands %sh{ (bzr) cmd="(cd $repo_root && bzr ls -R --versioned)" ;; (*) cmd=$kak_opt_fzf_bzr_command ;; esac - [ ! -z "${kak_client_env_TMUX}" ] && additional_flags="--expect $kak_opt_fzf_vertical_map --expect $kak_opt_fzf_horizontal_map" + [ -n "${kak_client_env_TMUX}" ] && additional_flags="--expect $kak_opt_fzf_vertical_map --expect $kak_opt_fzf_horizontal_map" printf "%s\n" "fzf -kak-cmd %{edit -existing} -items-cmd %{$cmd} -fzf-args %{-m --expect $kak_opt_fzf_window_map $additional_flags} -filter %{perl -pe \"if (/$kak_opt_fzf_window_map|$kak_opt_fzf_vertical_map|$kak_opt_fzf_horizontal_map|^$/) {} else {print \\\"$repo_root/\\\"}\"}" }} diff --git a/rc/modules/fzf-buffer.kak b/rc/modules/fzf-buffer.kak index 7de2205..b318c01 100644 --- a/rc/modules/fzf-buffer.kak +++ b/rc/modules/fzf-buffer.kak @@ -11,7 +11,7 @@ provide-module fzf-buffer %§ define-command -hidden fzf-buffer %{ evaluate-commands %sh{ buffers="" - eval "set -- $kak_quoted_buflist" + eval "set -- ${kak_quoted_buflist:?}" while [ $# -gt 0 ]; do buffers="$1 $buffers" @@ -20,19 +20,19 @@ $buffers" message="Set buffer to edit in current client. : switch to selected buffer. -$kak_opt_fzf_window_map: open buffer in new window" - [ ! -z "${kak_client_env_TMUX}" ] && tmux_keybindings=" -$kak_opt_fzf_horizontal_map: open buffer in horizontal split -$kak_opt_fzf_vertical_map: open buffer in vertical split" +${kak_opt_fzf_window_map:?}: open buffer in new window" + [ -n "${kak_client_env_TMUX:-}" ] && tmux_keybindings=" +${kak_opt_fzf_horizontal_map:-}: open buffer in horizontal split +${kak_opt_fzf_vertical_map:-}: open buffer in vertical split" printf "%s\n" "info -title 'fzf buffer' '$message$tmux_keybindings'" - [ ! -z "${kak_client_env_TMUX}" ] && additional_flags="--expect $kak_opt_fzf_vertical_map --expect $kak_opt_fzf_horizontal_map" + [ -n "${kak_client_env_TMUX:-}" ] && additional_flags="--expect $kak_opt_fzf_vertical_map --expect $kak_opt_fzf_horizontal_map" printf "%s\n" "fzf -kak-cmd %{buffer} -items-cmd %{printf \"%s\n\" \"$buffers\"} -fzf-args %{--expect $kak_opt_fzf_window_map $additional_flags}" }} define-command -hidden fzf-delete-buffer %{ evaluate-commands %sh{ buffers="" - eval "set -- $kak_quoted_buflist" + eval "set -- ${kak_quoted_buflist:?}" while [ $# -gt 0 ]; do buffers="$1 $buffers" @@ -42,7 +42,7 @@ $buffers" message="Delete buffer. : delete selected buffer." printf "%s\n" "info -title 'fzf delete-buffer' '$message'" - printf "%s\n" "fzf -kak-cmd %{delete-buffer} -multiple-cmd %{delete-buffer} -items-cmd %{printf \"%s\n\" \"$buffers\"} -fzf-args %{-m --expect $kak_opt_fzf_window_map $additional_flags}" + printf "%s\n" "fzf -kak-cmd %{delete-buffer} -multiple-cmd %{delete-buffer} -items-cmd %{printf \"%s\n\" \"$buffers\"} -fzf-args %{-m --expect ${kak_opt_fzf_window_map:?} ${additional_flags:-}}" }} § diff --git a/rc/modules/fzf-cd.kak b/rc/modules/fzf-cd.kak index f4917ec..d5f7145 100644 --- a/rc/modules/fzf-cd.kak +++ b/rc/modules/fzf-cd.kak @@ -30,16 +30,15 @@ declare-option -docstring 'maximum amount of previewed directories' \ int fzf_preview_dirs '300' define-command -hidden fzf-cd %{ evaluate-commands %sh{ - tmux_height=$kak_opt_fzf_tmux_height printf '%s\n' "info -title %{fzf change directory} %{Change the server's working directory current path: $(pwd)}" - case $kak_opt_fzf_cd_command in + case ${kak_opt_fzf_cd_command:-} in (find) items_command="(echo .. && find . \( -path '*/.svn*' -o -path '*/.git*' \) -prune -o -type d -print)" ;; (*) items_command=$kak_opt_fzf_cd_command ;; esac - if [ "$kak_opt_fzf_cd_preview" = "true" ]; then + if [ "${kak_opt_fzf_cd_preview:-}" = "true" ]; then preview_flag="-preview" - preview="--preview '($kak_opt_cd_preview_command) 2>/dev/null | head -n $kak_opt_fzf_preview_dirs'" + preview="--preview '(${kak_opt_cd_preview_command:-}) 2>/dev/null | head -n ${kak_opt_fzf_preview_dirs:-0}'" fi printf "%s\n" "fzf $preview_flag -kak-cmd %{change-directory} -items-cmd %{$items_command} -preview-cmd %{$preview} -post-action %{fzf-cd}" }} diff --git a/rc/modules/fzf-ctags.kak b/rc/modules/fzf-ctags.kak index 9f4e872..af5f062 100644 --- a/rc/modules/fzf-ctags.kak +++ b/rc/modules/fzf-ctags.kak @@ -23,9 +23,9 @@ try %{ # this huge try block defines filetype aware filter mappings for separate fzf-ctags mode define-command -hidden fzf-setup-filter-tags %{ evaluate-commands %sh{ - [ "$opt_fzf_tag_filters_defined" = "true" ] && exit + [ "${kak_opt_fzf_tag_filters_defined:-}" = "true" ] && exit - case $kak_opt_filetype in + case ${kak_opt_filetype:-} in (ada) printf "%s\n" " map global fzf-ctags '' ': fzf-tag P' -docstring 'package specifications' map global fzf-ctags 'p' ': fzf-tag p' -docstring 'packages' @@ -898,7 +898,7 @@ define-command -hidden fzf-setup-filter-tags %{ define-command -hidden fzf-tag -params ..2 %{ evaluate-commands %sh{ path=$PWD while [ "$path" != "$HOME" ]; do - if [ -e "./$kak_opt_fzf_tag_file_name" ]; then + if [ -e "./${kak_opt_fzf_tag_file_name:-}" ]; then break else cd .. @@ -914,7 +914,7 @@ define-command -hidden fzf-tag -params ..2 %{ evaluate-commands %sh{ fi cmd="cd $path;" - if [ -n "$(command -v ${kak_opt_readtagscmd})" ]; then + if [ -n "$(command -v "${kak_opt_readtagscmd%% *}")" ]; then if [ -n "$1" ]; then cmd="${cmd} ${kak_opt_readtagscmd} -t $kak_opt_fzf_tag_file_name -Q '(eq? \$kind \"$1\")' -l" else @@ -928,15 +928,15 @@ define-command -hidden fzf-tag -params ..2 %{ evaluate-commands %sh{ message="Jump to a symbol''s definition : open tag in new buffer -$kak_opt_fzf_window_map: open tag in new terminal" +${kak_opt_fzf_window_map:?}: open tag in new terminal" - [ -n "${kak_client_env_TMUX}" ] && tmux_keybindings=" -$kak_opt_fzf_horizontal_map: open tag in horizontal split -$kak_opt_fzf_vertical_map: open tag in vertical split" + [ -n "${kak_client_env_TMUX:?}" ] && tmux_keybindings=" +${kak_opt_fzf_horizontal_map:-}: open tag in horizontal split +${kak_opt_fzf_vertical_map:-}: open tag in vertical split" printf "%s\n" "info -title 'fzf tag' '$message$tmux_keybindings'" - [ ! -z "${kak_client_env_TMUX}" ] && additional_flags="--expect $kak_opt_fzf_vertical_map --expect $kak_opt_fzf_horizontal_map" + [ -n "${kak_client_env_TMUX}" ] && additional_flags="--expect $kak_opt_fzf_vertical_map --expect $kak_opt_fzf_horizontal_map" printf "%s\n" "set-option -add window ctagsfiles %{$path/$kak_opt_fzf_tag_file_name}" printf "%s\n" "fzf -kak-cmd %{ctags-search} -items-cmd %{$cmd | awk '!a[\$0]++'} -fzf-args %{--expect $kak_opt_fzf_window_map $additional_flags}" }} diff --git a/rc/modules/fzf-file.kak b/rc/modules/fzf-file.kak index a3ea14d..a1449e9 100644 --- a/rc/modules/fzf-file.kak +++ b/rc/modules/fzf-file.kak @@ -32,7 +32,7 @@ bool fzf_file_preview true define-command -hidden fzf-file %{ evaluate-commands %sh{ - if [ -z "$(command -v $kak_opt_fzf_file_command)" ]; then + if [ -z "$(command -v "${kak_opt_fzf_file_command%% *}")" ]; then printf "%s\n" "echo -markup '{Information}''$kak_opt_fzf_file_command'' is not installed. Falling back to ''find'''" kak_opt_fzf_file_command="find" fi @@ -50,14 +50,14 @@ define-command -hidden fzf-file %{ evaluate-commands %sh{ cmd="$cmd 2>/dev/null" message="Open single or multiple files. : open file in new buffer. -$kak_opt_fzf_window_map: open file in new terminal" - [ ! -z "${kak_client_env_TMUX}" ] && tmux_keybindings=" -$kak_opt_fzf_horizontal_map: open file in horizontal split -$kak_opt_fzf_vertical_map: open file in vertical split" +${kak_opt_fzf_window_map:?}: open file in new terminal" + [ -n "${kak_client_env_TMUX:-}" ] && tmux_keybindings=" +${kak_opt_fzf_horizontal_map:-}: open file in horizontal split +${kak_opt_fzf_vertical_map:-}: open file in vertical split" printf "%s\n" "info -title 'fzf file' '$message$tmux_keybindings'" - [ ! -z "${kak_client_env_TMUX}" ] && additional_flags="--expect $kak_opt_fzf_vertical_map --expect $kak_opt_fzf_horizontal_map" - [ "$kak_opt_fzf_file_preview" = "true" ] && preview_flag="-preview" + [ -n "${kak_client_env_TMUX}" ] && additional_flags="--expect $kak_opt_fzf_vertical_map --expect $kak_opt_fzf_horizontal_map" + [ "${kak_opt_fzf_file_preview:-}" = "true" ] && preview_flag="-preview" printf "%s\n" "fzf $preview_flag -kak-cmd %{edit -existing} -items-cmd %{$cmd} -fzf-args %{-m --expect $kak_opt_fzf_window_map $additional_flags}" }} diff --git a/rc/modules/fzf-grep.kak b/rc/modules/fzf-grep.kak index 936edef..e3a2de2 100644 --- a/rc/modules/fzf-grep.kak +++ b/rc/modules/fzf-grep.kak @@ -17,7 +17,7 @@ str fzf_grep_command 'grep' define-command -hidden fzf-grep %{ evaluate-commands %sh{ - if [ -z "$(command -v $kak_opt_fzf_grep_command)" ]; then + if [ -z "$(command -v "${kak_opt_fzf_grep_command%% *}")" ]; then printf "%s\n" "echo -markup '{Information}''$kak_opt_fzf_grep_command'' is not installed. Falling back to ''grep'''" kak_opt_fzf_grep_command="grep" fi @@ -35,13 +35,13 @@ define-command -hidden fzf-grep %{ evaluate-commands %sh{ title="fzf grep" message="grep through contents of all files recursively. : open search result in new buffer. -$kak_opt_fzf_window_map: open search result in new terminal" - [ ! -z "${kak_client_env_TMUX}" ] && tmux_keybindings=" -$kak_opt_fzf_horizontal_map: open search result in horizontal split -$kak_opt_fzf_vertical_map: open search result in vertical split" +${kak_opt_fzf_window_map:?}: open search result in new terminal" + [ -n "${kak_client_env_TMUX:-}" ] && tmux_keybindings=" +${kak_opt_fzf_horizontal_map:-}: open search result in horizontal split +${kak_opt_fzf_vertical_map:-}: open search result in vertical split" printf "%s\n" "info -title '${title}' '${message}${tmux_keybindings}'" - [ ! -z "${kak_client_env_TMUX}" ] && additional_flags="--expect $kak_opt_fzf_vertical_map --expect $kak_opt_fzf_horizontal_map" + [ -n "${kak_client_env_TMUX}" ] && additional_flags="--expect $kak_opt_fzf_vertical_map --expect $kak_opt_fzf_horizontal_map" printf "%s\n" "fzf -kak-cmd %{evaluate-commands} -fzf-args %{--expect $kak_opt_fzf_window_map $additional_flags --delimiter=':' -n'3..'} -items-cmd %{$cmd} -filter %{sed -E 's/([^:]+):([^:]+):.*/edit -existing \1; execute-keys \2gvc/'}" }} diff --git a/rc/modules/fzf-project.kak b/rc/modules/fzf-project.kak index 4255eaa..377dea7 100644 --- a/rc/modules/fzf-project.kak +++ b/rc/modules/fzf-project.kak @@ -24,7 +24,7 @@ map global fzf-project -docstring "delete project from project list" 'd' ': map global fzf-project -docstring "rename project" 'r' ': fzf-rename-project' define-command -hidden fzf-project %{ evaluate-commands %sh{ - if [ -s ${kak_opt_fzf_project_file} ]; then + if [ -s "${kak_opt_fzf_project_file:-}" ]; then printf '%s\n' "info -title %{fzf open project} %{Change the server's working directory to selected project}" printf "%s\n" "fzf -kak-cmd change-directory -items-cmd %{cat ${kak_opt_fzf_project_file}} -fzf-args %{--reverse --delimiter=':' -n'1'} -post-action fzf-file -filter %{sed 's/.*: //'}" else @@ -33,12 +33,12 @@ define-command -hidden fzf-project %{ evaluate-commands %sh{ }} define-command -hidden fzf-save-path-as-project %{ prompt -shell-script-candidates %{printf "%s\n" "${PWD##*/}"} "Project's name: " %{ evaluate-commands %sh{ - if [ -n "${kak_text}" ]; then + if [ -n "${kak_text:-}" ]; then mkdir -p "${kak_opt_fzf_project_file%/*}" - exists=$(grep "${kak_text}: " ${kak_opt_fzf_project_file}) + exists=$(grep "${kak_text}: " "${kak_opt_fzf_project_file:-}") if [ -z "${exists}" ]; then - [ "${kak_opt_fzf_project_use_tilda}" = "false" ] && project_path=$(pwd) || project_path=$(pwd | perl -pe "s(${HOME})(~)") - printf "%s: %s\n" "${kak_text}" "${project_path}" >> ${kak_opt_fzf_project_file} + [ "${kak_opt_fzf_project_use_tilda:-true}" = "false" ] && project_path=$(pwd) || project_path=$(pwd | perl -pe "s(${HOME})(~)") + printf "%s: %s\n" "${kak_text}" "${project_path}" >> "${kak_opt_fzf_project_file}" printf "%s\n" "echo -markup %{{Information}saved '$(pwd)' project as '${kak_text}'}" else printf "%s\n" "fzf-project-confirm-impl %{Project '${kak_text}' exists. Update? (y/N): } %{fzf-update-project-path-impl %{${kak_text}} %{${PWD}}} %{Project '${kak_text}' updated} %{Project '${kak_text}' kept}" @@ -65,11 +65,11 @@ define-command -hidden fzf-save-path-as-project-no-prompt %{ evaluate-commands % esac printf "%s\n" "${base}" } - project_name=$(base ${PWD}) - exists=$(grep "${project_name}: " ${kak_opt_fzf_project_file}) + project_name=$(base "${PWD}") + exists=$(grep "${project_name}: " "${kak_opt_fzf_project_file}") if [ -z "${exists}" ]; then - [ "${kak_opt_fzf_project_use_tilda}" = "false" ] && project_path=$(pwd) || project_path=$(pwd | perl -pe "s(${HOME})(~)") - printf "%s: %s\n" "${project_name}" "${project_path}" >> ${kak_opt_fzf_project_file} + [ "${kak_opt_fzf_project_use_tilda:-true}" = "false" ] && project_path=$(pwd) || project_path=$(pwd | perl -pe "s(${HOME})(~)") + printf "%s: %s\n" "${project_name}" "${project_path}" >> "${kak_opt_fzf_project_file}" printf "%s\n" "echo -markup %{{Information}saved '$(pwd)' project as '${project_name}'}" else printf "%s\n" "fzf-project-confirm-impl %{Project '${project_name}' exists. Update? (y/N): } %{fzf-update-project-path-impl %{${project_name}} %{${PWD}}} %{${project_name}} %{Project '${project_name}' updated} %{Project '${project_name}' kept}" @@ -103,11 +103,11 @@ fzf-add-project -file-completion -params 1..2 %{ evaluate-commands %sh{ mkdir -p "${kak_opt_fzf_project_file%/*}" project_path="$1" project_name="$2" - [ -z "${project_name}" ] && project_name=$(base ${project_path}) - exists=$(grep "${project_name}: " ${kak_opt_fzf_project_file}) + [ -z "${project_name}" ] && project_name=$(base "${project_path}") + exists=$(grep "${project_name}: " "${kak_opt_fzf_project_file}") if [ -z "${exists}" ] || [ "${force}" = "true" ]; then - [ "${kak_opt_fzf_project_use_tilda}" = "false" ] || project_path=$(printf "%s\n" ${project_path} | perl -pe "s(${HOME})(~)") - printf "%s: %s\n" "${project_name}" "${project_path}" >> ${kak_opt_fzf_project_file} + [ "${kak_opt_fzf_project_use_tilda:-true}" = "false" ] || project_path=$(printf "%s\n" "${project_path}" | perl -pe "s(${HOME})(~)") + printf "%s: %s\n" "${project_name}" "${project_path}" >> "${kak_opt_fzf_project_file}" printf "%s\n" "echo -markup %{{Information}saved '${project_path}' project as '${project_name}'}" else printf "%s\n" "fzf-project-confirm-impl %{Project '${project_name}' exists. Update? (y/N): } %{fzf-update-project-path-impl %{${project_name}} %{${project_path}}} %{Project '${project_name}' updated} %{Project '${project_name}' kept}" @@ -119,7 +119,7 @@ define-command -docstring \ -hidden fzf-project-confirm-impl -params 2..4 %{ prompt -shell-script-candidates %{printf "%s\n%s\n" "y" "n"} "%arg{1}" %{ evaluate-commands %sh{ shift; function_to_call=$1; success_message=$2; fail_message=$3 - choice=$(printf "%s" "${kak_text}" | perl -pe "s/y(es)?.*//i") # case isensetive lookup for yes answer + choice=$(printf "%s" "${kak_text:-}" | perl -pe "s/y(es)?.*//i") # case isensetive lookup for yes answer if [ -z "${choice}" ]; then printf "%s\n" "${function_to_call}" [ -n "${success_message}" ] && printf "%s\n" "echo -markup %{{Information}${success_message}}" diff --git a/rc/modules/fzf-search.kak b/rc/modules/fzf-search.kak index 5ce23b2..ad52bb7 100644 --- a/rc/modules/fzf-search.kak +++ b/rc/modules/fzf-search.kak @@ -12,7 +12,7 @@ define-command -hidden fzf-buffer-search %{ evaluate-commands %sh{ title="fzf buffer search" message="Search buffer with fzf, and jump to result location" printf "%s\n" "info -title '$title' '$message'" - buffer_content="$(mktemp ${TMPDIR:-/tmp}/fzf-buff-${kak_buffile##*/}.XXXXXX)" + buffer_content="$(mktemp "${TMPDIR:-/tmp}"/fzf-buff-"${kak_buffile##*/}".XXXXXX)" printf "%s\n" "execute-keys -draft %{%cat>$buffer_content;}" printf "%s\n" "fzf -kak-cmd %{execute-keys} -items-cmd %{(nl -b a -n ln $buffer_content; rm $buffer_content)} -fzf-args %{--reverse} -filter %{cut -f 1} -post-action %{execute-keys gx}" }} diff --git a/rc/modules/fzf-vcs.kak b/rc/modules/fzf-vcs.kak index 242413f..21a5085 100644 --- a/rc/modules/fzf-vcs.kak +++ b/rc/modules/fzf-vcs.kak @@ -33,17 +33,17 @@ bzr status" IFS=' ' for cmd in $commands; do - eval $cmd >/dev/null 2>&1 + eval "$cmd" >/dev/null 2>&1 res=$? if [ "$res" = "0" ]; then vcs=$(printf "%s\n" "$cmd" | awk '{print $1}') title="fzf $vcs" - [ ! -z "${kak_client_env_TMUX}" ] && additional_keybindings=" -$kak_opt_fzf_horizontal_map: open file in horizontal split -$kak_opt_fzf_vertical_map: open file in vertical split" + [ -n "${kak_client_env_TMUX:-}" ] && additional_keybindings=" +${kak_opt_fzf_horizontal_map:-}: open file in horizontal split +${kak_opt_fzf_vertical_map:-}: open file in vertical split" message="Open single or multiple files from git tree. : open file in new buffer. -$kak_opt_fzf_window_map: open file in new terminal $additional_keybindings" +${kak_opt_fzf_window_map:?}: open file in new terminal $additional_keybindings" printf "%s\n" "info -title %{$title} %{$message}" printf "%s\n" "fzf-$vcs" exit diff --git a/rc/modules/sk-grep.kak b/rc/modules/sk-grep.kak index 72a4dcd..3e541ab 100644 --- a/rc/modules/sk-grep.kak +++ b/rc/modules/sk-grep.kak @@ -29,14 +29,14 @@ define-command -hidden fzf-sk-grep %{ evaluate-commands %sh{ title="skim interactive grep" message="Interactively grep pattern from current directory : open search result in new buffer. -$kak_opt_fzf_window_map: open search result in new terminal" - [ ! -z "${kak_client_env_TMUX}" ] && tmux_keybindings=" -$kak_opt_fzf_horizontal_map: open search result in horizontal split -$kak_opt_fzf_vertical_map: open search result in vertical split" +${kak_opt_fzf_window_map:?}: open search result in new terminal" + [ -n "${kak_client_env_TMUX:-}" ] && tmux_keybindings=" +${kak_opt_fzf_horizontal_map:-}: open search result in horizontal split +${kak_opt_fzf_vertical_map:-}: open search result in vertical split" printf "%s\n" "info -title '${title}' '${message}${tmux_keybindings}'" - [ ! -z "${kak_client_env_TMUX}" ] && additional_flags="--expect $kak_opt_fzf_vertical_map --expect $kak_opt_fzf_horizontal_map" - printf "%s\n" "fzf -kak-cmd %{fzf-sk-grep-handler} -fzf-impl %{sk --ansi -m -i -c '$kak_opt_fzf_sk_grep_command {}'} -fzf-args %{--expect $kak_opt_fzf_window_map $additional_flags} -multiple-cmd %{fzf-sk-populate-grep} -post-action %{buffer %opt{fzf_sk_first_file}}" + [ -n "${kak_client_env_TMUX}" ] && additional_flags="--expect $kak_opt_fzf_vertical_map --expect $kak_opt_fzf_horizontal_map" + printf "%s\n" "fzf -kak-cmd %{fzf-sk-grep-handler} -fzf-impl %{sk --ansi -m -i -c '${kak_opt_fzf_sk_grep_command:-} {}'} -fzf-args %{--expect $kak_opt_fzf_window_map $additional_flags} -multiple-cmd %{fzf-sk-populate-grep} -post-action %{buffer %opt{fzf_sk_first_file}}" }} define-command -hidden fzf-sk-grep-handler -params 1 %{