1
0
Fork 0

allow configuring what command to use for opening windows when not using tmux

This commit is contained in:
Andrey Orst 2019-07-07 11:10:16 +03:00
parent d9e702250e
commit 9eb8dc2509

View file

@ -84,34 +84,29 @@ str fzf_vertical_map 'ctrl-v'
declare-option -docstring "mapping to execute action in new horizontal split" \ declare-option -docstring "mapping to execute action in new horizontal split" \
str fzf_horizontal_map 'ctrl-s' str fzf_horizontal_map 'ctrl-s'
declare-option -docstring 'command to use to create new window when not using tmux.
Default value: terminal kak -c %val{session} -e "%arg{@}"' \
str fzf_terminal_cmd 'terminal kak -c %val{session} -e "%arg{@}"'
try %{ declare-user-mode fzf } try %{ declare-user-mode fzf }
define-command -hidden -docstring "wrapper command to create new vertical split" \ define-command -hidden -docstring "wrapper command to create new vertical split" \
fzf-vertical -params .. %{ try %{ fzf-vertical -params .. %{ evaluate-commands %{
tmux-terminal-vertical kak -c %val{session} -e "%arg{@}" tmux-terminal-vertical kak -c %val{session} -e "%arg{@}"
} catch %{
tmux-new-vertical "%arg{@}"
}} }}
define-command -hidden -docstring "wrapper command to create new horizontal split" \ define-command -hidden -docstring "wrapper command to create new horizontal split" \
fzf-horizontal -params .. %{ try %{ fzf-horizontal -params .. %{ evaluate-commands %{
tmux-terminal-horizontal kak -c %val{session} -e "%arg{@}" tmux-terminal-horizontal kak -c %val{session} -e "%arg{@}"
} catch %{
tmux-new-horizontal "%arg{@}"
}} }}
define-command -hidden -docstring "wrapper command to create new terminal" \ define-command -hidden -docstring "wrapper command to create new terminal" \
fzf-window -params .. %{ try %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" 'terminal kak -c %val{session} -e "%arg{@}"' printf "%s\n" "$kak_opt_fzf_terminal_cmd"
fi
} catch %sh{
if [ -n "$kak_client_env_TMUX" ]; then
printf "%s\n" 'tmux-new-window "%arg{@}"'
else
printf "%s\n" 'new "%arg{@}"'
fi fi
}} }}
@ -162,21 +157,21 @@ fzf -params .. %{ evaluate-commands %sh{
# 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_cmd} in case ${kak_opt_fzf_highlight_cmd} 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_cmd}" ;; (*) highlight_cmd="${kak_opt_fzf_highlight_cmd}" ;;
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
@ -208,7 +203,7 @@ fzf -params .. %{ evaluate-commands %sh{
# `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 ${measure} ${tmux_height%%%*} '${fzfcmd}' }" cmd="nop %sh{ command tmux split-window ${measure} ${tmux_height%%%*} '${fzfcmd}' }"
else else
cmd="terminal %{${fzfcmd}}" cmd="${kak_opt_fzf_terminal_cmd%% *} %{${fzfcmd}}"
fi fi
printf "%s\n" "${cmd}" printf "%s\n" "${cmd}"
@ -219,22 +214,26 @@ fzf -params .. %{ evaluate-commands %sh{
( (
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")
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
[ -n "${multiple_cmd}" ] && multiple_cmd=$(printf "%s\n" "${multiple_cmd}" | sed "s/&/&&/g")
while read -r line; do while read -r line; do
printf "%s\n" "evaluate-commands -client ${kak_client} ${wincmd} %{${multiple_cmd} %{${line}}}" line=$(printf "%s\n" "${line}" | sed "s/@/@@/g;s/&/&&/g")
printf "%s\n" "evaluate-commands -client ${kak_client} ${wincmd} %&${multiple_cmd} %@${line}@&"
done done
if [ -n "${post_action}" ]; then if [ -n "${post_action}" ]; then
printf "%s\n" "evaluate-commands -client ${kak_client} %{${post_action}}" post_action=$(printf "%s\n" "${post_action}" | sed "s/&/&&/g")
printf "%s\n" "evaluate-commands -client ${kak_client} %&${post_action}&"
fi fi
) < ${result} | kak -p ${kak_session} ) < ${result} | kak -p ${kak_session}
fi fi