Compare commits
21 commits
Author | SHA1 | Date | |
---|---|---|---|
Cat /dev/Nulo | 62a3de575c | ||
010e395041 | |||
16e001c3a2 | |||
e91b76c517 | |||
d98b16680c | |||
66bc692ab3 | |||
68f21eb786 | |||
444a3449d4 | |||
124c3a2751 | |||
1b3a3beebb | |||
bfe1bc0a3d | |||
3f2773c919 | |||
a8765bb03d | |||
435cc240f3 | |||
aed44987a3 | |||
3d70299722 | |||
39ec448e5a | |||
d912a6ecf1 | |||
9ee5e4fea8 | |||
1a405fcc43 | |||
a8436627c3 |
356
README.md
356
README.md
|
@ -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 master branch.
|
||||
**fzf.kak** also supports [skim][9], which can be used via `fzf_implementation`
|
||||
option.
|
||||
fzf.kak is a plugin for [Kakoune][7] editor, that provides integration with the [fzf][8] tool.
|
||||
There's also 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,190 +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. All settings belong to `fzf` module, so in order to
|
||||
change variable values use `defer "fzf %{ ... }"` if you're using **plug.kak**,
|
||||
and if not, use `hook global ModuleLoaded fzf %{ ... }`, or simply `require-module
|
||||
fzf` before configuring options. Same goes for `fzf_vcs` module.
|
||||
|
||||
From now on I assume that you're using one of the methods listed above for all
|
||||
configurations below.
|
||||
fzf.kak features a lot of settings via options that can be altered to change how fzf.kak behaves.
|
||||
Each `.kak` file provides a Kakoune module, so any settings which alter variable values should be wrapped in 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
|
||||
**fzf.kak** by default will use main selection as default query for fzf, if the
|
||||
selection more than 1 character long (because cursor is simply 1-char
|
||||
selection). You can disable this behavior by setting `fzf_use_main_selection` to
|
||||
`false`.
|
||||
|
||||
| module |
|
||||
|--------|
|
||||
| `fzf` |
|
||||
|
||||
By default main selection is used as the default query for `fzf`, but only if the selection is more than 1 character long.
|
||||
This can be disabled by setting `fzf_use_main_selection` to `false`.
|
||||
|
||||
|
||||
### Windowing
|
||||
If you're using Tmux, you do not have to worry about windowing, since fzf.kak
|
||||
automatically creates all needed Tmux splits and panes for you. However in case
|
||||
you're not using Tmux, fzf.kak uses `fzf_terminal_command` option to call windowing
|
||||
command to create new windows. By default it is set to use `terminal` alias:
|
||||
`terminal kak -c %val{session} -e "%arg{@}"`, but some terminals can provide
|
||||
other aliases or commands, like `terminal-tab` in Kitty. You may want to edit
|
||||
this variable accordingly to your personal preferences.
|
||||
|
||||
| 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
|
||||
You can define what keys to use in `fzf` window via these options:
|
||||
|
||||
- `fzf_window_map` - mapping to perform an action in new window,
|
||||
- `fzf_vertical_map` - mapping to perform an action in new vertical split
|
||||
(Tmux),
|
||||
| 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.
|
||||
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_highlight_command` 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
|
||||
**fzf.kak** can store and load your projects. For that It creates a hidden file
|
||||
in your `%val{config}` called `.fzf-projects`. You can change the location of
|
||||
this file and its name with `fzf_project_file` option. You also can choose which
|
||||
method to use when storing projects. You can either convert your `$HOME` to `~/`
|
||||
or use plain `$HOME` in your path. This behavior is configured with
|
||||
`fzf_project_use_tilda` option, which accepts `true` and `false` values.
|
||||
|
||||
| module |
|
||||
|---------------|
|
||||
| `fzf-project` |
|
||||
|
||||
fzf.kak has basic project manipulation capabilities.
|
||||
|
||||
To store projects a hidden file is created in `%val{config}` and called `.fzf-projects`.
|
||||
The location of this file and its name can be changed by modifying the `fzf_project_file` option.
|
||||
By default project paths 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.
|
||||
|
||||
Of course modules can and will be more complex, since a good module checks if
|
||||
command for providing item list is available on user's machine, and supports
|
||||
various settings inside it. Feel free to look how existing modules are made.
|
||||
|
||||
### External modules
|
||||
Support for [yank-ring.kak][25] was externalized to separate plugin
|
||||
[fzf-yank-ring.kak][24]
|
||||
|
||||
Support for [yank-ring.kak][25] was externalized to separate plugin [fzf-yank-ring.kak][24]
|
||||
|
||||
|
||||
# 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`.
|
||||
|
||||
|
||||
[1]: https://img.shields.io/github/release/andreyorst/fzf.kak.svg
|
||||
[2]: https://github.com/andreyorst/fzf.kak/releases
|
||||
|
@ -307,3 +298,10 @@ Support for [yank-ring.kak][25] was externalized to separate plugin
|
|||
[23]: #configuration
|
||||
[24]: https://gitlab.com/losnappas/fzf-yank-ring.kak
|
||||
[25]: https://github.com/alexherbo2/yank-ring.kak
|
||||
[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
|
||||
-->
|
||||
|
|
87
rc/fzf.kak
87
rc/fzf.kak
|
@ -1,12 +1,7 @@
|
|||
# ╭─────────────╥───────────────────╮
|
||||
# │ Author: ║ Plugin: │
|
||||
# │ Andrey Orst ║ fzf.kak │
|
||||
# ╞═════════════╩═══════════════════╡
|
||||
# │ This plugin implements fzf │
|
||||
# │ mode for Kakoune. This mode │
|
||||
# │ adds several mappings to invoke │
|
||||
# │ different fzf commands. │
|
||||
# ╰─────────────────────────────────╯
|
||||
# Author: Andrey Listopadov
|
||||
# This plugin implements fzf mode for Kakoune.
|
||||
# This mode adds several mappings to invoke different fzf commands.
|
||||
# https://github.com/andreyorst/fzf.kak
|
||||
|
||||
define-command -docstring "Enter fzf-mode.
|
||||
fzf-mode contains mnemonic key bindings for every fzf.kak command
|
||||
|
@ -84,11 +79,16 @@ 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 new window when not using tmux.
|
||||
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
|
||||
|
||||
|
@ -109,10 +109,10 @@ fzf-horizontal -params .. %{ evaluate-commands %{
|
|||
|
||||
define-command -hidden -docstring "wrapper command to create new terminal" \
|
||||
fzf-window -params .. %{ evaluate-commands %sh{
|
||||
if [ -n "$kak_client_env_TMUX" ]; then
|
||||
if [ -n "${kak_client_env_TMUX:-}" ]; then
|
||||
printf "%s\n" 'tmux-terminal-window kak -c %val{session} -e "%arg{@}"'
|
||||
else
|
||||
printf "%s\n" "$kak_opt_fzf_terminal_command"
|
||||
printf "%s\n" "${kak_opt_fzf_new_terminal_command:?}"
|
||||
fi
|
||||
}}
|
||||
|
||||
|
@ -141,12 +141,15 @@ Switches:
|
|||
-post-action"
|
||||
} \
|
||||
fzf -params .. %{ evaluate-commands %sh{
|
||||
fzf_impl="${kak_opt_fzf_implementation}"
|
||||
fzf_impl="${kak_opt_fzf_implementation:?}"
|
||||
|
||||
[ "${kak_opt_fzf_use_main_selection}" = "true" ] && \
|
||||
[ $(printf "%s" "${kak_selection}" | wc -m) -gt 1 ] && \
|
||||
[ $(printf "%s" "${kak_selection}" | wc -l) -eq 1 ] && \
|
||||
default_query="-i -q ${kak_selection}"
|
||||
# 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
|
||||
|
@ -167,29 +170,29 @@ fzf -params .. %{ evaluate-commands %sh{
|
|||
|
||||
if [ "${preview}" = "true" ]; then
|
||||
# bake position option to define them at runtime
|
||||
[ -n "${kak_client_env_TMUX}" ] && tmux_height="${kak_opt_fzf_preview_tmux_height}"
|
||||
case ${kak_opt_fzf_preview_pos} in
|
||||
(top|up) preview_position="pos=top:${kak_opt_fzf_preview_height};" ;;
|
||||
(bottom|down) preview_position="pos=down:${kak_opt_fzf_preview_height};" ;;
|
||||
(right) preview_position="pos=right:${kak_opt_fzf_preview_width};" ;;
|
||||
(left) preview_position="pos=left:${kak_opt_fzf_preview_width};" ;;
|
||||
(auto|*) preview_position="sleep 0.1; [ \$(tput cols) -gt \$(expr \$(tput lines) \* 2) ] && pos=right:${kak_opt_fzf_preview_width} || pos=top:${kak_opt_fzf_preview_height};"
|
||||
[ -n "${kak_client_env_TMUX:-}" ] && tmux_height="${kak_opt_fzf_preview_tmux_height:-}"
|
||||
case ${kak_opt_fzf_preview_pos:-} in
|
||||
(top|up) preview_position="pos=top:${kak_opt_fzf_preview_height:-};" ;;
|
||||
(bottom|down) preview_position="pos=down:${kak_opt_fzf_preview_height:-};" ;;
|
||||
(right) preview_position="pos=right:${kak_opt_fzf_preview_width:-};" ;;
|
||||
(left) preview_position="pos=left:${kak_opt_fzf_preview_width:-};" ;;
|
||||
(auto|*) preview_position="sleep 0.1; [ \$(tput cols) -gt \$(expr \$(tput lines) \* 2) ] && pos=right:${kak_opt_fzf_preview_width:-} || pos=top:${kak_opt_fzf_preview_height:-};"
|
||||
esac
|
||||
|
||||
# handle preview if not defined explicitly with `-preview-cmd'
|
||||
if [ ${kak_opt_fzf_preview} = "true" ] && [ -z "${preview_cmd}" ]; then
|
||||
case ${kak_opt_fzf_highlight_command} in
|
||||
if [ "${kak_opt_fzf_preview:-}" = "true" ] && [ -z "${preview_cmd}" ]; then
|
||||
case ${kak_opt_fzf_highlight_command:-} in
|
||||
(bat) highlight_cmd="bat --color=always --style=plain {}" ;;
|
||||
(coderay) highlight_cmd="coderay {}" ;;
|
||||
(highlight) highlight_cmd="highlight --failsafe -O ansi {}" ;;
|
||||
(rouge) highlight_cmd="rougify {}" ;;
|
||||
(*) highlight_cmd="${kak_opt_fzf_highlight_command}" ;;
|
||||
esac
|
||||
preview_cmd="--preview '(${highlight_cmd} || cat {}) 2>/dev/null | head -n ${kak_opt_fzf_preview_lines}' --preview-window=\${pos}"
|
||||
preview_cmd="--preview '(${highlight_cmd} || cat {}) 2>/dev/null | head -n ${kak_opt_fzf_preview_lines:-}' --preview-window=\${pos}"
|
||||
fi
|
||||
fi
|
||||
|
||||
fzf_tmp=$(mktemp -d ${TMPDIR:-/tmp}/fzf.kak.XXXXXX)
|
||||
fzf_tmp=$(mktemp -d "${TMPDIR:-/tmp}"/fzf.kak.XXXXXX)
|
||||
fzfcmd="${fzf_tmp}/fzfcmd"
|
||||
result="${fzf_tmp}/result"
|
||||
|
||||
|
@ -202,19 +205,19 @@ fzf -params .. %{ evaluate-commands %sh{
|
|||
printf "%s\n" "SHELL=${shell_path}"
|
||||
fi
|
||||
# compose entire fzf command with all args into single file which will be executed later
|
||||
printf "%s\n" "export FZF_DEFAULT_OPTS=\"$kak_opt_fzf_default_opts\""
|
||||
printf "%s\n" "export FZF_DEFAULT_OPTS=\"${kak_opt_fzf_default_opts:-}\""
|
||||
printf "%s\n" "cd \"${PWD}\" && ${preview_position} ${items_cmd} ${fzf_impl} ${default_query} ${fzf_args} ${preview_cmd} ${filter} > ${result}"
|
||||
printf "%s\n" "rm ${fzfcmd}"
|
||||
) >> ${fzfcmd}
|
||||
chmod 755 ${fzfcmd}
|
||||
) >> "${fzfcmd}"
|
||||
chmod 755 "${fzfcmd}"
|
||||
|
||||
if [ -n "${kak_client_env_TMUX}" ]; then
|
||||
# set default height if not set already
|
||||
[ -z "${tmux_height}" ] && tmux_height=${kak_opt_fzf_tmux_height}
|
||||
[ -z "${tmux_height}" ] && tmux_height=${kak_opt_fzf_tmux_height:-}
|
||||
# if height contains `%' then `-p' will be used
|
||||
[ -n "${tmux_height%%*%}" ] && measure="-l" || measure="-p"
|
||||
# `terminal' doesn't support any kind of width and height parameters, so tmux panes are created by tmux itself
|
||||
cmd="nop %sh{ command tmux split-window -t '${kak_client_env_TMUX_PANE}' ${measure} ${tmux_height%%%*} env ${fzfcmd} < /dev/null > /dev/null 2>&1 }"
|
||||
cmd="nop %sh{ command tmux split-window -t '${kak_client_env_TMUX_PANE:-}' ${measure} ${tmux_height%%%*} env ${fzfcmd} < /dev/null > /dev/null 2>&1 }"
|
||||
else
|
||||
cmd="${kak_opt_fzf_terminal_command%% *} %{${fzfcmd}}"
|
||||
fi
|
||||
|
@ -222,20 +225,20 @@ fzf -params .. %{ evaluate-commands %sh{
|
|||
printf "%s\n" "${cmd}"
|
||||
|
||||
# main loop
|
||||
( while [ -e ${fzfcmd} ]; do sleep 0.1; done
|
||||
if [ -s ${result} ]; then
|
||||
( while [ -e "${fzfcmd}" ]; do sleep 0.1; done
|
||||
if [ -s "${result}" ]; then
|
||||
(
|
||||
while read -r line; do
|
||||
case ${line} in
|
||||
(${kak_opt_fzf_window_map}) wincmd="fzf-window" ;;
|
||||
(${kak_opt_fzf_vertical_map}) wincmd="fzf-vertical" ;;
|
||||
(${kak_opt_fzf_horizontal_map}) wincmd="fzf-horizontal" ;;
|
||||
(*) item=${line} ;;
|
||||
("${kak_opt_fzf_window_map:-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
|
||||
item=$(printf "%s\n" "${item}" | sed "s/@/@@/g;s/&/&&/g")
|
||||
kakoune_cmd=$(printf "%s\n" "${kakoune_cmd}" | sed "s/&/&&/g")
|
||||
printf "%s\n" "evaluate-commands -client ${kak_client} ${wincmd} %&${kakoune_cmd} %@${item}@&"
|
||||
printf "%s\n" "evaluate-commands -client ${kak_client:?} ${wincmd} %&${kakoune_cmd} %@${item}@&"
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
@ -248,9 +251,9 @@ fzf -params .. %{ evaluate-commands %sh{
|
|||
post_action=$(printf "%s\n" "${post_action}" | sed "s/&/&&/g")
|
||||
printf "%s\n" "evaluate-commands -client ${kak_client} %&${post_action}&"
|
||||
fi
|
||||
) < ${result} | kak -p ${kak_session}
|
||||
) < "${result}" | kak -p "${kak_session:?}"
|
||||
fi
|
||||
rm -rf ${fzf_tmp}
|
||||
rm -rf "${fzf_tmp}"
|
||||
) > /dev/null 2>&1 < /dev/null &
|
||||
}}
|
||||
|
||||
|
|
|
@ -1,13 +1,12 @@
|
|||
# ╭─────────────╥─────────────────────────╮
|
||||
# │ Author: ║ File: │
|
||||
# │ Andrey Orst ║ fzf-svn.kak │
|
||||
# ╞═════════════╩═════════════════════════╡
|
||||
# │ Submodule for Bzr support for fzf.kak │
|
||||
# ╞═══════════════════════════════════════╡
|
||||
# │ GitHub.com/andreyorst/fzf.kak │
|
||||
# ╰───────────────────────────────────────╯
|
||||
# Author: Andrey Listopadov
|
||||
# Submodule for Bzr support for fzf.kak
|
||||
# https://github.com/andreyorst/fzf.kak
|
||||
|
||||
hook global ModuleLoaded fzf_vcs %§
|
||||
hook global ModuleLoaded fzf-vcs %{
|
||||
map global fzf-vcs -docstring "edit file from GNU Bazaar tree" 'b' '<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:
|
||||
|
@ -19,16 +18,14 @@ Default arguments:
|
|||
" \
|
||||
str fzf_bzr_command "bzr"
|
||||
|
||||
map global fzf-vcs -docstring "edit file from GNU Bazaar tree" 'b' '<esc>: fzf-bzr<ret>'
|
||||
|
||||
define-command -hidden fzf-bzr %{ evaluate-commands %sh{
|
||||
repo_root=$(bzr root)
|
||||
case $kak_opt_fzf_bzr_command in
|
||||
(bzr) cmd="(cd $repo_root && bzr ls -R --versioned)" ;;
|
||||
(*) cmd=$kak_opt_fzf_bzr_command ;;
|
||||
esac
|
||||
[ ! -z "${kak_client_env_TMUX}" ] && additional_flags="--expect $kak_opt_fzf_vertical_map --expect $kak_opt_fzf_horizontal_map"
|
||||
printf "%s\n" "fzf -kak-cmd %{edit -existing} -items-cmd %{$cmd} -fzf-args %{-m --expect $kak_opt_fzf_window_map $additional_flags} -filter %{perl -pe \"if (/$kak_opt_fzf_window_map|$kak_opt_fzf_vertical_map|$kak_opt_fzf_horizontal_map|^$/) {} else {print \\\"$repo_root/\\\"}\"}"
|
||||
[ -n "${kak_client_env_TMUX}" ] && additional_flags="--expect ${kak_opt_fzf_vertical_map:-ctrl-v} --expect ${kak_opt_fzf_horizontal_map:-ctrl-s}"
|
||||
printf "%s\n" "fzf -kak-cmd %{edit -existing} -items-cmd %{$cmd} -fzf-args %{-m --expect ${kak_opt_fzf_window_map:-ctrl-w} $additional_flags} -filter %{perl -pe \"if (/${kak_opt_fzf_window_map:-ctrl-w}|${kak_opt_fzf_vertical_map:-ctrl-v}|${kak_opt_fzf_horizontal_map:-ctrl-s}|^$/) {} else {print \\\"$repo_root/\\\"}\"}"
|
||||
}}
|
||||
|
||||
§
|
||||
|
|
|
@ -1,13 +1,12 @@
|
|||
# ╭─────────────╥─────────────────────────╮
|
||||
# │ Author: ║ File: │
|
||||
# │ Andrey Orst ║ fzf-svn.kak │
|
||||
# ╞═════════════╩═════════════════════════╡
|
||||
# │ Submodule for Git support for fzf.kak │
|
||||
# ╞═══════════════════════════════════════╡
|
||||
# │ GitHub.com/andreyorst/fzf.kak │
|
||||
# ╰───────────────────────────────────────╯
|
||||
# Author: Andrey Listopadov
|
||||
# Submodule for Git support for fzf.kak
|
||||
# https://github.com/andreyorst/fzf.kak
|
||||
|
||||
hook global ModuleLoaded fzf_vcs %§
|
||||
hook global ModuleLoaded fzf-vcs %§
|
||||
map global fzf-vcs -docstring "edit file from Git tree" 'g' '<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:
|
||||
|
@ -19,16 +18,14 @@ Default arguments:
|
|||
" \
|
||||
str fzf_git_command "git"
|
||||
|
||||
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 -hidden fzf-git %{ evaluate-commands %sh{
|
||||
|
||||
case $kak_opt_fzf_git_command in
|
||||
(git) cmd='git ls-tree --full-tree --name-only -r HEAD' ;;
|
||||
(*) cmd=$kak_opt_fzf_git_command ;;
|
||||
esac
|
||||
[ ! -z "${kak_client_env_TMUX}" ] && additional_flags="--expect $kak_opt_fzf_vertical_map --expect $kak_opt_fzf_horizontal_map"
|
||||
printf "%s\n" "fzf -kak-cmd %{edit -existing} -items-cmd %{$cmd} -fzf-args %{-m --expect $kak_opt_fzf_window_map $additional_flags} -filter %{perl -pe \"if (/$kak_opt_fzf_window_map|$kak_opt_fzf_vertical_map|$kak_opt_fzf_horizontal_map|^$/) {} else {print \\\"$(git rev-parse --show-toplevel)/\\\"}\"}"
|
||||
[ ! -z "${kak_client_env_TMUX}" ] && additional_flags="--expect ${kak_opt_fzf_vertical_map:-ctrl-v} --expect ${kak_opt_fzf_horizontal_map:-ctrl-s}"
|
||||
printf "%s\n" "fzf -kak-cmd %{edit -existing} -items-cmd %{$cmd} -fzf-args %{-m --expect ${kak_opt_fzf_window_map:-ctrl-w} $additional_flags} -filter %{perl -pe \"if (/${kak_opt_fzf_window_map:-ctrl-w}|${kak_opt_fzf_vertical_map:-ctrl-v}|${kak_opt_fzf_horizontal_map:-ctrl-s}|^$/) {} else {print \\\"$(git rev-parse --show-toplevel)/\\\"}\"}"
|
||||
}}
|
||||
|
||||
§
|
||||
|
|
|
@ -1,13 +1,12 @@
|
|||
# ╭─────────────╥────────────────────────╮
|
||||
# │ Author: ║ File: │
|
||||
# │ Andrey Orst ║ fzf-svn.kak │
|
||||
# ╞═════════════╩════════════════════════╡
|
||||
# │ Submodule for Hg support for fzf.kak │
|
||||
# ╞══════════════════════════════════════╡
|
||||
# │ GitHub.com/andreyorst/fzf.kak │
|
||||
# ╰──────────────────────────────────────╯
|
||||
# Author: Andrey Listopadov
|
||||
# Submodule for Hg support for fzf.kak
|
||||
# https://github.com/andreyorst/fzf.kak
|
||||
|
||||
hook global ModuleLoaded fzf_vcs %§
|
||||
hook global ModuleLoaded fzf-vcs %{
|
||||
map global fzf-vcs -docstring "edit file from mercurial tree" 'h' '<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:
|
||||
|
@ -19,15 +18,14 @@ Default arguments:
|
|||
" \
|
||||
str fzf_hg_command "hg"
|
||||
|
||||
map global fzf-vcs -docstring "edit file from mercurial tree" 'h' '<esc>: fzf-hg<ret>'
|
||||
|
||||
define-command -hidden fzf-hg %{ evaluate-commands %sh{
|
||||
case $kak_opt_fzf_hg_command in
|
||||
(hg) cmd="hg locate -f" ;;
|
||||
(hg*) cmd=$kak_opt_fzf_hg_command ;;
|
||||
esac
|
||||
[ ! -z "${kak_client_env_TMUX}" ] && additional_flags="--expect $kak_opt_fzf_vertical_map --expect $kak_opt_fzf_horizontal_map"
|
||||
printf "%s\n" "fzf -kak-cmd %{edit -existing} -items-cmd %{$cmd} -fzf-args %{-m --expect $kak_opt_fzf_window_map $additional_flags}"
|
||||
[ ! -z "${kak_client_env_TMUX}" ] && additional_flags="--expect ${kak_opt_fzf_vertical_map:-ctrl-v} --expect ${kak_opt_fzf_horizontal_map:-ctrl-s}"
|
||||
printf "%s\n" "fzf -kak-cmd %{edit -existing} -items-cmd %{$cmd} -fzf-args %{-m --expect ${kak_opt_fzf_window_map:-ctrl-w} $additional_flags}"
|
||||
}}
|
||||
|
||||
§
|
||||
|
|
|
@ -1,13 +1,12 @@
|
|||
# ╭─────────────╥─────────────────────────╮
|
||||
# │ Author: ║ File: │
|
||||
# │ Andrey Orst ║ fzf-svn.kak │
|
||||
# ╞═════════════╩═════════════════════════╡
|
||||
# │ Submodule for Svn support for fzf.kak │
|
||||
# ╞═══════════════════════════════════════╡
|
||||
# │ GitHub.com/andreyorst/fzf.kak │
|
||||
# ╰───────────────────────────────────────╯
|
||||
# Author: Andrey Listopadov
|
||||
# Submodule for Svn support for fzf.kak
|
||||
# https://github.com/andreyorst/fzf.kak
|
||||
|
||||
hook global ModuleLoaded fzf_vcs %§
|
||||
hook global ModuleLoaded fzf-vcs %§
|
||||
map global fzf-vcs -docstring "edit file from Subversion tree" 's' '<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:
|
||||
|
@ -19,8 +18,6 @@ Default arguments:
|
|||
" \
|
||||
str fzf_svn_command "svn"
|
||||
|
||||
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}')
|
||||
|
@ -28,8 +25,8 @@ define-command -hidden fzf-svn %{ evaluate-commands %sh{
|
|||
(svn) cmd="svn list -R $repo_root | grep -v '$/'" ;;
|
||||
(svn*) cmd=$kak_opt_fzf_svn_command ;;
|
||||
esac
|
||||
[ ! -z "${kak_client_env_TMUX}" ] && additional_flags="--expect $kak_opt_fzf_vertical_map --expect $kak_opt_fzf_horizontal_map"
|
||||
printf "%s\n" "fzf -kak-cmd %{cd $repo_root; edit -existing} -items-cmd %{$cmd} -fzf-args %{-m --expect $kak_opt_fzf_window_map $additional_flags} -post-action %{cd $current_path}"
|
||||
[ ! -z "${kak_client_env_TMUX}" ] && additional_flags="--expect ${kak_opt_fzf_vertical_map:-ctrl-v} --expect ${kak_opt_fzf_horizontal_map:-ctrl-s}"
|
||||
printf "%s\n" "fzf -kak-cmd %{cd $repo_root; edit -existing} -items-cmd %{$cmd} -fzf-args %{-m --expect ${kak_opt_fzf_window_map:-ctrl-w} $additional_flags} -post-action %{cd $current_path}"
|
||||
}}
|
||||
|
||||
§
|
||||
|
|
|
@ -1,21 +1,17 @@
|
|||
# ╭─────────────╥────────────────────────╮
|
||||
# │ Author: ║ File: │
|
||||
# │ Andrey Orst ║ fzf-buffer.kak │
|
||||
# ╞═════════════╩════════════════════════╡
|
||||
# │ Module for changing buffers with fzf │
|
||||
# │ for fzf.kak plugin │
|
||||
# ╞══════════════════════════════════════╡
|
||||
# │ GitHub.com/andreyorst/fzf.kak │
|
||||
# ╰──────────────────────────────────────╯
|
||||
# Author: Andrey Listopadov
|
||||
# Module for changing buffers with fzf for fzf.kak plugin
|
||||
# https://github.com/andreyorst/fzf.kak
|
||||
|
||||
hook global ModuleLoaded fzf %§
|
||||
hook global ModuleLoaded fzf %{
|
||||
map global fzf -docstring "open buffer" 'b' '<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>'
|
||||
}
|
||||
|
||||
map global fzf -docstring "open buffer" 'b' '<esc>: fzf-buffer<ret>'
|
||||
map global fzf -docstring "delete buffer" '<a-b>' '<esc>: fzf-delete-buffer<ret>'
|
||||
provide-module fzf-buffer %§
|
||||
|
||||
define-command -hidden fzf-buffer %{ evaluate-commands %sh{
|
||||
buffers=""
|
||||
eval "set -- $kak_quoted_buflist"
|
||||
eval "set -- ${kak_quoted_buflist:?}"
|
||||
while [ $# -gt 0 ]; do
|
||||
buffers="$1
|
||||
$buffers"
|
||||
|
@ -24,19 +20,19 @@ $buffers"
|
|||
|
||||
message="Set buffer to edit in current client.
|
||||
<ret>: switch to selected buffer.
|
||||
$kak_opt_fzf_window_map: open buffer in new window"
|
||||
[ ! -z "${kak_client_env_TMUX}" ] && tmux_keybindings="
|
||||
$kak_opt_fzf_horizontal_map: open buffer in horizontal split
|
||||
$kak_opt_fzf_vertical_map: open buffer in vertical split"
|
||||
${kak_opt_fzf_window_map:-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 $kak_opt_fzf_vertical_map --expect $kak_opt_fzf_horizontal_map"
|
||||
[ -n "${kak_client_env_TMUX:-}" ] && additional_flags="--expect ${kak_opt_fzf_vertical_map:-ctrl-v} --expect ${kak_opt_fzf_horizontal_map:-ctrl-s}"
|
||||
|
||||
printf "%s\n" "fzf -kak-cmd %{buffer} -items-cmd %{printf \"%s\n\" \"$buffers\"} -fzf-args %{--expect $kak_opt_fzf_window_map $additional_flags}"
|
||||
printf "%s\n" "fzf -kak-cmd %{buffer} -items-cmd %{printf \"%s\n\" \"$buffers\"} -fzf-args %{--expect ${kak_opt_fzf_window_map:-ctrl-w} $additional_flags}"
|
||||
}}
|
||||
|
||||
define-command -hidden fzf-delete-buffer %{ evaluate-commands %sh{
|
||||
buffers=""
|
||||
eval "set -- $kak_quoted_buflist"
|
||||
eval "set -- ${kak_quoted_buflist:?}"
|
||||
while [ $# -gt 0 ]; do
|
||||
buffers="$1
|
||||
$buffers"
|
||||
|
@ -46,7 +42,7 @@ $buffers"
|
|||
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 $additional_flags}"
|
||||
printf "%s\n" "fzf -kak-cmd %{delete-buffer} -multiple-cmd %{delete-buffer} -items-cmd %{printf \"%s\n\" \"$buffers\"} -fzf-args %{-m --expect ${kak_opt_fzf_window_map:-ctrl-w} ${additional_flags:-}}"
|
||||
}}
|
||||
|
||||
§
|
||||
|
|
|
@ -1,14 +1,12 @@
|
|||
# ╭─────────────╥────────────────────────╮
|
||||
# │ Author: ║ File: │
|
||||
# │ Andrey Orst ║ fzf-cd.kak │
|
||||
# ╞═════════════╩════════════════════════╡
|
||||
# │ Module for changing directories with │
|
||||
# │ fzf for fzf.kak plugin │
|
||||
# ╞══════════════════════════════════════╡
|
||||
# │ GitHub.com/andreyorst/fzf.kak │
|
||||
# ╰──────────────────────────────────────╯
|
||||
# Author: Andrey Listopadov
|
||||
# Module for changing directories with fzf for fzf.kak plugin
|
||||
# https://github.com/andreyorst/fzf.kak
|
||||
|
||||
hook global ModuleLoaded fzf %§
|
||||
hook global ModuleLoaded fzf %{
|
||||
map global fzf -docstring "change directory" 'c' '<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:
|
||||
|
@ -31,20 +29,16 @@ str cd_preview_command "tree -d {}"
|
|||
declare-option -docstring 'maximum amount of previewed directories' \
|
||||
int fzf_preview_dirs '300'
|
||||
|
||||
|
||||
map global fzf -docstring "change directory" 'c' '<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
|
||||
case ${kak_opt_fzf_cd_command:-} in
|
||||
(find) items_command="(echo .. && find . \( -path '*/.svn*' -o -path '*/.git*' \) -prune -o -type d -print)" ;;
|
||||
(*) items_command=$kak_opt_fzf_cd_command ;;
|
||||
esac
|
||||
if [ "$kak_opt_fzf_cd_preview" = "true" ]; then
|
||||
if [ "${kak_opt_fzf_cd_preview:-}" = "true" ]; then
|
||||
preview_flag="-preview"
|
||||
preview="--preview '($kak_opt_cd_preview_command) 2>/dev/null | head -n $kak_opt_fzf_preview_dirs'"
|
||||
preview="--preview '(${kak_opt_cd_preview_command:-}) 2>/dev/null | head -n ${kak_opt_fzf_preview_dirs:-0}'"
|
||||
fi
|
||||
printf "%s\n" "fzf $preview_flag -kak-cmd %{change-directory} -items-cmd %{$items_command} -preview-cmd %{$preview} -post-action %{fzf-cd}"
|
||||
}}
|
||||
|
|
|
@ -1,20 +1,17 @@
|
|||
# ╭─────────────╥──────────────────────────╮
|
||||
# │ Author: ║ File: │
|
||||
# │ Andrey Orst ║ fzf-ctags.kak │
|
||||
# ╞═════════════╩══════════════════════════╡
|
||||
# │ Module for searching tags with fzf │
|
||||
# │ and universal-ctags for fzf.kak plugin │
|
||||
# ╞════════════════════════════════════════╡
|
||||
# │ GitHub.com/andreyorst/fzf.kak │
|
||||
# ╰────────────────────────────────────────╯
|
||||
# Author: Andrey Listopadov
|
||||
# Module for searching tags with fzf and universal-ctags for fzf.kak plugin
|
||||
# https://github.com/andreyorst/fzf.kak
|
||||
|
||||
hook global ModuleLoaded fzf %§
|
||||
hook global ModuleLoaded fzf %{
|
||||
map global fzf -docstring "find tag" 't' '<esc>: require-module fzf-ctags; fzf-tag<ret>'
|
||||
}
|
||||
|
||||
provide-module fzf-ctags %§
|
||||
|
||||
declare-option -docstring "file that should be used by fzf-tag to provide tags.
|
||||
Default value: tags" \
|
||||
str fzf_tag_file_name "tags"
|
||||
|
||||
map global fzf -docstring "find tag" 't' '<esc>: fzf-tag<ret>'
|
||||
|
||||
declare-option -hidden bool fzf_tag_filters_defined false
|
||||
|
||||
|
@ -26,9 +23,9 @@ try %{
|
|||
# this huge try block defines filetype aware filter mappings for separate fzf-ctags mode
|
||||
define-command -hidden fzf-setup-filter-tags %{
|
||||
evaluate-commands %sh{
|
||||
[ "$opt_fzf_tag_filters_defined" = "true" ] && exit
|
||||
[ "${kak_opt_fzf_tag_filters_defined:-}" = "true" ] && exit
|
||||
|
||||
case $kak_opt_filetype in
|
||||
case ${kak_opt_filetype:-} in
|
||||
(ada) printf "%s\n" "
|
||||
map global fzf-ctags '<a-p>' ': fzf-tag P<ret>' -docstring 'package specifications'
|
||||
map global fzf-ctags 'p' ': fzf-tag p<ret>' -docstring 'packages'
|
||||
|
@ -901,7 +898,7 @@ define-command -hidden fzf-setup-filter-tags %{
|
|||
define-command -hidden fzf-tag -params ..2 %{ evaluate-commands %sh{
|
||||
path=$PWD
|
||||
while [ "$path" != "$HOME" ]; do
|
||||
if [ -e "./$kak_opt_fzf_tag_file_name" ]; then
|
||||
if [ -e "./${kak_opt_fzf_tag_file_name:-}" ]; then
|
||||
break
|
||||
else
|
||||
cd ..
|
||||
|
@ -917,7 +914,7 @@ define-command -hidden fzf-tag -params ..2 %{ evaluate-commands %sh{
|
|||
fi
|
||||
|
||||
cmd="cd $path;"
|
||||
if [ -n "$(command -v ${kak_opt_readtagscmd})" ]; then
|
||||
if [ -n "$(command -v "${kak_opt_readtagscmd%% *}")" ]; then
|
||||
if [ -n "$1" ]; then
|
||||
cmd="${cmd} ${kak_opt_readtagscmd} -t $kak_opt_fzf_tag_file_name -Q '(eq? \$kind \"$1\")' -l"
|
||||
else
|
||||
|
@ -931,17 +928,17 @@ define-command -hidden fzf-tag -params ..2 %{ evaluate-commands %sh{
|
|||
|
||||
message="Jump to a symbol''s definition
|
||||
<ret>: open tag in new buffer
|
||||
$kak_opt_fzf_window_map: open tag in new terminal"
|
||||
${kak_opt_fzf_window_map:-ctrl-w}: open tag in new terminal"
|
||||
|
||||
[ -n "${kak_client_env_TMUX}" ] && tmux_keybindings="
|
||||
$kak_opt_fzf_horizontal_map: open tag in horizontal split
|
||||
$kak_opt_fzf_vertical_map: open tag in vertical split"
|
||||
[ -n "${kak_client_env_TMUX:-}" ] && tmux_keybindings="
|
||||
${kak_opt_fzf_horizontal_map:-ctrl-s}: open tag in horizontal split
|
||||
${kak_opt_fzf_vertical_map:-ctrl-v}: open tag in vertical split"
|
||||
|
||||
printf "%s\n" "info -title 'fzf tag' '$message$tmux_keybindings'"
|
||||
|
||||
[ ! -z "${kak_client_env_TMUX}" ] && additional_flags="--expect $kak_opt_fzf_vertical_map --expect $kak_opt_fzf_horizontal_map"
|
||||
[ -n "${kak_client_env_TMUX}" ] && additional_flags="--expect ${kak_opt_fzf_vertical_map:-ctrl-v} --expect ${kak_opt_fzf_horizontal_map:-ctrl-s}"
|
||||
printf "%s\n" "set-option -add window ctagsfiles %{$path/$kak_opt_fzf_tag_file_name}"
|
||||
printf "%s\n" "fzf -kak-cmd %{ctags-search} -items-cmd %{$cmd | awk '!a[\$0]++'} -fzf-args %{--expect $kak_opt_fzf_window_map $additional_flags}"
|
||||
printf "%s\n" "fzf -kak-cmd %{ctags-search} -items-cmd %{$cmd | awk '!a[\$0]++'} -fzf-args %{--expect ${kak_opt_fzf_window_map:-ctrl-w} $additional_flags}"
|
||||
}}
|
||||
|
||||
§
|
||||
|
|
|
@ -1,14 +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 %§
|
||||
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:
|
||||
|
@ -32,10 +31,19 @@ Default value:
|
|||
' \
|
||||
bool fzf_file_preview true
|
||||
|
||||
map global fzf -docstring "open file" 'f' '<esc>: fzf-file<ret>'
|
||||
|
||||
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
|
||||
|
@ -50,18 +58,25 @@ define-command -hidden fzf-file %{ evaluate-commands %sh{
|
|||
cmd=$kak_opt_fzf_file_command ;;
|
||||
esac
|
||||
|
||||
cmd="$cmd 2>/dev/null"
|
||||
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.
|
||||
$kak_opt_fzf_window_map: open file in new terminal"
|
||||
[ ! -z "${kak_client_env_TMUX}" ] && tmux_keybindings="
|
||||
$kak_opt_fzf_horizontal_map: open file in horizontal split
|
||||
$kak_opt_fzf_vertical_map: open file in vertical split"
|
||||
${kak_opt_fzf_window_map:-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 $kak_opt_fzf_vertical_map --expect $kak_opt_fzf_horizontal_map"
|
||||
[ "$kak_opt_fzf_file_preview" = "true" ] && preview_flag="-preview"
|
||||
printf "%s\n" "fzf $preview_flag -kak-cmd %{edit -existing} -items-cmd %{$cmd} -fzf-args %{-m --expect $kak_opt_fzf_window_map $additional_flags}"
|
||||
[ -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}"
|
||||
}}
|
||||
|
||||
§
|
||||
|
|
|
@ -1,25 +1,25 @@
|
|||
# ╭─────────────╥────────────────────────╮
|
||||
# │ Author: ║ File: │
|
||||
# │ Andrey Orst ║ fzf-grep.kak │
|
||||
# ╞═════════════╩════════════════════════╡
|
||||
# │ Module for grepping file contents │
|
||||
# ╞══════════════════════════════════════╡
|
||||
# │ GitHub.com/andreyorst/fzf.kak │
|
||||
# ╰──────────────────────────────────────╯
|
||||
# Author: Andrey Listopadov
|
||||
# Module for grepping file contents
|
||||
# https://github.com/andreyorst/fzf.kak
|
||||
|
||||
hook global ModuleLoaded fzf %§
|
||||
hook global ModuleLoaded fzf %{
|
||||
map -docstring 'grep file contents recursively' global fzf g ': require-module fzf-grep; fzf-grep<ret>'
|
||||
}
|
||||
|
||||
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'
|
||||
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" \
|
||||
grep -RHn '' ." \
|
||||
str fzf_grep_command 'grep'
|
||||
|
||||
map -docstring 'grep file contents recursively' global fzf g ': fzf-grep<ret>'
|
||||
|
||||
define-command -hidden fzf-grep %{ evaluate-commands %sh{
|
||||
if [ -z "$(command -v $kak_opt_fzf_grep_command)" ]; then
|
||||
if [ -z "$(command -v "${kak_opt_fzf_grep_command%% *}")" ]; then
|
||||
printf "%s\n" "echo -markup '{Information}''$kak_opt_fzf_grep_command'' is not installed. Falling back to ''grep'''"
|
||||
kak_opt_fzf_grep_command="grep"
|
||||
fi
|
||||
|
@ -37,14 +37,14 @@ define-command -hidden fzf-grep %{ evaluate-commands %sh{
|
|||
title="fzf grep"
|
||||
message="grep through contents of all files recursively.
|
||||
<ret>: open search result in new buffer.
|
||||
$kak_opt_fzf_window_map: open search result in new terminal"
|
||||
[ ! -z "${kak_client_env_TMUX}" ] && tmux_keybindings="
|
||||
$kak_opt_fzf_horizontal_map: open search result in horizontal split
|
||||
$kak_opt_fzf_vertical_map: open search result in vertical split"
|
||||
${kak_opt_fzf_window_map:-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 $kak_opt_fzf_vertical_map --expect $kak_opt_fzf_horizontal_map"
|
||||
printf "%s\n" "fzf -kak-cmd %{evaluate-commands} -fzf-args %{--expect $kak_opt_fzf_window_map $additional_flags --delimiter=':' -n'3..'} -items-cmd %{$cmd} -filter %{sed -E 's/([^:]+):([^:]+):.*/edit -existing \1; execute-keys \2gvc/'}"
|
||||
[ -n "${kak_client_env_TMUX}" ] && additional_flags="--expect ${kak_opt_fzf_vertical_map:-ctrl-v} --expect ${kak_opt_fzf_horizontal_map:-ctrl-s}"
|
||||
printf "%s\n" "fzf -kak-cmd %{evaluate-commands} -fzf-args %{--expect ${kak_opt_fzf_window_map:-ctrl-w} $additional_flags --delimiter=':' -n'3..'} -items-cmd %{$cmd} -filter %{sed -E 's/([^:]+):([^:]+):.*/edit -existing \1; execute-keys \2gvc/'}"
|
||||
}}
|
||||
|
||||
§
|
||||
|
|
|
@ -1,19 +1,18 @@
|
|||
# ╭─────────────╥────────────────────────╮
|
||||
# │ Author: ║ File: │
|
||||
# │ Andrey Orst ║ fzf-project.kak │
|
||||
# ╞═════════════╩════════════════════════╡
|
||||
# │ Module for storing and loading │
|
||||
# │ projects with fzf for fzf.kak plugin │
|
||||
# ╞══════════════════════════════════════╡
|
||||
# │ GitHub.com/andreyorst/fzf.kak │
|
||||
# ╰──────────────────────────────────────╯
|
||||
# Author: Andrey Listopadov
|
||||
# Module for storing and loading projects with fzf for fzf.kak plugin
|
||||
# https://github.com/andreyorst/fzf.kak
|
||||
|
||||
hook global ModuleLoaded fzf %§
|
||||
hook global ModuleLoaded fzf %{
|
||||
map global fzf -docstring "open project" 'p' '<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
|
||||
|
||||
map global fzf -docstring "open project" 'p' '<esc>: fzf-project<ret>'
|
||||
|
||||
try %{ declare-user-mode fzf-project }
|
||||
|
||||
|
@ -25,7 +24,7 @@ map global fzf-project -docstring "delete project from project list" 'd' '<esc>:
|
|||
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_project_file} ]; then
|
||||
if [ -s "${kak_opt_fzf_project_file:-}" ]; then
|
||||
printf '%s\n' "info -title %{fzf open project} %{Change the server's working directory to selected project}"
|
||||
printf "%s\n" "fzf -kak-cmd change-directory -items-cmd %{cat ${kak_opt_fzf_project_file}} -fzf-args %{--reverse --delimiter=':' -n'1'} -post-action fzf-file -filter %{sed 's/.*: //'}"
|
||||
else
|
||||
|
@ -34,12 +33,12 @@ define-command -hidden fzf-project %{ evaluate-commands %sh{
|
|||
}}
|
||||
|
||||
define-command -hidden fzf-save-path-as-project %{ prompt -shell-script-candidates %{printf "%s\n" "${PWD##*/}"} "Project's name: " %{ evaluate-commands %sh{
|
||||
if [ -n "${kak_text}" ]; then
|
||||
if [ -n "${kak_text:-}" ]; then
|
||||
mkdir -p "${kak_opt_fzf_project_file%/*}"
|
||||
exists=$(grep "${kak_text}: " ${kak_opt_fzf_project_file})
|
||||
exists=$(grep "${kak_text}: " "${kak_opt_fzf_project_file:-}")
|
||||
if [ -z "${exists}" ]; then
|
||||
[ "${kak_opt_fzf_project_use_tilda}" = "false" ] && project_path=$(pwd) || project_path=$(pwd | perl -pe "s(${HOME})(~)")
|
||||
printf "%s: %s\n" "${kak_text}" "${project_path}" >> ${kak_opt_fzf_project_file}
|
||||
[ "${kak_opt_fzf_project_use_tilda:-true}" = "false" ] && project_path=$(pwd) || project_path=$(pwd | perl -pe "s(${HOME})(~)")
|
||||
printf "%s: %s\n" "${kak_text}" "${project_path}" >> "${kak_opt_fzf_project_file}"
|
||||
printf "%s\n" "echo -markup %{{Information}saved '$(pwd)' project as '${kak_text}'}"
|
||||
else
|
||||
printf "%s\n" "fzf-project-confirm-impl %{Project '${kak_text}' exists. Update? (y/N): } %{fzf-update-project-path-impl %{${kak_text}} %{${PWD}}} %{Project '${kak_text}' updated} %{Project '${kak_text}' kept}"
|
||||
|
@ -66,11 +65,11 @@ define-command -hidden fzf-save-path-as-project-no-prompt %{ evaluate-commands %
|
|||
esac
|
||||
printf "%s\n" "${base}"
|
||||
}
|
||||
project_name=$(base ${PWD})
|
||||
exists=$(grep "${project_name}: " ${kak_opt_fzf_project_file})
|
||||
project_name=$(base "${PWD}")
|
||||
exists=$(grep "${project_name}: " "${kak_opt_fzf_project_file}")
|
||||
if [ -z "${exists}" ]; then
|
||||
[ "${kak_opt_fzf_project_use_tilda}" = "false" ] && project_path=$(pwd) || project_path=$(pwd | perl -pe "s(${HOME})(~)")
|
||||
printf "%s: %s\n" "${project_name}" "${project_path}" >> ${kak_opt_fzf_project_file}
|
||||
[ "${kak_opt_fzf_project_use_tilda:-true}" = "false" ] && project_path=$(pwd) || project_path=$(pwd | perl -pe "s(${HOME})(~)")
|
||||
printf "%s: %s\n" "${project_name}" "${project_path}" >> "${kak_opt_fzf_project_file}"
|
||||
printf "%s\n" "echo -markup %{{Information}saved '$(pwd)' project as '${project_name}'}"
|
||||
else
|
||||
printf "%s\n" "fzf-project-confirm-impl %{Project '${project_name}' exists. Update? (y/N): } %{fzf-update-project-path-impl %{${project_name}} %{${PWD}}} %{${project_name}} %{Project '${project_name}' updated} %{Project '${project_name}' kept}"
|
||||
|
@ -104,11 +103,11 @@ fzf-add-project -file-completion -params 1..2 %{ evaluate-commands %sh{
|
|||
mkdir -p "${kak_opt_fzf_project_file%/*}"
|
||||
project_path="$1"
|
||||
project_name="$2"
|
||||
[ -z "${project_name}" ] && project_name=$(base ${project_path})
|
||||
exists=$(grep "${project_name}: " ${kak_opt_fzf_project_file})
|
||||
[ -z "${project_name}" ] && project_name=$(base "${project_path}")
|
||||
exists=$(grep "${project_name}: " "${kak_opt_fzf_project_file}")
|
||||
if [ -z "${exists}" ] || [ "${force}" = "true" ]; then
|
||||
[ "${kak_opt_fzf_project_use_tilda}" = "false" ] || project_path=$(printf "%s\n" ${project_path} | perl -pe "s(${HOME})(~)")
|
||||
printf "%s: %s\n" "${project_name}" "${project_path}" >> ${kak_opt_fzf_project_file}
|
||||
[ "${kak_opt_fzf_project_use_tilda:-true}" = "false" ] || project_path=$(printf "%s\n" "${project_path}" | perl -pe "s(${HOME})(~)")
|
||||
printf "%s: %s\n" "${project_name}" "${project_path}" >> "${kak_opt_fzf_project_file}"
|
||||
printf "%s\n" "echo -markup %{{Information}saved '${project_path}' project as '${project_name}'}"
|
||||
else
|
||||
printf "%s\n" "fzf-project-confirm-impl %{Project '${project_name}' exists. Update? (y/N): } %{fzf-update-project-path-impl %{${project_name}} %{${project_path}}} %{Project '${project_name}' updated} %{Project '${project_name}' kept}"
|
||||
|
@ -120,7 +119,7 @@ define-command -docstring \
|
|||
-hidden fzf-project-confirm-impl -params 2..4 %{
|
||||
prompt -shell-script-candidates %{printf "%s\n%s\n" "y" "n"} "%arg{1}" %{ evaluate-commands %sh{
|
||||
shift; function_to_call=$1; success_message=$2; fail_message=$3
|
||||
choice=$(printf "%s" "${kak_text}" | perl -pe "s/y(es)?.*//i") # case isensetive lookup for yes answer
|
||||
choice=$(printf "%s" "${kak_text:-}" | perl -pe "s/y(es)?.*//i") # case isensetive lookup for yes answer
|
||||
if [ -z "${choice}" ]; then
|
||||
printf "%s\n" "${function_to_call}"
|
||||
[ -n "${success_message}" ] && printf "%s\n" "echo -markup %{{Information}${success_message}}"
|
||||
|
|
|
@ -1,22 +1,18 @@
|
|||
# ╭─────────────╥────────────────────────╮
|
||||
# │ Author: ║ File: │
|
||||
# │ Andrey Orst ║ fzf-search.kak │
|
||||
# ╞═════════════╩════════════════════════╡
|
||||
# │ Module for searching inside current │
|
||||
# │ buffer with fzf for fzf.kak │
|
||||
# ╞══════════════════════════════════════╡
|
||||
# │ GitHub.com/andreyorst/fzf.kak │
|
||||
# ╰──────────────────────────────────────╯
|
||||
# Author: Andrey Listopadov
|
||||
# Module for searching inside current buffer with fzf for fzf.kak
|
||||
# https://github.com/andreyorst/fzf.kak
|
||||
|
||||
hook global ModuleLoaded fzf %§
|
||||
hook global ModuleLoaded fzf %{
|
||||
map global fzf -docstring "search in buffer" 's' '<esc>: require-module fzf-search; fzf-buffer-search<ret>'
|
||||
}
|
||||
|
||||
map global fzf -docstring "search in buffer" 's' '<esc>: 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}"
|
||||
}}
|
||||
|
|
|
@ -1,26 +1,18 @@
|
|||
# ╭─────────────╥────────────────────────╮
|
||||
# │ Author: ║ File: │
|
||||
# │ Andrey Orst ║ fzf-vcs.kak │
|
||||
# ╞═════════════╩════════════════════════╡
|
||||
# │ Module that declares VCS submodule │
|
||||
# │ for various version control systems │
|
||||
# │ to open files with fzf │
|
||||
# ╞══════════════════════════════════════╡
|
||||
# │ GitHub.com/andreyorst/fzf.kak │
|
||||
# ╰──────────────────────────────────────╯
|
||||
# Author: Andrey Listopadov
|
||||
# Module that declares VCS submodule for various version control systems to open files with fzf
|
||||
# https://github.com/andreyorst/fzf.kak
|
||||
|
||||
hook global ModuleLoaded fzf %§
|
||||
|
||||
map global fzf -docstring "edit file from vcs repo" 'v' '<esc>: require-module fzf_vcs; fzf-vcs<ret>'
|
||||
map global fzf -docstring "switch to vcs selection mode" '<a-v>' '<esc>: fzf-vcs-mode<ret>'
|
||||
|
||||
define-command -docstring "Enter fzf-vcs-mode.
|
||||
This mode allows selecting specific vcs command." \
|
||||
fzf-vcs-mode %{ require-module fzf_vcs; evaluate-commands 'enter-user-mode fzf-vcs' }
|
||||
|
||||
map global fzf -docstring "edit file from vcs repo" 'v' '<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>'
|
||||
§
|
||||
|
||||
provide-module fzf_vcs %§
|
||||
provide-module fzf-vcs %§
|
||||
|
||||
require-module fzf-git
|
||||
require-module fzf-svn
|
||||
require-module fzf-hg
|
||||
require-module fzf-bzr
|
||||
|
||||
declare-user-mode fzf-vcs
|
||||
|
||||
|
@ -41,17 +33,17 @@ bzr status"
|
|||
IFS='
|
||||
'
|
||||
for cmd in $commands; do
|
||||
eval $cmd >/dev/null 2>&1
|
||||
eval "$cmd" >/dev/null 2>&1
|
||||
res=$?
|
||||
if [ "$res" = "0" ]; then
|
||||
vcs=$(printf "%s\n" "$cmd" | awk '{print $1}')
|
||||
title="fzf $vcs"
|
||||
[ ! -z "${kak_client_env_TMUX}" ] && additional_keybindings="
|
||||
$kak_opt_fzf_horizontal_map: open file in horizontal split
|
||||
$kak_opt_fzf_vertical_map: open file in vertical split"
|
||||
[ -n "${kak_client_env_TMUX:-}" ] && additional_keybindings="
|
||||
${kak_opt_fzf_horizontal_map:-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.
|
||||
$kak_opt_fzf_window_map: open file in new terminal $additional_keybindings"
|
||||
${kak_opt_fzf_window_map:-ctrl-w}: open file in new terminal $additional_keybindings"
|
||||
printf "%s\n" "info -title %{$title} %{$message}"
|
||||
printf "%s\n" "fzf-$vcs"
|
||||
exit
|
||||
|
|
|
@ -1,14 +1,16 @@
|
|||
# ╭─────────────╥────────────────────────╮
|
||||
# │ Author: ║ File: │
|
||||
# │ Andrey Orst ║ sk-grep.kak │
|
||||
# ╞═════════════╩════════════════════════╡
|
||||
# │ Module running interactive grep with │
|
||||
# │ ski for fzf.kak │
|
||||
# ╞══════════════════════════════════════╡
|
||||
# │ GitHub.com/andreyorst/fzf.kak │
|
||||
# ╰──────────────────────────────────────╯
|
||||
# Author: Andrey Listopadov
|
||||
# Module running interactive grep with skim for fzf.kak
|
||||
# https://github.com/andreyorst/fzf.kak
|
||||
|
||||
hook global ModuleLoaded fzf %§
|
||||
evaluate-commands %sh{
|
||||
if [ -n "$(command -v sk)" ]; then
|
||||
printf "%s\n" "map global fzf -docstring %{Interactive grep with skim} '<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'
|
||||
|
@ -19,12 +21,6 @@ str fzf_sk_grep_command 'grep -RHn'
|
|||
|
||||
declare-option -hidden str fzf_sk_first_file ''
|
||||
|
||||
evaluate-commands %sh{
|
||||
if [ -n "$(command -v sk)" ]; then
|
||||
printf "%s\n" "map global fzf -docstring %{Interactive grep with skim} '<a-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.
|
||||
$kak_opt_fzf_window_map: open search result in new terminal"
|
||||
[ ! -z "${kak_client_env_TMUX}" ] && tmux_keybindings="
|
||||
$kak_opt_fzf_horizontal_map: open search result in horizontal split
|
||||
$kak_opt_fzf_vertical_map: open search result in vertical split"
|
||||
${kak_opt_fzf_window_map:-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 $kak_opt_fzf_vertical_map --expect $kak_opt_fzf_horizontal_map"
|
||||
printf "%s\n" "fzf -kak-cmd %{fzf-sk-grep-handler} -fzf-impl %{sk --ansi -m -i -c '$kak_opt_fzf_sk_grep_command {}'} -fzf-args %{--expect $kak_opt_fzf_window_map $additional_flags} -multiple-cmd %{fzf-sk-populate-grep} -post-action %{buffer %opt{fzf_sk_first_file}}"
|
||||
[ -n "${kak_client_env_TMUX}" ] && additional_flags="--expect ${kak_opt_fzf_vertical_map:-ctrl-v} --expect ${kak_opt_fzf_horizontal_map:-ctrl-s}"
|
||||
printf "%s\n" "fzf -kak-cmd %{fzf-sk-grep-handler} -fzf-impl %{sk --ansi -m -i -c '${kak_opt_fzf_sk_grep_command:-} {}'} -fzf-args %{--expect ${kak_opt_fzf_window_map:-ctrl-w} $additional_flags} -multiple-cmd %{fzf-sk-populate-grep} -post-action %{buffer %opt{fzf_sk_first_file}}"
|
||||
}}
|
||||
|
||||
define-command -hidden fzf-sk-grep-handler -params 1 %{
|
||||
|
|
Loading…
Reference in a new issue