1
0
Fork 0

fix some shellcheck warnings

This commit is contained in:
Andrey Listopadov 2021-03-20 22:44:19 +03:00
parent d912a6ecf1
commit a8765bb03d
11 changed files with 92 additions and 93 deletions

View file

@ -104,10 +104,10 @@ fzf-horizontal -params .. %{ evaluate-commands %{
define-command -hidden -docstring "wrapper command to create new terminal" \ define-command -hidden -docstring "wrapper command to create new terminal" \
fzf-window -params .. %{ evaluate-commands %sh{ 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{@}"' printf "%s\n" 'tmux-terminal-window kak -c %val{session} -e "%arg{@}"'
else else
printf "%s\n" "$kak_opt_fzf_terminal_command" printf "%s\n" "${kak_opt_fzf_terminal_command:?}"
fi fi
}} }}
@ -136,12 +136,12 @@ Switches:
-post-action" -post-action"
} \ } \
fzf -params .. %{ evaluate-commands %sh{ fzf -params .. %{ evaluate-commands %sh{
fzf_impl="${kak_opt_fzf_implementation}" fzf_impl="${kak_opt_fzf_implementation:?}"
[ "${kak_opt_fzf_use_main_selection}" = "true" ] && \ [ "${kak_opt_fzf_use_main_selection:-}" = "true" ] && \
[ $(printf "%s" "${kak_selection}" | wc -m) -gt 1 ] && \ [ "$(printf "%s" "${kak_selection:-}" | wc -m)" -gt 1 ] && \
[ $(printf "%s" "${kak_selection}" | wc -l) -eq 1 ] && \ [ "$(printf "%s" "${kak_selection:-}" | wc -l)" -eq 1 ] && \
default_query="-i -q ${kak_selection}" default_query="-i -q ${kak_selection:-}"
while [ $# -gt 0 ]; do while [ $# -gt 0 ]; do
case $1 in case $1 in
@ -162,29 +162,29 @@ fzf -params .. %{ evaluate-commands %sh{
if [ "${preview}" = "true" ]; then if [ "${preview}" = "true" ]; then
# bake position option to define them at runtime # bake position option to define them at runtime
[ -n "${kak_client_env_TMUX}" ] && tmux_height="${kak_opt_fzf_preview_tmux_height}" [ -n "${kak_client_env_TMUX:-}" ] && tmux_height="${kak_opt_fzf_preview_tmux_height:-}"
case ${kak_opt_fzf_preview_pos} in case ${kak_opt_fzf_preview_pos:-} in
(top|up) preview_position="pos=top:${kak_opt_fzf_preview_height};" ;; (top|up) preview_position="pos=top:${kak_opt_fzf_preview_height:-};" ;;
(bottom|down) preview_position="pos=down:${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};" ;; (right) preview_position="pos=right:${kak_opt_fzf_preview_width:-};" ;;
(left) preview_position="pos=left:${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};" (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 esac
# handle preview if not defined explicitly with `-preview-cmd' # handle preview if not defined explicitly with `-preview-cmd'
if [ ${kak_opt_fzf_preview} = "true" ] && [ -z "${preview_cmd}" ]; then if [ "${kak_opt_fzf_preview:-}" = "true" ] && [ -z "${preview_cmd}" ]; then
case ${kak_opt_fzf_highlight_command} in case ${kak_opt_fzf_highlight_command:-} in
(bat) highlight_cmd="bat --color=always --style=plain {}" ;; (bat) highlight_cmd="bat --color=always --style=plain {}" ;;
(coderay) highlight_cmd="coderay {}" ;; (coderay) highlight_cmd="coderay {}" ;;
(highlight) highlight_cmd="highlight --failsafe -O ansi {}" ;; (highlight) highlight_cmd="highlight --failsafe -O ansi {}" ;;
(rouge) highlight_cmd="rougify {}" ;; (rouge) highlight_cmd="rougify {}" ;;
(*) highlight_cmd="${kak_opt_fzf_highlight_command}" ;; (*) highlight_cmd="${kak_opt_fzf_highlight_command}" ;;
esac 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
fi fi
fzf_tmp=$(mktemp -d ${TMPDIR:-/tmp}/fzf.kak.XXXXXX) fzf_tmp=$(mktemp -d "${TMPDIR:-/tmp}"/fzf.kak.XXXXXX)
fzfcmd="${fzf_tmp}/fzfcmd" fzfcmd="${fzf_tmp}/fzfcmd"
result="${fzf_tmp}/result" result="${fzf_tmp}/result"
@ -197,19 +197,19 @@ fzf -params .. %{ evaluate-commands %sh{
printf "%s\n" "SHELL=${shell_path}" printf "%s\n" "SHELL=${shell_path}"
fi fi
# compose entire fzf command with all args into single file which will be executed later # 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" "cd \"${PWD}\" && ${preview_position} ${items_cmd} ${fzf_impl} ${default_query} ${fzf_args} ${preview_cmd} ${filter} > ${result}"
printf "%s\n" "rm ${fzfcmd}" printf "%s\n" "rm ${fzfcmd}"
) >> ${fzfcmd} ) >> "${fzfcmd}"
chmod 755 ${fzfcmd} chmod 755 "${fzfcmd}"
if [ -n "${kak_client_env_TMUX}" ]; then if [ -n "${kak_client_env_TMUX}" ]; then
# set default height if not set already # 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 # if height contains `%' then `-p' will be used
[ -n "${tmux_height%%*%}" ] && measure="-l" || measure="-p" [ -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 # `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 else
cmd="${kak_opt_fzf_terminal_command%% *} %{${fzfcmd}}" cmd="${kak_opt_fzf_terminal_command%% *} %{${fzfcmd}}"
fi fi
@ -217,20 +217,20 @@ fzf -params .. %{ evaluate-commands %sh{
printf "%s\n" "${cmd}" printf "%s\n" "${cmd}"
# main loop # main loop
( while [ -e ${fzfcmd} ]; do sleep 0.1; done ( while [ -e "${fzfcmd}" ]; do sleep 0.1; done
if [ -s ${result} ]; then if [ -s "${result}" ]; then
( (
while read -r line; do while read -r line; do
case ${line} in case ${line} in
(${kak_opt_fzf_window_map}) wincmd="fzf-window" ;; ("${kak_opt_fzf_window_map:-}") wincmd="fzf-window" ;;
(${kak_opt_fzf_vertical_map}) wincmd="fzf-vertical" ;; ("${kak_opt_fzf_vertical_map:-}") wincmd="fzf-vertical" ;;
(${kak_opt_fzf_horizontal_map}) wincmd="fzf-horizontal" ;; ("${kak_opt_fzf_horizontal_map:-}") wincmd="fzf-horizontal" ;;
(*) item=${line} ;; (*) item=${line} ;;
esac esac
if [ -n "${item}" ]; then if [ -n "${item}" ]; then
item=$(printf "%s\n" "${item}" | sed "s/@/@@/g;s/&/&&/g") item=$(printf "%s\n" "${item}" | sed "s/@/@@/g;s/&/&&/g")
kakoune_cmd=$(printf "%s\n" "${kakoune_cmd}" | sed "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 break
fi fi
done done
@ -243,9 +243,9 @@ fzf -params .. %{ evaluate-commands %sh{
post_action=$(printf "%s\n" "${post_action}" | sed "s/&/&&/g") post_action=$(printf "%s\n" "${post_action}" | sed "s/&/&&/g")
printf "%s\n" "evaluate-commands -client ${kak_client} %&${post_action}&" printf "%s\n" "evaluate-commands -client ${kak_client} %&${post_action}&"
fi fi
) < ${result} | kak -p ${kak_session} ) < "${result}" | kak -p "${kak_session:?}"
fi fi
rm -rf ${fzf_tmp} rm -rf "${fzf_tmp}"
) > /dev/null 2>&1 < /dev/null & ) > /dev/null 2>&1 < /dev/null &
}} }}

View file

@ -24,7 +24,7 @@ define-command -hidden fzf-bzr %{ evaluate-commands %sh{
(bzr) cmd="(cd $repo_root && bzr ls -R --versioned)" ;; (bzr) cmd="(cd $repo_root && bzr ls -R --versioned)" ;;
(*) cmd=$kak_opt_fzf_bzr_command ;; (*) cmd=$kak_opt_fzf_bzr_command ;;
esac 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/\\\"}\"}" 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/\\\"}\"}"
}} }}

View file

@ -11,7 +11,7 @@ provide-module fzf-buffer %§
define-command -hidden fzf-buffer %{ evaluate-commands %sh{ define-command -hidden fzf-buffer %{ evaluate-commands %sh{
buffers="" buffers=""
eval "set -- $kak_quoted_buflist" eval "set -- ${kak_quoted_buflist:?}"
while [ $# -gt 0 ]; do while [ $# -gt 0 ]; do
buffers="$1 buffers="$1
$buffers" $buffers"
@ -20,19 +20,19 @@ $buffers"
message="Set buffer to edit in current client. message="Set buffer to edit in current client.
<ret>: switch to selected buffer. <ret>: switch to selected buffer.
$kak_opt_fzf_window_map: open buffer in new window" ${kak_opt_fzf_window_map:?}: open buffer in new window"
[ ! -z "${kak_client_env_TMUX}" ] && tmux_keybindings=" [ -n "${kak_client_env_TMUX:-}" ] && tmux_keybindings="
$kak_opt_fzf_horizontal_map: open buffer in horizontal split ${kak_opt_fzf_horizontal_map:-}: open buffer in horizontal split
$kak_opt_fzf_vertical_map: open buffer in vertical split" ${kak_opt_fzf_vertical_map:-}: open buffer in vertical split"
printf "%s\n" "info -title 'fzf buffer' '$message$tmux_keybindings'" 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}" 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{ define-command -hidden fzf-delete-buffer %{ evaluate-commands %sh{
buffers="" buffers=""
eval "set -- $kak_quoted_buflist" eval "set -- ${kak_quoted_buflist:?}"
while [ $# -gt 0 ]; do while [ $# -gt 0 ]; do
buffers="$1 buffers="$1
$buffers" $buffers"
@ -42,7 +42,7 @@ $buffers"
message="Delete buffer. message="Delete buffer.
<ret>: delete selected buffer." <ret>: delete selected buffer."
printf "%s\n" "info -title 'fzf delete-buffer' '$message'" 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:-}}"
}} }}
§ §

View file

@ -30,16 +30,15 @@ declare-option -docstring 'maximum amount of previewed directories' \
int fzf_preview_dirs '300' int fzf_preview_dirs '300'
define-command -hidden fzf-cd %{ evaluate-commands %sh{ 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 printf '%s\n' "info -title %{fzf change directory} %{Change the server's working directory
current path: $(pwd)}" 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)" ;; (find) items_command="(echo .. && find . \( -path '*/.svn*' -o -path '*/.git*' \) -prune -o -type d -print)" ;;
(*) items_command=$kak_opt_fzf_cd_command ;; (*) items_command=$kak_opt_fzf_cd_command ;;
esac esac
if [ "$kak_opt_fzf_cd_preview" = "true" ]; then if [ "${kak_opt_fzf_cd_preview:-}" = "true" ]; then
preview_flag="-preview" 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 fi
printf "%s\n" "fzf $preview_flag -kak-cmd %{change-directory} -items-cmd %{$items_command} -preview-cmd %{$preview} -post-action %{fzf-cd}" printf "%s\n" "fzf $preview_flag -kak-cmd %{change-directory} -items-cmd %{$items_command} -preview-cmd %{$preview} -post-action %{fzf-cd}"
}} }}

View file

@ -23,9 +23,9 @@ try %{
# this huge try block defines filetype aware filter mappings for separate fzf-ctags mode # this huge try block defines filetype aware filter mappings for separate fzf-ctags mode
define-command -hidden fzf-setup-filter-tags %{ define-command -hidden fzf-setup-filter-tags %{
evaluate-commands %sh{ 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" " (ada) printf "%s\n" "
map global fzf-ctags '<a-p>' ': fzf-tag P<ret>' -docstring 'package specifications' map global fzf-ctags '<a-p>' ': fzf-tag P<ret>' -docstring 'package specifications'
map global fzf-ctags 'p' ': fzf-tag p<ret>' -docstring 'packages' map global fzf-ctags 'p' ': fzf-tag p<ret>' -docstring 'packages'
@ -898,7 +898,7 @@ define-command -hidden fzf-setup-filter-tags %{
define-command -hidden fzf-tag -params ..2 %{ evaluate-commands %sh{ define-command -hidden fzf-tag -params ..2 %{ evaluate-commands %sh{
path=$PWD path=$PWD
while [ "$path" != "$HOME" ]; do while [ "$path" != "$HOME" ]; do
if [ -e "./$kak_opt_fzf_tag_file_name" ]; then if [ -e "./${kak_opt_fzf_tag_file_name:-}" ]; then
break break
else else
cd .. cd ..
@ -914,7 +914,7 @@ define-command -hidden fzf-tag -params ..2 %{ evaluate-commands %sh{
fi fi
cmd="cd $path;" cmd="cd $path;"
if [ -n "$(command -v ${kak_opt_readtagscmd})" ]; then if [ -n "$(command -v "${kak_opt_readtagscmd%% *}")" ]; then
if [ -n "$1" ]; then if [ -n "$1" ]; then
cmd="${cmd} ${kak_opt_readtagscmd} -t $kak_opt_fzf_tag_file_name -Q '(eq? \$kind \"$1\")' -l" cmd="${cmd} ${kak_opt_readtagscmd} -t $kak_opt_fzf_tag_file_name -Q '(eq? \$kind \"$1\")' -l"
else else
@ -928,15 +928,15 @@ define-command -hidden fzf-tag -params ..2 %{ evaluate-commands %sh{
message="Jump to a symbol''s definition message="Jump to a symbol''s definition
<ret>: open tag in new buffer <ret>: 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=" [ -n "${kak_client_env_TMUX:?}" ] && tmux_keybindings="
$kak_opt_fzf_horizontal_map: open tag in horizontal split ${kak_opt_fzf_horizontal_map:-}: open tag in horizontal split
$kak_opt_fzf_vertical_map: open tag in vertical split" ${kak_opt_fzf_vertical_map:-}: open tag in vertical split"
printf "%s\n" "info -title 'fzf tag' '$message$tmux_keybindings'" 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" "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}" printf "%s\n" "fzf -kak-cmd %{ctags-search} -items-cmd %{$cmd | awk '!a[\$0]++'} -fzf-args %{--expect $kak_opt_fzf_window_map $additional_flags}"
}} }}

View file

@ -32,7 +32,7 @@ bool fzf_file_preview true
define-command -hidden fzf-file %{ evaluate-commands %sh{ 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'''" printf "%s\n" "echo -markup '{Information}''$kak_opt_fzf_file_command'' is not installed. Falling back to ''find'''"
kak_opt_fzf_file_command="find" kak_opt_fzf_file_command="find"
fi fi
@ -50,14 +50,14 @@ define-command -hidden fzf-file %{ evaluate-commands %sh{
cmd="$cmd 2>/dev/null" cmd="$cmd 2>/dev/null"
message="Open single or multiple files. message="Open single or multiple files.
<ret>: open file in new buffer. <ret>: open file in new buffer.
$kak_opt_fzf_window_map: open file in new terminal" ${kak_opt_fzf_window_map:?}: open file in new terminal"
[ ! -z "${kak_client_env_TMUX}" ] && tmux_keybindings=" [ -n "${kak_client_env_TMUX:-}" ] && tmux_keybindings="
$kak_opt_fzf_horizontal_map: open file in horizontal split ${kak_opt_fzf_horizontal_map:-}: open file in horizontal split
$kak_opt_fzf_vertical_map: open file in vertical split" ${kak_opt_fzf_vertical_map:-}: open file in vertical split"
printf "%s\n" "info -title 'fzf file' '$message$tmux_keybindings'" 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" [ -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" [ "${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}" printf "%s\n" "fzf $preview_flag -kak-cmd %{edit -existing} -items-cmd %{$cmd} -fzf-args %{-m --expect $kak_opt_fzf_window_map $additional_flags}"
}} }}

View file

@ -17,7 +17,7 @@ str fzf_grep_command 'grep'
define-command -hidden fzf-grep %{ evaluate-commands %sh{ 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'''" printf "%s\n" "echo -markup '{Information}''$kak_opt_fzf_grep_command'' is not installed. Falling back to ''grep'''"
kak_opt_fzf_grep_command="grep" kak_opt_fzf_grep_command="grep"
fi fi
@ -35,13 +35,13 @@ define-command -hidden fzf-grep %{ evaluate-commands %sh{
title="fzf grep" title="fzf grep"
message="grep through contents of all files recursively. message="grep through contents of all files recursively.
<ret>: open search result in new buffer. <ret>: open search result in new buffer.
$kak_opt_fzf_window_map: open search result in new terminal" ${kak_opt_fzf_window_map:?}: open search result in new terminal"
[ ! -z "${kak_client_env_TMUX}" ] && tmux_keybindings=" [ -n "${kak_client_env_TMUX:-}" ] && tmux_keybindings="
$kak_opt_fzf_horizontal_map: open search result in horizontal split ${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_vertical_map:-}: open search result in vertical split"
printf "%s\n" "info -title '${title}' '${message}${tmux_keybindings}'" 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/'}" 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/'}"
}} }}

View file

@ -24,7 +24,7 @@ map global fzf-project -docstring "delete project from project list" 'd' '<esc>:
map global fzf-project -docstring "rename project" 'r' '<esc>: fzf-rename-project<ret>' map global fzf-project -docstring "rename project" 'r' '<esc>: fzf-rename-project<ret>'
define-command -hidden fzf-project %{ evaluate-commands %sh{ 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' "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/.*: //'}" 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 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{ 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%/*}" 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 if [ -z "${exists}" ]; then
[ "${kak_opt_fzf_project_use_tilda}" = "false" ] && project_path=$(pwd) || project_path=$(pwd | perl -pe "s(${HOME})(~)") [ "${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: %s\n" "${kak_text}" "${project_path}" >> "${kak_opt_fzf_project_file}"
printf "%s\n" "echo -markup %{{Information}saved '$(pwd)' project as '${kak_text}'}" printf "%s\n" "echo -markup %{{Information}saved '$(pwd)' project as '${kak_text}'}"
else 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}" 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 esac
printf "%s\n" "${base}" printf "%s\n" "${base}"
} }
project_name=$(base ${PWD}) project_name=$(base "${PWD}")
exists=$(grep "${project_name}: " ${kak_opt_fzf_project_file}) exists=$(grep "${project_name}: " "${kak_opt_fzf_project_file}")
if [ -z "${exists}" ]; then if [ -z "${exists}" ]; then
[ "${kak_opt_fzf_project_use_tilda}" = "false" ] && project_path=$(pwd) || project_path=$(pwd | perl -pe "s(${HOME})(~)") [ "${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: %s\n" "${project_name}" "${project_path}" >> "${kak_opt_fzf_project_file}"
printf "%s\n" "echo -markup %{{Information}saved '$(pwd)' project as '${project_name}'}" printf "%s\n" "echo -markup %{{Information}saved '$(pwd)' project as '${project_name}'}"
else 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}" 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%/*}" mkdir -p "${kak_opt_fzf_project_file%/*}"
project_path="$1" project_path="$1"
project_name="$2" project_name="$2"
[ -z "${project_name}" ] && project_name=$(base ${project_path}) [ -z "${project_name}" ] && project_name=$(base "${project_path}")
exists=$(grep "${project_name}: " ${kak_opt_fzf_project_file}) exists=$(grep "${project_name}: " "${kak_opt_fzf_project_file}")
if [ -z "${exists}" ] || [ "${force}" = "true" ]; then if [ -z "${exists}" ] || [ "${force}" = "true" ]; then
[ "${kak_opt_fzf_project_use_tilda}" = "false" ] || project_path=$(printf "%s\n" ${project_path} | perl -pe "s(${HOME})(~)") [ "${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: %s\n" "${project_name}" "${project_path}" >> "${kak_opt_fzf_project_file}"
printf "%s\n" "echo -markup %{{Information}saved '${project_path}' project as '${project_name}'}" printf "%s\n" "echo -markup %{{Information}saved '${project_path}' project as '${project_name}'}"
else 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}" 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 %{ -hidden fzf-project-confirm-impl -params 2..4 %{
prompt -shell-script-candidates %{printf "%s\n%s\n" "y" "n"} "%arg{1}" %{ evaluate-commands %sh{ 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 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 if [ -z "${choice}" ]; then
printf "%s\n" "${function_to_call}" printf "%s\n" "${function_to_call}"
[ -n "${success_message}" ] && printf "%s\n" "echo -markup %{{Information}${success_message}}" [ -n "${success_message}" ] && printf "%s\n" "echo -markup %{{Information}${success_message}}"

View file

@ -12,7 +12,7 @@ define-command -hidden fzf-buffer-search %{ evaluate-commands %sh{
title="fzf buffer search" title="fzf buffer search"
message="Search buffer with fzf, and jump to result location" message="Search buffer with fzf, and jump to result location"
printf "%s\n" "info -title '$title' '$message'" 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 %{%<a-|>cat<space>><space>$buffer_content<ret>;}" printf "%s\n" "execute-keys -draft %{%<a-|>cat<space>><space>$buffer_content<ret>;}"
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}" 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}"
}} }}

View file

@ -33,17 +33,17 @@ bzr status"
IFS=' IFS='
' '
for cmd in $commands; do for cmd in $commands; do
eval $cmd >/dev/null 2>&1 eval "$cmd" >/dev/null 2>&1
res=$? res=$?
if [ "$res" = "0" ]; then if [ "$res" = "0" ]; then
vcs=$(printf "%s\n" "$cmd" | awk '{print $1}') vcs=$(printf "%s\n" "$cmd" | awk '{print $1}')
title="fzf $vcs" title="fzf $vcs"
[ ! -z "${kak_client_env_TMUX}" ] && additional_keybindings=" [ -n "${kak_client_env_TMUX:-}" ] && additional_keybindings="
$kak_opt_fzf_horizontal_map: open file in horizontal split ${kak_opt_fzf_horizontal_map:-}: open file in horizontal split
$kak_opt_fzf_vertical_map: open file in vertical split" ${kak_opt_fzf_vertical_map:-}: open file in vertical split"
message="Open single or multiple files from git tree. message="Open single or multiple files from git tree.
<ret>: open file in new buffer. <ret>: 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" "info -title %{$title} %{$message}"
printf "%s\n" "fzf-$vcs" printf "%s\n" "fzf-$vcs"
exit exit

View file

@ -29,14 +29,14 @@ define-command -hidden fzf-sk-grep %{ evaluate-commands %sh{
title="skim interactive grep" title="skim interactive grep"
message="Interactively grep pattern from current directory message="Interactively grep pattern from current directory
<ret>: open search result in new buffer. <ret>: open search result in new buffer.
$kak_opt_fzf_window_map: open search result in new terminal" ${kak_opt_fzf_window_map:?}: open search result in new terminal"
[ ! -z "${kak_client_env_TMUX}" ] && tmux_keybindings=" [ -n "${kak_client_env_TMUX:-}" ] && tmux_keybindings="
$kak_opt_fzf_horizontal_map: open search result in horizontal split ${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_vertical_map:-}: open search result in vertical split"
printf "%s\n" "info -title '${title}' '${message}${tmux_keybindings}'" 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 %{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}}" 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 %{ define-command -hidden fzf-sk-grep-handler -params 1 %{