get rid of escaping hell
This commit is contained in:
parent
bffe65c405
commit
7c4d921a74
1 changed files with 26 additions and 27 deletions
53
rc/fzf.kak
53
rc/fzf.kak
|
@ -11,45 +11,47 @@
|
||||||
try %{ declare-user-mode fzf } catch %{echo -markup "{Error}Can't declare mode 'fzf' - already exists"}
|
try %{ declare-user-mode fzf } catch %{echo -markup "{Error}Can't declare mode 'fzf' - already exists"}
|
||||||
|
|
||||||
# Options
|
# Options
|
||||||
declare-option -docstring "allow showing preview window
|
declare-option -docstring 'allow showing preview window
|
||||||
Default value:
|
Default value:
|
||||||
true
|
true
|
||||||
" \
|
' \
|
||||||
bool fzf_preview true
|
bool fzf_preview true
|
||||||
|
|
||||||
declare-option -docstring "amount of lines to pass to preview window
|
declare-option -docstring 'amount of lines to pass to preview window
|
||||||
Default value: 100" \
|
Default value: 100' \
|
||||||
int fzf_preview_lines 100
|
int fzf_preview_lines 100
|
||||||
|
|
||||||
declare-option -docstring "highlighter to use in preview window
|
declare-option -docstring 'Highlighter to use in preview window. You can provide
|
||||||
|
only the name of the tool that you want to use, or specify a command.
|
||||||
Supported tools:
|
Supported tools:
|
||||||
<package>: <value>:
|
<package>: <value>:
|
||||||
Bat: ""bat""
|
Bat: "bat"
|
||||||
Coderay: ""coderay""
|
Coderay: "coderay"
|
||||||
Highlight: ""highlight""
|
Highlight: "highlight"
|
||||||
Rouge: ""rouge""
|
Rouge: "rouge"
|
||||||
|
|
||||||
Default arguments:
|
These are default arguments for the tools above:
|
||||||
bat: ""bat --color=always --style=header,grid,numbers {}""
|
<tool>: <value>:
|
||||||
coderay: ""coderay {}""
|
bat: "bat --color=always --style=header,grid,numbers {}"
|
||||||
highlight: ""highlight --failsafe -O ansi {}""
|
coderay: "coderay {}"
|
||||||
rouge: ""rougify {}""
|
highlight: "highlight --failsafe -O ansi {}"
|
||||||
" \
|
rouge: "rougify {}"
|
||||||
|
' \
|
||||||
str fzf_highlighter "highlight"
|
str fzf_highlighter "highlight"
|
||||||
|
|
||||||
declare-option -docstring "height of fzf tmux split in screen lines or percents
|
declare-option -docstring "height of fzf tmux split in screen lines or percents.
|
||||||
Default value: 25%%" \
|
Default value: 25%%" \
|
||||||
str fzf_tmux_height '25%'
|
str fzf_tmux_height '25%'
|
||||||
|
|
||||||
declare-option -docstring "height of fzf tmux split for file preview in screen lines or percents
|
declare-option -docstring "height of fzf tmux split for file preview in screen lines or percents.
|
||||||
Default value: 70%%" \
|
Default value: 70%%" \
|
||||||
str fzf_tmux_height_file_preview '70%'
|
str fzf_tmux_height_file_preview '70%'
|
||||||
|
|
||||||
declare-option -docstring "width of preview window
|
declare-option -docstring "width of preview window.
|
||||||
Default value: 50%%" \
|
Default value: 50%%" \
|
||||||
str fzf_preview_width '50%'
|
str fzf_preview_width '50%'
|
||||||
|
|
||||||
declare-option -docstring "height of preview window
|
declare-option -docstring "height of preview window.
|
||||||
Default value: 60%%" \
|
Default value: 60%%" \
|
||||||
str fzf_preview_height '60%'
|
str fzf_preview_height '60%'
|
||||||
|
|
||||||
|
@ -98,21 +100,18 @@ define-command -hidden fzf -params 2..3 %{ evaluate-commands %sh{
|
||||||
preview_pos="pos=right:$kak_opt_fzf_preview_width;"
|
preview_pos="pos=right:$kak_opt_fzf_preview_width;"
|
||||||
tmux_height=$kak_opt_fzf_tmux_height_file_preview
|
tmux_height=$kak_opt_fzf_tmux_height_file_preview
|
||||||
else
|
else
|
||||||
preview_pos='sleep 0.1; if [ \$(tput cols) -gt \$(expr \$(tput lines) \* 2) ]; then pos=right:'$kak_opt_fzf_preview_width'; else pos=top:'$kak_opt_fzf_preview_height'; fi;'
|
preview_pos='sleep 0.1; if [ $(tput cols) -gt $(expr $(tput lines) \* 2) ]; then pos=right:'$kak_opt_fzf_preview_width'; else pos=top:'$kak_opt_fzf_preview_height'; fi;'
|
||||||
fi
|
fi
|
||||||
additional_flags="--preview '($highlighter || cat {}) 2>/dev/null | head -n $kak_opt_fzf_preview_lines' --preview-window=\$pos $additional_flags"
|
additional_flags="--preview '($highlighter || cat {}) 2>/dev/null | head -n $kak_opt_fzf_preview_lines' --preview-window=\$pos $additional_flags"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ ! -z "${kak_client_env_TMUX}" ]; then
|
if [ ! -z "${kak_client_env_TMUX}" ]; then
|
||||||
[ -z "${items_command##*Q*}" ] && items_command=$(echo $items_command | sed 's:$kind \(\w\):\$kind \"\1\":')
|
|
||||||
[ "$(echo $callback | awk '{print $1}')" = "ctags-search" ] && items_command="$items_command | awk '!a[\$0]++'"
|
|
||||||
cmd="$preview_pos $items_command | fzf-tmux -d $tmux_height --expect ctrl-q $additional_flags > $tmp"
|
cmd="$preview_pos $items_command | fzf-tmux -d $tmux_height --expect ctrl-q $additional_flags > $tmp"
|
||||||
elif [ ! -z "${kak_opt_termcmd}" ]; then
|
elif [ ! -z "${kak_opt_termcmd}" ]; then
|
||||||
path=$(pwd)
|
tmp2=$(mktemp $(eval echo ${TMPDIR:-/tmp}/kak-tmp2.XXXXXX))
|
||||||
additional_flags=$(echo $additional_flags | sed 's:\$pos:\\\\\\\$pos:')
|
chmod 755 $tmp2
|
||||||
[ -z "${items_command##*Q*}" ] && items_command=$(echo $items_command | sed 's:$kind \(\w\):\\\\\\$kind \\\\\\\"\1\\\\\\\":')
|
echo "cd $PWD && $preview_pos $items_command | fzf --expect ctrl-q $additional_flags" > $tmp2
|
||||||
[ "$(echo $callback | awk '{print $1}')" = "ctags-search" ] && items_command="$items_command | awk '!a[\\\\\\\$0]++'"
|
cmd="$kak_opt_termcmd \"sh -c $tmp2\" > $tmp"
|
||||||
cmd="$kak_opt_termcmd \"sh -c \\\"sh=$(command -v sh); SHELL=\\\$sh; export SHELL; cd $path && $preview_pos $items_command | fzf --expect ctrl-q $additional_flags > $tmp\\\"\""
|
|
||||||
else
|
else
|
||||||
echo "fail termcmd option is not set"
|
echo "fail termcmd option is not set"
|
||||||
exit
|
exit
|
||||||
|
|
Loading…
Reference in a new issue