From 8382d908d0cf078ca927643661dcaa6f553b8224 Mon Sep 17 00:00:00 2001 From: Andrey Orst Date: Mon, 13 May 2019 21:34:46 +0300 Subject: [PATCH] make keys mapable. Fix #58 --- README.md | 11 +++++++++++ rc/fzf.kak | 17 +++++++++++++---- rc/modules/VCS/fzf-bzr.kak | 4 ++-- rc/modules/VCS/fzf-git.kak | 4 ++-- rc/modules/VCS/fzf-hg.kak | 4 ++-- rc/modules/VCS/fzf-svn.kak | 4 ++-- rc/modules/fzf-buffer.kak | 10 +++++----- rc/modules/fzf-ctags.kak | 10 +++++----- rc/modules/fzf-file.kak | 10 +++++----- rc/modules/fzf-vcs.kak | 6 +++--- rc/modules/sk-grep.kak | 10 +++++----- 11 files changed, 55 insertions(+), 35 deletions(-) diff --git a/README.md b/README.md index 93505c3..758ebeb 100644 --- a/README.md +++ b/README.md @@ -109,6 +109,17 @@ is being used to create new windows. **fzf.kak** features a lot of settings via options that can be altered to change how **fzf.kak** behaves. +### Mappings +You can define what keys to use in `fzf` window via these options: + +- `fzf_window_map` - mapping to perform an action in new window, +- `fzf_vertical_map` - mapping to perform an action in new vertical split + (Tmux), +- `fzf_horizontal_map` - mapping to perform an action in new horizontal split. + +These options should be set to work with fzf `--expect` parameter, so check out +fzf documentation on this. + ### File command You can configure what command to use to search for files, and it's arguments. Supported tools are [GNU Find][12], [The Silver Searcher][13], [ripgrep][14], diff --git a/rc/fzf.kak b/rc/fzf.kak index c3f3743..38031a5 100644 --- a/rc/fzf.kak +++ b/rc/fzf.kak @@ -66,6 +66,15 @@ declare-option -docstring "height of preview window. Default value: 60%%" \ str fzf_preview_height '60%' +declare-option -docstring "mapping to execute action in new window" \ +str fzf_window_map 'ctrl-w' + +declare-option -docstring "mapping to execute action in new vertical split" \ +str fzf_vertical_map 'ctrl-v' + +declare-option -docstring "mapping to execute action in new horizontal split" \ +str fzf_horizontal_map 'ctrl-s' + define-command -docstring "Enter fzf-mode. fzf-mode contains mnemonic key bindings for every fzf.kak command @@ -211,10 +220,10 @@ fzf -params .. %{ evaluate-commands %sh{ ( while read -r line; do case ${line} in - ctrl-w) wincmd="fzf-window" ;; - ctrl-s) wincmd="fzf-vertical" ;; - ctrl-v) 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 printf "%s\n" "evaluate-commands -client ${kak_client} ${wincmd} %{${kakoune_cmd} %{${item}}}" diff --git a/rc/modules/VCS/fzf-bzr.kak b/rc/modules/VCS/fzf-bzr.kak index 29baf92..5dcb0c2 100644 --- a/rc/modules/VCS/fzf-bzr.kak +++ b/rc/modules/VCS/fzf-bzr.kak @@ -30,8 +30,8 @@ define-command -hidden fzf-bzr %{ evaluate-commands %sh{ bzr*) cmd=$kak_opt_fzf_bzr_command ;; esac - [ ! -z "${kak_client_env_TMUX}" ] && additional_flags="--expect ctrl-v --expect ctrl-s" - printf "%s\n" "fzf -kak-cmd %{cd $repo_root; edit -existing} -items-cmd %{$cmd} -fzf-args %{-m --expect ctrl-w $additional_flags} -post-action %{cd $current_path}" + [ ! -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 %{cd $repo_root; edit -existing} -items-cmd %{$cmd} -fzf-args %{-m --expect $kak_opt_fzf_window_map $additional_flags} -post-action %{cd $current_path}" }} § diff --git a/rc/modules/VCS/fzf-git.kak b/rc/modules/VCS/fzf-git.kak index 9d54a99..cbac91a 100644 --- a/rc/modules/VCS/fzf-git.kak +++ b/rc/modules/VCS/fzf-git.kak @@ -30,8 +30,8 @@ define-command -override -hidden fzf-git %{ evaluate-commands %sh{ git*) cmd=$kak_opt_fzf_git_command ;; esac - [ ! -z "${kak_client_env_TMUX}" ] && additional_flags="--expect ctrl-v --expect ctrl-s" - printf "%s\n" "fzf -kak-cmd %{cd $repo_root; edit -existing} -items-cmd %{$cmd} -fzf-args %{-m --expect ctrl-w $additional_flags} -post-action %{cd $current_path}" + [ ! -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 %{cd $repo_root; edit -existing} -items-cmd %{$cmd} -fzf-args %{-m --expect $kak_opt_fzf_window_map $additional_flags} -post-action %{cd $current_path}" }} § diff --git a/rc/modules/VCS/fzf-hg.kak b/rc/modules/VCS/fzf-hg.kak index 0409451..ab21d51 100644 --- a/rc/modules/VCS/fzf-hg.kak +++ b/rc/modules/VCS/fzf-hg.kak @@ -30,8 +30,8 @@ define-command -hidden fzf-hg %{ evaluate-commands %sh{ hg*) cmd=$kak_opt_fzf_hg_command ;; esac - [ ! -z "${kak_client_env_TMUX}" ] && additional_flags="--expect ctrl-v --expect ctrl-s" - printf "%s\n" "fzf -kak-cmd %{cd $repo_root; edit -existing} -items-cmd %{$cmd} -fzf-args %{-m --expect ctrl-w $additional_flags} -post-action %{cd $current_path}" + [ ! -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 %{cd $repo_root; edit -existing} -items-cmd %{$cmd} -fzf-args %{-m --expect $kak_opt_fzf_window_map $additional_flags} -post-action %{cd $current_path}" }} § diff --git a/rc/modules/VCS/fzf-svn.kak b/rc/modules/VCS/fzf-svn.kak index a5305b8..48b520c 100644 --- a/rc/modules/VCS/fzf-svn.kak +++ b/rc/modules/VCS/fzf-svn.kak @@ -29,8 +29,8 @@ define-command -hidden fzf-svn %{ evaluate-commands %sh{ svn*) cmd=$kak_opt_fzf_svn_command ;; esac - [ ! -z "${kak_client_env_TMUX}" ] && additional_flags="--expect ctrl-v --expect ctrl-s" - printf "%s\n" "fzf -kak-cmd %{cd $repo_root; edit -existing} -items-cmd %{$cmd} -fzf-args %{-m --expect ctrl-w $additional_flags} -post-action %{cd $current_path}" + [ ! -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 %{cd $repo_root; edit -existing} -items-cmd %{$cmd} -fzf-args %{-m --expect $kak_opt_fzf_window_map $additional_flags} -post-action %{cd $current_path}" }} § diff --git a/rc/modules/fzf-buffer.kak b/rc/modules/fzf-buffer.kak index aa32522..c1cc1e1 100644 --- a/rc/modules/fzf-buffer.kak +++ b/rc/modules/fzf-buffer.kak @@ -22,14 +22,14 @@ define-command -hidden fzf-buffer %{ evaluate-commands %sh{ message="Set buffer to edit in current client. : switch to selected buffer. -: open buffer in new window" +$kak_opt_fzf_window_map: open buffer in new window" [ ! -z "${kak_client_env_TMUX}" ] && tmux_keybindings=" -: open buffer in horizontal split -: open buffer in vertical split" +$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 ctrl-v --expect ctrl-s" + [ ! -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 %{buffer} -items-cmd %{(cat $buffers; rm $buffers)} -fzf-args %{--expect ctrl-w $additional_flags}" + printf "%s\n" "fzf -kak-cmd %{buffer} -items-cmd %{(cat $buffers; rm $buffers)} -fzf-args %{--expect $kak_opt_fzf_window_map $additional_flags}" }} § diff --git a/rc/modules/fzf-ctags.kak b/rc/modules/fzf-ctags.kak index b6941e7..644780b 100644 --- a/rc/modules/fzf-ctags.kak +++ b/rc/modules/fzf-ctags.kak @@ -815,17 +815,17 @@ define-command -hidden fzf-tag -params ..2 %{ evaluate-commands %sh{ message="Jump to a symbol''s definition : open tag in new buffer -: open tag in new terminal" +$kak_opt_fzf_window_map: open tag in new terminal" [ -n "${kak_client_env_TMUX}" ] && tmux_keybindings=" -: open tag in horizontal split -: open tag in vertical split" +$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 ctrl-v --expect ctrl-s" + [ ! -z "${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 ctrl-w $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}" }} § diff --git a/rc/modules/fzf-file.kak b/rc/modules/fzf-file.kak index aafeed7..7708542 100644 --- a/rc/modules/fzf-file.kak +++ b/rc/modules/fzf-file.kak @@ -53,14 +53,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. -: open file in new terminal" +$kak_opt_fzf_window_map: open file in new terminal" [ ! -z "${kak_client_env_TMUX}" ] && tmux_keybindings=" -: open file in horizontal split -: open file in vertical split" +$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 ctrl-v --expect ctrl-s" - printf "%s\n" "fzf -preview -kak-cmd %{edit -existing} -items-cmd %{$cmd} -fzf-args %{-m --expect ctrl-w $additional_flags}" + [ ! -z "${kak_client_env_TMUX}" ] && additional_flags="--expect $kak_opt_fzf_vertical_map --expect $kak_opt_fzf_horizontal_map" + printf "%s\n" "fzf -preview -kak-cmd %{edit -existing} -items-cmd %{$cmd} -fzf-args %{-m --expect $kak_opt_fzf_window_map $additional_flags}" }} § diff --git a/rc/modules/fzf-vcs.kak b/rc/modules/fzf-vcs.kak index da0f5d4..9508da8 100644 --- a/rc/modules/fzf-vcs.kak +++ b/rc/modules/fzf-vcs.kak @@ -47,11 +47,11 @@ bzr status" vcs=$(printf "%s\n" "$cmd" | awk '{print $1}') title="fzf $vcs" [ ! -z "${kak_client_env_TMUX}" ] && additional_keybindings=" -: open file in horizontal split -: open file in vertical split" +$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. -: 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 f52544c..ed88525 100644 --- a/rc/modules/sk-grep.kak +++ b/rc/modules/sk-grep.kak @@ -33,14 +33,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. -: open search result in new terminal" +$kak_opt_fzf_window_map: open search result in new terminal" [ ! -z "${kak_client_env_TMUX}" ] && tmux_keybindings=" -: open search result in horizontal split -: open search result in vertical split" +$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 ctrl-v --expect ctrl-s" - printf "%s\n" "fzf -kak-cmd %{fzf-sk-grep-handler} -fzf-impl %{sk -m -i -c '$kak_opt_fzf_sk_grep_command {}'} -fzf-args %{--expect ctrl-w $additional_flags} -multiple-cmd %{fzf-sk-populate-grep} -post-action %{buffer %opt{fzf_sk_first_file}}" + [ ! -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 -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 %{