From a8436627c3157bd105258d57266c7f7281e17705 Mon Sep 17 00:00:00 2001 From: Andrey Listopadov Date: Fri, 19 Mar 2021 21:00:49 +0300 Subject: [PATCH 1/7] refactor modules to provide submodules --- rc/fzf.kak | 13 ++++--------- rc/modules/VCS/fzf-bzr.kak | 19 ++++++++----------- rc/modules/VCS/fzf-git.kak | 21 +++++++++------------ rc/modules/VCS/fzf-hg.kak | 18 ++++++++---------- rc/modules/VCS/fzf-svn.kak | 19 ++++++++----------- rc/modules/fzf-buffer.kak | 20 ++++++++------------ rc/modules/fzf-cd.kak | 21 ++++++++------------- rc/modules/fzf-ctags.kak | 19 ++++++++----------- rc/modules/fzf-file.kak | 19 ++++++++----------- rc/modules/fzf-grep.kak | 18 ++++++++---------- rc/modules/fzf-project.kak | 21 ++++++++++----------- rc/modules/fzf-search.kak | 18 +++++++----------- rc/modules/fzf-vcs.kak | 30 +++++++++++------------------- rc/modules/sk-grep.kak | 26 +++++++++++--------------- 14 files changed, 116 insertions(+), 166 deletions(-) diff --git a/rc/fzf.kak b/rc/fzf.kak index 7bff9df..7c2811a 100644 --- a/rc/fzf.kak +++ b/rc/fzf.kak @@ -1,12 +1,7 @@ -# ╭─────────────╥───────────────────╮ -# │ Author: ║ Plugin: │ -# │ Andrey Orst ║ fzf.kak │ -# ╞═════════════╩═══════════════════╡ -# │ This plugin implements fzf │ -# │ mode for Kakoune. This mode │ -# │ adds several mappings to invoke │ -# │ different fzf commands. │ -# ╰─────────────────────────────────╯ +# Author: Andrey Listopadov +# This plugin implements fzf mode for Kakoune. +# This mode adds several mappings to invoke different fzf commands. +# https://github.com/andreyorst/fzf.kak define-command -docstring "Enter fzf-mode. fzf-mode contains mnemonic key bindings for every fzf.kak command diff --git a/rc/modules/VCS/fzf-bzr.kak b/rc/modules/VCS/fzf-bzr.kak index e0f27a2..cdd10f8 100644 --- a/rc/modules/VCS/fzf-bzr.kak +++ b/rc/modules/VCS/fzf-bzr.kak @@ -1,13 +1,12 @@ -# ╭─────────────╥─────────────────────────╮ -# │ Author: ║ File: │ -# │ Andrey Orst ║ fzf-svn.kak │ -# ╞═════════════╩═════════════════════════╡ -# │ Submodule for Bzr support for fzf.kak │ -# ╞═══════════════════════════════════════╡ -# │ GitHub.com/andreyorst/fzf.kak │ -# ╰───────────────────────────────────────╯ +# Author: Andrey Listopadov +# Submodule for Bzr support for fzf.kak +# https://github.com/andreyorst/fzf.kak -hook global ModuleLoaded fzf_vcs %§ +hook global ModuleLoaded fzf-vcs %{ + map global fzf-vcs -docstring "edit file from GNU Bazaar tree" 'b' ': require-module fzf-bzr; fzf-bzr' +} + +provide-module fzf-bzr %§ declare-option -docstring "command to provide list of files in GNU Bazaar repository to fzf. Arguments are supported Supported tools: @@ -19,8 +18,6 @@ Default arguments: " \ str fzf_bzr_command "bzr" -map global fzf-vcs -docstring "edit file from GNU Bazaar tree" 'b' ': fzf-bzr' - define-command -hidden fzf-bzr %{ evaluate-commands %sh{ repo_root=$(bzr root) case $kak_opt_fzf_bzr_command in diff --git a/rc/modules/VCS/fzf-git.kak b/rc/modules/VCS/fzf-git.kak index 117f184..d1e878b 100644 --- a/rc/modules/VCS/fzf-git.kak +++ b/rc/modules/VCS/fzf-git.kak @@ -1,13 +1,12 @@ -# ╭─────────────╥─────────────────────────╮ -# │ Author: ║ File: │ -# │ Andrey Orst ║ fzf-svn.kak │ -# ╞═════════════╩═════════════════════════╡ -# │ Submodule for Git support for fzf.kak │ -# ╞═══════════════════════════════════════╡ -# │ GitHub.com/andreyorst/fzf.kak │ -# ╰───────────────────────────────────────╯ +# Author: Andrey Listopadov +# Submodule for Git support for fzf.kak +# https://github.com/andreyorst/fzf.kak -hook global ModuleLoaded fzf_vcs %§ +hook global ModuleLoaded fzf-vcs %§ + map global fzf-vcs -docstring "edit file from Git tree" 'g' ': require-module fzf-git; fzf-git' +§ + +provide-module fzf-git %§ declare-option -docstring "command to provide list of files in git tree to fzf. Arguments are supported Supported tools: @@ -19,9 +18,7 @@ Default arguments: " \ str fzf_git_command "git" -map global fzf-vcs -docstring "edit file from Git tree" 'g' ': fzf-git' - -define-command -override -hidden fzf-git %{ evaluate-commands %sh{ +define-command -hidden fzf-git %{ evaluate-commands %sh{ case $kak_opt_fzf_git_command in (git) cmd='git ls-tree --full-tree --name-only -r HEAD' ;; diff --git a/rc/modules/VCS/fzf-hg.kak b/rc/modules/VCS/fzf-hg.kak index 743e0af..9ce5e9c 100644 --- a/rc/modules/VCS/fzf-hg.kak +++ b/rc/modules/VCS/fzf-hg.kak @@ -1,13 +1,12 @@ -# ╭─────────────╥────────────────────────╮ -# │ Author: ║ File: │ -# │ Andrey Orst ║ fzf-svn.kak │ -# ╞═════════════╩════════════════════════╡ -# │ Submodule for Hg support for fzf.kak │ -# ╞══════════════════════════════════════╡ -# │ GitHub.com/andreyorst/fzf.kak │ -# ╰──────────────────────────────────────╯ +# Author: Andrey Listopadov +# Submodule for Hg support for fzf.kak +# https://github.com/andreyorst/fzf.kak -hook global ModuleLoaded fzf_vcs %§ +hook global ModuleLoaded fzf-vcs %{ + map global fzf-vcs -docstring "edit file from mercurial tree" 'h' ': require-module fzf-hg; fzf-hg' +} + +provide-module fzf-hg %§ declare-option -docstring "command to provide list of files in mercurial repository to fzf. Arguments are supported Supported tools: @@ -19,7 +18,6 @@ Default arguments: " \ str fzf_hg_command "hg" -map global fzf-vcs -docstring "edit file from mercurial tree" 'h' ': fzf-hg' define-command -hidden fzf-hg %{ evaluate-commands %sh{ case $kak_opt_fzf_hg_command in diff --git a/rc/modules/VCS/fzf-svn.kak b/rc/modules/VCS/fzf-svn.kak index 0792773..01812a1 100644 --- a/rc/modules/VCS/fzf-svn.kak +++ b/rc/modules/VCS/fzf-svn.kak @@ -1,13 +1,12 @@ -# ╭─────────────╥─────────────────────────╮ -# │ Author: ║ File: │ -# │ Andrey Orst ║ fzf-svn.kak │ -# ╞═════════════╩═════════════════════════╡ -# │ Submodule for Svn support for fzf.kak │ -# ╞═══════════════════════════════════════╡ -# │ GitHub.com/andreyorst/fzf.kak │ -# ╰───────────────────────────────────────╯ +# Author: Andrey Listopadov +# Submodule for Svn support for fzf.kak +# https://github.com/andreyorst/fzf.kak -hook global ModuleLoaded fzf_vcs %§ +hook global ModuleLoaded fzf-vcs %§ + map global fzf-vcs -docstring "edit file from Subversion tree" 's' ': require-module fzf-svn; fzf-svn' +§ + +provide-module fzf-svn %§ declare-option -docstring "command to provide list of files in svn repository to fzf. Arguments are supported Supported tools: @@ -19,8 +18,6 @@ Default arguments: " \ str fzf_svn_command "svn" -map global fzf-vcs -docstring "edit file from Subversion tree" 's' ': fzf-svn' - define-command -hidden fzf-svn %{ evaluate-commands %sh{ current_path=$(pwd) repo_root=$(svn info | awk -F': ' '/Working Copy Root Path: .*/ {print $2}') diff --git a/rc/modules/fzf-buffer.kak b/rc/modules/fzf-buffer.kak index 4c34d78..7de2205 100644 --- a/rc/modules/fzf-buffer.kak +++ b/rc/modules/fzf-buffer.kak @@ -1,17 +1,13 @@ -# ╭─────────────╥────────────────────────╮ -# │ Author: ║ File: │ -# │ Andrey Orst ║ fzf-buffer.kak │ -# ╞═════════════╩════════════════════════╡ -# │ Module for changing buffers with fzf │ -# │ for fzf.kak plugin │ -# ╞══════════════════════════════════════╡ -# │ GitHub.com/andreyorst/fzf.kak │ -# ╰──────────────────────────────────────╯ +# Author: Andrey Listopadov +# Module for changing buffers with fzf for fzf.kak plugin +# https://github.com/andreyorst/fzf.kak -hook global ModuleLoaded fzf %§ +hook global ModuleLoaded fzf %{ + map global fzf -docstring "open buffer" 'b' ': require-module fzf-buffer; fzf-buffer' + map global fzf -docstring "delete buffer" '' ': require-module fzf-buffer; fzf-delete-buffer' +} -map global fzf -docstring "open buffer" 'b' ': fzf-buffer' -map global fzf -docstring "delete buffer" '' ': fzf-delete-buffer' +provide-module fzf-buffer %§ define-command -hidden fzf-buffer %{ evaluate-commands %sh{ buffers="" diff --git a/rc/modules/fzf-cd.kak b/rc/modules/fzf-cd.kak index fb19ade..f4917ec 100644 --- a/rc/modules/fzf-cd.kak +++ b/rc/modules/fzf-cd.kak @@ -1,14 +1,12 @@ -# ╭─────────────╥────────────────────────╮ -# │ Author: ║ File: │ -# │ Andrey Orst ║ fzf-cd.kak │ -# ╞═════════════╩════════════════════════╡ -# │ Module for changing directories with │ -# │ fzf for fzf.kak plugin │ -# ╞══════════════════════════════════════╡ -# │ GitHub.com/andreyorst/fzf.kak │ -# ╰──────────────────────────────────────╯ +# Author: Andrey Listopadov +# Module for changing directories with fzf for fzf.kak plugin +# https://github.com/andreyorst/fzf.kak -hook global ModuleLoaded fzf %§ +hook global ModuleLoaded fzf %{ + map global fzf -docstring "change directory" 'c' ': require-module fzf-cd; fzf-cd' +} + +provide-module fzf-cd %§ declare-option -docstring "command to provide list of directories to fzf. Default value: @@ -31,9 +29,6 @@ str cd_preview_command "tree -d {}" declare-option -docstring 'maximum amount of previewed directories' \ int fzf_preview_dirs '300' - -map global fzf -docstring "change directory" 'c' ': fzf-cd' - 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 diff --git a/rc/modules/fzf-ctags.kak b/rc/modules/fzf-ctags.kak index 5ce7614..9f4e872 100644 --- a/rc/modules/fzf-ctags.kak +++ b/rc/modules/fzf-ctags.kak @@ -1,20 +1,17 @@ -# ╭─────────────╥──────────────────────────╮ -# │ Author: ║ File: │ -# │ Andrey Orst ║ fzf-ctags.kak │ -# ╞═════════════╩══════════════════════════╡ -# │ Module for searching tags with fzf │ -# │ and universal-ctags for fzf.kak plugin │ -# ╞════════════════════════════════════════╡ -# │ GitHub.com/andreyorst/fzf.kak │ -# ╰────────────────────────────────────────╯ +# Author: Andrey Listopadov +# Module for searching tags with fzf and universal-ctags for fzf.kak plugin +# https://github.com/andreyorst/fzf.kak -hook global ModuleLoaded fzf %§ +hook global ModuleLoaded fzf %{ + map global fzf -docstring "find tag" 't' ': require-module fzf-ctags; fzf-tag' +} + +provide-module fzf-ctags %§ declare-option -docstring "file that should be used by fzf-tag to provide tags. Default value: tags" \ str fzf_tag_file_name "tags" -map global fzf -docstring "find tag" 't' ': fzf-tag' declare-option -hidden bool fzf_tag_filters_defined false diff --git a/rc/modules/fzf-file.kak b/rc/modules/fzf-file.kak index 479a496..a3ea14d 100644 --- a/rc/modules/fzf-file.kak +++ b/rc/modules/fzf-file.kak @@ -1,14 +1,12 @@ -# ╭─────────────╥────────────────────────╮ -# │ Author: ║ File: │ -# │ Andrey Orst ║ fzf-file.kak │ -# ╞═════════════╩════════════════════════╡ -# │ Module for opening files with fzf │ -# │ for fzf.kak plugin │ -# ╞══════════════════════════════════════╡ -# │ GitHub.com/andreyorst/fzf.kak │ -# ╰──────────────────────────────────────╯ +# Author: Andrey Listopadov +# Module for opening files with fzf for fzf.kak plugin +# https://github.com/andreyorst/fzf.kak -hook global ModuleLoaded fzf %§ +hook global ModuleLoaded fzf %{ + map global fzf -docstring "open file" 'f' ': require-module fzf-file; fzf-file' +} + +provide-module fzf-file %§ declare-option -docstring "command to provide list of files to fzf. Arguments are supported Supported tools: @@ -32,7 +30,6 @@ Default value: ' \ bool fzf_file_preview true -map global fzf -docstring "open file" 'f' ': fzf-file' define-command -hidden fzf-file %{ evaluate-commands %sh{ if [ -z "$(command -v $kak_opt_fzf_file_command)" ]; then diff --git a/rc/modules/fzf-grep.kak b/rc/modules/fzf-grep.kak index 10c4e3c..936edef 100644 --- a/rc/modules/fzf-grep.kak +++ b/rc/modules/fzf-grep.kak @@ -1,13 +1,12 @@ -# ╭─────────────╥────────────────────────╮ -# │ Author: ║ File: │ -# │ Andrey Orst ║ fzf-grep.kak │ -# ╞═════════════╩════════════════════════╡ -# │ Module for grepping file contents │ -# ╞══════════════════════════════════════╡ -# │ GitHub.com/andreyorst/fzf.kak │ -# ╰──────────────────────────────────────╯ +# Author: Andrey Listopadov +# Module for grepping file contents +# https://github.com/andreyorst/fzf.kak -hook global ModuleLoaded fzf %§ +hook global ModuleLoaded fzf %{ + map -docstring 'grep file contents recursively' global fzf g ': require-module fzf-grep; fzf-grep' +} + +provide-module fzf-grep %§ declare-option -docstring "what command to use to provide list of grep search matches. Grep output must follow the format of 'filename:line-number:text' @@ -16,7 +15,6 @@ Default value: grep -RHn" \ str fzf_grep_command 'grep' -map -docstring 'grep file contents recursively' global fzf g ': fzf-grep' define-command -hidden fzf-grep %{ evaluate-commands %sh{ if [ -z "$(command -v $kak_opt_fzf_grep_command)" ]; then diff --git a/rc/modules/fzf-project.kak b/rc/modules/fzf-project.kak index d4fc3bf..4255eaa 100644 --- a/rc/modules/fzf-project.kak +++ b/rc/modules/fzf-project.kak @@ -1,19 +1,18 @@ -# ╭─────────────╥────────────────────────╮ -# │ Author: ║ File: │ -# │ Andrey Orst ║ fzf-project.kak │ -# ╞═════════════╩════════════════════════╡ -# │ Module for storing and loading │ -# │ projects with fzf for fzf.kak plugin │ -# ╞══════════════════════════════════════╡ -# │ GitHub.com/andreyorst/fzf.kak │ -# ╰──────────────────────────────────────╯ +# Author: Andrey Listopadov +# Module for storing and loading projects with fzf for fzf.kak plugin +# https://github.com/andreyorst/fzf.kak -hook global ModuleLoaded fzf %§ +hook global ModuleLoaded fzf %{ + map global fzf -docstring "open project" 'p' ': require-module fzf-project; fzf-project' +} + +provide-module fzf-project %§ + +require-module fzf-file declare-option -docstring "file where saved projects are stored" str fzf_project_file "%val{config}/.fzf-projects" declare-option -docstring %sh{ printf "%s\n" "use '~/' instead of '${HOME}'" } bool fzf_project_use_tilda false -map global fzf -docstring "open project" 'p' ': fzf-project' try %{ declare-user-mode fzf-project } diff --git a/rc/modules/fzf-search.kak b/rc/modules/fzf-search.kak index 961de83..5ce23b2 100644 --- a/rc/modules/fzf-search.kak +++ b/rc/modules/fzf-search.kak @@ -1,16 +1,12 @@ -# ╭─────────────╥────────────────────────╮ -# │ Author: ║ File: │ -# │ Andrey Orst ║ fzf-search.kak │ -# ╞═════════════╩════════════════════════╡ -# │ Module for searching inside current │ -# │ buffer with fzf for fzf.kak │ -# ╞══════════════════════════════════════╡ -# │ GitHub.com/andreyorst/fzf.kak │ -# ╰──────────────────────────────────────╯ +# Author: Andrey Listopadov +# Module for searching inside current buffer with fzf for fzf.kak +# https://github.com/andreyorst/fzf.kak -hook global ModuleLoaded fzf %§ +hook global ModuleLoaded fzf %{ + map global fzf -docstring "search in buffer" 's' ': require-module fzf-search; fzf-buffer-search' +} -map global fzf -docstring "search in buffer" 's' ': fzf-buffer-search' +provide-module fzf-search %§ define-command -hidden fzf-buffer-search %{ evaluate-commands %sh{ title="fzf buffer search" diff --git a/rc/modules/fzf-vcs.kak b/rc/modules/fzf-vcs.kak index 58d4033..242413f 100644 --- a/rc/modules/fzf-vcs.kak +++ b/rc/modules/fzf-vcs.kak @@ -1,26 +1,18 @@ -# ╭─────────────╥────────────────────────╮ -# │ Author: ║ File: │ -# │ Andrey Orst ║ fzf-vcs.kak │ -# ╞═════════════╩════════════════════════╡ -# │ Module that declares VCS submodule │ -# │ for various version control systems │ -# │ to open files with fzf │ -# ╞══════════════════════════════════════╡ -# │ GitHub.com/andreyorst/fzf.kak │ -# ╰──────────────────────────────────────╯ +# Author: Andrey Listopadov +# Module that declares VCS submodule for various version control systems to open files with fzf +# https://github.com/andreyorst/fzf.kak hook global ModuleLoaded fzf %§ - -map global fzf -docstring "edit file from vcs repo" 'v' ': require-module fzf_vcs; fzf-vcs' -map global fzf -docstring "switch to vcs selection mode" '' ': fzf-vcs-mode' - -define-command -docstring "Enter fzf-vcs-mode. -This mode allows selecting specific vcs command." \ -fzf-vcs-mode %{ require-module fzf_vcs; evaluate-commands 'enter-user-mode fzf-vcs' } - + map global fzf -docstring "edit file from vcs repo" 'v' ': require-module fzf-vcs; fzf-vcs' + map global fzf -docstring "switch to vcs selection mode" '' ': require-module fzf-vcs; enter-user-mode fzf-vcs' § -provide-module fzf_vcs %§ +provide-module fzf-vcs %§ + +require-module fzf-git +require-module fzf-svn +require-module fzf-hg +require-module fzf-bzr declare-user-mode fzf-vcs diff --git a/rc/modules/sk-grep.kak b/rc/modules/sk-grep.kak index ee21975..72a4dcd 100644 --- a/rc/modules/sk-grep.kak +++ b/rc/modules/sk-grep.kak @@ -1,14 +1,16 @@ -# ╭─────────────╥────────────────────────╮ -# │ Author: ║ File: │ -# │ Andrey Orst ║ sk-grep.kak │ -# ╞═════════════╩════════════════════════╡ -# │ Module running interactive grep with │ -# │ ski for fzf.kak │ -# ╞══════════════════════════════════════╡ -# │ GitHub.com/andreyorst/fzf.kak │ -# ╰──────────────────────────────────────╯ +# Author: Andrey Listopadov +# Module running interactive grep with skim for fzf.kak +# https://github.com/andreyorst/fzf.kak hook global ModuleLoaded fzf %§ + evaluate-commands %sh{ + if [ -n "$(command -v sk)" ]; then + printf "%s\n" "map global fzf -docstring %{Interactive grep with skim} '' ': require-module fzf-sk-grep; fzf-sk-grep'" + fi + } +§ + +provide-module fzf-sk-grep %§ declare-option -docstring "what command to use to provide list of grep search matches. Grep output must follow the format of 'filename:line-number:text' @@ -19,12 +21,6 @@ str fzf_sk_grep_command 'grep -RHn' declare-option -hidden str fzf_sk_first_file '' -evaluate-commands %sh{ - if [ -n "$(command -v sk)" ]; then - printf "%s\n" "map global fzf -docstring %{Interactive grep with skim} '' ': fzf-sk-grep'" - fi -} - define-command -hidden fzf-sk-grep %{ evaluate-commands %sh{ if [ -z "$(command -v sk)" ]; then printf "%s\n" "echo -markup %{{Information}skim required to run this command}" From 1a405fcc43a3f77fb90a0ebfe1b9c42ed51de48e Mon Sep 17 00:00:00 2001 From: Andrey Listopadov Date: Fri, 19 Mar 2021 21:36:37 +0300 Subject: [PATCH 2/7] convert to one sentence per line style --- README.md | 242 +++++++++++++++++++++++------------------------------- 1 file changed, 101 insertions(+), 141 deletions(-) diff --git a/README.md b/README.md index 851ced5..078b1db 100644 --- a/README.md +++ b/README.md @@ -3,17 +3,16 @@ [![GitHub release][1]][2] [![GitHub Release Date][3]][4] ![Github commits (since latest release)][5] ![license][6] -**fzf.kak** is a plugin for [Kakoune][7] editor, that brings integration with -[fzf][8] tool. This plugin is being tested against Kakoune master branch. -**fzf.kak** also supports [skim][9], which can be used via `fzf_implementation` -option. +**fzf.kak** is a plugin for [Kakoune][7] editor, that brings integration with [fzf][8] tool. +This plugin is being tested against Kakoune master branch. +**fzf.kak** also supports [skim][9], which can be used via `fzf_implementation` option. ![showcase][10] ## Installation ### With [plug.kak][11] (recommended) -Recommended way to install is to use plug.kak plugin manager. You can install -**fzf.kak** by adding this to your `kakrc`: +Recommended way to install is to use plug.kak plugin manager. +You can install **fzf.kak** by adding this to your `kakrc`: ```kak plug "andreyorst/fzf.kak" @@ -23,18 +22,15 @@ Then reload Kakoune config or restart Kakoune and run `:plug-install`. Now you can proceed to the [configuration][23] section. ### Without plugin manager -This plugin consists of several parts which are "modules", that provide -different functions to plugin. There's central module that must be loaded -before any other module, named `fzf.kak`, so in order to properly load -**fzf.kak** plugin, you need to source it in your `kakrc`. +This plugin consists of several parts which are "modules", that provide different functions to plugin. +There's central module that must be loaded before any other module, named `fzf.kak`, so in order to properly load **fzf.kak** plugin, you need to source it in your `kakrc`. ```sh source "/path/to/fzf.kak/rc/fzf.kak" # loading base fzf module ``` -This will load base `fzf` module, but It can't do anything on it's own. You can -load only needed modules, to keep your configuration rather simple, or load -every module if you need all plugin abilities: +This will load base `fzf` module, but It can't do anything on it's own. +You can load only needed modules, to keep your configuration rather simple, or load every module if you need all plugin abilities: ```sh source "/path/to/fzf.kak/rc/modules/fzf-file.kak" # fzf file chooser @@ -44,16 +40,15 @@ source "/path/to/fzf.kak/rc/modules/fzf-cd.kak" # change server's working di source "/path/to/fzf.kak/rc/modules/fzf-ctags.kak" # search for tag in your project ctags file ``` -The same principle is applied to handling different version control systems. You -need a base module for `fzf`, called `fzf-vcs.kak` and its sub-modules for each -VCS. There are plenty of version control systems, so modules come in handy. +The same principle is applied to handling different version control systems. +You need a base module for `fzf`, called `fzf-vcs.kak` and its sub-modules for each VCS. +There are plenty of version control systems, so modules come in handy. ```sh source "/path/to/fzf.kak/rc/modules/fzf-vcs.kak" # VCS base module ``` -So if you never work with, say, GNU Bazaar, or Mercurial you can remove them -from your configuration. +So if you never work with, say, GNU Bazaar, or Mercurial you can remove them from your configuration. ```sh source "/path/to/fzf.kak/rc/modules/VCS/fzf-bzr.kak" # GNU Bazaar support @@ -62,28 +57,24 @@ source "/path/to/fzf.kak/rc/modules/VCS/fzf-hg.kak" # Mercurial VCS source "/path/to/fzf.kak/rc/modules/VCS/fzf-svn.kak" # Subversion module ``` -Order of sourcing files should not matter, but it is preferable to source main -script first, and then the modules. This may look complex, but it makes plugin -more versatile. And plugin managers, like [plug.kak][11] for example, just does -all those steps for you. +Order of sourcing files should not matter, but it is preferable to source main script first, and then the modules. +This may look complex, but it makes plugin more versatile. +And plugin managers, like [plug.kak][11] for example, just does all those steps for you. -By the way, this structure makes it easy to extend plugin with new modules, and -you [can add modules on your own][20]! +By the way, this structure makes it easy to extend plugin with new modules, and you [can add modules on your own][20]! ## Usage -There's no default key binding to invoke `fzf`, but **fzf.kak** provides a -`fzf-mode` command that can be mapped to preferred key. You can set your own -mapping to invoke `fzf-mode`: +There's no default key binding to invoke `fzf`, but **fzf.kak** provides a `fzf-mode` command that can be mapped to preferred key. +You can set your own mapping to invoke `fzf-mode`: ```kak map global normal ': fzf-mode' ``` -Note that space between colon and command is intentional and will strip this -command from command history. +Note that space between colon and command is intentional and will strip this command from command history. -Each `fzf` module defines mnemonic mapping, like f for opening files, -t for tags, s for search, and so on. Available mappings: +Each `fzf` module defines mnemonic mapping, like f for opening files, t for tags, s for search, and so on. +Available mappings: - b - Select buffer. - c - Switch server's working directory. @@ -97,96 +88,76 @@ Each `fzf` module defines mnemonic mapping, like f for opening files, - p - Project selector. - Alt+p - Project related commands. -So for example pressing Ctrl+p f will open -`fzf` window, showing you all files from current directory recursively. +So for example pressing Ctrl+p f will open `fzf` window, showing you all files from current directory recursively. -When Kakoune is being run in Tmux, **fzf.kak** will use bottom split to display -`fzf`. Additional keybindings are available to open file in vertical or -horizontal split. When Kakoune is used in plain terminal, the `terminal` command -is being used to create new windows. +When Kakoune is being run in Tmux, **fzf.kak** will use bottom split to display `fzf`. +Additional keybindings are available to open file in vertical or horizontal split. +When Kakoune is used in plain terminal, the `terminal` command is being used to create new windows. ## Configuration -**fzf.kak** features a lot of settings via options that can be altered to change -how **fzf.kak** behaves. All settings belong to `fzf` module, so in order to -change variable values use `defer "fzf %{ ... }"` if you're using **plug.kak**, -and if not, use `hook global ModuleLoaded fzf %{ ... }`, or simply `require-module -fzf` before configuring options. Same goes for `fzf_vcs` module. +**fzf.kak** features a lot of settings via options that can be altered to change how **fzf.kak** behaves. +All settings belong to `fzf` module, so in order to change variable values use `defer "fzf %{ ... }"` if you're using **plug.kak**, and if not, use `hook global ModuleLoaded fzf %{ ... }`, or simply `require-module fzf` before configuring options. +Same goes for `fzf_vcs` module. -From now on I assume that you're using one of the methods listed above for all -configurations below. +From now on I assume that you're using one of the methods listed above for all configurations below. ### Default query -**fzf.kak** by default will use main selection as default query for fzf, if the -selection more than 1 character long (because cursor is simply 1-char -selection). You can disable this behavior by setting `fzf_use_main_selection` to -`false`. +**fzf.kak** by default will use main selection as default query for fzf, if the selection more than 1 character long (because cursor is simply 1-char selection). +You can disable this behavior by setting `fzf_use_main_selection` to `false`. ### Windowing -If you're using Tmux, you do not have to worry about windowing, since fzf.kak -automatically creates all needed Tmux splits and panes for you. However in case -you're not using Tmux, fzf.kak uses `fzf_terminal_command` option to call windowing -command to create new windows. By default it is set to use `terminal` alias: -`terminal kak -c %val{session} -e "%arg{@}"`, but some terminals can provide -other aliases or commands, like `terminal-tab` in Kitty. You may want to edit -this variable accordingly to your personal preferences. +If you're using Tmux, you do not have to worry about windowing, since fzf.kak automatically creates all needed Tmux splits and panes for you. +However in case you're not using Tmux, fzf.kak uses `fzf_terminal_command` option to call windowing command to create new windows. +By default it is set to use `terminal` alias: `terminal kak -c %val{session} -e "%arg{@}"`, but some terminals can provide other aliases or commands, like `terminal-tab` in Kitty. +You may want to edit this variable accordingly to your personal preferences. ### 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_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. +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], -[fd][15]. GNU find is used by default, but you can switch to another one. There -are some default values for those, so you can just state the name of the tool: +Supported tools are [GNU Find][12], [The Silver Searcher][13], [ripgrep][14], [fd][15]. +GNU find is used by default, but you can switch to another one. +There are some default values for those, so you can just state the name of the tool: ```kak set-option global fzf_file_command 'rg' # 'ag', 'fd', or 'find' ``` -Or if you don't like default arguments, which for `find` are `find -type f`, and -would like to disable searching in, say `.svn` and `.git` directories you can -set option like this: +Or if you don't like default arguments, which for `find` are `find -type f`, and would like to disable searching in, say `.svn` and `.git` directories you can set option like this: ```kak set-option global fzf_file_command "find . \( -path '*/.svn*' -o -path '*/.git*' \) -prune -o -type f -print" ``` -This can give you the idea of how this plugin can be customized. Most of -**fzf.kak** modules provide settings for their commands, so you should check all -`fzf-optionname` available in prompt mode. All such options are well documented, -so listing those in readme would make it unnecessary long. +This can give you the idea of how this plugin can be customized. +Most of **fzf.kak** modules provide settings for their commands, so you should check all `fzf-optionname` available in prompt mode. +All such options are well documented, so listing those in readme would make it unnecessary long. ### Preview -**fzf.kak** tries to automatically detect where to show preview window, -depending on aspect ratio of new terminal window. By default if the doubled -height is bigger than the width, preview occupies upper 60% of space. If height -is smaller than the width, preview is shown at the right side. +**fzf.kak** tries to automatically detect where to show preview window, depending on aspect ratio of new terminal window. +By default if the doubled height is bigger than the width, preview occupies upper 60% of space. +If height is smaller than the width, preview is shown at the right side. -You can configure the amount of space for preview window with these options: -`fzf_preview_height` and `fzf_preview_width`. +You can configure the amount of space for preview window with these options: `fzf_preview_height` and `fzf_preview_width`. -When using **fzf.kak** inside `tmux`, bottom pane is used for all `fzf` -commands, and preview window is displayed on the right side. When preview is -turned on, height of `tmux` split is increased to provide more space. You can -configure split height with `fzf_preview_tmux_height` +When using **fzf.kak** inside `tmux`, bottom pane is used for all `fzf` commands, and preview window is displayed on the right side. +When preview is turned on, height of `tmux` split is increased to provide more space. +You can configure split height with `fzf_preview_tmux_height` -Amount of lines in preview window can be changed with `fzf_preview_lines` -option. +Amount of lines in preview window can be changed with `fzf_preview_lines` option. -If you don't want preview feature you can disable it by setting `fzf_preview` -option to `false`. +If you don't want preview feature you can disable it by setting `fzf_preview` option to `false`. #### Highlighting preview window -You also can highlight contents of the file displayed within preview window. To -do so, you can specify which highlighter to use with `fzf_highlight_command` option. +You also can highlight contents of the file displayed within preview window. +To do so, you can specify which highlighter to use with `fzf_highlight_command` option. Supported highlighters are: * [Bat][16] @@ -194,93 +165,78 @@ Supported highlighters are: * [Highlight][18] * [Rouge][19] -Although other tools are not supported by the script, then should work fine as -long as they work with `fzf`. +Although other tools are not supported by the script, then should work fine as long as they work with `fzf`. ### VCS -This script supports these version control systems: Git, Subversion, GNU Bazaar, -and Mercurial. By default v mapping from `fzf` mode will detect your -version control system and open `fzf` window for you. If you wish to explicitly -use some particular VCS command, you can use Alt+v -mapping, which includes all supported VCS shortcuts. +This script supports these version control systems: Git, Subversion, GNU Bazaar, and Mercurial. +By default v mapping from `fzf` mode will detect your version control system and open `fzf` window for you. +If you wish to explicitly use some particular VCS command, you can use Alt+v mapping, which includes all supported VCS shortcuts. -You also able to set parameters to VCS command to use to provide project -files. Supported options: +You also able to set parameters to VCS command to use to provide project files. +Supported options: * `fzf_git_command` * `fzf_svn_command` * `fzf_bzr_command` * `fzf_hg_command` -Other VCS are not supported officially. Open a feature request if you want some -unsupported VCS to be included. You also can change one of options to contain -your VCS command, and use this command explicitly from VCS sub-mode. +Other VCS are not supported officially. +Open a feature request if you want some unsupported VCS to be included. +You also can change one of options to contain your VCS command, and use this command explicitly from VCS sub-mode. ### Tmux -When using inside tmux, `fzf` will use bottom split. Height of this split can be -changed with `fzf_tmux_height` option. `fzf_tmux_height_file_preview` option is -used to control height of the split when you do file searching with file-preview -turned on. +When using inside Tmux, `fzf` will use bottom split. +Height of this split can be changed with `fzf_tmux_height` option. +`fzf_tmux_height_file_preview` option is used to control height of the split when you do file searching with file-preview turned on. ### Projects -**fzf.kak** can store and load your projects. For that It creates a hidden file -in your `%val{config}` called `.fzf-projects`. You can change the location of -this file and its name with `fzf_project_file` option. You also can choose which -method to use when storing projects. You can either convert your `$HOME` to `~/` -or use plain `$HOME` in your path. This behavior is configured with -`fzf_project_use_tilda` option, which accepts `true` and `false` values. +**fzf.kak** can store and load your projects. +For that It creates a hidden file in your `%val{config}` called `.fzf-projects`. +You can change the location of this file and its name with `fzf_project_file` option. +You also can choose which method to use when storing projects. +You can either convert your `$HOME` to `~/` or use plain `$HOME` in your path. +This behavior is configured with `fzf_project_use_tilda` option, which accepts `true` and `false` values. ## `fzf` command -`fzf` command can be used from prompt mode and for [scripting][20]. It supports -these arguments: +`fzf` command can be used from prompt mode and for [scripting][20]. +It supports these arguments: -- `-kak-cmd`: A Kakoune command that is applied to `fzf` resulting value, e.g. - `edit -existing`, `change-directory`, e.t.c. -- `-multiple-cmd`: A Kakoune command that is applied when multiple items - selected to every item but the first one. -- `-items-cmd`: A command that is used as a pipe to provide list of values to - `fzf`. For example, if we want to pass list of all files recursively in - current directory, we would use `-items-cmd %{find .}` which will be piped to - `fzf` tool. -- `-fzf-impl`: Override `fzf` implementation variable. Can be used if command - needs to provide a different arguments to `fzf`. See [sk-grep.kak][21] as - example. +- `-kak-cmd`: A Kakoune command that is applied to `fzf` resulting value, e.g. `edit -existing`, `change-directory`, e.t.c. +- `-multiple-cmd`: A Kakoune command that is applied when multiple items selected to every item but the first one. +- `-items-cmd`: A command that is used as a pipe to provide list of values to `fzf`. + For example, if we want to pass list of all files recursively in current directory, we would use `-items-cmd %{find .}` which will be piped to `fzf` tool. +- `-fzf-impl`: Override `fzf` implementation variable. + Can be used if command needs to provide a different arguments to `fzf`. + See [sk-grep.kak][21] as example. - `-fzf-args`: Additional flags for `fzf` program. -- `-preview-cmd`: A preview command. Can be used to override default preview - handling. +- `-preview-cmd`: A preview command. + Can be used to override default preview handling. - `-preview`: If specified, command will ask for preview. -- `-filter`: A pipe which will be applied to result provided by `fzf`. For - example, if we are returning such line `3 hello, world!` from `fzf`, and we - are interested only in the first field which is `3`, we can use `-filter %{cut - -f 1}`. Basically everything what `fzf` returns is piped to this filter - command. See [fzf-search.kak][22] as example. +- `-filter`: A pipe which will be applied to result provided by `fzf`. + For example, if we are returning such line `3 hello, world!` from `fzf`, and we are interested only in the first field which is `3`, we can use `-filter %{cut -f 1}`. + Basically everything what `fzf` returns is piped to this filter command. + See [fzf-search.kak][22] as example. - `-post-action`: Extra commands that are preformed after `-kak-cmd` command. ## Contributing -If you want to contribute to **fzf.kak** by adding a module, you can submit one -by providing a pull request, or just open a feature request and we'll see what -can be done. +If you want to contribute to **fzf.kak** by adding a module, you can submit one by providing a pull request, or just open a feature request and we'll see what can be done. ### Writing a module -You can write a module for **fzf.kak**. To create one, simply define a function -in separate file, located in `rc/modules/`, and named after the -function. **fzf.kak** provides a general purpose command, that can be called -with some Kakoune command as first parameter, and command that provides list of -items for `fzf` as a second parameter. Third optional parameter is for defining -extra arguments for `fzf` itself, like additional keybindings. +You can write a module for **fzf.kak**. +To create one, simply define a function in separate file, located in `rc/modules/`, and named after the function. +**fzf.kak** provides a general purpose command, that can be called with some Kakoune command as first parameter, and command that provides list of items for `fzf` as a second parameter. +Third optional parameter is for defining extra arguments for `fzf` itself, like additional keybindings. Overall module structure is: * Define a `fzf-command` command * Prepare list of items for `fzf`, or define an item command * call `fzf` command and pass needed arguments to it. -Of course modules can and will be more complex, since a good module checks if -command for providing item list is available on user's machine, and supports -various settings inside it. Feel free to look how existing modules are made. +Of course modules can and will be more complex, since a good module checks if command for providing item list is available on user's machine, and supports various settings inside it. +Feel free to look how existing modules are made. ### External modules -Support for [yank-ring.kak][25] was externalized to separate plugin -[fzf-yank-ring.kak][24] +Support for [yank-ring.kak][25] was externalized to separate plugin [fzf-yank-ring.kak][24] [1]: https://img.shields.io/github/release/andreyorst/fzf.kak.svg [2]: https://github.com/andreyorst/fzf.kak/releases @@ -307,3 +263,7 @@ Support for [yank-ring.kak][25] was externalized to separate plugin [23]: #configuration [24]: https://gitlab.com/losnappas/fzf-yank-ring.kak [25]: https://github.com/alexherbo2/yank-ring.kak + + From 9ee5e4fea86b6234cbede057a04e1de09d6a2fe8 Mon Sep 17 00:00:00 2001 From: Andrey Listopadov Date: Fri, 19 Mar 2021 22:38:01 +0300 Subject: [PATCH 3/7] rewrite readme a bit --- README.md | 220 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 113 insertions(+), 107 deletions(-) diff --git a/README.md b/README.md index 078b1db..d7d9849 100644 --- a/README.md +++ b/README.md @@ -3,78 +3,57 @@ [![GitHub release][1]][2] [![GitHub Release Date][3]][4] ![Github commits (since latest release)][5] ![license][6] -**fzf.kak** is a plugin for [Kakoune][7] editor, that brings integration with [fzf][8] tool. -This plugin is being tested against Kakoune master branch. -**fzf.kak** also supports [skim][9], which can be used via `fzf_implementation` option. +**fzf.kak** is a plugin for [Kakoune][7] editor, that provides integration with the [fzf][8] tool. +There's also a limited support for [skim][9], which can be enabled by changing `fzf_implementation` option. ![showcase][10] -## Installation -### With [plug.kak][11] (recommended) -Recommended way to install is to use plug.kak plugin manager. -You can install **fzf.kak** by adding this to your `kakrc`: -```kak +## Installation + + +### With [plug.kak][11] + +The recommended way to install **fzf.kak** is to use plug.kak plugin manager. +To install **fzf.kak** add this to the `kakrc`: + +``` kak plug "andreyorst/fzf.kak" ``` -Then reload Kakoune config or restart Kakoune and run `:plug-install`. -Now you can proceed to the [configuration][23] section. +Then reload the configuration file or restart Kakoune and run `:plug-install`. + ### Without plugin manager -This plugin consists of several parts which are "modules", that provide different functions to plugin. -There's central module that must be loaded before any other module, named `fzf.kak`, so in order to properly load **fzf.kak** plugin, you need to source it in your `kakrc`. -```sh +This plugin consists of several parts which are referred here as "modules". +So, for plugin to work the base module must be loaded: + +``` sh source "/path/to/fzf.kak/rc/fzf.kak" # loading base fzf module ``` -This will load base `fzf` module, but It can't do anything on it's own. -You can load only needed modules, to keep your configuration rather simple, or load every module if you need all plugin abilities: +This module doesn't do anything on it's own. +Each module in the `modules` directory provides features that extend base `fzf` module with new commands and mappings. +Those can be loaded manually one by one the same way as the base module, or with the use of the `find` command: -```sh -source "/path/to/fzf.kak/rc/modules/fzf-file.kak" # fzf file chooser -source "/path/to/fzf.kak/rc/modules/fzf-buffer.kak" # switching buffers with fzf -source "/path/to/fzf.kak/rc/modules/fzf-search.kak" # search within file contents -source "/path/to/fzf.kak/rc/modules/fzf-cd.kak" # change server's working directory -source "/path/to/fzf.kak/rc/modules/fzf-ctags.kak" # search for tag in your project ctags file +``` sh +evaluate-commands %sh{ + find -L "path/to/fzf.kak/modules/" -type f -name '*.kak' -exec printf 'source "%s"\n' {} \; +} ``` -The same principle is applied to handling different version control systems. -You need a base module for `fzf`, called `fzf-vcs.kak` and its sub-modules for each VCS. -There are plenty of version control systems, so modules come in handy. - -```sh -source "/path/to/fzf.kak/rc/modules/fzf-vcs.kak" # VCS base module -``` - -So if you never work with, say, GNU Bazaar, or Mercurial you can remove them from your configuration. - -```sh -source "/path/to/fzf.kak/rc/modules/VCS/fzf-bzr.kak" # GNU Bazaar support -source "/path/to/fzf.kak/rc/modules/VCS/fzf-git.kak" # Git support module -source "/path/to/fzf.kak/rc/modules/VCS/fzf-hg.kak" # Mercurial VCS -source "/path/to/fzf.kak/rc/modules/VCS/fzf-svn.kak" # Subversion module -``` - -Order of sourcing files should not matter, but it is preferable to source main script first, and then the modules. -This may look complex, but it makes plugin more versatile. -And plugin managers, like [plug.kak][11] for example, just does all those steps for you. - -By the way, this structure makes it easy to extend plugin with new modules, and you [can add modules on your own][20]! ## Usage -There's no default key binding to invoke `fzf`, but **fzf.kak** provides a `fzf-mode` command that can be mapped to preferred key. -You can set your own mapping to invoke `fzf-mode`: + +**fzf.kak** provides a `fzf-mode` command that can be mapped to preferred key: ```kak map global normal ': fzf-mode' ``` -Note that space between colon and command is intentional and will strip this command from command history. - -Each `fzf` module defines mnemonic mapping, like f for opening files, t for tags, s for search, and so on. -Available mappings: +This will invoke the user mode, which contains mnemonic keybindings for each sub-module. +If all modules were loaded, the following mappings are available: - b - Select buffer. - c - Switch server's working directory. @@ -88,31 +67,40 @@ Available mappings: - p - Project selector. - Alt+p - Project related commands. -So for example pressing Ctrl+p f will open `fzf` window, showing you all files from current directory recursively. +When Kakoune runs inside Tmux, **fzf.kak** will use bottom split to display `fzf` window. +Additional keybindings are also made available to open file in vertical or horizontal split. +Otherwise, the `terminal` command is being used to create new windows. -When Kakoune is being run in Tmux, **fzf.kak** will use bottom split to display `fzf`. -Additional keybindings are available to open file in vertical or horizontal split. -When Kakoune is used in plain terminal, the `terminal` command is being used to create new windows. ## Configuration -**fzf.kak** features a lot of settings via options that can be altered to change how **fzf.kak** behaves. -All settings belong to `fzf` module, so in order to change variable values use `defer "fzf %{ ... }"` if you're using **plug.kak**, and if not, use `hook global ModuleLoaded fzf %{ ... }`, or simply `require-module fzf` before configuring options. -Same goes for `fzf_vcs` module. -From now on I assume that you're using one of the methods listed above for all configurations below. +**fzf.kak** features a lot of settings via options that can be altered to change how **fzf.kak** behaves. +Each `.kak` file provides a Kakoune module, so any settings which alter variable values should be wrapped in `ModuleLoaded` hook. +See [plug.kak manual section for `defer`](https://github.com/andreyorst/plug.kak/tree/master#deferring-plugin-configuration) that explains how to do this when using plug.kak. + ### Default query -**fzf.kak** by default will use main selection as default query for fzf, if the selection more than 1 character long (because cursor is simply 1-char selection). -You can disable this behavior by setting `fzf_use_main_selection` to `false`. + +| module | `fzf` | + +By default main selection is used as the default query for `fzf`, but only if the selection more than 1 character long. +This can be disabled by setting `fzf_use_main_selection` to `false`. + ### Windowing -If you're using Tmux, you do not have to worry about windowing, since fzf.kak automatically creates all needed Tmux splits and panes for you. -However in case you're not using Tmux, fzf.kak uses `fzf_terminal_command` option to call windowing command to create new windows. + +| module | `fzf` | + +When using Tmux fzf.kak automatically creates all needed Tmux splits and panes for you. +In other cases **fzf.kak** uses `fzf_terminal_command` option to call windowing command to create new windows. By default it is set to use `terminal` alias: `terminal kak -c %val{session} -e "%arg{@}"`, but some terminals can provide other aliases or commands, like `terminal-tab` in Kitty. -You may want to edit this variable accordingly to your personal preferences. + ### Mappings -You can define what keys to use in `fzf` window via these options: + +| module | `fzf` | + +Keys that are used in the `fzf` window can be configured with 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), @@ -120,45 +108,52 @@ You can define what keys to use in `fzf` window via these options: 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. + +| module | `fzf-file` | + +A command that is used to search for files and it's arguments can be configured by changing the value of `fzf_file_command` variable, that is available in the `fzf-file` module. + Supported tools are [GNU Find][12], [The Silver Searcher][13], [ripgrep][14], [fd][15]. -GNU find is used by default, but you can switch to another one. -There are some default values for those, so you can just state the name of the tool: +Default set of arguments is provided for each of these searchers, only the name of the tool can be assigned to the `fzf_file_command` variable: ```kak set-option global fzf_file_command 'rg' # 'ag', 'fd', or 'find' ``` -Or if you don't like default arguments, which for `find` are `find -type f`, and would like to disable searching in, say `.svn` and `.git` directories you can set option like this: +Default arguments can be changing by setting the complete command to execute: ```kak set-option global fzf_file_command "find . \( -path '*/.svn*' -o -path '*/.git*' \) -prune -o -type f -print" ``` -This can give you the idea of how this plugin can be customized. -Most of **fzf.kak** modules provide settings for their commands, so you should check all `fzf-optionname` available in prompt mode. -All such options are well documented, so listing those in readme would make it unnecessary long. ### Preview -**fzf.kak** tries to automatically detect where to show preview window, depending on aspect ratio of new terminal window. + +| module | `fzf-file` | + +**fzf.kak** tries to automatically detect where to show preview window, depending on aspect ratio of the new terminal window. By default if the doubled height is bigger than the width, preview occupies upper 60% of space. If height is smaller than the width, preview is shown at the right side. - -You can configure the amount of space for preview window with these options: `fzf_preview_height` and `fzf_preview_width`. +These amounts can be configured with `fzf_preview_height` and `fzf_preview_width` options. When using **fzf.kak** inside `tmux`, bottom pane is used for all `fzf` commands, and preview window is displayed on the right side. When preview is turned on, height of `tmux` split is increased to provide more space. -You can configure split height with `fzf_preview_tmux_height` +Split height can be configured with the `fzf_preview_tmux_height` variable. Amount of lines in preview window can be changed with `fzf_preview_lines` option. -If you don't want preview feature you can disable it by setting `fzf_preview` option to `false`. +Preview feature can be disabled entirely by setting `fzf_preview` option to `false`. + #### Highlighting preview window -You also can highlight contents of the file displayed within preview window. -To do so, you can specify which highlighter to use with `fzf_highlight_command` option. -Supported highlighters are: + +| module | `fzf-file` | + +Contents of the file displayed within preview window can be syntax highlighted. +This can be enabled by specifying highlighter to use with the `fzf_highlight_command` option. +These highlighters are are supported out of the box: * [Bat][16] * [Coderay][17] @@ -167,13 +162,16 @@ Supported highlighters are: Although other tools are not supported by the script, then should work fine as long as they work with `fzf`. -### VCS -This script supports these version control systems: Git, Subversion, GNU Bazaar, and Mercurial. -By default v mapping from `fzf` mode will detect your version control system and open `fzf` window for you. -If you wish to explicitly use some particular VCS command, you can use Alt+v mapping, which includes all supported VCS shortcuts. -You also able to set parameters to VCS command to use to provide project files. -Supported options: +### VCS + +| module | `fzf-vcs` | + +This script supports these version control systems: Git, Subversion, GNU Bazaar, and Mercurial. +By default v mapping from `fzf` mode will detect your version control system automatically. +To explicitly use some particular VCS command, the Alt+v mapping can be used, which includes all supported VCS shortcuts. + +To set parameters to VCS command used to provide project files the following options can be used: * `fzf_git_command` * `fzf_svn_command` @@ -181,25 +179,34 @@ Supported options: * `fzf_hg_command` Other VCS are not supported officially. -Open a feature request if you want some unsupported VCS to be included. -You also can change one of options to contain your VCS command, and use this command explicitly from VCS sub-mode. +Feature requests and merge requests are welcome. + ### Tmux -When using inside Tmux, `fzf` will use bottom split. -Height of this split can be changed with `fzf_tmux_height` option. -`fzf_tmux_height_file_preview` option is used to control height of the split when you do file searching with file-preview turned on. + +| module | `fzf` | + +When running inside Tmux, `fzf` will use bottom split. +Height of this split can be changed with the `fzf_tmux_height` option. +`fzf_tmux_height_file_preview` option is used to control height of the split when file-preview is turned on. + ### Projects -**fzf.kak** can store and load your projects. -For that It creates a hidden file in your `%val{config}` called `.fzf-projects`. -You can change the location of this file and its name with `fzf_project_file` option. -You also can choose which method to use when storing projects. -You can either convert your `$HOME` to `~/` or use plain `$HOME` in your path. -This behavior is configured with `fzf_project_use_tilda` option, which accepts `true` and `false` values. + +| module | `fzf-project` | + +**fzf.kak** has basic project manipulation capabilities. + +To store projects a hidden file is created in `%val{config}` and called `.fzf-projects`. +The location of this file and its name can be changed by modifying the `fzf_project_file` option. +By default project paths which start from home directory will use `~` instead of read path. +To change this, set `fzf_project_use_tilda` option to `false`. + ## `fzf` command + `fzf` command can be used from prompt mode and for [scripting][20]. -It supports these arguments: +The following arguments are supported: - `-kak-cmd`: A Kakoune command that is applied to `fzf` resulting value, e.g. `edit -existing`, `change-directory`, e.t.c. - `-multiple-cmd`: A Kakoune command that is applied when multiple items selected to every item but the first one. @@ -218,24 +225,23 @@ It supports these arguments: See [fzf-search.kak][22] as example. - `-post-action`: Extra commands that are preformed after `-kak-cmd` command. + ## Contributing + +Please do. If you want to contribute to **fzf.kak** by adding a module, you can submit one by providing a pull request, or just open a feature request and we'll see what can be done. -### Writing a module -You can write a module for **fzf.kak**. -To create one, simply define a function in separate file, located in `rc/modules/`, and named after the function. -**fzf.kak** provides a general purpose command, that can be called with some Kakoune command as first parameter, and command that provides list of items for `fzf` as a second parameter. -Third optional parameter is for defining extra arguments for `fzf` itself, like additional keybindings. +The basic idea behind the module structure can be described as: -Overall module structure is: -* Define a `fzf-command` command -* Prepare list of items for `fzf`, or define an item command -* call `fzf` command and pass needed arguments to it. +1. Provide a user module; +2. Define a command that calls `fzf` function with appropriate arguments; +3. Create a mapping in a `ModuleLoaded` hook, that requires new module, and calls the command. + +See how existing modules are implemented to understand the idea of how modules are constructed. -Of course modules can and will be more complex, since a good module checks if command for providing item list is available on user's machine, and supports various settings inside it. -Feel free to look how existing modules are made. ### External modules + Support for [yank-ring.kak][25] was externalized to separate plugin [fzf-yank-ring.kak][24] [1]: https://img.shields.io/github/release/andreyorst/fzf.kak.svg From d912a6ecf139eae70fc5011ed7dee5a546d9db66 Mon Sep 17 00:00:00 2001 From: Andrey Listopadov Date: Fri, 19 Mar 2021 22:48:55 +0300 Subject: [PATCH 4/7] markdown doesn't like one-line tables --- README.md | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index d7d9849..25a6bff 100644 --- a/README.md +++ b/README.md @@ -81,7 +81,9 @@ See [plug.kak manual section for `defer`](https://github.com/andreyorst/plug.kak ### Default query -| module | `fzf` | +| module | +|--------| +| `fzf` | By default main selection is used as the default query for `fzf`, but only if the selection more than 1 character long. This can be disabled by setting `fzf_use_main_selection` to `false`. @@ -89,7 +91,9 @@ This can be disabled by setting `fzf_use_main_selection` to `false`. ### Windowing -| module | `fzf` | +| module | +|--------| +| `fzf` | When using Tmux fzf.kak automatically creates all needed Tmux splits and panes for you. In other cases **fzf.kak** uses `fzf_terminal_command` option to call windowing command to create new windows. @@ -98,7 +102,9 @@ By default it is set to use `terminal` alias: `terminal kak -c %val{session} -e ### Mappings -| module | `fzf` | +| module | +|--------| +| `fzf` | Keys that are used in the `fzf` window can be configured with these options: @@ -111,7 +117,9 @@ These options should be set to work with fzf `--expect` parameter, so check out ### File command -| module | `fzf-file` | +| module | +|------------| +| `fzf-file` | A command that is used to search for files and it's arguments can be configured by changing the value of `fzf_file_command` variable, that is available in the `fzf-file` module. @@ -131,7 +139,9 @@ set-option global fzf_file_command "find . \( -path '*/.svn*' -o -path '*/.git*' ### Preview -| module | `fzf-file` | +| module | +|------------| +| `fzf-file` | **fzf.kak** tries to automatically detect where to show preview window, depending on aspect ratio of the new terminal window. By default if the doubled height is bigger than the width, preview occupies upper 60% of space. @@ -149,7 +159,9 @@ Preview feature can be disabled entirely by setting `fzf_preview` option to `fal #### Highlighting preview window -| module | `fzf-file` | +| module | +|------------| +| `fzf-file` | Contents of the file displayed within preview window can be syntax highlighted. This can be enabled by specifying highlighter to use with the `fzf_highlight_command` option. @@ -165,7 +177,9 @@ Although other tools are not supported by the script, then should work fine as l ### VCS -| module | `fzf-vcs` | +| module | +|-----------| +| `fzf-vcs` | This script supports these version control systems: Git, Subversion, GNU Bazaar, and Mercurial. By default v mapping from `fzf` mode will detect your version control system automatically. @@ -184,7 +198,9 @@ Feature requests and merge requests are welcome. ### Tmux -| module | `fzf` | +| module | +|--------| +| `fzf` | When running inside Tmux, `fzf` will use bottom split. Height of this split can be changed with the `fzf_tmux_height` option. @@ -193,7 +209,9 @@ Height of this split can be changed with the `fzf_tmux_height` option. ### Projects -| module | `fzf-project` | +| module | +|---------------| +| `fzf-project` | **fzf.kak** has basic project manipulation capabilities. From a8765bb03d4993c6f64b16d0d34edb5f16473bd5 Mon Sep 17 00:00:00 2001 From: Andrey Listopadov Date: Sat, 20 Mar 2021 22:44:19 +0300 Subject: [PATCH 5/7] fix some shellcheck warnings --- rc/fzf.kak | 64 +++++++++++++++++++------------------- rc/modules/VCS/fzf-bzr.kak | 2 +- rc/modules/fzf-buffer.kak | 16 +++++----- rc/modules/fzf-cd.kak | 7 ++--- rc/modules/fzf-ctags.kak | 18 +++++------ rc/modules/fzf-file.kak | 14 ++++----- rc/modules/fzf-grep.kak | 12 +++---- rc/modules/fzf-project.kak | 28 ++++++++--------- rc/modules/fzf-search.kak | 2 +- rc/modules/fzf-vcs.kak | 10 +++--- rc/modules/sk-grep.kak | 12 +++---- 11 files changed, 92 insertions(+), 93 deletions(-) diff --git a/rc/fzf.kak b/rc/fzf.kak index 7c2811a..7f12c55 100644 --- a/rc/fzf.kak +++ b/rc/fzf.kak @@ -104,10 +104,10 @@ fzf-horizontal -params .. %{ evaluate-commands %{ define-command -hidden -docstring "wrapper command to create new terminal" \ 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{@}"' else - printf "%s\n" "$kak_opt_fzf_terminal_command" + printf "%s\n" "${kak_opt_fzf_terminal_command:?}" fi }} @@ -136,12 +136,12 @@ Switches: -post-action" } \ fzf -params .. %{ evaluate-commands %sh{ - fzf_impl="${kak_opt_fzf_implementation}" + fzf_impl="${kak_opt_fzf_implementation:?}" - [ "${kak_opt_fzf_use_main_selection}" = "true" ] && \ - [ $(printf "%s" "${kak_selection}" | wc -m) -gt 1 ] && \ - [ $(printf "%s" "${kak_selection}" | wc -l) -eq 1 ] && \ - default_query="-i -q ${kak_selection}" + [ "${kak_opt_fzf_use_main_selection:-}" = "true" ] && \ + [ "$(printf "%s" "${kak_selection:-}" | wc -m)" -gt 1 ] && \ + [ "$(printf "%s" "${kak_selection:-}" | wc -l)" -eq 1 ] && \ + default_query="-i -q ${kak_selection:-}" while [ $# -gt 0 ]; do case $1 in @@ -162,29 +162,29 @@ fzf -params .. %{ evaluate-commands %sh{ if [ "${preview}" = "true" ]; then # bake position option to define them at runtime - [ -n "${kak_client_env_TMUX}" ] && tmux_height="${kak_opt_fzf_preview_tmux_height}" - case ${kak_opt_fzf_preview_pos} in - (top|up) preview_position="pos=top:${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};" ;; - (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};" + [ -n "${kak_client_env_TMUX:-}" ] && tmux_height="${kak_opt_fzf_preview_tmux_height:-}" + case ${kak_opt_fzf_preview_pos:-} in + (top|up) preview_position="pos=top:${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:-};" ;; + (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:-};" esac # handle preview if not defined explicitly with `-preview-cmd' - if [ ${kak_opt_fzf_preview} = "true" ] && [ -z "${preview_cmd}" ]; then - case ${kak_opt_fzf_highlight_command} in + if [ "${kak_opt_fzf_preview:-}" = "true" ] && [ -z "${preview_cmd}" ]; then + case ${kak_opt_fzf_highlight_command:-} in (bat) highlight_cmd="bat --color=always --style=plain {}" ;; (coderay) highlight_cmd="coderay {}" ;; (highlight) highlight_cmd="highlight --failsafe -O ansi {}" ;; (rouge) highlight_cmd="rougify {}" ;; (*) highlight_cmd="${kak_opt_fzf_highlight_command}" ;; 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 - fzf_tmp=$(mktemp -d ${TMPDIR:-/tmp}/fzf.kak.XXXXXX) + fzf_tmp=$(mktemp -d "${TMPDIR:-/tmp}"/fzf.kak.XXXXXX) fzfcmd="${fzf_tmp}/fzfcmd" result="${fzf_tmp}/result" @@ -197,19 +197,19 @@ fzf -params .. %{ evaluate-commands %sh{ printf "%s\n" "SHELL=${shell_path}" fi # 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" "rm ${fzfcmd}" - ) >> ${fzfcmd} - chmod 755 ${fzfcmd} + ) >> "${fzfcmd}" + chmod 755 "${fzfcmd}" if [ -n "${kak_client_env_TMUX}" ]; then # 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 [ -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 - 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 cmd="${kak_opt_fzf_terminal_command%% *} %{${fzfcmd}}" fi @@ -217,20 +217,20 @@ fzf -params .. %{ evaluate-commands %sh{ printf "%s\n" "${cmd}" # main loop - ( while [ -e ${fzfcmd} ]; do sleep 0.1; done - if [ -s ${result} ]; then + ( while [ -e "${fzfcmd}" ]; do sleep 0.1; done + if [ -s "${result}" ]; then ( while read -r line; do case ${line} in - (${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} ;; + ("${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 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 fi done @@ -243,9 +243,9 @@ fzf -params .. %{ evaluate-commands %sh{ post_action=$(printf "%s\n" "${post_action}" | sed "s/&/&&/g") printf "%s\n" "evaluate-commands -client ${kak_client} %&${post_action}&" fi - ) < ${result} | kak -p ${kak_session} + ) < "${result}" | kak -p "${kak_session:?}" fi - rm -rf ${fzf_tmp} + rm -rf "${fzf_tmp}" ) > /dev/null 2>&1 < /dev/null & }} diff --git a/rc/modules/VCS/fzf-bzr.kak b/rc/modules/VCS/fzf-bzr.kak index cdd10f8..a25c8fa 100644 --- a/rc/modules/VCS/fzf-bzr.kak +++ b/rc/modules/VCS/fzf-bzr.kak @@ -24,7 +24,7 @@ define-command -hidden fzf-bzr %{ evaluate-commands %sh{ (bzr) cmd="(cd $repo_root && bzr ls -R --versioned)" ;; (*) cmd=$kak_opt_fzf_bzr_command ;; 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/\\\"}\"}" }} diff --git a/rc/modules/fzf-buffer.kak b/rc/modules/fzf-buffer.kak index 7de2205..b318c01 100644 --- a/rc/modules/fzf-buffer.kak +++ b/rc/modules/fzf-buffer.kak @@ -11,7 +11,7 @@ provide-module fzf-buffer %§ define-command -hidden fzf-buffer %{ evaluate-commands %sh{ buffers="" - eval "set -- $kak_quoted_buflist" + eval "set -- ${kak_quoted_buflist:?}" while [ $# -gt 0 ]; do buffers="$1 $buffers" @@ -20,19 +20,19 @@ $buffers" message="Set buffer to edit in current client. : switch to selected buffer. -$kak_opt_fzf_window_map: open buffer in new window" - [ ! -z "${kak_client_env_TMUX}" ] && tmux_keybindings=" -$kak_opt_fzf_horizontal_map: open buffer in horizontal split -$kak_opt_fzf_vertical_map: open buffer in vertical split" +${kak_opt_fzf_window_map:?}: open buffer in new window" + [ -n "${kak_client_env_TMUX:-}" ] && tmux_keybindings=" +${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 $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}" }} define-command -hidden fzf-delete-buffer %{ evaluate-commands %sh{ buffers="" - eval "set -- $kak_quoted_buflist" + eval "set -- ${kak_quoted_buflist:?}" while [ $# -gt 0 ]; do buffers="$1 $buffers" @@ -42,7 +42,7 @@ $buffers" message="Delete buffer. : delete selected buffer." 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:-}}" }} § diff --git a/rc/modules/fzf-cd.kak b/rc/modules/fzf-cd.kak index f4917ec..d5f7145 100644 --- a/rc/modules/fzf-cd.kak +++ b/rc/modules/fzf-cd.kak @@ -30,16 +30,15 @@ declare-option -docstring 'maximum amount of previewed directories' \ int fzf_preview_dirs '300' 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 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)" ;; (*) items_command=$kak_opt_fzf_cd_command ;; esac - if [ "$kak_opt_fzf_cd_preview" = "true" ]; then + if [ "${kak_opt_fzf_cd_preview:-}" = "true" ]; then 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 printf "%s\n" "fzf $preview_flag -kak-cmd %{change-directory} -items-cmd %{$items_command} -preview-cmd %{$preview} -post-action %{fzf-cd}" }} diff --git a/rc/modules/fzf-ctags.kak b/rc/modules/fzf-ctags.kak index 9f4e872..af5f062 100644 --- a/rc/modules/fzf-ctags.kak +++ b/rc/modules/fzf-ctags.kak @@ -23,9 +23,9 @@ try %{ # this huge try block defines filetype aware filter mappings for separate fzf-ctags mode define-command -hidden fzf-setup-filter-tags %{ 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" " map global fzf-ctags '' ': fzf-tag P' -docstring 'package specifications' map global fzf-ctags 'p' ': fzf-tag p' -docstring 'packages' @@ -898,7 +898,7 @@ define-command -hidden fzf-setup-filter-tags %{ define-command -hidden fzf-tag -params ..2 %{ evaluate-commands %sh{ path=$PWD while [ "$path" != "$HOME" ]; do - if [ -e "./$kak_opt_fzf_tag_file_name" ]; then + if [ -e "./${kak_opt_fzf_tag_file_name:-}" ]; then break else cd .. @@ -914,7 +914,7 @@ define-command -hidden fzf-tag -params ..2 %{ evaluate-commands %sh{ fi cmd="cd $path;" - if [ -n "$(command -v ${kak_opt_readtagscmd})" ]; then + if [ -n "$(command -v "${kak_opt_readtagscmd%% *}")" ]; then if [ -n "$1" ]; then cmd="${cmd} ${kak_opt_readtagscmd} -t $kak_opt_fzf_tag_file_name -Q '(eq? \$kind \"$1\")' -l" else @@ -928,15 +928,15 @@ define-command -hidden fzf-tag -params ..2 %{ evaluate-commands %sh{ message="Jump to a symbol''s definition : 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=" -$kak_opt_fzf_horizontal_map: open tag in horizontal split -$kak_opt_fzf_vertical_map: open tag in vertical split" + [ -n "${kak_client_env_TMUX:?}" ] && tmux_keybindings=" +${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 $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" "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 a3ea14d..a1449e9 100644 --- a/rc/modules/fzf-file.kak +++ b/rc/modules/fzf-file.kak @@ -32,7 +32,7 @@ bool fzf_file_preview true 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'''" kak_opt_fzf_file_command="find" fi @@ -50,14 +50,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. -$kak_opt_fzf_window_map: open file in new terminal" - [ ! -z "${kak_client_env_TMUX}" ] && tmux_keybindings=" -$kak_opt_fzf_horizontal_map: open file in horizontal split -$kak_opt_fzf_vertical_map: open file in vertical split" +${kak_opt_fzf_window_map:?}: open file in new terminal" + [ -n "${kak_client_env_TMUX:-}" ] && tmux_keybindings=" +${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 $kak_opt_fzf_vertical_map --expect $kak_opt_fzf_horizontal_map" - [ "$kak_opt_fzf_file_preview" = "true" ] && preview_flag="-preview" + [ -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" printf "%s\n" "fzf $preview_flag -kak-cmd %{edit -existing} -items-cmd %{$cmd} -fzf-args %{-m --expect $kak_opt_fzf_window_map $additional_flags}" }} diff --git a/rc/modules/fzf-grep.kak b/rc/modules/fzf-grep.kak index 936edef..e3a2de2 100644 --- a/rc/modules/fzf-grep.kak +++ b/rc/modules/fzf-grep.kak @@ -17,7 +17,7 @@ str fzf_grep_command 'grep' 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'''" kak_opt_fzf_grep_command="grep" fi @@ -35,13 +35,13 @@ define-command -hidden fzf-grep %{ evaluate-commands %sh{ title="fzf grep" message="grep through contents of all files recursively. : open search result in new buffer. -$kak_opt_fzf_window_map: open search result in new terminal" - [ ! -z "${kak_client_env_TMUX}" ] && tmux_keybindings=" -$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_window_map:?}: open search result in new terminal" + [ -n "${kak_client_env_TMUX:-}" ] && tmux_keybindings=" +${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 $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/'}" }} diff --git a/rc/modules/fzf-project.kak b/rc/modules/fzf-project.kak index 4255eaa..377dea7 100644 --- a/rc/modules/fzf-project.kak +++ b/rc/modules/fzf-project.kak @@ -24,7 +24,7 @@ map global fzf-project -docstring "delete project from project list" 'd' ': map global fzf-project -docstring "rename project" 'r' ': fzf-rename-project' 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" "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 @@ -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{ - if [ -n "${kak_text}" ]; then + if [ -n "${kak_text:-}" ]; then 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 - [ "${kak_opt_fzf_project_use_tilda}" = "false" ] && project_path=$(pwd) || project_path=$(pwd | perl -pe "s(${HOME})(~)") - printf "%s: %s\n" "${kak_text}" "${project_path}" >> ${kak_opt_fzf_project_file} + [ "${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\n" "echo -markup %{{Information}saved '$(pwd)' project as '${kak_text}'}" 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}" @@ -65,11 +65,11 @@ define-command -hidden fzf-save-path-as-project-no-prompt %{ evaluate-commands % esac printf "%s\n" "${base}" } - project_name=$(base ${PWD}) - exists=$(grep "${project_name}: " ${kak_opt_fzf_project_file}) + project_name=$(base "${PWD}") + exists=$(grep "${project_name}: " "${kak_opt_fzf_project_file}") if [ -z "${exists}" ]; then - [ "${kak_opt_fzf_project_use_tilda}" = "false" ] && project_path=$(pwd) || project_path=$(pwd | perl -pe "s(${HOME})(~)") - printf "%s: %s\n" "${project_name}" "${project_path}" >> ${kak_opt_fzf_project_file} + [ "${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\n" "echo -markup %{{Information}saved '$(pwd)' project as '${project_name}'}" 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}" @@ -103,11 +103,11 @@ fzf-add-project -file-completion -params 1..2 %{ evaluate-commands %sh{ mkdir -p "${kak_opt_fzf_project_file%/*}" project_path="$1" project_name="$2" - [ -z "${project_name}" ] && project_name=$(base ${project_path}) - exists=$(grep "${project_name}: " ${kak_opt_fzf_project_file}) + [ -z "${project_name}" ] && project_name=$(base "${project_path}") + exists=$(grep "${project_name}: " "${kak_opt_fzf_project_file}") if [ -z "${exists}" ] || [ "${force}" = "true" ]; then - [ "${kak_opt_fzf_project_use_tilda}" = "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} + [ "${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\n" "echo -markup %{{Information}saved '${project_path}' project as '${project_name}'}" 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}" @@ -119,7 +119,7 @@ define-command -docstring \ -hidden fzf-project-confirm-impl -params 2..4 %{ 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 - 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 printf "%s\n" "${function_to_call}" [ -n "${success_message}" ] && printf "%s\n" "echo -markup %{{Information}${success_message}}" diff --git a/rc/modules/fzf-search.kak b/rc/modules/fzf-search.kak index 5ce23b2..ad52bb7 100644 --- a/rc/modules/fzf-search.kak +++ b/rc/modules/fzf-search.kak @@ -12,7 +12,7 @@ define-command -hidden fzf-buffer-search %{ evaluate-commands %sh{ title="fzf buffer search" message="Search buffer with fzf, and jump to result location" 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 %{%cat>$buffer_content;}" 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}" }} diff --git a/rc/modules/fzf-vcs.kak b/rc/modules/fzf-vcs.kak index 242413f..21a5085 100644 --- a/rc/modules/fzf-vcs.kak +++ b/rc/modules/fzf-vcs.kak @@ -33,17 +33,17 @@ bzr status" IFS=' ' for cmd in $commands; do - eval $cmd >/dev/null 2>&1 + eval "$cmd" >/dev/null 2>&1 res=$? if [ "$res" = "0" ]; then vcs=$(printf "%s\n" "$cmd" | awk '{print $1}') title="fzf $vcs" - [ ! -z "${kak_client_env_TMUX}" ] && additional_keybindings=" -$kak_opt_fzf_horizontal_map: open file in horizontal split -$kak_opt_fzf_vertical_map: open file in vertical split" + [ -n "${kak_client_env_TMUX:-}" ] && additional_keybindings=" +${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. -$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" "fzf-$vcs" exit diff --git a/rc/modules/sk-grep.kak b/rc/modules/sk-grep.kak index 72a4dcd..3e541ab 100644 --- a/rc/modules/sk-grep.kak +++ b/rc/modules/sk-grep.kak @@ -29,14 +29,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. -$kak_opt_fzf_window_map: open search result in new terminal" - [ ! -z "${kak_client_env_TMUX}" ] && tmux_keybindings=" -$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_window_map:?}: open search result in new terminal" + [ -n "${kak_client_env_TMUX:-}" ] && tmux_keybindings=" +${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 $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}}" + [ -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}}" }} define-command -hidden fzf-sk-grep-handler -params 1 %{ From 3f2773c91937cf4753010ffd9f4053ce87daa4e5 Mon Sep 17 00:00:00 2001 From: Andrey Listopadov Date: Sun, 21 Mar 2021 13:33:27 +0300 Subject: [PATCH 6/7] use default mappings when unset --- rc/fzf.kak | 6 +++--- 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 | 12 ++++++------ rc/modules/fzf-ctags.kak | 10 +++++----- rc/modules/fzf-file.kak | 10 +++++----- rc/modules/fzf-grep.kak | 10 +++++----- rc/modules/fzf-vcs.kak | 6 +++--- rc/modules/sk-grep.kak | 10 +++++----- 11 files changed, 40 insertions(+), 40 deletions(-) diff --git a/rc/fzf.kak b/rc/fzf.kak index 7f12c55..21ab66d 100644 --- a/rc/fzf.kak +++ b/rc/fzf.kak @@ -222,9 +222,9 @@ fzf -params .. %{ evaluate-commands %sh{ ( while read -r line; do case ${line} in - ("${kak_opt_fzf_window_map:-}") wincmd="fzf-window" ;; - ("${kak_opt_fzf_vertical_map:-}") wincmd="fzf-vertical" ;; - ("${kak_opt_fzf_horizontal_map:-}") wincmd="fzf-horizontal" ;; + ("${kak_opt_fzf_window_map:-ctrl-w}") wincmd="fzf-window" ;; + ("${kak_opt_fzf_vertical_map:-ctrl-v}") wincmd="fzf-vertical" ;; + ("${kak_opt_fzf_horizontal_map:-ctrl-s}") wincmd="fzf-horizontal" ;; (*) item=${line} ;; esac if [ -n "${item}" ]; then diff --git a/rc/modules/VCS/fzf-bzr.kak b/rc/modules/VCS/fzf-bzr.kak index a25c8fa..c24ed6c 100644 --- a/rc/modules/VCS/fzf-bzr.kak +++ b/rc/modules/VCS/fzf-bzr.kak @@ -24,8 +24,8 @@ define-command -hidden fzf-bzr %{ evaluate-commands %sh{ (bzr) cmd="(cd $repo_root && bzr ls -R --versioned)" ;; (*) cmd=$kak_opt_fzf_bzr_command ;; esac - [ -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/\\\"}\"}" + [ -n "${kak_client_env_TMUX}" ] && additional_flags="--expect ${kak_opt_fzf_vertical_map:-ctrl-v} --expect ${kak_opt_fzf_horizontal_map:-ctrl-s}" + printf "%s\n" "fzf -kak-cmd %{edit -existing} -items-cmd %{$cmd} -fzf-args %{-m --expect ${kak_opt_fzf_window_map:-ctrl-w} $additional_flags} -filter %{perl -pe \"if (/${kak_opt_fzf_window_map:-ctrl-w}|${kak_opt_fzf_vertical_map:-ctrl-v}|${kak_opt_fzf_horizontal_map:-ctrl-s}|^$/) {} else {print \\\"$repo_root/\\\"}\"}" }} § diff --git a/rc/modules/VCS/fzf-git.kak b/rc/modules/VCS/fzf-git.kak index d1e878b..8227eb8 100644 --- a/rc/modules/VCS/fzf-git.kak +++ b/rc/modules/VCS/fzf-git.kak @@ -24,8 +24,8 @@ define-command -hidden fzf-git %{ evaluate-commands %sh{ (git) cmd='git ls-tree --full-tree --name-only -r HEAD' ;; (*) cmd=$kak_opt_fzf_git_command ;; esac - [ ! -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 %{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 \\\"$(git rev-parse --show-toplevel)/\\\"}\"}" + [ ! -z "${kak_client_env_TMUX}" ] && additional_flags="--expect ${kak_opt_fzf_vertical_map:-ctrl-v} --expect ${kak_opt_fzf_horizontal_map:-ctrl-s}" + printf "%s\n" "fzf -kak-cmd %{edit -existing} -items-cmd %{$cmd} -fzf-args %{-m --expect ${kak_opt_fzf_window_map:-ctrl-w} $additional_flags} -filter %{perl -pe \"if (/${kak_opt_fzf_window_map:-ctrl-w}|${kak_opt_fzf_vertical_map:-ctrl-v}|${kak_opt_fzf_horizontal_map:-ctrl-s}|^$/) {} else {print \\\"$(git rev-parse --show-toplevel)/\\\"}\"}" }} § diff --git a/rc/modules/VCS/fzf-hg.kak b/rc/modules/VCS/fzf-hg.kak index 9ce5e9c..8dcdbb7 100644 --- a/rc/modules/VCS/fzf-hg.kak +++ b/rc/modules/VCS/fzf-hg.kak @@ -24,8 +24,8 @@ define-command -hidden fzf-hg %{ evaluate-commands %sh{ (hg) cmd="hg locate -f" ;; (hg*) cmd=$kak_opt_fzf_hg_command ;; esac - [ ! -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 %{edit -existing} -items-cmd %{$cmd} -fzf-args %{-m --expect $kak_opt_fzf_window_map $additional_flags}" + [ ! -z "${kak_client_env_TMUX}" ] && additional_flags="--expect ${kak_opt_fzf_vertical_map:-ctrl-v} --expect ${kak_opt_fzf_horizontal_map:-ctrl-s}" + printf "%s\n" "fzf -kak-cmd %{edit -existing} -items-cmd %{$cmd} -fzf-args %{-m --expect ${kak_opt_fzf_window_map:-ctrl-w} $additional_flags}" }} § diff --git a/rc/modules/VCS/fzf-svn.kak b/rc/modules/VCS/fzf-svn.kak index 01812a1..9fb42da 100644 --- a/rc/modules/VCS/fzf-svn.kak +++ b/rc/modules/VCS/fzf-svn.kak @@ -25,8 +25,8 @@ define-command -hidden fzf-svn %{ evaluate-commands %sh{ (svn) cmd="svn list -R $repo_root | grep -v '$/'" ;; (svn*) cmd=$kak_opt_fzf_svn_command ;; esac - [ ! -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}" + [ ! -z "${kak_client_env_TMUX}" ] && additional_flags="--expect ${kak_opt_fzf_vertical_map:-ctrl-v} --expect ${kak_opt_fzf_horizontal_map:-ctrl-s}" + printf "%s\n" "fzf -kak-cmd %{cd $repo_root; edit -existing} -items-cmd %{$cmd} -fzf-args %{-m --expect ${kak_opt_fzf_window_map:-ctrl-w} $additional_flags} -post-action %{cd $current_path}" }} § diff --git a/rc/modules/fzf-buffer.kak b/rc/modules/fzf-buffer.kak index b318c01..f42ebbc 100644 --- a/rc/modules/fzf-buffer.kak +++ b/rc/modules/fzf-buffer.kak @@ -20,14 +20,14 @@ $buffers" message="Set buffer to edit in current client. : switch to selected buffer. -${kak_opt_fzf_window_map:?}: open buffer in new window" +${kak_opt_fzf_window_map:-ctrl-w}: open buffer in new window" [ -n "${kak_client_env_TMUX:-}" ] && tmux_keybindings=" -${kak_opt_fzf_horizontal_map:-}: open buffer in horizontal split -${kak_opt_fzf_vertical_map:-}: open buffer in vertical split" +${kak_opt_fzf_horizontal_map:-ctrl-s}: open buffer in horizontal split +${kak_opt_fzf_vertical_map:-ctrl-v}: open buffer in vertical split" printf "%s\n" "info -title 'fzf buffer' '$message$tmux_keybindings'" - [ -n "${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:-ctrl-v} --expect ${kak_opt_fzf_horizontal_map:-ctrl-s}" - 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:-ctrl-w} $additional_flags}" }} define-command -hidden fzf-delete-buffer %{ evaluate-commands %sh{ @@ -42,7 +42,7 @@ $buffers" message="Delete buffer. : delete selected buffer." 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:-ctrl-w} ${additional_flags:-}}" }} § diff --git a/rc/modules/fzf-ctags.kak b/rc/modules/fzf-ctags.kak index af5f062..0ddb5c2 100644 --- a/rc/modules/fzf-ctags.kak +++ b/rc/modules/fzf-ctags.kak @@ -928,17 +928,17 @@ define-command -hidden fzf-tag -params ..2 %{ evaluate-commands %sh{ message="Jump to a symbol''s definition : open tag in new buffer -${kak_opt_fzf_window_map:?}: open tag in new terminal" +${kak_opt_fzf_window_map:-ctrl-w}: open tag in new terminal" [ -n "${kak_client_env_TMUX:?}" ] && tmux_keybindings=" -${kak_opt_fzf_horizontal_map:-}: open tag in horizontal split -${kak_opt_fzf_vertical_map:-}: open tag in vertical split" +${kak_opt_fzf_horizontal_map:-ctrl-s}: open tag in horizontal split +${kak_opt_fzf_vertical_map:-ctrl-v}: open tag in vertical split" printf "%s\n" "info -title 'fzf tag' '$message$tmux_keybindings'" - [ -n "${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:-ctrl-v} --expect ${kak_opt_fzf_horizontal_map:-ctrl-s}" 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:-ctrl-w} $additional_flags}" }} § diff --git a/rc/modules/fzf-file.kak b/rc/modules/fzf-file.kak index a1449e9..6b51a9c 100644 --- a/rc/modules/fzf-file.kak +++ b/rc/modules/fzf-file.kak @@ -50,15 +50,15 @@ define-command -hidden fzf-file %{ evaluate-commands %sh{ cmd="$cmd 2>/dev/null" message="Open single or multiple files. : open file in new buffer. -${kak_opt_fzf_window_map:?}: open file in new terminal" +${kak_opt_fzf_window_map:-ctrl-w}: open file in new terminal" [ -n "${kak_client_env_TMUX:-}" ] && tmux_keybindings=" -${kak_opt_fzf_horizontal_map:-}: open file in horizontal split -${kak_opt_fzf_vertical_map:-}: open file in vertical split" +${kak_opt_fzf_horizontal_map:-ctrl-s}: open file in horizontal split +${kak_opt_fzf_vertical_map:-ctrl-v}: open file in vertical split" printf "%s\n" "info -title 'fzf file' '$message$tmux_keybindings'" - [ -n "${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:-ctrl-v} --expect ${kak_opt_fzf_horizontal_map:-ctrl-s}" [ "${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:-ctrl-w} $additional_flags}" }} § diff --git a/rc/modules/fzf-grep.kak b/rc/modules/fzf-grep.kak index e3a2de2..3f23704 100644 --- a/rc/modules/fzf-grep.kak +++ b/rc/modules/fzf-grep.kak @@ -35,14 +35,14 @@ define-command -hidden fzf-grep %{ evaluate-commands %sh{ title="fzf grep" message="grep through contents of all files recursively. : open search result in new buffer. -${kak_opt_fzf_window_map:?}: open search result in new terminal" +${kak_opt_fzf_window_map:-ctrl-w}: open search result in new terminal" [ -n "${kak_client_env_TMUX:-}" ] && tmux_keybindings=" -${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_horizontal_map:-ctrl-s}: open search result in horizontal split +${kak_opt_fzf_vertical_map:-ctrl-v}: open search result in vertical split" printf "%s\n" "info -title '${title}' '${message}${tmux_keybindings}'" - [ -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/'}" + [ -n "${kak_client_env_TMUX}" ] && additional_flags="--expect ${kak_opt_fzf_vertical_map:-ctrl-v} --expect ${kak_opt_fzf_horizontal_map:-ctrl-s}" + printf "%s\n" "fzf -kak-cmd %{evaluate-commands} -fzf-args %{--expect ${kak_opt_fzf_window_map:-ctrl-w} $additional_flags --delimiter=':' -n'3..'} -items-cmd %{$cmd} -filter %{sed -E 's/([^:]+):([^:]+):.*/edit -existing \1; execute-keys \2gvc/'}" }} § diff --git a/rc/modules/fzf-vcs.kak b/rc/modules/fzf-vcs.kak index 21a5085..e3e323f 100644 --- a/rc/modules/fzf-vcs.kak +++ b/rc/modules/fzf-vcs.kak @@ -39,11 +39,11 @@ bzr status" vcs=$(printf "%s\n" "$cmd" | awk '{print $1}') title="fzf $vcs" [ -n "${kak_client_env_TMUX:-}" ] && additional_keybindings=" -${kak_opt_fzf_horizontal_map:-}: open file in horizontal split -${kak_opt_fzf_vertical_map:-}: open file in vertical split" +${kak_opt_fzf_horizontal_map:-ctrl-s}: open file in horizontal split +${kak_opt_fzf_vertical_map:-ctrl-v}: open file in vertical split" message="Open single or multiple files from git tree. : open file in new buffer. -${kak_opt_fzf_window_map:?}: open file in new terminal $additional_keybindings" +${kak_opt_fzf_window_map:-ctrl-w}: 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 3e541ab..1105d97 100644 --- a/rc/modules/sk-grep.kak +++ b/rc/modules/sk-grep.kak @@ -29,14 +29,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. -${kak_opt_fzf_window_map:?}: open search result in new terminal" +${kak_opt_fzf_window_map:-ctrl-w}: open search result in new terminal" [ -n "${kak_client_env_TMUX:-}" ] && tmux_keybindings=" -${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_horizontal_map:-ctrl-s}: open search result in horizontal split +${kak_opt_fzf_vertical_map:-ctrl-v}: open search result in vertical split" printf "%s\n" "info -title '${title}' '${message}${tmux_keybindings}'" - [ -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}}" + [ -n "${kak_client_env_TMUX}" ] && additional_flags="--expect ${kak_opt_fzf_vertical_map:-ctrl-v} --expect ${kak_opt_fzf_horizontal_map:-ctrl-s}" + 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:-ctrl-w} $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 %{ From bfe1bc0a3de1f11d362acd67e476c7167f5558c7 Mon Sep 17 00:00:00 2001 From: Andrey Listopadov Date: Sat, 3 Apr 2021 13:02:39 +0300 Subject: [PATCH 7/7] fix #87 --- rc/fzf.kak | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/rc/fzf.kak b/rc/fzf.kak index 21ab66d..60ba15b 100644 --- a/rc/fzf.kak +++ b/rc/fzf.kak @@ -138,10 +138,13 @@ Switches: fzf -params .. %{ evaluate-commands %sh{ fzf_impl="${kak_opt_fzf_implementation:?}" + # trims selection and escapes single quotes + selection=$(printf "%s" "${kak_selection:-}" | sed -e "s/^[[:blank:]]*//g;s/[[:blank:]]*$//g;s/'/'\\\\''/g") + [ "${kak_opt_fzf_use_main_selection:-}" = "true" ] && \ - [ "$(printf "%s" "${kak_selection:-}" | wc -m)" -gt 1 ] && \ - [ "$(printf "%s" "${kak_selection:-}" | wc -l)" -eq 1 ] && \ - default_query="-i -q ${kak_selection:-}" + [ "$(printf "%s" "$kak_selection" | wc -m)" -gt 1 ] && \ + [ "$(printf "%s\n" "$selection" | wc -l)" -eq 1 ] && \ + default_query="-i -q '$selection'" while [ $# -gt 0 ]; do case $1 in