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
|
# fzf.kak
|
||||||
|
|
||||||
[](https://github.com/andreyorst/fzf.kak/releases)
|
[![GitHub release][1]][2] [![GitHub Release Date][3]][4]
|
||||||
[](https://github.com/andreyorst/fzf.kak/releases)
|
![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
|
## Installation
|
||||||
### With [plug.kak](https://github.com/andreyorst/plug.kak) (recommended)
|
### With [plug.kak][11] (recommended)
|
||||||
Recommended way to install is to use plug.kak plugin manager.
|
Recommended way to install is to use plug.kak plugin manager. You can install
|
||||||
You can install **fzf.kak** by adding this to your `kakrc`:
|
**fzf.kak** by adding this to your `kakrc`:
|
||||||
|
|
||||||
```kak
|
```kak
|
||||||
plug "andreyorst/fzf.kak"
|
plug "andreyorst/fzf.kak"
|
||||||
```
|
```
|
||||||
|
|
||||||
Then reload Kakoune config or restart Kakoune and run `:plug-install`.
|
Then reload Kakoune config or restart Kakoune and run `:plug-install`.
|
||||||
|
Now you can proceed to the [configuration][23] section.
|
||||||
|
|
||||||
### Without plugin manager
|
### Without plugin manager
|
||||||
This plugin consists of several parts which are "modules", that provide different functions to plugin.
|
This plugin consists of several parts which are "modules", that provide
|
||||||
There's central module that must be loaded before any other module, named `fzf.kak`, so in order to properly
|
different functions to plugin. There's central module that must be loaded
|
||||||
load **fzf.kak** plugin, you need to source it in your kakrc.
|
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:
|
|
||||||
|
|
||||||
```sh
|
```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
|
This will load base `fzf` module, but It can't do anything on it's own. You can
|
||||||
keep your configuration rather simple, or load every module if you need all plugin abilities:
|
load only needed modules, to keep your configuration rather simple, or load
|
||||||
|
every module if you need all plugin abilities:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
source "~/.config/kak/plugins/fzf.kak/rc/fzf-modules/fzf-file.kak" # fzf file chooser
|
source "/path/to/fzf.kak/rc/modules/fzf-file.kak" # fzf file chooser
|
||||||
source "~/.config/kak/plugins/fzf.kak/rc/fzf-modules/fzf-buffer.kak" # switching buffers with fzf
|
source "/path/to/fzf.kak/rc/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 "/path/to/fzf.kak/rc/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 "/path/to/fzf.kak/rc/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-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,
|
The same principle is applied to handling different version control systems. You
|
||||||
called `fzf-vcs.kak` and its submodules for each VCS. There are plenty of VC systems, so modules come in handy.
|
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
|
```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
|
```sh
|
||||||
source "~/.config/kak/plugins/fzf.kak/rc/fzf-modules/VCS/fzf-bzr.kak" # GNU Bazaar support
|
source "/path/to/fzf.kak/rc/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 "/path/to/fzf.kak/rc/modules/VCS/fzf-git.kak" # Git support module
|
||||||
source "~/.config/kak/plugins/fzf.kak/rc/fzf-modules/VCS/fzf-hg.kak" # Mercurial VCS
|
source "/path/to/fzf.kak/rc/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-svn.kak" # Subversion module
|
||||||
```
|
```
|
||||||
|
|
||||||
You can see that we load less nested modules first, and then go deeper and deeper. Besides that order of
|
Order of sourcing files should not matter, but it is preferable to source main
|
||||||
files within single depth level doesn't matter. This may look complex, but it makes plugin more versatile.
|
script first, and then the modules. This may look complex, but it makes plugin
|
||||||
And plugin managers, like [plug.kak](https://github.com/andreyorst/plug.kak) for example, just does all
|
more versatile. And plugin managers, like [plug.kak][11] for example, just does
|
||||||
those steps for you.
|
all those steps for you.
|
||||||
|
|
||||||
By the way, this structure makes it easy to extend plugin with new modules,
|
By the way, this structure makes it easy to extend plugin with new modules, and
|
||||||
and you [can add modules on your own](#writing-a-module)!
|
you [can add modules on your own][20]!
|
||||||
|
|
||||||
## Usage
|
## 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.
|
There's no default key binding to invoke `fzf`, but **fzf.kak** provides a
|
||||||
You can set your own mapping to invoke `fzf-mode`:
|
`fzf-mode` command that can be mapped to preferred key. You can set your own
|
||||||
|
mapping to invoke `fzf-mode`:
|
||||||
|
|
||||||
```kak
|
```kak
|
||||||
map global normal <c-p> ': fzf-mode<ret>'
|
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.
|
Note that space between colon and command is intentional and will strip this
|
||||||
Available mappings:
|
command from command history.
|
||||||
- <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
|
|
||||||
|
|
||||||
So for example pressing <kbd>Ctrl+p</kbd><kbd>f</kbd> will open fzf at the
|
Each `fzf` module defines mnemonic mapping, like <kbd>f</kbd> for opening files,
|
||||||
bottom of the Kakoune buffer, showing you all possible files.
|
<kbd>t</kbd> for tags, <kbd>s</kbd> for search, and so on. Available mappings:
|
||||||
|
|
||||||
### Settings
|
- <kbd>b</kbd> - Select buffer.
|
||||||
**fzf.kak** features a lot of settings via options that can be altered to change how **fzf.kak** behaves.
|
- <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
|
So for example pressing <kbd>Ctrl</kbd>+<kbd>p</kbd> <kbd>f</kbd> will open
|
||||||
When using inside tmux, fzf will use bottom split. Height of this split can be changed with `fzf_tmux_height` option.
|
`fzf` window, showing you all files from current directory recursively.
|
||||||
`fzf_tmux_height_file_preview` option is used to control height of the split when you do file searching with file-preview turned on.
|
|
||||||
|
|
||||||
#### 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.
|
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
|
```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
|
```kak
|
||||||
set-option global fzf_file_command "find . \( -path '*/.svn*' -o -path '*/.git*' \) -prune -o -type f -print"
|
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
|
### Preview
|
||||||
This script supports these version control systems: Git, Subversion, GNU Bazaar, Mercurial.
|
**fzf.kak** tries to automatically detect where to show preview window,
|
||||||
By default <kbd>v</kbd> mapping from `fzf mode` will detect your version control system and open fzf for you.
|
depending on aspect ratio of new terminal window. By default if the doubled
|
||||||
If you wish to explicitly use some particular vcs command, you can use `V` mapping, which includes
|
height is bigger than the width, preview occupies upper 60% of space. If height
|
||||||
all supported vcs shortcuts.
|
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_git_command`
|
||||||
* `fzf_svn_command`
|
* `fzf_svn_command`
|
||||||
* `fzf_bzr_command`
|
* `fzf_bzr_command`
|
||||||
* `fzf_hg_command`
|
* `fzf_hg_command`
|
||||||
|
|
||||||
Other VCS are not supported officially. Open a feature request if you want some unsupported VCS to be included.
|
Other VCS are not supported officially. Open a feature request if you want some
|
||||||
You also can change one of options to contain your VCS command, and use this command explicitly from VCS sub-mode.
|
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
|
### Tmux
|
||||||
It is also possible to add parameters to ctags search executable. like `sort -u` and others:
|
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
|
## `fzf` command
|
||||||
set-option global fzf_tag_command 'readtags -l | cut -f1 | sort -u | ... '
|
`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.
|
- `-kak-cmd`: A Kakoune command that is applied to `fzf` resulting value, e.g.
|
||||||
|
`edit -existing`, `change-directory`, e.t.c.
|
||||||
##### Filtering tags
|
- `-items-cmd`: A command that is used as a pipe to provide list of values to
|
||||||
Since ctags supports showing particular kind of tag for many languages,
|
`fzf`. For example, if we want to pass list of all files recursively in
|
||||||
`fzf-tag` dinamicly defines mappings for those languages with <kbd>Alt</kbd> key based on current filetype.
|
current directory, we would use `-items-cmd %{find .}` which will be piped to
|
||||||
For example to show only functions while `fzf-tag` is active press <kbd>Alt</kbd>+<kbd>f</kbd>.
|
`fzf` tool.
|
||||||
It will reload fzf window and only function tags will be listed.
|
- `-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
|
||||||
#### Preview
|
example.
|
||||||
When using X11 **fzf.kak** automatically tries to detect where to show preview window, depending
|
- `-fzf-args`: Additional flags for `fzf` program.
|
||||||
on aspect ratio of new termial window. By default if the height is bigger than the width, preview occupies
|
- `-preview-cmd`: A preview command. Can be used to override default preview
|
||||||
upper 60% of space. If height is smaller than the width, preview is shown at the right side.
|
handling.
|
||||||
|
- `-preview`: If specified, command will ask for preview.
|
||||||
You can configure the amount of space for preview window with these options: `fzf_preview_height` and `fzf_preview_width`.
|
- `-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
|
||||||
When **fzf.kak** is used in tmux, it will show preview on the right side. Heigth of preview split can be adjusted with
|
are interested only in the first field which is `3`, we can use `-filter %{cut
|
||||||
`fzf_tmux_height_file_preview`
|
-f 1}`. Basically everything what `fzf` returns is piped to this filter
|
||||||
|
command. See [fzf-search.kak][22] as example.
|
||||||
Amount of lines in preview window can be changed with `fzf_preview_lines` option.
|
- `-post-action`: Extra commands that are preformed after `-kak-cmd` command.
|
||||||
|
|
||||||
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
|
|
||||||
```
|
|
||||||
|
|
||||||
## Contributing
|
## Contributing
|
||||||
|
If you want to contribute to **fzf.kak** by adding a module, you can submit one
|
||||||
If you want to contribute to **fzf.kak** by adding a module, you can submit one by providing a pull request,
|
by providing a pull request, or just open a feature request and we'll see what
|
||||||
or just open a feature request and we'll see what can be done.
|
can be done.
|
||||||
|
|
||||||
### Writing a module
|
### Writing a module
|
||||||
|
You can write a module for **fzf.kak**. To create one, simply define a function
|
||||||
You can write a module for **fzf.kak**. To create one, simply define a function in separate file, located
|
in separate file, located in `rc/modules/`, and named after the
|
||||||
in `rc/fzf-modules/`, and named after the function. **fzf.kak** provides a general purpose command, that can be called with some
|
function. **fzf.kak** provides a general purpose command, that can be called
|
||||||
Kakoune command as first parameter, and command that provides list of items for fzf as a second parameter. Third optional parameter is
|
with some Kakoune command as first parameter, and command that provides list of
|
||||||
for defining extra arguments for fzf itself, like additional keybindings.
|
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:
|
Overall module structure is:
|
||||||
* Define a `fzf-command` command
|
* 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.
|
* 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,
|
Of course modules can and will be more complex, since a good module checks if
|
||||||
and supports various settings inside it. Feel free to look how existing modules are made.
|
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
|
||||||
|
|
262
rc/fzf.kak
262
rc/fzf.kak
|
@ -8,7 +8,7 @@
|
||||||
# │ different fzf commands. │
|
# │ 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
|
# Options
|
||||||
declare-option -docstring 'implementation of fzf that you want to use.
|
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 {}"
|
highlight: "highlight --failsafe -O ansi {}"
|
||||||
rouge: "rougify {}"
|
rouge: "rougify {}"
|
||||||
' \
|
' \
|
||||||
str fzf_highlighter "highlight"
|
str fzf_highlight_cmd "highlight"
|
||||||
|
|
||||||
declare-option -docstring "height of fzf tmux split in screen lines or percents.
|
declare-option -docstring "height of fzf tmux split in screen lines or percents.
|
||||||
Default value: 25%%" \
|
Default value: 25%%" \
|
||||||
|
@ -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.
|
declare-option -docstring "height of fzf tmux split for file preview in screen lines or percents.
|
||||||
Default value: 70%%" \
|
Default value: 70%%" \
|
||||||
str fzf_tmux_height_file_preview '70%'
|
str fzf_preview_tmux_height '70%'
|
||||||
|
|
||||||
declare-option -docstring "width of preview window.
|
declare-option -docstring "width of preview window.
|
||||||
Default value: 50%%" \
|
Default value: 50%%" \
|
||||||
|
@ -69,155 +69,141 @@ Best used with mapping like:
|
||||||
" \
|
" \
|
||||||
fzf-mode %{ try %{ evaluate-commands 'enter-user-mode fzf' } }
|
fzf-mode %{ try %{ evaluate-commands 'enter-user-mode fzf' } }
|
||||||
|
|
||||||
define-command -hidden fzf-vertical -params .. %{
|
define-command -hidden -docstring "wrapper command to create new vertical split" \
|
||||||
try %{
|
fzf-vertical -params .. %{ try %{
|
||||||
tmux-terminal-vertical kak -c %val{session} -e "%arg{@}"
|
tmux-terminal-vertical kak -c %val{session} -e "%arg{@}"
|
||||||
} catch %{
|
} catch %{
|
||||||
tmux-new-vertical "%arg{@}"
|
tmux-new-vertical "%arg{@}"
|
||||||
}
|
}}
|
||||||
}
|
|
||||||
|
|
||||||
define-command -hidden fzf-horizontal -params .. %{
|
define-command -hidden -docstring "wrapper command to create new horizontal split" \
|
||||||
try %{
|
fzf-horizontal -params .. %{ try %{
|
||||||
tmux-terminal-horizontal kak -c %val{session} -e "%arg{@}"
|
tmux-terminal-horizontal kak -c %val{session} -e "%arg{@}"
|
||||||
} catch %{
|
} catch %{
|
||||||
tmux-new-horizontal "%arg{@}"
|
tmux-new-horizontal "%arg{@}"
|
||||||
}
|
}}
|
||||||
}
|
|
||||||
|
|
||||||
define-command -hidden 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{@}"'
|
|
||||||
fi
|
|
||||||
} catch %sh{
|
|
||||||
if [ -n "$kak_client_env_TMUX" ]; then
|
|
||||||
printf "%s\n" 'tmux-new-window "%arg{@}"'
|
|
||||||
else
|
|
||||||
printf "%s\n" 'x11-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:
|
|
||||||
|
|
||||||
<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.
|
|
||||||
|
|
||||||
<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.
|
|
||||||
|
|
||||||
<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
|
|
||||||
|
|
||||||
|
define-command -hidden -docstring "wrapper command to create new terminal" \
|
||||||
|
fzf-window -params .. %{ try %sh{
|
||||||
if [ -n "$kak_client_env_TMUX" ]; then
|
if [ -n "$kak_client_env_TMUX" ]; then
|
||||||
preview_pos="pos=right:$kak_opt_fzf_preview_width;"
|
printf "%s\n" 'tmux-terminal-window kak -c %val{session} -e "%arg{@}"'
|
||||||
else
|
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;"
|
printf "%s\n" 'terminal kak -c %val{session} -e "%arg{@}"'
|
||||||
|
fi
|
||||||
|
} catch %sh{
|
||||||
|
if [ -n "$kak_client_env_TMUX" ]; then
|
||||||
|
printf "%s\n" 'tmux-new-window "%arg{@}"'
|
||||||
|
else
|
||||||
|
printf "%s\n" 'new "%arg{@}"'
|
||||||
|
fi
|
||||||
|
}}
|
||||||
|
|
||||||
|
define-command -docstring \
|
||||||
|
"fzf <switches>: generic fzf command. This command can be used to create new fzf wrappers for various Kakoune or external features.
|
||||||
|
|
||||||
|
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}"
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
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
|
||||||
|
# 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
|
fi
|
||||||
|
|
||||||
tmp=$(mktemp ${TMPDIR:-/tmp}/kak-fzf-tmp.XXXXXX)
|
fzf_tmp=$(mktemp -d ${TMPDIR:-/tmp}/fzf.kak.XXXXXX)
|
||||||
fzfcmd=$(mktemp ${TMPDIR:-/tmp}/kak-fzfcmd.XXXXXX)
|
fzfcmd="${fzf_tmp}/fzfcmd"
|
||||||
printf "%s\n" "cd \"$PWD\" && $preview_pos $items_command | SHELL=$(command -v sh) $kak_opt_fzf_implementation $additional_flags > $tmp; rm $fzfcmd" > $fzfcmd
|
result="${fzf_tmp}/result"
|
||||||
chmod 755 $fzfcmd
|
|
||||||
|
|
||||||
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"
|
[ -n "${tmux_height%%*%}" ] && measure="-l" || measure="-p"
|
||||||
cmd="command tmux split-window $measure ${tmux_height%%%*} 'sh -c $fzfcmd'"
|
# `terminal' doesn't support any kind of width and height parameters, so tmux panes are created by tmux itself
|
||||||
elif [ -n "$kak_opt_termcmd" ]; then
|
cmd="nop %sh{ command tmux split-window ${measure} ${tmux_height%%%*} '${fzfcmd}' }"
|
||||||
cmd="$kak_opt_termcmd 'sh -c $fzfcmd'"
|
|
||||||
else
|
else
|
||||||
printf "%s\n" "fail %{termcmd option is not set}"
|
cmd="terminal %{${fzfcmd}}"
|
||||||
rm $fzfcmd
|
|
||||||
rm $tmp
|
|
||||||
exit
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
(
|
printf "%s\n" "${cmd}"
|
||||||
eval "$cmd"
|
|
||||||
while [ -e $fzfcmd ]; do
|
# main loop
|
||||||
sleep 0.1
|
( while [ -e ${fzfcmd} ]; do sleep 0.1; done
|
||||||
done
|
if [ -s ${result} ]; then
|
||||||
if [ -s $tmp ]; then
|
|
||||||
(
|
(
|
||||||
read action
|
while read line; do
|
||||||
case $action in
|
case ${line} in
|
||||||
ctrl-w)
|
ctrl-w) wincmd="fzf-window" ;;
|
||||||
wincmd="fzf-window" ;;
|
ctrl-s) wincmd="fzf-vertical" ;;
|
||||||
ctrl-s)
|
ctrl-v) wincmd="fzf-horizontal" ;;
|
||||||
wincmd="fzf-vertical" ;;
|
*) item=${line} ;;
|
||||||
ctrl-v)
|
esac
|
||||||
wincmd="fzf-horizontal" ;;
|
if [ -n "${item}" ]; then
|
||||||
*)
|
printf "%s\n" "evaluate-commands -client ${kak_client} ${wincmd} %{${kakoune_cmd} %{${item}}}"
|
||||||
if [ -n "$action" ]; then
|
fi
|
||||||
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 ;;
|
|
||||||
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
|
done
|
||||||
) < $tmp
|
if [ -n "${post_action}" ]; then
|
||||||
|
printf "%s\n" "evaluate-commands -client ${kak_client} %{${post_action}}"
|
||||||
|
fi
|
||||||
|
) < ${result} | kak -p ${kak_session}
|
||||||
fi
|
fi
|
||||||
rm $tmp
|
rm -rf ${fzf_tmp}
|
||||||
) > /dev/null 2>&1 < /dev/null &
|
) > /dev/null 2>&1 < /dev/null &
|
||||||
}}
|
}}
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,7 @@ Default arguments:
|
||||||
" \
|
" \
|
||||||
str fzf_bzr_command "bzr"
|
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>'
|
map global fzf-vcs -docstring "edit file from GNU Bazaar tree" 'b' '<esc>: fzf-bzr<ret>'
|
||||||
|
|
||||||
define-command -hidden fzf-bzr %{ evaluate-commands %sh{
|
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 ;;
|
cmd=$kak_opt_fzf_bzr_command ;;
|
||||||
esac
|
esac
|
||||||
[ ! -z "${kak_client_env_TMUX}" ] && additional_flags="--expect ctrl-v --expect ctrl-s"
|
[ ! -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"
|
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>'
|
map global fzf-vcs -docstring "edit file from Git tree" 'g' '<esc>: fzf-git<ret>'
|
||||||
|
|
||||||
define-command -override -hidden fzf-git %{ evaluate-commands %sh{
|
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 ;;
|
cmd=$kak_opt_fzf_git_command ;;
|
||||||
esac
|
esac
|
||||||
[ ! -z "${kak_client_env_TMUX}" ] && additional_flags="--expect ctrl-v --expect ctrl-s"
|
[ ! -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"
|
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>'
|
map global fzf-vcs -docstring "edit file from mercurial tree" 'h' '<esc>: fzf-hg<ret>'
|
||||||
|
|
||||||
define-command -hidden fzf-hg %{ evaluate-commands %sh{
|
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 ;;
|
cmd=$kak_opt_fzf_hg_command ;;
|
||||||
esac
|
esac
|
||||||
[ ! -z "${kak_client_env_TMUX}" ] && additional_flags="--expect ctrl-v --expect ctrl-s"
|
[ ! -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"
|
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>'
|
map global fzf-vcs -docstring "edit file from Subversion tree" 's' '<esc>: fzf-svn<ret>'
|
||||||
|
|
||||||
define-command -hidden fzf-svn %{ evaluate-commands %sh{
|
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 ;;
|
cmd=$kak_opt_fzf_svn_command ;;
|
||||||
esac
|
esac
|
||||||
[ ! -z "${kak_client_env_TMUX}" ] && additional_flags="--expect ctrl-v --expect ctrl-s"
|
[ ! -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 │
|
# │ GitHub.com/andreyorst/fzf.kak │
|
||||||
# ╰──────────────────────────────────────╯
|
# ╰──────────────────────────────────────╯
|
||||||
|
|
||||||
|
try %{ declare-user-mode fzf }
|
||||||
map global fzf -docstring "open buffer" 'b' '<esc>: fzf-buffer<ret>'
|
map global fzf -docstring "open buffer" 'b' '<esc>: fzf-buffer<ret>'
|
||||||
|
|
||||||
define-command -hidden fzf-buffer %{ evaluate-commands %sh{
|
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'"
|
printf "%s\n" "info -title 'fzf buffer' '$message$tmux_keybindings'"
|
||||||
[ ! -z "${kak_client_env_TMUX}" ] && additional_flags="--expect ctrl-v --expect ctrl-s"
|
[ ! -z "${kak_client_env_TMUX}" ] && additional_flags="--expect 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' \
|
declare-option -docstring 'maximum amount of previewed directories' \
|
||||||
int fzf_preview_dirs '300'
|
int fzf_preview_dirs '300'
|
||||||
|
|
||||||
|
try %{ declare-user-mode fzf }
|
||||||
map global fzf -docstring "change directory" 'c' '<esc>: fzf-cd<ret>'
|
map global fzf -docstring "change directory" 'c' '<esc>: fzf-cd<ret>'
|
||||||
|
|
||||||
define-command -hidden fzf-cd %{ evaluate-commands %sh{
|
define-command -hidden fzf-cd %{ evaluate-commands %sh{
|
||||||
tmux_height=$kak_opt_fzf_tmux_height
|
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
|
case $kak_opt_fzf_cd_command in
|
||||||
find)
|
find)
|
||||||
|
@ -41,9 +43,10 @@ define-command -hidden fzf-cd %{ evaluate-commands %sh{
|
||||||
*)
|
*)
|
||||||
items_command=$kak_opt_fzf_cd_command ;;
|
items_command=$kak_opt_fzf_cd_command ;;
|
||||||
esac
|
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'"
|
preview="--preview '($kak_opt_cd_preview_cmd) 2>/dev/null | head -n $kak_opt_fzf_preview_dirs'"
|
||||||
fi
|
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" \
|
Default value: tags" \
|
||||||
str fzf_tag_file_name "tags"
|
str fzf_tag_file_name "tags"
|
||||||
|
|
||||||
|
try %{ declare-user-mode fzf }
|
||||||
map global fzf -docstring "find tag" 't' '<esc>: fzf-tag<ret>'
|
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
|
# 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
|
message="Jump to a symbol''s definition
|
||||||
<ret>: open tag in new buffer
|
<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="
|
[ -n "${kak_client_env_TMUX}" ] && tmux_keybindings="
|
||||||
<c-s>: open tag in horizontal split
|
<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"
|
[ ! -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" "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"
|
str fzf_file_command "find"
|
||||||
|
|
||||||
|
try %{ declare-user-mode fzf }
|
||||||
map global fzf -docstring "open file" 'f' '<esc>: fzf-file<ret>'
|
map global fzf -docstring "open file" 'f' '<esc>: fzf-file<ret>'
|
||||||
|
|
||||||
define-command -hidden fzf-file %{ evaluate-commands %sh{
|
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.
|
message="Open single or multiple files.
|
||||||
<ret>: open file in new buffer.
|
<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="
|
[ ! -z "${kak_client_env_TMUX}" ] && tmux_keybindings="
|
||||||
<c-s>: open file in horizontal split
|
<c-s>: open file in horizontal split
|
||||||
<c-v>: open file in vertical split"
|
<c-v>: open file in vertical split"
|
||||||
|
|
||||||
printf "%s\n" "info -title 'fzf file' '$message$tmux_keybindings'"
|
printf "%s\n" "info -title 'fzf file' '$message$tmux_keybindings'"
|
||||||
[ ! -z "${kak_client_env_TMUX}" ] && additional_flags="--expect ctrl-v --expect ctrl-s"
|
[ ! -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 │
|
# │ GitHub.com/andreyorst/fzf.kak │
|
||||||
# ╰──────────────────────────────────────╯
|
# ╰──────────────────────────────────────╯
|
||||||
|
|
||||||
|
try %{ declare-user-mode fzf }
|
||||||
map global fzf -docstring "search in buffer" 's' '<esc>: fzf-buffer-search<ret>'
|
map global fzf -docstring "search in buffer" 's' '<esc>: fzf-buffer-search<ret>'
|
||||||
|
|
||||||
define-command -hidden fzf-buffer-search %{ evaluate-commands %sh{
|
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'"
|
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 %{%<a-|>cat<space>><space>$buffer_content<ret>;}"
|
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-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 "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>'
|
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"
|
<c-v>: open file in vertical split"
|
||||||
message="Open single or multiple files from git tree.
|
message="Open single or multiple files from git tree.
|
||||||
<ret>: open file in new buffer.
|
<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" "info -title %{$title} %{$message}"
|
||||||
printf "%s\n" "fzf-$vcs"
|
printf "%s\n" "fzf-$vcs"
|
||||||
exit
|
exit
|
|
@ -15,13 +15,15 @@ Default value:
|
||||||
grep -RHn" \
|
grep -RHn" \
|
||||||
str fzf_sk_grep_command 'grep -RHn'
|
str fzf_sk_grep_command 'grep -RHn'
|
||||||
|
|
||||||
|
try %{ declare-user-mode fzf }
|
||||||
|
|
||||||
evaluate-commands %sh{
|
evaluate-commands %sh{
|
||||||
if [ -n "$(command -v sk)" ]; then
|
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
|
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
|
if [ -z "$(command -v sk)" ]; then
|
||||||
printf "%s\n" "echo -markup %{{Information}skim required to run this command}"
|
printf "%s\n" "echo -markup %{{Information}skim required to run this command}"
|
||||||
exit
|
exit
|
||||||
|
@ -29,20 +31,17 @@ define-command -hidden fzf-sk-interactive-grep %{ evaluate-commands %sh{
|
||||||
title="skim interactive grep"
|
title="skim interactive grep"
|
||||||
message="Interactively grep pattern from current directory
|
message="Interactively grep pattern from current directory
|
||||||
<ret>: open search result in new buffer.
|
<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="
|
[ ! -z "${kak_client_env_TMUX}" ] && tmux_keybindings="
|
||||||
<c-s>: open search result in horizontal split
|
<c-s>: open search result in horizontal split
|
||||||
<c-v>: open search result in vertical split"
|
<c-v>: open search result in vertical split"
|
||||||
|
|
||||||
printf "%s\n" "info -title '${title}' '${message}${tmux_keybindings}'"
|
printf "%s\n" "info -title '${title}' '${message}${tmux_keybindings}'"
|
||||||
[ ! -z "${kak_client_env_TMUX}" ] && additional_flags="--expect ctrl-v --expect ctrl-s"
|
[ ! -z "${kak_client_env_TMUX}" ] && additional_flags="--expect ctrl-v --expect ctrl-s"
|
||||||
impl=$kak_opt_fzf_implementation
|
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}"
|
||||||
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"
|
|
||||||
}}
|
}}
|
||||||
|
|
||||||
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 '{
|
printf "%s\n" "$1" | awk '{
|
||||||
file = $0; sub(/:.*/, "", file); gsub("&", "&&", file);
|
file = $0; sub(/:.*/, "", file); gsub("&", "&&", file);
|
||||||
line = $0; sub(/[^:]+:/, "", line); sub(/:.*/, "", line)
|
line = $0; sub(/[^:]+:/, "", line); sub(/:.*/, "", line)
|
Loading…
Reference in a new issue