1
0
Fork 0

more args, restructurize

This commit is contained in:
Andrey Orst 2019-03-26 10:22:47 +03:00
parent 7e936ad3aa
commit 2a97c358f6

View file

@ -43,7 +43,7 @@ These are default arguments for the tools above:
highlight: "highlight --failsafe -O ansi {}"
rouge: "rougify {}"
' \
str fzf_highlighter "highlight"
str fzf_highligh_cmd "highlight"
declare-option -docstring "height of fzf tmux split in screen lines or percents.
Default value: 25%%" \
@ -143,7 +143,7 @@ fzf -params 2..4 %{ evaluate-commands %sh{
fi
if [ -z "${command##edit*}" ] && [ $kak_opt_fzf_preview = "true" ]; then
case $kak_opt_fzf_highlighter in
case $kak_opt_fzf_highligh_cmd in
bat)
highlighter="bat --color=always --style=plain {}" ;;
coderay)
@ -153,11 +153,11 @@ fzf -params 2..4 %{ evaluate-commands %sh{
rouge)
highlighter="rougify {}" ;;
bat*|coderay*|highlight*|rougify*)
highlighter=$kak_opt_fzf_highlighter ;;
highlighter=$kak_opt_fzf_highligh_cmd ;;
*)
executable=$(printf "%s\n" "$kak_opt_fzf_highlighter" | grep -o -E '[[:alpha:]]+' | head -1)
executable=$(printf "%s\n" "$kak_opt_fzf_highligh_cmd" | grep -o -E '[[:alpha:]]+' | head -1)
printf "%s\n" "echo -markup %{{Information}'$executable' highlighter is not supported by the script. fzf.kak may not work as you expect.}"
highlighter=$kak_opt_fzf_highlighter ;;
highlighter=$kak_opt_fzf_highligh_cmd ;;
esac
tmux_height=$kak_opt_fzf_tmux_height_file_preview
@ -217,25 +217,54 @@ fzf -params 2..4 %{ evaluate-commands %sh{
}}
define-command -docstring \
"fzf <switches> fzf-command: generic fzf command.
This command can be used to create new fzf wrappers for various Kakoune or external
features. More about arguments:
"fzf <switches>: generic fzf command. This command can be used to create new fzf wrappers for various Kakoune or external features.
Switches:
-kak-cmd <command>: A Kakoune cmd that is applied to fzf resulting value.
-fzf-cmd <items command>: A command that is used to provide list of values to fzf.
-fzf-args <args>: Additional flags for fzf program
-post-action <commands>: Extra commands that are preformed after `-kak-cmd' command." \
-kak-cmd <command>: A Kakoune cmd that is applied to fzf resulting value.
-fzf-cmd <items command>: A command that is used to provide list of values to fzf.
-fzf-args <args>: Additional flags for fzf program
-post-action <commands>: Extra commands that are preformed after `-kak-cmd' command.
-preview: should fzf window include preview" \
new-fzf -shell-script-candidates %{echo "-kak-cmd\n-fzf-cmd\n-fzf-args\n-post-action\n"} -params .. %{ evaluate-commands %sh{
while [ $# -gt 0 ]; do
case $1 in
-kak-cmd) shift; kak_cmd="$kak_cmd $1" ;;
-fzf-cmd) shift; fzf_cmd="$fzf_cmd $1" ;;
-fzf-args) shift; fzf_args="$fzf_args $1" ;;
-post-action) shift; post_action="$post_action $1" ;;
*) ignore="$ignore $1" ;;
-kak-cmd) shift; kak_cmd="${kak_cmd} $1" ;;
-fzf-cmd) shift; fzf_cmd="${fzf_cmd} $1" ;;
-fzf-args) shift; fzf_args="${fzf_args} $1" ;;
-post-action) shift; post_action="${post_action} $1" ;;
-preview) preview=true
*) ignored="${ignored} $1" ;;
esac
shift
done
if [ "$preview" = "true" ] && [ ${kak_opt_fzf_preview} = "true" ]; then
case ${kak_opt_fzf_highligh_cmd} in
bat) highligh_cmd="bat --color=always --style=plain {}" ;;
coderay) highligh_cmd="coderay {}" ;;
highlight) highligh_cmd="highlight --failsafe -O ansi {}" ;;
rouge) highligh_cmd="rougify {}" ;;
*) highligh_cmd="${kak_opt_fzf_highligh_cmd}" ;;
esac
if [ -n "${kak_client_env_TMUX}" ]; then
[ -z "${kak_cmd##edit*}" ] && tmux_height=$kak_opt_fzf_tmux_height_file_preview
preview_pos="pos=right:${kak_opt_fzf_preview_width};"
else
preview_pos="sleep 0.1; [ \$(tput cols) -gt \$(expr \$(tput lines) \* 2) ] && pos=right:${kak_opt_fzf_preview_width} || pos=top:${kak_opt_fzf_preview_height};"
fi
fzf_args="${fzf_args} --preview '(${highligh_cmd} || cat {}) 2>/dev/null | head -n ${kak_opt_fzf_preview_lines}' --preview-window=\${pos}"
fi
fzf_tmp=$(mktemp -d ${TMPDIR:-/tmp}/fzf.kak.XXXXXX)
fzfcmd="${fzf_tmp}/fzfcmd"
result="${fzf_tmp}/result"
printf "%s\n" "cd \"${PWD}\" && ${preview_pos} ${fzf_cmd} | SHELL=$(command -v sh) ${kak_opt_fzf_implementation} ${fzf_args} > ${result}; rm ${fzfcmd}" > ${fzfcmd}
chmod 755 ${fzfcmd}
if [ -n "${kak_client_env_TMUX}" ]; then
[ -n "${tmux_height%%*%}" ] && measure="-l" || measure="-p"
cmd="nop %sh{ command tmux split-window ${measure} ${tmux_height%%%*} 'sh -c ${fzfcmd}' }"
else
cmd="terminal %{${fzfcmd}}"
fi
}}