Merge pull request #46 from andreyorst/spring-refactoring
Spring refactoring
This commit is contained in:
commit
c5ce4d90da
13 changed files with 345 additions and 279 deletions
305
README.md
305
README.md
|
@ -1,190 +1,259 @@
|
|||
# fzf.kak
|
||||
|
||||
[](https://github.com/andreyorst/fzf.kak/releases)
|
||||
[](https://github.com/andreyorst/fzf.kak/releases)
|
||||

|
||||

|
||||
[![GitHub release][1]][2] [![GitHub Release Date][3]][4]
|
||||
![Github commits (since latest release)][5] ![license][6]
|
||||
|
||||
**fzf.kak** is a plugin for [Kakoune](https://github.com/mawww/kakoune) editor, that brings integration with [fzf](https://github.com/junegunn/fzf) tool. This plugin is being tested against Kakoune 2018.09.04. **fzf.kak** also supports [skim](https://github.com/lotabout/skim), 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 2018.09.04.
|
||||
**fzf.kak** also supports [skim][9], which can be used via `fzf_implementation`
|
||||
option.
|
||||
|
||||

|
||||
![showcase][10]
|
||||
|
||||
## Installation
|
||||
### With [plug.kak](https://github.com/andreyorst/plug.kak) (recommended)
|
||||
Recommended way to install is to use plug.kak plugin manager.
|
||||
You can install **fzf.kak** by adding this to your `kakrc`:
|
||||
### 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
|
||||
plug "andreyorst/fzf.kak"
|
||||
```
|
||||
|
||||
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.
|
||||
|
||||
Assuming that you've cloned **fzf.kak** repository to your Kakoune configuration folder:
|
||||
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 "~/.config/kak/fzf.kak/rc/fzf.kak" # loading base fzf module
|
||||
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 "~/.config/kak/plugins/fzf.kak/rc/fzf-modules/fzf-file.kak" # fzf file chooser
|
||||
source "~/.config/kak/plugins/fzf.kak/rc/fzf-modules/fzf-buffer.kak" # switching buffers with fzf
|
||||
source "~/.config/kak/plugins/fzf.kak/rc/fzf-modules/fzf-search.kak" # search within file contents
|
||||
source "~/.config/kak/plugins/fzf.kak/rc/fzf-modules/fzf-cd.kak" # change server's working directory
|
||||
source "~/.config/kak/plugins/fzf.kak/rc/fzf-modules/fzf-ctags.kak" # search for tag in your project ctags file
|
||||
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
|
||||
```
|
||||
|
||||
The same principle is applied to handling different version control systems. You need a base module for fzf,
|
||||
called `fzf-vcs.kak` and its submodules for each VCS. There are plenty of VC 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 "~/.config/kak/plugins/fzf.kak/rc/fzf-modules/fzf-vcs.kak" # VCS base module
|
||||
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 "~/.config/kak/plugins/fzf.kak/rc/fzf-modules/VCS/fzf-bzr.kak" # GNU Bazaar support
|
||||
source "~/.config/kak/plugins/fzf.kak/rc/fzf-modules/VCS/fzf-git.kak" # Git support module
|
||||
source "~/.config/kak/plugins/fzf.kak/rc/fzf-modules/VCS/fzf-hg.kak" # Mercurial VCS
|
||||
source "~/.config/kak/plugins/fzf.kak/rc/fzf-modules/VCS/fzf-svn.kak" # Subversion module
|
||||
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
|
||||
```
|
||||
|
||||
You can see that we load less nested modules first, and then go deeper and deeper. Besides that order of
|
||||
files within single depth level doesn't matter. This may look complex, but it makes plugin more versatile.
|
||||
And plugin managers, like [plug.kak](https://github.com/andreyorst/plug.kak) 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](#writing-a-module)!
|
||||
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 <c-p> ': fzf-mode<ret>'
|
||||
# note that the space after colon is intentional to suppess fzf-mode to show in command history
|
||||
```
|
||||
|
||||
Each fzf sub-command has mnemonic mapping, like `f` for opening files, `t` for tags and so on.
|
||||
Available mappings:
|
||||
- <kbd>b</kbd> - Select buffer
|
||||
- <kbd>c</kbd> - Switch server's working directory
|
||||
- <kbd>f</kbd> - Search for file and open it
|
||||
- <kbd>v</kbd> - Edit file in version control system tree
|
||||
- <kbd>Alt+v</kbd> - Explicitly select which vcs command to run
|
||||
- <kbd>s</kbd> - Search over buffer contents and jump to result line
|
||||
- <kbd>t</kbd> - Browse ctags tags
|
||||
- <kbd>Alt+t</kbd> - Select tag kind filter on per language basis
|
||||
Note that space between colon and command is intentional and will strip this
|
||||
command from command history.
|
||||
|
||||
So for example pressing <kbd>Ctrl+p</kbd><kbd>f</kbd> will open fzf at the
|
||||
bottom of the Kakoune buffer, showing you all possible files.
|
||||
Each `fzf` module defines mnemonic mapping, like <kbd>f</kbd> for opening files,
|
||||
<kbd>t</kbd> for tags, <kbd>s</kbd> for search, and so on. Available mappings:
|
||||
|
||||
### Settings
|
||||
**fzf.kak** features a lot of settings via options that can be altered to change how **fzf.kak** behaves.
|
||||
- <kbd>b</kbd> - Select buffer.
|
||||
- <kbd>c</kbd> - Switch server's working directory.
|
||||
- <kbd>f</kbd> - Search for file and open it.
|
||||
- <kbd>v</kbd> - Edit file in version control system tree.
|
||||
- <kbd>Alt</kbd>+<kbd>v</kbd> - Explicitly select which VCS command to run.
|
||||
- <kbd>s</kbd> - Search over buffer contents and jump to result line.
|
||||
- <kbd>t</kbd> - Browse ctags tags.
|
||||
- <kbd>Alt</kbd>+<kbd>t</kbd> - Select tag kind filter on per language basis.
|
||||
- <kbd>g</kbd> - Interactive grep.
|
||||
|
||||
#### 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.
|
||||
So for example pressing <kbd>Ctrl</kbd>+<kbd>p</kbd> <kbd>f</kbd> will open
|
||||
`fzf` window, showing you all files from current directory recursively.
|
||||
|
||||
#### File with file-preview turned on.
|
||||
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.
|
||||
|
||||
### File command
|
||||
You can configure what command to use to search for files, and it's arguments.
|
||||
Supported tools are [GNU Find](https://www.gnu.org/software/findutils/), [The Silver Searcher](https://github.com/ggreer/the_silver_searcher), [ripgrep](https://github.com/BurntSushi/ripgrep), [fd](https://github.com/sharkdp/fd). GNU find is used by default, but you can switch to another one. There are some default values for those, so you can go:
|
||||
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'
|
||||
set-option global fzf_file_command 'rg' # 'ag', 'fd', or 'find'
|
||||
```
|
||||
|
||||
Or if you don't like default file arguments, which are `find -type f`, and would like to disable searching in, say `.git` directories you can set it like so:
|
||||
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"
|
||||
```
|
||||
|
||||
The same pattern applies for other commands, except `buffer`, and `cd`.
|
||||
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.
|
||||
|
||||
#### VCS
|
||||
This script supports these version control systems: Git, Subversion, GNU Bazaar, Mercurial.
|
||||
By default <kbd>v</kbd> mapping from `fzf mode` will detect your version control system and open fzf for you.
|
||||
If you wish to explicitly use some particular vcs command, you can use `V` mapping, which includes
|
||||
all supported vcs shortcuts.
|
||||
### 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.
|
||||
|
||||
You also able to set parameters to vcs command to use to provide project files. Supported options:
|
||||
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`
|
||||
|
||||
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`.
|
||||
|
||||
#### 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_highlighter` option.
|
||||
Supported highlighters are:
|
||||
|
||||
* [Bat][16]
|
||||
* [Coderay][17]
|
||||
* [Highlight][18]
|
||||
* [Rouge][19]
|
||||
|
||||
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 <kbd>v</kbd> 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 <kbd>Alt</kbd>+<kbd>v</kbd>
|
||||
mapping, which includes all supported VCS shortcuts.
|
||||
|
||||
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.
|
||||
|
||||
#### ctags
|
||||
It is also possible to add parameters to ctags search executable. like `sort -u` and others:
|
||||
### 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.
|
||||
|
||||
```kak
|
||||
set-option global fzf_tag_command 'readtags -l | cut -f1 | sort -u | ... '
|
||||
```
|
||||
## `fzf` command
|
||||
`fzf` command can be used from prompt mode and for [scripting][20]. It supports
|
||||
these arguments:
|
||||
|
||||
Though it is not recommended, since `sort` may slowdown `fzf-tag` on huge projects.
|
||||
|
||||
##### Filtering tags
|
||||
Since ctags supports showing particular kind of tag for many languages,
|
||||
`fzf-tag` dinamicly defines mappings for those languages with <kbd>Alt</kbd> key based on current filetype.
|
||||
For example to show only functions while `fzf-tag` is active press <kbd>Alt</kbd>+<kbd>f</kbd>.
|
||||
It will reload fzf window and only function tags will be listed.
|
||||
|
||||
#### Preview
|
||||
When using X11 **fzf.kak** automatically tries to detect where to show preview window, depending
|
||||
on aspect ratio of new termial window. By default if the 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`.
|
||||
|
||||
When **fzf.kak** is used in tmux, it will show preview on the right side. Heigth of preview split can be adjusted with
|
||||
`fzf_tmux_height_file_preview`
|
||||
|
||||
Amount of lines in preview window can be changed with `fzf_preview_lines` option.
|
||||
|
||||
You also can specify which highlighter to use within the preview window with `fzf_highlighter` option.
|
||||
Supported tools are:
|
||||
|
||||
* [Bat](https://github.com/sharkdp/bat)
|
||||
* [Coderay](https://github.com/rubychan/coderay)
|
||||
* [Highlight](https://gitlab.com/saalen/highlight)
|
||||
* [Rouge](https://github.com/jneen/rouge)
|
||||
|
||||
You can disable the preview window in fzf window by setting `fzf_preview` option to `false`:
|
||||
|
||||
```kak
|
||||
set-option global fzf_preview false
|
||||
```
|
||||
- `-kak-cmd`: A Kakoune command that is applied to `fzf` resulting value, e.g.
|
||||
`edit -existing`, `change-directory`, e.t.c.
|
||||
- `-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`: 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.
|
||||
- `-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/fzf-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
|
||||
* 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.
|
||||
|
||||
[1]: https://img.shields.io/github/release/andreyorst/fzf.kak.svg
|
||||
[2]: https://github.com/andreyorst/fzf.kak/releases
|
||||
[3]: https://img.shields.io/github/release-date/andreyorst/fzf.kak.svg
|
||||
[4]: https://github.com/andreyorst/fzf.kak/releases
|
||||
[5]: https://img.shields.io/github/commits-since/andreyorst/fzf.kak/latest.svg
|
||||
[6]: https://img.shields.io/github/license/andreyorst/fzf.kak.svg
|
||||
[7]: https://github.com/mawww/kakoune
|
||||
[8]: https://github.com/junegunn/fzf
|
||||
[9]: https://github.com/lotabout/skim
|
||||
[10]: https://user-images.githubusercontent.com/19470159/46813471-6ee76800-cd7f-11e8-89aa-123b3a5f9f1b.gif
|
||||
[11]: https://github.com/andreyorst/plug.kak
|
||||
[12]: https://www.gnu.org/software/findutils/
|
||||
[13]: https://github.com/ggreer/the_silver_searcher
|
||||
[14]: https://github.com/BurntSushi/ripgrep
|
||||
[15]: https://github.com/sharkdp/fd
|
||||
[16]: https://github.com/sharkdp/bat
|
||||
[17]: https://github.com/rubychan/coderay
|
||||
[18]: https://gitlab.com/saalen/highlight
|
||||
[19]: https://github.com/jneen/rouge
|
||||
[20]: #writing-a-module
|
||||
[21]: rc/modules/sk-grep.kak
|
||||
[22]: rc/modules/fzf-search.kak
|
||||
[23]: #configuration
|
||||
|
|
232
rc/fzf.kak
232
rc/fzf.kak
|
@ -8,7 +8,7 @@
|
|||
# │ different fzf commands. │
|
||||
# ╰─────────────────────────────────╯
|
||||
|
||||
try %{ declare-user-mode fzf } catch %{ echo -markup "{Error}Can't declare mode 'fzf' - already exists" }
|
||||
try %{ declare-user-mode fzf }
|
||||
|
||||
# Options
|
||||
declare-option -docstring 'implementation of fzf that you want to use.
|
||||
|
@ -43,7 +43,7 @@ These are default arguments for the tools above:
|
|||
highlight: "highlight --failsafe -O ansi {}"
|
||||
rouge: "rougify {}"
|
||||
' \
|
||||
str fzf_highlighter "highlight"
|
||||
str fzf_highlight_cmd "highlight"
|
||||
|
||||
declare-option -docstring "height of fzf tmux split in screen lines or percents.
|
||||
Default value: 25%%" \
|
||||
|
@ -51,7 +51,7 @@ str fzf_tmux_height '25%'
|
|||
|
||||
declare-option -docstring "height of fzf tmux split for file preview in screen lines or percents.
|
||||
Default value: 70%%" \
|
||||
str fzf_tmux_height_file_preview '70%'
|
||||
str fzf_preview_tmux_height '70%'
|
||||
|
||||
declare-option -docstring "width of preview window.
|
||||
Default value: 50%%" \
|
||||
|
@ -69,155 +69,141 @@ Best used with mapping like:
|
|||
" \
|
||||
fzf-mode %{ try %{ evaluate-commands 'enter-user-mode fzf' } }
|
||||
|
||||
define-command -hidden fzf-vertical -params .. %{
|
||||
try %{
|
||||
define-command -hidden -docstring "wrapper command to create new vertical split" \
|
||||
fzf-vertical -params .. %{ try %{
|
||||
tmux-terminal-vertical kak -c %val{session} -e "%arg{@}"
|
||||
} catch %{
|
||||
} catch %{
|
||||
tmux-new-vertical "%arg{@}"
|
||||
}
|
||||
}
|
||||
}}
|
||||
|
||||
define-command -hidden fzf-horizontal -params .. %{
|
||||
try %{
|
||||
define-command -hidden -docstring "wrapper command to create new horizontal split" \
|
||||
fzf-horizontal -params .. %{ try %{
|
||||
tmux-terminal-horizontal kak -c %val{session} -e "%arg{@}"
|
||||
} catch %{
|
||||
} catch %{
|
||||
tmux-new-horizontal "%arg{@}"
|
||||
}
|
||||
}
|
||||
}}
|
||||
|
||||
define-command -hidden fzf-window -params .. %{
|
||||
try %sh{
|
||||
define-command -hidden -docstring "wrapper command to create new terminal" \
|
||||
fzf-window -params .. %{ try %sh{
|
||||
if [ -n "$kak_client_env_TMUX" ]; then
|
||||
printf "%s\n" 'tmux-terminal-window kak -c %val{session} -e "%arg{@}"'
|
||||
else
|
||||
printf "%s\n" 'x11-terminal kak -c %val{session} -e "%arg{@}"'
|
||||
printf "%s\n" 'terminal kak -c %val{session} -e "%arg{@}"'
|
||||
fi
|
||||
} catch %sh{
|
||||
} catch %sh{
|
||||
if [ -n "$kak_client_env_TMUX" ]; then
|
||||
printf "%s\n" 'tmux-new-window "%arg{@}"'
|
||||
else
|
||||
printf "%s\n" 'x11-new "%arg{@}"'
|
||||
printf "%s\n" 'new "%arg{@}"'
|
||||
fi
|
||||
}
|
||||
}
|
||||
}}
|
||||
|
||||
define-command -hidden -docstring \
|
||||
"fzf <command> <items command> [<fzf args> <extra commands>]: generic fzf command.
|
||||
This command can be used to create new fzf wrappers for various Kakoune or external
|
||||
features. More about arguments:
|
||||
define-command -docstring \
|
||||
"fzf <switches>: generic fzf command. This command can be used to create new fzf wrappers for various Kakoune or external features.
|
||||
|
||||
<command>:
|
||||
The <command> is a Kakoune command that should be used after fzf returns some result.
|
||||
For example to open file chooser we can call fzf with `edit` as a command:
|
||||
'fzf %{edit} %{<items command>}'
|
||||
After choosing one or more files in fzf, <command> will be used with each of them.
|
||||
Switches:
|
||||
-kak-cmd <command>: A Kakoune cmd that is applied to fzf resulting value
|
||||
-items-cmd <items command>: A command that is used as a pipe to provide list of values to fzf
|
||||
-fzf-impl <implementation>: Owerride fzf implementation variable
|
||||
-fzf-args <args>: Additional flags for fzf program
|
||||
-preview-cmd: A preview command
|
||||
-preview: Should fzf window include preview
|
||||
-filter <commands>: A pipe which will be applied to result provided by fzf
|
||||
-post-action <commands>: Extra commands that are preformed after `-kak-cmd' command" \
|
||||
-shell-script-completion %{
|
||||
printf "%s\n" "-kak-cmd
|
||||
-items-cmd
|
||||
-fzf-impl
|
||||
-fzf-args
|
||||
-preview-cmd
|
||||
-preview
|
||||
-filter
|
||||
-post-action"
|
||||
} \
|
||||
fzf -params .. %{ evaluate-commands %sh{
|
||||
fzf_impl="${kak_opt_fzf_implementation}"
|
||||
|
||||
<items command>
|
||||
This is the shell command that is used to provide list of values to fzf. It can be
|
||||
any command that provides newline separated list of items, which is then piped to fzf.
|
||||
while [ $# -gt 0 ]; do
|
||||
case $1 in
|
||||
-kak-cmd) shift; kakoune_cmd="$1" ;;
|
||||
-items-cmd) shift; items_cmd="$1 |" ;;
|
||||
-fzf-impl) shift; fzf_impl="$1" ;;
|
||||
-fzf-args) shift; fzf_args="$1" ;;
|
||||
-preview-cmd) shift; preview_cmd="$1" ;;
|
||||
-preview) preview="true" ;;
|
||||
-filter) shift; filter="| $1" ;;
|
||||
-post-action) shift; post_action="$1" ;;
|
||||
esac; shift
|
||||
done
|
||||
|
||||
<fzf args>
|
||||
These are additional flags for fzf program, that are passed to it. You can check them
|
||||
in fzf manual.
|
||||
|
||||
<extra commands>
|
||||
This is extra commands that are preformed after fzf finishes and main command was
|
||||
executed. This can be used to invoke fzf back, like in fzf-cd command, or to execute
|
||||
any other Kakoune command that is meaningfull in current situation. This is more is
|
||||
a workaround of problem with executing composite commands, where fzf result should
|
||||
be in the middle of the command and may be changed or removed it further versions.
|
||||
|
||||
If you want to develop a module with fzf command, feel free to check for existing
|
||||
module implementations in 'rc/fzf-modules' directory." \
|
||||
fzf -params 2..4 %{ evaluate-commands %sh{
|
||||
command=$1
|
||||
items_command=$2
|
||||
additional_flags=$3
|
||||
extra_action=$4
|
||||
tmux_height=$kak_opt_fzf_tmux_height
|
||||
|
||||
items_executable=$(printf "%s\n" "$items_command" | grep -o -E "[[:alpha:]]+" | head -1)
|
||||
if [ -z "$(command -v $items_executable)" ]; then
|
||||
printf "%s\n" "fail %{'$items_executable' executable not found}"
|
||||
exit
|
||||
fi
|
||||
|
||||
if [ -z "${command##edit*}" ] && [ $kak_opt_fzf_preview = "true" ]; then
|
||||
case $kak_opt_fzf_highlighter in
|
||||
bat)
|
||||
highlighter="bat --color=always --style=plain {}" ;;
|
||||
coderay)
|
||||
highlighter="coderay {}" ;;
|
||||
highlight)
|
||||
highlighter="highlight --failsafe -O ansi {}" ;;
|
||||
rouge)
|
||||
highlighter="rougify {}" ;;
|
||||
bat*|coderay*|highlight*|rougify*)
|
||||
highlighter=$kak_opt_fzf_highlighter ;;
|
||||
*)
|
||||
executable=$(printf "%s\n" "$kak_opt_fzf_highlighter" | grep -o -E '[[:alpha:]]+' | head -1)
|
||||
printf "%s\n" "echo -markup %{{Information}'$executable' highlighter is not supported by the script. fzf.kak may not work as you expect.}"
|
||||
highlighter=$kak_opt_fzf_highlighter ;;
|
||||
esac
|
||||
|
||||
tmux_height=$kak_opt_fzf_tmux_height_file_preview
|
||||
additional_flags="--preview '($highlighter || cat {}) 2>/dev/null | head -n $kak_opt_fzf_preview_lines' --preview-window=\$pos $additional_flags"
|
||||
fi
|
||||
|
||||
if [ -n "$kak_client_env_TMUX" ]; then
|
||||
preview_pos="pos=right:$kak_opt_fzf_preview_width;"
|
||||
if [ "${preview}" = "true" ]; then
|
||||
# bake position option to define them at runtime
|
||||
if [ -n "${kak_client_env_TMUX}" ]; then
|
||||
preview_position="pos=right:${kak_opt_fzf_preview_width};"
|
||||
# tmux height should be changed when preview is on
|
||||
tmux_height="${kak_opt_fzf_preview_tmux_height}"
|
||||
else
|
||||
preview_pos="sleep 0.1; [ \$(tput cols) -gt \$(expr \$(tput lines) \* 2) ] && pos=right:$kak_opt_fzf_preview_width || pos=top:$kak_opt_fzf_preview_height;"
|
||||
# this code chooses previewposition depending on window width at runtime
|
||||
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};"
|
||||
fi
|
||||
# handle preview if not defined explicitly with `-preview-cmd'
|
||||
if [ ${kak_opt_fzf_preview} = "true" ] && [ -z "${preview_cmd}" ]; then
|
||||
case ${kak_opt_fzf_highlight_cmd} 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_cmd}" ;;
|
||||
esac
|
||||
preview_cmd="--preview '(${highlight_cmd} || cat {}) 2>/dev/null | head -n ${kak_opt_fzf_preview_lines}' --preview-window=\${pos}"
|
||||
fi
|
||||
fi
|
||||
|
||||
tmp=$(mktemp ${TMPDIR:-/tmp}/kak-fzf-tmp.XXXXXX)
|
||||
fzfcmd=$(mktemp ${TMPDIR:-/tmp}/kak-fzfcmd.XXXXXX)
|
||||
printf "%s\n" "cd \"$PWD\" && $preview_pos $items_command | SHELL=$(command -v sh) $kak_opt_fzf_implementation $additional_flags > $tmp; rm $fzfcmd" > $fzfcmd
|
||||
chmod 755 $fzfcmd
|
||||
fzf_tmp=$(mktemp -d ${TMPDIR:-/tmp}/fzf.kak.XXXXXX)
|
||||
fzfcmd="${fzf_tmp}/fzfcmd"
|
||||
result="${fzf_tmp}/result"
|
||||
|
||||
if [ -n "$kak_client_env_TMUX" ]; then
|
||||
shell_executable="$(command -v sh)"
|
||||
|
||||
# compose entire fzf command with all args into single file which will be executed later
|
||||
printf "%s\n" "cd \"${PWD}\" && ${preview_position} ${items_cmd} SHELL=${shell_executable} ${fzf_impl} ${fzf_args} ${preview_cmd} ${filter} > ${result}; rm ${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}
|
||||
# if height contains `%' then `-p' will be used
|
||||
[ -n "${tmux_height%%*%}" ] && measure="-l" || measure="-p"
|
||||
cmd="command tmux split-window $measure ${tmux_height%%%*} 'sh -c $fzfcmd'"
|
||||
elif [ -n "$kak_opt_termcmd" ]; then
|
||||
cmd="$kak_opt_termcmd 'sh -c $fzfcmd'"
|
||||
# `terminal' doesn't support any kind of width and height parameters, so tmux panes are created by tmux itself
|
||||
cmd="nop %sh{ command tmux split-window ${measure} ${tmux_height%%%*} '${fzfcmd}' }"
|
||||
else
|
||||
printf "%s\n" "fail %{termcmd option is not set}"
|
||||
rm $fzfcmd
|
||||
rm $tmp
|
||||
exit
|
||||
cmd="terminal %{${fzfcmd}}"
|
||||
fi
|
||||
|
||||
printf "%s\n" "${cmd}"
|
||||
|
||||
# main loop
|
||||
( while [ -e ${fzfcmd} ]; do sleep 0.1; done
|
||||
if [ -s ${result} ]; then
|
||||
(
|
||||
eval "$cmd"
|
||||
while [ -e $fzfcmd ]; do
|
||||
sleep 0.1
|
||||
done
|
||||
if [ -s $tmp ]; then
|
||||
(
|
||||
read action
|
||||
case $action in
|
||||
ctrl-w)
|
||||
wincmd="fzf-window" ;;
|
||||
ctrl-s)
|
||||
wincmd="fzf-vertical" ;;
|
||||
ctrl-v)
|
||||
wincmd="fzf-horizontal" ;;
|
||||
*)
|
||||
if [ -n "$action" ]; then
|
||||
printf "%s\n" "evaluate-commands -client $kak_client '$command' '$action'" | kak -p $kak_session
|
||||
[ -n "$extra_action" ] && printf "%s\n" "evaluate-commands -client $kak_client $extra_action" | kak -p $kak_session
|
||||
fi ;;
|
||||
while read line; do
|
||||
case ${line} in
|
||||
ctrl-w) wincmd="fzf-window" ;;
|
||||
ctrl-s) wincmd="fzf-vertical" ;;
|
||||
ctrl-v) wincmd="fzf-horizontal" ;;
|
||||
*) item=${line} ;;
|
||||
esac
|
||||
kakoune_command() {
|
||||
printf "%s\n" "evaluate-commands -client $kak_client $wincmd %{$command %{$1}}"
|
||||
[ -n "$extra_action" ] && printf "%s\n" "evaluate-commands -client $kak_client $extra_action"
|
||||
}
|
||||
while read item; do
|
||||
kakoune_command "$item" | kak -p $kak_session
|
||||
done
|
||||
) < $tmp
|
||||
if [ -n "${item}" ]; then
|
||||
printf "%s\n" "evaluate-commands -client ${kak_client} ${wincmd} %{${kakoune_cmd} %{${item}}}"
|
||||
fi
|
||||
rm $tmp
|
||||
done
|
||||
if [ -n "${post_action}" ]; then
|
||||
printf "%s\n" "evaluate-commands -client ${kak_client} %{${post_action}}"
|
||||
fi
|
||||
) < ${result} | kak -p ${kak_session}
|
||||
fi
|
||||
rm -rf ${fzf_tmp}
|
||||
) > /dev/null 2>&1 < /dev/null &
|
||||
}}
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@ Default arguments:
|
|||
" \
|
||||
str fzf_bzr_command "bzr"
|
||||
|
||||
try %{ declare-user-mode fzf-vcs }
|
||||
map global fzf-vcs -docstring "edit file from GNU Bazaar tree" 'b' '<esc>: fzf-bzr<ret>'
|
||||
|
||||
define-command -hidden fzf-bzr %{ evaluate-commands %sh{
|
||||
|
@ -29,6 +30,6 @@ define-command -hidden fzf-bzr %{ evaluate-commands %sh{
|
|||
cmd=$kak_opt_fzf_bzr_command ;;
|
||||
esac
|
||||
[ ! -z "${kak_client_env_TMUX}" ] && additional_flags="--expect ctrl-v --expect ctrl-s"
|
||||
printf "%s\n" "fzf %{cd $repo_root; edit -existing} %{$cmd} %{-m --expect ctrl-w $additional_flags} %{cd $current_path}"
|
||||
printf "%s\n" "fzf -kak-cmd %{cd $repo_root; edit -existing} -items-cmd %{$cmd} -fzf-args %{-m --expect ctrl-w $additional_flags} -post-action %{cd $current_path}"
|
||||
}}
|
||||
|
|
@ -17,6 +17,7 @@ Default arguments:
|
|||
" \
|
||||
str fzf_git_command "git"
|
||||
|
||||
try %{ declare-user-mode fzf-vcs }
|
||||
map global fzf-vcs -docstring "edit file from Git tree" 'g' '<esc>: fzf-git<ret>'
|
||||
|
||||
define-command -override -hidden fzf-git %{ evaluate-commands %sh{
|
||||
|
@ -29,6 +30,6 @@ define-command -override -hidden fzf-git %{ evaluate-commands %sh{
|
|||
cmd=$kak_opt_fzf_git_command ;;
|
||||
esac
|
||||
[ ! -z "${kak_client_env_TMUX}" ] && additional_flags="--expect ctrl-v --expect ctrl-s"
|
||||
printf "%s\n" "fzf %{cd $repo_root; edit -existing} %{$cmd} %{-m --expect ctrl-w $additional_flags} %{cd $current_path}"
|
||||
printf "%s\n" "fzf -kak-cmd %{cd $repo_root; edit -existing} -items-cmd %{$cmd} -fzf-args %{-m --expect ctrl-w $additional_flags} -post-action %{cd $current_path}"
|
||||
}}
|
||||
|
|
@ -17,6 +17,7 @@ Default arguments:
|
|||
" \
|
||||
str fzf_hg_command "hg"
|
||||
|
||||
try %{ declare-user-mode fzf-vcs }
|
||||
map global fzf-vcs -docstring "edit file from mercurial tree" 'h' '<esc>: fzf-hg<ret>'
|
||||
|
||||
define-command -hidden fzf-hg %{ evaluate-commands %sh{
|
||||
|
@ -29,6 +30,6 @@ define-command -hidden fzf-hg %{ evaluate-commands %sh{
|
|||
cmd=$kak_opt_fzf_hg_command ;;
|
||||
esac
|
||||
[ ! -z "${kak_client_env_TMUX}" ] && additional_flags="--expect ctrl-v --expect ctrl-s"
|
||||
printf "%s\n" "fzf %{cd $repo_root; edit -existing} %{$cmd} %{-m --expect ctrl-w $additional_flags} %{cd $current_path}"
|
||||
printf "%s\n" "fzf -kak-cmd %{cd $repo_root; edit -existing} -items-cmd %{$cmd} -fzf-args %{-m --expect ctrl-w $additional_flags} -post-action %{cd $current_path}"
|
||||
}}
|
||||
|
|
@ -17,6 +17,7 @@ Default arguments:
|
|||
" \
|
||||
str fzf_svn_command "svn"
|
||||
|
||||
try %{ declare-user-mode fzf-vcs }
|
||||
map global fzf-vcs -docstring "edit file from Subversion tree" 's' '<esc>: fzf-svn<ret>'
|
||||
|
||||
define-command -hidden fzf-svn %{ evaluate-commands %sh{
|
||||
|
@ -29,6 +30,6 @@ define-command -hidden fzf-svn %{ evaluate-commands %sh{
|
|||
cmd=$kak_opt_fzf_svn_command ;;
|
||||
esac
|
||||
[ ! -z "${kak_client_env_TMUX}" ] && additional_flags="--expect ctrl-v --expect ctrl-s"
|
||||
printf "%s\n" "fzf %{cd $repo_root; edit -existing} %{$cmd} %{-m --expect ctrl-w $additional_flags} %{cd $current_path}"
|
||||
printf "%s\n" "fzf -kak-cmd %{cd $repo_root; edit -existing} -items-cmd %{$cmd} -fzf-args %{-m --expect ctrl-w $additional_flags} -post-action %{cd $current_path}"
|
||||
}}
|
||||
|
|
@ -8,6 +8,7 @@
|
|||
# │ GitHub.com/andreyorst/fzf.kak │
|
||||
# ╰──────────────────────────────────────╯
|
||||
|
||||
try %{ declare-user-mode fzf }
|
||||
map global fzf -docstring "open buffer" 'b' '<esc>: fzf-buffer<ret>'
|
||||
|
||||
define-command -hidden fzf-buffer %{ evaluate-commands %sh{
|
||||
|
@ -27,5 +28,5 @@ define-command -hidden fzf-buffer %{ evaluate-commands %sh{
|
|||
printf "%s\n" "info -title 'fzf buffer' '$message$tmux_keybindings'"
|
||||
[ ! -z "${kak_client_env_TMUX}" ] && additional_flags="--expect ctrl-v --expect ctrl-s"
|
||||
|
||||
printf "%s\n" "fzf %{buffer} %{(cat $buffers; rm $buffers)} %{--expect ctrl-w $additional_flags}"
|
||||
printf "%s\n" "fzf -kak-cmd %{buffer} -items-cmd %{(cat $buffers; rm $buffers)} -fzf-args %{--expect ctrl-w $additional_flags}"
|
||||
}}
|
|
@ -29,11 +29,13 @@ str cd_preview_cmd "tree -d {}"
|
|||
declare-option -docstring 'maximum amount of previewed directories' \
|
||||
int fzf_preview_dirs '300'
|
||||
|
||||
try %{ declare-user-mode fzf }
|
||||
map global fzf -docstring "change directory" 'c' '<esc>: fzf-cd<ret>'
|
||||
|
||||
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}"
|
||||
printf '%s\n' "info -title %{fzf change directory} %{Change the server's working directory
|
||||
current path: $(pwd)}"
|
||||
|
||||
case $kak_opt_fzf_cd_command in
|
||||
find)
|
||||
|
@ -41,9 +43,10 @@ define-command -hidden fzf-cd %{ evaluate-commands %sh{
|
|||
*)
|
||||
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_cmd) 2>/dev/null | head -n $kak_opt_fzf_preview_dirs'"
|
||||
fi
|
||||
printf "%s\n" "fzf %{change-directory} %{$items_command} %{$preview} %{fzf-cd}"
|
||||
printf "%s\n" "fzf $preview_flag -kak-cmd %{change-directory} -items-cmd %{$items_command} -preview-cmd %{$preview} -post-action %{fzf-cd}"
|
||||
}}
|
||||
|
|
@ -11,6 +11,7 @@ declare-option -docstring "file that should be used by fzf-tag to provide tags.
|
|||
Default value: tags" \
|
||||
str fzf_tag_file_name "tags"
|
||||
|
||||
try %{ declare-user-mode fzf }
|
||||
map global fzf -docstring "find tag" 't' '<esc>: fzf-tag<ret>'
|
||||
|
||||
# this huge try block defines filetype aware filter mappings for separate fzf-ctags mode
|
||||
|
@ -813,7 +814,7 @@ define-command -hidden fzf-tag -params ..2 %{ evaluate-commands %sh{
|
|||
|
||||
message="Jump to a symbol''s definition
|
||||
<ret>: open tag in new buffer
|
||||
<c-w>: open tag in new window"
|
||||
<c-w>: open tag in new terminal"
|
||||
|
||||
[ -n "${kak_client_env_TMUX}" ] && tmux_keybindings="
|
||||
<c-s>: open tag in horizontal split
|
||||
|
@ -823,5 +824,5 @@ define-command -hidden fzf-tag -params ..2 %{ evaluate-commands %sh{
|
|||
|
||||
[ ! -z "${kak_client_env_TMUX}" ] && additional_flags="--expect ctrl-v --expect ctrl-s"
|
||||
printf "%s\n" "set-option -add window ctagsfiles %{$path/$kak_opt_fzf_tag_file_name}"
|
||||
printf "%s\n" "fzf %{ctags-search} %{$cmd | awk '!a[\$0]++'} %{--expect ctrl-w $additional_flags}"
|
||||
printf "%s\n" "fzf -kak-cmd %{ctags-search} -items-cmd %{$cmd | awk '!a[\$0]++'} -fzf-args %{--expect ctrl-w $additional_flags}"
|
||||
}}
|
|
@ -24,6 +24,7 @@ Default arguments:
|
|||
" \
|
||||
str fzf_file_command "find"
|
||||
|
||||
try %{ declare-user-mode fzf }
|
||||
map global fzf -docstring "open file" 'f' '<esc>: fzf-file<ret>'
|
||||
|
||||
define-command -hidden fzf-file %{ evaluate-commands %sh{
|
||||
|
@ -50,13 +51,13 @@ define-command -hidden fzf-file %{ evaluate-commands %sh{
|
|||
|
||||
message="Open single or multiple files.
|
||||
<ret>: open file in new buffer.
|
||||
<c-w>: open file in new window"
|
||||
<c-w>: open file in new terminal"
|
||||
[ ! -z "${kak_client_env_TMUX}" ] && tmux_keybindings="
|
||||
<c-s>: open file in horizontal split
|
||||
<c-v>: open file in vertical split"
|
||||
|
||||
printf "%s\n" "info -title 'fzf file' '$message$tmux_keybindings'"
|
||||
[ ! -z "${kak_client_env_TMUX}" ] && additional_flags="--expect ctrl-v --expect ctrl-s"
|
||||
printf "%s\n" "fzf %{edit -existing} %{$cmd} %{-m --expect ctrl-w $additional_flags}"
|
||||
printf "%s\n" "fzf -preview -kak-cmd %{edit -existing} -items-cmd %{$cmd} -fzf-args %{-m --expect ctrl-w $additional_flags}"
|
||||
}}
|
||||
|
|
@ -8,6 +8,7 @@
|
|||
# │ GitHub.com/andreyorst/fzf.kak │
|
||||
# ╰──────────────────────────────────────╯
|
||||
|
||||
try %{ declare-user-mode fzf }
|
||||
map global fzf -docstring "search in buffer" 's' '<esc>: fzf-buffer-search<ret>'
|
||||
|
||||
define-command -hidden fzf-buffer-search %{ evaluate-commands %sh{
|
||||
|
@ -16,6 +17,6 @@ define-command -hidden fzf-buffer-search %{ evaluate-commands %sh{
|
|||
printf "%s\n" "info -title '$title' '$message'"
|
||||
buffer_content="$(mktemp ${TMPDIR:-/tmp}/fzf-buff-${kak_buffile##*/}.XXXXXX)"
|
||||
printf "%s\n" "execute-keys -draft %{%<a-|>cat<space>><space>$buffer_content<ret>;}"
|
||||
printf "%s\n" "fzf %{execute-keys} %{(nl -b a -n ln $buffer_content; rm $buffer_content)} %{--reverse | cut -f 1} %{execute-keys gx}"
|
||||
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}"
|
||||
}}
|
||||
|
|
@ -11,6 +11,7 @@
|
|||
|
||||
try %{ declare-user-mode fzf-vcs } catch %{echo -markup "{Error}Can't declare mode 'fzf-vcs' - already exists"}
|
||||
|
||||
try %{ declare-user-mode fzf }
|
||||
map global fzf -docstring "edit file from vcs repo" 'v' '<esc>: fzf-vcs<ret>'
|
||||
map global fzf -docstring "svitch to vcs selection mode" '<a-v>' '<esc>: fzf-vcs-mode<ret>'
|
||||
|
||||
|
@ -45,7 +46,7 @@ bzr status"
|
|||
<c-v>: open file in vertical split"
|
||||
message="Open single or multiple files from git tree.
|
||||
<ret>: open file in new buffer.
|
||||
<c-w>: open file in new window $additional_keybindings"
|
||||
<c-w>: open file in new terminal $additional_keybindings"
|
||||
printf "%s\n" "info -title %{$title} %{$message}"
|
||||
printf "%s\n" "fzf-$vcs"
|
||||
exit
|
|
@ -15,13 +15,15 @@ Default value:
|
|||
grep -RHn" \
|
||||
str fzf_sk_grep_command 'grep -RHn'
|
||||
|
||||
try %{ declare-user-mode fzf }
|
||||
|
||||
evaluate-commands %sh{
|
||||
if [ -n "$(command -v sk)" ]; then
|
||||
printf "%s\n" "map global fzf -docstring %{Interactive grep with skim} 'g' '<esc>: fzf-sk-interactive-grep<ret>'"
|
||||
printf "%s\n" "map global fzf -docstring %{Interactive grep with skim} 'g' '<esc>: fzf-sk-grep<ret>'"
|
||||
fi
|
||||
}
|
||||
|
||||
define-command -hidden fzf-sk-interactive-grep %{ evaluate-commands %sh{
|
||||
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}"
|
||||
exit
|
||||
|
@ -29,20 +31,17 @@ define-command -hidden fzf-sk-interactive-grep %{ evaluate-commands %sh{
|
|||
title="skim interactive grep"
|
||||
message="Interactively grep pattern from current directory
|
||||
<ret>: open search result in new buffer.
|
||||
<c-w>: open search result in new window"
|
||||
<c-w>: open search result in new terminal"
|
||||
[ ! -z "${kak_client_env_TMUX}" ] && tmux_keybindings="
|
||||
<c-s>: open search result in horizontal split
|
||||
<c-v>: open search result in vertical split"
|
||||
|
||||
printf "%s\n" "info -title '${title}' '${message}${tmux_keybindings}'"
|
||||
[ ! -z "${kak_client_env_TMUX}" ] && additional_flags="--expect ctrl-v --expect ctrl-s"
|
||||
impl=$kak_opt_fzf_implementation
|
||||
printf "%s\n" "set-option global fzf_implementation \"sk -i -c '$kak_opt_fzf_sk_grep_command {}'\"
|
||||
fzf %{fzf-sk-grep-handler} %{echo >/dev/null 2>&1} %{--expect ctrl-w $additional_flags}
|
||||
set-option global fzf_implementation $impl"
|
||||
printf "%s\n" "fzf -kak-cmd %{fzf-sk-grep-handler} -fzf-impl %{sk -i -c '$kak_opt_fzf_sk_grep_command {}'} -fzf-args %{--expect ctrl-w $additional_flags}"
|
||||
}}
|
||||
|
||||
define-command fzf-sk-grep-handler -params 1 %{ evaluate-commands %sh{
|
||||
define-command -hidden fzf-sk-grep-handler -params 1 %{ evaluate-commands %sh{
|
||||
printf "%s\n" "$1" | awk '{
|
||||
file = $0; sub(/:.*/, "", file); gsub("&", "&&", file);
|
||||
line = $0; sub(/[^:]+:/, "", line); sub(/:.*/, "", line)
|
Loading…
Reference in a new issue