1
0
Fork 0

Compare commits

...

96 commits

Author SHA1 Message Date
Cat /dev/Nulo 62a3de575c Use separate terminal commands for the FZF window and for opening new windows 2022-02-03 13:42:28 -03:00
Sidharth Kshatriya 010e395041 Fix the open files in directory of current file feature
Since we cd-ed into search dir in $cmd, prefix the $search_dir path
after fzf returns the results by using -filter switch of fzf.
Kakoune either needs an absolute path or path relative to its pwd
to edit a file. Since the pwd of $cmd and kakoune now differ,
we cannot use a relative path, so we construct the absolute path
by prefixing the $search_dir to the file outputted by fzf.
2022-01-25 15:07:46 +03:00
Sidharth Kshatriya 16e001c3a2 Improve comment 2022-01-19 16:15:15 +03:00
Sidharth Kshatriya e91b76c517 Feature to allow users to open a file in the same directory as the current file
Let say you have a file open in a kakoune buffer and you are currently interested
in opening another file _only_ in the _same_ directory as the current file.
You could do this with the usual `<fzf-mode> f` but that will
list many files you are not interested in.

Add functionality and shortcut `<fzf-mode> F` that will list the files
only in the directory of the currently displayed file. This is useful
when your kakoune current directory is different from the directory
of the currently displayed file.

E.g. if you have /home/abc/xzy/lmn/hello.cpp open in kakoune and your current
directory in kakoune is /home/abc/xyz then `<fzf-mode> F` will list all files in
/home/abc/xyz/lmn as candidates for opening.
2022-01-18 19:38:04 +03:00
Andrey Listopadov d98b16680c
fix typos and spelling errors 2022-01-08 10:55:23 +03:00
Andrey Listopadov 66bc692ab3
fix: more clear explanation of default grep command 2022-01-08 10:39:49 +03:00
Andrey Listopadov 68f21eb786
fix: wrong link to kakoune.cr 2021-09-11 14:34:40 +03:00
Andrey Listopadov 444a3449d4
fix: add alternative plugins 2021-09-11 14:33:51 +03:00
Andrey Listopadov 124c3a2751
fix #91 2021-06-23 22:31:12 +03:00
Andrey Listopadov 1b3a3beebb
Merge pull request #88 from andreyorst/develop
Develop
2021-04-03 13:07:45 +03:00
Andrey Listopadov bfe1bc0a3d fix #87 2021-04-03 13:02:39 +03:00
Andrey Listopadov 3f2773c919 use default mappings when unset 2021-03-21 13:33:27 +03:00
Andrey Listopadov a8765bb03d fix some shellcheck warnings 2021-03-20 22:44:19 +03:00
Andrey Listopadov 435cc240f3 markdown doesn't like one-line tables 2021-03-19 22:52:08 +03:00
Andrey Listopadov aed44987a3 rewrite readme a bit 2021-03-19 22:52:08 +03:00
Andrey Listopadov 3d70299722 convert to one sentence per line style 2021-03-19 22:52:08 +03:00
Andrey Listopadov 39ec448e5a refactor modules to provide submodules 2021-03-19 22:52:08 +03:00
Andrey Listopadov d912a6ecf1 markdown doesn't like one-line tables 2021-03-19 22:48:55 +03:00
Andrey Listopadov 9ee5e4fea8 rewrite readme a bit 2021-03-19 22:38:01 +03:00
Andrey Listopadov 1a405fcc43 convert to one sentence per line style 2021-03-19 21:36:37 +03:00
Andrey Listopadov a8436627c3 refactor modules to provide submodules 2021-03-19 21:00:49 +03:00
Zeming Lin 4e6c9a8575 fix fzf_use_main_selection on multi-line
If your `kak_selection` has multiple lines and `fzf_use_main_selection` is true, then the preview window would not even show up. This fixes that error.
2021-03-15 22:35:06 +03:00
Andrey Listopadov 94b259cbd8 ignore path in project select menu 2021-03-14 15:23:10 +03:00
purxiz 2ff1246599 ignore filenames grep
This commit makes it so that fzf ignores the filenames and line numbers in the recursive grep module. I really couldn't find a nicer place to add these fzf-args, but I'm very open to fixing this PR with feedback from whoever. Basically fzf requires all grep tools to return filename:line_number:text, so we can ignore filename and line number with a column delimiter and then only looking from column 3 onward.
2021-03-13 18:15:34 +03:00
Andrey Listopadov ce97b7efa9 check if project name was empty 2021-02-26 18:40:07 +03:00
Andrey Listopadov cce440353e
remove maintainance warning! 2021-02-24 21:17:50 +03:00
Andrey Orst e10de405e2
update maintenance note 2021-01-27 23:34:59 +03:00
Joshua Trees c6ee9b3c11 Support colors with interactive sk grep
This can be combined with something like this to get color highlighting of matches:

```
set-option global fzf_sk_grep_command 'rg --color=always'
```
2021-01-27 23:30:59 +03:00
Andrey Orst f23daa698a
Add maintaninace warning 2020-07-26 11:04:00 +03:00
Andrey Orst b2aeb26473 fix #77 2020-05-24 12:46:52 +03:00
Andrey Orst 766fd11dad fix #80 2020-05-07 15:38:16 +03:00
Andrey Orst cfbcfbb796 add option to disable selection use, and document it 2020-04-07 17:48:23 +03:00
Andrey Orst 355f05d832 fix definition of filters, check for readtagscmd 2020-03-19 09:13:53 +03:00
Andrey Orst 302045491c Merge branch 'check-readtags' into 'master'
fzf-ctags: Check for readtags command

See merge request andreyorst/fzf.kak!76
2020-03-19 05:18:57 +00:00
robem c71e5aaab2 Use grep as a fallback for readtags
The `grep` query is more loose than `readtags` when a tag is given.
2020-03-18 16:21:33 -07:00
robem 5cf11c44fe fzf-ctags: Check for readtags command
Not every universal ctags package out there comes with the `readtags` command.
Therefore, it was a bit tedious to figure out why fzf-ctags didn't work. With
this change fzf-ctags will abort if readtags doesn't exist.
2020-03-17 18:12:42 -07:00
Andrey Orst dc6d0a504e use selection as default search query 2020-03-13 19:01:19 +03:00
Andrey Orst e862cb5b78 Improve latency when creating tmux windows #77 2020-03-06 13:04:19 +03:00
Andrey Orst f697b7d11e Update PULL_REQUEST_TEMPLATE.md 2020-03-06 07:54:05 +00:00
Andrey Orst 8a8414fb57 fix #75 2019-12-19 12:03:23 +03:00
Andrey Orst 2d3340ec55 Merge branch 'master' of https://gitlab.com/andreyorst/fzf.kak 2019-12-19 11:44:44 +03:00
Andrey Orst ec506b5b9b partly fix #75 2019-12-19 11:44:05 +03:00
Andrey Orst b536296251 fix docstring, thanks to https://github.com/geppettodivacin for pointing out! 2019-12-19 07:33:10 +00:00
Andrey Orst 16a083cb69 fix messages 2019-12-17 14:29:59 +03:00
Andrey Orst 820e700389 Merge branch 'patch-1' into 'master'
Update fzf-yank-ring.kak - Fix quoting for strings like `hello 'test' world`

See merge request andreyorst/fzf.kak!75
2019-12-06 19:07:11 +00:00
Lynn c54e0d7030 Update fzf-yank-ring.kak - Fix quoting for strings like hello 'test' world 2019-12-06 16:51:15 +00:00
Andrey Orst 68d7717295
Update fzf-grep.kak 2019-11-13 15:00:51 +03:00
Andrey Orst b48b4e34a4 add grep command inspired by https://discuss.kakoune.com/t/how-to-search-for-text-in-all-files-in-a-directory/785 2019-11-13 14:58:55 +03:00
Andrey Orst c6e894a033
Merge pull request #74 from krobelus/split-window-in-client-pane
create fzf split-window in the calling client's pane
2019-10-09 12:53:05 +03:00
Johannes Altmanninger f1b9f9c301 create fzf split-window in the calling client's pane
fix #73
2019-10-09 10:39:06 +02:00
Andrey Orst 5d7267d0db allow configuring preview for file search, and move variables to module 2019-10-04 16:24:44 +03:00
Andrey Orst 6d1fd2c645 fix #72 2019-10-04 15:50:51 +03:00
Andrey Orst 9a10a6b64a
Merge pull request #69 from gbrlsnchs/gbrlsnchs-patch-1
fzf-vcs: fix typo in command docstring
2019-09-23 12:19:24 +01:00
Gabriel Sanches 59f28b903a
fzf-vcs: fix typo in command docstring 2019-09-22 19:58:25 -03:00
Andrey Orst b257db0bf8 fix #66 2019-09-09 18:20:42 +03:00
Andrey Orst 2494c9c8b5 fix #66 2019-09-09 17:59:38 +03:00
Andrey Orst 0319d8769c add fzf-delete-buffer 2019-09-09 17:02:02 +03:00
Andrey Orst ed81b70619
Merge pull request #67 from Bownairo/tags
Pass custom file to readtags
2019-09-04 08:10:28 +03:00
Bownairo ef7902395e Pass custom file to readtags
When fzf_tag_file_name is passed, it needs to be passed to readtags,
too.
2019-09-02 20:55:34 -07:00
Andrey Orst ede90d3e02
Merge pull request #64 from andreyorst/v1.1.0-dev
V1.1.0 dev
2019-07-17 08:55:21 +03:00
Andrey Orst c5d8ca65a1 use 'command' instead of 'cmd' #63 2019-07-17 08:53:36 +03:00
Andrey Orst 7fef4973e6 formatting & cleanup 2019-07-07 11:27:37 +03:00
Andrey Orst 1de1082a45 document new feature for configuring terminal command #63 2019-07-07 11:16:49 +03:00
Andrey Orst 9eb8dc2509 allow configuring what command to use for opening windows when not using tmux 2019-07-07 11:10:16 +03:00
Andrey Orst d9e702250e fix mistake 2019-07-02 11:45:49 +03:00
Andrey Orst 9180b69217
Merge pull request #62 from ficoos/module_loaded
Change ModuleLoad to ModuleLoaded as per kakoune change
2019-06-30 14:33:49 +03:00
Saggi Mizrahi e14a0c3e84 Change ModuleLoad to ModuleLoaded as per kakoune change
This was change in:
eae92c9ae3
2019-06-30 12:45:43 +03:00
Andrey Orst 4243c4b9e9 use new quoted syntax 2019-06-28 15:27:50 +03:00
Andrey Orst 2d2d4b47ad fix escaping of & 2019-06-26 16:41:36 +03:00
Andrey Orst 1143b5b164 fix #61 2019-06-09 20:45:14 +03:00
Andrey Orst f9b476ed62
fix typo (#59) 2019-05-27 08:45:00 +03:00
Andrey Orst f75e48a40e move all variables to respective modules 2019-05-20 13:35:10 +03:00
Andrey Orst 8382d908d0 make keys mapable. Fix #58 2019-05-13 21:34:46 +03:00
Andrey Orst fcb86e9bed use provides requires 2019-05-09 18:12:06 +03:00
Andrey Orst b924eaaade fix #56 2019-04-28 14:24:29 +03:00
Andrey Orst ba9dc4298a
Merge pull request #55 from losnappas/patch-1
Send errors away
2019-04-08 17:27:21 +03:00
Andrey Orst bd3de3a3ad #53 add preview of yank-ring item 2019-04-08 16:29:42 +03:00
losnappas 5b2e9751ac
Update fzf-file.kak 2019-04-08 13:13:40 +00:00
losnappas efdf1231ca
Send errors away
Find worked wihtout this, `rg` keeps throwing errors about file operation not permitted when it goes searching into the Trash folder...
2019-04-08 13:11:26 +00:00
Andrey Orst 5b2b21b8d3 formatting 2019-04-08 11:31:50 +03:00
Andrey Orst c604547c09 simplify fzf-yank-ring 2019-04-08 11:28:11 +03:00
Andrey Orst 78b1314fa9
Merge pull request #54 from andreyorst/fix-yank-ring
Fix yank ring
2019-04-08 11:25:54 +03:00
Andrey Orst bae554f28e fix yank ring 2019-04-08 11:24:07 +03:00
Andrey Orst 58e065669f remove surrounding quotes 2019-04-08 09:08:56 +03:00
Andrey Orst 8dab12526d add yank-ring #53 2019-04-07 23:44:46 +03:00
Andrey Orst 1812d7b9de add -force switch #52 2019-04-07 19:11:02 +03:00
Andrey Orst ecde71af36 add a function to add paths without interactive dialogs 2019-04-07 19:02:42 +03:00
Andrey Orst 384571cf3a allow renaming projects, show default name as basename of current dir for new projects 2019-04-06 21:02:24 +03:00
Andrey Orst 1bf4f86a43 add reverse flag 2019-04-06 16:32:00 +03:00
Andrey Orst cd14282e5e add ability to convert $HOME to ~/ when saving and updating projects 2019-04-06 14:10:36 +03:00
Andrey Orst a702041479 typo 2019-04-01 08:42:06 +03:00
Andrey Orst be72a973ce
Merge pull request #51 from BurNiinTRee/fix-readme
Fix README.md
2019-03-31 16:46:25 +03:00
Lars Mühmel 1e6c8eb9c7
Fix README.md
The option to change the preview highlighter is called `fzf_highlight_cmd`, not `fzf_highlighter`
2019-03-31 13:32:34 +02:00
Andrey Orst c58323ddb3
Merge pull request #50 from andreyorst/fix-fish
Fix fish
2019-03-31 13:17:12 +03:00
Andrey Orst 4b1f1fcdf9 set SHELL 2019-03-31 12:57:39 +03:00
Andrey Orst d2a9bdabfc use shebang instead of exporting shell 2019-03-31 09:47:36 +03:00
16 changed files with 1619 additions and 1270 deletions

View file

@ -1,6 +1 @@
**Breaking change**: yes/no
<!-- Please provide meaningful description about your contribution -->
**Description**:
<!-- note that code will be reviewed and changes much likely will be requested -->
**NOTE**: This repository is not actively maintened. If you want to become a maintainer please contact github.com/andreyorst

342
README.md
View file

@ -3,87 +3,57 @@
[![GitHub release][1]][2] [![GitHub Release Date][3]][4]
![Github commits (since latest release)][5] ![license][6]
**fzf.kak** is a plugin for [Kakoune][7] editor, that brings integration with
[fzf][8] tool. This plugin is being tested against Kakoune 2018.09.04.
**fzf.kak** also supports [skim][9], which can be used via `fzf_implementation`
option.
fzf.kak is a plugin for [Kakoune][7] editor, that provides integration with the [fzf][8] tool.
There's also limited support for [skim][9], which can be enabled by changing the `fzf_implementation` option.
![showcase][10]
## Installation
### With [plug.kak][11] (recommended)
Recommended way to install is to use plug.kak plugin manager. You can install
**fzf.kak** by adding this to your `kakrc`:
```kak
## Installation
### With [plug.kak][11]
The recommended way to install fzf.kak is to use a plug.kak plugin manager.
To install fzf.kak add this to the `kakrc`:
``` kak
plug "andreyorst/fzf.kak"
```
Then reload Kakoune config or restart Kakoune and run `:plug-install`.
Now you can proceed to the [configuration][23] section.
Then reload the configuration file or restart Kakoune and run `:plug-install`.
### Without plugin manager
This plugin consists of several parts which are "modules", that provide
different functions to plugin. There's central module that must be loaded
before any other module, named `fzf.kak`, so in order to properly load
**fzf.kak** plugin, you need to source it in your `kakrc`.
```sh
This plugin consists of several parts which are referred to as "modules".
So, for the plugin to work the base module must be loaded:
``` sh
source "/path/to/fzf.kak/rc/fzf.kak" # loading base fzf module
```
This will load base `fzf` module, but It can't do anything on it's own. You can
load only needed modules, to keep your configuration rather simple, or load
every module if you need all plugin abilities:
This module doesn't do anything on its own.
Each module in the `modules` directory provides features that extend the base `fzf` module with new commands and mappings.
Those can be loaded manually one by one the same way as the base module, or with the use of the `find` command:
```sh
source "/path/to/fzf.kak/rc/modules/fzf-file.kak" # fzf file chooser
source "/path/to/fzf.kak/rc/modules/fzf-buffer.kak" # switching buffers with fzf
source "/path/to/fzf.kak/rc/modules/fzf-search.kak" # search within file contents
source "/path/to/fzf.kak/rc/modules/fzf-cd.kak" # change server's working directory
source "/path/to/fzf.kak/rc/modules/fzf-ctags.kak" # search for tag in your project ctags file
``` sh
evaluate-commands %sh{
find -L "path/to/fzf.kak/modules/" -type f -name '*.kak' -exec printf 'source "%s"\n' {} \;
}
```
The same principle is applied to handling different version control systems. You
need a base module for `fzf`, called `fzf-vcs.kak` and its sub-modules for each
VCS. There are plenty of version control systems, so modules come in handy.
```sh
source "/path/to/fzf.kak/rc/modules/fzf-vcs.kak" # VCS base module
```
So if you never work with, say, GNU Bazaar, or Mercurial you can remove them
from your configuration.
```sh
source "/path/to/fzf.kak/rc/modules/VCS/fzf-bzr.kak" # GNU Bazaar support
source "/path/to/fzf.kak/rc/modules/VCS/fzf-git.kak" # Git support module
source "/path/to/fzf.kak/rc/modules/VCS/fzf-hg.kak" # Mercurial VCS
source "/path/to/fzf.kak/rc/modules/VCS/fzf-svn.kak" # Subversion module
```
Order of sourcing files should not matter, but it is preferable to source main
script first, and then the modules. This may look complex, but it makes plugin
more versatile. And plugin managers, like [plug.kak][11] for example, just does
all those steps for you.
By the way, this structure makes it easy to extend plugin with new modules, and
you [can add modules on your own][20]!
## Usage
There's no default key binding to invoke `fzf`, but **fzf.kak** provides a
`fzf-mode` command that can be mapped to preferred key. You can set your own
mapping to invoke `fzf-mode`:
fzf.kak provides a `fzf-mode` command that can be mapped to preferred key:
```kak
map global normal <c-p> ': fzf-mode<ret>'
```
Note that space between colon and command is intentional and will strip this
command from command history.
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:
This will invoke the user mode, which contains mnemonic keybindings for each sub-module.
If all modules were loaded, the following mappings are available:
- <kbd>b</kbd> - Select buffer.
- <kbd>c</kbd> - Switch server's working directory.
@ -97,146 +67,211 @@ Each `fzf` module defines mnemonic mapping, like <kbd>f</kbd> for opening files,
- <kbd>p</kbd> - Project selector.
- <kbd>Alt</kbd>+<kbd>p</kbd> - Project related commands.
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.
When Kakoune runs inside Tmux, fzf.kak will use the bottom split to display the `fzf` window.
Additional keybindings are also made available to open files in a vertical or horizontal split.
Otherwise, the `terminal` command is being used to create new windows.
When Kakoune is being run in Tmux, **fzf.kak** will use bottom split to display
`fzf`. Additional keybindings are available to open file in vertical or
horizontal split. When Kakoune is used in plain terminal, the `terminal` command
is being used to create new windows.
## Configuration
**fzf.kak** features a lot of settings via options that can be altered to change
how **fzf.kak** behaves.
fzf.kak features a lot of settings via options that can be altered to change how fzf.kak behaves.
Each `.kak` file provides a Kakoune module, so any settings which alter variable values should be wrapped in the `ModuleLoaded` hook.
See [plug.kak manual section for `defer`](https://github.com/andreyorst/plug.kak/tree/master#deferring-plugin-configuration) that explains how to do this when using the plug.kak.
### Default query
| module |
|--------|
| `fzf` |
By default main selection is used as the default query for `fzf`, but only if the selection is more than 1 character long.
This can be disabled by setting `fzf_use_main_selection` to `false`.
### Windowing
| module |
|--------|
| `fzf` |
When using Tmux fzf.kak automatically creates all needed Tmux splits and panes for you.
In other cases fzf.kak uses the `fzf_terminal_command` option to call the windowing command to create new windows.
By default it is set to use `terminal` alias: `terminal kak -c %val{session} -e "%arg{@}"`, but some terminals can provide other aliases or commands, like `terminal-tab` in Kitty.
### Mappings
| module |
|--------|
| `fzf` |
Keys that are used in the `fzf` window can be configured with these options:
- `fzf_window_map` - mapping to perform an action in a new window,
- `fzf_vertical_map` - mapping to perform an action in new vertical split (Tmux),
- `fzf_horizontal_map` - mapping to perform an action in new horizontal split.
These options should be set to work with fzf `--expect` parameter, so check out fzf documentation on this.
### File command
You can configure what command to use to search for files, and it's arguments.
Supported tools are [GNU Find][12], [The Silver Searcher][13], [ripgrep][14],
[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:
| module |
|------------|
| `fzf-file` |
A command that is used to search for files and their arguments can be configured by changing the value of the `fzf_file_command` variable, which is available in the `fzf-file` module.
Supported tools are [GNU Find][12], [The Silver Searcher][13], [ripgrep][14], [fd][15].
A default set of arguments is provided for each of these searchers, only the name of the tool can be assigned to the `fzf_file_command` variable:
```kak
set-option global fzf_file_command 'rg' # 'ag', 'fd', or 'find'
```
Or if you don't like default arguments, which for `find` are `find -type f`, and
would like to disable searching in, say `.svn` and `.git` directories you can
set option like this:
Default arguments can be changed by setting the complete command to execute:
```kak
set-option global fzf_file_command "find . \( -path '*/.svn*' -o -path '*/.git*' \) -prune -o -type f -print"
```
This can give you the idea of how this plugin can be customized. Most of
**fzf.kak** modules provide settings for their commands, so you should check all
`fzf-optionname` available in prompt mode. All such options are well documented,
so listing those in readme would make it unnecessary long.
### Preview
**fzf.kak** tries to automatically detect where to show preview window,
depending on aspect ratio of new terminal window. By default if the doubled
height is bigger than the width, preview occupies upper 60% of space. If height
is smaller than the width, preview is shown at the right side.
You can configure the amount of space for preview window with these options:
`fzf_preview_height` and `fzf_preview_width`.
| module |
|------------|
| `fzf-file` |
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`
fzf.kak tries to automatically detect where to show preview window, depending on the aspect ratio of the new terminal window.
By default, if the doubled height is bigger than the width, preview occupies the upper 60% of space.
If the height is smaller than the width, a preview is shown on the right side.
These amounts can be configured with `fzf_preview_height` and `fzf_preview_width` options.
Amount of lines in preview window can be changed with `fzf_preview_lines`
option.
When using fzf.kak inside `tmux`, the bottom pane is used for all `fzf` commands, and the preview window is displayed on the right side.
When the preview is turned on, the height of the `tmux` split is increased to provide more space.
Split height can be configured with the `fzf_preview_tmux_height` variable.
Amount of lines in the preview window can be changed with the `fzf_preview_lines` option.
The preview feature can be disabled entirely by setting the `fzf_preview` option to `false`.
If you don't want preview feature you can disable it by setting `fzf_preview`
option to `false`.
#### Highlighting preview window
You also can highlight contents of the file displayed within preview window. To
do so, you can specify which highlighter to use with `fzf_highlighter` option.
Supported highlighters are:
| module |
|------------|
| `fzf-file` |
Contents of the file displayed within the preview window can be syntax highlighted.
This can be enabled by specifying a highlighter to use with the `fzf_highlight_command` option.
These highlighters are are supported out of the box:
* [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`.
Although other tools are not supported by the script, they 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:
| module |
|-----------|
| `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 automatically.
To explicitly use some particular VCS command, the <kbd>Alt</kbd>+<kbd>v</kbd> mapping can be used, which includes all supported VCS shortcuts.
To set parameters to VCS command used to provide project files the following options can be used:
* `fzf_git_command`
* `fzf_svn_command`
* `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.
Feature requests and merge requests are welcome.
### Tmux
When using inside tmux, `fzf` will use bottom split. Height of this split can be
changed with `fzf_tmux_height` option. `fzf_tmux_height_file_preview` option is
used to control height of the split when you do file searching with file-preview
turned on.
| module |
|--------|
| `fzf` |
When running inside Tmux, `fzf` will use bottom split.
The height of this split can be changed with the `fzf_tmux_height` option.
`fzf_tmux_height_file_preview` option is used to control the height of the split when file-preview is turned on.
### Projects
| module |
|---------------|
| `fzf-project` |
fzf.kak has basic project manipulation capabilities.
To store projects a hidden file is created in `%val{config}` and called `.fzf-projects`.
The location of this file and its name can be changed by modifying the `fzf_project_file` option.
By default project paths that start from the home directory will use `~` instead of the real path.
To change this, set `fzf_project_use_tilda` option to `false`.
## `fzf` command
`fzf` command can be used from prompt mode and for [scripting][20]. It supports
these arguments:
- `-kak-cmd`: A Kakoune command that is applied to `fzf` resulting value, e.g.
`edit -existing`, `change-directory`, e.t.c.
- `-multiple-cmd`: A Kakoune command that is applied when multiple items
selected to every item but the first one.
- `-items-cmd`: A command that is used as a pipe to provide list of values to
`fzf`. For example, if we want to pass list of all files recursively in
current directory, we would use `-items-cmd %{find .}` which will be piped to
`fzf` tool.
- `-fzf-impl`: Override `fzf` implementation variable. Can be used if command
needs to provide a different arguments to `fzf`. See [sk-grep.kak][21] as
example.
`fzf` command can be used from prompt mode and for [scripting][20].
The following arguments are supported:
- `-kak-cmd`: A Kakoune command that is applied to `fzf` resulting value, e.g. `edit -existing`, `change-directory`, e.t.c.
- `-multiple-cmd`: A Kakoune command that is applied when multiple items are selected to every item but the first one.
- `-items-cmd`: A command that is used as a pipe to provide a list of values to `fzf`.
For example, if we want to pass a list of all files recursively in the current directory, we would use `-items-cmd %{find .}` which will be piped to the `fzf` tool.
- `-fzf-impl`: Override `fzf` implementation variable.
Can be used if the command needs to provide 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.
- `-preview-cmd`: A preview command.
Can be used to override default preview handling.
- `-preview`: If specified, the command will ask for a preview.
- `-filter`: A pipe which will be applied to the 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 that `fzf` returns is piped to this filter command.
See [fzf-search.kak][22] as example.
- `-post-action`: Extra commands that are performed after the `-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.
### Writing a module
You can write a module for **fzf.kak**. To create one, simply define a function
in separate file, located in `rc/modules/`, and named after the
function. **fzf.kak** provides a general purpose command, that can be called
with some Kakoune command as first parameter, and command that provides list of
items for `fzf` as a second parameter. Third optional parameter is for defining
extra arguments for `fzf` itself, like additional keybindings.
Please do.
If you want to contribute to fzf.kak by adding a module, you can submit one by providing a pull request, or just open a feature request and we'll see what can be done.
Overall module structure is:
* Define a `fzf-command` command
* Prepare list of items for `fzf`, or define an item command
* call `fzf` command and pass needed arguments to it.
The basic idea behind the module structure can be described as:
1. Provide a user module;
2. Define a command that calls the `fzf` function with appropriate arguments;
3. Create a mapping in a `ModuleLoaded` hook, that requires a new module, and calls the command.
See how existing modules are implemented to understand the idea of how modules are constructed.
### External modules
Support for [yank-ring.kak][25] was externalized to separate plugin [fzf-yank-ring.kak][24]
# Alternatives
There are another (often more simple and robust) plugins, which add support for integration with `fzf` or other fuzzy finders that you might be interested in:
1. [peneira][26] - a fuzzy finder implemented specifically for Kakoune.
2. [connect.kak][27] - a tool that allows you to connect Kakoune with various applications like `fzf` and more.
3. [kakoune.cr][28] - a similar tool to `connect.kak`, but written in the Crystal language.
Also allows you to connect Kakoune to other applications, including `fzf`.
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
@ -261,3 +296,12 @@ various settings inside it. Feel free to look how existing modules are made.
[21]: rc/modules/sk-grep.kak
[22]: rc/modules/fzf-search.kak
[23]: #configuration
[24]: https://gitlab.com/losnappas/fzf-yank-ring.kak
[25]: https://github.com/alexherbo2/yank-ring.kak
[26]: https://github.com/gustavo-hms/peneira
[27]: https://github.com/kakounedotcom/connect.kak
[28]: https://github.com/alexherbo2/kakoune.cr
<!-- LocalWords: Github Kakoune fzf kak config VCS ctags Tmux fd sk
LocalWords: ripgrep readme Coderay rc
-->

View file

@ -1,14 +1,17 @@
# ╭─────────────╥───────────────────╮
# │ Author: ║ Plugin: │
# │ Andrey Orst ║ fzf.kak │
# ╞═════════════╩═══════════════════╡
# │ This plugin implements fzf │
# │ mode for Kakoune. This mode │
# │ adds several mappings to invoke │
# │ different fzf commands. │
# ╰─────────────────────────────────╯
# Author: Andrey Listopadov
# This plugin implements fzf mode for Kakoune.
# This mode adds several mappings to invoke different fzf commands.
# https://github.com/andreyorst/fzf.kak
try %{ declare-user-mode fzf }
define-command -docstring "Enter fzf-mode.
fzf-mode contains mnemonic key bindings for every fzf.kak command
Best used with mapping like:
map global normal '<some key>' ': fzf-mode<ret>'
" \
fzf-mode %{ require-module fzf; evaluate-commands 'enter-user-mode fzf' }
provide-module fzf %§
# Options
declare-option -docstring 'implementation of fzf that you want to use.
@ -27,6 +30,12 @@ declare-option -docstring 'amount of lines to pass to preview window
Default value: 100' \
int fzf_preview_lines 100
declare-option -docstring 'preview window position.
Supported values: up (top), down (bottom), left, right, auto
Default value: auto' \
str fzf_preview_pos "auto"
declare-option -docstring 'Highlighter to use in preview window. You can provide
only the name of the tool that you want to use, or specify a command.
Supported tools:
@ -43,7 +52,7 @@ These are default arguments for the tools above:
highlight: "highlight --failsafe -O ansi {}"
rouge: "rougify {}"
' \
str fzf_highlight_cmd "highlight"
str fzf_highlight_command "highlight"
declare-option -docstring "height of fzf tmux split in screen lines or percents.
Default value: 25%%" \
@ -61,40 +70,49 @@ declare-option -docstring "height of preview window.
Default value: 60%%" \
str fzf_preview_height '60%'
define-command -docstring "Enter fzf-mode.
fzf-mode contains mnemonic key bindings for every fzf.kak command
declare-option -docstring "mapping to execute action in new window" \
str fzf_window_map 'ctrl-w'
Best used with mapping like:
map global normal '<some key>' ': fzf-mode<ret>'
" \
fzf-mode %{ try %{ evaluate-commands 'enter-user-mode fzf' } }
declare-option -docstring "mapping to execute action in new vertical split" \
str fzf_vertical_map 'ctrl-v'
declare-option -docstring "mapping to execute action in new horizontal split" \
str fzf_horizontal_map 'ctrl-s'
declare-option -docstring 'command to use to create the FZF window when not using tmux.
Default value: terminal kak -c %val{session} -e "%arg{@}"' \
str fzf_terminal_command 'terminal kak -c %val{session} -e "%arg{@}"'
declare-option -docstring 'command to use to create a new window (ctrl-w) when not using tmux.
Default value: terminal kak -c %val{session} -e "%arg{@}"' \
str fzf_new_terminal_command 'terminal kak -c %val{session} -e "%arg{@}"'
declare-option -docstring "use main selection as default query for fzf if the selection is longer than 1 char." \
bool fzf_use_main_selection true
declare-option -docstring "Default options for fzf." \
str fzf_default_opts ''
try %{ declare-user-mode fzf }
define-command -hidden -docstring "wrapper command to create new vertical split" \
fzf-vertical -params .. %{ try %{
fzf-vertical -params .. %{ evaluate-commands %{
tmux-terminal-vertical kak -c %val{session} -e "%arg{@}"
} catch %{
tmux-new-vertical "%arg{@}"
}}
define-command -hidden -docstring "wrapper command to create new horizontal split" \
fzf-horizontal -params .. %{ try %{
fzf-horizontal -params .. %{ evaluate-commands %{
tmux-terminal-horizontal kak -c %val{session} -e "%arg{@}"
} catch %{
tmux-new-horizontal "%arg{@}"
}}
define-command -hidden -docstring "wrapper command to create new terminal" \
fzf-window -params .. %{ try %sh{
if [ -n "$kak_client_env_TMUX" ]; then
fzf-window -params .. %{ evaluate-commands %sh{
if [ -n "${kak_client_env_TMUX:-}" ]; then
printf "%s\n" 'tmux-terminal-window kak -c %val{session} -e "%arg{@}"'
else
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{@}"'
printf "%s\n" "${kak_opt_fzf_new_terminal_command:?}"
fi
}}
@ -123,96 +141,120 @@ Switches:
-post-action"
} \
fzf -params .. %{ evaluate-commands %sh{
fzf_impl="${kak_opt_fzf_implementation}"
fzf_impl="${kak_opt_fzf_implementation:?}"
# trims selection and escapes single quotes
selection=$(printf "%s" "${kak_selection:-}" | sed -e "s/^[[:blank:]]*//g;s/[[:blank:]]*$//g;s/'/'\\\\''/g")
[ "${kak_opt_fzf_use_main_selection:-}" = "true" ] && \
[ "$(printf "%s" "$kak_selection" | wc -m)" -gt 1 ] && \
[ "$(printf "%s\n" "$selection" | wc -l)" -eq 1 ] && \
default_query="-i -q '$selection'"
while [ $# -gt 0 ]; do
case $1 in
-kak-cmd) shift; kakoune_cmd="$1" ;;
-multiple-cmd) shift; multiple_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
(-kak-cmd) shift; kakoune_cmd="$1" ;;
(-multiple-cmd) shift; multiple_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
[ -z "$multiple_cmd" ] && multiple_cmd="$kakoune_cmd"
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
[ -n "${kak_client_env_TMUX:-}" ] && tmux_height="${kak_opt_fzf_preview_tmux_height:-}"
case ${kak_opt_fzf_preview_pos:-} in
(top|up) preview_position="pos=top:${kak_opt_fzf_preview_height:-};" ;;
(bottom|down) preview_position="pos=down:${kak_opt_fzf_preview_height:-};" ;;
(right) preview_position="pos=right:${kak_opt_fzf_preview_width:-};" ;;
(left) preview_position="pos=left:${kak_opt_fzf_preview_width:-};" ;;
(auto|*) preview_position="sleep 0.1; [ \$(tput cols) -gt \$(expr \$(tput lines) \* 2) ] && pos=right:${kak_opt_fzf_preview_width:-} || pos=top:${kak_opt_fzf_preview_height:-};"
esac
# handle preview if not defined explicitly with `-preview-cmd'
if [ ${kak_opt_fzf_preview} = "true" ] && [ -z "${preview_cmd}" ]; then
case ${kak_opt_fzf_highlight_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}" ;;
if [ "${kak_opt_fzf_preview:-}" = "true" ] && [ -z "${preview_cmd}" ]; then
case ${kak_opt_fzf_highlight_command:-} in
(bat) highlight_cmd="bat --color=always --style=plain {}" ;;
(coderay) highlight_cmd="coderay {}" ;;
(highlight) highlight_cmd="highlight --failsafe -O ansi {}" ;;
(rouge) highlight_cmd="rougify {}" ;;
(*) highlight_cmd="${kak_opt_fzf_highlight_command}" ;;
esac
preview_cmd="--preview '(${highlight_cmd} || cat {}) 2>/dev/null | head -n ${kak_opt_fzf_preview_lines}' --preview-window=\${pos}"
preview_cmd="--preview '(${highlight_cmd} || cat {}) 2>/dev/null | head -n ${kak_opt_fzf_preview_lines:-}' --preview-window=\${pos}"
fi
fi
fzf_tmp=$(mktemp -d ${TMPDIR:-/tmp}/fzf.kak.XXXXXX)
fzf_tmp=$(mktemp -d "${TMPDIR:-/tmp}"/fzf.kak.XXXXXX)
fzfcmd="${fzf_tmp}/fzfcmd"
result="${fzf_tmp}/result"
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}
(
shell_path="$(command -v sh)"
if [ -n "${shell_path}" ]; then
# portable shebang
printf "%s\n" "#!${shell_path}"
# set SHELL because fzf preview uses it
printf "%s\n" "SHELL=${shell_path}"
fi
# compose entire fzf command with all args into single file which will be executed later
printf "%s\n" "export FZF_DEFAULT_OPTS=\"${kak_opt_fzf_default_opts:-}\""
printf "%s\n" "cd \"${PWD}\" && ${preview_position} ${items_cmd} ${fzf_impl} ${default_query} ${fzf_args} ${preview_cmd} ${filter} > ${result}"
printf "%s\n" "rm ${fzfcmd}"
) >> "${fzfcmd}"
chmod 755 "${fzfcmd}"
if [ -n "${kak_client_env_TMUX}" ]; then
# set default height if not set already
[ -z "${tmux_height}" ] && tmux_height=${kak_opt_fzf_tmux_height}
[ -z "${tmux_height}" ] && tmux_height=${kak_opt_fzf_tmux_height:-}
# if height contains `%' then `-p' will be used
[ -n "${tmux_height%%*%}" ] && measure="-l" || measure="-p"
# `terminal' doesn't support any kind of width and height parameters, so tmux panes are created by tmux itself
cmd="nop %sh{ command tmux split-window ${measure} ${tmux_height%%%*} '${fzfcmd}' }"
cmd="nop %sh{ command tmux split-window -t '${kak_client_env_TMUX_PANE:-}' ${measure} ${tmux_height%%%*} env ${fzfcmd} < /dev/null > /dev/null 2>&1 }"
else
cmd="terminal %{${fzfcmd}}"
cmd="${kak_opt_fzf_terminal_command%% *} %{${fzfcmd}}"
fi
printf "%s\n" "${cmd}"
# main loop
( while [ -e ${fzfcmd} ]; do sleep 0.1; done
if [ -s ${result} ]; then
( while [ -e "${fzfcmd}" ]; do sleep 0.1; done
if [ -s "${result}" ]; then
(
while read -r line; do
case ${line} in
ctrl-w) wincmd="fzf-window" ;;
ctrl-s) wincmd="fzf-vertical" ;;
ctrl-v) wincmd="fzf-horizontal" ;;
*) item=${line} ;;
("${kak_opt_fzf_window_map:-ctrl-w}") wincmd="fzf-window" ;;
("${kak_opt_fzf_vertical_map:-ctrl-v}") wincmd="fzf-vertical" ;;
("${kak_opt_fzf_horizontal_map:-ctrl-s}") wincmd="fzf-horizontal" ;;
(*) item=${line} ;;
esac
if [ -n "${item}" ]; then
printf "%s\n" "evaluate-commands -client ${kak_client} ${wincmd} %{${kakoune_cmd} %{${item}}}"
item=$(printf "%s\n" "${item}" | sed "s/@/@@/g;s/&/&&/g")
kakoune_cmd=$(printf "%s\n" "${kakoune_cmd}" | sed "s/&/&&/g")
printf "%s\n" "evaluate-commands -client ${kak_client:?} ${wincmd} %&${kakoune_cmd} %@${item}@&"
break
fi
done
[ -n "${multiple_cmd}" ] && multiple_cmd=$(printf "%s\n" "${multiple_cmd}" | sed "s/&/&&/g")
while read -r line; do
printf "%s\n" "evaluate-commands -client ${kak_client} ${wincmd} %{${multiple_cmd} %{${line}}}"
line=$(printf "%s\n" "${line}" | sed "s/@/@@/g;s/&/&&/g")
printf "%s\n" "evaluate-commands -client ${kak_client} ${wincmd} %&${multiple_cmd} %@${line}@&"
done
if [ -n "${post_action}" ]; then
printf "%s\n" "evaluate-commands -client ${kak_client} %{${post_action}}"
post_action=$(printf "%s\n" "${post_action}" | sed "s/&/&&/g")
printf "%s\n" "evaluate-commands -client ${kak_client} %&${post_action}&"
fi
) < ${result} | kak -p ${kak_session}
) < "${result}" | kak -p "${kak_session:?}"
fi
rm -rf ${fzf_tmp}
rm -rf "${fzf_tmp}"
) > /dev/null 2>&1 < /dev/null &
}}
§

View file

@ -1,11 +1,12 @@
# ╭─────────────╥─────────────────────────╮
# │ Author: ║ File: │
# │ Andrey Orst ║ fzf-svn.kak │
# ╞═════════════╩═════════════════════════╡
# │ Submodule for Bzr support for fzf.kak │
# ╞═══════════════════════════════════════╡
# │ GitHub.com/andreyorst/fzf.kak │
# ╰───────────────────────────────────────╯
# Author: Andrey Listopadov
# Submodule for Bzr support for fzf.kak
# https://github.com/andreyorst/fzf.kak
hook global ModuleLoaded fzf-vcs %{
map global fzf-vcs -docstring "edit file from GNU Bazaar tree" 'b' '<esc>: require-module fzf-bzr; fzf-bzr<ret>'
}
provide-module fzf-bzr %§
declare-option -docstring "command to provide list of files in GNU Bazaar repository to fzf. Arguments are supported
Supported tools:
@ -13,23 +14,18 @@ Supported tools:
GNU Bazaar: ""bzr""
Default arguments:
""bzr ls -R --versioned -0""
'(cd $repo_root && bzr ls -R --versioned)'
" \
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{
current_path=$(pwd)
repo_root=$(bzr root)
case $kak_opt_fzf_bzr_command in
bzr)
cmd="bzr ls -R --versioned -0" ;;
bzr*)
cmd=$kak_opt_fzf_bzr_command ;;
(bzr) cmd="(cd $repo_root && bzr ls -R --versioned)" ;;
(*) cmd=$kak_opt_fzf_bzr_command ;;
esac
[ ! -z "${kak_client_env_TMUX}" ] && additional_flags="--expect ctrl-v --expect ctrl-s"
printf "%s\n" "fzf -kak-cmd %{cd $repo_root; edit -existing} -items-cmd %{$cmd} -fzf-args %{-m --expect ctrl-w $additional_flags} -post-action %{cd $current_path}"
[ -n "${kak_client_env_TMUX}" ] && additional_flags="--expect ${kak_opt_fzf_vertical_map:-ctrl-v} --expect ${kak_opt_fzf_horizontal_map:-ctrl-s}"
printf "%s\n" "fzf -kak-cmd %{edit -existing} -items-cmd %{$cmd} -fzf-args %{-m --expect ${kak_opt_fzf_window_map:-ctrl-w} $additional_flags} -filter %{perl -pe \"if (/${kak_opt_fzf_window_map:-ctrl-w}|${kak_opt_fzf_vertical_map:-ctrl-v}|${kak_opt_fzf_horizontal_map:-ctrl-s}|^$/) {} else {print \\\"$repo_root/\\\"}\"}"
}}
§

View file

@ -1,35 +1,31 @@
# ╭─────────────╥─────────────────────────╮
# │ Author: ║ File: │
# │ Andrey Orst ║ fzf-svn.kak │
# ╞═════════════╩═════════════════════════╡
# │ Submodule for Git support for fzf.kak │
# ╞═══════════════════════════════════════╡
# │ GitHub.com/andreyorst/fzf.kak │
# ╰───────────────────────────────────────╯
# Author: Andrey Listopadov
# Submodule for Git support for fzf.kak
# https://github.com/andreyorst/fzf.kak
hook global ModuleLoaded fzf-vcs %§
map global fzf-vcs -docstring "edit file from Git tree" 'g' '<esc>: require-module fzf-git; fzf-git<ret>'
§
provide-module fzf-git %§
declare-option -docstring "command to provide list of files in git tree to fzf. Arguments are supported
Supported tools:
<package>: <value>:
Git : ""git""
Git: ""git""
Default arguments:
""git ls-tree --full-tree --name-only -r HEAD""
'git ls-tree --full-tree --name-only -r HEAD'
" \
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 -hidden fzf-git %{ evaluate-commands %sh{
define-command -override -hidden fzf-git %{ evaluate-commands %sh{
current_path=$(pwd)
repo_root=$(git rev-parse --show-toplevel)
case $kak_opt_fzf_git_command in
git)
cmd="git ls-tree --full-tree --name-only -r HEAD" ;;
git*)
cmd=$kak_opt_fzf_git_command ;;
(git) cmd='git ls-tree --full-tree --name-only -r HEAD' ;;
(*) cmd=$kak_opt_fzf_git_command ;;
esac
[ ! -z "${kak_client_env_TMUX}" ] && additional_flags="--expect ctrl-v --expect ctrl-s"
printf "%s\n" "fzf -kak-cmd %{cd $repo_root; edit -existing} -items-cmd %{$cmd} -fzf-args %{-m --expect ctrl-w $additional_flags} -post-action %{cd $current_path}"
[ ! -z "${kak_client_env_TMUX}" ] && additional_flags="--expect ${kak_opt_fzf_vertical_map:-ctrl-v} --expect ${kak_opt_fzf_horizontal_map:-ctrl-s}"
printf "%s\n" "fzf -kak-cmd %{edit -existing} -items-cmd %{$cmd} -fzf-args %{-m --expect ${kak_opt_fzf_window_map:-ctrl-w} $additional_flags} -filter %{perl -pe \"if (/${kak_opt_fzf_window_map:-ctrl-w}|${kak_opt_fzf_vertical_map:-ctrl-v}|${kak_opt_fzf_horizontal_map:-ctrl-s}|^$/) {} else {print \\\"$(git rev-parse --show-toplevel)/\\\"}\"}"
}}
§

View file

@ -1,11 +1,12 @@
# ╭─────────────╥────────────────────────╮
# │ Author: ║ File: │
# │ Andrey Orst ║ fzf-svn.kak │
# ╞═════════════╩════════════════════════╡
# │ Submodule for Hg support for fzf.kak │
# ╞══════════════════════════════════════╡
# │ GitHub.com/andreyorst/fzf.kak │
# ╰──────────────────────────────────────╯
# Author: Andrey Listopadov
# Submodule for Hg support for fzf.kak
# https://github.com/andreyorst/fzf.kak
hook global ModuleLoaded fzf-vcs %{
map global fzf-vcs -docstring "edit file from mercurial tree" 'h' '<esc>: require-module fzf-hg; fzf-hg<ret>'
}
provide-module fzf-hg %§
declare-option -docstring "command to provide list of files in mercurial repository to fzf. Arguments are supported
Supported tools:
@ -13,23 +14,18 @@ Supported tools:
Mercurial SCM: ""hg""
Default arguments:
""hg locate -f -0 -I .hg locate -f -0 -I .""
""hg locate -f""
" \
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{
current_path=$(pwd)
repo_root=$(hg root)
case $kak_opt_fzf_hg_command in
hg)
cmd="hg locate -f -0 -I .hg locate -f -0 -I ." ;;
hg*)
cmd=$kak_opt_fzf_hg_command ;;
(hg) cmd="hg locate -f" ;;
(hg*) cmd=$kak_opt_fzf_hg_command ;;
esac
[ ! -z "${kak_client_env_TMUX}" ] && additional_flags="--expect ctrl-v --expect ctrl-s"
printf "%s\n" "fzf -kak-cmd %{cd $repo_root; edit -existing} -items-cmd %{$cmd} -fzf-args %{-m --expect ctrl-w $additional_flags} -post-action %{cd $current_path}"
[ ! -z "${kak_client_env_TMUX}" ] && additional_flags="--expect ${kak_opt_fzf_vertical_map:-ctrl-v} --expect ${kak_opt_fzf_horizontal_map:-ctrl-s}"
printf "%s\n" "fzf -kak-cmd %{edit -existing} -items-cmd %{$cmd} -fzf-args %{-m --expect ${kak_opt_fzf_window_map:-ctrl-w} $additional_flags}"
}}
§

View file

@ -1,11 +1,12 @@
# ╭─────────────╥─────────────────────────╮
# │ Author: ║ File: │
# │ Andrey Orst ║ fzf-svn.kak │
# ╞═════════════╩═════════════════════════╡
# │ Submodule for Svn support for fzf.kak │
# ╞═══════════════════════════════════════╡
# │ GitHub.com/andreyorst/fzf.kak │
# ╰───────────────────────────────────────╯
# Author: Andrey Listopadov
# Submodule for Svn support for fzf.kak
# https://github.com/andreyorst/fzf.kak
hook global ModuleLoaded fzf-vcs %§
map global fzf-vcs -docstring "edit file from Subversion tree" 's' '<esc>: require-module fzf-svn; fzf-svn<ret>'
§
provide-module fzf-svn %§
declare-option -docstring "command to provide list of files in svn repository to fzf. Arguments are supported
Supported tools:
@ -17,19 +18,15 @@ 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{
current_path=$(pwd)
repo_root=$(svn info | awk -F': ' '/Working Copy Root Path: .*/ {print $2}')
case $kak_opt_fzf_svn_command in
svn)
cmd="svn list -R $repo_root | grep -v '$/'" ;;
svn*)
cmd=$kak_opt_fzf_svn_command ;;
(svn) cmd="svn list -R $repo_root | grep -v '$/'" ;;
(svn*) cmd=$kak_opt_fzf_svn_command ;;
esac
[ ! -z "${kak_client_env_TMUX}" ] && additional_flags="--expect ctrl-v --expect ctrl-s"
printf "%s\n" "fzf -kak-cmd %{cd $repo_root; edit -existing} -items-cmd %{$cmd} -fzf-args %{-m --expect ctrl-w $additional_flags} -post-action %{cd $current_path}"
[ ! -z "${kak_client_env_TMUX}" ] && additional_flags="--expect ${kak_opt_fzf_vertical_map:-ctrl-v} --expect ${kak_opt_fzf_horizontal_map:-ctrl-s}"
printf "%s\n" "fzf -kak-cmd %{cd $repo_root; edit -existing} -items-cmd %{$cmd} -fzf-args %{-m --expect ${kak_opt_fzf_window_map:-ctrl-w} $additional_flags} -post-action %{cd $current_path}"
}}
§

View file

@ -1,32 +1,48 @@
# ╭─────────────╥────────────────────────╮
# │ Author: ║ File: │
# │ Andrey Orst ║ fzf-buffer.kak │
# ╞═════════════╩════════════════════════╡
# │ Module for changing buffers with fzf │
# │ for fzf.kak plugin │
# ╞══════════════════════════════════════╡
# │ GitHub.com/andreyorst/fzf.kak │
# ╰──────────────────────────────────────╯
# Author: Andrey Listopadov
# Module for changing buffers with fzf for fzf.kak plugin
# https://github.com/andreyorst/fzf.kak
try %{ declare-user-mode fzf }
map global fzf -docstring "open buffer" 'b' '<esc>: fzf-buffer<ret>'
hook global ModuleLoaded fzf %{
map global fzf -docstring "open buffer" 'b' '<esc>: require-module fzf-buffer; fzf-buffer<ret>'
map global fzf -docstring "delete buffer" '<a-b>' '<esc>: require-module fzf-buffer; fzf-delete-buffer<ret>'
}
provide-module fzf-buffer %§
define-command -hidden fzf-buffer %{ evaluate-commands %sh{
buffers=$(mktemp ${TMPDIR:-/tmp}/kak-fzf-buffers.XXXXXX)
eval "set -- $kak_buflist"
buffers=""
eval "set -- ${kak_quoted_buflist:?}"
while [ $# -gt 0 ]; do
printf "%s\n" "$1" >> $buffers
buffers="$1
$buffers"
shift
done
message="Set buffer to edit in current client.
<ret>: switch to selected buffer.
<c-w>: open buffer in new window"
[ ! -z "${kak_client_env_TMUX}" ] && tmux_keybindings="
<c-s>: open buffer in horizontal split
<c-v>: open buffer in vertical split"
${kak_opt_fzf_window_map:-ctrl-w}: open buffer in new window"
[ -n "${kak_client_env_TMUX:-}" ] && tmux_keybindings="
${kak_opt_fzf_horizontal_map:-ctrl-s}: open buffer in horizontal split
${kak_opt_fzf_vertical_map:-ctrl-v}: open buffer in vertical split"
printf "%s\n" "info -title 'fzf buffer' '$message$tmux_keybindings'"
[ ! -z "${kak_client_env_TMUX}" ] && additional_flags="--expect ctrl-v --expect ctrl-s"
[ -n "${kak_client_env_TMUX:-}" ] && additional_flags="--expect ${kak_opt_fzf_vertical_map:-ctrl-v} --expect ${kak_opt_fzf_horizontal_map:-ctrl-s}"
printf "%s\n" "fzf -kak-cmd %{buffer} -items-cmd %{(cat $buffers; rm $buffers)} -fzf-args %{--expect ctrl-w $additional_flags}"
printf "%s\n" "fzf -kak-cmd %{buffer} -items-cmd %{printf \"%s\n\" \"$buffers\"} -fzf-args %{--expect ${kak_opt_fzf_window_map:-ctrl-w} $additional_flags}"
}}
define-command -hidden fzf-delete-buffer %{ evaluate-commands %sh{
buffers=""
eval "set -- ${kak_quoted_buflist:?}"
while [ $# -gt 0 ]; do
buffers="$1
$buffers"
shift
done
message="Delete buffer.
<ret>: delete selected buffer."
printf "%s\n" "info -title 'fzf delete-buffer' '$message'"
printf "%s\n" "fzf -kak-cmd %{delete-buffer} -multiple-cmd %{delete-buffer} -items-cmd %{printf \"%s\n\" \"$buffers\"} -fzf-args %{-m --expect ${kak_opt_fzf_window_map:-ctrl-w} ${additional_flags:-}}"
}}
§

View file

@ -1,12 +1,12 @@
# ╭─────────────╥────────────────────────╮
# │ Author: ║ File: │
# │ Andrey Orst ║ fzf-cd.kak │
# ╞═════════════╩════════════════════════╡
# │ Module for changing directories with │
# │ fzf for fzf.kak plugin │
# ╞══════════════════════════════════════╡
# │ GitHub.com/andreyorst/fzf.kak │
# ╰──────────────────────────────────────╯
# Author: Andrey Listopadov
# Module for changing directories with fzf for fzf.kak plugin
# https://github.com/andreyorst/fzf.kak
hook global ModuleLoaded fzf %{
map global fzf -docstring "change directory" 'c' '<esc>: require-module fzf-cd; fzf-cd<ret>'
}
provide-module fzf-cd %§
declare-option -docstring "command to provide list of directories to fzf.
Default value:
@ -24,29 +24,23 @@ declare-option -docstring 'command to show list of directories in preview window
Default value:
tree -d
' \
str cd_preview_cmd "tree -d {}"
str cd_preview_command "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
current path: $(pwd)}"
case $kak_opt_fzf_cd_command in
find)
items_command="(echo .. && find . \( -path '*/.svn*' -o -path '*/.git*' \) -prune -o -type d -print)" ;;
*)
items_command=$kak_opt_fzf_cd_command ;;
case ${kak_opt_fzf_cd_command:-} in
(find) items_command="(echo .. && find . \( -path '*/.svn*' -o -path '*/.git*' \) -prune -o -type d -print)" ;;
(*) items_command=$kak_opt_fzf_cd_command ;;
esac
if [ "$kak_opt_fzf_cd_preview" = "true" ]; then
if [ "${kak_opt_fzf_cd_preview:-}" = "true" ]; then
preview_flag="-preview"
preview="--preview '($kak_opt_cd_preview_cmd) 2>/dev/null | head -n $kak_opt_fzf_preview_dirs'"
preview="--preview '(${kak_opt_cd_preview_command:-}) 2>/dev/null | head -n ${kak_opt_fzf_preview_dirs:-0}'"
fi
printf "%s\n" "fzf $preview_flag -kak-cmd %{change-directory} -items-cmd %{$items_command} -preview-cmd %{$preview} -post-action %{fzf-cd}"
}}
§

File diff suppressed because it is too large Load diff

View file

@ -1,12 +1,13 @@
# ╭─────────────╥────────────────────────╮
# │ Author: ║ File: │
# │ Andrey Orst ║ fzf-file.kak │
# ╞═════════════╩════════════════════════╡
# │ Module for opening files with fzf │
# │ for fzf.kak plugin │
# ╞══════════════════════════════════════╡
# │ GitHub.com/andreyorst/fzf.kak │
# ╰──────────────────────────────────────╯
# Author: Andrey Listopadov
# Module for opening files with fzf for fzf.kak plugin
# https://github.com/andreyorst/fzf.kak
hook global ModuleLoaded fzf %{
map global fzf -docstring "open file" 'f' '<esc>: require-module fzf-file; fzf-file<ret>'
map global fzf -docstring "open file in dir of currently displayed file" 'F' '<esc>: require-module fzf-file; fzf-file buffile-dir<ret>'
}
provide-module fzf-file %§
declare-option -docstring "command to provide list of files to fzf. Arguments are supported
Supported tools:
@ -24,40 +25,58 @@ Default arguments:
" \
str fzf_file_command "find"
try %{ declare-user-mode fzf }
map global fzf -docstring "open file" 'f' '<esc>: fzf-file<ret>'
declare-option -docstring 'allow showing preview window while searching for file
Default value:
true
' \
bool fzf_file_preview true
define-command -hidden fzf-file %{ evaluate-commands %sh{
if [ -z "$(command -v $kak_opt_fzf_file_command)" ]; then
define-command -hidden fzf-file -params 0..1 %{ evaluate-commands %sh{
# Default fzf-file behavior
search_dir="."
if [ "$1" = "buffile-dir" ]; then
# If the buffile-dir functionality (which is currently mapped to <fzf-mode> F) is
# invoked by mistake on a buffile like `*scratch*` or `*grep*` and similar, there will be
# no slashes in the buffile name and `dirname` will return `.` which means the functionality
# will revert to the normal fzf-file behavior -- which is what we want in this scenario.
search_dir=$(dirname "$kak_buffile")
fi
if [ -z "$(command -v "${kak_opt_fzf_file_command%% *}")" ]; then
printf "%s\n" "echo -markup '{Information}''$kak_opt_fzf_file_command'' is not installed. Falling back to ''find'''"
kak_opt_fzf_file_command="find"
fi
case $kak_opt_fzf_file_command in
find)
cmd="find -L . -type f" ;;
ag)
cmd="ag -l -f --hidden --one-device . " ;;
rg)
cmd="rg -L --hidden --files" ;;
fd)
cmd="fd --type f --follow" ;;
find*|ag*|rg*|fd*)
cmd=$kak_opt_fzf_file_command ;;
*)
items_executable=$(printf "%s\n" "$kak_opt_fzf_file_command" | grep -o -E "[[:alpha:]]+" | head -1)
printf "%s\n" "echo -markup '{Information}'Warning: '$executable'' is not supported by fzf.kak.'"
cmd=$kak_opt_fzf_file_command ;;
(find) cmd="find -L . -type f" ;;
(ag) cmd="ag -l -f --hidden --one-device . " ;;
(rg) cmd="rg -L --hidden --files" ;;
(fd) cmd="fd --type f --follow" ;;
(find*|ag*|rg*|fd*) cmd=$kak_opt_fzf_file_command ;;
(*) items_executable=$(printf "%s\n" "$kak_opt_fzf_file_command" | grep -o -E "[[:alpha:]]+" | head -1)
printf "%s\n" "echo -markup %{{Information}Warning: '$items_executable' is not supported by fzf.kak.}"
cmd=$kak_opt_fzf_file_command ;;
esac
cmd="cd $search_dir; $cmd 2>/dev/null"
maybe_filter_param=""
if [ "$search_dir" != "." ]; then
# Since we cd-ed into search dir in $cmd, prefix the $search_dir path after fzf returns the results by using -filter switch of fzf.
# Kakoune either needs an absolute path or path relative to its pwd to edit a file. Since the pwd of $cmd and kakoune now differ,
# we cannot use a relative path, so we construct the absolute path by prefixing the $search_dir to the file outputted by fzf.
maybe_filter_param=$(printf "%s %s" "-filter" "%{perl -pe \"if (/${kak_opt_fzf_window_map:-ctrl-w}|${kak_opt_fzf_vertical_map:-ctrl-v}|${kak_opt_fzf_horizontal_map:-ctrl-s}|^$/) {} else {print \\\"$search_dir/\\\"\"}}")
fi
message="Open single or multiple files.
<ret>: open file in new buffer.
<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"
${kak_opt_fzf_window_map:-ctrl-w}: open file in new terminal"
[ -n "${kak_client_env_TMUX:-}" ] && tmux_keybindings="
${kak_opt_fzf_horizontal_map:-ctrl-s}: open file in horizontal split
${kak_opt_fzf_vertical_map:-ctrl-v}: open file in vertical split"
printf "%s\n" "info -title 'fzf file' '$message$tmux_keybindings'"
[ ! -z "${kak_client_env_TMUX}" ] && additional_flags="--expect ctrl-v --expect ctrl-s"
printf "%s\n" "fzf -preview -kak-cmd %{edit -existing} -items-cmd %{$cmd} -fzf-args %{-m --expect ctrl-w $additional_flags}"
[ -n "${kak_client_env_TMUX}" ] && additional_flags="--expect ${kak_opt_fzf_vertical_map:-ctrl-v} --expect ${kak_opt_fzf_horizontal_map:-ctrl-s}"
[ "${kak_opt_fzf_file_preview:-}" = "true" ] && preview_flag="-preview"
printf "%s\n" "fzf $preview_flag $maybe_filter_param -kak-cmd %{edit -existing} -items-cmd %{$cmd} -fzf-args %{-m --expect ${kak_opt_fzf_window_map:-ctrl-w} $additional_flags}"
}}
§

50
rc/modules/fzf-grep.kak Normal file
View file

@ -0,0 +1,50 @@
# Author: Andrey Listopadov
# Module for grepping file contents
# https://github.com/andreyorst/fzf.kak
hook global ModuleLoaded fzf %{
map -docstring 'grep file contents recursively' global fzf g ': require-module fzf-grep; fzf-grep<ret>'
}
provide-module fzf-grep %§
declare-option -docstring "hat command to use to provide a list of grep search matches.
Grep output must follow the format of 'filename:line-number:text', and specify a pattern to match across all file contents.
By default, an empty pattern is searched, effectively matching every line in every file.
GNU grep and ripgrep are supported by default.
Default value:
grep -RHn '' ." \
str fzf_grep_command 'grep'
define-command -hidden fzf-grep %{ evaluate-commands %sh{
if [ -z "$(command -v "${kak_opt_fzf_grep_command%% *}")" ]; then
printf "%s\n" "echo -markup '{Information}''$kak_opt_fzf_grep_command'' is not installed. Falling back to ''grep'''"
kak_opt_fzf_grep_command="grep"
fi
case $kak_opt_fzf_grep_command in
(grep) cmd="grep -RHn '' ." ;;
(rg) cmd="rg --line-number --no-column --no-heading --color=never ''" ;;
(grep*|rg*) cmd=$kak_opt_fzf_grep_command ;;
(*) items_executable=$(printf "%s\n" "$kak_opt_fzf_grep_command" | grep -o -E "[[:alpha:]]+" | head -1)
printf "%s\n" "echo -markup %{{Information}Warning: '$items_executable' is not supported by fzf.kak.}"
cmd=$kak_opt_fzf_grep_command ;;
esac
cmd="$cmd 2>/dev/null"
title="fzf grep"
message="grep through contents of all files recursively.
<ret>: open search result in new buffer.
${kak_opt_fzf_window_map:-ctrl-w}: open search result in new terminal"
[ -n "${kak_client_env_TMUX:-}" ] && tmux_keybindings="
${kak_opt_fzf_horizontal_map:-ctrl-s}: open search result in horizontal split
${kak_opt_fzf_vertical_map:-ctrl-v}: open search result in vertical split"
printf "%s\n" "info -title '${title}' '${message}${tmux_keybindings}'"
[ -n "${kak_client_env_TMUX}" ] && additional_flags="--expect ${kak_opt_fzf_vertical_map:-ctrl-v} --expect ${kak_opt_fzf_horizontal_map:-ctrl-s}"
printf "%s\n" "fzf -kak-cmd %{evaluate-commands} -fzf-args %{--expect ${kak_opt_fzf_window_map:-ctrl-w} $additional_flags --delimiter=':' -n'3..'} -items-cmd %{$cmd} -filter %{sed -E 's/([^:]+):([^:]+):.*/edit -existing \1; execute-keys \2gvc/'}"
}}
§

View file

@ -1,72 +1,167 @@
# ╭─────────────╥────────────────────────╮
# │ Author: ║ File: │
# │ Andrey Orst ║ fzf-project.kak │
# ╞═════════════╩════════════════════════╡
# │ Module for storing and loading │
# │ projects with fzf for fzf.kak plugin │
# ╞══════════════════════════════════════╡
# │ GitHub.com/andreyorst/fzf.kak │
# ╰──────────────────────────────────────╯
# Author: Andrey Listopadov
# Module for storing and loading projects with fzf for fzf.kak plugin
# https://github.com/andreyorst/fzf.kak
hook global ModuleLoaded fzf %{
map global fzf -docstring "open project" 'p' '<esc>: require-module fzf-project; fzf-project<ret>'
}
provide-module fzf-project %§
require-module fzf-file
declare-option -docstring "file where saved projects are stored" str fzf_project_file "%val{config}/.fzf-projects"
declare-option -docstring %sh{ printf "%s\n" "use '~/' instead of '${HOME}'" } bool fzf_project_use_tilda false
try %{ declare-user-mode fzf }
map global fzf -docstring "open project" 'p' '<esc>: fzf-project<ret>'
try %{ declare-user-mode fzf-project }
map global fzf -docstring "project menu" '<a-p>' '<esc>: enter-user-mode fzf-project<ret>'
map global fzf-project -docstring "save current path as project" 's' '<esc>: fzf-save-path-as-project<ret>'
map global fzf-project -docstring "save current path as project (use basename)" '<a-s>' '<esc>: fzf-save-path-as-project-no-prompt<ret>'
map global fzf-project -docstring "update project" 'u' '<esc>: fzf-update-project-path<ret>'
map global fzf-project -docstring "delete project from project list" 'd' '<esc>: fzf-delete-project<ret>'
declare-option -docstring "file where saved projects are stored" str fzf_projects_file "%val{config}/.fzf-projects"
map global fzf-project -docstring "rename project" 'r' '<esc>: fzf-rename-project<ret>'
define-command -hidden fzf-project %{ evaluate-commands %sh{
if [ -s $kak_opt_fzf_projects_file ]; then
if [ -s "${kak_opt_fzf_project_file:-}" ]; then
printf '%s\n' "info -title %{fzf open project} %{Change the server's working directory to selected project}"
printf "%s\n" "fzf -kak-cmd change-directory -items-cmd %{cat $kak_opt_fzf_projects_file} -preview-cmd %{$preview} -post-action fzf-file -filter %{sed 's/.*: //'}"
printf "%s\n" "fzf -kak-cmd change-directory -items-cmd %{cat ${kak_opt_fzf_project_file}} -fzf-args %{--reverse --delimiter=':' -n'1'} -post-action fzf-file -filter %{sed 's/.*: //'}"
else
printf "%s\n" "echo -markup %{{Information}No projects defined in '$kak_opt_fzf_projects_file'}"
printf "%s\n" "echo -markup %{{Information}No project defined in '${kak_opt_fzf_project_file}'}"
fi
}}
define-command -hidden fzf-save-path-as-project %{ prompt "Project's name: " %{ evaluate-commands %sh{
mkdir -p "${kak_opt_fzf_projects_file%/*}"
tmp=$(mktemp "${TMPDIR:-/tmp}/fzf-project.XXXXXXX")
project=$(grep "$kak_text: " $kak_opt_fzf_projects_file)
if [ -z "${project}" ]; then
printf "%s: %s\n" "$kak_text" "$(pwd)" >> $kak_opt_fzf_projects_file
printf "%s\n" "echo -markup %{{Information}saved '$(pwd)' project as '$kak_text'}"
define-command -hidden fzf-save-path-as-project %{ prompt -shell-script-candidates %{printf "%s\n" "${PWD##*/}"} "Project's name: " %{ evaluate-commands %sh{
if [ -n "${kak_text:-}" ]; then
mkdir -p "${kak_opt_fzf_project_file%/*}"
exists=$(grep "${kak_text}: " "${kak_opt_fzf_project_file:-}")
if [ -z "${exists}" ]; then
[ "${kak_opt_fzf_project_use_tilda:-true}" = "false" ] && project_path=$(pwd) || project_path=$(pwd | perl -pe "s(${HOME})(~)")
printf "%s: %s\n" "${kak_text}" "${project_path}" >> "${kak_opt_fzf_project_file}"
printf "%s\n" "echo -markup %{{Information}saved '$(pwd)' project as '${kak_text}'}"
else
printf "%s\n" "fzf-project-confirm-impl %{Project '${kak_text}' exists. Update? (y/N): } %{fzf-update-project-path-impl %{${kak_text}} %{${PWD}}} %{Project '${kak_text}' updated} %{Project '${kak_text}' kept}"
fi
else
project="$kak_text"
printf "%s\n" "prompt -shell-script-candidates %{printf '%s\n%s\n' 'y' 'n'} %{Project '$project' exists. Update? (y/N): } %{ evaluate-commands %sh{
if [ \"\$kak_text\" = 'y' ] || [ \"\$kak_text\" = 'Y' ] || [ \"\$kak_text\" = 'yes' ] || [ \"\$kak_text\" = 'Yes' ] || [ \"\$kak_text\" = 'YEs' ] || [ \"\$kak_text\" = 'YES' ]; then
printf \"%s\n\" \"fzf-update-project-path-impl %{$project}\"
printf \"%s\n\" \"echo -markup %{{Information}'$project' project updated}\"
else
printf \"%s\n\" \"echo -markup %{{Information}'$project' project kept}\"
fi
}}"
printf "%s\n" "echo -markup %{{Error} Project name can't be empty}"
fi
rm -rf ${tmp}
}}}
define-command -hidden fzf-save-path-as-project-no-prompt %{ evaluate-commands %sh{
mkdir -p "${kak_opt_fzf_project_file%/*}"
# portable version of `basename'
base() {
filename="$1"
case "$filename" in
(*/*[!/]*)
trail=${filename##*[!/]}
filename=${filename%%"$trail"}
base=${filename##*/} ;;
(*[!/]*)
trail=${filename##*[!/]}
base=${filename%%"$trail"} ;;
(*) base="/" ;;
esac
printf "%s\n" "${base}"
}
project_name=$(base "${PWD}")
exists=$(grep "${project_name}: " "${kak_opt_fzf_project_file}")
if [ -z "${exists}" ]; then
[ "${kak_opt_fzf_project_use_tilda:-true}" = "false" ] && project_path=$(pwd) || project_path=$(pwd | perl -pe "s(${HOME})(~)")
printf "%s: %s\n" "${project_name}" "${project_path}" >> "${kak_opt_fzf_project_file}"
printf "%s\n" "echo -markup %{{Information}saved '$(pwd)' project as '${project_name}'}"
else
printf "%s\n" "fzf-project-confirm-impl %{Project '${project_name}' exists. Update? (y/N): } %{fzf-update-project-path-impl %{${project_name}} %{${PWD}}} %{${project_name}} %{Project '${project_name}' updated} %{Project '${project_name}' kept}"
fi
}}
define-command -docstring \
"fzf-add-project [<switches>] <path> [<name>]: add given <path> to project list with given <name>. If name omitted basename of the project is used for the name
Switches:
-force: overwrite project if exists without asking" \
fzf-add-project -file-completion -params 1..2 %{ evaluate-commands %sh{
if [ "$1" = "-force" ]; then
force="true"
shift
fi
# portable version of `basename'
base() {
filename="$1"
case "$filename" in
(*/*[!/]*)
trail=${filename##*[!/]}
filename=${filename%%"$trail"}
base=${filename##*/} ;;
(*[!/]*)
trail=${filename##*[!/]}
base=${filename%%"$trail"} ;;
(*) base="/" ;;
esac
printf "%s\n" "${base}"
}
mkdir -p "${kak_opt_fzf_project_file%/*}"
project_path="$1"
project_name="$2"
[ -z "${project_name}" ] && project_name=$(base "${project_path}")
exists=$(grep "${project_name}: " "${kak_opt_fzf_project_file}")
if [ -z "${exists}" ] || [ "${force}" = "true" ]; then
[ "${kak_opt_fzf_project_use_tilda:-true}" = "false" ] || project_path=$(printf "%s\n" "${project_path}" | perl -pe "s(${HOME})(~)")
printf "%s: %s\n" "${project_name}" "${project_path}" >> "${kak_opt_fzf_project_file}"
printf "%s\n" "echo -markup %{{Information}saved '${project_path}' project as '${project_name}'}"
else
printf "%s\n" "fzf-project-confirm-impl %{Project '${project_name}' exists. Update? (y/N): } %{fzf-update-project-path-impl %{${project_name}} %{${project_path}}} %{Project '${project_name}' updated} %{Project '${project_name}' kept}"
fi
}}
define-command -docstring \
"fzf-project-confirm-impl <message> <command> [<success_message>] [<fail_message>]: promt user to confirm action" \
-hidden fzf-project-confirm-impl -params 2..4 %{
prompt -shell-script-candidates %{printf "%s\n%s\n" "y" "n"} "%arg{1}" %{ evaluate-commands %sh{
shift; function_to_call=$1; success_message=$2; fail_message=$3
choice=$(printf "%s" "${kak_text:-}" | perl -pe "s/y(es)?.*//i") # case isensetive lookup for yes answer
if [ -z "${choice}" ]; then
printf "%s\n" "${function_to_call}"
[ -n "${success_message}" ] && printf "%s\n" "echo -markup %{{Information}${success_message}}"
else
[ -n "${fail_message}" ] && printf "%s\n" "echo -markup %{{Information}${fail_message}}"
fi
}}
}
define-command -hidden fzf-update-project-path %{
prompt -shell-script-candidates %{ perl -n -e '/^([^:]+)/ && print "$1\n"' $kak_opt_fzf_projects_file } "Project to update: " %{
prompt -shell-script-candidates %{ perl -ne '/^([^:]+)/ && print "$1\n"' ${kak_opt_fzf_project_file} } "Project to update: " %{
fzf-update-project-path-impl %val{text}
echo -markup "{Information}'%val{text}' project updated"
}
}
define-command fzf-update-project-path-impl -params 1 %{ nop %sh{
define-command -hidden fzf-update-project-path-impl -params 1..2 %{ nop %sh{
tmp=$(mktemp "${TMPDIR:-/tmp}/fzf-project.XXXXXXX")
perl -pe "s(\Q$1: \E.*)($1: $(pwd))" "${kak_opt_fzf_projects_file}" > ${tmp} && cat ${tmp} > "${kak_opt_fzf_projects_file}"
[ $# -eq 1 ] && project_path=$(pwd)
[ "${kak_opt_fzf_project_use_tilda}" = "false" ] && project_path=$2 || project_path=$(printf "%s\n" $2 | perl -pe "s(${HOME})(~)")
perl -pe "s(\Q$1: \E.*)($1: ${project_path})" "${kak_opt_fzf_project_file}" > ${tmp} && cat ${tmp} > "${kak_opt_fzf_project_file}"
rm -rf ${tmp}
}}
define-command -hidden fzf-delete-project %{
prompt -shell-script-candidates %{ perl -n -e '/^([^:]+)/ && print "$1\n"' $kak_opt_fzf_projects_file } "Project to delete: " %{ nop %sh{
prompt -shell-script-candidates %{ perl -ne '/^([^:]+)/ && print "$1\n"' ${kak_opt_fzf_project_file} } "Project to delete: " %{ nop %sh{
tmp=$(mktemp "${TMPDIR:-/tmp}/fzf-project.XXXXXXX")
perl -pe "s(\Q$kak_text: \E.*\n)()" "${kak_opt_fzf_projects_file}" > ${tmp} && cat ${tmp} > "${kak_opt_fzf_projects_file}"
perl -pe "s(\Q${kak_text}: \E.*\n)()" "${kak_opt_fzf_project_file}" > ${tmp} && cat ${tmp} > "${kak_opt_fzf_project_file}"
rm -rf ${tmp}
}}
}
define-command -hidden fzf-rename-project %{
prompt -shell-script-candidates %{ perl -ne '/^([^:]+)/ && print "$1\n"' ${kak_opt_fzf_project_file} } "Project to rename: " %{ evaluate-commands %sh{
tmp=$(mktemp "${TMPDIR:-/tmp}/fzf-project.XXXXXXX")
project_name=${kak_text}
printf "%s\n" "prompt %{New name: } %{ evaluate-commands %sh{
perl -pe \"s(${project_name}:)(\${kak_text}:)\" \"${kak_opt_fzf_project_file}\" > ${tmp} && cat ${tmp} > "${kak_opt_fzf_project_file}"
printf \"%s\n\" \"echo -markup %{{Information}'${project_name}' renamed to '\${kak_text}'}\"
}}"
rm -rf ${tmp}
}}
}
§

View file

@ -1,22 +1,20 @@
# ╭─────────────╥────────────────────────╮
# │ Author: ║ File: │
# │ Andrey Orst ║ fzf-search.kak │
# ╞═════════════╩════════════════════════╡
# │ Module for searching inside current │
# │ buffer with fzf for fzf.kak │
# ╞══════════════════════════════════════╡
# │ GitHub.com/andreyorst/fzf.kak │
# ╰──────────────────────────────────────╯
# Author: Andrey Listopadov
# Module for searching inside current buffer with fzf for fzf.kak
# https://github.com/andreyorst/fzf.kak
try %{ declare-user-mode fzf }
map global fzf -docstring "search in buffer" 's' '<esc>: fzf-buffer-search<ret>'
hook global ModuleLoaded fzf %{
map global fzf -docstring "search in buffer" 's' '<esc>: require-module fzf-search; fzf-buffer-search<ret>'
}
provide-module fzf-search %§
define-command -hidden fzf-buffer-search %{ evaluate-commands %sh{
title="fzf buffer search"
message="Search buffer with fzf, and jump to result location"
printf "%s\n" "info -title '$title' '$message'"
buffer_content="$(mktemp ${TMPDIR:-/tmp}/fzf-buff-${kak_buffile##*/}.XXXXXX)"
buffer_content="$(mktemp "${TMPDIR:-/tmp}"/fzf-buff-"${kak_buffile##*/}".XXXXXX)"
printf "%s\n" "execute-keys -draft %{%<a-|>cat<space>><space>$buffer_content<ret>;}"
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}"
}}
§

View file

@ -1,23 +1,20 @@
# ╭─────────────╥────────────────────────╮
# │ Author: ║ File: │
# │ Andrey Orst ║ fzf-vcs.kak │
# ╞═════════════╩════════════════════════╡
# │ Module that declares VCS submodule │
# │ for various version control systems │
# │ to open files with fzf │
# ╞══════════════════════════════════════╡
# │ GitHub.com/andreyorst/fzf.kak │
# ╰──────────────────────────────────────╯
# Author: Andrey Listopadov
# Module that declares VCS submodule for various version control systems to open files with fzf
# https://github.com/andreyorst/fzf.kak
try %{ declare-user-mode fzf-vcs } catch %{echo -markup "{Error}Can't declare mode 'fzf-vcs' - already exists"}
hook global ModuleLoaded fzf %§
map global fzf -docstring "edit file from vcs repo" 'v' '<esc>: require-module fzf-vcs; fzf-vcs<ret>'
map global fzf -docstring "switch to vcs selection mode" '<a-v>' '<esc>: require-module fzf-vcs; enter-user-mode fzf-vcs<ret>'
§
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>'
provide-module fzf-vcs %§
define-command -docstring "Enter fzf-vcs-mode.
This mode allows selecting specific vcs command." \
fzf-vcs-mode %{ try %{ evaluate-commands 'enter-user-mode fzf-vcs' } }
require-module fzf-git
require-module fzf-svn
require-module fzf-hg
require-module fzf-bzr
declare-user-mode fzf-vcs
define-command -hidden -docstring 'Wrapper command for fzf vcs to automatically decect
used version control system.
@ -36,17 +33,17 @@ bzr status"
IFS='
'
for cmd in $commands; do
eval $cmd >/dev/null 2>&1
eval "$cmd" >/dev/null 2>&1
res=$?
if [ "$res" = "0" ]; then
vcs=$(printf "%s\n" "$cmd" | awk '{print $1}')
title="fzf $vcs"
[ ! -z "${kak_client_env_TMUX}" ] && additional_keybindings="
<c-s>: open file in horizontal split
<c-v>: open file in vertical split"
[ -n "${kak_client_env_TMUX:-}" ] && additional_keybindings="
${kak_opt_fzf_horizontal_map:-ctrl-s}: open file in horizontal split
${kak_opt_fzf_vertical_map:-ctrl-v}: open file in vertical split"
message="Open single or multiple files from git tree.
<ret>: open file in new buffer.
<c-w>: open file in new terminal $additional_keybindings"
${kak_opt_fzf_window_map:-ctrl-w}: open file in new terminal $additional_keybindings"
printf "%s\n" "info -title %{$title} %{$message}"
printf "%s\n" "fzf-$vcs"
exit
@ -55,3 +52,4 @@ bzr status"
printf "%s\n" "echo -markup '{Information}No VCS found in current folder'"
}}
§

View file

@ -1,12 +1,16 @@
# ╭─────────────╥────────────────────────╮
# │ Author: ║ File: │
# │ Andrey Orst ║ sk-grep.kak │
# ╞═════════════╩════════════════════════╡
# │ Module running interactive grep with │
# │ ski for fzf.kak │
# ╞══════════════════════════════════════╡
# │ GitHub.com/andreyorst/fzf.kak │
# ╰──────────────────────────────────────╯
# Author: Andrey Listopadov
# Module running interactive grep with skim for fzf.kak
# https://github.com/andreyorst/fzf.kak
hook global ModuleLoaded fzf %§
evaluate-commands %sh{
if [ -n "$(command -v sk)" ]; then
printf "%s\n" "map global fzf -docstring %{Interactive grep with skim} '<a-g>' '<esc>: require-module fzf-sk-grep; fzf-sk-grep<ret>'"
fi
}
§
provide-module fzf-sk-grep %§
declare-option -docstring "what command to use to provide list of grep search matches.
Grep output must follow the format of 'filename:line-number:text'
@ -17,14 +21,6 @@ str fzf_sk_grep_command 'grep -RHn'
declare-option -hidden str fzf_sk_first_file ''
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-grep<ret>'"
fi
}
define-command -hidden fzf-sk-grep %{ evaluate-commands %sh{
if [ -z "$(command -v sk)" ]; then
printf "%s\n" "echo -markup %{{Information}skim required to run this command}"
@ -33,14 +29,14 @@ define-command -hidden fzf-sk-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 terminal"
[ ! -z "${kak_client_env_TMUX}" ] && tmux_keybindings="
<c-s>: open search result in horizontal split
<c-v>: open search result in vertical split"
${kak_opt_fzf_window_map:-ctrl-w}: open search result in new terminal"
[ -n "${kak_client_env_TMUX:-}" ] && tmux_keybindings="
${kak_opt_fzf_horizontal_map:-ctrl-s}: open search result in horizontal split
${kak_opt_fzf_vertical_map:-ctrl-v}: open search result in vertical split"
printf "%s\n" "info -title '${title}' '${message}${tmux_keybindings}'"
[ ! -z "${kak_client_env_TMUX}" ] && additional_flags="--expect ctrl-v --expect ctrl-s"
printf "%s\n" "fzf -kak-cmd %{fzf-sk-grep-handler} -fzf-impl %{sk -m -i -c '$kak_opt_fzf_sk_grep_command {}'} -fzf-args %{--expect ctrl-w $additional_flags} -multiple-cmd %{fzf-sk-populate-grep} -post-action %{buffer %opt{fzf_sk_first_file}}"
[ -n "${kak_client_env_TMUX}" ] && additional_flags="--expect ${kak_opt_fzf_vertical_map:-ctrl-v} --expect ${kak_opt_fzf_horizontal_map:-ctrl-s}"
printf "%s\n" "fzf -kak-cmd %{fzf-sk-grep-handler} -fzf-impl %{sk --ansi -m -i -c '${kak_opt_fzf_sk_grep_command:-} {}'} -fzf-args %{--expect ${kak_opt_fzf_window_map:-ctrl-w} $additional_flags} -multiple-cmd %{fzf-sk-populate-grep} -post-action %{buffer %opt{fzf_sk_first_file}}"
}}
define-command -hidden fzf-sk-grep-handler -params 1 %{
@ -62,9 +58,10 @@ define-command -hidden fzf-sk-populate-grep -params 1 %{
edit -scratch *grep*
set-option buffer filetype grep
}
evaluate-commands -buffer *grep* %{
evaluate-commands -save-regs '"' -buffer *grep* %{
set-register dquote %arg{1}
execute-keys gjPo
}
}
§