mirror of
https://github.com/junegunn/fzf.git
synced 2025-07-31 20:22:01 -07:00
Compare commits
222 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
fccc93176b | ||
|
6439a138fe | ||
|
a9a29dff4f | ||
|
6a52f8b8dd | ||
|
a1049328d6 | ||
|
5c2b96bd00 | ||
|
c36413fdf6 | ||
|
52cf5af91c | ||
|
3a4e053af7 | ||
|
049bc9ec68 | ||
|
b461a555b8 | ||
|
0f87b2d1e1 | ||
|
0fb5b76c0d | ||
|
0c918dd87a | ||
|
05299a0fee | ||
|
b36b0a91f5 | ||
|
6081eac58a | ||
|
942ba749c7 | ||
|
f941012687 | ||
|
fed5e5d5af | ||
|
b864885753 | ||
|
64747c2324 | ||
|
34965edcda | ||
|
bd4377084d | ||
|
38a2076b89 | ||
|
5759d50d4a | ||
|
e455836cc9 | ||
|
8a90f26c8a | ||
|
24e1fabf2e | ||
|
c39c039e15 | ||
|
07f176f426 | ||
|
19339e3a6d | ||
|
3e1d6a7bcf | ||
|
2bbc12063c | ||
|
b8737b724b | ||
|
d91c3a2f5e | ||
|
fe5db5aadc | ||
|
cf9c957c66 | ||
|
68b60c6d19 | ||
|
3a644b16a4 | ||
|
95b34de339 | ||
|
6a431cbf49 | ||
|
56fb2f00b3 | ||
|
1c86aaf342 | ||
|
cfc0b18eaa | ||
|
412c211655 | ||
|
923feb69ab | ||
|
92dba7035a | ||
|
b8a3ba16a2 | ||
|
cd5e4d9402 | ||
|
f074709fc9 | ||
|
e0b29e437b | ||
|
bdb94fba7d | ||
|
2f364c62f4 | ||
|
7ed9f83662 | ||
|
f498a9b3fb | ||
|
13330738b8 | ||
|
e53535cc61 | ||
|
c62fc5e75c | ||
|
70245ad98c | ||
|
6d235bceee | ||
|
4adebfc856 | ||
|
faccc0a410 | ||
|
9078688baf | ||
|
9bd8b1d25f | ||
|
dd4be1da38 | ||
|
66f86e1870 | ||
|
4ab75b68dc | ||
|
73cb70dbb3 | ||
|
d082cccb6d | ||
|
88a80e3c2c | ||
|
24516bcf4d | ||
|
b4c4a642ed | ||
|
0231617857 | ||
|
7f64fba80f | ||
|
633aec38f5 | ||
|
d1b402a23c | ||
|
35a9aff8e1 | ||
|
988c9bd9be | ||
|
095f31b316 | ||
|
d86cee2a69 | ||
|
e986f20a85 | ||
|
c727ba1d99 | ||
|
bb70923cd8 | ||
|
772fa42dcb | ||
|
85ef3263fc | ||
|
4bde8de63f | ||
|
654a7df9b0 | ||
|
c3aa836ec0 | ||
|
95764bef6f | ||
|
63dbf48546 | ||
|
e2401350a3 | ||
|
e867355b2a | ||
|
b28c14b93a | ||
|
879ead210f | ||
|
2f6d23b91e | ||
|
5f63a7b587 | ||
|
d9ce797d88 | ||
|
12230f8043 | ||
|
0c8de1ca44 | ||
|
89687105f4 | ||
|
74d1694be9 | ||
|
935e986be5 | ||
|
e5ac2ebd7c | ||
|
8d6e13bf94 | ||
|
2ca704405a | ||
|
802c1c2937 | ||
|
3cb5fef6b6 | ||
|
6da2e0aa1e | ||
|
24f3ec7f33 | ||
|
a57b375b41 | ||
|
6cc9d53978 | ||
|
df32c05833 | ||
|
c0652adf4c | ||
|
6ea760a336 | ||
|
f704b94603 | ||
|
444a67cafa | ||
|
f91cbd5688 | ||
|
3073ca3e5a | ||
|
b47ab633e2 | ||
|
09a2ab39fe | ||
|
6cf54833f7 | ||
|
2ccdf21a1f | ||
|
cf8afc527e | ||
|
1d6f05f974 | ||
|
85751966e9 | ||
|
a7bc9d5351 | ||
|
42c006d07c | ||
|
1b9ca314b8 | ||
|
e72a360337 | ||
|
45108ddd53 | ||
|
e3401a0645 | ||
|
26b9100709 | ||
|
a568120e42 | ||
|
e57182c658 | ||
|
6354dbbbdf | ||
|
2b3e740569 | ||
|
40d934e378 | ||
|
e95d82748f | ||
|
30bd0b53db | ||
|
1893eca41a | ||
|
82067463b8 | ||
|
ce9c51d399 | ||
|
96176476f3 | ||
|
68c84264af | ||
|
69438a55ca | ||
|
8695b5e319 | ||
|
95970164ad | ||
|
f6c6e59a50 | ||
|
45143f9541 | ||
|
23244bb410 | ||
|
edb647667e | ||
|
8d3a302a17 | ||
|
1d2d32c847 | ||
|
d635b3fd3c | ||
|
0f281ef894 | ||
|
b18db4733c | ||
|
6e08fe337c | ||
|
2a2c0a0957 | ||
|
4230b6f3c9 | ||
|
aa171b45cb | ||
|
661d06c90a | ||
|
a9aa263d3a | ||
|
6208fc9cfd | ||
|
e1dd798482 | ||
|
c8a3f6f06a | ||
|
3b9984379c | ||
|
a1b60b1d42 | ||
|
b5850ebd4c | ||
|
ac0a62e494 | ||
|
54b4b0c56f | ||
|
033afde3b5 | ||
|
a07944a5bb | ||
|
32010055e1 | ||
|
971ea2217c | ||
|
d513a210c6 | ||
|
a1db64e7b1 | ||
|
0b9c4e1e74 | ||
|
248320fa55 | ||
|
d4e26707c7 | ||
|
99ea1056ac | ||
|
7bcf4effa5 | ||
|
e1df876b61 | ||
|
28ffb9638d | ||
|
1c20255504 | ||
|
1fd884b34f | ||
|
701687faab | ||
|
bbc3055feb | ||
|
95c69083c7 | ||
|
57a37b5832 | ||
|
d29ae1c462 | ||
|
df468fc482 | ||
|
31278bcc68 | ||
|
e7e86b68f4 | ||
|
a89d8995c3 | ||
|
dbc854d5f4 | ||
|
f1cd0e2daf | ||
|
90d32bd756 | ||
|
e99731ea85 | ||
|
15659ac6e6 | ||
|
3ef41845a9 | ||
|
c84e681581 | ||
|
c3cf3427b1 | ||
|
2c4f71d85b | ||
|
c6328affae | ||
|
aaef18295d | ||
|
14f0d2035e | ||
|
64afff6b9a | ||
|
6bddffbca4 | ||
|
81a88693c1 | ||
|
68541e66b7 | ||
|
672b593634 | ||
|
5769d3867d | ||
|
724ffa3756 | ||
|
5694b5ed30 | ||
|
a1184ceb4e | ||
|
02203c7739 | ||
|
4d709e0dd2 | ||
|
ae04f56dbd | ||
|
f80ff8c917 | ||
|
b4ce89bbf5 | ||
|
486b87d821 |
29
.github/ISSUE_TEMPLATE.md
vendored
Normal file
29
.github/ISSUE_TEMPLATE.md
vendored
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
<!-- Check all that apply [x] -->
|
||||||
|
- Category
|
||||||
|
- [ ] fzf binary
|
||||||
|
- [ ] fzf-tmux script
|
||||||
|
- [ ] Key bindings
|
||||||
|
- [ ] Completion
|
||||||
|
- [ ] Vim
|
||||||
|
- [ ] Neovim
|
||||||
|
- [ ] Etc.
|
||||||
|
- OS
|
||||||
|
- [ ] Linux
|
||||||
|
- [ ] Mac OS X
|
||||||
|
- [ ] Windows
|
||||||
|
- [ ] Etc.
|
||||||
|
- Shell
|
||||||
|
- [ ] bash
|
||||||
|
- [ ] zsh
|
||||||
|
- [ ] fish
|
||||||
|
|
||||||
|
<!--
|
||||||
|
### Before submitting
|
||||||
|
|
||||||
|
- Make sure that you have the latest version of fzf
|
||||||
|
- If you use tmux, make sure $TERM is set to screen or screen-256color
|
||||||
|
- For more Vim stuff, check out https://github.com/junegunn/fzf.vim
|
||||||
|
|
||||||
|
Describe your problem or suggestion from here ...
|
||||||
|
-->
|
||||||
|
|
3
.gitignore
vendored
3
.gitignore
vendored
@@ -1,5 +1,6 @@
|
|||||||
bin
|
bin
|
||||||
src/fzf/fzf_*
|
src/fzf/fzf-*
|
||||||
|
gopath
|
||||||
pkg
|
pkg
|
||||||
Gemfile.lock
|
Gemfile.lock
|
||||||
.DS_Store
|
.DS_Store
|
||||||
|
108
CHANGELOG.md
108
CHANGELOG.md
@@ -1,6 +1,114 @@
|
|||||||
CHANGELOG
|
CHANGELOG
|
||||||
=========
|
=========
|
||||||
|
|
||||||
|
0.13.3
|
||||||
|
------
|
||||||
|
- Fixed duplicate rendering of the last line in preview window
|
||||||
|
|
||||||
|
0.13.2
|
||||||
|
------
|
||||||
|
- Fixed race condition where preview window is not properly cleared
|
||||||
|
|
||||||
|
0.13.1
|
||||||
|
------
|
||||||
|
- Fixed UI issue with large `--preview` output with many ANSI codes
|
||||||
|
|
||||||
|
0.13.0
|
||||||
|
------
|
||||||
|
- Added preview feature
|
||||||
|
- `--preview CMD`
|
||||||
|
- `--preview-window POS[:SIZE][:hidden]`
|
||||||
|
- `{}` in execute action is now replaced to the single-quoted (instead of
|
||||||
|
double-quoted) string of the current line
|
||||||
|
- Fixed to ignore control characters for bracketed paste mode
|
||||||
|
|
||||||
|
0.12.2
|
||||||
|
------
|
||||||
|
|
||||||
|
- 256-color capability detection does not require `256` in `$TERM`
|
||||||
|
- Added `print-query` action
|
||||||
|
- More named keys for binding; <kbd>F1</kbd> ~ <kbd>F10</kbd>,
|
||||||
|
<kbd>ALT-/</kbd>, <kbd>ALT-space</kbd>, and <kbd>ALT-enter</kbd>
|
||||||
|
- Added `jump` and `jump-accept` actions that implement [EasyMotion][em]-like
|
||||||
|
movement
|
||||||
|
![][jump]
|
||||||
|
|
||||||
|
[em]: https://github.com/easymotion/vim-easymotion
|
||||||
|
[jump]: https://cloud.githubusercontent.com/assets/700826/15367574/b3999dc4-1d64-11e6-85da-28ceeb1a9bc2.png
|
||||||
|
|
||||||
|
0.12.1
|
||||||
|
------
|
||||||
|
|
||||||
|
- Ranking algorithm introduced in 0.12.0 is now universally applied
|
||||||
|
- Fixed invalid cache reference in exact mode
|
||||||
|
- Fixes and improvements in Vim plugin and shell extensions
|
||||||
|
|
||||||
|
0.12.0
|
||||||
|
------
|
||||||
|
|
||||||
|
- Enhanced ranking algorithm
|
||||||
|
- Minor bug fixes
|
||||||
|
|
||||||
|
0.11.4
|
||||||
|
------
|
||||||
|
|
||||||
|
- Added `--hscroll-off=COL` option (default: 10) (#513)
|
||||||
|
- Some fixes in Vim plugin and shell extensions
|
||||||
|
|
||||||
|
0.11.3
|
||||||
|
------
|
||||||
|
|
||||||
|
- Graceful exit on SIGTERM (#482)
|
||||||
|
- `$SHELL` instead of `sh` for `execute` action and `$FZF_DEFAULT_COMMAND` (#481)
|
||||||
|
- Changes in fuzzy completion API
|
||||||
|
- [`_fzf_compgen_{path,dir}`](https://github.com/junegunn/fzf/commit/9617647)
|
||||||
|
- [`_fzf_complete_COMMAND_post`](https://github.com/junegunn/fzf/commit/8206746)
|
||||||
|
for post-processing
|
||||||
|
|
||||||
|
0.11.2
|
||||||
|
------
|
||||||
|
|
||||||
|
- `--tiebreak` now accepts comma-separated list of sort criteria
|
||||||
|
- Each criterion should appear only once in the list
|
||||||
|
- `index` is only allowed at the end of the list
|
||||||
|
- `index` is implicitly appended to the list when not specified
|
||||||
|
- Default is `length` (or equivalently `length,index`)
|
||||||
|
- `begin` criterion will ignore leading whitespaces when calculating the index
|
||||||
|
- Added `toggle-in` and `toggle-out` actions
|
||||||
|
- Switch direction depending on `--reverse`-ness
|
||||||
|
- `export FZF_DEFAULT_OPTS="--bind tab:toggle-out,shift-tab:toggle-in"`
|
||||||
|
- Reduced the initial delay when `--tac` is not given
|
||||||
|
- fzf defers the initial rendering of the screen up to 100ms if the input
|
||||||
|
stream is ongoing to prevent unnecessary redraw during the initial
|
||||||
|
phase. However, 100ms delay is quite noticeable and might give the
|
||||||
|
impression that fzf is not snappy enough. This commit reduces the
|
||||||
|
maximum delay down to 20ms when `--tac` is not specified, in which case
|
||||||
|
the input list quickly fills the entire screen.
|
||||||
|
|
||||||
|
0.11.1
|
||||||
|
------
|
||||||
|
|
||||||
|
- Added `--tabstop=SPACES` option
|
||||||
|
|
||||||
|
0.11.0
|
||||||
|
------
|
||||||
|
|
||||||
|
- Added OR operator for extended-search mode
|
||||||
|
- Added `--execute-multi` action
|
||||||
|
- Fixed incorrect cursor position when unicode wide characters are used in
|
||||||
|
`--prompt`
|
||||||
|
- Fixes and improvements in shell extensions
|
||||||
|
|
||||||
|
0.10.9
|
||||||
|
------
|
||||||
|
|
||||||
|
- Extended-search mode is now enabled by default
|
||||||
|
- `--extended-exact` is deprecated and instead we have `--exact` for
|
||||||
|
orthogonally controlling "exactness" of search
|
||||||
|
- Fixed not to display non-printable characters
|
||||||
|
- Added `double-click` for `--bind` option
|
||||||
|
- More robust handling of SIGWINCH
|
||||||
|
|
||||||
0.10.8
|
0.10.8
|
||||||
------
|
------
|
||||||
|
|
||||||
|
2
LICENSE
2
LICENSE
@@ -1,6 +1,6 @@
|
|||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
|
|
||||||
Copyright (c) 2015 Junegunn Choi
|
Copyright (c) 2016 Junegunn Choi
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
125
README.md
125
README.md
@@ -21,7 +21,7 @@ Pros
|
|||||||
Installation
|
Installation
|
||||||
------------
|
------------
|
||||||
|
|
||||||
fzf project consists of the followings:
|
fzf project consists of the following:
|
||||||
|
|
||||||
- `fzf` executable
|
- `fzf` executable
|
||||||
- `fzf-tmux` script for launching fzf in a tmux pane
|
- `fzf-tmux` script for launching fzf in a tmux pane
|
||||||
@@ -50,10 +50,10 @@ git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf
|
|||||||
On OS X, you can use [Homebrew](http://brew.sh/) to install fzf.
|
On OS X, you can use [Homebrew](http://brew.sh/) to install fzf.
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
brew reinstall --HEAD fzf
|
brew install fzf
|
||||||
|
|
||||||
# Install shell extensions
|
# Install shell extensions
|
||||||
/usr/local/Cellar/fzf/HEAD/install
|
/usr/local/opt/fzf/install
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Install as Vim plugin
|
#### Install as Vim plugin
|
||||||
@@ -68,7 +68,7 @@ Or you can have [vim-plug](https://github.com/junegunn/vim-plug) manage fzf
|
|||||||
(recommended):
|
(recommended):
|
||||||
|
|
||||||
```vim
|
```vim
|
||||||
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': 'yes \| ./install' }
|
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Upgrading fzf
|
#### Upgrading fzf
|
||||||
@@ -78,7 +78,7 @@ while. Please follow the instruction below depending on the installation
|
|||||||
method.
|
method.
|
||||||
|
|
||||||
- git: `cd ~/.fzf && git pull && ./install`
|
- git: `cd ~/.fzf && git pull && ./install`
|
||||||
- brew: `brew reinstall --HEAD fzf`
|
- brew: `brew update; brew reinstall fzf`
|
||||||
- vim-plug: `:PlugUpdate fzf`
|
- vim-plug: `:PlugUpdate fzf`
|
||||||
|
|
||||||
Usage
|
Usage
|
||||||
@@ -108,32 +108,41 @@ vim $(fzf)
|
|||||||
- Mouse: scroll, click, double-click; shift-click and shift-scroll on
|
- Mouse: scroll, click, double-click; shift-click and shift-scroll on
|
||||||
multi-select mode
|
multi-select mode
|
||||||
|
|
||||||
#### Extended-search mode
|
#### Search syntax
|
||||||
|
|
||||||
With `-x` or `--extended` option, fzf will start in "extended-search mode".
|
Unless otherwise specified, fzf starts in "extended-search mode" where you can
|
||||||
|
type in multiple search terms delimited by spaces. e.g. `^music .mp3$ sbtrkt
|
||||||
|
!rmx`
|
||||||
|
|
||||||
In this mode, you can specify multiple patterns delimited by spaces,
|
| Token | Match type | Description |
|
||||||
such as: `^music .mp3$ sbtrkt !rmx`
|
| -------- | -------------------- | -------------------------------- |
|
||||||
|
| `sbtrkt` | fuzzy-match | Items that match `sbtrkt` |
|
||||||
| Token | Description | Match type |
|
| `^music` | prefix-exact-match | Items that start with `music` |
|
||||||
| -------- | -------------------------------- | -------------------- |
|
| `.mp3$` | suffix-exact-match | Items that end with `.mp3` |
|
||||||
| `^music` | Items that start with `music` | prefix-exact-match |
|
| `'wild` | exact-match (quoted) | Items that include `wild` |
|
||||||
| `.mp3$` | Items that end with `.mp3` | suffix-exact-match |
|
| `!rmx` | inverse-fuzzy-match | Items that do not match `rmx` |
|
||||||
| `sbtrkt` | Items that match `sbtrkt` | fuzzy-match |
|
| `!'fire` | inverse-exact-match | Items that do not include `fire` |
|
||||||
| `!rmx` | Items that do not match `rmx` | inverse-fuzzy-match |
|
|
||||||
| `'wild` | Items that include `wild` | exact-match (quoted) |
|
|
||||||
| `!'fire` | Items that do not include `fire` | inverse-exact-match |
|
|
||||||
|
|
||||||
If you don't prefer fuzzy matching and do not wish to "quote" every word,
|
If you don't prefer fuzzy matching and do not wish to "quote" every word,
|
||||||
start fzf with `-e` or `--extended-exact` option. Note that in
|
start fzf with `-e` or `--exact` option. Note that when `--exact` is set,
|
||||||
`--extended-exact` mode, `'`-prefix "unquotes" the term.
|
`'`-prefix "unquotes" the term.
|
||||||
|
|
||||||
|
A single bar character term acts as an OR operator. For example, the following
|
||||||
|
query matches entries that start with `core` and end with either `go`, `rb`,
|
||||||
|
or `py`.
|
||||||
|
|
||||||
|
```
|
||||||
|
^core go$ | rb$ | py$
|
||||||
|
```
|
||||||
|
|
||||||
#### Environment variables
|
#### Environment variables
|
||||||
|
|
||||||
- `FZF_DEFAULT_COMMAND`
|
- `FZF_DEFAULT_COMMAND`
|
||||||
- Default command to use when input is tty
|
- Default command to use when input is tty
|
||||||
|
- e.g. `export FZF_DEFAULT_COMMAND='ag -g ""'`
|
||||||
- `FZF_DEFAULT_OPTS`
|
- `FZF_DEFAULT_OPTS`
|
||||||
- Default options. e.g. `export FZF_DEFAULT_OPTS="--extended --cycle"`
|
- Default options
|
||||||
|
- e.g. `export FZF_DEFAULT_OPTS="--reverse --inline-info"`
|
||||||
|
|
||||||
Examples
|
Examples
|
||||||
--------
|
--------
|
||||||
@@ -142,27 +151,6 @@ Many useful examples can be found on [the wiki
|
|||||||
page](https://github.com/junegunn/fzf/wiki/examples). Feel free to add your
|
page](https://github.com/junegunn/fzf/wiki/examples). Feel free to add your
|
||||||
own as well.
|
own as well.
|
||||||
|
|
||||||
Key bindings for command line
|
|
||||||
-----------------------------
|
|
||||||
|
|
||||||
The install script will setup the following key bindings for bash, zsh, and
|
|
||||||
fish.
|
|
||||||
|
|
||||||
- `CTRL-T` - Paste the selected files and directories onto the command line
|
|
||||||
- Set `FZF_CTRL_T_COMMAND` to override the default command
|
|
||||||
- `CTRL-R` - Paste the selected command from history onto the command line
|
|
||||||
- Sort is disabled by default to respect chronological ordering
|
|
||||||
- Press `CTRL-R` again to toggle sort
|
|
||||||
- `ALT-C` - cd into the selected directory
|
|
||||||
|
|
||||||
If you're on a tmux session, fzf will start in a split pane. You may disable
|
|
||||||
this tmux integration by setting `FZF_TMUX` to 0, or change the height of the
|
|
||||||
pane with `FZF_TMUX_HEIGHT` (e.g. `20`, `50%`).
|
|
||||||
|
|
||||||
If you use vi mode on bash, you need to add `set -o vi` *before* `source
|
|
||||||
~/.fzf.bash` in your .bashrc, so that it correctly sets up key bindings for vi
|
|
||||||
mode.
|
|
||||||
|
|
||||||
`fzf-tmux` script
|
`fzf-tmux` script
|
||||||
-----------------
|
-----------------
|
||||||
|
|
||||||
@@ -182,6 +170,31 @@ cat /usr/share/dict/words | fzf-tmux -l 20% --multi --reverse
|
|||||||
It will still work even when you're not on tmux, silently ignoring `-[udlr]`
|
It will still work even when you're not on tmux, silently ignoring `-[udlr]`
|
||||||
options, so you can invariably use `fzf-tmux` in your scripts.
|
options, so you can invariably use `fzf-tmux` in your scripts.
|
||||||
|
|
||||||
|
Key bindings for command line
|
||||||
|
-----------------------------
|
||||||
|
|
||||||
|
The install script will setup the following key bindings for bash, zsh, and
|
||||||
|
fish.
|
||||||
|
|
||||||
|
- `CTRL-T` - Paste the selected files and directories onto the command line
|
||||||
|
- Set `FZF_CTRL_T_COMMAND` to override the default command
|
||||||
|
- Set `FZF_CTRL_T_OPTS` to pass additional options
|
||||||
|
- `CTRL-R` - Paste the selected command from history onto the command line
|
||||||
|
- Sort is disabled by default to respect chronological ordering
|
||||||
|
- Press `CTRL-R` again to toggle sort
|
||||||
|
- Set `FZF_CTRL_R_OPTS` to pass additional options
|
||||||
|
- `ALT-C` - cd into the selected directory
|
||||||
|
- Set `FZF_ALT_C_COMMAND` to override the default command
|
||||||
|
- Set `FZF_ALT_C_OPTS` to pass additional options
|
||||||
|
|
||||||
|
If you're on a tmux session, fzf will start in a split pane. You may disable
|
||||||
|
this tmux integration by setting `FZF_TMUX` to 0, or change the height of the
|
||||||
|
pane with `FZF_TMUX_HEIGHT` (e.g. `20`, `50%`).
|
||||||
|
|
||||||
|
If you use vi mode on bash, you need to add `set -o vi` *before* `source
|
||||||
|
~/.fzf.bash` in your .bashrc, so that it correctly sets up key bindings for vi
|
||||||
|
mode.
|
||||||
|
|
||||||
Fuzzy completion for bash and zsh
|
Fuzzy completion for bash and zsh
|
||||||
---------------------------------
|
---------------------------------
|
||||||
|
|
||||||
@@ -250,6 +263,25 @@ export FZF_COMPLETION_TRIGGER='~~'
|
|||||||
|
|
||||||
# Options to fzf command
|
# Options to fzf command
|
||||||
export FZF_COMPLETION_OPTS='+c -x'
|
export FZF_COMPLETION_OPTS='+c -x'
|
||||||
|
|
||||||
|
# Use ag instead of the default find command for listing candidates.
|
||||||
|
# - The first argument to the function is the base path to start traversal
|
||||||
|
# - Note that ag only lists files not directories
|
||||||
|
# - See the source code (completion.{bash,zsh}) for the details.
|
||||||
|
_fzf_compgen_path() {
|
||||||
|
ag -g "" "$1"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Supported commands
|
||||||
|
|
||||||
|
On bash, fuzzy completion is enabled only for a predefined set of commands
|
||||||
|
(`complete | grep _fzf` to see the list). But you can enable it for other
|
||||||
|
commands as well like follows.
|
||||||
|
|
||||||
|
```sh
|
||||||
|
# There are also _fzf_path_completion and _fzf_dir_completion
|
||||||
|
complete -F _fzf_file_completion -o default -o bashdefault doge
|
||||||
```
|
```
|
||||||
|
|
||||||
Usage as Vim plugin
|
Usage as Vim plugin
|
||||||
@@ -315,7 +347,7 @@ Tips
|
|||||||
|
|
||||||
#### Rendering issues
|
#### Rendering issues
|
||||||
|
|
||||||
If you have any rendering issues, check the followings:
|
If you have any rendering issues, check the following:
|
||||||
|
|
||||||
1. Make sure `$TERM` is correctly set. fzf will use 256-color only if it
|
1. Make sure `$TERM` is correctly set. fzf will use 256-color only if it
|
||||||
contains `256` (e.g. `xterm-256color`)
|
contains `256` (e.g. `xterm-256color`)
|
||||||
@@ -335,10 +367,10 @@ filtering:
|
|||||||
|
|
||||||
```sh
|
```sh
|
||||||
# Feed the output of ag into fzf
|
# Feed the output of ag into fzf
|
||||||
ag -l -g "" | fzf
|
ag -g "" | fzf
|
||||||
|
|
||||||
# Setting ag as the default source for fzf
|
# Setting ag as the default source for fzf
|
||||||
export FZF_DEFAULT_COMMAND='ag -l -g ""'
|
export FZF_DEFAULT_COMMAND='ag -g ""'
|
||||||
|
|
||||||
# Now fzf (w/o pipe) will use ag instead of find
|
# Now fzf (w/o pipe) will use ag instead of find
|
||||||
fzf
|
fzf
|
||||||
@@ -355,7 +387,8 @@ speed of the traversal.
|
|||||||
```sh
|
```sh
|
||||||
export FZF_DEFAULT_COMMAND='
|
export FZF_DEFAULT_COMMAND='
|
||||||
(git ls-tree -r --name-only HEAD ||
|
(git ls-tree -r --name-only HEAD ||
|
||||||
find * -name ".*" -prune -o -type f -print -o -type l -print) 2> /dev/null'
|
find . -path "*/\.*" -prune -o -type f -print -o -type l -print |
|
||||||
|
sed s/^..//) 2> /dev/null'
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Fish shell
|
#### Fish shell
|
||||||
|
117
bin/fzf-tmux
117
bin/fzf-tmux
@@ -2,24 +2,51 @@
|
|||||||
# fzf-tmux: starts fzf in a tmux pane
|
# fzf-tmux: starts fzf in a tmux pane
|
||||||
# usage: fzf-tmux [-u|-d [HEIGHT[%]]] [-l|-r [WIDTH[%]]] [--] [FZF OPTIONS]
|
# usage: fzf-tmux [-u|-d [HEIGHT[%]]] [-l|-r [WIDTH[%]]] [--] [FZF OPTIONS]
|
||||||
|
|
||||||
|
fail() {
|
||||||
|
>&2 echo "$1"
|
||||||
|
exit 2
|
||||||
|
}
|
||||||
|
|
||||||
|
fzf="$(command -v fzf 2> /dev/null)" || fzf="$(dirname "$0")/fzf"
|
||||||
|
[[ -x "$fzf" ]] || fail 'fzf executable not found'
|
||||||
|
|
||||||
args=()
|
args=()
|
||||||
opt=""
|
opt=""
|
||||||
skip=""
|
skip=""
|
||||||
swap=""
|
swap=""
|
||||||
close=""
|
close=""
|
||||||
term=""
|
term=""
|
||||||
while [ $# -gt 0 ]; do
|
[[ -n "$LINES" ]] && lines=$LINES || lines=$(tput lines)
|
||||||
|
|
||||||
|
help() {
|
||||||
|
>&2 echo 'usage: fzf-tmux [-u|-d [HEIGHT[%]]] [-l|-r [WIDTH[%]]] [--] [FZF OPTIONS]
|
||||||
|
|
||||||
|
Layout
|
||||||
|
-u [HEIGHT[%]] Split above (up)
|
||||||
|
-d [HEIGHT[%]] Split below (down)
|
||||||
|
-l [WIDTH[%]] Split left
|
||||||
|
-r [WIDTH[%]] Split right
|
||||||
|
|
||||||
|
(default: -d 50%)
|
||||||
|
'
|
||||||
|
exit
|
||||||
|
}
|
||||||
|
|
||||||
|
while [[ $# -gt 0 ]]; do
|
||||||
arg="$1"
|
arg="$1"
|
||||||
case "$arg" in
|
shift
|
||||||
|
[[ -z "$skip" ]] && case "$arg" in
|
||||||
-)
|
-)
|
||||||
term=1
|
term=1
|
||||||
;;
|
;;
|
||||||
|
--help)
|
||||||
|
help
|
||||||
|
;;
|
||||||
|
--version)
|
||||||
|
echo "fzf-tmux (with fzf $("$fzf" --version))"
|
||||||
|
exit
|
||||||
|
;;
|
||||||
-w*|-h*|-d*|-u*|-r*|-l*)
|
-w*|-h*|-d*|-u*|-r*|-l*)
|
||||||
if [ -n "$skip" ]; then
|
|
||||||
args+=("$1")
|
|
||||||
shift
|
|
||||||
continue
|
|
||||||
fi
|
|
||||||
if [[ "$arg" =~ ^.[lrw] ]]; then
|
if [[ "$arg" =~ ^.[lrw] ]]; then
|
||||||
opt="-h"
|
opt="-h"
|
||||||
if [[ "$arg" =~ ^.l ]]; then
|
if [[ "$arg" =~ ^.l ]]; then
|
||||||
@@ -35,35 +62,33 @@ while [ $# -gt 0 ]; do
|
|||||||
close="; tmux swap-pane -D"
|
close="; tmux swap-pane -D"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
if [ ${#arg} -gt 2 ]; then
|
if [[ ${#arg} -gt 2 ]]; then
|
||||||
size="${arg:2}"
|
size="${arg:2}"
|
||||||
else
|
else
|
||||||
shift
|
|
||||||
if [[ "$1" =~ ^[0-9]+%?$ ]]; then
|
if [[ "$1" =~ ^[0-9]+%?$ ]]; then
|
||||||
size="$1"
|
size="$1"
|
||||||
else
|
|
||||||
[ -n "$1" -a "$1" != "--" ] && args+=("$1")
|
|
||||||
shift
|
shift
|
||||||
|
else
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ "$size" =~ %$ ]]; then
|
if [[ "$size" =~ %$ ]]; then
|
||||||
size=${size:0:((${#size}-1))}
|
size=${size:0:((${#size}-1))}
|
||||||
if [ -n "$swap" ]; then
|
if [[ -n "$swap" ]]; then
|
||||||
opt="$opt -p $(( 100 - size ))"
|
opt="$opt -p $(( 100 - size ))"
|
||||||
else
|
else
|
||||||
opt="$opt -p $size"
|
opt="$opt -p $size"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
if [ -n "$swap" ]; then
|
if [[ -n "$swap" ]]; then
|
||||||
if [[ "$arg" =~ ^.l ]]; then
|
if [[ "$arg" =~ ^.l ]]; then
|
||||||
[ -n "$COLUMNS" ] && max=$COLUMNS || max=$(tput cols)
|
[[ -n "$COLUMNS" ]] && max=$COLUMNS || max=$(tput cols)
|
||||||
else
|
else
|
||||||
[ -n "$LINES" ] && max=$LINES || max=$(tput lines)
|
max=$lines
|
||||||
fi
|
fi
|
||||||
size=$(( max - size ))
|
size=$(( max - size ))
|
||||||
[ $size -lt 0 ] && size=0
|
[[ $size -lt 0 ]] && size=0
|
||||||
opt="$opt -l $size"
|
opt="$opt -l $size"
|
||||||
else
|
else
|
||||||
opt="$opt -l $size"
|
opt="$opt -l $size"
|
||||||
@@ -74,19 +99,28 @@ while [ $# -gt 0 ]; do
|
|||||||
# "--" can be used to separate fzf-tmux options from fzf options to
|
# "--" can be used to separate fzf-tmux options from fzf options to
|
||||||
# avoid conflicts
|
# avoid conflicts
|
||||||
skip=1
|
skip=1
|
||||||
|
continue
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
args+=("$1")
|
args+=("$arg")
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
shift
|
[[ -n "$skip" ]] && args+=("$arg")
|
||||||
done
|
done
|
||||||
|
|
||||||
if [ -z "$TMUX_PANE" ] || tmux list-panes -F '#F' | grep -q Z; then
|
if [[ -z "$TMUX" ]] || [[ "$lines" -le 15 ]]; then
|
||||||
fzf "${args[@]}"
|
"$fzf" "${args[@]}"
|
||||||
exit $?
|
exit $?
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Handle zoomed tmux pane by moving it to a temp window
|
||||||
|
if tmux list-panes -F '#F' | grep -q Z; then
|
||||||
|
zoomed=1
|
||||||
|
original_window=$(tmux display-message -p "#{window_id}")
|
||||||
|
tmp_window=$(tmux new-window -d -P -F "#{window_id}" "bash -c 'while :; do for c in \\| / - \\\\; do sleep 0.2; printf \"\\r\$c fzf-tmux is running\\r\"; done; done'")
|
||||||
|
tmux swap-pane -t $tmp_window \; select-window -t $tmp_window
|
||||||
|
fi
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
# Clean up named pipes on exit
|
# Clean up named pipes on exit
|
||||||
@@ -97,40 +131,47 @@ fifo2="${TMPDIR:-/tmp}/fzf-fifo2-$id"
|
|||||||
fifo3="${TMPDIR:-/tmp}/fzf-fifo3-$id"
|
fifo3="${TMPDIR:-/tmp}/fzf-fifo3-$id"
|
||||||
cleanup() {
|
cleanup() {
|
||||||
rm -f $argsf $fifo1 $fifo2 $fifo3
|
rm -f $argsf $fifo1 $fifo2 $fifo3
|
||||||
|
|
||||||
|
# Remove temp window if we were zoomed
|
||||||
|
if [[ -n "$zoomed" ]]; then
|
||||||
|
tmux swap-pane -t $original_window \; \
|
||||||
|
select-window -t $original_window \; \
|
||||||
|
kill-window -t $tmp_window \; \
|
||||||
|
resize-pane -Z
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
trap cleanup EXIT SIGINT SIGTERM
|
trap cleanup EXIT SIGINT SIGTERM
|
||||||
|
|
||||||
fail() {
|
|
||||||
>&2 echo "$1"
|
|
||||||
exit 2
|
|
||||||
}
|
|
||||||
fzf="$(which fzf 2> /dev/null)" || fzf="$(dirname "$0")/fzf"
|
|
||||||
[ -x "$fzf" ] || fail "fzf executable not found"
|
|
||||||
|
|
||||||
envs="env TERM=$TERM "
|
envs="env TERM=$TERM "
|
||||||
[ -n "$FZF_DEFAULT_OPTS" ] && envs="$envs FZF_DEFAULT_OPTS=$(printf %q "$FZF_DEFAULT_OPTS")"
|
[[ -n "$FZF_DEFAULT_OPTS" ]] && envs="$envs FZF_DEFAULT_OPTS=$(printf %q "$FZF_DEFAULT_OPTS")"
|
||||||
[ -n "$FZF_DEFAULT_COMMAND" ] && envs="$envs FZF_DEFAULT_COMMAND=$(printf %q "$FZF_DEFAULT_COMMAND")"
|
[[ -n "$FZF_DEFAULT_COMMAND" ]] && envs="$envs FZF_DEFAULT_COMMAND=$(printf %q "$FZF_DEFAULT_COMMAND")"
|
||||||
|
|
||||||
mkfifo $fifo2
|
mkfifo -m o+w $fifo2
|
||||||
mkfifo $fifo3
|
mkfifo -m o+w $fifo3
|
||||||
|
|
||||||
# Build arguments to fzf
|
# Build arguments to fzf
|
||||||
opts=""
|
opts=""
|
||||||
for arg in "${args[@]}"; do
|
for arg in "${args[@]}"; do
|
||||||
|
arg="${arg//\\/\\\\}"
|
||||||
arg="${arg//\"/\\\"}"
|
arg="${arg//\"/\\\"}"
|
||||||
arg="${arg//\`/\\\`}"
|
arg="${arg//\`/\\\`}"
|
||||||
|
arg="${arg//$/\\$}"
|
||||||
opts="$opts \"$arg\""
|
opts="$opts \"$arg\""
|
||||||
done
|
done
|
||||||
|
|
||||||
if [ -n "$term" -o -t 0 ]; then
|
if [[ -n "$term" ]] || [[ -t 0 ]]; then
|
||||||
cat <<< "$fzf $opts > $fifo2; echo \$? > $fifo3 $close" > $argsf
|
cat <<< "\"$fzf\" $opts > $fifo2; echo \$? > $fifo3 $close" > $argsf
|
||||||
tmux set-window-option -q synchronize-panes off \;\
|
tmux set-window-option synchronize-panes off \;\
|
||||||
split-window $opt "cd $(printf %q "$PWD");$envs bash $argsf" $swap
|
set-window-option remain-on-exit off \;\
|
||||||
|
split-window $opt "cd $(printf %q "$PWD");$envs bash $argsf" $swap \
|
||||||
|
> /dev/null 2>&1
|
||||||
else
|
else
|
||||||
mkfifo $fifo1
|
mkfifo $fifo1
|
||||||
cat <<< "$fzf $opts < $fifo1 > $fifo2; echo \$? > $fifo3 $close" > $argsf
|
cat <<< "\"$fzf\" $opts < $fifo1 > $fifo2; echo \$? > $fifo3 $close" > $argsf
|
||||||
tmux set-window-option -q synchronize-panes off \;\
|
tmux set-window-option synchronize-panes off \;\
|
||||||
split-window $opt "$envs bash $argsf" $swap
|
set-window-option remain-on-exit off \;\
|
||||||
|
split-window $opt "$envs bash $argsf" $swap \
|
||||||
|
> /dev/null 2>&1
|
||||||
cat <&0 > $fifo1 &
|
cat <&0 > $fifo1 &
|
||||||
fi
|
fi
|
||||||
cat $fifo2
|
cat $fifo2
|
||||||
|
4
fzf
4
fzf
@@ -370,7 +370,7 @@ class FZF
|
|||||||
+i Case-sensitive match
|
+i Case-sensitive match
|
||||||
-n, --nth=N[,..] Comma-separated list of field index expressions
|
-n, --nth=N[,..] Comma-separated list of field index expressions
|
||||||
for limiting search scope. Each can be a non-zero
|
for limiting search scope. Each can be a non-zero
|
||||||
integer or a range expression ([BEGIN]..[END])
|
integer or a range expression ([BEGIN]..[END]).
|
||||||
--with-nth=N[,..] Transform the item using index expressions for search
|
--with-nth=N[,..] Transform the item using index expressions for search
|
||||||
-d, --delimiter=STR Field delimiter regex for --nth (default: AWK-style)
|
-d, --delimiter=STR Field delimiter regex for --nth (default: AWK-style)
|
||||||
|
|
||||||
@@ -396,7 +396,7 @@ class FZF
|
|||||||
|
|
||||||
Environment variables
|
Environment variables
|
||||||
FZF_DEFAULT_COMMAND Default command to use when input is tty
|
FZF_DEFAULT_COMMAND Default command to use when input is tty
|
||||||
FZF_DEFAULT_OPTS Defaults options. (e.g. "-x -m --sort 10000")] + $/ + $/
|
FZF_DEFAULT_OPTS Default options (e.g. "-x -m --sort 10000")] + $/ + $/
|
||||||
exit x
|
exit x
|
||||||
end
|
end
|
||||||
|
|
||||||
|
249
install
249
install
@@ -1,22 +1,74 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
[[ "$@" =~ --pre ]] && version=0.10.8 pre=1 ||
|
set -u
|
||||||
version=0.10.8 pre=0
|
|
||||||
|
|
||||||
cd $(dirname $BASH_SOURCE)
|
[[ "$@" =~ --pre ]] && version=0.13.3 pre=1 ||
|
||||||
fzf_base=$(pwd)
|
version=0.13.3 pre=0
|
||||||
|
|
||||||
# If stdin is a tty, we are "interactive".
|
auto_completion=
|
||||||
[ -t 0 ] && interactive=yes
|
key_bindings=
|
||||||
|
update_config=2
|
||||||
|
binary_arch=
|
||||||
|
allow_legacy=
|
||||||
|
|
||||||
|
help() {
|
||||||
|
cat << EOF
|
||||||
|
usage: $0 [OPTIONS]
|
||||||
|
|
||||||
|
--help Show this message
|
||||||
|
--bin Download fzf binary only; Do not generate ~/.fzf.{bash,zsh}
|
||||||
|
--all Download fzf binary and update configuration files
|
||||||
|
to enable key bindings and fuzzy completion
|
||||||
|
--[no-]key-bindings Enable/disable key bindings (CTRL-T, CTRL-R, ALT-C)
|
||||||
|
--[no-]completion Enable/disable fuzzy completion (bash & zsh)
|
||||||
|
--[no-]update-rc Whether or not to update shell configuration files
|
||||||
|
|
||||||
|
--32 Download 32-bit binary
|
||||||
|
--64 Download 64-bit binary
|
||||||
|
EOF
|
||||||
|
}
|
||||||
|
|
||||||
|
for opt in "$@"; do
|
||||||
|
case $opt in
|
||||||
|
--help)
|
||||||
|
help
|
||||||
|
exit 0
|
||||||
|
;;
|
||||||
|
--all)
|
||||||
|
auto_completion=1
|
||||||
|
key_bindings=1
|
||||||
|
update_config=1
|
||||||
|
allow_legacy=1
|
||||||
|
;;
|
||||||
|
--key-bindings) key_bindings=1 ;;
|
||||||
|
--no-key-bindings) key_bindings=0 ;;
|
||||||
|
--completion) auto_completion=1 ;;
|
||||||
|
--no-completion) auto_completion=0 ;;
|
||||||
|
--update-rc) update_config=1 ;;
|
||||||
|
--no-update-rc) update_config=0 ;;
|
||||||
|
--32) binary_arch=386 ;;
|
||||||
|
--64) binary_arch=amd64 ;;
|
||||||
|
--bin|--pre) ;;
|
||||||
|
*)
|
||||||
|
echo "unknown option: $opt"
|
||||||
|
help
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
cd "$(dirname "${BASH_SOURCE[0]}")"
|
||||||
|
fzf_base="$(pwd)"
|
||||||
|
|
||||||
ask() {
|
ask() {
|
||||||
|
# If stdin is a tty, we are "interactive".
|
||||||
# non-interactive shell: wait for a linefeed
|
# non-interactive shell: wait for a linefeed
|
||||||
# interactive shell: continue after a single keypress
|
# interactive shell: continue after a single keypress
|
||||||
[ -n "$interactive" ] && read_n='-n 1' || read_n=
|
read_n=$([ -t 0 ] && echo "-n 1")
|
||||||
|
|
||||||
read -p "$1 ([y]/n) " $read_n -r
|
read -p "$1 ([y]/n) " $read_n -r
|
||||||
echo
|
echo
|
||||||
[[ ! $REPLY =~ ^[Nn]$ ]]
|
[[ $REPLY =~ ^[Nn]$ ]]
|
||||||
}
|
}
|
||||||
|
|
||||||
check_binary() {
|
check_binary() {
|
||||||
@@ -49,15 +101,35 @@ symlink() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
link_fzf_in_path() {
|
||||||
|
if which_fzf="$(command -v fzf)"; then
|
||||||
|
echo " - Found in \$PATH"
|
||||||
|
echo " - Creating symlink: $which_fzf -> bin/fzf"
|
||||||
|
(cd "$fzf_base"/bin && rm -f fzf && ln -sf "$which_fzf" fzf)
|
||||||
|
check_binary && return
|
||||||
|
fi
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
try_curl() {
|
||||||
|
command -v curl > /dev/null && curl -fL $1 | tar -xz
|
||||||
|
}
|
||||||
|
|
||||||
|
try_wget() {
|
||||||
|
command -v wget > /dev/null && wget -O - $1 | tar -xz
|
||||||
|
}
|
||||||
|
|
||||||
download() {
|
download() {
|
||||||
echo "Downloading bin/fzf ..."
|
echo "Downloading bin/fzf ..."
|
||||||
if [ $pre = 0 ]; then
|
if [ $pre = 0 ]; then
|
||||||
if [ -x "$fzf_base"/bin/fzf ]; then
|
if [ -x "$fzf_base"/bin/fzf ]; then
|
||||||
echo " - Already exists"
|
echo " - Already exists"
|
||||||
check_binary && return
|
check_binary && return
|
||||||
elif [ -x "$fzf_base"/bin/$1 ]; then
|
fi
|
||||||
|
if [ -x "$fzf_base"/bin/$1 ]; then
|
||||||
symlink $1 && check_binary && return
|
symlink $1 && check_binary && return
|
||||||
fi
|
fi
|
||||||
|
link_fzf_in_path && return
|
||||||
fi
|
fi
|
||||||
mkdir -p "$fzf_base"/bin && cd "$fzf_base"/bin
|
mkdir -p "$fzf_base"/bin && cd "$fzf_base"/bin
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
@@ -66,14 +138,13 @@ download() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
local url=https://github.com/junegunn/fzf-bin/releases/download/$version/${1}.tgz
|
local url=https://github.com/junegunn/fzf-bin/releases/download/$version/${1}.tgz
|
||||||
if which curl > /dev/null; then
|
set -o pipefail
|
||||||
curl -fL $url | tar -xz
|
if ! (try_curl $url || try_wget $url); then
|
||||||
elif which wget > /dev/null; then
|
set +o pipefail
|
||||||
wget -O - $url | tar -xz
|
binary_error="Failed to download with curl and wget"
|
||||||
else
|
|
||||||
binary_error="curl or wget not found"
|
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
set +o pipefail
|
||||||
|
|
||||||
if [ ! -f $1 ]; then
|
if [ ! -f $1 ]; then
|
||||||
binary_error="Failed to download ${1}"
|
binary_error="Failed to download ${1}"
|
||||||
@@ -88,26 +159,22 @@ archi=$(uname -sm)
|
|||||||
binary_available=1
|
binary_available=1
|
||||||
binary_error=""
|
binary_error=""
|
||||||
case "$archi" in
|
case "$archi" in
|
||||||
Darwin\ x86_64) download fzf-$version-darwin_amd64 ;;
|
Darwin\ x86_64) download fzf-$version-darwin_${binary_arch:-amd64} ;;
|
||||||
Darwin\ i*86) download fzf-$version-darwin_386 ;;
|
Darwin\ i*86) download fzf-$version-darwin_${binary_arch:-386} ;;
|
||||||
Linux\ x86_64) download fzf-$version-linux_amd64 ;;
|
Linux\ x86_64) download fzf-$version-linux_${binary_arch:-amd64} ;;
|
||||||
Linux\ i*86) download fzf-$version-linux_386 ;;
|
Linux\ i*86) download fzf-$version-linux_${binary_arch:-386} ;;
|
||||||
*) binary_available=0 binary_error=1 ;;
|
*) binary_available=0 binary_error=1 ;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
cd "$fzf_base"
|
install_ruby_fzf() {
|
||||||
if [ -n "$binary_error" ]; then
|
if [ -z "$allow_legacy" ]; then
|
||||||
if [ $binary_available -eq 0 ]; then
|
ask "Do you want to install legacy Ruby version instead?" && exit 1
|
||||||
echo "No prebuilt binary for $archi ... "
|
|
||||||
else
|
|
||||||
echo " - $binary_error !!!"
|
|
||||||
exit 1
|
|
||||||
fi
|
fi
|
||||||
echo "Installing legacy Ruby version ..."
|
echo "Installing legacy Ruby version ..."
|
||||||
|
|
||||||
# ruby executable
|
# ruby executable
|
||||||
echo -n "Checking Ruby executable ... "
|
echo -n "Checking Ruby executable ... "
|
||||||
ruby=`which ruby`
|
ruby=$(command -v ruby)
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
echo "ruby executable not found !!!"
|
echo "ruby executable not found !!!"
|
||||||
exit 1
|
exit 1
|
||||||
@@ -115,7 +182,7 @@ if [ -n "$binary_error" ]; then
|
|||||||
|
|
||||||
# System ruby is preferred
|
# System ruby is preferred
|
||||||
system_ruby=/usr/bin/ruby
|
system_ruby=/usr/bin/ruby
|
||||||
if [ -x $system_ruby -a $system_ruby != "$ruby" ]; then
|
if [ -x $system_ruby ] && [ $system_ruby != "$ruby" ]; then
|
||||||
$system_ruby --disable-gems -rcurses -e0 2> /dev/null
|
$system_ruby --disable-gems -rcurses -e0 2> /dev/null
|
||||||
[ $? -eq 0 ] && ruby=$system_ruby
|
[ $? -eq 0 ] && ruby=$system_ruby
|
||||||
fi
|
fi
|
||||||
@@ -168,30 +235,62 @@ if [ -n "$binary_error" ]; then
|
|||||||
echo "$fzf_cmd \"\$@\"" >> "$fzf_base"/bin/fzf
|
echo "$fzf_cmd \"\$@\"" >> "$fzf_base"/bin/fzf
|
||||||
chmod +x "$fzf_base"/bin/fzf
|
chmod +x "$fzf_base"/bin/fzf
|
||||||
echo "OK"
|
echo "OK"
|
||||||
|
}
|
||||||
|
|
||||||
|
cd "$fzf_base"
|
||||||
|
if [ -n "$binary_error" ]; then
|
||||||
|
if [ $binary_available -eq 0 ]; then
|
||||||
|
echo "No prebuilt binary for $archi ..."
|
||||||
|
else
|
||||||
|
echo " - $binary_error !!!"
|
||||||
|
fi
|
||||||
|
if command -v go > /dev/null; then
|
||||||
|
echo -n "Building binary (go get -u github.com/junegunn/fzf/src/fzf) ... "
|
||||||
|
if [ -z "${GOPATH-}" ]; then
|
||||||
|
export GOPATH="${TMPDIR:-/tmp}/fzf-gopath"
|
||||||
|
mkdir -p "$GOPATH"
|
||||||
|
fi
|
||||||
|
if go get -u github.com/junegunn/fzf/src/fzf; then
|
||||||
|
echo "OK"
|
||||||
|
cp "$GOPATH/bin/fzf" "$fzf_base/bin/"
|
||||||
|
else
|
||||||
|
echo "Failed to build binary ..."
|
||||||
|
install_ruby_fzf
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "go executable not found. Cannot build binary ..."
|
||||||
|
install_ruby_fzf
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
[[ "$*" =~ "--bin" ]] && exit 0
|
[[ "$*" =~ "--bin" ]] && exit 0
|
||||||
|
|
||||||
# Auto-completion
|
# Auto-completion
|
||||||
ask "Do you want to add auto-completion support?"
|
if [ -z "$auto_completion" ]; then
|
||||||
|
ask "Do you want to enable fuzzy auto-completion?"
|
||||||
auto_completion=$?
|
auto_completion=$?
|
||||||
|
fi
|
||||||
|
|
||||||
# Key-bindings
|
# Key-bindings
|
||||||
ask "Do you want to add key bindings?"
|
if [ -z "$key_bindings" ]; then
|
||||||
|
ask "Do you want to enable key bindings?"
|
||||||
key_bindings=$?
|
key_bindings=$?
|
||||||
|
fi
|
||||||
|
|
||||||
echo
|
echo
|
||||||
for shell in bash zsh; do
|
has_zsh=$(command -v zsh > /dev/null && echo 1 || echo 0)
|
||||||
|
shells=$([ $has_zsh -eq 1 ] && echo "bash zsh" || echo "bash")
|
||||||
|
for shell in $shells; do
|
||||||
echo -n "Generate ~/.fzf.$shell ... "
|
echo -n "Generate ~/.fzf.$shell ... "
|
||||||
src=~/.fzf.${shell}
|
src=~/.fzf.${shell}
|
||||||
|
|
||||||
fzf_completion="[[ \$- == *i* ]] && source \"$fzf_base/shell/completion.${shell}\" 2> /dev/null"
|
fzf_completion="[[ \$- == *i* ]] && source \"$fzf_base/shell/completion.${shell}\" 2> /dev/null"
|
||||||
if [ $auto_completion -ne 0 ]; then
|
if [ $auto_completion -eq 0 ]; then
|
||||||
fzf_completion="# $fzf_completion"
|
fzf_completion="# $fzf_completion"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
fzf_key_bindings="source \"$fzf_base/shell/key-bindings.${shell}\""
|
fzf_key_bindings="source \"$fzf_base/shell/key-bindings.${shell}\""
|
||||||
if [ $key_bindings -ne 0 ]; then
|
if [ $key_bindings -eq 0 ]; then
|
||||||
fzf_key_bindings="# $fzf_key_bindings"
|
fzf_key_bindings="# $fzf_key_bindings"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -221,9 +320,8 @@ EOF
|
|||||||
done
|
done
|
||||||
|
|
||||||
# fish
|
# fish
|
||||||
has_fish=0
|
has_fish=$(command -v fish > /dev/null && echo 1 || echo 0)
|
||||||
if [ -n "$(which fish 2> /dev/null)" ]; then
|
if [ $has_fish -eq 1 ]; then
|
||||||
has_fish=1
|
|
||||||
echo -n "Update fish_user_paths ... "
|
echo -n "Update fish_user_paths ... "
|
||||||
fish << EOF
|
fish << EOF
|
||||||
echo \$fish_user_paths | grep $fzf_base/bin > /dev/null
|
echo \$fish_user_paths | grep $fzf_base/bin > /dev/null
|
||||||
@@ -237,53 +335,74 @@ EOF
|
|||||||
rm -f ~/.config/fish/functions/fzf.fish && echo "OK" || echo "Failed"
|
rm -f ~/.config/fish/functions/fzf.fish && echo "OK" || echo "Failed"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ $key_bindings -eq 0 ]; then
|
fish_binding=~/.config/fish/functions/fzf_key_bindings.fish
|
||||||
echo -n "Symlink ~/.config/fish/functions/fzf_key_bindings.fish ... "
|
if [ $key_bindings -ne 0 ]; then
|
||||||
ln -sf $fzf_base/shell/key-bindings.fish \
|
echo -n "Symlink $fish_binding ... "
|
||||||
~/.config/fish/functions/fzf_key_bindings.fish && echo "OK" || echo "Failed"
|
ln -sf "$fzf_base/shell/key-bindings.fish" \
|
||||||
|
"$fish_binding" && echo "OK" || echo "Failed"
|
||||||
|
else
|
||||||
|
echo -n "Removing $fish_binding ... "
|
||||||
|
rm -f "$fish_binding"
|
||||||
|
echo "OK"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
append_line() {
|
append_line() {
|
||||||
set -e
|
set -e
|
||||||
echo "Update $2:"
|
|
||||||
echo " - $1"
|
local update line file pat lno
|
||||||
[ -f "$2" ] || touch "$2"
|
update="$1"
|
||||||
if [ $# -lt 3 ]; then
|
line="$2"
|
||||||
line=$(\grep -nF "$1" "$2" | sed 's/:.*//' | tr '\n' ' ')
|
file="$3"
|
||||||
|
pat="${4:-}"
|
||||||
|
|
||||||
|
echo "Update $file:"
|
||||||
|
echo " - $line"
|
||||||
|
[ -f "$file" ] || touch "$file"
|
||||||
|
if [ $# -lt 4 ]; then
|
||||||
|
lno=$(\grep -nF "$line" "$file" | sed 's/:.*//' | tr '\n' ' ')
|
||||||
else
|
else
|
||||||
line=$(\grep -nF "$3" "$2" | sed 's/:.*//' | tr '\n' ' ')
|
lno=$(\grep -nF "$pat" "$file" | sed 's/:.*//' | tr '\n' ' ')
|
||||||
fi
|
fi
|
||||||
if [ -n "$line" ]; then
|
if [ -n "$lno" ]; then
|
||||||
echo " - Already exists: line #$line"
|
echo " - Already exists: line #$lno"
|
||||||
else
|
else
|
||||||
echo >> "$2"
|
if [ $update -eq 1 ]; then
|
||||||
echo "$1" >> "$2"
|
echo >> "$file"
|
||||||
|
echo "$line" >> "$file"
|
||||||
echo " + Added"
|
echo " + Added"
|
||||||
|
else
|
||||||
|
echo " ~ Skipped"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
echo
|
echo
|
||||||
set +e
|
set +e
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if [ $update_config -eq 2 ]; then
|
||||||
echo
|
echo
|
||||||
for shell in bash zsh; do
|
ask "Do you want to update your shell configuration files?"
|
||||||
append_line "[ -f ~/.fzf.${shell} ] && source ~/.fzf.${shell}" ~/.${shell}rc "~/.fzf.${shell}"
|
update_config=$?
|
||||||
|
fi
|
||||||
|
echo
|
||||||
|
for shell in $shells; do
|
||||||
|
[ $shell = zsh ] && dest=${ZDOTDIR:-~}/.zshrc || dest=~/.bashrc
|
||||||
|
append_line $update_config "[ -f ~/.fzf.${shell} ] && source ~/.fzf.${shell}" "$dest" "~/.fzf.${shell}"
|
||||||
done
|
done
|
||||||
|
|
||||||
if [ $key_bindings -eq 0 -a $has_fish -eq 1 ]; then
|
if [ $key_bindings -eq 1 ] && [ $has_fish -eq 1 ]; then
|
||||||
bind_file=~/.config/fish/functions/fish_user_key_bindings.fish
|
bind_file=~/.config/fish/functions/fish_user_key_bindings.fish
|
||||||
append_line "fzf_key_bindings" "$bind_file"
|
append_line $update_config "fzf_key_bindings" "$bind_file"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
cat << EOF
|
if [ $update_config -eq 1 ]; then
|
||||||
Finished. Restart your shell or reload config file.
|
echo 'Finished. Restart your shell or reload config file.'
|
||||||
source ~/.bashrc # bash
|
echo ' source ~/.bashrc # bash'
|
||||||
source ~/.zshrc # zsh
|
[ $has_zsh -eq 1 ] && echo " source ${ZDOTDIR:-~}/.zshrc # zsh"
|
||||||
EOF
|
[ $has_fish -eq 1 ] && [ $key_bindings -eq 1 ] && echo ' fzf_key_bindings # fish'
|
||||||
[ $has_fish -eq 1 ] && echo " fzf_key_bindings # fish"; cat << EOF
|
echo
|
||||||
|
echo 'Use uninstall script to remove fzf.'
|
||||||
Use uninstall script to remove fzf.
|
echo
|
||||||
|
fi
|
||||||
For more information, see: https://github.com/junegunn/fzf
|
echo 'For more information, see: https://github.com/junegunn/fzf'
|
||||||
EOF
|
|
||||||
|
|
||||||
|
54
man/man1/fzf-tmux.1
Normal file
54
man/man1/fzf-tmux.1
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
.ig
|
||||||
|
The MIT License (MIT)
|
||||||
|
|
||||||
|
Copyright (c) 2016 Junegunn Choi
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in
|
||||||
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
THE SOFTWARE.
|
||||||
|
..
|
||||||
|
.TH fzf-tmux 1 "Jul 2016" "fzf 0.13.3" "fzf-tmux - open fzf in tmux split pane"
|
||||||
|
|
||||||
|
.SH NAME
|
||||||
|
fzf-tmux - open fzf in tmux split pane
|
||||||
|
|
||||||
|
.SH SYNOPSIS
|
||||||
|
.B fzf-tmux [-u|-d [HEIGHT[%]]] [-l|-r [WIDTH[%]]] [--] [FZF OPTIONS]
|
||||||
|
|
||||||
|
.SH DESCRIPTION
|
||||||
|
fzf-tmux is a wrapper script for fzf that opens fzf in a tmux split pane. It is
|
||||||
|
designed to work just like fzf except that it does not take up the whole
|
||||||
|
screen. You can safely use fzf-tmux instead of fzf in your scripts as the extra
|
||||||
|
options will be silently ignored if you're not on tmux.
|
||||||
|
|
||||||
|
.SH OPTIONS
|
||||||
|
.SS Layout
|
||||||
|
|
||||||
|
(default: \fB-d 50%\fR)
|
||||||
|
|
||||||
|
.TP
|
||||||
|
.B "-u [height[%]]"
|
||||||
|
Split above (up)
|
||||||
|
.TP
|
||||||
|
.B "-d [height[%]]"
|
||||||
|
Split below (down)
|
||||||
|
.TP
|
||||||
|
.B "-l [width[%]]"
|
||||||
|
Split left
|
||||||
|
.TP
|
||||||
|
.B "-r [width[%]]"
|
||||||
|
Split right
|
446
man/man1/fzf.1
446
man/man1/fzf.1
@@ -1,7 +1,7 @@
|
|||||||
.ig
|
.ig
|
||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
|
|
||||||
Copyright (c) 2015 Junegunn Choi
|
Copyright (c) 2016 Junegunn Choi
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
@@ -21,7 +21,7 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
THE SOFTWARE.
|
THE SOFTWARE.
|
||||||
..
|
..
|
||||||
.TH fzf 1 "Oct 2015" "fzf 0.10.8" "fzf - a command-line fuzzy finder"
|
.TH fzf 1 "Jul 2016" "fzf 0.13.3" "fzf - a command-line fuzzy finder"
|
||||||
|
|
||||||
.SH NAME
|
.SH NAME
|
||||||
fzf - a command-line fuzzy finder
|
fzf - a command-line fuzzy finder
|
||||||
@@ -36,10 +36,11 @@ fzf is a general-purpose command-line fuzzy finder.
|
|||||||
.SS Search mode
|
.SS Search mode
|
||||||
.TP
|
.TP
|
||||||
.B "-x, --extended"
|
.B "-x, --extended"
|
||||||
Extended-search mode
|
Extended-search mode. Since 0.10.9, this is enabled by default. You can disable
|
||||||
|
it with \fB+x\fR or \fB--no-extended\fR.
|
||||||
.TP
|
.TP
|
||||||
.B "-e, --extended-exact"
|
.B "-e, --exact"
|
||||||
Extended-search mode (exact match)
|
Enable exact-match
|
||||||
.TP
|
.TP
|
||||||
.B "-i"
|
.B "-i"
|
||||||
Case-insensitive match (default: smart-case match)
|
Case-insensitive match (default: smart-case match)
|
||||||
@@ -49,10 +50,10 @@ Case-sensitive match
|
|||||||
.TP
|
.TP
|
||||||
.BI "-n, --nth=" "N[,..]"
|
.BI "-n, --nth=" "N[,..]"
|
||||||
Comma-separated list of field index expressions for limiting search scope.
|
Comma-separated list of field index expressions for limiting search scope.
|
||||||
See \fBFIELD INDEX EXPRESSION\fR for details.
|
See \fBFIELD INDEX EXPRESSION\fR for the details.
|
||||||
.TP
|
.TP
|
||||||
.BI "--with-nth=" "N[,..]"
|
.BI "--with-nth=" "N[,..]"
|
||||||
Transform each item using index expressions within finder
|
Transform the presentation of each line using field index expressions
|
||||||
.TP
|
.TP
|
||||||
.BI "-d, --delimiter=" "STR"
|
.BI "-d, --delimiter=" "STR"
|
||||||
Field delimiter regex for \fB--nth\fR and \fB--with-nth\fR (default: AWK-style)
|
Field delimiter regex for \fB--nth\fR and \fB--with-nth\fR (default: AWK-style)
|
||||||
@@ -63,33 +64,113 @@ Do not sort the result
|
|||||||
.TP
|
.TP
|
||||||
.B "--tac"
|
.B "--tac"
|
||||||
Reverse the order of the input
|
Reverse the order of the input
|
||||||
|
|
||||||
.RS
|
.RS
|
||||||
e.g. \fBhistory | fzf --tac --no-sort\fR
|
e.g. \fBhistory | fzf --tac --no-sort\fR
|
||||||
.RE
|
.RE
|
||||||
.TP
|
.TP
|
||||||
.BI "--tiebreak=" "CRI"
|
.BI "--tiebreak=" "CRI[,..]"
|
||||||
Sort criterion to use when the scores are tied
|
Comma-separated list of sort criteria to apply when the scores are tied.
|
||||||
.br
|
.br
|
||||||
.R ""
|
|
||||||
.br
|
.br
|
||||||
.BR length " Prefers item with shorter length"
|
.BR length " Prefers line with shorter length"
|
||||||
.br
|
.br
|
||||||
.BR begin " Prefers item with matched substring closer to the beginning"
|
.BR begin " Prefers line with matched substring closer to the beginning"
|
||||||
.br
|
.br
|
||||||
.BR end " Prefers item with matched substring closer to the end"
|
.BR end " Prefers line with matched substring closer to the end"
|
||||||
.br
|
.br
|
||||||
.BR index " Prefers item that appeared earlier in the input stream"
|
.BR index " Prefers line that appeared earlier in the input stream"
|
||||||
.br
|
.br
|
||||||
|
|
||||||
|
.br
|
||||||
|
- Each criterion should appear only once in the list
|
||||||
|
.br
|
||||||
|
- \fBindex\fR is only allowed at the end of the list
|
||||||
|
.br
|
||||||
|
- \fBindex\fR is implicitly appended to the list when not specified
|
||||||
|
.br
|
||||||
|
- Default is \fBlength\fR (or equivalently \fBlength\fR,index)
|
||||||
|
.br
|
||||||
|
- If \fBend\fR is found in the list, fzf will scan each line backwards
|
||||||
.SS Interface
|
.SS Interface
|
||||||
.TP
|
.TP
|
||||||
.B "-m, --multi"
|
.B "-m, --multi"
|
||||||
Enable multi-select with tab/shift-tab
|
Enable multi-select with tab/shift-tab
|
||||||
.TP
|
.TP
|
||||||
|
.B "--no-mouse"
|
||||||
|
Disable mouse
|
||||||
|
.TP
|
||||||
|
.BI "--bind=" "KEYBINDS"
|
||||||
|
Comma-separated list of custom key bindings. See \fBKEY BINDINGS\fR for the
|
||||||
|
details.
|
||||||
|
.TP
|
||||||
|
.B "--cycle"
|
||||||
|
Enable cyclic scroll
|
||||||
|
.TP
|
||||||
|
.B "--no-hscroll"
|
||||||
|
Disable horizontal scroll
|
||||||
|
.TP
|
||||||
|
.BI "--hscroll-off=" "COL"
|
||||||
|
Number of screen columns to keep to the right of the highlighted substring
|
||||||
|
(default: 10). Setting it to a large value will cause the text to be positioned
|
||||||
|
on the center of the screen.
|
||||||
|
.TP
|
||||||
|
.BI "--jump-labels=" "CHARS"
|
||||||
|
Label characters for \fBjump\fR and \fBjump-accept\fR
|
||||||
|
.SS Layout
|
||||||
|
.TP
|
||||||
|
.B "--reverse"
|
||||||
|
Reverse orientation
|
||||||
|
.TP
|
||||||
|
.BI "--margin=" MARGIN
|
||||||
|
Comma-separated expression for margins around the finder.
|
||||||
|
.br
|
||||||
|
|
||||||
|
.br
|
||||||
|
.RS
|
||||||
|
.BR TRBL " Same margin for top, right, bottom, and left"
|
||||||
|
.br
|
||||||
|
.BR TB,RL " Vertical, horizontal margin"
|
||||||
|
.br
|
||||||
|
.BR T,RL,B " Top, horizontal, bottom margin"
|
||||||
|
.br
|
||||||
|
.BR T,R,B,L " Top, right, bottom, left margin"
|
||||||
|
.br
|
||||||
|
|
||||||
|
.br
|
||||||
|
Each part can be given in absolute number or in percentage relative to the
|
||||||
|
terminal size with \fB%\fR suffix.
|
||||||
|
.br
|
||||||
|
|
||||||
|
.br
|
||||||
|
e.g. \fBfzf --margin 10%\fR
|
||||||
|
\fBfzf --margin 1,5%\fR
|
||||||
|
.RE
|
||||||
|
.TP
|
||||||
|
.B "--inline-info"
|
||||||
|
Display finder info inline with the query
|
||||||
|
.TP
|
||||||
|
.BI "--prompt=" "STR"
|
||||||
|
Input prompt (default: '> ')
|
||||||
|
.TP
|
||||||
|
.BI "--header=" "STR"
|
||||||
|
The given string will be printed as the sticky header. The lines are displayed
|
||||||
|
in the given order from top to bottom regardless of \fB--reverse\fR option, and
|
||||||
|
are not affected by \fB--with-nth\fR. ANSI color codes are processed even when
|
||||||
|
\fB--ansi\fR is not set.
|
||||||
|
.TP
|
||||||
|
.BI "--header-lines=" "N"
|
||||||
|
The first N lines of the input are treated as the sticky header. When
|
||||||
|
\fB--with-nth\fR is set, the lines are transformed just like the other
|
||||||
|
lines that follow.
|
||||||
|
.SS Display
|
||||||
|
.TP
|
||||||
.B "--ansi"
|
.B "--ansi"
|
||||||
Enable processing of ANSI color codes
|
Enable processing of ANSI color codes
|
||||||
.TP
|
.TP
|
||||||
.B "--no-mouse"
|
.BI "--tabstop=" SPACES
|
||||||
Disable mouse
|
Number of spaces for a tab character (default: 8)
|
||||||
.TP
|
.TP
|
||||||
.BI "--color=" "[BASE_SCHEME][,COLOR:ANSI]"
|
.BI "--color=" "[BASE_SCHEME][,COLOR:ANSI]"
|
||||||
Color configuration. The name of the base color scheme is followed by custom
|
Color configuration. The name of the base color scheme is followed by custom
|
||||||
@@ -127,154 +208,7 @@ e.g. \fBfzf --color=bg+:24\fR
|
|||||||
.TP
|
.TP
|
||||||
.B "--black"
|
.B "--black"
|
||||||
Use black background
|
Use black background
|
||||||
.TP
|
.SS History
|
||||||
.B "--reverse"
|
|
||||||
Reverse orientation
|
|
||||||
.TP
|
|
||||||
.BI "--margin=" MARGIN
|
|
||||||
Comma-separated expression for margins around the finder.
|
|
||||||
.br
|
|
||||||
.R ""
|
|
||||||
.br
|
|
||||||
.RS
|
|
||||||
.BR TRBL " Same margin for top, right, bottom, and left"
|
|
||||||
.br
|
|
||||||
.BR TB,RL " Vertical, horizontal margin"
|
|
||||||
.br
|
|
||||||
.BR T,RL,B " Top, horizontal, bottom margin"
|
|
||||||
.br
|
|
||||||
.BR T,R,B,L " Top, right, bottom, left margin"
|
|
||||||
.br
|
|
||||||
.R ""
|
|
||||||
.br
|
|
||||||
Each part can be given in absolute number or in percentage relative to the
|
|
||||||
terminal size with \fB%\fR suffix.
|
|
||||||
.br
|
|
||||||
.R ""
|
|
||||||
.br
|
|
||||||
e.g. \fBfzf --margin 10%\fR
|
|
||||||
\fBfzf --margin 1,5%\fR
|
|
||||||
.RE
|
|
||||||
.TP
|
|
||||||
.B "--cycle"
|
|
||||||
Enable cyclic scroll
|
|
||||||
.TP
|
|
||||||
.B "--no-hscroll"
|
|
||||||
Disable horizontal scroll
|
|
||||||
.TP
|
|
||||||
.B "--inline-info"
|
|
||||||
Display finder info inline with the query
|
|
||||||
.TP
|
|
||||||
.BI "--prompt=" "STR"
|
|
||||||
Input prompt (default: '> ')
|
|
||||||
.TP
|
|
||||||
.BI "--toggle-sort=" "KEY"
|
|
||||||
Key to toggle sort. For the list of the allowed key names, see \fB--bind\fR.
|
|
||||||
.TP
|
|
||||||
.BI "--bind=" "KEYBINDS"
|
|
||||||
Comma-separated list of custom key bindings. Each key binding expression
|
|
||||||
follows the following format: \fBKEY:ACTION\fR
|
|
||||||
.RS
|
|
||||||
e.g. \fBfzf --bind=ctrl-j:accept,ctrl-k:kill-line\fR
|
|
||||||
.RE
|
|
||||||
|
|
||||||
.RS
|
|
||||||
.B AVAILABLE KEYS:
|
|
||||||
\fIctrl-[a-z]\fR
|
|
||||||
\fIalt-[a-z]\fR
|
|
||||||
\fIf[1-4]\fR
|
|
||||||
\fIenter\fR (\fIreturn\fR)
|
|
||||||
\fIspace\fR
|
|
||||||
\fIbspace\fR (\fIbs\fR)
|
|
||||||
\fIalt-bspace\fR (\fIalt-bs\fR)
|
|
||||||
\fItab\fR
|
|
||||||
\fIbtab\fR (\fIshift-tab\fR)
|
|
||||||
\fIesc\fR
|
|
||||||
\fIdel\fR
|
|
||||||
\fIup\fR
|
|
||||||
\fIdown\fR
|
|
||||||
\fIleft\fR
|
|
||||||
\fIright\fR
|
|
||||||
\fIhome\fR
|
|
||||||
\fIend\fR
|
|
||||||
\fIpgup\fR (\fIpage-up\fR)
|
|
||||||
\fIpgdn\fR (\fIpage-down\fR)
|
|
||||||
\fIshift-left\fR
|
|
||||||
\fIshift-right\fR
|
|
||||||
or any single character
|
|
||||||
.RE
|
|
||||||
|
|
||||||
.RS
|
|
||||||
\fBACTION: DEFAULT BINDINGS:
|
|
||||||
\fBabort\fR \fIctrl-c ctrl-g ctrl-q esc\fR
|
|
||||||
\fBaccept\fR \fIctrl-m (enter)\fR
|
|
||||||
\fBbackward-char\fR \fIctrl-b left\fR
|
|
||||||
\fBbackward-delete-char\fR \fIctrl-h bspace\fR
|
|
||||||
\fBbackward-kill-word\fR \fIalt-bs\fR
|
|
||||||
\fBbackward-word\fR \fIalt-b shift-left\fR
|
|
||||||
\fBbeginning-of-line\fR \fIctrl-a home\fR
|
|
||||||
\fBcancel\fR
|
|
||||||
\fBclear-screen\fR \fIctrl-l\fR
|
|
||||||
\fBdelete-char\fR \fIdel\fR
|
|
||||||
\fBdelete-char/eof\fR \fIctrl-d\fR
|
|
||||||
\fBdeselect-all\fR
|
|
||||||
\fBdown\fR \fIctrl-j ctrl-n down\fR
|
|
||||||
\fBend-of-line\fR \fIctrl-e end\fR
|
|
||||||
\fBexecute(...)\fR (see below for the details)
|
|
||||||
\fBforward-char\fR \fIctrl-f right\fR
|
|
||||||
\fBforward-word\fR \fIalt-f shift-right\fR
|
|
||||||
\fBignore\fR
|
|
||||||
\fBkill-line\fR
|
|
||||||
\fBkill-word\fR \fIalt-d\fR
|
|
||||||
\fBnext-history\fR (\fIctrl-n\fR on \fB--history\fR)
|
|
||||||
\fBpage-down\fR \fIpgdn\fR
|
|
||||||
\fBpage-up\fR \fIpgup\fR
|
|
||||||
\fBprevious-history\fR (\fIctrl-p\fR on \fB--history\fR)
|
|
||||||
\fBselect-all\fR
|
|
||||||
\fBtoggle\fR
|
|
||||||
\fBtoggle-all\fR
|
|
||||||
\fBtoggle-down\fR \fIctrl-i (tab)\fR
|
|
||||||
\fBtoggle-sort\fR (equivalent to \fB--toggle-sort\fR)
|
|
||||||
\fBtoggle-up\fR \fIbtab (shift-tab)\fR
|
|
||||||
\fBunix-line-discard\fR \fIctrl-u\fR
|
|
||||||
\fBunix-word-rubout\fR \fIctrl-w\fR
|
|
||||||
\fBup\fR \fIctrl-k ctrl-p up\fR
|
|
||||||
\fByank\fR \fIctrl-y\fR
|
|
||||||
.RE
|
|
||||||
|
|
||||||
.RS
|
|
||||||
With \fBexecute(...)\fR action, you can execute arbitrary commands without
|
|
||||||
leaving fzf. For example, you can turn fzf into a simple file browser by
|
|
||||||
binding \fBenter\fR key to \fBless\fR command like follows.
|
|
||||||
|
|
||||||
.RS
|
|
||||||
\fBfzf --bind "enter:execute(less {})"\fR
|
|
||||||
.RE
|
|
||||||
|
|
||||||
\fB{}\fR is the placeholder for the double-quoted string of the current line.
|
|
||||||
If the command contains parentheses, you can use any of the following
|
|
||||||
alternative notations to avoid parse errors.
|
|
||||||
|
|
||||||
\fBexecute[...]\fR
|
|
||||||
\fBexecute~...~\fR
|
|
||||||
\fBexecute!...!\fR
|
|
||||||
\fBexecute@...@\fR
|
|
||||||
\fBexecute#...#\fR
|
|
||||||
\fBexecute$...$\fR
|
|
||||||
\fBexecute%...%\fR
|
|
||||||
\fBexecute^...^\fR
|
|
||||||
\fBexecute&...&\fR
|
|
||||||
\fBexecute*...*\fR
|
|
||||||
\fBexecute;...;\fR
|
|
||||||
\fBexecute/.../\fR
|
|
||||||
\fBexecute|...|\fR
|
|
||||||
\fBexecute:...\fR
|
|
||||||
.RS
|
|
||||||
This is the special form that frees you from parse errors as it does not expect
|
|
||||||
the closing character. The catch is that it should be the last one in the
|
|
||||||
comma-separated list.
|
|
||||||
.RE
|
|
||||||
.RE
|
|
||||||
.TP
|
.TP
|
||||||
.BI "--history=" "HISTORY_FILE"
|
.BI "--history=" "HISTORY_FILE"
|
||||||
Load search history from the specified file and update the file on completion.
|
Load search history from the specified file and update the file on completion.
|
||||||
@@ -284,17 +218,34 @@ When enabled, \fBCTRL-N\fR and \fBCTRL-P\fR are automatically remapped to
|
|||||||
.BI "--history-size=" "N"
|
.BI "--history-size=" "N"
|
||||||
Maximum number of entries in the history file (default: 1000). The file is
|
Maximum number of entries in the history file (default: 1000). The file is
|
||||||
automatically truncated when the number of the lines exceeds the value.
|
automatically truncated when the number of the lines exceeds the value.
|
||||||
|
.SS Preview
|
||||||
.TP
|
.TP
|
||||||
.BI "--header=" "STR"
|
.BI "--preview=" "COMMAND"
|
||||||
The given string will be printed as the sticky header. The lines are displayed
|
Execute the given command for the current line and display the result on the
|
||||||
in the given order from top to bottom regardless of \fB--reverse\fR option, and
|
preview window. \fB{}\fR is the placeholder for the quoted string of the
|
||||||
are not affected by \fB--with-nth\fR. ANSI color codes are processed even when
|
current line.
|
||||||
\fB--ansi\fR is not set.
|
|
||||||
|
.RS
|
||||||
|
e.g. \fBfzf --preview="head -$LINES {}"\fR
|
||||||
|
.RE
|
||||||
.TP
|
.TP
|
||||||
.BI "--header-lines=" "N"
|
.BI "--preview-window=" "[POSITION][:SIZE[%]][:hidden]"
|
||||||
The first N lines of the input are treated as the sticky header. When
|
Determine the layout of the preview window. If the argument ends with
|
||||||
\fB--with-nth\fR is set, the lines are transformed just like the other
|
\fB:hidden\fR, the preview window will be hidden by default until
|
||||||
lines that follow.
|
\fBtoggle-preview\fR action is triggered.
|
||||||
|
|
||||||
|
.RS
|
||||||
|
.B POSITION: (default: right)
|
||||||
|
\fBup
|
||||||
|
\fBdown
|
||||||
|
\fBleft
|
||||||
|
\fBright
|
||||||
|
.RE
|
||||||
|
|
||||||
|
.RS
|
||||||
|
e.g. \fBfzf --preview="head {}" --preview-window=up:30%\fR
|
||||||
|
\fBfzf --preview="file {}" --preview-window=down:1\fR
|
||||||
|
.RE
|
||||||
.SS Scripting
|
.SS Scripting
|
||||||
.TP
|
.TP
|
||||||
.BI "-q, --query=" "STR"
|
.BI "-q, --query=" "STR"
|
||||||
@@ -319,6 +270,7 @@ the default enter key. When this option is set, fzf will print the name of the
|
|||||||
key pressed as the first line of its output (or as the second line if
|
key pressed as the first line of its output (or as the second line if
|
||||||
\fB--print-query\fR is also used). The line will be empty if fzf is completed
|
\fB--print-query\fR is also used). The line will be empty if fzf is completed
|
||||||
with the default enter key.
|
with the default enter key.
|
||||||
|
|
||||||
.RS
|
.RS
|
||||||
e.g. \fBfzf --expect=ctrl-v,ctrl-t,alt-s,f1,f2,~,@\fR
|
e.g. \fBfzf --expect=ctrl-v,ctrl-t,alt-s,f1,f2,~,@\fR
|
||||||
.RE
|
.RE
|
||||||
@@ -326,11 +278,12 @@ e.g. \fBfzf --expect=ctrl-v,ctrl-t,alt-s,f1,f2,~,@\fR
|
|||||||
.B "--sync"
|
.B "--sync"
|
||||||
Synchronous search for multi-staged filtering. If specified, fzf will launch
|
Synchronous search for multi-staged filtering. If specified, fzf will launch
|
||||||
ncurses finder only after the input stream is complete.
|
ncurses finder only after the input stream is complete.
|
||||||
|
|
||||||
.RS
|
.RS
|
||||||
e.g. \fBfzf --multi | fzf --sync\fR
|
e.g. \fBfzf --multi | fzf --sync\fR
|
||||||
.RE
|
.RE
|
||||||
|
|
||||||
.SH ENVIRONMENT
|
.SH ENVIRONMENT VARIABLES
|
||||||
.TP
|
.TP
|
||||||
.B FZF_DEFAULT_COMMAND
|
.B FZF_DEFAULT_COMMAND
|
||||||
Default command to use when input is tty
|
Default command to use when input is tty
|
||||||
@@ -341,7 +294,11 @@ Default options. e.g. \fBexport FZF_DEFAULT_OPTS="--extended --cycle"\fR
|
|||||||
.SH EXIT STATUS
|
.SH EXIT STATUS
|
||||||
.BR 0 " Normal exit"
|
.BR 0 " Normal exit"
|
||||||
.br
|
.br
|
||||||
.BR 1 " Interrupted with \fBCTRL-C\fR or \fBESC\fR"
|
.BR 1 " No match"
|
||||||
|
.br
|
||||||
|
.BR 2 " Error"
|
||||||
|
.br
|
||||||
|
.BR 130 " Interrupted with \fBCTRL-C\fR or \fBESC\fR"
|
||||||
|
|
||||||
.SH FIELD INDEX EXPRESSION
|
.SH FIELD INDEX EXPRESSION
|
||||||
|
|
||||||
@@ -369,9 +326,9 @@ of field index expressions.
|
|||||||
|
|
||||||
.SH EXTENDED SEARCH MODE
|
.SH EXTENDED SEARCH MODE
|
||||||
|
|
||||||
With \fB-x\fR or \fB--extended\fR option, fzf will start in "extended-search
|
Unless specified otherwise, fzf will start in "extended-search mode". In this
|
||||||
mode". In this mode, you can specify multiple patterns delimited by spaces,
|
mode, you can specify multiple patterns delimited by spaces, such as: \fB'wild
|
||||||
such as: \fB'wild ^music .mp3$ sbtrkt !rmx\fR
|
^music .mp3$ sbtrkt !rmx\fR
|
||||||
|
|
||||||
.SS Exact-match (quoted)
|
.SS Exact-match (quoted)
|
||||||
A term that is prefixed by a single-quote character (\fB'\fR) is interpreted as
|
A term that is prefixed by a single-quote character (\fB'\fR) is interpreted as
|
||||||
@@ -380,18 +337,137 @@ occurrences of the string.
|
|||||||
|
|
||||||
.SS Anchored-match
|
.SS Anchored-match
|
||||||
A term can be prefixed by \fB^\fR, or suffixed by \fB$\fR to become an
|
A term can be prefixed by \fB^\fR, or suffixed by \fB$\fR to become an
|
||||||
anchored-match term. Then fzf will search for the items that start with or end
|
anchored-match term. Then fzf will search for the lines that start with or end
|
||||||
with the given string. An anchored-match term is also an exact-match term.
|
with the given string. An anchored-match term is also an exact-match term.
|
||||||
|
|
||||||
.SS Negation
|
.SS Negation
|
||||||
If a term is prefixed by \fB!\fR, fzf will exclude the items that satisfy the
|
If a term is prefixed by \fB!\fR, fzf will exclude the lines that satisfy the
|
||||||
term from the result.
|
term from the result.
|
||||||
|
|
||||||
.SS Extended-exact mode
|
.SS Exact-match by default
|
||||||
If you don't prefer fuzzy matching and do not wish to "quote" (prefixing with
|
If you don't prefer fuzzy matching and do not wish to "quote" (prefixing with
|
||||||
\fB'\fR) every word, start fzf with \fB-e\fR or \fB--extended-exact\fR option
|
\fB'\fR) every word, start fzf with \fB-e\fR or \fB--exact\fR option. Note that
|
||||||
(instead of \fB-x\fR or \fB--extended\fR). Note that in \fB--extended-exact\fR
|
when \fB--exact\fR is set, \fB'\fR-prefix "unquotes" the term.
|
||||||
mode, \fB'\fR-prefix "unquotes" the term.
|
|
||||||
|
.SS OR operator
|
||||||
|
A single bar character term acts as an OR operator. For example, the following
|
||||||
|
query matches entries that start with \fBcore\fR and end with either \fBgo\fR,
|
||||||
|
\fBrb\fR, or \fBpy\fR.
|
||||||
|
|
||||||
|
e.g. \fB^core go$ | rb$ | py$\fR
|
||||||
|
|
||||||
|
.SH KEY BINDINGS
|
||||||
|
You can customize key bindings of fzf with \fB--bind\fR option which takes
|
||||||
|
a comma-separated list of key binding expressions. Each key binding expression
|
||||||
|
follows the following format: \fBKEY:ACTION\fR
|
||||||
|
|
||||||
|
e.g. \fBfzf --bind=ctrl-j:accept,ctrl-k:kill-line\fR
|
||||||
|
|
||||||
|
.B AVAILABLE KEYS: (SYNONYMS)
|
||||||
|
\fIctrl-[a-z]\fR
|
||||||
|
\fIalt-[a-z]\fR
|
||||||
|
\fIf[1-10]\fR
|
||||||
|
\fIenter\fR (\fIreturn\fR \fIctrl-m\fR)
|
||||||
|
\fIspace\fR
|
||||||
|
\fIbspace\fR (\fIbs\fR)
|
||||||
|
\fIalt-enter\fR
|
||||||
|
\fIalt-space\fR
|
||||||
|
\fIalt-bspace\fR (\fIalt-bs\fR)
|
||||||
|
\fIalt-/\fR
|
||||||
|
\fItab\fR
|
||||||
|
\fIbtab\fR (\fIshift-tab\fR)
|
||||||
|
\fIesc\fR
|
||||||
|
\fIdel\fR
|
||||||
|
\fIup\fR
|
||||||
|
\fIdown\fR
|
||||||
|
\fIleft\fR
|
||||||
|
\fIright\fR
|
||||||
|
\fIhome\fR
|
||||||
|
\fIend\fR
|
||||||
|
\fIpgup\fR (\fIpage-up\fR)
|
||||||
|
\fIpgdn\fR (\fIpage-down\fR)
|
||||||
|
\fIshift-left\fR
|
||||||
|
\fIshift-right\fR
|
||||||
|
\fIdouble-click\fR
|
||||||
|
or any single character
|
||||||
|
|
||||||
|
\fBACTION: DEFAULT BINDINGS (NOTES):
|
||||||
|
\fBabort\fR \fIctrl-c ctrl-g ctrl-q esc\fR
|
||||||
|
\fBaccept\fR \fIenter double-click\fR
|
||||||
|
\fBbackward-char\fR \fIctrl-b left\fR
|
||||||
|
\fBbackward-delete-char\fR \fIctrl-h bspace\fR
|
||||||
|
\fBbackward-kill-word\fR \fIalt-bs\fR
|
||||||
|
\fBbackward-word\fR \fIalt-b shift-left\fR
|
||||||
|
\fBbeginning-of-line\fR \fIctrl-a home\fR
|
||||||
|
\fBcancel\fR
|
||||||
|
\fBclear-screen\fR \fIctrl-l\fR
|
||||||
|
\fBdelete-char\fR \fIdel\fR
|
||||||
|
\fBdelete-char/eof\fR \fIctrl-d\fR
|
||||||
|
\fBdeselect-all\fR
|
||||||
|
\fBdown\fR \fIctrl-j ctrl-n down\fR
|
||||||
|
\fBend-of-line\fR \fIctrl-e end\fR
|
||||||
|
\fBexecute(...)\fR (see below for the details)
|
||||||
|
\fBexecute-multi(...)\fR (see below for the details)
|
||||||
|
\fBforward-char\fR \fIctrl-f right\fR
|
||||||
|
\fBforward-word\fR \fIalt-f shift-right\fR
|
||||||
|
\fBignore\fR
|
||||||
|
\fBjump\fR (EasyMotion-like 2-keystroke movement)
|
||||||
|
\fBjump-accept\fR (jump and accept)
|
||||||
|
\fBkill-line\fR
|
||||||
|
\fBkill-word\fR \fIalt-d\fR
|
||||||
|
\fBnext-history\fR (\fIctrl-n\fR on \fB--history\fR)
|
||||||
|
\fBpage-down\fR \fIpgdn\fR
|
||||||
|
\fBpage-up\fR \fIpgup\fR
|
||||||
|
\fBprevious-history\fR (\fIctrl-p\fR on \fB--history\fR)
|
||||||
|
\fBprint-query\fR (print query and exit)
|
||||||
|
\fBselect-all\fR
|
||||||
|
\fBtoggle\fR
|
||||||
|
\fBtoggle-all\fR
|
||||||
|
\fBtoggle-down\fR \fIctrl-i (tab)\fR
|
||||||
|
\fBtoggle-in\fR (\fB--reverse\fR ? \fBtoggle-up\fR : \fBtoggle-down\fR)
|
||||||
|
\fBtoggle-out\fR (\fB--reverse\fR ? \fBtoggle-down\fR : \fBtoggle-up\fR)
|
||||||
|
\fBtoggle-preview\fR
|
||||||
|
\fBtoggle-sort\fR (equivalent to \fB--toggle-sort\fR)
|
||||||
|
\fBtoggle-up\fR \fIbtab (shift-tab)\fR
|
||||||
|
\fBunix-line-discard\fR \fIctrl-u\fR
|
||||||
|
\fBunix-word-rubout\fR \fIctrl-w\fR
|
||||||
|
\fBup\fR \fIctrl-k ctrl-p up\fR
|
||||||
|
\fByank\fR \fIctrl-y\fR
|
||||||
|
|
||||||
|
With \fBexecute(...)\fR action, you can execute arbitrary commands without
|
||||||
|
leaving fzf. For example, you can turn fzf into a simple file browser by
|
||||||
|
binding \fBenter\fR key to \fBless\fR command like follows.
|
||||||
|
|
||||||
|
\fBfzf --bind "enter:execute(less {})"\fR
|
||||||
|
|
||||||
|
\fB{}\fR is the placeholder for the quoted string of the current line.
|
||||||
|
If the command contains parentheses, you can use any of the following
|
||||||
|
alternative notations to avoid parse errors.
|
||||||
|
|
||||||
|
\fBexecute[...]\fR
|
||||||
|
\fBexecute~...~\fR
|
||||||
|
\fBexecute!...!\fR
|
||||||
|
\fBexecute@...@\fR
|
||||||
|
\fBexecute#...#\fR
|
||||||
|
\fBexecute$...$\fR
|
||||||
|
\fBexecute%...%\fR
|
||||||
|
\fBexecute^...^\fR
|
||||||
|
\fBexecute&...&\fR
|
||||||
|
\fBexecute*...*\fR
|
||||||
|
\fBexecute;...;\fR
|
||||||
|
\fBexecute/.../\fR
|
||||||
|
\fBexecute|...|\fR
|
||||||
|
\fBexecute:...\fR
|
||||||
|
.RS
|
||||||
|
This is the special form that frees you from parse errors as it does not expect
|
||||||
|
the closing character. The catch is that it should be the last one in the
|
||||||
|
comma-separated list.
|
||||||
|
.RE
|
||||||
|
|
||||||
|
\fBexecute-multi(...)\fR is an alternative action that executes the command
|
||||||
|
with the selected entries when multi-select is enabled (\fB--multi\fR). With
|
||||||
|
this action, \fB{}\fR is replaced with the quoted strings of the selected
|
||||||
|
entries separated by spaces.
|
||||||
|
|
||||||
.SH AUTHOR
|
.SH AUTHOR
|
||||||
Junegunn Choi (\fIjunegunn.c@gmail.com\fR)
|
Junegunn Choi (\fIjunegunn.c@gmail.com\fR)
|
||||||
@@ -402,7 +478,7 @@ Junegunn Choi (\fIjunegunn.c@gmail.com\fR)
|
|||||||
.I https://github.com/junegunn/fzf
|
.I https://github.com/junegunn/fzf
|
||||||
.RE
|
.RE
|
||||||
.br
|
.br
|
||||||
.R ""
|
|
||||||
.br
|
.br
|
||||||
.B Extra Vim plugin:
|
.B Extra Vim plugin:
|
||||||
.RS
|
.RS
|
||||||
|
193
plugin/fzf.vim
193
plugin/fzf.vim
@@ -1,4 +1,4 @@
|
|||||||
" Copyright (c) 2015 Junegunn Choi
|
" Copyright (c) 2016 Junegunn Choi
|
||||||
"
|
"
|
||||||
" MIT License
|
" MIT License
|
||||||
"
|
"
|
||||||
@@ -49,11 +49,7 @@ function! s:fzf_exec()
|
|||||||
throw 'fzf executable not found'
|
throw 'fzf executable not found'
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
return s:exec
|
return s:shellesc(s:exec)
|
||||||
endfunction
|
|
||||||
|
|
||||||
function! s:tmux_not_zoomed()
|
|
||||||
return system('tmux list-panes -F "#F"') !~# 'Z'
|
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:tmux_enabled()
|
function! s:tmux_enabled()
|
||||||
@@ -62,7 +58,7 @@ function! s:tmux_enabled()
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
if exists('s:tmux')
|
if exists('s:tmux')
|
||||||
return s:tmux && s:tmux_not_zoomed()
|
return s:tmux
|
||||||
endif
|
endif
|
||||||
|
|
||||||
let s:tmux = 0
|
let s:tmux = 0
|
||||||
@@ -70,7 +66,7 @@ function! s:tmux_enabled()
|
|||||||
let output = system('tmux -V')
|
let output = system('tmux -V')
|
||||||
let s:tmux = !v:shell_error && output >= 'tmux 1.7'
|
let s:tmux = !v:shell_error && output >= 'tmux 1.7'
|
||||||
endif
|
endif
|
||||||
return s:tmux && s:tmux_not_zoomed()
|
return s:tmux
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:shellesc(arg)
|
function! s:shellesc(arg)
|
||||||
@@ -78,7 +74,7 @@ function! s:shellesc(arg)
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:escape(path)
|
function! s:escape(path)
|
||||||
return escape(a:path, ' %#''"\')
|
return escape(a:path, ' $%#''"\')
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
" Upgrade legacy options
|
" Upgrade legacy options
|
||||||
@@ -125,6 +121,12 @@ try
|
|||||||
throw v:exception
|
throw v:exception
|
||||||
endtry
|
endtry
|
||||||
|
|
||||||
|
if !has_key(dict, 'source') && !empty($FZF_DEFAULT_COMMAND)
|
||||||
|
let temps.source = tempname()
|
||||||
|
call writefile(split($FZF_DEFAULT_COMMAND, "\n"), temps.source)
|
||||||
|
let dict.source = (empty($SHELL) ? 'sh' : $SHELL) . ' ' . s:shellesc(temps.source)
|
||||||
|
endif
|
||||||
|
|
||||||
if has_key(dict, 'source')
|
if has_key(dict, 'source')
|
||||||
let source = dict.source
|
let source = dict.source
|
||||||
let type = type(source)
|
let type = type(source)
|
||||||
@@ -140,20 +142,16 @@ try
|
|||||||
else
|
else
|
||||||
let prefix = ''
|
let prefix = ''
|
||||||
endif
|
endif
|
||||||
let tmux = !has('nvim') && s:tmux_enabled() && s:splittable(dict)
|
let tmux = (!has('nvim') || get(g:, 'fzf_prefer_tmux', 0)) && s:tmux_enabled() && s:splittable(dict)
|
||||||
let command = prefix.(tmux ? s:fzf_tmux(dict) : fzf_exec).' '.optstr.' > '.temps.result
|
let command = prefix.(tmux ? s:fzf_tmux(dict) : fzf_exec).' '.optstr.' > '.temps.result
|
||||||
|
|
||||||
try
|
if has('nvim') && !tmux
|
||||||
if tmux
|
|
||||||
return s:execute_tmux(dict, command, temps)
|
|
||||||
elseif has('nvim')
|
|
||||||
return s:execute_term(dict, command, temps)
|
return s:execute_term(dict, command, temps)
|
||||||
else
|
|
||||||
return s:execute(dict, command, temps)
|
|
||||||
endif
|
endif
|
||||||
finally
|
|
||||||
call s:popd(dict)
|
let lines = tmux ? s:execute_tmux(dict, command, temps) : s:execute(dict, command, temps)
|
||||||
endtry
|
call s:callback(dict, lines)
|
||||||
|
return lines
|
||||||
finally
|
finally
|
||||||
let &shell = oshell
|
let &shell = oshell
|
||||||
endtry
|
endtry
|
||||||
@@ -183,7 +181,7 @@ function! s:fzf_tmux(dict)
|
|||||||
endif
|
endif
|
||||||
endfor
|
endfor
|
||||||
return printf('LINES=%d COLUMNS=%d %s %s %s --',
|
return printf('LINES=%d COLUMNS=%d %s %s %s --',
|
||||||
\ &lines, &columns, s:fzf_tmux, size, (has_key(a:dict, 'source') ? '' : '-'))
|
\ &lines, &columns, s:shellesc(s:fzf_tmux), size, (has_key(a:dict, 'source') ? '' : '-'))
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:splittable(dict)
|
function! s:splittable(dict)
|
||||||
@@ -197,17 +195,24 @@ function! s:pushd(dict)
|
|||||||
return 1
|
return 1
|
||||||
endif
|
endif
|
||||||
let a:dict.prev_dir = cwd
|
let a:dict.prev_dir = cwd
|
||||||
execute 'chdir '.s:escape(a:dict.dir)
|
execute 'lcd' s:escape(a:dict.dir)
|
||||||
let a:dict.dir = getcwd()
|
let a:dict.dir = getcwd()
|
||||||
return 1
|
return 1
|
||||||
endif
|
endif
|
||||||
return 0
|
return 0
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:popd(dict)
|
augroup fzf_popd
|
||||||
if has_key(a:dict, 'prev_dir')
|
autocmd!
|
||||||
execute 'chdir '.s:escape(remove(a:dict, 'prev_dir'))
|
autocmd WinEnter * call s:dopopd()
|
||||||
|
augroup END
|
||||||
|
|
||||||
|
function! s:dopopd()
|
||||||
|
if !exists('w:fzf_prev_dir') || exists('*haslocaldir') && !haslocaldir()
|
||||||
|
return
|
||||||
endif
|
endif
|
||||||
|
execute 'lcd' s:escape(w:fzf_prev_dir)
|
||||||
|
unlet w:fzf_prev_dir
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:xterm_launcher()
|
function! s:xterm_launcher()
|
||||||
@@ -235,7 +240,7 @@ function! s:exit_handler(code, command, ...)
|
|||||||
return 1
|
return 1
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:execute(dict, command, temps)
|
function! s:execute(dict, command, temps) abort
|
||||||
call s:pushd(a:dict)
|
call s:pushd(a:dict)
|
||||||
silent! !clear 2> /dev/null
|
silent! !clear 2> /dev/null
|
||||||
let escaped = escape(substitute(a:command, '\n', '\\n', 'g'), '%#')
|
let escaped = escape(substitute(a:command, '\n', '\\n', 'g'), '%#')
|
||||||
@@ -248,10 +253,10 @@ function! s:execute(dict, command, temps)
|
|||||||
endif
|
endif
|
||||||
execute 'silent !'.command
|
execute 'silent !'.command
|
||||||
redraw!
|
redraw!
|
||||||
return s:exit_handler(v:shell_error, command) ? s:callback(a:dict, a:temps) : []
|
return s:exit_handler(v:shell_error, command) ? s:collect(a:temps) : []
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:execute_tmux(dict, command, temps)
|
function! s:execute_tmux(dict, command, temps) abort
|
||||||
let command = a:command
|
let command = a:command
|
||||||
if s:pushd(a:dict)
|
if s:pushd(a:dict)
|
||||||
" -c '#{pane_current_path}' is only available on tmux 1.9 or above
|
" -c '#{pane_current_path}' is only available on tmux 1.9 or above
|
||||||
@@ -260,7 +265,7 @@ function! s:execute_tmux(dict, command, temps)
|
|||||||
|
|
||||||
call system(command)
|
call system(command)
|
||||||
redraw!
|
redraw!
|
||||||
return s:exit_handler(v:shell_error, command) ? s:callback(a:dict, a:temps) : []
|
return s:exit_handler(v:shell_error, command) ? s:collect(a:temps) : []
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:calc_size(max, val, dict)
|
function! s:calc_size(max, val, dict)
|
||||||
@@ -277,11 +282,12 @@ function! s:calc_size(max, val, dict)
|
|||||||
|
|
||||||
let opts = get(a:dict, 'options', '').$FZF_DEFAULT_OPTS
|
let opts = get(a:dict, 'options', '').$FZF_DEFAULT_OPTS
|
||||||
let margin = stridx(opts, '--inline-info') > stridx(opts, '--no-inline-info') ? 1 : 2
|
let margin = stridx(opts, '--inline-info') > stridx(opts, '--no-inline-info') ? 1 : 2
|
||||||
|
let margin += stridx(opts, '--header') > stridx(opts, '--no-header')
|
||||||
return srcsz >= 0 ? min([srcsz + margin, size]) : size
|
return srcsz >= 0 ? min([srcsz + margin, size]) : size
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:getpos()
|
function! s:getpos()
|
||||||
return {'tab': tabpagenr(), 'win': winnr(), 'cnt': winnr('$')}
|
return {'tab': tabpagenr(), 'win': winnr(), 'cnt': winnr('$'), 'tcnt': tabpagenr('$')}
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:split(dict)
|
function! s:split(dict)
|
||||||
@@ -290,7 +296,7 @@ function! s:split(dict)
|
|||||||
\ 'down': ['botright', 'resize', &lines],
|
\ 'down': ['botright', 'resize', &lines],
|
||||||
\ 'left': ['vertical topleft', 'vertical resize', &columns],
|
\ 'left': ['vertical topleft', 'vertical resize', &columns],
|
||||||
\ 'right': ['vertical botright', 'vertical resize', &columns] }
|
\ 'right': ['vertical botright', 'vertical resize', &columns] }
|
||||||
let s:ppos = s:getpos()
|
let ppos = s:getpos()
|
||||||
try
|
try
|
||||||
for [dir, triple] in items(directions)
|
for [dir, triple] in items(directions)
|
||||||
let val = get(a:dict, dir, '')
|
let val = get(a:dict, dir, '')
|
||||||
@@ -303,72 +309,108 @@ function! s:split(dict)
|
|||||||
endif
|
endif
|
||||||
execute cmd sz.'new'
|
execute cmd sz.'new'
|
||||||
execute resz sz
|
execute resz sz
|
||||||
return
|
return [ppos, {}]
|
||||||
endif
|
endif
|
||||||
endfor
|
endfor
|
||||||
if s:present(a:dict, 'window')
|
if s:present(a:dict, 'window')
|
||||||
execute a:dict.window
|
execute a:dict.window
|
||||||
else
|
else
|
||||||
tabnew
|
execute (tabpagenr()-1).'tabnew'
|
||||||
endif
|
endif
|
||||||
|
return [ppos, { '&l:wfw': &l:wfw, '&l:wfh': &l:wfh }]
|
||||||
finally
|
finally
|
||||||
setlocal winfixwidth winfixheight buftype=nofile bufhidden=wipe nobuflisted
|
setlocal winfixwidth winfixheight
|
||||||
endtry
|
endtry
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:execute_term(dict, command, temps)
|
function! s:execute_term(dict, command, temps) abort
|
||||||
call s:split(a:dict)
|
let [ppos, winopts] = s:split(a:dict)
|
||||||
call s:pushd(a:dict)
|
let fzf = { 'buf': bufnr('%'), 'ppos': ppos, 'dict': a:dict, 'temps': a:temps,
|
||||||
|
\ 'name': 'FZF', 'winopts': winopts, 'command': a:command }
|
||||||
let fzf = { 'buf': bufnr('%'), 'dict': a:dict, 'temps': a:temps, 'name': 'FZF' }
|
function! fzf.switch_back(inplace)
|
||||||
let s:command = a:command
|
if a:inplace && bufnr('') == self.buf
|
||||||
|
" FIXME: Can't re-enter normal mode from terminal mode
|
||||||
|
" execute "normal! \<c-^>"
|
||||||
|
b #
|
||||||
|
" No other listed buffer
|
||||||
|
if bufnr('') == self.buf
|
||||||
|
enew
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
endfunction
|
||||||
function! fzf.on_exit(id, code)
|
function! fzf.on_exit(id, code)
|
||||||
let pos = s:getpos()
|
if s:getpos() == self.ppos " {'window': 'enew'}
|
||||||
let inplace = pos == s:ppos " {'window': 'enew'}
|
for [opt, val] in items(self.winopts)
|
||||||
if !inplace
|
execute 'let' opt '=' val
|
||||||
|
endfor
|
||||||
|
call self.switch_back(1)
|
||||||
|
else
|
||||||
if bufnr('') == self.buf
|
if bufnr('') == self.buf
|
||||||
" We use close instead of bd! since Vim does not close the split when
|
" We use close instead of bd! since Vim does not close the split when
|
||||||
" there's no other listed buffer (nvim +'set nobuflisted')
|
" there's no other listed buffer (nvim +'set nobuflisted')
|
||||||
close
|
close
|
||||||
endif
|
endif
|
||||||
if pos.tab == s:ppos.tab
|
execute 'tabnext' self.ppos.tab
|
||||||
wincmd p
|
execute self.ppos.win.'wincmd w'
|
||||||
endif
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if !s:exit_handler(a:code, s:command, 1)
|
if !s:exit_handler(a:code, self.command, 1)
|
||||||
return
|
return
|
||||||
endif
|
endif
|
||||||
|
|
||||||
call s:pushd(self.dict)
|
call s:pushd(self.dict)
|
||||||
try
|
let lines = s:collect(self.temps)
|
||||||
call s:callback(self.dict, self.temps)
|
call s:callback(self.dict, lines)
|
||||||
|
call self.switch_back(s:getpos() == self.ppos)
|
||||||
if inplace && bufnr('') == self.buf
|
|
||||||
execute "normal! \<c-^>"
|
|
||||||
" No other listed buffer
|
|
||||||
if bufnr('') == self.buf
|
|
||||||
bd!
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
finally
|
|
||||||
call s:popd(self.dict)
|
|
||||||
endtry
|
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
try
|
||||||
|
if s:present(a:dict, 'dir')
|
||||||
|
execute 'lcd' s:escape(a:dict.dir)
|
||||||
|
endif
|
||||||
call termopen(a:command, fzf)
|
call termopen(a:command, fzf)
|
||||||
|
finally
|
||||||
|
if s:present(a:dict, 'dir')
|
||||||
|
lcd -
|
||||||
|
endif
|
||||||
|
endtry
|
||||||
|
setlocal nospell bufhidden=wipe nobuflisted
|
||||||
|
setf fzf
|
||||||
startinsert
|
startinsert
|
||||||
return []
|
return []
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:callback(dict, temps)
|
function! s:collect(temps) abort
|
||||||
|
try
|
||||||
|
return filereadable(a:temps.result) ? readfile(a:temps.result) : []
|
||||||
|
finally
|
||||||
|
for tf in values(a:temps)
|
||||||
|
silent! call delete(tf)
|
||||||
|
endfor
|
||||||
|
endtry
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! s:callback(dict, lines) abort
|
||||||
|
" Since anything can be done in the sink function, there is no telling that
|
||||||
|
" the change of the working directory was made by &autochdir setting.
|
||||||
|
"
|
||||||
|
" We use the following heuristic to determine whether to restore CWD:
|
||||||
|
" - Always restore the current directory when &autochdir is disabled.
|
||||||
|
" FIXME This makes it impossible to change directory from inside the sink
|
||||||
|
" function when &autochdir is not used.
|
||||||
|
" - In case of an error or an interrupt, a:lines will be empty.
|
||||||
|
" And it will be an array of a single empty string when fzf was finished
|
||||||
|
" without a match. In these cases, we presume that the change of the
|
||||||
|
" directory is not expected and should be undone.
|
||||||
|
let popd = has_key(a:dict, 'prev_dir') &&
|
||||||
|
\ (!&autochdir || (empty(a:lines) || len(a:lines) == 1 && empty(a:lines[0])))
|
||||||
|
if popd
|
||||||
|
let w:fzf_prev_dir = a:dict.prev_dir
|
||||||
|
endif
|
||||||
|
|
||||||
try
|
try
|
||||||
if !filereadable(a:temps.result)
|
|
||||||
let lines = []
|
|
||||||
else
|
|
||||||
let lines = readfile(a:temps.result)
|
|
||||||
if has_key(a:dict, 'sink')
|
if has_key(a:dict, 'sink')
|
||||||
for line in lines
|
for line in a:lines
|
||||||
if type(a:dict.sink) == 2
|
if type(a:dict.sink) == 2
|
||||||
call a:dict.sink(line)
|
call a:dict.sink(line)
|
||||||
else
|
else
|
||||||
@@ -377,20 +419,19 @@ try
|
|||||||
endfor
|
endfor
|
||||||
endif
|
endif
|
||||||
if has_key(a:dict, 'sink*')
|
if has_key(a:dict, 'sink*')
|
||||||
call a:dict['sink*'](lines)
|
call a:dict['sink*'](a:lines)
|
||||||
endif
|
endif
|
||||||
endif
|
|
||||||
|
|
||||||
for tf in values(a:temps)
|
|
||||||
silent! call delete(tf)
|
|
||||||
endfor
|
|
||||||
|
|
||||||
return lines
|
|
||||||
catch
|
catch
|
||||||
if stridx(v:exception, ':E325:') < 0
|
if stridx(v:exception, ':E325:') < 0
|
||||||
echoerr v:exception
|
echoerr v:exception
|
||||||
endif
|
endif
|
||||||
endtry
|
endtry
|
||||||
|
|
||||||
|
" We may have opened a new window or tab
|
||||||
|
if popd
|
||||||
|
let w:fzf_prev_dir = a:dict.prev_dir
|
||||||
|
call s:dopopd()
|
||||||
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
let s:default_action = {
|
let s:default_action = {
|
||||||
@@ -412,10 +453,16 @@ function! s:cmd_callback(lines) abort
|
|||||||
augroup END
|
augroup END
|
||||||
endif
|
endif
|
||||||
try
|
try
|
||||||
|
let empty = empty(expand('%')) && line('$') == 1 && empty(getline(1)) && !&modified
|
||||||
let autochdir = &autochdir
|
let autochdir = &autochdir
|
||||||
set noautochdir
|
set noautochdir
|
||||||
for item in a:lines
|
for item in a:lines
|
||||||
|
if empty
|
||||||
|
execute 'e' s:escape(item)
|
||||||
|
let empty = 0
|
||||||
|
else
|
||||||
execute cmd s:escape(item)
|
execute cmd s:escape(item)
|
||||||
|
endif
|
||||||
if exists('#BufEnter') && isdirectory(item)
|
if exists('#BufEnter') && isdirectory(item)
|
||||||
doautocmd BufEnter
|
doautocmd BufEnter
|
||||||
endif
|
endif
|
||||||
|
@@ -10,9 +10,29 @@
|
|||||||
# - $FZF_COMPLETION_TRIGGER (default: '**')
|
# - $FZF_COMPLETION_TRIGGER (default: '**')
|
||||||
# - $FZF_COMPLETION_OPTS (default: empty)
|
# - $FZF_COMPLETION_OPTS (default: empty)
|
||||||
|
|
||||||
|
# To use custom commands instead of find, override _fzf_compgen_{path,dir}
|
||||||
|
if ! declare -f _fzf_compgen_path > /dev/null; then
|
||||||
|
_fzf_compgen_path() {
|
||||||
|
echo "$1"
|
||||||
|
command find -L "$1" \
|
||||||
|
-name .git -prune -o -name .svn -prune -o \( -type d -o -type f -o -type l \) \
|
||||||
|
-a -not -path "$1" -print 2> /dev/null | sed 's@^\./@@'
|
||||||
|
}
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! declare -f _fzf_compgen_dir > /dev/null; then
|
||||||
|
_fzf_compgen_dir() {
|
||||||
|
command find -L "$1" \
|
||||||
|
-name .git -prune -o -name .svn -prune -o -type d \
|
||||||
|
-a -not -path "$1" -print 2> /dev/null | sed 's@^\./@@'
|
||||||
|
}
|
||||||
|
fi
|
||||||
|
|
||||||
|
###########################################################
|
||||||
|
|
||||||
_fzf_orig_completion_filter() {
|
_fzf_orig_completion_filter() {
|
||||||
sed 's/.*-F *\([^ ]*\).* \([^ ]*\)$/export _fzf_orig_completion_\2=\1;/' |
|
sed 's/^\(.*-F\) *\([^ ]*\).* \([^ ]*\)$/export _fzf_orig_completion_\3="\1 %s \3 #\2";/' |
|
||||||
sed 's/[^a-z0-9_= ;]/_/g'
|
awk -F= '{gsub(/[^a-z0-9_= ;]/, "_", $1); print $1"="$2}'
|
||||||
}
|
}
|
||||||
|
|
||||||
_fzf_opts_completion() {
|
_fzf_opts_completion() {
|
||||||
@@ -22,7 +42,7 @@ _fzf_opts_completion() {
|
|||||||
prev="${COMP_WORDS[COMP_CWORD-1]}"
|
prev="${COMP_WORDS[COMP_CWORD-1]}"
|
||||||
opts="
|
opts="
|
||||||
-x --extended
|
-x --extended
|
||||||
-e --extended-exact
|
-e --exact
|
||||||
-i +i
|
-i +i
|
||||||
-n --nth
|
-n --nth
|
||||||
-d --delimiter
|
-d --delimiter
|
||||||
@@ -55,11 +75,11 @@ _fzf_opts_completion() {
|
|||||||
|
|
||||||
case "${prev}" in
|
case "${prev}" in
|
||||||
--tiebreak)
|
--tiebreak)
|
||||||
COMPREPLY=( $(compgen -W "length begin end index" -- ${cur}) )
|
COMPREPLY=( $(compgen -W "length begin end index" -- "$cur") )
|
||||||
return 0
|
return 0
|
||||||
;;
|
;;
|
||||||
--color)
|
--color)
|
||||||
COMPREPLY=( $(compgen -W "dark light 16 bw" -- ${cur}) )
|
COMPREPLY=( $(compgen -W "dark light 16 bw" -- "$cur") )
|
||||||
return 0
|
return 0
|
||||||
;;
|
;;
|
||||||
--history)
|
--history)
|
||||||
@@ -68,8 +88,8 @@ _fzf_opts_completion() {
|
|||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
if [[ ${cur} =~ ^-|\+ ]]; then
|
if [[ "$cur" =~ ^-|\+ ]]; then
|
||||||
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
|
COMPREPLY=( $(compgen -W "${opts}" -- "$cur") )
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -77,42 +97,43 @@ _fzf_opts_completion() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_fzf_handle_dynamic_completion() {
|
_fzf_handle_dynamic_completion() {
|
||||||
local cmd orig ret orig_cmd
|
local cmd orig_var orig ret orig_cmd
|
||||||
cmd="$1"
|
cmd="$1"
|
||||||
shift
|
shift
|
||||||
orig_cmd="$1"
|
orig_cmd="$1"
|
||||||
|
orig_var="_fzf_orig_completion_$cmd"
|
||||||
orig=$(eval "echo \$_fzf_orig_completion_$cmd")
|
orig="${!orig_var##*#}"
|
||||||
if [ -n "$orig" ] && type "$orig" > /dev/null 2>&1; then
|
if [ -n "$orig" ] && type "$orig" > /dev/null 2>&1; then
|
||||||
$orig "$@"
|
$orig "$@"
|
||||||
elif [ -n "$_fzf_completion_loader" ]; then
|
elif [ -n "$_fzf_completion_loader" ]; then
|
||||||
_completion_loader "$@"
|
_completion_loader "$@"
|
||||||
ret=$?
|
ret=$?
|
||||||
eval $(complete | \grep "\-F.* $orig_cmd$" | _fzf_orig_completion_filter)
|
eval "$(complete | command grep "\-F.* $orig_cmd$" | _fzf_orig_completion_filter)"
|
||||||
source $BASH_SOURCE
|
source "${BASH_SOURCE[0]}"
|
||||||
return $ret
|
return $ret
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
__fzf_generic_path_completion() {
|
__fzf_generic_path_completion() {
|
||||||
local cur base dir leftover matches trigger cmd fzf
|
local cur base dir leftover matches trigger cmd fzf
|
||||||
[ ${FZF_TMUX:-1} -eq 1 ] && fzf="fzf-tmux -d ${FZF_TMUX_HEIGHT:-40%}" || fzf="fzf"
|
[ "${FZF_TMUX:-1}" != 0 ] && fzf="fzf-tmux -d ${FZF_TMUX_HEIGHT:-40%}" || fzf="fzf"
|
||||||
cmd=$(echo ${COMP_WORDS[0]} | sed 's/[^a-z0-9_=]/_/g')
|
cmd=$(echo "${COMP_WORDS[0]}" | sed 's/[^a-z0-9_=]/_/g')
|
||||||
COMPREPLY=()
|
COMPREPLY=()
|
||||||
trigger=${FZF_COMPLETION_TRIGGER-'**'}
|
trigger=${FZF_COMPLETION_TRIGGER-'**'}
|
||||||
cur="${COMP_WORDS[COMP_CWORD]}"
|
cur="${COMP_WORDS[COMP_CWORD]}"
|
||||||
if [[ ${cur} == *"$trigger" ]]; then
|
if [[ "$cur" == *"$trigger" ]]; then
|
||||||
base=${cur:0:${#cur}-${#trigger}}
|
base=${cur:0:${#cur}-${#trigger}}
|
||||||
eval base=$base
|
eval "base=$base"
|
||||||
|
|
||||||
dir="$base"
|
dir="$base"
|
||||||
while [ 1 ]; do
|
while true; do
|
||||||
if [ -z "$dir" -o -d "$dir" ]; then
|
if [ -z "$dir" ] || [ -d "$dir" ]; then
|
||||||
leftover=${base/#"$dir"}
|
leftover=${base/#"$dir"}
|
||||||
leftover=${leftover/#\/}
|
leftover=${leftover/#\/}
|
||||||
[ "$dir" = './' ] && dir=''
|
[ -z "$dir" ] && dir='.'
|
||||||
|
[ "$dir" != "/" ] && dir="${dir/%\//}"
|
||||||
tput sc
|
tput sc
|
||||||
matches=$(find -L "$dir"* $1 2> /dev/null | $fzf $FZF_COMPLETION_OPTS $2 -q "$leftover" | while read item; do
|
matches=$(eval "$1 $(printf %q "$dir")" | $fzf $FZF_COMPLETION_OPTS $2 -q "$leftover" | while read -r item; do
|
||||||
printf "%q$3 " "$item"
|
printf "%q$3 " "$item"
|
||||||
done)
|
done)
|
||||||
matches=${matches% }
|
matches=${matches% }
|
||||||
@@ -135,29 +156,22 @@ __fzf_generic_path_completion() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
_fzf_feed_fifo() (
|
|
||||||
rm -f "$fifo"
|
|
||||||
mkfifo "$fifo"
|
|
||||||
cat <&0 > "$fifo" &
|
|
||||||
)
|
|
||||||
|
|
||||||
_fzf_complete() {
|
_fzf_complete() {
|
||||||
local fifo cur selected trigger cmd fzf
|
local cur selected trigger cmd fzf post
|
||||||
fifo="${TMPDIR:-/tmp}/fzf-complete-fifo-$$"
|
post="$(caller 0 | awk '{print $2}')_post"
|
||||||
[ ${FZF_TMUX:-1} -eq 1 ] && fzf="fzf-tmux -d ${FZF_TMUX_HEIGHT:-40%}" || fzf="fzf"
|
type -t "$post" > /dev/null 2>&1 || post=cat
|
||||||
|
[ "${FZF_TMUX:-1}" != 0 ] && fzf="fzf-tmux -d ${FZF_TMUX_HEIGHT:-40%}" || fzf="fzf"
|
||||||
|
|
||||||
cmd=$(echo ${COMP_WORDS[0]} | sed 's/[^a-z0-9_=]/_/g')
|
cmd=$(echo "${COMP_WORDS[0]}" | sed 's/[^a-z0-9_=]/_/g')
|
||||||
trigger=${FZF_COMPLETION_TRIGGER-'**'}
|
trigger=${FZF_COMPLETION_TRIGGER-'**'}
|
||||||
cur="${COMP_WORDS[COMP_CWORD]}"
|
cur="${COMP_WORDS[COMP_CWORD]}"
|
||||||
if [[ ${cur} == *"$trigger" ]]; then
|
if [[ "$cur" == *"$trigger" ]]; then
|
||||||
cur=${cur:0:${#cur}-${#trigger}}
|
cur=${cur:0:${#cur}-${#trigger}}
|
||||||
|
|
||||||
_fzf_feed_fifo "$fifo"
|
|
||||||
tput sc
|
tput sc
|
||||||
selected=$(eval "cat '$fifo' | $fzf $FZF_COMPLETION_OPTS $1 -q '$cur'" | tr '\n' ' ')
|
selected=$(cat | $fzf $FZF_COMPLETION_OPTS $1 -q "$cur" | $post | tr '\n' ' ')
|
||||||
selected=${selected% } # Strip trailing space not to repeat "-o nospace"
|
selected=${selected% } # Strip trailing space not to repeat "-o nospace"
|
||||||
tput rc
|
tput rc
|
||||||
rm -f "$fifo"
|
|
||||||
|
|
||||||
if [ -n "$selected" ]; then
|
if [ -n "$selected" ]; then
|
||||||
COMPREPLY=("$selected")
|
COMPREPLY=("$selected")
|
||||||
@@ -170,28 +184,23 @@ _fzf_complete() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_fzf_path_completion() {
|
_fzf_path_completion() {
|
||||||
__fzf_generic_path_completion \
|
__fzf_generic_path_completion _fzf_compgen_path "-m" "" "$@"
|
||||||
"-name .git -prune -o -name .svn -prune -o -type d -print -o -type f -print -o -type l -print" \
|
|
||||||
"-m" "" "$@"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Deprecated. No file only completion.
|
||||||
_fzf_file_completion() {
|
_fzf_file_completion() {
|
||||||
__fzf_generic_path_completion \
|
_fzf_path_completion "$@"
|
||||||
"-name .git -prune -o -name .svn -prune -o -type f -print -o -type l -print" \
|
|
||||||
"-m" "" "$@"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_fzf_dir_completion() {
|
_fzf_dir_completion() {
|
||||||
__fzf_generic_path_completion \
|
__fzf_generic_path_completion _fzf_compgen_dir "" "/" "$@"
|
||||||
"-name .git -prune -o -name .svn -prune -o -type d -print" \
|
|
||||||
"" "/" "$@"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_fzf_complete_kill() {
|
_fzf_complete_kill() {
|
||||||
[ -n "${COMP_WORDS[COMP_CWORD]}" ] && return 1
|
[ -n "${COMP_WORDS[COMP_CWORD]}" ] && return 1
|
||||||
|
|
||||||
local selected fzf
|
local selected fzf
|
||||||
[ ${FZF_TMUX:-1} -eq 1 ] && fzf="fzf-tmux -d ${FZF_TMUX_HEIGHT:-40%}" || fzf="fzf"
|
[ "${FZF_TMUX:-1}" != 0 ] && fzf="fzf-tmux -d ${FZF_TMUX_HEIGHT:-40%}" || fzf="fzf"
|
||||||
tput sc
|
tput sc
|
||||||
selected=$(ps -ef | sed 1d | $fzf -m $FZF_COMPLETION_OPTS | awk '{print $2}' | tr '\n' ' ')
|
selected=$(ps -ef | sed 1d | $fzf -m $FZF_COMPLETION_OPTS | awk '{print $2}' | tr '\n' ' ')
|
||||||
tput rc
|
tput rc
|
||||||
@@ -204,15 +213,16 @@ _fzf_complete_kill() {
|
|||||||
|
|
||||||
_fzf_complete_telnet() {
|
_fzf_complete_telnet() {
|
||||||
_fzf_complete '+m' "$@" < <(
|
_fzf_complete '+m' "$@" < <(
|
||||||
\grep -v '^\s*\(#\|$\)' /etc/hosts | \grep -Fv '0.0.0.0' |
|
command grep -v '^\s*\(#\|$\)' /etc/hosts | command grep -Fv '0.0.0.0' |
|
||||||
awk '{if (length($2) > 0) {print $2}}' | sort -u
|
awk '{if (length($2) > 0) {print $2}}' | sort -u
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
_fzf_complete_ssh() {
|
_fzf_complete_ssh() {
|
||||||
_fzf_complete '+m' "$@" < <(
|
_fzf_complete '+m' "$@" < <(
|
||||||
cat <(cat ~/.ssh/config /etc/ssh/ssh_config 2> /dev/null | \grep -i '^host' | \grep -v '*') \
|
cat <(cat ~/.ssh/config /etc/ssh/ssh_config 2> /dev/null | command grep -i '^host' | command grep -v '*') \
|
||||||
<(\grep -v '^\s*\(#\|$\)' /etc/hosts | \grep -Fv '0.0.0.0') |
|
<(command grep -oE '^[^ ]+' ~/.ssh/known_hosts | tr ',' '\n' | awk '{ print $1 " " $1 }') \
|
||||||
|
<(command grep -v '^\s*\(#\|$\)' /etc/hosts | command grep -Fv '0.0.0.0') |
|
||||||
awk '{if (length($2) > 0) {print $2}}' | sort -u
|
awk '{if (length($2) > 0) {print $2}}' | sort -u
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -238,13 +248,12 @@ _fzf_complete_unalias() {
|
|||||||
# fzf options
|
# fzf options
|
||||||
complete -o default -F _fzf_opts_completion fzf
|
complete -o default -F _fzf_opts_completion fzf
|
||||||
|
|
||||||
d_cmds="cd pushd rmdir"
|
d_cmds="${FZF_COMPLETION_DIR_COMMANDS:-cd pushd rmdir}"
|
||||||
f_cmds="
|
|
||||||
awk cat diff diff3
|
|
||||||
emacs ex file ftp g++ gcc gvim head hg java
|
|
||||||
javac ld less more mvim patch perl python ruby
|
|
||||||
sed sftp sort source tail tee uniq vi view vim wc"
|
|
||||||
a_cmds="
|
a_cmds="
|
||||||
|
awk cat diff diff3
|
||||||
|
emacs emacsclient ex file ftp g++ gcc gvim head hg java
|
||||||
|
javac ld less more mvim nvim patch perl python ruby
|
||||||
|
sed sftp sort source tail tee uniq vi view vim wc xdg-open
|
||||||
basename bunzip2 bzip2 chmod chown curl cp dirname du
|
basename bunzip2 bzip2 chmod chown curl cp dirname du
|
||||||
find git grep gunzip gzip hg jar
|
find git grep gunzip gzip hg jar
|
||||||
ln ls mv open rm rsync scp
|
ln ls mv open rm rsync scp
|
||||||
@@ -252,32 +261,44 @@ a_cmds="
|
|||||||
x_cmds="kill ssh telnet unset unalias export"
|
x_cmds="kill ssh telnet unset unalias export"
|
||||||
|
|
||||||
# Preserve existing completion
|
# Preserve existing completion
|
||||||
if [ "$_fzf_completion_loaded" != '0.9.12' ]; then
|
if [ "$_fzf_completion_loaded" != '0.11.3' ]; then
|
||||||
# Really wish I could use associative array but OSX comes with bash 3.2 :(
|
# Really wish I could use associative array but OSX comes with bash 3.2 :(
|
||||||
eval $(complete | \grep '\-F' | \grep -v _fzf_ |
|
eval $(complete | command grep '\-F' | command grep -v _fzf_ |
|
||||||
\grep -E " ($(echo $d_cmds $f_cmds $a_cmds $x_cmds | sed 's/ /|/g' | sed 's/+/\\+/g'))$" | _fzf_orig_completion_filter)
|
command grep -E " ($(echo $d_cmds $a_cmds $x_cmds | sed 's/ /|/g' | sed 's/+/\\+/g'))$" | _fzf_orig_completion_filter)
|
||||||
export _fzf_completion_loaded=0.9.12
|
export _fzf_completion_loaded=0.11.3
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if type _completion_loader > /dev/null 2>&1; then
|
if type _completion_loader > /dev/null 2>&1; then
|
||||||
_fzf_completion_loader=1
|
_fzf_completion_loader=1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Directory
|
_fzf_defc() {
|
||||||
for cmd in $d_cmds; do
|
local cmd func opts orig_var orig def
|
||||||
complete -F _fzf_dir_completion -o nospace -o plusdirs $cmd
|
cmd="$1"
|
||||||
done
|
func="$2"
|
||||||
|
opts="$3"
|
||||||
# File
|
orig_var="_fzf_orig_completion_$cmd"
|
||||||
for cmd in $f_cmds; do
|
orig="${!orig_var}"
|
||||||
complete -F _fzf_file_completion -o default -o bashdefault $cmd
|
if [ -n "$orig" ]; then
|
||||||
done
|
printf -v def "$orig" "$func"
|
||||||
|
eval "$def"
|
||||||
|
else
|
||||||
|
complete -F "$func" $opts "$cmd"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
# Anything
|
# Anything
|
||||||
for cmd in $a_cmds; do
|
for cmd in $a_cmds; do
|
||||||
complete -F _fzf_path_completion -o default -o bashdefault $cmd
|
_fzf_defc "$cmd" _fzf_path_completion "-o default -o bashdefault"
|
||||||
done
|
done
|
||||||
|
|
||||||
|
# Directory
|
||||||
|
for cmd in $d_cmds; do
|
||||||
|
_fzf_defc "$cmd" _fzf_dir_completion "-o nospace -o plusdirs"
|
||||||
|
done
|
||||||
|
|
||||||
|
unset _fzf_defc
|
||||||
|
|
||||||
# Kill completion
|
# Kill completion
|
||||||
complete -F _fzf_complete_kill -o nospace -o default -o bashdefault kill
|
complete -F _fzf_complete_kill -o nospace -o default -o bashdefault kill
|
||||||
|
|
||||||
@@ -290,4 +311,4 @@ complete -F _fzf_complete_unset -o default -o bashdefault unset
|
|||||||
complete -F _fzf_complete_export -o default -o bashdefault export
|
complete -F _fzf_complete_export -o default -o bashdefault export
|
||||||
complete -F _fzf_complete_unalias -o default -o bashdefault unalias
|
complete -F _fzf_complete_unalias -o default -o bashdefault unalias
|
||||||
|
|
||||||
unset cmd d_cmds f_cmds a_cmds x_cmds
|
unset cmd d_cmds a_cmds x_cmds
|
||||||
|
@@ -10,89 +10,110 @@
|
|||||||
# - $FZF_COMPLETION_TRIGGER (default: '**')
|
# - $FZF_COMPLETION_TRIGGER (default: '**')
|
||||||
# - $FZF_COMPLETION_OPTS (default: empty)
|
# - $FZF_COMPLETION_OPTS (default: empty)
|
||||||
|
|
||||||
|
# To use custom commands instead of find, override _fzf_compgen_{path,dir}
|
||||||
|
if ! declare -f _fzf_compgen_path > /dev/null; then
|
||||||
|
_fzf_compgen_path() {
|
||||||
|
echo "$1"
|
||||||
|
command find -L "$1" \
|
||||||
|
-name .git -prune -o -name .svn -prune -o \( -type d -o -type f -o -type l \) \
|
||||||
|
-a -not -path "$1" -print 2> /dev/null | sed 's@^\./@@'
|
||||||
|
}
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! declare -f _fzf_compgen_dir > /dev/null; then
|
||||||
|
_fzf_compgen_dir() {
|
||||||
|
command find -L "$1" \
|
||||||
|
-name .git -prune -o -name .svn -prune -o -type d \
|
||||||
|
-a -not -path "$1" -print 2> /dev/null | sed 's@^\./@@'
|
||||||
|
}
|
||||||
|
fi
|
||||||
|
|
||||||
|
###########################################################
|
||||||
|
|
||||||
__fzf_generic_path_completion() {
|
__fzf_generic_path_completion() {
|
||||||
local base lbuf find_opts fzf_opts suffix tail fzf dir leftover matches nnm
|
local base lbuf compgen fzf_opts suffix tail fzf dir leftover matches
|
||||||
# (Q) flag removes a quoting level: "foo\ bar" => "foo bar"
|
# (Q) flag removes a quoting level: "foo\ bar" => "foo bar"
|
||||||
base=${(Q)1}
|
base=${(Q)1}
|
||||||
lbuf=$2
|
lbuf=$2
|
||||||
find_opts=$3
|
compgen=$3
|
||||||
fzf_opts=$4
|
fzf_opts=$4
|
||||||
suffix=$5
|
suffix=$5
|
||||||
tail=$6
|
tail=$6
|
||||||
[ ${FZF_TMUX:-1} -eq 1 ] && fzf="fzf-tmux -d ${FZF_TMUX_HEIGHT:-40%}" || fzf="fzf"
|
[ ${FZF_TMUX:-1} -eq 1 ] && fzf="fzf-tmux -d ${FZF_TMUX_HEIGHT:-40%}" || fzf="fzf"
|
||||||
|
|
||||||
if ! setopt | grep nonomatch > /dev/null; then
|
setopt localoptions nonomatch
|
||||||
nnm=1
|
|
||||||
setopt nonomatch
|
|
||||||
fi
|
|
||||||
dir="$base"
|
dir="$base"
|
||||||
while [ 1 ]; do
|
while [ 1 ]; do
|
||||||
if [ -z "$dir" -o -d ${~dir} ]; then
|
if [ -z "$dir" -o -d ${~dir} ]; then
|
||||||
leftover=${base/#"$dir"}
|
leftover=${base/#"$dir"}
|
||||||
leftover=${leftover/#\/}
|
leftover=${leftover/#\/}
|
||||||
[ "$dir" = './' ] && dir=''
|
[ -z "$dir" ] && dir='.'
|
||||||
|
[ "$dir" != "/" ] && dir="${dir/%\//}"
|
||||||
dir=${~dir}
|
dir=${~dir}
|
||||||
matches=$(\find -L $dir* ${=find_opts} 2> /dev/null | ${=fzf} ${=FZF_COMPLETION_OPTS} ${=fzf_opts} -q "$leftover" | while read item; do
|
matches=$(eval "$compgen $(printf %q "$dir")" | ${=fzf} ${=FZF_COMPLETION_OPTS} ${=fzf_opts} -q "$leftover" | while read item; do
|
||||||
printf "%q$suffix " "$item"
|
echo -n "${(q)item}$suffix "
|
||||||
done)
|
done)
|
||||||
matches=${matches% }
|
matches=${matches% }
|
||||||
if [ -n "$matches" ]; then
|
if [ -n "$matches" ]; then
|
||||||
LBUFFER="$lbuf$matches$tail"
|
LBUFFER="$lbuf$matches$tail"
|
||||||
fi
|
fi
|
||||||
zle redisplay
|
zle redisplay
|
||||||
|
typeset -f zle-line-init >/dev/null && zle zle-line-init
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
dir=$(dirname "$dir")
|
dir=$(dirname "$dir")
|
||||||
dir=${dir%/}/
|
dir=${dir%/}/
|
||||||
done
|
done
|
||||||
[ -n "$nnm" ] && unsetopt nonomatch
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_fzf_path_completion() {
|
_fzf_path_completion() {
|
||||||
__fzf_generic_path_completion "$1" "$2" \
|
__fzf_generic_path_completion "$1" "$2" _fzf_compgen_path \
|
||||||
"-name .git -prune -o -name .svn -prune -o -type d -print -o -type f -print -o -type l -print" \
|
|
||||||
"-m" "" " "
|
"-m" "" " "
|
||||||
}
|
}
|
||||||
|
|
||||||
_fzf_dir_completion() {
|
_fzf_dir_completion() {
|
||||||
__fzf_generic_path_completion "$1" "$2" \
|
__fzf_generic_path_completion "$1" "$2" _fzf_compgen_dir \
|
||||||
"-name .git -prune -o -name .svn -prune -o -type d -print" \
|
|
||||||
"" "/" ""
|
"" "/" ""
|
||||||
}
|
}
|
||||||
|
|
||||||
_fzf_feed_fifo() (
|
_fzf_feed_fifo() (
|
||||||
rm -f "$fifo"
|
command rm -f "$1"
|
||||||
mkfifo "$fifo"
|
mkfifo "$1"
|
||||||
cat <&0 > "$fifo" &
|
cat <&0 > "$1" &
|
||||||
)
|
)
|
||||||
|
|
||||||
_fzf_complete() {
|
_fzf_complete() {
|
||||||
local fifo fzf_opts lbuf fzf matches
|
local fifo fzf_opts lbuf fzf matches post
|
||||||
fifo="${TMPDIR:-/tmp}/fzf-complete-fifo-$$"
|
fifo="${TMPDIR:-/tmp}/fzf-complete-fifo-$$"
|
||||||
fzf_opts=$1
|
fzf_opts=$1
|
||||||
lbuf=$2
|
lbuf=$2
|
||||||
|
post="${funcstack[2]}_post"
|
||||||
|
type $post > /dev/null 2>&1 || post=cat
|
||||||
|
|
||||||
[ ${FZF_TMUX:-1} -eq 1 ] && fzf="fzf-tmux -d ${FZF_TMUX_HEIGHT:-40%}" || fzf="fzf"
|
[ ${FZF_TMUX:-1} -eq 1 ] && fzf="fzf-tmux -d ${FZF_TMUX_HEIGHT:-40%}" || fzf="fzf"
|
||||||
|
|
||||||
_fzf_feed_fifo "$fifo"
|
_fzf_feed_fifo "$fifo"
|
||||||
matches=$(cat "$fifo" | ${=fzf} ${=FZF_COMPLETION_OPTS} ${=fzf_opts} -q "${(Q)prefix}" | tr '\n' ' ')
|
matches=$(cat "$fifo" | ${=fzf} ${=FZF_COMPLETION_OPTS} ${=fzf_opts} -q "${(Q)prefix}" | $post | tr '\n' ' ')
|
||||||
if [ -n "$matches" ]; then
|
if [ -n "$matches" ]; then
|
||||||
LBUFFER="$lbuf$matches"
|
LBUFFER="$lbuf$matches"
|
||||||
fi
|
fi
|
||||||
zle redisplay
|
zle redisplay
|
||||||
rm -f "$fifo"
|
typeset -f zle-line-init >/dev/null && zle zle-line-init
|
||||||
|
command rm -f "$fifo"
|
||||||
}
|
}
|
||||||
|
|
||||||
_fzf_complete_telnet() {
|
_fzf_complete_telnet() {
|
||||||
_fzf_complete '+m' "$@" < <(
|
_fzf_complete '+m' "$@" < <(
|
||||||
\grep -v '^\s*\(#\|$\)' /etc/hosts | \grep -Fv '0.0.0.0' |
|
command grep -v '^\s*\(#\|$\)' /etc/hosts | command grep -Fv '0.0.0.0' |
|
||||||
awk '{if (length($2) > 0) {print $2}}' | sort -u
|
awk '{if (length($2) > 0) {print $2}}' | sort -u
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
_fzf_complete_ssh() {
|
_fzf_complete_ssh() {
|
||||||
_fzf_complete '+m' "$@" < <(
|
_fzf_complete '+m' "$@" < <(
|
||||||
cat <(cat ~/.ssh/config /etc/ssh/ssh_config 2> /dev/null | \grep -i '^host' | \grep -v '*') \
|
cat <(cat ~/.ssh/config /etc/ssh/ssh_config 2> /dev/null | command grep -i '^host' | command grep -v '*') \
|
||||||
<(\grep -v '^\s*\(#\|$\)' /etc/hosts | \grep -Fv '0.0.0.0') |
|
<(command grep -oE '^[^ ]+' ~/.ssh/known_hosts | tr ',' '\n' | awk '{ print $1 " " $1 }') \
|
||||||
|
<(command grep -v '^\s*\(#\|$\)' /etc/hosts | command grep -Fv '0.0.0.0') |
|
||||||
awk '{if (length($2) > 0) {print $2}}' | sort -u
|
awk '{if (length($2) > 0) {print $2}}' | sort -u
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -116,17 +137,14 @@ _fzf_complete_unalias() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fzf-completion() {
|
fzf-completion() {
|
||||||
local tokens cmd prefix trigger tail fzf matches lbuf d_cmds sws
|
local tokens cmd prefix trigger tail fzf matches lbuf d_cmds
|
||||||
if setopt | grep shwordsplit > /dev/null; then
|
setopt localoptions noshwordsplit noksh_arrays
|
||||||
sws=1
|
|
||||||
unsetopt shwordsplit
|
|
||||||
fi
|
|
||||||
|
|
||||||
# http://zsh.sourceforge.net/FAQ/zshfaq03.html
|
# http://zsh.sourceforge.net/FAQ/zshfaq03.html
|
||||||
# http://zsh.sourceforge.net/Doc/Release/Expansion.html#Parameter-Expansion-Flags
|
# http://zsh.sourceforge.net/Doc/Release/Expansion.html#Parameter-Expansion-Flags
|
||||||
tokens=(${(z)LBUFFER})
|
tokens=(${(z)LBUFFER})
|
||||||
if [ ${#tokens} -lt 1 ]; then
|
if [ ${#tokens} -lt 1 ]; then
|
||||||
eval "zle ${fzf_default_completion:-expand-or-complete}"
|
zle ${fzf_default_completion:-expand-or-complete}
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -145,9 +163,10 @@ fzf-completion() {
|
|||||||
LBUFFER="$LBUFFER$matches"
|
LBUFFER="$LBUFFER$matches"
|
||||||
fi
|
fi
|
||||||
zle redisplay
|
zle redisplay
|
||||||
|
typeset -f zle-line-init >/dev/null && zle zle-line-init
|
||||||
# Trigger sequence given
|
# Trigger sequence given
|
||||||
elif [ ${#tokens} -gt 1 -a "$tail" = "$trigger" ]; then
|
elif [ ${#tokens} -gt 1 -a "$tail" = "$trigger" ]; then
|
||||||
d_cmds=(cd pushd rmdir)
|
d_cmds=(${=FZF_COMPLETION_DIR_COMMANDS:-cd pushd rmdir})
|
||||||
|
|
||||||
[ -z "$trigger" ] && prefix=${tokens[-1]} || prefix=${tokens[-1]:0:-${#trigger}}
|
[ -z "$trigger" ] && prefix=${tokens[-1]} || prefix=${tokens[-1]:0:-${#trigger}}
|
||||||
[ -z "${tokens[-1]}" ] && lbuf=$LBUFFER || lbuf=${LBUFFER:0:-${#tokens[-1]}}
|
[ -z "${tokens[-1]}" ] && lbuf=$LBUFFER || lbuf=${LBUFFER:0:-${#tokens[-1]}}
|
||||||
@@ -161,14 +180,15 @@ fzf-completion() {
|
|||||||
fi
|
fi
|
||||||
# Fall back to default completion
|
# Fall back to default completion
|
||||||
else
|
else
|
||||||
eval "zle ${fzf_default_completion:-expand-or-complete}"
|
zle ${fzf_default_completion:-expand-or-complete}
|
||||||
fi
|
fi
|
||||||
[ -n "$sws" ] && setopt shwordsplit
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[ -z "$fzf_default_completion" ] &&
|
[ -z "$fzf_default_completion" ] && {
|
||||||
fzf_default_completion=$(bindkey '^I' | grep -v undefined-key | awk '{print $2}')
|
binding=$(bindkey '^I')
|
||||||
|
[[ $binding =~ 'undefined-key' ]] || fzf_default_completion=$binding[(w)2]
|
||||||
|
unset binding
|
||||||
|
}
|
||||||
|
|
||||||
zle -N fzf-completion
|
zle -N fzf-completion
|
||||||
bindkey '^I' fzf-completion
|
bindkey '^I' fzf-completion
|
||||||
|
|
||||||
|
@@ -1,11 +1,11 @@
|
|||||||
# Key bindings
|
# Key bindings
|
||||||
# ------------
|
# ------------
|
||||||
__fzf_select__() {
|
__fzf_select__() {
|
||||||
local cmd="${FZF_CTRL_T_COMMAND:-"command \\find -L . \\( -path '*/\\.*' -o -fstype 'dev' -o -fstype 'proc' \\) -prune \
|
local cmd="${FZF_CTRL_T_COMMAND:-"command find -L . \\( -path '*/\\.*' -o -fstype 'dev' -o -fstype 'proc' \\) -prune \
|
||||||
-o -type f -print \
|
-o -type f -print \
|
||||||
-o -type d -print \
|
-o -type d -print \
|
||||||
-o -type l -print 2> /dev/null | sed 1d | cut -b3-"}"
|
-o -type l -print 2> /dev/null | sed 1d | cut -b3-"}"
|
||||||
eval "$cmd" | fzf -m | while read item; do
|
eval "$cmd | fzf -m $FZF_CTRL_T_OPTS" | while read -r item; do
|
||||||
printf '%q ' "$item"
|
printf '%q ' "$item"
|
||||||
done
|
done
|
||||||
echo
|
echo
|
||||||
@@ -14,7 +14,7 @@ __fzf_select__() {
|
|||||||
if [[ $- =~ i ]]; then
|
if [[ $- =~ i ]]; then
|
||||||
|
|
||||||
__fzfcmd() {
|
__fzfcmd() {
|
||||||
[ ${FZF_TMUX:-1} -eq 1 ] && echo "fzf-tmux -d${FZF_TMUX_HEIGHT:-40%}" || echo "fzf"
|
[ "${FZF_TMUX:-1}" != 0 ] && echo "fzf-tmux -d${FZF_TMUX_HEIGHT:-40%}" || echo "fzf"
|
||||||
}
|
}
|
||||||
|
|
||||||
__fzf_select_tmux__() {
|
__fzf_select_tmux__() {
|
||||||
@@ -25,13 +25,25 @@ __fzf_select_tmux__() {
|
|||||||
else
|
else
|
||||||
height="-l $height"
|
height="-l $height"
|
||||||
fi
|
fi
|
||||||
tmux split-window $height "cd $(printf %q "$PWD"); FZF_CTRL_T_COMMAND=$(printf %q "$FZF_CTRL_T_COMMAND") bash -c 'source ~/.fzf.bash; tmux send-keys -t $TMUX_PANE \"\$(__fzf_select__)\"'"
|
|
||||||
|
tmux split-window $height "cd $(printf %q "$PWD"); FZF_DEFAULT_OPTS=$(printf %q "$FZF_DEFAULT_OPTS") PATH=$(printf %q "$PATH") FZF_CTRL_T_COMMAND=$(printf %q "$FZF_CTRL_T_COMMAND") FZF_CTRL_T_OPTS=$(printf %q "$FZF_CTRL_T_OPTS") bash -c 'source \"${BASH_SOURCE[0]}\"; RESULT=\"\$(__fzf_select__)\"; tmux setb -b fzf \"\$RESULT\" \\; pasteb -b fzf -t $TMUX_PANE \\; deleteb -b fzf || tmux send-keys -t $TMUX_PANE \"\$RESULT\"'"
|
||||||
|
}
|
||||||
|
|
||||||
|
fzf-file-widget() {
|
||||||
|
if __fzf_use_tmux__; then
|
||||||
|
__fzf_select_tmux__
|
||||||
|
else
|
||||||
|
local selected="$(__fzf_select__)"
|
||||||
|
READLINE_LINE="${READLINE_LINE:0:$READLINE_POINT}$selected${READLINE_LINE:$READLINE_POINT}"
|
||||||
|
READLINE_POINT=$(( READLINE_POINT + ${#selected} ))
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
__fzf_cd__() {
|
__fzf_cd__() {
|
||||||
local dir
|
local cmd dir
|
||||||
dir=$(command \find -L ${1:-.} \( -path '*/\.*' -o -fstype 'dev' -o -fstype 'proc' \) -prune \
|
cmd="${FZF_ALT_C_COMMAND:-"command find -L . \\( -path '*/\\.*' -o -fstype 'dev' -o -fstype 'proc' \\) -prune \
|
||||||
-o -type d -print 2> /dev/null | sed 1d | cut -b3- | $(__fzfcmd) +m) && printf 'cd %q' "$dir"
|
-o -type d -print 2> /dev/null | sed 1d | cut -b3-"}"
|
||||||
|
dir=$(eval "$cmd | $(__fzfcmd) +m $FZF_ALT_C_OPTS") && printf 'cd %q' "$dir"
|
||||||
}
|
}
|
||||||
|
|
||||||
__fzf_history__() (
|
__fzf_history__() (
|
||||||
@@ -39,8 +51,8 @@ __fzf_history__() (
|
|||||||
shopt -u nocaseglob nocasematch
|
shopt -u nocaseglob nocasematch
|
||||||
line=$(
|
line=$(
|
||||||
HISTTIMEFORMAT= history |
|
HISTTIMEFORMAT= history |
|
||||||
$(__fzfcmd) +s --tac +m -n2..,.. --tiebreak=index --toggle-sort=ctrl-r |
|
eval "$(__fzfcmd) +s --tac +m -n2..,.. --tiebreak=index --toggle-sort=ctrl-r $FZF_CTRL_R_OPTS" |
|
||||||
\grep '^ *[0-9]') &&
|
command grep '^ *[0-9]') &&
|
||||||
if [[ $- =~ H ]]; then
|
if [[ $- =~ H ]]; then
|
||||||
sed 's/^ *\([0-9]*\)\** .*/!\1/' <<< "$line"
|
sed 's/^ *\([0-9]*\)\** .*/!\1/' <<< "$line"
|
||||||
else
|
else
|
||||||
@@ -48,49 +60,66 @@ __fzf_history__() (
|
|||||||
fi
|
fi
|
||||||
)
|
)
|
||||||
|
|
||||||
__use_tmux=0
|
__fzf_use_tmux__() {
|
||||||
[ -n "$TMUX_PANE" -a ${FZF_TMUX:-1} -ne 0 -a ${LINES:-40} -gt 15 ] && __use_tmux=1
|
[ -n "$TMUX_PANE" ] && [ "${FZF_TMUX:-1}" != 0 ] && [ ${LINES:-40} -gt 15 ]
|
||||||
|
}
|
||||||
|
|
||||||
if [ -z "$(set -o | \grep '^vi.*on')" ]; then
|
[ $BASH_VERSINFO -gt 3 ] && __use_bind_x=1 || __use_bind_x=0
|
||||||
|
__fzf_use_tmux__ && __use_tmux=1 || __use_tmux=0
|
||||||
|
|
||||||
|
if [[ ! -o vi ]]; then
|
||||||
# Required to refresh the prompt after fzf
|
# Required to refresh the prompt after fzf
|
||||||
bind '"\er": redraw-current-line'
|
bind '"\er": redraw-current-line'
|
||||||
bind '"\e^": history-expand-line'
|
bind '"\e^": history-expand-line'
|
||||||
|
|
||||||
# CTRL-T - Paste the selected file path into the command line
|
# CTRL-T - Paste the selected file path into the command line
|
||||||
if [ $__use_tmux -eq 1 ]; then
|
if [ $__use_bind_x -eq 1 ]; then
|
||||||
|
bind -x '"\C-t": "fzf-file-widget"'
|
||||||
|
elif [ $__use_tmux -eq 1 ]; then
|
||||||
bind '"\C-t": " \C-u \C-a\C-k$(__fzf_select_tmux__)\e\C-e\C-y\C-a\C-d\C-y\ey\C-h"'
|
bind '"\C-t": " \C-u \C-a\C-k$(__fzf_select_tmux__)\e\C-e\C-y\C-a\C-d\C-y\ey\C-h"'
|
||||||
else
|
else
|
||||||
bind '"\C-t": " \C-u \C-a\C-k$(__fzf_select__)\e\C-e\C-y\C-a\C-y\ey\C-h\C-e\er \C-h"'
|
bind '"\C-t": " \C-u \C-a\C-k$(__fzf_select__)\e\C-e\C-y\C-a\C-y\ey\C-h\C-e\er \C-h"'
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# CTRL-R - Paste the selected command from history into the command line
|
# CTRL-R - Paste the selected command from history into the command line
|
||||||
bind '"\C-r": " \C-e\C-u$(__fzf_history__)\e\C-e\e^\er"'
|
bind '"\C-r": " \C-e\C-u`__fzf_history__`\e\C-e\e^\er"'
|
||||||
|
|
||||||
# ALT-C - cd into the selected directory
|
# ALT-C - cd into the selected directory
|
||||||
bind '"\ec": " \C-e\C-u$(__fzf_cd__)\e\C-e\er\C-m"'
|
bind '"\ec": " \C-e\C-u`__fzf_cd__`\e\C-e\er\C-m"'
|
||||||
else
|
else
|
||||||
|
# We'd usually use "\e" to enter vi-movement-mode so we can do our magic,
|
||||||
|
# but this incurs a very noticeable delay of a half second or so,
|
||||||
|
# because many other commands start with "\e".
|
||||||
|
# Instead, we bind an unused key, "\C-x\C-a",
|
||||||
|
# to also enter vi-movement-mode,
|
||||||
|
# and then use that thereafter.
|
||||||
|
# (We imagine that "\C-x\C-a" is relatively unlikely to be in use.)
|
||||||
|
bind '"\C-x\C-a": vi-movement-mode'
|
||||||
|
|
||||||
bind '"\C-x\C-e": shell-expand-line'
|
bind '"\C-x\C-e": shell-expand-line'
|
||||||
bind '"\C-x\C-r": redraw-current-line'
|
bind '"\C-x\C-r": redraw-current-line'
|
||||||
bind '"\C-x^": history-expand-line'
|
bind '"\C-x^": history-expand-line'
|
||||||
|
|
||||||
# CTRL-T - Paste the selected file path into the command line
|
# CTRL-T - Paste the selected file path into the command line
|
||||||
# - FIXME: Selected items are attached to the end regardless of cursor position
|
# - FIXME: Selected items are attached to the end regardless of cursor position
|
||||||
if [ $__use_tmux -eq 1 ]; then
|
if [ $__use_bind_x -eq 1 ]; then
|
||||||
bind '"\C-t": "\e$a \eddi$(__fzf_select_tmux__)\C-x\C-e\e0P$xa"'
|
bind -x '"\C-t": "fzf-file-widget"'
|
||||||
|
elif [ $__use_tmux -eq 1 ]; then
|
||||||
|
bind '"\C-t": "\C-x\C-a$a \C-x\C-addi$(__fzf_select_tmux__)\C-x\C-e\C-x\C-a0P$xa"'
|
||||||
else
|
else
|
||||||
bind '"\C-t": "\e$a \eddi$(__fzf_select__)\C-x\C-e\e0Px$a \C-x\C-r\exa "'
|
bind '"\C-t": "\C-x\C-a$a \C-x\C-addi$(__fzf_select__)\C-x\C-e\C-x\C-a0Px$a \C-x\C-r\C-x\C-axa "'
|
||||||
fi
|
fi
|
||||||
bind -m vi-command '"\C-t": "i\C-t"'
|
bind -m vi-command '"\C-t": "i\C-t"'
|
||||||
|
|
||||||
# CTRL-R - Paste the selected command from history into the command line
|
# CTRL-R - Paste the selected command from history into the command line
|
||||||
bind '"\C-r": "\eddi$(__fzf_history__)\C-x\C-e\C-x^\e$a\C-x\C-r"'
|
bind '"\C-r": "\C-x\C-addi$(__fzf_history__)\C-x\C-e\C-x^\C-x\C-a$a\C-x\C-r"'
|
||||||
bind -m vi-command '"\C-r": "i\C-r"'
|
bind -m vi-command '"\C-r": "i\C-r"'
|
||||||
|
|
||||||
# ALT-C - cd into the selected directory
|
# ALT-C - cd into the selected directory
|
||||||
bind '"\ec": "\eddi$(__fzf_cd__)\C-x\C-e\C-x\C-r\C-m"'
|
bind '"\ec": "\C-x\C-addi$(__fzf_cd__)\C-x\C-e\C-x\C-r\C-m"'
|
||||||
bind -m vi-command '"\ec": "i\ec"'
|
bind -m vi-command '"\ec": "ddi$(__fzf_cd__)\C-x\C-e\C-x\C-r\C-m"'
|
||||||
fi
|
fi
|
||||||
|
|
||||||
unset __use_tmux
|
unset -v __use_tmux __use_bind_x
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
@@ -13,29 +13,31 @@ function fzf_key_bindings
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function __fzf_ctrl_t
|
function fzf-file-widget
|
||||||
set -q FZF_CTRL_T_COMMAND; or set -l FZF_CTRL_T_COMMAND "
|
set -q FZF_CTRL_T_COMMAND; or set -l FZF_CTRL_T_COMMAND "
|
||||||
command find -L . \\( -path '*/\\.*' -o -fstype 'dev' -o -fstype 'proc' \\) -prune \
|
command find -L . \\( -path '*/\\.*' -o -fstype 'dev' -o -fstype 'proc' \\) -prune \
|
||||||
-o -type f -print \
|
-o -type f -print \
|
||||||
-o -type d -print \
|
-o -type d -print \
|
||||||
-o -type l -print 2> /dev/null | sed 1d | cut -b3-"
|
-o -type l -print 2> /dev/null | sed 1d | cut -b3-"
|
||||||
eval "$FZF_CTRL_T_COMMAND | "(__fzfcmd)" -m > $TMPDIR/fzf.result"
|
eval "$FZF_CTRL_T_COMMAND | "(__fzfcmd)" -m $FZF_CTRL_T_OPTS > $TMPDIR/fzf.result"
|
||||||
and commandline -i (cat $TMPDIR/fzf.result | __fzf_escape)
|
and for i in (seq 20); commandline -i (cat $TMPDIR/fzf.result | __fzf_escape) 2> /dev/null; and break; sleep 0.1; end
|
||||||
commandline -f repaint
|
commandline -f repaint
|
||||||
rm -f $TMPDIR/fzf.result
|
rm -f $TMPDIR/fzf.result
|
||||||
end
|
end
|
||||||
|
|
||||||
function __fzf_ctrl_r
|
function fzf-history-widget
|
||||||
history | eval (__fzfcmd) +s +m --tiebreak=index --toggle-sort=ctrl-r > $TMPDIR/fzf.result
|
history | eval (__fzfcmd) +s +m --tiebreak=index --toggle-sort=ctrl-r $FZF_CTRL_R_OPTS > $TMPDIR/fzf.result
|
||||||
and commandline (cat $TMPDIR/fzf.result)
|
and commandline (cat $TMPDIR/fzf.result)
|
||||||
commandline -f repaint
|
commandline -f repaint
|
||||||
rm -f $TMPDIR/fzf.result
|
rm -f $TMPDIR/fzf.result
|
||||||
end
|
end
|
||||||
|
|
||||||
function __fzf_alt_c
|
function fzf-cd-widget
|
||||||
|
set -q FZF_ALT_C_COMMAND; or set -l FZF_ALT_C_COMMAND "
|
||||||
|
command find -L . \\( -path '*/\\.*' -o -fstype 'dev' -o -fstype 'proc' \\) -prune \
|
||||||
|
-o -type d -print 2> /dev/null | sed 1d | cut -b3-"
|
||||||
# Fish hangs if the command before pipe redirects (2> /dev/null)
|
# Fish hangs if the command before pipe redirects (2> /dev/null)
|
||||||
command find -L . \( -path '*/\.*' -o -fstype 'dev' -o -fstype 'proc' \) \
|
eval "$FZF_ALT_C_COMMAND | "(__fzfcmd)" +m $FZF_ALT_C_OPTS > $TMPDIR/fzf.result"
|
||||||
-prune -o -type d -print 2> /dev/null | sed 1d | cut -b3- | eval (__fzfcmd) +m > $TMPDIR/fzf.result
|
|
||||||
[ (cat $TMPDIR/fzf.result | wc -l) -gt 0 ]
|
[ (cat $TMPDIR/fzf.result | wc -l) -gt 0 ]
|
||||||
and cd (cat $TMPDIR/fzf.result)
|
and cd (cat $TMPDIR/fzf.result)
|
||||||
commandline -f repaint
|
commandline -f repaint
|
||||||
@@ -56,14 +58,14 @@ function fzf_key_bindings
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
bind \ct '__fzf_ctrl_t'
|
bind \ct fzf-file-widget
|
||||||
bind \cr '__fzf_ctrl_r'
|
bind \cr fzf-history-widget
|
||||||
bind \ec '__fzf_alt_c'
|
bind \ec fzf-cd-widget
|
||||||
|
|
||||||
if bind -M insert > /dev/null 2>&1
|
if bind -M insert > /dev/null 2>&1
|
||||||
bind -M insert \ct '__fzf_ctrl_t'
|
bind -M insert \ct fzf-file-widget
|
||||||
bind -M insert \cr '__fzf_ctrl_r'
|
bind -M insert \cr fzf-history-widget
|
||||||
bind -M insert \ec '__fzf_alt_c'
|
bind -M insert \ec fzf-cd-widget
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@@ -4,14 +4,17 @@ if [[ $- == *i* ]]; then
|
|||||||
|
|
||||||
# CTRL-T - Paste the selected file path(s) into the command line
|
# CTRL-T - Paste the selected file path(s) into the command line
|
||||||
__fsel() {
|
__fsel() {
|
||||||
local cmd="${FZF_CTRL_T_COMMAND:-"command \\find -L . \\( -path '*/\\.*' -o -fstype 'dev' -o -fstype 'proc' \\) -prune \
|
local cmd="${FZF_CTRL_T_COMMAND:-"command find -L . \\( -path '*/\\.*' -o -fstype 'dev' -o -fstype 'proc' \\) -prune \
|
||||||
-o -type f -print \
|
-o -type f -print \
|
||||||
-o -type d -print \
|
-o -type d -print \
|
||||||
-o -type l -print 2> /dev/null | sed 1d | cut -b3-"}"
|
-o -type l -print 2> /dev/null | sed 1d | cut -b3-"}"
|
||||||
eval "$cmd" | $(__fzfcmd) -m | while read item; do
|
setopt localoptions pipefail 2> /dev/null
|
||||||
printf '%q ' "$item"
|
eval "$cmd | $(__fzfcmd) -m $FZF_CTRL_T_OPTS" | while read item; do
|
||||||
|
echo -n "${(q)item} "
|
||||||
done
|
done
|
||||||
|
local ret=$?
|
||||||
echo
|
echo
|
||||||
|
return $ret
|
||||||
}
|
}
|
||||||
|
|
||||||
__fzfcmd() {
|
__fzfcmd() {
|
||||||
@@ -20,30 +23,43 @@ __fzfcmd() {
|
|||||||
|
|
||||||
fzf-file-widget() {
|
fzf-file-widget() {
|
||||||
LBUFFER="${LBUFFER}$(__fsel)"
|
LBUFFER="${LBUFFER}$(__fsel)"
|
||||||
|
local ret=$?
|
||||||
zle redisplay
|
zle redisplay
|
||||||
|
typeset -f zle-line-init >/dev/null && zle zle-line-init
|
||||||
|
return $ret
|
||||||
}
|
}
|
||||||
zle -N fzf-file-widget
|
zle -N fzf-file-widget
|
||||||
bindkey '^T' fzf-file-widget
|
bindkey '^T' fzf-file-widget
|
||||||
|
|
||||||
# ALT-C - cd into the selected directory
|
# ALT-C - cd into the selected directory
|
||||||
fzf-cd-widget() {
|
fzf-cd-widget() {
|
||||||
cd "${$(command \find -L . \( -path '*/\.*' -o -fstype 'dev' -o -fstype 'proc' \) -prune \
|
local cmd="${FZF_ALT_C_COMMAND:-"command find -L . \\( -path '*/\\.*' -o -fstype 'dev' -o -fstype 'proc' \\) -prune \
|
||||||
-o -type d -print 2> /dev/null | sed 1d | cut -b3- | $(__fzfcmd) +m):-.}"
|
-o -type d -print 2> /dev/null | sed 1d | cut -b3-"}"
|
||||||
|
setopt localoptions pipefail 2> /dev/null
|
||||||
|
cd "${$(eval "$cmd | $(__fzfcmd) +m $FZF_ALT_C_OPTS"):-.}"
|
||||||
|
local ret=$?
|
||||||
zle reset-prompt
|
zle reset-prompt
|
||||||
|
typeset -f zle-line-init >/dev/null && zle zle-line-init
|
||||||
|
return $ret
|
||||||
}
|
}
|
||||||
zle -N fzf-cd-widget
|
zle -N fzf-cd-widget
|
||||||
bindkey '\ec' fzf-cd-widget
|
bindkey '\ec' fzf-cd-widget
|
||||||
|
|
||||||
# CTRL-R - Paste the selected command from history into the command line
|
# CTRL-R - Paste the selected command from history into the command line
|
||||||
fzf-history-widget() {
|
fzf-history-widget() {
|
||||||
local selected restore_no_bang_hist
|
local selected num
|
||||||
if selected=( $(fc -l 1 | $(__fzfcmd) +s --tac +m -n2..,.. --tiebreak=index --toggle-sort=ctrl-r -q "$LBUFFER") ); then
|
setopt localoptions noglobsubst pipefail 2> /dev/null
|
||||||
|
selected=( $(fc -l 1 | eval "$(__fzfcmd) +s --tac +m -n2..,.. --tiebreak=index --toggle-sort=ctrl-r $FZF_CTRL_R_OPTS -q ${(q)LBUFFER}") )
|
||||||
|
local ret=$?
|
||||||
|
if [ -n "$selected" ]; then
|
||||||
num=$selected[1]
|
num=$selected[1]
|
||||||
if [ -n "$num" ]; then
|
if [ -n "$num" ]; then
|
||||||
zle vi-fetch-history -n $num
|
zle vi-fetch-history -n $num
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
zle redisplay
|
zle redisplay
|
||||||
|
typeset -f zle-line-init >/dev/null && zle zle-line-init
|
||||||
|
return $ret
|
||||||
}
|
}
|
||||||
zle -N fzf-history-widget
|
zle -N fzf-history-widget
|
||||||
bindkey '^R' fzf-history-widget
|
bindkey '^R' fzf-history-widget
|
||||||
|
40
src/Dockerfile.android
Normal file
40
src/Dockerfile.android
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
FROM ubuntu:14.04
|
||||||
|
MAINTAINER Junegunn Choi <junegunn.c@gmail.com>
|
||||||
|
|
||||||
|
# apt-get
|
||||||
|
RUN apt-get update && apt-get -y upgrade && \
|
||||||
|
apt-get install -y --force-yes git curl build-essential
|
||||||
|
|
||||||
|
# Install Go 1.4
|
||||||
|
RUN cd / && curl \
|
||||||
|
https://storage.googleapis.com/golang/go1.4.2.linux-amd64.tar.gz | \
|
||||||
|
tar -xz && mv go go1.4 && \
|
||||||
|
sed -i 's@#define PTHREAD_KEYS_MAX 128@@' /go1.4/src/runtime/cgo/gcc_android_arm.c
|
||||||
|
|
||||||
|
ENV GOROOT /go1.4
|
||||||
|
ENV PATH /go1.4/bin:$PATH
|
||||||
|
|
||||||
|
RUN cd / && \
|
||||||
|
curl -O http://dl.google.com/android/ndk/android-ndk-r10e-linux-x86_64.bin && \
|
||||||
|
chmod 755 /android-ndk* && /android-ndk-r10e-linux-x86_64.bin && \
|
||||||
|
mv android-ndk-r10e /android-ndk
|
||||||
|
|
||||||
|
RUN cd /android-ndk && bash ./build/tools/make-standalone-toolchain.sh --platform=android-21 --install-dir=/ndk --arch=arm
|
||||||
|
|
||||||
|
ENV NDK_CC /ndk/bin/arm-linux-androideabi-gcc
|
||||||
|
|
||||||
|
RUN cd $GOROOT/src && \
|
||||||
|
CC_FOR_TARGET=$NDK_CC GOOS=android GOARCH=arm GOARM=7 ./make.bash
|
||||||
|
|
||||||
|
RUN cd / && curl \
|
||||||
|
http://ftp.gnu.org/gnu/ncurses/ncurses-5.9.tar.gz | \
|
||||||
|
tar -xz && cd /ncurses-5.9 && \
|
||||||
|
./configure CC=$NDK_CC CFLAGS="-fPIE -march=armv7-a -mfpu=neon -mhard-float -Wl,--no-warn-mismatch" LDFLAGS="-march=armv7-a -Wl,--no-warn-mismatch" --host=arm-linux --enable-overwrite --enable-const --without-cxx-binding --without-shared --without-debug --enable-widec --enable-ext-colors --enable-ext-mouse --enable-pc-files --with-pkg-config-libdir=$PKG_CONFIG_LIBDIR --without-manpages --without-ada --disable-shared --without-tests --prefix=/ndk/sysroot/usr --with-default-terminfo-dirs=/usr/share/terminfo --with-terminfo-dirs=/usr/share/terminfo ac_cv_header_locale_h=n ac_cv_func_getpwent=no ac_cv_func_getpwnam=no ac_cv_func_getpwuid=no && \
|
||||||
|
sed -i 's@#define HAVE_LOCALE_H 1@/* #undef HAVE_LOCALE_H */@' include/ncurses_cfg.h && \
|
||||||
|
make && \
|
||||||
|
sed -i '0,/echo.*/{s/echo.*/exit 0/}' misc/run_tic.sh && \
|
||||||
|
make install && \
|
||||||
|
mv /ndk/sysroot/usr/lib/libncursesw.a /ndk/sysroot/usr/lib/libncurses.a
|
||||||
|
|
||||||
|
# Default CMD
|
||||||
|
CMD cd /fzf/src && /bin/bash
|
@@ -10,7 +10,6 @@ RUN cd / && curl \
|
|||||||
https://storage.googleapis.com/golang/go1.4.2.linux-amd64.tar.gz | \
|
https://storage.googleapis.com/golang/go1.4.2.linux-amd64.tar.gz | \
|
||||||
tar -xz && mv go go1.4
|
tar -xz && mv go go1.4
|
||||||
|
|
||||||
ENV GOPATH /go
|
|
||||||
ENV GOROOT /go1.4
|
ENV GOROOT /go1.4
|
||||||
ENV PATH /go1.4/bin:$PATH
|
ENV PATH /go1.4/bin:$PATH
|
||||||
|
|
||||||
@@ -20,9 +19,6 @@ RUN echo '[multilib]' >> /etc/pacman.conf && \
|
|||||||
pacman-db-upgrade && yes | pacman -Sy gcc-multilib lib32-ncurses && \
|
pacman-db-upgrade && yes | pacman -Sy gcc-multilib lib32-ncurses && \
|
||||||
cd $GOROOT/src && GOARCH=386 ./make.bash
|
cd $GOROOT/src && GOARCH=386 ./make.bash
|
||||||
|
|
||||||
# Volume
|
|
||||||
VOLUME /go
|
|
||||||
|
|
||||||
# Default CMD
|
# Default CMD
|
||||||
CMD cd /go/src/github.com/junegunn/fzf/src && /bin/bash
|
CMD cd /fzf/src && /bin/bash
|
||||||
|
|
||||||
|
@@ -11,16 +11,22 @@ RUN cd / && curl \
|
|||||||
https://storage.googleapis.com/golang/go1.4.2.linux-amd64.tar.gz | \
|
https://storage.googleapis.com/golang/go1.4.2.linux-amd64.tar.gz | \
|
||||||
tar -xz && mv go go1.4
|
tar -xz && mv go go1.4
|
||||||
|
|
||||||
ENV GOPATH /go
|
# Install Go 1.5
|
||||||
ENV GOROOT /go1.4
|
RUN cd / && curl \
|
||||||
ENV PATH /go1.4/bin:$PATH
|
https://storage.googleapis.com/golang/go1.5.3.linux-amd64.tar.gz | \
|
||||||
|
tar -xz && mv go go1.5
|
||||||
|
|
||||||
|
# Install RPMs for building static 32-bit binary
|
||||||
|
RUN curl ftp://ftp.pbone.net/mirror/ftp.centos.org/6.7/os/i386/Packages/ncurses-static-5.7-4.20090207.el6.i686.rpm -o rpm && rpm -i rpm && \
|
||||||
|
curl ftp://ftp.pbone.net/mirror/ftp.centos.org/6.7/os/i386/Packages/gpm-static-1.20.6-12.el6.i686.rpm -o rpm && rpm -i rpm
|
||||||
|
|
||||||
|
ENV GOROOT_BOOTSTRAP /go1.4
|
||||||
|
ENV GOROOT /go1.5
|
||||||
|
ENV PATH /go1.5/bin:$PATH
|
||||||
|
|
||||||
# For i386 build
|
# For i386 build
|
||||||
RUN cd $GOROOT/src && GOARCH=386 ./make.bash
|
RUN cd $GOROOT/src && GOARCH=386 ./make.bash
|
||||||
|
|
||||||
# Volume
|
|
||||||
VOLUME /go
|
|
||||||
|
|
||||||
# Default CMD
|
# Default CMD
|
||||||
CMD cd /go/src/github.com/junegunn/fzf/src && /bin/bash
|
CMD cd /fzf/src && /bin/bash
|
||||||
|
|
||||||
|
@@ -10,7 +10,6 @@ RUN cd / && curl \
|
|||||||
https://storage.googleapis.com/golang/go1.4.2.linux-amd64.tar.gz | \
|
https://storage.googleapis.com/golang/go1.4.2.linux-amd64.tar.gz | \
|
||||||
tar -xz && mv go go1.4
|
tar -xz && mv go go1.4
|
||||||
|
|
||||||
ENV GOPATH /go
|
|
||||||
ENV GOROOT /go1.4
|
ENV GOROOT /go1.4
|
||||||
ENV PATH /go1.4/bin:$PATH
|
ENV PATH /go1.4/bin:$PATH
|
||||||
|
|
||||||
@@ -18,9 +17,6 @@ ENV PATH /go1.4/bin:$PATH
|
|||||||
RUN apt-get install -y lib32ncurses5-dev && \
|
RUN apt-get install -y lib32ncurses5-dev && \
|
||||||
cd $GOROOT/src && GOARCH=386 ./make.bash
|
cd $GOROOT/src && GOARCH=386 ./make.bash
|
||||||
|
|
||||||
# Volume
|
|
||||||
VOLUME /go
|
|
||||||
|
|
||||||
# Default CMD
|
# Default CMD
|
||||||
CMD cd /go/src/github.com/junegunn/fzf/src && /bin/bash
|
CMD cd /fzf/src && /bin/bash
|
||||||
|
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
|
|
||||||
Copyright (c) 2015 Junegunn Choi
|
Copyright (c) 2016 Junegunn Choi
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
103
src/Makefile
103
src/Makefile
@@ -1,57 +1,76 @@
|
|||||||
ifndef GOPATH
|
ifndef GOOS
|
||||||
$(error GOPATH is undefined)
|
|
||||||
endif
|
|
||||||
|
|
||||||
UNAME_S := $(shell uname -s)
|
UNAME_S := $(shell uname -s)
|
||||||
ifeq ($(UNAME_S),Darwin)
|
ifeq ($(UNAME_S),Darwin)
|
||||||
GOOS := darwin
|
GOOS := darwin
|
||||||
else ifeq ($(UNAME_S),Linux)
|
else ifeq ($(UNAME_S),Linux)
|
||||||
GOOS := linux
|
GOOS := linux
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifneq ($(shell uname -m),x86_64)
|
|
||||||
$(error "Build on $(UNAME_M) is not supported, yet.")
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
SOURCES := $(wildcard *.go */*.go)
|
SOURCES := $(wildcard *.go */*.go)
|
||||||
BINDIR := ../bin
|
ROOTDIR := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
|
||||||
|
BINDIR := $(shell dirname $(ROOTDIR))/bin
|
||||||
|
GOPATH := $(shell dirname $(ROOTDIR))/gopath
|
||||||
|
SRCDIR := $(GOPATH)/src/github.com/junegunn/fzf/src
|
||||||
|
DOCKEROPTS := -i -t -v $(ROOTDIR):/fzf/src
|
||||||
BINARY32 := fzf-$(GOOS)_386
|
BINARY32 := fzf-$(GOOS)_386
|
||||||
BINARY64 := fzf-$(GOOS)_amd64
|
BINARY64 := fzf-$(GOOS)_amd64
|
||||||
VERSION = $(shell fzf/$(BINARY64) --version)
|
BINARYARM7 := fzf-$(GOOS)_arm7
|
||||||
RELEASE32 = fzf-$(VERSION)-$(GOOS)_386
|
VERSION := $(shell awk -F= '/version =/ {print $$2}' constants.go | tr -d "\" ")
|
||||||
RELEASE64 = fzf-$(VERSION)-$(GOOS)_amd64
|
RELEASE32 := fzf-$(VERSION)-$(GOOS)_386
|
||||||
|
RELEASE64 := fzf-$(VERSION)-$(GOOS)_amd64
|
||||||
|
RELEASEARM7 := fzf-$(VERSION)-$(GOOS)_arm7
|
||||||
|
export GOPATH
|
||||||
|
|
||||||
all: release
|
UNAME_M := $(shell uname -m)
|
||||||
|
ifeq ($(UNAME_M),x86_64)
|
||||||
|
BINARY := $(BINARY64)
|
||||||
|
else ifeq ($(UNAME_M),i686)
|
||||||
|
BINARY := $(BINARY32)
|
||||||
|
else
|
||||||
|
$(error "Build on $(UNAME_M) is not supported, yet.")
|
||||||
|
endif
|
||||||
|
|
||||||
release: build
|
all: fzf/$(BINARY)
|
||||||
|
|
||||||
|
release: test fzf/$(BINARY32) fzf/$(BINARY64)
|
||||||
-cd fzf && cp $(BINARY32) $(RELEASE32) && tar -czf $(RELEASE32).tgz $(RELEASE32)
|
-cd fzf && cp $(BINARY32) $(RELEASE32) && tar -czf $(RELEASE32).tgz $(RELEASE32)
|
||||||
cd fzf && cp $(BINARY64) $(RELEASE64) && tar -czf $(RELEASE64).tgz $(RELEASE64) && \
|
cd fzf && cp $(BINARY64) $(RELEASE64) && tar -czf $(RELEASE64).tgz $(RELEASE64) && \
|
||||||
rm -f $(RELEASE32) $(RELEASE64)
|
rm -f $(RELEASE32) $(RELEASE64)
|
||||||
|
|
||||||
build: test fzf/$(BINARY32) fzf/$(BINARY64)
|
$(SRCDIR):
|
||||||
|
mkdir -p $(shell dirname $(SRCDIR))
|
||||||
|
ln -s $(ROOTDIR) $(SRCDIR)
|
||||||
|
|
||||||
test:
|
deps: $(SRCDIR) $(SOURCES)
|
||||||
go get
|
cd $(SRCDIR) && go get
|
||||||
go test -v ./...
|
|
||||||
|
android-build: $(SRCDIR)
|
||||||
|
cd $(SRCDIR) && GOARCH=arm GOARM=7 CGO_ENABLED=1 go get
|
||||||
|
cd $(SRCDIR)/fzf && GOARCH=arm GOARM=7 CGO_ENABLED=1 go build -a -ldflags="-w -extldflags=-pie" -o $(BINARYARM7)
|
||||||
|
cd $(SRCDIR)/fzf && cp $(BINARYARM7) $(RELEASEARM7) && tar -czf $(RELEASEARM7).tgz $(RELEASEARM7) && \
|
||||||
|
rm -f $(RELEASEARM7)
|
||||||
|
|
||||||
|
test: deps
|
||||||
|
SHELL=/bin/sh go test -v ./...
|
||||||
|
|
||||||
install: $(BINDIR)/fzf
|
install: $(BINDIR)/fzf
|
||||||
|
|
||||||
uninstall:
|
uninstall:
|
||||||
rm -f $(BINDIR)/fzf $(BINDIR)/$(BINARY64)
|
rm -f $(BINDIR)/fzf $(BINDIR)/$(BINARY)
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
cd fzf && rm -f fzf-*
|
cd fzf && rm -f fzf-*
|
||||||
|
|
||||||
fzf/$(BINARY32): $(SOURCES)
|
fzf/$(BINARY32): deps
|
||||||
cd fzf && GOARCH=386 CGO_ENABLED=1 go build -a -o $(BINARY32)
|
cd fzf && GOARCH=386 CGO_ENABLED=1 go build -a -ldflags -w -tags "$(TAGS)" -o $(BINARY32)
|
||||||
|
|
||||||
fzf/$(BINARY64): $(SOURCES)
|
fzf/$(BINARY64): deps
|
||||||
cd fzf && go build -a -tags "$(TAGS)" -o $(BINARY64)
|
cd fzf && go build -a -ldflags -w -tags "$(TAGS)" -o $(BINARY64)
|
||||||
|
|
||||||
$(BINDIR)/fzf: fzf/$(BINARY64) | $(BINDIR)
|
$(BINDIR)/fzf: fzf/$(BINARY) | $(BINDIR)
|
||||||
cp -f fzf/$(BINARY64) $(BINDIR)
|
cp -f fzf/$(BINARY) $(BINDIR)
|
||||||
cd $(BINDIR) && ln -sf $(BINARY64) fzf
|
cd $(BINDIR) && ln -sf $(BINARY) fzf
|
||||||
|
|
||||||
$(BINDIR):
|
$(BINDIR):
|
||||||
mkdir -p $@
|
mkdir -p $@
|
||||||
@@ -65,21 +84,33 @@ docker-ubuntu:
|
|||||||
docker-centos:
|
docker-centos:
|
||||||
docker build -t junegunn/centos-sandbox - < Dockerfile.centos
|
docker build -t junegunn/centos-sandbox - < Dockerfile.centos
|
||||||
|
|
||||||
|
docker-android:
|
||||||
|
docker build -t junegunn/android-sandbox - < Dockerfile.android
|
||||||
|
|
||||||
arch: docker-arch
|
arch: docker-arch
|
||||||
docker run -i -t -v $(GOPATH):/go junegunn/$@-sandbox \
|
docker run $(DOCKEROPTS) junegunn/$@-sandbox \
|
||||||
sh -c 'cd /go/src/github.com/junegunn/fzf/src; /bin/bash'
|
sh -c 'cd /fzf/src; /bin/bash'
|
||||||
|
|
||||||
ubuntu: docker-ubuntu
|
ubuntu: docker-ubuntu
|
||||||
docker run -i -t -v $(GOPATH):/go junegunn/$@-sandbox \
|
docker run $(DOCKEROPTS) junegunn/$@-sandbox \
|
||||||
sh -c 'cd /go/src/github.com/junegunn/fzf/src; /bin/bash'
|
sh -c 'cd /fzf/src; /bin/bash'
|
||||||
|
|
||||||
centos: docker-centos
|
centos: docker-centos
|
||||||
docker run -i -t -v $(GOPATH):/go junegunn/$@-sandbox \
|
docker run $(DOCKEROPTS) junegunn/$@-sandbox \
|
||||||
sh -c 'cd /go/src/github.com/junegunn/fzf/src; /bin/bash'
|
sh -c 'cd /fzf/src; /bin/bash'
|
||||||
|
|
||||||
linux: docker-centos
|
linux: docker-centos
|
||||||
docker run -i -t -v $(GOPATH):/go junegunn/centos-sandbox \
|
docker run $(DOCKEROPTS) junegunn/centos-sandbox \
|
||||||
/bin/bash -ci 'cd /go/src/github.com/junegunn/fzf/src; make TAGS=static'
|
/bin/bash -ci 'cd /fzf/src; make TAGS=static release'
|
||||||
|
|
||||||
.PHONY: all build release test install uninstall clean docker \
|
ubuntu-android: docker-android
|
||||||
linux arch ubuntu centos docker-arch docker-ubuntu docker-centos
|
docker run $(DOCKEROPTS) junegunn/android-sandbox \
|
||||||
|
sh -c 'cd /fzf/src; /bin/bash'
|
||||||
|
|
||||||
|
android: docker-android
|
||||||
|
docker run $(DOCKEROPTS) junegunn/android-sandbox \
|
||||||
|
/bin/bash -ci 'cd /fzf/src; GOOS=android make android-build'
|
||||||
|
|
||||||
|
.PHONY: all deps release test install uninstall clean \
|
||||||
|
linux arch ubuntu centos docker-arch docker-ubuntu docker-centos \
|
||||||
|
android-build docker-android ubuntu-android android
|
||||||
|
@@ -79,7 +79,7 @@ Build
|
|||||||
|
|
||||||
```sh
|
```sh
|
||||||
# Build fzf executables and tarballs
|
# Build fzf executables and tarballs
|
||||||
make
|
make release
|
||||||
|
|
||||||
# Install the executable to ../bin directory
|
# Install the executable to ../bin directory
|
||||||
make install
|
make install
|
||||||
|
150
src/algo/algo.go
150
src/algo/algo.go
@@ -22,10 +22,94 @@ func runeAt(runes []rune, index int, max int, forward bool) rune {
|
|||||||
return runes[max-index-1]
|
return runes[max-index-1]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Result conatins the results of running a match function.
|
||||||
|
type Result struct {
|
||||||
|
Start int32
|
||||||
|
End int32
|
||||||
|
|
||||||
|
// Items are basically sorted by the lengths of matched substrings.
|
||||||
|
// But we slightly adjust the score with bonus for better results.
|
||||||
|
Bonus int32
|
||||||
|
}
|
||||||
|
|
||||||
|
type charClass int
|
||||||
|
|
||||||
|
const (
|
||||||
|
charNonWord charClass = iota
|
||||||
|
charLower
|
||||||
|
charUpper
|
||||||
|
charLetter
|
||||||
|
charNumber
|
||||||
|
)
|
||||||
|
|
||||||
|
func evaluateBonus(caseSensitive bool, runes []rune, pattern []rune, sidx int, eidx int) int32 {
|
||||||
|
var bonus int32
|
||||||
|
pidx := 0
|
||||||
|
lenPattern := len(pattern)
|
||||||
|
consecutive := false
|
||||||
|
prevClass := charNonWord
|
||||||
|
for index := 0; index < eidx; index++ {
|
||||||
|
char := runes[index]
|
||||||
|
var class charClass
|
||||||
|
if unicode.IsLower(char) {
|
||||||
|
class = charLower
|
||||||
|
} else if unicode.IsUpper(char) {
|
||||||
|
class = charUpper
|
||||||
|
} else if unicode.IsLetter(char) {
|
||||||
|
class = charLetter
|
||||||
|
} else if unicode.IsNumber(char) {
|
||||||
|
class = charNumber
|
||||||
|
} else {
|
||||||
|
class = charNonWord
|
||||||
|
}
|
||||||
|
|
||||||
|
var point int32
|
||||||
|
if prevClass == charNonWord && class != charNonWord {
|
||||||
|
// Word boundary
|
||||||
|
point = 2
|
||||||
|
} else if prevClass == charLower && class == charUpper ||
|
||||||
|
prevClass != charNumber && class == charNumber {
|
||||||
|
// camelCase letter123
|
||||||
|
point = 1
|
||||||
|
}
|
||||||
|
prevClass = class
|
||||||
|
|
||||||
|
if index >= sidx {
|
||||||
|
if !caseSensitive {
|
||||||
|
if char >= 'A' && char <= 'Z' {
|
||||||
|
char += 32
|
||||||
|
} else if char > unicode.MaxASCII {
|
||||||
|
char = unicode.To(unicode.LowerCase, char)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pchar := pattern[pidx]
|
||||||
|
if pchar == char {
|
||||||
|
// Boost bonus for the first character in the pattern
|
||||||
|
if pidx == 0 {
|
||||||
|
point *= 2
|
||||||
|
}
|
||||||
|
// Bonus to consecutive matching chars
|
||||||
|
if consecutive {
|
||||||
|
point++
|
||||||
|
}
|
||||||
|
bonus += point
|
||||||
|
|
||||||
|
if pidx++; pidx == lenPattern {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
consecutive = true
|
||||||
|
} else {
|
||||||
|
consecutive = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return bonus
|
||||||
|
}
|
||||||
|
|
||||||
// FuzzyMatch performs fuzzy-match
|
// FuzzyMatch performs fuzzy-match
|
||||||
func FuzzyMatch(caseSensitive bool, forward bool, runes []rune, pattern []rune) (int, int) {
|
func FuzzyMatch(caseSensitive bool, forward bool, runes []rune, pattern []rune) Result {
|
||||||
if len(pattern) == 0 {
|
if len(pattern) == 0 {
|
||||||
return 0, 0
|
return Result{0, 0, 0}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 0. (FIXME) How to find the shortest match?
|
// 0. (FIXME) How to find the shortest match?
|
||||||
@@ -90,12 +174,17 @@ func FuzzyMatch(caseSensitive bool, forward bool, runes []rune, pattern []rune)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if forward {
|
|
||||||
return sidx, eidx
|
// Calculate the bonus. This can't be done at the same time as the
|
||||||
|
// pattern scan above because 'forward' may be false.
|
||||||
|
if !forward {
|
||||||
|
sidx, eidx = lenRunes-eidx, lenRunes-sidx
|
||||||
}
|
}
|
||||||
return lenRunes - eidx, lenRunes - sidx
|
|
||||||
|
return Result{int32(sidx), int32(eidx),
|
||||||
|
evaluateBonus(caseSensitive, runes, pattern, sidx, eidx)}
|
||||||
}
|
}
|
||||||
return -1, -1
|
return Result{-1, -1, 0}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ExactMatchNaive is a basic string searching algorithm that handles case
|
// ExactMatchNaive is a basic string searching algorithm that handles case
|
||||||
@@ -105,16 +194,16 @@ func FuzzyMatch(caseSensitive bool, forward bool, runes []rune, pattern []rune)
|
|||||||
//
|
//
|
||||||
// We might try to implement better algorithms in the future:
|
// We might try to implement better algorithms in the future:
|
||||||
// http://en.wikipedia.org/wiki/String_searching_algorithm
|
// http://en.wikipedia.org/wiki/String_searching_algorithm
|
||||||
func ExactMatchNaive(caseSensitive bool, forward bool, runes []rune, pattern []rune) (int, int) {
|
func ExactMatchNaive(caseSensitive bool, forward bool, runes []rune, pattern []rune) Result {
|
||||||
if len(pattern) == 0 {
|
if len(pattern) == 0 {
|
||||||
return 0, 0
|
return Result{0, 0, 0}
|
||||||
}
|
}
|
||||||
|
|
||||||
lenRunes := len(runes)
|
lenRunes := len(runes)
|
||||||
lenPattern := len(pattern)
|
lenPattern := len(pattern)
|
||||||
|
|
||||||
if lenRunes < lenPattern {
|
if lenRunes < lenPattern {
|
||||||
return -1, -1
|
return Result{-1, -1, 0}
|
||||||
}
|
}
|
||||||
|
|
||||||
pidx := 0
|
pidx := 0
|
||||||
@@ -131,23 +220,29 @@ func ExactMatchNaive(caseSensitive bool, forward bool, runes []rune, pattern []r
|
|||||||
if pchar == char {
|
if pchar == char {
|
||||||
pidx++
|
pidx++
|
||||||
if pidx == lenPattern {
|
if pidx == lenPattern {
|
||||||
|
var sidx, eidx int
|
||||||
if forward {
|
if forward {
|
||||||
return index - lenPattern + 1, index + 1
|
sidx = index - lenPattern + 1
|
||||||
|
eidx = index + 1
|
||||||
|
} else {
|
||||||
|
sidx = lenRunes - (index + 1)
|
||||||
|
eidx = lenRunes - (index - lenPattern + 1)
|
||||||
}
|
}
|
||||||
return lenRunes - (index + 1), lenRunes - (index - lenPattern + 1)
|
return Result{int32(sidx), int32(eidx),
|
||||||
|
evaluateBonus(caseSensitive, runes, pattern, sidx, eidx)}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
index -= pidx
|
index -= pidx
|
||||||
pidx = 0
|
pidx = 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return -1, -1
|
return Result{-1, -1, 0}
|
||||||
}
|
}
|
||||||
|
|
||||||
// PrefixMatch performs prefix-match
|
// PrefixMatch performs prefix-match
|
||||||
func PrefixMatch(caseSensitive bool, forward bool, runes []rune, pattern []rune) (int, int) {
|
func PrefixMatch(caseSensitive bool, forward bool, runes []rune, pattern []rune) Result {
|
||||||
if len(runes) < len(pattern) {
|
if len(runes) < len(pattern) {
|
||||||
return -1, -1
|
return Result{-1, -1, 0}
|
||||||
}
|
}
|
||||||
|
|
||||||
for index, r := range pattern {
|
for index, r := range pattern {
|
||||||
@@ -156,19 +251,21 @@ func PrefixMatch(caseSensitive bool, forward bool, runes []rune, pattern []rune)
|
|||||||
char = unicode.ToLower(char)
|
char = unicode.ToLower(char)
|
||||||
}
|
}
|
||||||
if char != r {
|
if char != r {
|
||||||
return -1, -1
|
return Result{-1, -1, 0}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0, len(pattern)
|
lenPattern := len(pattern)
|
||||||
|
return Result{0, int32(lenPattern),
|
||||||
|
evaluateBonus(caseSensitive, runes, pattern, 0, lenPattern)}
|
||||||
}
|
}
|
||||||
|
|
||||||
// SuffixMatch performs suffix-match
|
// SuffixMatch performs suffix-match
|
||||||
func SuffixMatch(caseSensitive bool, forward bool, input []rune, pattern []rune) (int, int) {
|
func SuffixMatch(caseSensitive bool, forward bool, input []rune, pattern []rune) Result {
|
||||||
runes := util.TrimRight(input)
|
runes := util.TrimRight(input)
|
||||||
trimmedLen := len(runes)
|
trimmedLen := len(runes)
|
||||||
diff := trimmedLen - len(pattern)
|
diff := trimmedLen - len(pattern)
|
||||||
if diff < 0 {
|
if diff < 0 {
|
||||||
return -1, -1
|
return Result{-1, -1, 0}
|
||||||
}
|
}
|
||||||
|
|
||||||
for index, r := range pattern {
|
for index, r := range pattern {
|
||||||
@@ -177,23 +274,28 @@ func SuffixMatch(caseSensitive bool, forward bool, input []rune, pattern []rune)
|
|||||||
char = unicode.ToLower(char)
|
char = unicode.ToLower(char)
|
||||||
}
|
}
|
||||||
if char != r {
|
if char != r {
|
||||||
return -1, -1
|
return Result{-1, -1, 0}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return trimmedLen - len(pattern), trimmedLen
|
lenPattern := len(pattern)
|
||||||
|
sidx := trimmedLen - lenPattern
|
||||||
|
eidx := trimmedLen
|
||||||
|
return Result{int32(sidx), int32(eidx),
|
||||||
|
evaluateBonus(caseSensitive, runes, pattern, sidx, eidx)}
|
||||||
}
|
}
|
||||||
|
|
||||||
// EqualMatch performs equal-match
|
// EqualMatch performs equal-match
|
||||||
func EqualMatch(caseSensitive bool, forward bool, runes []rune, pattern []rune) (int, int) {
|
func EqualMatch(caseSensitive bool, forward bool, runes []rune, pattern []rune) Result {
|
||||||
|
// Note: EqualMatch always return a zero bonus.
|
||||||
if len(runes) != len(pattern) {
|
if len(runes) != len(pattern) {
|
||||||
return -1, -1
|
return Result{-1, -1, 0}
|
||||||
}
|
}
|
||||||
runesStr := string(runes)
|
runesStr := string(runes)
|
||||||
if !caseSensitive {
|
if !caseSensitive {
|
||||||
runesStr = strings.ToLower(runesStr)
|
runesStr = strings.ToLower(runesStr)
|
||||||
}
|
}
|
||||||
if runesStr == string(pattern) {
|
if runesStr == string(pattern) {
|
||||||
return 0, len(pattern)
|
return Result{0, int32(len(pattern)), 0}
|
||||||
}
|
}
|
||||||
return -1, -1
|
return Result{-1, -1, 0}
|
||||||
}
|
}
|
||||||
|
@@ -5,65 +5,91 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func assertMatch(t *testing.T, fun func(bool, bool, []rune, []rune) (int, int), caseSensitive bool, forward bool, input string, pattern string, sidx int, eidx int) {
|
func assertMatch(t *testing.T, fun func(bool, bool, []rune, []rune) Result, caseSensitive, forward bool, input, pattern string, sidx int32, eidx int32, bonus int32) {
|
||||||
if !caseSensitive {
|
if !caseSensitive {
|
||||||
pattern = strings.ToLower(pattern)
|
pattern = strings.ToLower(pattern)
|
||||||
}
|
}
|
||||||
s, e := fun(caseSensitive, forward, []rune(input), []rune(pattern))
|
res := fun(caseSensitive, forward, []rune(input), []rune(pattern))
|
||||||
if s != sidx {
|
if res.Start != sidx {
|
||||||
t.Errorf("Invalid start index: %d (expected: %d, %s / %s)", s, sidx, input, pattern)
|
t.Errorf("Invalid start index: %d (expected: %d, %s / %s)", res.Start, sidx, input, pattern)
|
||||||
}
|
}
|
||||||
if e != eidx {
|
if res.End != eidx {
|
||||||
t.Errorf("Invalid end index: %d (expected: %d, %s / %s)", e, eidx, input, pattern)
|
t.Errorf("Invalid end index: %d (expected: %d, %s / %s)", res.End, eidx, input, pattern)
|
||||||
|
}
|
||||||
|
if res.Bonus != bonus {
|
||||||
|
t.Errorf("Invalid bonus: %d (expected: %d, %s / %s)", res.Bonus, bonus, input, pattern)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFuzzyMatch(t *testing.T) {
|
func TestFuzzyMatch(t *testing.T) {
|
||||||
assertMatch(t, FuzzyMatch, false, true, "fooBarbaz", "oBZ", 2, 9)
|
assertMatch(t, FuzzyMatch, false, true, "fooBarbaz", "oBZ", 2, 9, 2)
|
||||||
assertMatch(t, FuzzyMatch, true, true, "fooBarbaz", "oBZ", -1, -1)
|
assertMatch(t, FuzzyMatch, false, true, "foo bar baz", "fbb", 0, 9, 8)
|
||||||
assertMatch(t, FuzzyMatch, true, true, "fooBarbaz", "oBz", 2, 9)
|
assertMatch(t, FuzzyMatch, false, true, "/AutomatorDocument.icns", "rdoc", 9, 13, 4)
|
||||||
assertMatch(t, FuzzyMatch, true, true, "fooBarbaz", "fooBarbazz", -1, -1)
|
assertMatch(t, FuzzyMatch, false, true, "/man1/zshcompctl.1", "zshc", 6, 10, 7)
|
||||||
|
assertMatch(t, FuzzyMatch, false, true, "/.oh-my-zsh/cache", "zshc", 8, 13, 8)
|
||||||
|
assertMatch(t, FuzzyMatch, false, true, "ab0123 456", "12356", 3, 10, 3)
|
||||||
|
assertMatch(t, FuzzyMatch, false, true, "abc123 456", "12356", 3, 10, 5)
|
||||||
|
|
||||||
|
assertMatch(t, FuzzyMatch, false, true, "foo/bar/baz", "fbb", 0, 9, 8)
|
||||||
|
assertMatch(t, FuzzyMatch, false, true, "fooBarBaz", "fbb", 0, 7, 6)
|
||||||
|
assertMatch(t, FuzzyMatch, false, true, "foo barbaz", "fbb", 0, 8, 6)
|
||||||
|
assertMatch(t, FuzzyMatch, false, true, "fooBar Baz", "foob", 0, 4, 8)
|
||||||
|
assertMatch(t, FuzzyMatch, true, true, "fooBarbaz", "oBZ", -1, -1, 0)
|
||||||
|
assertMatch(t, FuzzyMatch, true, true, "fooBarbaz", "oBz", 2, 9, 2)
|
||||||
|
assertMatch(t, FuzzyMatch, true, true, "Foo Bar Baz", "fbb", -1, -1, 0)
|
||||||
|
assertMatch(t, FuzzyMatch, true, true, "Foo/Bar/Baz", "FBB", 0, 9, 8)
|
||||||
|
assertMatch(t, FuzzyMatch, true, true, "FooBarBaz", "FBB", 0, 7, 6)
|
||||||
|
assertMatch(t, FuzzyMatch, true, true, "foo BarBaz", "fBB", 0, 8, 7)
|
||||||
|
assertMatch(t, FuzzyMatch, true, true, "FooBar Baz", "FooB", 0, 4, 8)
|
||||||
|
assertMatch(t, FuzzyMatch, true, true, "fooBarbaz", "fooBarbazz", -1, -1, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFuzzyMatchBackward(t *testing.T) {
|
func TestFuzzyMatchBackward(t *testing.T) {
|
||||||
assertMatch(t, FuzzyMatch, false, true, "foobar fb", "fb", 0, 4)
|
assertMatch(t, FuzzyMatch, false, true, "foobar fb", "fb", 0, 4, 4)
|
||||||
assertMatch(t, FuzzyMatch, false, false, "foobar fb", "fb", 7, 9)
|
assertMatch(t, FuzzyMatch, false, false, "foobar fb", "fb", 7, 9, 5)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestExactMatchNaive(t *testing.T) {
|
func TestExactMatchNaive(t *testing.T) {
|
||||||
for _, dir := range []bool{true, false} {
|
for _, dir := range []bool{true, false} {
|
||||||
assertMatch(t, ExactMatchNaive, false, dir, "fooBarbaz", "oBA", 2, 5)
|
assertMatch(t, ExactMatchNaive, false, dir, "fooBarbaz", "oBA", 2, 5, 3)
|
||||||
assertMatch(t, ExactMatchNaive, true, dir, "fooBarbaz", "oBA", -1, -1)
|
assertMatch(t, ExactMatchNaive, true, dir, "fooBarbaz", "oBA", -1, -1, 0)
|
||||||
assertMatch(t, ExactMatchNaive, true, dir, "fooBarbaz", "fooBarbazz", -1, -1)
|
assertMatch(t, ExactMatchNaive, true, dir, "fooBarbaz", "fooBarbazz", -1, -1, 0)
|
||||||
|
|
||||||
|
assertMatch(t, ExactMatchNaive, false, dir, "/AutomatorDocument.icns", "rdoc", 9, 13, 4)
|
||||||
|
assertMatch(t, ExactMatchNaive, false, dir, "/man1/zshcompctl.1", "zshc", 6, 10, 7)
|
||||||
|
assertMatch(t, ExactMatchNaive, false, dir, "/.oh-my-zsh/cache", "zsh/c", 8, 13, 10)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestExactMatchNaiveBackward(t *testing.T) {
|
func TestExactMatchNaiveBackward(t *testing.T) {
|
||||||
assertMatch(t, FuzzyMatch, false, true, "foobar foob", "oo", 1, 3)
|
assertMatch(t, ExactMatchNaive, false, true, "foobar foob", "oo", 1, 3, 1)
|
||||||
assertMatch(t, FuzzyMatch, false, false, "foobar foob", "oo", 8, 10)
|
assertMatch(t, ExactMatchNaive, false, false, "foobar foob", "oo", 8, 10, 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPrefixMatch(t *testing.T) {
|
func TestPrefixMatch(t *testing.T) {
|
||||||
for _, dir := range []bool{true, false} {
|
for _, dir := range []bool{true, false} {
|
||||||
assertMatch(t, PrefixMatch, false, dir, "fooBarbaz", "Foo", 0, 3)
|
assertMatch(t, PrefixMatch, true, dir, "fooBarbaz", "Foo", -1, -1, 0)
|
||||||
assertMatch(t, PrefixMatch, true, dir, "fooBarbaz", "Foo", -1, -1)
|
assertMatch(t, PrefixMatch, false, dir, "fooBarBaz", "baz", -1, -1, 0)
|
||||||
assertMatch(t, PrefixMatch, false, dir, "fooBarbaz", "baz", -1, -1)
|
assertMatch(t, PrefixMatch, false, dir, "fooBarbaz", "Foo", 0, 3, 6)
|
||||||
|
assertMatch(t, PrefixMatch, false, dir, "foOBarBaZ", "foo", 0, 3, 7)
|
||||||
|
assertMatch(t, PrefixMatch, false, dir, "f-oBarbaz", "f-o", 0, 3, 8)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSuffixMatch(t *testing.T) {
|
func TestSuffixMatch(t *testing.T) {
|
||||||
for _, dir := range []bool{true, false} {
|
for _, dir := range []bool{true, false} {
|
||||||
assertMatch(t, SuffixMatch, false, dir, "fooBarbaz", "Foo", -1, -1)
|
assertMatch(t, SuffixMatch, false, dir, "fooBarbaz", "Foo", -1, -1, 0)
|
||||||
assertMatch(t, SuffixMatch, false, dir, "fooBarbaz", "baz", 6, 9)
|
assertMatch(t, SuffixMatch, false, dir, "fooBarbaz", "baz", 6, 9, 2)
|
||||||
assertMatch(t, SuffixMatch, true, dir, "fooBarbaz", "Baz", -1, -1)
|
assertMatch(t, SuffixMatch, false, dir, "fooBarBaZ", "baz", 6, 9, 5)
|
||||||
|
assertMatch(t, SuffixMatch, true, dir, "fooBarbaz", "Baz", -1, -1, 0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEmptyPattern(t *testing.T) {
|
func TestEmptyPattern(t *testing.T) {
|
||||||
for _, dir := range []bool{true, false} {
|
for _, dir := range []bool{true, false} {
|
||||||
assertMatch(t, FuzzyMatch, true, dir, "foobar", "", 0, 0)
|
assertMatch(t, FuzzyMatch, true, dir, "foobar", "", 0, 0, 0)
|
||||||
assertMatch(t, ExactMatchNaive, true, dir, "foobar", "", 0, 0)
|
assertMatch(t, ExactMatchNaive, true, dir, "foobar", "", 0, 0, 0)
|
||||||
assertMatch(t, PrefixMatch, true, dir, "foobar", "", 0, 0)
|
assertMatch(t, PrefixMatch, true, dir, "foobar", "", 0, 0, 0)
|
||||||
assertMatch(t, SuffixMatch, true, dir, "foobar", "", 6, 6)
|
assertMatch(t, SuffixMatch, true, dir, "foobar", "", 6, 6, 0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
11
src/ansi.go
11
src/ansi.go
@@ -36,7 +36,7 @@ func init() {
|
|||||||
ansiRegex = regexp.MustCompile("\x1b\\[[0-9;]*[mK]")
|
ansiRegex = regexp.MustCompile("\x1b\\[[0-9;]*[mK]")
|
||||||
}
|
}
|
||||||
|
|
||||||
func extractColor(str string, state *ansiState) (string, []ansiOffset, *ansiState) {
|
func extractColor(str string, state *ansiState, proc func(string, *ansiState) bool) (string, []ansiOffset, *ansiState) {
|
||||||
var offsets []ansiOffset
|
var offsets []ansiOffset
|
||||||
var output bytes.Buffer
|
var output bytes.Buffer
|
||||||
|
|
||||||
@@ -46,7 +46,11 @@ func extractColor(str string, state *ansiState) (string, []ansiOffset, *ansiStat
|
|||||||
|
|
||||||
idx := 0
|
idx := 0
|
||||||
for _, offset := range ansiRegex.FindAllStringIndex(str, -1) {
|
for _, offset := range ansiRegex.FindAllStringIndex(str, -1) {
|
||||||
output.WriteString(str[idx:offset[0]])
|
prev := str[idx:offset[0]]
|
||||||
|
output.WriteString(prev)
|
||||||
|
if proc != nil && !proc(prev, state) {
|
||||||
|
return "", nil, nil
|
||||||
|
}
|
||||||
newState := interpretCode(str[offset[0]:offset[1]], state)
|
newState := interpretCode(str[offset[0]:offset[1]], state)
|
||||||
|
|
||||||
if !newState.equals(state) {
|
if !newState.equals(state) {
|
||||||
@@ -77,6 +81,9 @@ func extractColor(str string, state *ansiState) (string, []ansiOffset, *ansiStat
|
|||||||
(&offsets[len(offsets)-1]).offset[1] = int32(utf8.RuneCount(output.Bytes()))
|
(&offsets[len(offsets)-1]).offset[1] = int32(utf8.RuneCount(output.Bytes()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if proc != nil {
|
||||||
|
proc(rest, state)
|
||||||
|
}
|
||||||
return output.String(), offsets, state
|
return output.String(), offsets, state
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -17,7 +17,7 @@ func TestExtractColor(t *testing.T) {
|
|||||||
var state *ansiState
|
var state *ansiState
|
||||||
clean := "\x1b[0m"
|
clean := "\x1b[0m"
|
||||||
check := func(assertion func(ansiOffsets []ansiOffset, state *ansiState)) {
|
check := func(assertion func(ansiOffsets []ansiOffset, state *ansiState)) {
|
||||||
output, ansiOffsets, newState := extractColor(src, state)
|
output, ansiOffsets, newState := extractColor(src, state, nil)
|
||||||
state = newState
|
state = newState
|
||||||
if output != "hello world" {
|
if output != "hello world" {
|
||||||
t.Errorf("Invalid output: {}", output)
|
t.Errorf("Invalid output: {}", output)
|
||||||
|
@@ -6,8 +6,11 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestChunkList(t *testing.T) {
|
func TestChunkList(t *testing.T) {
|
||||||
|
// FIXME global
|
||||||
|
sortCriteria = []criterion{byMatchLen, byLength}
|
||||||
|
|
||||||
cl := NewChunkList(func(s []byte, i int) *Item {
|
cl := NewChunkList(func(s []byte, i int) *Item {
|
||||||
return &Item{text: []rune(string(s)), rank: Rank{0, 0, uint32(i * 2)}}
|
return &Item{text: []rune(string(s)), rank: buildEmptyRank(int32(i * 2))}
|
||||||
})
|
})
|
||||||
|
|
||||||
// Snapshot
|
// Snapshot
|
||||||
@@ -36,8 +39,11 @@ func TestChunkList(t *testing.T) {
|
|||||||
if len(*chunk1) != 2 {
|
if len(*chunk1) != 2 {
|
||||||
t.Error("Snapshot should contain only two items")
|
t.Error("Snapshot should contain only two items")
|
||||||
}
|
}
|
||||||
if string((*chunk1)[0].text) != "hello" || (*chunk1)[0].rank.index != 0 ||
|
last := func(arr [5]int32) int32 {
|
||||||
string((*chunk1)[1].text) != "world" || (*chunk1)[1].rank.index != 2 {
|
return arr[len(arr)-1]
|
||||||
|
}
|
||||||
|
if string((*chunk1)[0].text) != "hello" || last((*chunk1)[0].rank) != 0 ||
|
||||||
|
string((*chunk1)[1].text) != "world" || last((*chunk1)[1].rank) != 2 {
|
||||||
t.Error("Invalid data")
|
t.Error("Invalid data")
|
||||||
}
|
}
|
||||||
if chunk1.IsFull() {
|
if chunk1.IsFull() {
|
||||||
|
@@ -8,7 +8,7 @@ import (
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
// Current version
|
// Current version
|
||||||
version = "0.10.8"
|
version = "0.13.3"
|
||||||
|
|
||||||
// Core
|
// Core
|
||||||
coordinatorDelayMax time.Duration = 100 * time.Millisecond
|
coordinatorDelayMax time.Duration = 100 * time.Millisecond
|
||||||
@@ -18,7 +18,8 @@ const (
|
|||||||
defaultCommand = `find . -path '*/\.*' -prune -o -type f -print -o -type l -print 2> /dev/null | sed s/^..//`
|
defaultCommand = `find . -path '*/\.*' -prune -o -type f -print -o -type l -print 2> /dev/null | sed s/^..//`
|
||||||
|
|
||||||
// Terminal
|
// Terminal
|
||||||
initialDelay = 100 * time.Millisecond
|
initialDelay = 20 * time.Millisecond
|
||||||
|
initialDelayTac = 100 * time.Millisecond
|
||||||
spinnerDuration = 200 * time.Millisecond
|
spinnerDuration = 200 * time.Millisecond
|
||||||
|
|
||||||
// Matcher
|
// Matcher
|
||||||
@@ -35,6 +36,9 @@ const (
|
|||||||
|
|
||||||
// History
|
// History
|
||||||
defaultHistoryMax int = 1000
|
defaultHistoryMax int = 1000
|
||||||
|
|
||||||
|
// Jump labels
|
||||||
|
defaultJumpLabels string = "asdfghjklqwertyuiopzxcvbnm1234567890ASDFGHJKLQWERTYUIOPZXCVBNM`~;:,<.>/?'\"!@#$%^&*()[{]}-_=+"
|
||||||
)
|
)
|
||||||
|
|
||||||
// fzf events
|
// fzf events
|
||||||
|
26
src/core.go
26
src/core.go
@@ -3,7 +3,7 @@ Package fzf implements fzf, a command-line fuzzy finder.
|
|||||||
|
|
||||||
The MIT License (MIT)
|
The MIT License (MIT)
|
||||||
|
|
||||||
Copyright (c) 2015 Junegunn Choi
|
Copyright (c) 2016 Junegunn Choi
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
@@ -52,7 +52,7 @@ func Run(opts *Options) {
|
|||||||
initProcs()
|
initProcs()
|
||||||
|
|
||||||
sort := opts.Sort > 0
|
sort := opts.Sort > 0
|
||||||
rankTiebreak = opts.Tiebreak
|
sortCriteria = opts.Criteria
|
||||||
|
|
||||||
if opts.Version {
|
if opts.Version {
|
||||||
fmt.Println(version)
|
fmt.Println(version)
|
||||||
@@ -73,7 +73,7 @@ func Run(opts *Options) {
|
|||||||
if opts.Theme != nil {
|
if opts.Theme != nil {
|
||||||
var state *ansiState
|
var state *ansiState
|
||||||
ansiProcessor = func(data []byte) ([]rune, []ansiOffset) {
|
ansiProcessor = func(data []byte) ([]rune, []ansiOffset) {
|
||||||
trimmed, offsets, newState := extractColor(string(data), state)
|
trimmed, offsets, newState := extractColor(string(data), state, nil)
|
||||||
state = newState
|
state = newState
|
||||||
return []rune(trimmed), offsets
|
return []rune(trimmed), offsets
|
||||||
}
|
}
|
||||||
@@ -81,7 +81,7 @@ func Run(opts *Options) {
|
|||||||
// When color is disabled but ansi option is given,
|
// When color is disabled but ansi option is given,
|
||||||
// we simply strip out ANSI codes from the input
|
// we simply strip out ANSI codes from the input
|
||||||
ansiProcessor = func(data []byte) ([]rune, []ansiOffset) {
|
ansiProcessor = func(data []byte) ([]rune, []ansiOffset) {
|
||||||
trimmed, _, _ := extractColor(string(data), nil)
|
trimmed, _, _ := extractColor(string(data), nil, nil)
|
||||||
return []rune(trimmed), nil
|
return []rune(trimmed), nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -103,9 +103,8 @@ func Run(opts *Options) {
|
|||||||
runes, colors := ansiProcessor(data)
|
runes, colors := ansiProcessor(data)
|
||||||
return &Item{
|
return &Item{
|
||||||
text: runes,
|
text: runes,
|
||||||
index: uint32(index),
|
|
||||||
colors: colors,
|
colors: colors,
|
||||||
rank: Rank{0, 0, uint32(index)}}
|
rank: buildEmptyRank(int32(index))}
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
chunkList = NewChunkList(func(data []byte, index int) *Item {
|
chunkList = NewChunkList(func(data []byte, index int) *Item {
|
||||||
@@ -120,9 +119,8 @@ func Run(opts *Options) {
|
|||||||
item := Item{
|
item := Item{
|
||||||
text: joinTokens(trans),
|
text: joinTokens(trans),
|
||||||
origText: &runes,
|
origText: &runes,
|
||||||
index: uint32(index),
|
|
||||||
colors: nil,
|
colors: nil,
|
||||||
rank: Rank{0, 0, uint32(index)}}
|
rank: buildEmptyRank(int32(index))}
|
||||||
|
|
||||||
trimmed, colors := ansiProcessorRunes(item.text)
|
trimmed, colors := ansiProcessorRunes(item.text)
|
||||||
item.text = trimmed
|
item.text = trimmed
|
||||||
@@ -141,9 +139,19 @@ func Run(opts *Options) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Matcher
|
// Matcher
|
||||||
|
forward := true
|
||||||
|
for _, cri := range opts.Criteria[1:] {
|
||||||
|
if cri == byEnd {
|
||||||
|
forward = false
|
||||||
|
break
|
||||||
|
}
|
||||||
|
if cri == byBegin {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
patternBuilder := func(runes []rune) *Pattern {
|
patternBuilder := func(runes []rune) *Pattern {
|
||||||
return BuildPattern(
|
return BuildPattern(
|
||||||
opts.Mode, opts.Case, opts.Tiebreak != byEnd,
|
opts.Fuzzy, opts.Extended, opts.Case, forward,
|
||||||
opts.Nth, opts.Delimiter, runes)
|
opts.Nth, opts.Delimiter, runes)
|
||||||
}
|
}
|
||||||
matcher := NewMatcher(patternBuilder, sort, opts.Tac, eventBox)
|
matcher := NewMatcher(patternBuilder, sort, opts.Tac, eventBox)
|
||||||
|
@@ -4,13 +4,20 @@ package curses
|
|||||||
#include <ncurses.h>
|
#include <ncurses.h>
|
||||||
#include <locale.h>
|
#include <locale.h>
|
||||||
#cgo !static LDFLAGS: -lncurses
|
#cgo !static LDFLAGS: -lncurses
|
||||||
#cgo static LDFLAGS: -l:libncurses.a -l:libtinfo.a -l:libgpm.a -ldl
|
#cgo static LDFLAGS: -l:libncursesw.a -l:libtinfo.a -l:libgpm.a -ldl
|
||||||
|
#cgo android static LDFLAGS: -l:libncurses.a -fPIE -march=armv7-a -mfpu=neon -mhard-float -Wl,--no-warn-mismatch
|
||||||
|
|
||||||
|
SCREEN *c_newterm () {
|
||||||
|
return newterm(NULL, stderr, stdin);
|
||||||
|
}
|
||||||
|
|
||||||
*/
|
*/
|
||||||
import "C"
|
import "C"
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
"unicode/utf8"
|
"unicode/utf8"
|
||||||
@@ -50,6 +57,7 @@ const (
|
|||||||
|
|
||||||
Invalid
|
Invalid
|
||||||
Mouse
|
Mouse
|
||||||
|
DoubleClick
|
||||||
|
|
||||||
BTab
|
BTab
|
||||||
BSpace
|
BSpace
|
||||||
@@ -72,7 +80,16 @@ const (
|
|||||||
F2
|
F2
|
||||||
F3
|
F3
|
||||||
F4
|
F4
|
||||||
|
F5
|
||||||
|
F6
|
||||||
|
F7
|
||||||
|
F8
|
||||||
|
F9
|
||||||
|
F10
|
||||||
|
|
||||||
|
AltEnter
|
||||||
|
AltSpace
|
||||||
|
AltSlash
|
||||||
AltBS
|
AltBS
|
||||||
AltA
|
AltA
|
||||||
AltB
|
AltB
|
||||||
@@ -96,11 +113,14 @@ const (
|
|||||||
ColCursor
|
ColCursor
|
||||||
ColSelected
|
ColSelected
|
||||||
ColHeader
|
ColHeader
|
||||||
ColUser
|
ColBorder
|
||||||
|
ColUser // Should be the last entry
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
doubleClickDuration = 500 * time.Millisecond
|
doubleClickDuration = 500 * time.Millisecond
|
||||||
|
colDefault = -1
|
||||||
|
colUndefined = -2
|
||||||
)
|
)
|
||||||
|
|
||||||
type ColorTheme struct {
|
type ColorTheme struct {
|
||||||
@@ -117,6 +137,7 @@ type ColorTheme struct {
|
|||||||
Cursor int16
|
Cursor int16
|
||||||
Selected int16
|
Selected int16
|
||||||
Header int16
|
Header int16
|
||||||
|
Border int16
|
||||||
}
|
}
|
||||||
|
|
||||||
type Event struct {
|
type Event struct {
|
||||||
@@ -151,6 +172,49 @@ var (
|
|||||||
DarkBG int
|
DarkBG int
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type Window struct {
|
||||||
|
win *C.WINDOW
|
||||||
|
Top int
|
||||||
|
Left int
|
||||||
|
Width int
|
||||||
|
Height int
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewWindow(top int, left int, width int, height int, border bool) *Window {
|
||||||
|
win := C.newwin(C.int(height), C.int(width), C.int(top), C.int(left))
|
||||||
|
if border {
|
||||||
|
attr := _color(ColBorder, false)
|
||||||
|
C.wattron(win, attr)
|
||||||
|
C.box(win, 0, 0)
|
||||||
|
C.wattroff(win, attr)
|
||||||
|
}
|
||||||
|
return &Window{
|
||||||
|
win: win,
|
||||||
|
Top: top,
|
||||||
|
Left: left,
|
||||||
|
Width: width,
|
||||||
|
Height: height,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func EmptyTheme() *ColorTheme {
|
||||||
|
return &ColorTheme{
|
||||||
|
UseDefault: true,
|
||||||
|
Fg: colUndefined,
|
||||||
|
Bg: colUndefined,
|
||||||
|
DarkBg: colUndefined,
|
||||||
|
Prompt: colUndefined,
|
||||||
|
Match: colUndefined,
|
||||||
|
Current: colUndefined,
|
||||||
|
CurrentMatch: colUndefined,
|
||||||
|
Spinner: colUndefined,
|
||||||
|
Info: colUndefined,
|
||||||
|
Cursor: colUndefined,
|
||||||
|
Selected: colUndefined,
|
||||||
|
Header: colUndefined,
|
||||||
|
Border: colUndefined}
|
||||||
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
_prevDownTime = time.Unix(0, 0)
|
_prevDownTime = time.Unix(0, 0)
|
||||||
_clickY = []int{}
|
_clickY = []int{}
|
||||||
@@ -168,7 +232,8 @@ func init() {
|
|||||||
Info: C.COLOR_WHITE,
|
Info: C.COLOR_WHITE,
|
||||||
Cursor: C.COLOR_RED,
|
Cursor: C.COLOR_RED,
|
||||||
Selected: C.COLOR_MAGENTA,
|
Selected: C.COLOR_MAGENTA,
|
||||||
Header: C.COLOR_CYAN}
|
Header: C.COLOR_CYAN,
|
||||||
|
Border: C.COLOR_BLACK}
|
||||||
Dark256 = &ColorTheme{
|
Dark256 = &ColorTheme{
|
||||||
UseDefault: true,
|
UseDefault: true,
|
||||||
Fg: 15,
|
Fg: 15,
|
||||||
@@ -182,7 +247,8 @@ func init() {
|
|||||||
Info: 144,
|
Info: 144,
|
||||||
Cursor: 161,
|
Cursor: 161,
|
||||||
Selected: 168,
|
Selected: 168,
|
||||||
Header: 109}
|
Header: 109,
|
||||||
|
Border: 59}
|
||||||
Light256 = &ColorTheme{
|
Light256 = &ColorTheme{
|
||||||
UseDefault: true,
|
UseDefault: true,
|
||||||
Fg: 15,
|
Fg: 15,
|
||||||
@@ -196,7 +262,8 @@ func init() {
|
|||||||
Info: 101,
|
Info: 101,
|
||||||
Cursor: 161,
|
Cursor: 161,
|
||||||
Selected: 168,
|
Selected: 168,
|
||||||
Header: 31}
|
Header: 31,
|
||||||
|
Border: 145}
|
||||||
}
|
}
|
||||||
|
|
||||||
func attrColored(pair int, bold bool) C.int {
|
func attrColored(pair int, bold bool) C.int {
|
||||||
@@ -258,7 +325,7 @@ func Init(theme *ColorTheme, black bool, mouse bool) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
C.setlocale(C.LC_ALL, C.CString(""))
|
C.setlocale(C.LC_ALL, C.CString(""))
|
||||||
_screen = C.newterm(nil, C.stderr, C.stdin)
|
_screen = C.c_newterm()
|
||||||
if _screen == nil {
|
if _screen == nil {
|
||||||
fmt.Println("Invalid $TERM: " + os.Getenv("TERM"))
|
fmt.Println("Invalid $TERM: " + os.Getenv("TERM"))
|
||||||
os.Exit(2)
|
os.Exit(2)
|
||||||
@@ -272,44 +339,59 @@ func Init(theme *ColorTheme, black bool, mouse bool) {
|
|||||||
|
|
||||||
if theme != nil {
|
if theme != nil {
|
||||||
C.start_color()
|
C.start_color()
|
||||||
initPairs(theme, black)
|
var baseTheme *ColorTheme
|
||||||
|
if C.tigetnum(C.CString("colors")) >= 256 {
|
||||||
|
baseTheme = Dark256
|
||||||
|
} else {
|
||||||
|
baseTheme = Default16
|
||||||
|
}
|
||||||
|
initPairs(baseTheme, theme, black)
|
||||||
_color = attrColored
|
_color = attrColored
|
||||||
} else {
|
} else {
|
||||||
_color = attrMono
|
_color = attrMono
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func initPairs(theme *ColorTheme, black bool) {
|
func override(a int16, b int16) C.short {
|
||||||
fg := C.short(theme.Fg)
|
if b == colUndefined {
|
||||||
bg := C.short(theme.Bg)
|
return C.short(a)
|
||||||
|
}
|
||||||
|
return C.short(b)
|
||||||
|
}
|
||||||
|
|
||||||
|
func initPairs(baseTheme *ColorTheme, theme *ColorTheme, black bool) {
|
||||||
|
fg := override(baseTheme.Fg, theme.Fg)
|
||||||
|
bg := override(baseTheme.Bg, theme.Bg)
|
||||||
if black {
|
if black {
|
||||||
bg = C.COLOR_BLACK
|
bg = C.COLOR_BLACK
|
||||||
} else if theme.UseDefault {
|
} else if theme.UseDefault {
|
||||||
fg = -1
|
fg = colDefault
|
||||||
bg = -1
|
bg = colDefault
|
||||||
C.use_default_colors()
|
C.use_default_colors()
|
||||||
}
|
}
|
||||||
if theme.UseDefault {
|
if theme.UseDefault {
|
||||||
FG = -1
|
FG = colDefault
|
||||||
BG = -1
|
BG = colDefault
|
||||||
} else {
|
} else {
|
||||||
FG = int(fg)
|
FG = int(fg)
|
||||||
BG = int(bg)
|
BG = int(bg)
|
||||||
C.assume_default_colors(C.int(theme.Fg), C.int(bg))
|
C.assume_default_colors(C.int(override(baseTheme.Fg, theme.Fg)), C.int(bg))
|
||||||
}
|
}
|
||||||
|
|
||||||
CurrentFG = int(theme.Current)
|
currentFG := override(baseTheme.Current, theme.Current)
|
||||||
DarkBG = int(theme.DarkBg)
|
darkBG := override(baseTheme.DarkBg, theme.DarkBg)
|
||||||
darkBG := C.short(DarkBG)
|
CurrentFG = int(currentFG)
|
||||||
C.init_pair(ColPrompt, C.short(theme.Prompt), bg)
|
DarkBG = int(darkBG)
|
||||||
C.init_pair(ColMatch, C.short(theme.Match), bg)
|
C.init_pair(ColPrompt, override(baseTheme.Prompt, theme.Prompt), bg)
|
||||||
C.init_pair(ColCurrent, C.short(theme.Current), darkBG)
|
C.init_pair(ColMatch, override(baseTheme.Match, theme.Match), bg)
|
||||||
C.init_pair(ColCurrentMatch, C.short(theme.CurrentMatch), darkBG)
|
C.init_pair(ColCurrent, currentFG, darkBG)
|
||||||
C.init_pair(ColSpinner, C.short(theme.Spinner), bg)
|
C.init_pair(ColCurrentMatch, override(baseTheme.CurrentMatch, theme.CurrentMatch), darkBG)
|
||||||
C.init_pair(ColInfo, C.short(theme.Info), bg)
|
C.init_pair(ColSpinner, override(baseTheme.Spinner, theme.Spinner), bg)
|
||||||
C.init_pair(ColCursor, C.short(theme.Cursor), darkBG)
|
C.init_pair(ColInfo, override(baseTheme.Info, theme.Info), bg)
|
||||||
C.init_pair(ColSelected, C.short(theme.Selected), darkBG)
|
C.init_pair(ColCursor, override(baseTheme.Cursor, theme.Cursor), darkBG)
|
||||||
C.init_pair(ColHeader, C.short(theme.Header), bg)
|
C.init_pair(ColSelected, override(baseTheme.Selected, theme.Selected), darkBG)
|
||||||
|
C.init_pair(ColHeader, override(baseTheme.Header, theme.Header), bg)
|
||||||
|
C.init_pair(ColBorder, override(baseTheme.Border, theme.Border), bg)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Close() {
|
func Close() {
|
||||||
@@ -365,7 +447,9 @@ func mouseSequence(sz *int) Event {
|
|||||||
97, 101, 105, 113: // scroll-down / shift / cmd / ctrl
|
97, 101, 105, 113: // scroll-down / shift / cmd / ctrl
|
||||||
mod := _buf[3] >= 100
|
mod := _buf[3] >= 100
|
||||||
s := 1 - int(_buf[3]%2)*2
|
s := 1 - int(_buf[3]%2)*2
|
||||||
return Event{Mouse, 0, &MouseEvent{0, 0, s, false, false, mod}}
|
x := int(_buf[4] - 33)
|
||||||
|
y := int(_buf[5] - 33)
|
||||||
|
return Event{Mouse, 0, &MouseEvent{y, x, s, false, false, mod}}
|
||||||
}
|
}
|
||||||
return Event{Invalid, 0, nil}
|
return Event{Invalid, 0, nil}
|
||||||
}
|
}
|
||||||
@@ -376,6 +460,12 @@ func escSequence(sz *int) Event {
|
|||||||
}
|
}
|
||||||
*sz = 2
|
*sz = 2
|
||||||
switch _buf[1] {
|
switch _buf[1] {
|
||||||
|
case 13:
|
||||||
|
return Event{AltEnter, 0, nil}
|
||||||
|
case 32:
|
||||||
|
return Event{AltSpace, 0, nil}
|
||||||
|
case 47:
|
||||||
|
return Event{AltSlash, 0, nil}
|
||||||
case 98:
|
case 98:
|
||||||
return Event{AltB, 0, nil}
|
return Event{AltB, 0, nil}
|
||||||
case 100:
|
case 100:
|
||||||
@@ -421,6 +511,20 @@ func escSequence(sz *int) Event {
|
|||||||
*sz = 4
|
*sz = 4
|
||||||
switch _buf[2] {
|
switch _buf[2] {
|
||||||
case 50:
|
case 50:
|
||||||
|
if len(_buf) == 5 && _buf[4] == 126 {
|
||||||
|
*sz = 5
|
||||||
|
switch _buf[3] {
|
||||||
|
case 48:
|
||||||
|
return Event{F9, 0, nil}
|
||||||
|
case 49:
|
||||||
|
return Event{F10, 0, nil}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Bracketed paste mode \e[200~ / \e[201
|
||||||
|
if _buf[3] == 48 && (_buf[4] == 48 || _buf[4] == 49) && _buf[5] == 126 {
|
||||||
|
*sz = 6
|
||||||
|
return Event{Invalid, 0, nil}
|
||||||
|
}
|
||||||
return Event{Invalid, 0, nil} // INS
|
return Event{Invalid, 0, nil} // INS
|
||||||
case 51:
|
case 51:
|
||||||
return Event{Del, 0, nil}
|
return Event{Del, 0, nil}
|
||||||
@@ -434,6 +538,21 @@ func escSequence(sz *int) Event {
|
|||||||
switch _buf[3] {
|
switch _buf[3] {
|
||||||
case 126:
|
case 126:
|
||||||
return Event{Home, 0, nil}
|
return Event{Home, 0, nil}
|
||||||
|
case 53, 55, 56, 57:
|
||||||
|
if len(_buf) == 5 && _buf[4] == 126 {
|
||||||
|
*sz = 5
|
||||||
|
switch _buf[3] {
|
||||||
|
case 53:
|
||||||
|
return Event{F5, 0, nil}
|
||||||
|
case 55:
|
||||||
|
return Event{F6, 0, nil}
|
||||||
|
case 56:
|
||||||
|
return Event{F7, 0, nil}
|
||||||
|
case 57:
|
||||||
|
return Event{F8, 0, nil}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Event{Invalid, 0, nil}
|
||||||
case 59:
|
case 59:
|
||||||
if len(_buf) != 6 {
|
if len(_buf) != 6 {
|
||||||
return Event{Invalid, 0, nil}
|
return Event{Invalid, 0, nil}
|
||||||
@@ -503,24 +622,37 @@ func GetChar() Event {
|
|||||||
return Event{Rune, r, nil}
|
return Event{Rune, r, nil}
|
||||||
}
|
}
|
||||||
|
|
||||||
func Move(y int, x int) {
|
func (w *Window) Close() {
|
||||||
C.move(C.int(y), C.int(x))
|
C.delwin(w.win)
|
||||||
}
|
}
|
||||||
|
|
||||||
func MoveAndClear(y int, x int) {
|
func (w *Window) Enclose(y int, x int) bool {
|
||||||
Move(y, x)
|
return bool(C.wenclose(w.win, C.int(y), C.int(x)))
|
||||||
C.clrtoeol()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func Print(text string) {
|
func (w *Window) Move(y int, x int) {
|
||||||
C.addstr(C.CString(text))
|
C.wmove(w.win, C.int(y), C.int(x))
|
||||||
}
|
}
|
||||||
|
|
||||||
func CPrint(pair int, bold bool, text string) {
|
func (w *Window) MoveAndClear(y int, x int) {
|
||||||
|
w.Move(y, x)
|
||||||
|
C.wclrtoeol(w.win)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *Window) Print(text string) {
|
||||||
|
C.waddstr(w.win, C.CString(strings.Map(func(r rune) rune {
|
||||||
|
if r < 32 {
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
return r
|
||||||
|
}, text)))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *Window) CPrint(pair int, bold bool, text string) {
|
||||||
attr := _color(pair, bold)
|
attr := _color(pair, bold)
|
||||||
C.attron(attr)
|
C.wattron(w.win, attr)
|
||||||
Print(text)
|
w.Print(text)
|
||||||
C.attroff(attr)
|
C.wattroff(w.win, attr)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Clear() {
|
func Clear() {
|
||||||
@@ -535,6 +667,30 @@ func Refresh() {
|
|||||||
C.refresh()
|
C.refresh()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (w *Window) Erase() {
|
||||||
|
C.werase(w.win)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *Window) Fill(str string) bool {
|
||||||
|
return C.waddstr(w.win, C.CString(str)) == C.OK
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *Window) CFill(str string, fg int, bg int, bold bool) bool {
|
||||||
|
attr := _color(PairFor(fg, bg), bold)
|
||||||
|
C.wattron(w.win, attr)
|
||||||
|
ret := w.Fill(str)
|
||||||
|
C.wattroff(w.win, attr)
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w *Window) Refresh() {
|
||||||
|
C.wnoutrefresh(w.win)
|
||||||
|
}
|
||||||
|
|
||||||
|
func DoUpdate() {
|
||||||
|
C.doupdate()
|
||||||
|
}
|
||||||
|
|
||||||
func PairFor(fg int, bg int) int {
|
func PairFor(fg int, bg int) int {
|
||||||
key := (fg << 8) + bg
|
key := (fg << 8) + bg
|
||||||
if found, prs := _colorMap[key]; prs {
|
if found, prs := _colorMap[key]; prs {
|
||||||
|
89
src/item.go
89
src/item.go
@@ -20,31 +20,42 @@ type Item struct {
|
|||||||
text []rune
|
text []rune
|
||||||
origText *[]rune
|
origText *[]rune
|
||||||
transformed []Token
|
transformed []Token
|
||||||
index uint32
|
|
||||||
offsets []Offset
|
offsets []Offset
|
||||||
colors []ansiOffset
|
colors []ansiOffset
|
||||||
rank Rank
|
rank [5]int32
|
||||||
|
bonus int32
|
||||||
}
|
}
|
||||||
|
|
||||||
// Rank is used to sort the search result
|
// Sort criteria to use. Never changes once fzf is started.
|
||||||
type Rank struct {
|
var sortCriteria []criterion
|
||||||
matchlen uint16
|
|
||||||
tiebreak uint16
|
func isRankValid(rank [5]int32) bool {
|
||||||
index uint32
|
// Exclude ordinal index
|
||||||
|
for _, r := range rank[:4] {
|
||||||
|
if r > 0 {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tiebreak criterion to use. Never changes once fzf is started.
|
func buildEmptyRank(index int32) [5]int32 {
|
||||||
var rankTiebreak tiebreak
|
return [5]int32{0, 0, 0, 0, index}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (item *Item) Index() int32 {
|
||||||
|
return item.rank[4]
|
||||||
|
}
|
||||||
|
|
||||||
// Rank calculates rank of the Item
|
// Rank calculates rank of the Item
|
||||||
func (item *Item) Rank(cache bool) Rank {
|
func (item *Item) Rank(cache bool) [5]int32 {
|
||||||
if cache && (item.rank.matchlen > 0 || item.rank.tiebreak > 0) {
|
if cache && isRankValid(item.rank) {
|
||||||
return item.rank
|
return item.rank
|
||||||
}
|
}
|
||||||
matchlen := 0
|
matchlen := 0
|
||||||
prevEnd := 0
|
prevEnd := 0
|
||||||
lenSum := 0
|
lenSum := 0
|
||||||
minBegin := math.MaxUint16
|
minBegin := math.MaxInt32
|
||||||
for _, offset := range item.offsets {
|
for _, offset := range item.offsets {
|
||||||
begin := int(offset[0])
|
begin := int(offset[0])
|
||||||
end := int(offset[1])
|
end := int(offset[1])
|
||||||
@@ -63,30 +74,45 @@ func (item *Item) Rank(cache bool) Rank {
|
|||||||
matchlen += end - begin
|
matchlen += end - begin
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var tiebreak uint16
|
rank := buildEmptyRank(item.Index())
|
||||||
switch rankTiebreak {
|
for idx, criterion := range sortCriteria {
|
||||||
|
var val int32
|
||||||
|
switch criterion {
|
||||||
|
case byMatchLen:
|
||||||
|
if matchlen == 0 {
|
||||||
|
val = math.MaxInt32
|
||||||
|
} else {
|
||||||
|
// It is extremely unlikely that bonus exceeds 128
|
||||||
|
val = 128*int32(matchlen) - item.bonus
|
||||||
|
}
|
||||||
case byLength:
|
case byLength:
|
||||||
// It is guaranteed that .transformed in not null in normal execution
|
// It is guaranteed that .transformed in not null in normal execution
|
||||||
if item.transformed != nil {
|
if item.transformed != nil {
|
||||||
// If offsets is empty, lenSum will be 0, but we don't care
|
// If offsets is empty, lenSum will be 0, but we don't care
|
||||||
tiebreak = uint16(lenSum)
|
val = int32(lenSum)
|
||||||
} else {
|
} else {
|
||||||
tiebreak = uint16(len(item.text))
|
val = int32(len(item.text))
|
||||||
}
|
}
|
||||||
case byBegin:
|
case byBegin:
|
||||||
// We can't just look at item.offsets[0][0] because it can be an inverse term
|
// We can't just look at item.offsets[0][0] because it can be an inverse term
|
||||||
tiebreak = uint16(minBegin)
|
whitePrefixLen := 0
|
||||||
|
for idx, r := range item.text {
|
||||||
|
whitePrefixLen = idx
|
||||||
|
if idx == minBegin || r != ' ' && r != '\t' {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
val = int32(minBegin - whitePrefixLen)
|
||||||
case byEnd:
|
case byEnd:
|
||||||
if prevEnd > 0 {
|
if prevEnd > 0 {
|
||||||
tiebreak = uint16(1 + len(item.text) - prevEnd)
|
val = int32(1 + len(item.text) - prevEnd)
|
||||||
} else {
|
} else {
|
||||||
// Empty offsets due to inverse terms.
|
// Empty offsets due to inverse terms.
|
||||||
tiebreak = 1
|
val = 1
|
||||||
}
|
}
|
||||||
case byIndex:
|
|
||||||
tiebreak = 1
|
|
||||||
}
|
}
|
||||||
rank := Rank{uint16(matchlen), tiebreak, item.index}
|
rank[idx] = val
|
||||||
|
}
|
||||||
if cache {
|
if cache {
|
||||||
item.rank = rank
|
item.rank = rank
|
||||||
}
|
}
|
||||||
@@ -102,7 +128,7 @@ func (item *Item) AsString(stripAnsi bool) string {
|
|||||||
func (item *Item) StringPtr(stripAnsi bool) *string {
|
func (item *Item) StringPtr(stripAnsi bool) *string {
|
||||||
if item.origText != nil {
|
if item.origText != nil {
|
||||||
if stripAnsi {
|
if stripAnsi {
|
||||||
trimmed, _, _ := extractColor(string(*item.origText), nil)
|
trimmed, _, _ := extractColor(string(*item.origText), nil, nil)
|
||||||
return &trimmed
|
return &trimmed
|
||||||
}
|
}
|
||||||
orig := string(*item.origText)
|
orig := string(*item.origText)
|
||||||
@@ -251,18 +277,15 @@ func (a ByRelevanceTac) Less(i, j int) bool {
|
|||||||
return compareRanks(irank, jrank, true)
|
return compareRanks(irank, jrank, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
func compareRanks(irank Rank, jrank Rank, tac bool) bool {
|
func compareRanks(irank [5]int32, jrank [5]int32, tac bool) bool {
|
||||||
if irank.matchlen < jrank.matchlen {
|
for idx := 0; idx < 4; idx++ {
|
||||||
|
left := irank[idx]
|
||||||
|
right := jrank[idx]
|
||||||
|
if left < right {
|
||||||
return true
|
return true
|
||||||
} else if irank.matchlen > jrank.matchlen {
|
} else if left > right {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
if irank.tiebreak < jrank.tiebreak {
|
|
||||||
return true
|
|
||||||
} else if irank.tiebreak > jrank.tiebreak {
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
return (irank[4] <= jrank[4]) != tac
|
||||||
return (irank.index <= jrank.index) != tac
|
|
||||||
}
|
}
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
package fzf
|
package fzf
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"math"
|
||||||
"sort"
|
"sort"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
@@ -22,31 +23,34 @@ func TestOffsetSort(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestRankComparison(t *testing.T) {
|
func TestRankComparison(t *testing.T) {
|
||||||
if compareRanks(Rank{3, 0, 5}, Rank{2, 0, 7}, false) ||
|
if compareRanks([5]int32{3, 0, 0, 0, 5}, [5]int32{2, 0, 0, 0, 7}, false) ||
|
||||||
!compareRanks(Rank{3, 0, 5}, Rank{3, 0, 6}, false) ||
|
!compareRanks([5]int32{3, 0, 0, 0, 5}, [5]int32{3, 0, 0, 0, 6}, false) ||
|
||||||
!compareRanks(Rank{1, 2, 3}, Rank{1, 3, 2}, false) ||
|
!compareRanks([5]int32{1, 2, 0, 0, 3}, [5]int32{1, 3, 0, 0, 2}, false) ||
|
||||||
!compareRanks(Rank{0, 0, 0}, Rank{0, 0, 0}, false) {
|
!compareRanks([5]int32{0, 0, 0, 0, 0}, [5]int32{0, 0, 0, 0, 0}, false) {
|
||||||
t.Error("Invalid order")
|
t.Error("Invalid order")
|
||||||
}
|
}
|
||||||
|
|
||||||
if compareRanks(Rank{3, 0, 5}, Rank{2, 0, 7}, true) ||
|
if compareRanks([5]int32{3, 0, 0, 0, 5}, [5]int32{2, 0, 0, 0, 7}, true) ||
|
||||||
!compareRanks(Rank{3, 0, 5}, Rank{3, 0, 6}, false) ||
|
!compareRanks([5]int32{3, 0, 0, 0, 5}, [5]int32{3, 0, 0, 0, 6}, false) ||
|
||||||
!compareRanks(Rank{1, 2, 3}, Rank{1, 3, 2}, true) ||
|
!compareRanks([5]int32{1, 2, 0, 0, 3}, [5]int32{1, 3, 0, 0, 2}, true) ||
|
||||||
!compareRanks(Rank{0, 0, 0}, Rank{0, 0, 0}, false) {
|
!compareRanks([5]int32{0, 0, 0, 0, 0}, [5]int32{0, 0, 0, 0, 0}, false) {
|
||||||
t.Error("Invalid order (tac)")
|
t.Error("Invalid order (tac)")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Match length, string length, index
|
// Match length, string length, index
|
||||||
func TestItemRank(t *testing.T) {
|
func TestItemRank(t *testing.T) {
|
||||||
|
// FIXME global
|
||||||
|
sortCriteria = []criterion{byMatchLen, byLength}
|
||||||
|
|
||||||
strs := [][]rune{[]rune("foo"), []rune("foobar"), []rune("bar"), []rune("baz")}
|
strs := [][]rune{[]rune("foo"), []rune("foobar"), []rune("bar"), []rune("baz")}
|
||||||
item1 := Item{text: strs[0], index: 1, offsets: []Offset{}}
|
item1 := Item{text: strs[0], offsets: []Offset{}, rank: [5]int32{0, 0, 0, 0, 1}}
|
||||||
rank1 := item1.Rank(true)
|
rank1 := item1.Rank(true)
|
||||||
if rank1.matchlen != 0 || rank1.tiebreak != 3 || rank1.index != 1 {
|
if rank1[0] != math.MaxInt32 || rank1[1] != 3 || rank1[4] != 1 {
|
||||||
t.Error(item1.Rank(true))
|
t.Error(item1.Rank(true))
|
||||||
}
|
}
|
||||||
// Only differ in index
|
// Only differ in index
|
||||||
item2 := Item{text: strs[0], index: 0, offsets: []Offset{}}
|
item2 := Item{text: strs[0], offsets: []Offset{}}
|
||||||
|
|
||||||
items := []*Item{&item1, &item2}
|
items := []*Item{&item1, &item2}
|
||||||
sort.Sort(ByRelevance(items))
|
sort.Sort(ByRelevance(items))
|
||||||
@@ -62,15 +66,15 @@ func TestItemRank(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Sort by relevance
|
// Sort by relevance
|
||||||
item3 := Item{text: strs[1], rank: Rank{0, 0, 2}, offsets: []Offset{Offset{1, 3}, Offset{5, 7}}}
|
item3 := Item{text: strs[1], rank: [5]int32{0, 0, 0, 0, 2}, offsets: []Offset{Offset{1, 3}, Offset{5, 7}}}
|
||||||
item4 := Item{text: strs[1], rank: Rank{0, 0, 2}, offsets: []Offset{Offset{1, 2}, Offset{6, 7}}}
|
item4 := Item{text: strs[1], rank: [5]int32{0, 0, 0, 0, 2}, offsets: []Offset{Offset{1, 2}, Offset{6, 7}}}
|
||||||
item5 := Item{text: strs[2], rank: Rank{0, 0, 2}, offsets: []Offset{Offset{1, 3}, Offset{5, 7}}}
|
item5 := Item{text: strs[2], rank: [5]int32{0, 0, 0, 0, 2}, offsets: []Offset{Offset{1, 3}, Offset{5, 7}}}
|
||||||
item6 := Item{text: strs[2], rank: Rank{0, 0, 2}, offsets: []Offset{Offset{1, 2}, Offset{6, 7}}}
|
item6 := Item{text: strs[2], rank: [5]int32{0, 0, 0, 0, 2}, offsets: []Offset{Offset{1, 2}, Offset{6, 7}}}
|
||||||
items = []*Item{&item1, &item2, &item3, &item4, &item5, &item6}
|
items = []*Item{&item1, &item2, &item3, &item4, &item5, &item6}
|
||||||
sort.Sort(ByRelevance(items))
|
sort.Sort(ByRelevance(items))
|
||||||
if items[0] != &item2 || items[1] != &item1 ||
|
if items[0] != &item6 || items[1] != &item4 ||
|
||||||
items[2] != &item6 || items[3] != &item4 ||
|
items[2] != &item5 || items[3] != &item3 ||
|
||||||
items[4] != &item5 || items[5] != &item3 {
|
items[4] != &item2 || items[5] != &item1 {
|
||||||
t.Error(items)
|
t.Error(items)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -200,7 +200,7 @@ func (m *Matcher) scan(request MatchRequest) (*Merger, bool) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
partialResults := make([][]*Item, numSlices)
|
partialResults := make([][]*Item, numSlices)
|
||||||
for range slices {
|
for _, _ = range slices {
|
||||||
partialResult := <-resultChan
|
partialResult := <-resultChan
|
||||||
partialResults[partialResult.index] = partialResult.matches
|
partialResults[partialResult.index] = partialResult.matches
|
||||||
}
|
}
|
||||||
|
@@ -88,7 +88,7 @@ func (mg *Merger) cacheable() bool {
|
|||||||
|
|
||||||
func (mg *Merger) mergedGet(idx int) *Item {
|
func (mg *Merger) mergedGet(idx int) *Item {
|
||||||
for i := len(mg.merged); i <= idx; i++ {
|
for i := len(mg.merged); i <= idx; i++ {
|
||||||
minRank := Rank{0, 0, 0}
|
minRank := buildEmptyRank(0)
|
||||||
minIdx := -1
|
minIdx := -1
|
||||||
for listIdx, list := range mg.lists {
|
for listIdx, list := range mg.lists {
|
||||||
cursor := mg.cursors[listIdx]
|
cursor := mg.cursors[listIdx]
|
||||||
|
@@ -23,7 +23,7 @@ func randItem() *Item {
|
|||||||
}
|
}
|
||||||
return &Item{
|
return &Item{
|
||||||
text: []rune(str),
|
text: []rune(str),
|
||||||
index: rand.Uint32(),
|
rank: buildEmptyRank(rand.Int31()),
|
||||||
offsets: offsets}
|
offsets: offsets}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
407
src/options.go
407
src/options.go
@@ -1,6 +1,7 @@
|
|||||||
package fzf
|
package fzf
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
@@ -16,37 +17,54 @@ const usage = `usage: fzf [options]
|
|||||||
|
|
||||||
Search
|
Search
|
||||||
-x, --extended Extended-search mode
|
-x, --extended Extended-search mode
|
||||||
-e, --extended-exact Extended-search mode (exact match)
|
(enabled by default; +x or --no-extended to disable)
|
||||||
|
-e, --exact Enable Exact-match
|
||||||
-i Case-insensitive match (default: smart-case match)
|
-i Case-insensitive match (default: smart-case match)
|
||||||
+i Case-sensitive match
|
+i Case-sensitive match
|
||||||
-n, --nth=N[,..] Comma-separated list of field index expressions
|
-n, --nth=N[,..] Comma-separated list of field index expressions
|
||||||
for limiting search scope. Each can be a non-zero
|
for limiting search scope. Each can be a non-zero
|
||||||
integer or a range expression ([BEGIN]..[END])
|
integer or a range expression ([BEGIN]..[END]).
|
||||||
--with-nth=N[,..] Transform item using index expressions within finder
|
--with-nth=N[,..] Transform the presentation of each line using
|
||||||
-d, --delimiter=STR Field delimiter regex for --nth (default: AWK-style)
|
field index expressions
|
||||||
|
-d, --delimiter=STR Field delimiter regex (default: AWK-style)
|
||||||
+s, --no-sort Do not sort the result
|
+s, --no-sort Do not sort the result
|
||||||
--tac Reverse the order of the input
|
--tac Reverse the order of the input
|
||||||
--tiebreak=CRITERION Sort criterion when the scores are tied;
|
--tiebreak=CRI[,..] Comma-separated list of sort criteria to apply
|
||||||
[length|begin|end|index] (default: length)
|
when the scores are tied [length|begin|end|index]
|
||||||
|
(default: length)
|
||||||
|
|
||||||
Interface
|
Interface
|
||||||
-m, --multi Enable multi-select with tab/shift-tab
|
-m, --multi Enable multi-select with tab/shift-tab
|
||||||
--ansi Enable processing of ANSI color codes
|
|
||||||
--no-mouse Disable mouse
|
--no-mouse Disable mouse
|
||||||
--color=COLSPEC Base scheme (dark|light|16|bw) and/or custom colors
|
--bind=KEYBINDS Custom key bindings. Refer to the man page.
|
||||||
--black Use black background
|
|
||||||
--reverse Reverse orientation
|
|
||||||
--margin=MARGIN Screen margin (TRBL / TB,RL / T,RL,B / T,R,B,L)
|
|
||||||
--cycle Enable cyclic scroll
|
--cycle Enable cyclic scroll
|
||||||
--no-hscroll Disable horizontal scroll
|
--no-hscroll Disable horizontal scroll
|
||||||
|
--hscroll-off=COL Number of screen columns to keep to the right of the
|
||||||
|
highlighted substring (default: 10)
|
||||||
|
--jump-labels=CHARS Label characters for jump and jump-accept
|
||||||
|
|
||||||
|
Layout
|
||||||
|
--reverse Reverse orientation
|
||||||
|
--margin=MARGIN Screen margin (TRBL / TB,RL / T,RL,B / T,R,B,L)
|
||||||
--inline-info Display finder info inline with the query
|
--inline-info Display finder info inline with the query
|
||||||
--prompt=STR Input prompt (default: '> ')
|
--prompt=STR Input prompt (default: '> ')
|
||||||
--bind=KEYBINDS Custom key bindings. Refer to the man page.
|
|
||||||
--history=FILE History file
|
|
||||||
--history-size=N Maximum number of history entries (default: 1000)
|
|
||||||
--header=STR String to print as header
|
--header=STR String to print as header
|
||||||
--header-lines=N The first N lines of the input are treated as header
|
--header-lines=N The first N lines of the input are treated as header
|
||||||
|
|
||||||
|
Display
|
||||||
|
--ansi Enable processing of ANSI color codes
|
||||||
|
--tabstop=SPACES Number of spaces for a tab character (default: 8)
|
||||||
|
--color=COLSPEC Base scheme (dark|light|16|bw) and/or custom colors
|
||||||
|
|
||||||
|
History
|
||||||
|
--history=FILE History file
|
||||||
|
--history-size=N Maximum number of history entries (default: 1000)
|
||||||
|
|
||||||
|
Preview
|
||||||
|
--preview=COMMAND Command to preview highlighted line ({})
|
||||||
|
--preview-window=OPT Preview window layout (default: right:50%)
|
||||||
|
[up|down|left|right][:SIZE[%]][:hidden]
|
||||||
|
|
||||||
Scripting
|
Scripting
|
||||||
-q, --query=STR Start the finder with the given query
|
-q, --query=STR Start the finder with the given query
|
||||||
-1, --select-1 Automatically select the only match
|
-1, --select-1 Automatically select the only match
|
||||||
@@ -58,20 +76,10 @@ const usage = `usage: fzf [options]
|
|||||||
|
|
||||||
Environment variables
|
Environment variables
|
||||||
FZF_DEFAULT_COMMAND Default command to use when input is tty
|
FZF_DEFAULT_COMMAND Default command to use when input is tty
|
||||||
FZF_DEFAULT_OPTS Defaults options. (e.g. '-x -m')
|
FZF_DEFAULT_OPTS Default options (e.g. '--reverse --inline-info')
|
||||||
|
|
||||||
`
|
`
|
||||||
|
|
||||||
// Mode denotes the current search mode
|
|
||||||
type Mode int
|
|
||||||
|
|
||||||
// Search modes
|
|
||||||
const (
|
|
||||||
ModeFuzzy Mode = iota
|
|
||||||
ModeExtended
|
|
||||||
ModeExtendedExact
|
|
||||||
)
|
|
||||||
|
|
||||||
// Case denotes case-sensitivity of search
|
// Case denotes case-sensitivity of search
|
||||||
type Case int
|
type Case int
|
||||||
|
|
||||||
@@ -83,29 +91,51 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Sort criteria
|
// Sort criteria
|
||||||
type tiebreak int
|
type criterion int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
byLength tiebreak = iota
|
byMatchLen criterion = iota
|
||||||
|
byLength
|
||||||
byBegin
|
byBegin
|
||||||
byEnd
|
byEnd
|
||||||
byIndex
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func defaultMargin() [4]string {
|
type sizeSpec struct {
|
||||||
return [4]string{"0", "0", "0", "0"}
|
size float64
|
||||||
|
percent bool
|
||||||
|
}
|
||||||
|
|
||||||
|
func defaultMargin() [4]sizeSpec {
|
||||||
|
return [4]sizeSpec{}
|
||||||
|
}
|
||||||
|
|
||||||
|
type windowPosition int
|
||||||
|
|
||||||
|
const (
|
||||||
|
posUp windowPosition = iota
|
||||||
|
posDown
|
||||||
|
posLeft
|
||||||
|
posRight
|
||||||
|
)
|
||||||
|
|
||||||
|
type previewOpts struct {
|
||||||
|
command string
|
||||||
|
position windowPosition
|
||||||
|
size sizeSpec
|
||||||
|
hidden bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// Options stores the values of command-line options
|
// Options stores the values of command-line options
|
||||||
type Options struct {
|
type Options struct {
|
||||||
Mode Mode
|
Fuzzy bool
|
||||||
|
Extended bool
|
||||||
Case Case
|
Case Case
|
||||||
Nth []Range
|
Nth []Range
|
||||||
WithNth []Range
|
WithNth []Range
|
||||||
Delimiter Delimiter
|
Delimiter Delimiter
|
||||||
Sort int
|
Sort int
|
||||||
Tac bool
|
Tac bool
|
||||||
Tiebreak tiebreak
|
Criteria []criterion
|
||||||
Multi bool
|
Multi bool
|
||||||
Ansi bool
|
Ansi bool
|
||||||
Mouse bool
|
Mouse bool
|
||||||
@@ -114,7 +144,9 @@ type Options struct {
|
|||||||
Reverse bool
|
Reverse bool
|
||||||
Cycle bool
|
Cycle bool
|
||||||
Hscroll bool
|
Hscroll bool
|
||||||
|
HscrollOff int
|
||||||
InlineInfo bool
|
InlineInfo bool
|
||||||
|
JumpLabels string
|
||||||
Prompt string
|
Prompt string
|
||||||
Query string
|
Query string
|
||||||
Select1 bool
|
Select1 bool
|
||||||
@@ -124,42 +156,40 @@ type Options struct {
|
|||||||
Expect map[int]string
|
Expect map[int]string
|
||||||
Keymap map[int]actionType
|
Keymap map[int]actionType
|
||||||
Execmap map[int]string
|
Execmap map[int]string
|
||||||
|
Preview previewOpts
|
||||||
PrintQuery bool
|
PrintQuery bool
|
||||||
ReadZero bool
|
ReadZero bool
|
||||||
Sync bool
|
Sync bool
|
||||||
History *History
|
History *History
|
||||||
Header []string
|
Header []string
|
||||||
HeaderLines int
|
HeaderLines int
|
||||||
Margin [4]string
|
Margin [4]sizeSpec
|
||||||
|
Tabstop int
|
||||||
Version bool
|
Version bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func defaultTheme() *curses.ColorTheme {
|
|
||||||
if strings.Contains(os.Getenv("TERM"), "256") {
|
|
||||||
return curses.Dark256
|
|
||||||
}
|
|
||||||
return curses.Default16
|
|
||||||
}
|
|
||||||
|
|
||||||
func defaultOptions() *Options {
|
func defaultOptions() *Options {
|
||||||
return &Options{
|
return &Options{
|
||||||
Mode: ModeFuzzy,
|
Fuzzy: true,
|
||||||
|
Extended: true,
|
||||||
Case: CaseSmart,
|
Case: CaseSmart,
|
||||||
Nth: make([]Range, 0),
|
Nth: make([]Range, 0),
|
||||||
WithNth: make([]Range, 0),
|
WithNth: make([]Range, 0),
|
||||||
Delimiter: Delimiter{},
|
Delimiter: Delimiter{},
|
||||||
Sort: 1000,
|
Sort: 1000,
|
||||||
Tac: false,
|
Tac: false,
|
||||||
Tiebreak: byLength,
|
Criteria: []criterion{byMatchLen, byLength},
|
||||||
Multi: false,
|
Multi: false,
|
||||||
Ansi: false,
|
Ansi: false,
|
||||||
Mouse: true,
|
Mouse: true,
|
||||||
Theme: defaultTheme(),
|
Theme: curses.EmptyTheme(),
|
||||||
Black: false,
|
Black: false,
|
||||||
Reverse: false,
|
Reverse: false,
|
||||||
Cycle: false,
|
Cycle: false,
|
||||||
Hscroll: true,
|
Hscroll: true,
|
||||||
|
HscrollOff: 10,
|
||||||
InlineInfo: false,
|
InlineInfo: false,
|
||||||
|
JumpLabels: defaultJumpLabels,
|
||||||
Prompt: "> ",
|
Prompt: "> ",
|
||||||
Query: "",
|
Query: "",
|
||||||
Select1: false,
|
Select1: false,
|
||||||
@@ -167,8 +197,9 @@ func defaultOptions() *Options {
|
|||||||
Filter: nil,
|
Filter: nil,
|
||||||
ToggleSort: false,
|
ToggleSort: false,
|
||||||
Expect: make(map[int]string),
|
Expect: make(map[int]string),
|
||||||
Keymap: defaultKeymap(),
|
Keymap: make(map[int]actionType),
|
||||||
Execmap: make(map[int]string),
|
Execmap: make(map[int]string),
|
||||||
|
Preview: previewOpts{"", posRight, sizeSpec{50, true}, false},
|
||||||
PrintQuery: false,
|
PrintQuery: false,
|
||||||
ReadZero: false,
|
ReadZero: false,
|
||||||
Sync: false,
|
Sync: false,
|
||||||
@@ -176,6 +207,7 @@ func defaultOptions() *Options {
|
|||||||
Header: make([]string, 0),
|
Header: make([]string, 0),
|
||||||
HeaderLines: 0,
|
HeaderLines: 0,
|
||||||
Margin: defaultMargin(),
|
Margin: defaultMargin(),
|
||||||
|
Tabstop: 8,
|
||||||
Version: false}
|
Version: false}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -321,6 +353,12 @@ func parseKeyChords(str string, message string) map[int]string {
|
|||||||
chord = curses.AltZ + int(' ')
|
chord = curses.AltZ + int(' ')
|
||||||
case "bspace", "bs":
|
case "bspace", "bs":
|
||||||
chord = curses.BSpace
|
chord = curses.BSpace
|
||||||
|
case "alt-enter", "alt-return":
|
||||||
|
chord = curses.AltEnter
|
||||||
|
case "alt-space":
|
||||||
|
chord = curses.AltSpace
|
||||||
|
case "alt-/":
|
||||||
|
chord = curses.AltSlash
|
||||||
case "alt-bs", "alt-bspace":
|
case "alt-bs", "alt-bspace":
|
||||||
chord = curses.AltBS
|
chord = curses.AltBS
|
||||||
case "tab":
|
case "tab":
|
||||||
@@ -343,12 +381,16 @@ func parseKeyChords(str string, message string) map[int]string {
|
|||||||
chord = curses.SLeft
|
chord = curses.SLeft
|
||||||
case "shift-right":
|
case "shift-right":
|
||||||
chord = curses.SRight
|
chord = curses.SRight
|
||||||
|
case "double-click":
|
||||||
|
chord = curses.DoubleClick
|
||||||
|
case "f10":
|
||||||
|
chord = curses.F10
|
||||||
default:
|
default:
|
||||||
if len(key) == 6 && strings.HasPrefix(lkey, "ctrl-") && isAlphabet(lkey[5]) {
|
if len(key) == 6 && strings.HasPrefix(lkey, "ctrl-") && isAlphabet(lkey[5]) {
|
||||||
chord = curses.CtrlA + int(lkey[5]) - 'a'
|
chord = curses.CtrlA + int(lkey[5]) - 'a'
|
||||||
} else if len(key) == 5 && strings.HasPrefix(lkey, "alt-") && isAlphabet(lkey[4]) {
|
} else if len(key) == 5 && strings.HasPrefix(lkey, "alt-") && isAlphabet(lkey[4]) {
|
||||||
chord = curses.AltA + int(lkey[4]) - 'a'
|
chord = curses.AltA + int(lkey[4]) - 'a'
|
||||||
} else if len(key) == 2 && strings.HasPrefix(lkey, "f") && key[1] >= '1' && key[1] <= '4' {
|
} else if len(key) == 2 && strings.HasPrefix(lkey, "f") && key[1] >= '1' && key[1] <= '9' {
|
||||||
chord = curses.F1 + int(key[1]) - '1'
|
chord = curses.F1 + int(key[1]) - '1'
|
||||||
} else if utf8.RuneCountInString(key) == 1 {
|
} else if utf8.RuneCountInString(key) == 1 {
|
||||||
chord = curses.AltZ + int([]rune(key)[0])
|
chord = curses.AltZ + int([]rune(key)[0])
|
||||||
@@ -363,20 +405,39 @@ func parseKeyChords(str string, message string) map[int]string {
|
|||||||
return chords
|
return chords
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseTiebreak(str string) tiebreak {
|
func parseTiebreak(str string) []criterion {
|
||||||
switch strings.ToLower(str) {
|
criteria := []criterion{byMatchLen}
|
||||||
case "length":
|
hasIndex := false
|
||||||
return byLength
|
hasLength := false
|
||||||
|
hasBegin := false
|
||||||
|
hasEnd := false
|
||||||
|
check := func(notExpected *bool, name string) {
|
||||||
|
if *notExpected {
|
||||||
|
errorExit("duplicate sort criteria: " + name)
|
||||||
|
}
|
||||||
|
if hasIndex {
|
||||||
|
errorExit("index should be the last criterion")
|
||||||
|
}
|
||||||
|
*notExpected = true
|
||||||
|
}
|
||||||
|
for _, str := range strings.Split(strings.ToLower(str), ",") {
|
||||||
|
switch str {
|
||||||
case "index":
|
case "index":
|
||||||
return byIndex
|
check(&hasIndex, "index")
|
||||||
|
case "length":
|
||||||
|
check(&hasLength, "length")
|
||||||
|
criteria = append(criteria, byLength)
|
||||||
case "begin":
|
case "begin":
|
||||||
return byBegin
|
check(&hasBegin, "begin")
|
||||||
|
criteria = append(criteria, byBegin)
|
||||||
case "end":
|
case "end":
|
||||||
return byEnd
|
check(&hasEnd, "end")
|
||||||
|
criteria = append(criteria, byEnd)
|
||||||
default:
|
default:
|
||||||
errorExit("invalid sort criterion: " + str)
|
errorExit("invalid sort criterion: " + str)
|
||||||
}
|
}
|
||||||
return byLength
|
}
|
||||||
|
return criteria
|
||||||
}
|
}
|
||||||
|
|
||||||
func dupeTheme(theme *curses.ColorTheme) *curses.ColorTheme {
|
func dupeTheme(theme *curses.ColorTheme) *curses.ColorTheme {
|
||||||
@@ -432,6 +493,8 @@ func parseTheme(defaultTheme *curses.ColorTheme, str string) *curses.ColorTheme
|
|||||||
theme.Match = ansi
|
theme.Match = ansi
|
||||||
case "hl+":
|
case "hl+":
|
||||||
theme.CurrentMatch = ansi
|
theme.CurrentMatch = ansi
|
||||||
|
case "border":
|
||||||
|
theme.Border = ansi
|
||||||
case "prompt":
|
case "prompt":
|
||||||
theme.Prompt = ansi
|
theme.Prompt = ansi
|
||||||
case "spinner":
|
case "spinner":
|
||||||
@@ -466,15 +529,18 @@ const (
|
|||||||
escapedComma = 1
|
escapedComma = 1
|
||||||
)
|
)
|
||||||
|
|
||||||
func parseKeymap(keymap map[int]actionType, execmap map[int]string, toggleSort bool, str string) (map[int]actionType, map[int]string, bool) {
|
func parseKeymap(keymap map[int]actionType, execmap map[int]string, str string) {
|
||||||
if executeRegexp == nil {
|
if executeRegexp == nil {
|
||||||
// Backreferences are not supported.
|
// Backreferences are not supported.
|
||||||
// "~!@#$%^&*;/|".each_char.map { |c| Regexp.escape(c) }.map { |c| "#{c}[^#{c}]*#{c}" }.join('|')
|
// "~!@#$%^&*;/|".each_char.map { |c| Regexp.escape(c) }.map { |c| "#{c}[^#{c}]*#{c}" }.join('|')
|
||||||
executeRegexp = regexp.MustCompile(
|
executeRegexp = regexp.MustCompile(
|
||||||
"(?s):execute:.*|:execute(\\([^)]*\\)|\\[[^\\]]*\\]|~[^~]*~|![^!]*!|@[^@]*@|\\#[^\\#]*\\#|\\$[^\\$]*\\$|%[^%]*%|\\^[^\\^]*\\^|&[^&]*&|\\*[^\\*]*\\*|;[^;]*;|/[^/]*/|\\|[^\\|]*\\|)")
|
"(?s):execute(-multi)?:.*|:execute(-multi)?(\\([^)]*\\)|\\[[^\\]]*\\]|~[^~]*~|![^!]*!|@[^@]*@|\\#[^\\#]*\\#|\\$[^\\$]*\\$|%[^%]*%|\\^[^\\^]*\\^|&[^&]*&|\\*[^\\*]*\\*|;[^;]*;|/[^/]*/|\\|[^\\|]*\\|)")
|
||||||
}
|
}
|
||||||
masked := executeRegexp.ReplaceAllStringFunc(str, func(src string) string {
|
masked := executeRegexp.ReplaceAllStringFunc(str, func(src string) string {
|
||||||
return ":execute(" + strings.Repeat(" ", len(src)-10) + ")"
|
if strings.HasPrefix(src, ":execute-multi") {
|
||||||
|
return ":execute-multi(" + strings.Repeat(" ", len(src)-len(":execute-multi()")) + ")"
|
||||||
|
}
|
||||||
|
return ":execute(" + strings.Repeat(" ", len(src)-len(":execute()")) + ")"
|
||||||
})
|
})
|
||||||
masked = strings.Replace(masked, "::", string([]rune{escapedColon, ':'}), -1)
|
masked = strings.Replace(masked, "::", string([]rune{escapedColon, ':'}), -1)
|
||||||
masked = strings.Replace(masked, ",:", string([]rune{escapedComma, ':'}), -1)
|
masked = strings.Replace(masked, ",:", string([]rune{escapedComma, ':'}), -1)
|
||||||
@@ -509,6 +575,8 @@ func parseKeymap(keymap map[int]actionType, execmap map[int]string, toggleSort b
|
|||||||
keymap[key] = actAbort
|
keymap[key] = actAbort
|
||||||
case "accept":
|
case "accept":
|
||||||
keymap[key] = actAccept
|
keymap[key] = actAccept
|
||||||
|
case "print-query":
|
||||||
|
keymap[key] = actPrintQuery
|
||||||
case "backward-char":
|
case "backward-char":
|
||||||
keymap[key] = actBackwardChar
|
keymap[key] = actBackwardChar
|
||||||
case "backward-delete-char":
|
case "backward-delete-char":
|
||||||
@@ -529,6 +597,10 @@ func parseKeymap(keymap map[int]actionType, execmap map[int]string, toggleSort b
|
|||||||
keymap[key] = actForwardChar
|
keymap[key] = actForwardChar
|
||||||
case "forward-word":
|
case "forward-word":
|
||||||
keymap[key] = actForwardWord
|
keymap[key] = actForwardWord
|
||||||
|
case "jump":
|
||||||
|
keymap[key] = actJump
|
||||||
|
case "jump-accept":
|
||||||
|
keymap[key] = actJumpAccept
|
||||||
case "kill-line":
|
case "kill-line":
|
||||||
keymap[key] = actKillLine
|
keymap[key] = actKillLine
|
||||||
case "kill-word":
|
case "kill-word":
|
||||||
@@ -545,6 +617,10 @@ func parseKeymap(keymap map[int]actionType, execmap map[int]string, toggleSort b
|
|||||||
keymap[key] = actToggleDown
|
keymap[key] = actToggleDown
|
||||||
case "toggle-up":
|
case "toggle-up":
|
||||||
keymap[key] = actToggleUp
|
keymap[key] = actToggleUp
|
||||||
|
case "toggle-in":
|
||||||
|
keymap[key] = actToggleIn
|
||||||
|
case "toggle-out":
|
||||||
|
keymap[key] = actToggleOut
|
||||||
case "toggle-all":
|
case "toggle-all":
|
||||||
keymap[key] = actToggleAll
|
keymap[key] = actToggleAll
|
||||||
case "select-all":
|
case "select-all":
|
||||||
@@ -565,30 +641,43 @@ func parseKeymap(keymap map[int]actionType, execmap map[int]string, toggleSort b
|
|||||||
keymap[key] = actPreviousHistory
|
keymap[key] = actPreviousHistory
|
||||||
case "next-history":
|
case "next-history":
|
||||||
keymap[key] = actNextHistory
|
keymap[key] = actNextHistory
|
||||||
|
case "toggle-preview":
|
||||||
|
keymap[key] = actTogglePreview
|
||||||
case "toggle-sort":
|
case "toggle-sort":
|
||||||
keymap[key] = actToggleSort
|
keymap[key] = actToggleSort
|
||||||
toggleSort = true
|
|
||||||
default:
|
default:
|
||||||
if isExecuteAction(actLower) {
|
if isExecuteAction(actLower) {
|
||||||
keymap[key] = actExecute
|
var offset int
|
||||||
if act[7] == ':' {
|
if strings.HasPrefix(actLower, "execute-multi") {
|
||||||
execmap[key] = act[8:]
|
keymap[key] = actExecuteMulti
|
||||||
|
offset = len("execute-multi")
|
||||||
} else {
|
} else {
|
||||||
execmap[key] = act[8 : len(act)-1]
|
keymap[key] = actExecute
|
||||||
|
offset = len("execute")
|
||||||
|
}
|
||||||
|
if act[offset] == ':' {
|
||||||
|
execmap[key] = act[offset+1:]
|
||||||
|
} else {
|
||||||
|
execmap[key] = act[offset+1 : len(act)-1]
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
errorExit("unknown action: " + act)
|
errorExit("unknown action: " + act)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return keymap, execmap, toggleSort
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func isExecuteAction(str string) bool {
|
func isExecuteAction(str string) bool {
|
||||||
if !strings.HasPrefix(str, "execute") || len(str) < 9 {
|
if !strings.HasPrefix(str, "execute") || len(str) < len("execute()") {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
b := str[7]
|
b := str[len("execute")]
|
||||||
|
if strings.HasPrefix(str, "execute-multi") {
|
||||||
|
if len(str) < len("execute-multi()") {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
b = str[len("execute-multi")]
|
||||||
|
}
|
||||||
e := str[len(str)-1]
|
e := str[len(str)-1]
|
||||||
if b == ':' || b == '(' && e == ')' || b == '[' && e == ']' ||
|
if b == ':' || b == '(' && e == ')' || b == '[' && e == ']' ||
|
||||||
b == e && strings.ContainsAny(string(b), "~!@#$%^&*;/|") {
|
b == e && strings.ContainsAny(string(b), "~!@#$%^&*;/|") {
|
||||||
@@ -597,53 +686,98 @@ func isExecuteAction(str string) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func checkToggleSort(keymap map[int]actionType, str string) map[int]actionType {
|
func parseToggleSort(keymap map[int]actionType, str string) {
|
||||||
keys := parseKeyChords(str, "key name required")
|
keys := parseKeyChords(str, "key name required")
|
||||||
if len(keys) != 1 {
|
if len(keys) != 1 {
|
||||||
errorExit("multiple keys specified")
|
errorExit("multiple keys specified")
|
||||||
}
|
}
|
||||||
keymap[firstKey(keys)] = actToggleSort
|
keymap[firstKey(keys)] = actToggleSort
|
||||||
return keymap
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func strLines(str string) []string {
|
func strLines(str string) []string {
|
||||||
return strings.Split(strings.TrimSuffix(str, "\n"), "\n")
|
return strings.Split(strings.TrimSuffix(str, "\n"), "\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseMargin(margin string) [4]string {
|
func parseSize(str string, maxPercent float64, label string) sizeSpec {
|
||||||
margins := strings.Split(margin, ",")
|
var val float64
|
||||||
checked := func(str string) string {
|
percent := strings.HasSuffix(str, "%")
|
||||||
if strings.HasSuffix(str, "%") {
|
if percent {
|
||||||
val := atof(str[:len(str)-1])
|
val = atof(str[:len(str)-1])
|
||||||
if val < 0 {
|
if val < 0 {
|
||||||
errorExit("margin must be non-negative")
|
errorExit(label + " must be non-negative")
|
||||||
}
|
}
|
||||||
if val > 100 {
|
if val > maxPercent {
|
||||||
errorExit("margin too large")
|
errorExit(fmt.Sprintf("%s too large (max: %d%%)", label, int(maxPercent)))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
val := atoi(str)
|
if strings.Contains(str, ".") {
|
||||||
|
errorExit(label + " (without %) must be a non-negative integer")
|
||||||
|
}
|
||||||
|
|
||||||
|
val = float64(atoi(str))
|
||||||
if val < 0 {
|
if val < 0 {
|
||||||
errorExit("margin must be non-negative")
|
errorExit(label + " must be non-negative")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return str
|
return sizeSpec{val, percent}
|
||||||
|
}
|
||||||
|
|
||||||
|
func parsePreviewWindow(opts *previewOpts, input string) {
|
||||||
|
layout := input
|
||||||
|
if strings.HasSuffix(layout, ":hidden") {
|
||||||
|
opts.hidden = true
|
||||||
|
layout = strings.TrimSuffix(layout, ":hidden")
|
||||||
|
}
|
||||||
|
|
||||||
|
tokens := strings.Split(layout, ":")
|
||||||
|
if len(tokens) == 0 || len(tokens) > 2 {
|
||||||
|
errorExit("invalid window layout: " + input)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(tokens) > 1 {
|
||||||
|
opts.size = parseSize(tokens[1], 99, "window size")
|
||||||
|
} else {
|
||||||
|
opts.size = sizeSpec{50, true}
|
||||||
|
}
|
||||||
|
if !opts.size.percent && opts.size.size > 0 {
|
||||||
|
// Adjust size for border
|
||||||
|
opts.size.size += 2
|
||||||
|
}
|
||||||
|
|
||||||
|
switch tokens[0] {
|
||||||
|
case "up":
|
||||||
|
opts.position = posUp
|
||||||
|
case "down":
|
||||||
|
opts.position = posDown
|
||||||
|
case "left":
|
||||||
|
opts.position = posLeft
|
||||||
|
case "right":
|
||||||
|
opts.position = posRight
|
||||||
|
default:
|
||||||
|
errorExit("invalid window position: " + input)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func parseMargin(margin string) [4]sizeSpec {
|
||||||
|
margins := strings.Split(margin, ",")
|
||||||
|
checked := func(str string) sizeSpec {
|
||||||
|
return parseSize(str, 49, "margin")
|
||||||
}
|
}
|
||||||
switch len(margins) {
|
switch len(margins) {
|
||||||
case 1:
|
case 1:
|
||||||
m := checked(margins[0])
|
m := checked(margins[0])
|
||||||
return [4]string{m, m, m, m}
|
return [4]sizeSpec{m, m, m, m}
|
||||||
case 2:
|
case 2:
|
||||||
tb := checked(margins[0])
|
tb := checked(margins[0])
|
||||||
rl := checked(margins[1])
|
rl := checked(margins[1])
|
||||||
return [4]string{tb, rl, tb, rl}
|
return [4]sizeSpec{tb, rl, tb, rl}
|
||||||
case 3:
|
case 3:
|
||||||
t := checked(margins[0])
|
t := checked(margins[0])
|
||||||
rl := checked(margins[1])
|
rl := checked(margins[1])
|
||||||
b := checked(margins[2])
|
b := checked(margins[2])
|
||||||
return [4]string{t, rl, b, rl}
|
return [4]sizeSpec{t, rl, b, rl}
|
||||||
case 4:
|
case 4:
|
||||||
return [4]string{
|
return [4]sizeSpec{
|
||||||
checked(margins[0]), checked(margins[1]),
|
checked(margins[0]), checked(margins[1]),
|
||||||
checked(margins[2]), checked(margins[3])}
|
checked(margins[2]), checked(margins[3])}
|
||||||
default:
|
default:
|
||||||
@@ -653,7 +787,6 @@ func parseMargin(margin string) [4]string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func parseOptions(opts *Options, allArgs []string) {
|
func parseOptions(opts *Options, allArgs []string) {
|
||||||
keymap := make(map[int]actionType)
|
|
||||||
var historyMax int
|
var historyMax int
|
||||||
if opts.History == nil {
|
if opts.History == nil {
|
||||||
historyMax = defaultHistoryMax
|
historyMax = defaultHistoryMax
|
||||||
@@ -676,17 +809,24 @@ func parseOptions(opts *Options, allArgs []string) {
|
|||||||
opts.History.maxSize = historyMax
|
opts.History.maxSize = historyMax
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
validateJumpLabels := false
|
||||||
for i := 0; i < len(allArgs); i++ {
|
for i := 0; i < len(allArgs); i++ {
|
||||||
arg := allArgs[i]
|
arg := allArgs[i]
|
||||||
switch arg {
|
switch arg {
|
||||||
case "-h", "--help":
|
case "-h", "--help":
|
||||||
help(exitOk)
|
help(exitOk)
|
||||||
case "-x", "--extended":
|
case "-x", "--extended":
|
||||||
opts.Mode = ModeExtended
|
opts.Extended = true
|
||||||
case "-e", "--extended-exact":
|
case "-e", "--exact":
|
||||||
opts.Mode = ModeExtendedExact
|
opts.Fuzzy = false
|
||||||
case "+x", "--no-extended", "+e", "--no-extended-exact":
|
case "--extended-exact":
|
||||||
opts.Mode = ModeFuzzy
|
// Note that we now don't have --no-extended-exact
|
||||||
|
opts.Fuzzy = false
|
||||||
|
opts.Extended = true
|
||||||
|
case "+x", "--no-extended":
|
||||||
|
opts.Extended = false
|
||||||
|
case "+e", "--no-exact":
|
||||||
|
opts.Fuzzy = true
|
||||||
case "-q", "--query":
|
case "-q", "--query":
|
||||||
opts.Query = nextString(allArgs, &i, "query string required")
|
opts.Query = nextString(allArgs, &i, "query string required")
|
||||||
case "-f", "--filter":
|
case "-f", "--filter":
|
||||||
@@ -695,20 +835,18 @@ func parseOptions(opts *Options, allArgs []string) {
|
|||||||
case "--expect":
|
case "--expect":
|
||||||
opts.Expect = parseKeyChords(nextString(allArgs, &i, "key names required"), "key names required")
|
opts.Expect = parseKeyChords(nextString(allArgs, &i, "key names required"), "key names required")
|
||||||
case "--tiebreak":
|
case "--tiebreak":
|
||||||
opts.Tiebreak = parseTiebreak(nextString(allArgs, &i, "sort criterion required"))
|
opts.Criteria = parseTiebreak(nextString(allArgs, &i, "sort criterion required"))
|
||||||
case "--bind":
|
case "--bind":
|
||||||
keymap, opts.Execmap, opts.ToggleSort =
|
parseKeymap(opts.Keymap, opts.Execmap, nextString(allArgs, &i, "bind expression required"))
|
||||||
parseKeymap(keymap, opts.Execmap, opts.ToggleSort, nextString(allArgs, &i, "bind expression required"))
|
|
||||||
case "--color":
|
case "--color":
|
||||||
spec := optionalNextString(allArgs, &i)
|
spec := optionalNextString(allArgs, &i)
|
||||||
if len(spec) == 0 {
|
if len(spec) == 0 {
|
||||||
opts.Theme = defaultTheme()
|
opts.Theme = curses.EmptyTheme()
|
||||||
} else {
|
} else {
|
||||||
opts.Theme = parseTheme(opts.Theme, spec)
|
opts.Theme = parseTheme(opts.Theme, spec)
|
||||||
}
|
}
|
||||||
case "--toggle-sort":
|
case "--toggle-sort":
|
||||||
keymap = checkToggleSort(keymap, nextString(allArgs, &i, "key name required"))
|
parseToggleSort(opts.Keymap, nextString(allArgs, &i, "key name required"))
|
||||||
opts.ToggleSort = true
|
|
||||||
case "-d", "--delimiter":
|
case "-d", "--delimiter":
|
||||||
opts.Delimiter = delimiterRegexp(nextString(allArgs, &i, "delimiter required"))
|
opts.Delimiter = delimiterRegexp(nextString(allArgs, &i, "delimiter required"))
|
||||||
case "-n", "--nth":
|
case "-n", "--nth":
|
||||||
@@ -757,10 +895,15 @@ func parseOptions(opts *Options, allArgs []string) {
|
|||||||
opts.Hscroll = true
|
opts.Hscroll = true
|
||||||
case "--no-hscroll":
|
case "--no-hscroll":
|
||||||
opts.Hscroll = false
|
opts.Hscroll = false
|
||||||
|
case "--hscroll-off":
|
||||||
|
opts.HscrollOff = nextInt(allArgs, &i, "hscroll offset required")
|
||||||
case "--inline-info":
|
case "--inline-info":
|
||||||
opts.InlineInfo = true
|
opts.InlineInfo = true
|
||||||
case "--no-inline-info":
|
case "--no-inline-info":
|
||||||
opts.InlineInfo = false
|
opts.InlineInfo = false
|
||||||
|
case "--jump-labels":
|
||||||
|
opts.JumpLabels = nextString(allArgs, &i, "label characters required")
|
||||||
|
validateJumpLabels = true
|
||||||
case "-1", "--select-1":
|
case "-1", "--select-1":
|
||||||
opts.Select1 = true
|
opts.Select1 = true
|
||||||
case "+1", "--no-select-1":
|
case "+1", "--no-select-1":
|
||||||
@@ -800,11 +943,20 @@ func parseOptions(opts *Options, allArgs []string) {
|
|||||||
case "--header-lines":
|
case "--header-lines":
|
||||||
opts.HeaderLines = atoi(
|
opts.HeaderLines = atoi(
|
||||||
nextString(allArgs, &i, "number of header lines required"))
|
nextString(allArgs, &i, "number of header lines required"))
|
||||||
|
case "--preview":
|
||||||
|
opts.Preview.command = nextString(allArgs, &i, "preview command required")
|
||||||
|
case "--no-preview":
|
||||||
|
opts.Preview.command = ""
|
||||||
|
case "--preview-window":
|
||||||
|
parsePreviewWindow(&opts.Preview,
|
||||||
|
nextString(allArgs, &i, "preview window layout required: [up|down|left|right][:SIZE[%]]"))
|
||||||
case "--no-margin":
|
case "--no-margin":
|
||||||
opts.Margin = defaultMargin()
|
opts.Margin = defaultMargin()
|
||||||
case "--margin":
|
case "--margin":
|
||||||
opts.Margin = parseMargin(
|
opts.Margin = parseMargin(
|
||||||
nextString(allArgs, &i, "margin required (TRBL / TB,RL / T,RL,B / T,R,B,L)"))
|
nextString(allArgs, &i, "margin required (TRBL / TB,RL / T,RL,B / T,R,B,L)"))
|
||||||
|
case "--tabstop":
|
||||||
|
opts.Tabstop = nextInt(allArgs, &i, "tab stop required")
|
||||||
case "--version":
|
case "--version":
|
||||||
opts.Version = true
|
opts.Version = true
|
||||||
default:
|
default:
|
||||||
@@ -823,17 +975,15 @@ func parseOptions(opts *Options, allArgs []string) {
|
|||||||
} else if match, _ := optString(arg, "-s", "--sort="); match {
|
} else if match, _ := optString(arg, "-s", "--sort="); match {
|
||||||
opts.Sort = 1 // Don't care
|
opts.Sort = 1 // Don't care
|
||||||
} else if match, value := optString(arg, "--toggle-sort="); match {
|
} else if match, value := optString(arg, "--toggle-sort="); match {
|
||||||
keymap = checkToggleSort(keymap, value)
|
parseToggleSort(opts.Keymap, value)
|
||||||
opts.ToggleSort = true
|
|
||||||
} else if match, value := optString(arg, "--expect="); match {
|
} else if match, value := optString(arg, "--expect="); match {
|
||||||
opts.Expect = parseKeyChords(value, "key names required")
|
opts.Expect = parseKeyChords(value, "key names required")
|
||||||
} else if match, value := optString(arg, "--tiebreak="); match {
|
} else if match, value := optString(arg, "--tiebreak="); match {
|
||||||
opts.Tiebreak = parseTiebreak(value)
|
opts.Criteria = parseTiebreak(value)
|
||||||
} else if match, value := optString(arg, "--color="); match {
|
} else if match, value := optString(arg, "--color="); match {
|
||||||
opts.Theme = parseTheme(opts.Theme, value)
|
opts.Theme = parseTheme(opts.Theme, value)
|
||||||
} else if match, value := optString(arg, "--bind="); match {
|
} else if match, value := optString(arg, "--bind="); match {
|
||||||
keymap, opts.Execmap, opts.ToggleSort =
|
parseKeymap(opts.Keymap, opts.Execmap, value)
|
||||||
parseKeymap(keymap, opts.Execmap, opts.ToggleSort, value)
|
|
||||||
} else if match, value := optString(arg, "--history="); match {
|
} else if match, value := optString(arg, "--history="); match {
|
||||||
setHistory(value)
|
setHistory(value)
|
||||||
} else if match, value := optString(arg, "--history-size="); match {
|
} else if match, value := optString(arg, "--history-size="); match {
|
||||||
@@ -842,8 +992,18 @@ func parseOptions(opts *Options, allArgs []string) {
|
|||||||
opts.Header = strLines(value)
|
opts.Header = strLines(value)
|
||||||
} else if match, value := optString(arg, "--header-lines="); match {
|
} else if match, value := optString(arg, "--header-lines="); match {
|
||||||
opts.HeaderLines = atoi(value)
|
opts.HeaderLines = atoi(value)
|
||||||
|
} else if match, value := optString(arg, "--preview="); match {
|
||||||
|
opts.Preview.command = value
|
||||||
|
} else if match, value := optString(arg, "--preview-window="); match {
|
||||||
|
parsePreviewWindow(&opts.Preview, value)
|
||||||
} else if match, value := optString(arg, "--margin="); match {
|
} else if match, value := optString(arg, "--margin="); match {
|
||||||
opts.Margin = parseMargin(value)
|
opts.Margin = parseMargin(value)
|
||||||
|
} else if match, value := optString(arg, "--tabstop="); match {
|
||||||
|
opts.Tabstop = atoi(value)
|
||||||
|
} else if match, value := optString(arg, "--hscroll-off="); match {
|
||||||
|
opts.HscrollOff = atoi(value)
|
||||||
|
} else if match, value := optString(arg, "--jump-labels="); match {
|
||||||
|
opts.JumpLabels = value
|
||||||
} else {
|
} else {
|
||||||
errorExit("unknown option: " + arg)
|
errorExit("unknown option: " + arg)
|
||||||
}
|
}
|
||||||
@@ -854,24 +1014,51 @@ func parseOptions(opts *Options, allArgs []string) {
|
|||||||
errorExit("header lines must be a non-negative integer")
|
errorExit("header lines must be a non-negative integer")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Change default actions for CTRL-N / CTRL-P when --history is used
|
if opts.HscrollOff < 0 {
|
||||||
if opts.History != nil {
|
errorExit("hscroll offset must be a non-negative integer")
|
||||||
if _, prs := keymap[curses.CtrlP]; !prs {
|
}
|
||||||
keymap[curses.CtrlP] = actPreviousHistory
|
|
||||||
|
if opts.Tabstop < 1 {
|
||||||
|
errorExit("tab stop must be a positive integer")
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(opts.JumpLabels) == 0 {
|
||||||
|
errorExit("empty jump labels")
|
||||||
|
}
|
||||||
|
|
||||||
|
if validateJumpLabels {
|
||||||
|
for _, r := range opts.JumpLabels {
|
||||||
|
if r < 32 || r > 126 {
|
||||||
|
errorExit("non-ascii jump labels are not allowed")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if _, prs := keymap[curses.CtrlN]; !prs {
|
|
||||||
keymap[curses.CtrlN] = actNextHistory
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Override default key bindings
|
func postProcessOptions(opts *Options) {
|
||||||
for key, act := range keymap {
|
// Default actions for CTRL-N / CTRL-P when --history is set
|
||||||
opts.Keymap[key] = act
|
if opts.History != nil {
|
||||||
|
if _, prs := opts.Keymap[curses.CtrlP]; !prs {
|
||||||
|
opts.Keymap[curses.CtrlP] = actPreviousHistory
|
||||||
}
|
}
|
||||||
|
if _, prs := opts.Keymap[curses.CtrlN]; !prs {
|
||||||
|
opts.Keymap[curses.CtrlN] = actNextHistory
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Extend the default key map
|
||||||
|
keymap := defaultKeymap()
|
||||||
|
for key, act := range opts.Keymap {
|
||||||
|
if act == actToggleSort {
|
||||||
|
opts.ToggleSort = true
|
||||||
|
}
|
||||||
|
keymap[key] = act
|
||||||
|
}
|
||||||
|
opts.Keymap = keymap
|
||||||
|
|
||||||
// If we're not using extended search mode, --nth option becomes irrelevant
|
// If we're not using extended search mode, --nth option becomes irrelevant
|
||||||
// if it contains the whole range
|
// if it contains the whole range
|
||||||
if opts.Mode == ModeFuzzy || len(opts.Nth) == 1 {
|
if !opts.Extended || len(opts.Nth) == 1 {
|
||||||
for _, r := range opts.Nth {
|
for _, r := range opts.Nth {
|
||||||
if r.begin == rangeEllipsis && r.end == rangeEllipsis {
|
if r.begin == rangeEllipsis && r.end == rangeEllipsis {
|
||||||
opts.Nth = make([]Range, 0)
|
opts.Nth = make([]Range, 0)
|
||||||
@@ -887,9 +1074,13 @@ func ParseOptions() *Options {
|
|||||||
|
|
||||||
// Options from Env var
|
// Options from Env var
|
||||||
words, _ := shellwords.Parse(os.Getenv("FZF_DEFAULT_OPTS"))
|
words, _ := shellwords.Parse(os.Getenv("FZF_DEFAULT_OPTS"))
|
||||||
|
if len(words) > 0 {
|
||||||
parseOptions(opts, words)
|
parseOptions(opts, words)
|
||||||
|
}
|
||||||
|
|
||||||
// Options from command-line arguments
|
// Options from command-line arguments
|
||||||
parseOptions(opts, os.Args[1:])
|
parseOptions(opts, os.Args[1:])
|
||||||
|
|
||||||
|
postProcessOptions(opts)
|
||||||
return opts
|
return opts
|
||||||
}
|
}
|
||||||
|
@@ -96,14 +96,16 @@ func TestIrrelevantNth(t *testing.T) {
|
|||||||
opts := defaultOptions()
|
opts := defaultOptions()
|
||||||
words := []string{"--nth", "..", "-x"}
|
words := []string{"--nth", "..", "-x"}
|
||||||
parseOptions(opts, words)
|
parseOptions(opts, words)
|
||||||
|
postProcessOptions(opts)
|
||||||
if len(opts.Nth) != 0 {
|
if len(opts.Nth) != 0 {
|
||||||
t.Errorf("nth should be empty: %s", opts.Nth)
|
t.Errorf("nth should be empty: %s", opts.Nth)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for _, words := range [][]string{[]string{"--nth", "..,3"}, []string{"--nth", "3,1.."}, []string{"--nth", "..-1,1"}} {
|
for _, words := range [][]string{[]string{"--nth", "..,3", "+x"}, []string{"--nth", "3,1..", "+x"}, []string{"--nth", "..-1,1", "+x"}} {
|
||||||
{
|
{
|
||||||
opts := defaultOptions()
|
opts := defaultOptions()
|
||||||
parseOptions(opts, words)
|
parseOptions(opts, words)
|
||||||
|
postProcessOptions(opts)
|
||||||
if len(opts.Nth) != 0 {
|
if len(opts.Nth) != 0 {
|
||||||
t.Errorf("nth should be empty: %s", opts.Nth)
|
t.Errorf("nth should be empty: %s", opts.Nth)
|
||||||
}
|
}
|
||||||
@@ -112,6 +114,7 @@ func TestIrrelevantNth(t *testing.T) {
|
|||||||
opts := defaultOptions()
|
opts := defaultOptions()
|
||||||
words = append(words, "-x")
|
words = append(words, "-x")
|
||||||
parseOptions(opts, words)
|
parseOptions(opts, words)
|
||||||
|
postProcessOptions(opts)
|
||||||
if len(opts.Nth) != 2 {
|
if len(opts.Nth) != 2 {
|
||||||
t.Errorf("nth should not be empty: %s", opts.Nth)
|
t.Errorf("nth should not be empty: %s", opts.Nth)
|
||||||
}
|
}
|
||||||
@@ -120,14 +123,14 @@ func TestIrrelevantNth(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestParseKeys(t *testing.T) {
|
func TestParseKeys(t *testing.T) {
|
||||||
pairs := parseKeyChords("ctrl-z,alt-z,f2,@,Alt-a,!,ctrl-G,J,g", "")
|
pairs := parseKeyChords("ctrl-z,alt-z,f2,@,Alt-a,!,ctrl-G,J,g,ALT-enter,alt-SPACE", "")
|
||||||
check := func(i int, s string) {
|
check := func(i int, s string) {
|
||||||
if pairs[i] != s {
|
if pairs[i] != s {
|
||||||
t.Errorf("%s != %s", pairs[i], s)
|
t.Errorf("%s != %s", pairs[i], s)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if len(pairs) != 9 {
|
if len(pairs) != 11 {
|
||||||
t.Error(9)
|
t.Error(11)
|
||||||
}
|
}
|
||||||
check(curses.CtrlZ, "ctrl-z")
|
check(curses.CtrlZ, "ctrl-z")
|
||||||
check(curses.AltZ, "alt-z")
|
check(curses.AltZ, "alt-z")
|
||||||
@@ -138,6 +141,8 @@ func TestParseKeys(t *testing.T) {
|
|||||||
check(curses.CtrlA+'g'-'a', "ctrl-G")
|
check(curses.CtrlA+'g'-'a', "ctrl-G")
|
||||||
check(curses.AltZ+'J', "J")
|
check(curses.AltZ+'J', "J")
|
||||||
check(curses.AltZ+'g', "g")
|
check(curses.AltZ+'g', "g")
|
||||||
|
check(curses.AltEnter, "ALT-enter")
|
||||||
|
check(curses.AltSpace, "alt-SPACE")
|
||||||
|
|
||||||
// Synonyms
|
// Synonyms
|
||||||
pairs = parseKeyChords("enter,Return,space,tab,btab,esc,up,down,left,right", "")
|
pairs = parseKeyChords("enter,Return,space,tab,btab,esc,up,down,left,right", "")
|
||||||
@@ -231,15 +236,11 @@ func TestBind(t *testing.T) {
|
|||||||
keymap := defaultKeymap()
|
keymap := defaultKeymap()
|
||||||
execmap := make(map[int]string)
|
execmap := make(map[int]string)
|
||||||
check(actBeginningOfLine, keymap[curses.CtrlA])
|
check(actBeginningOfLine, keymap[curses.CtrlA])
|
||||||
keymap, execmap, toggleSort :=
|
parseKeymap(keymap, execmap,
|
||||||
parseKeymap(keymap, execmap, false,
|
|
||||||
"ctrl-a:kill-line,ctrl-b:toggle-sort,c:page-up,alt-z:page-down,"+
|
"ctrl-a:kill-line,ctrl-b:toggle-sort,c:page-up,alt-z:page-down,"+
|
||||||
"f1:execute(ls {}),f2:execute/echo {}, {}, {}/,f3:execute[echo '({})'],f4:execute;less {};,"+
|
"f1:execute(ls {}),f2:execute/echo {}, {}, {}/,f3:execute[echo '({})'],f4:execute;less {};,"+
|
||||||
"alt-a:execute@echo (,),[,],/,:,;,%,{}@,alt-b:execute;echo (,),[,],/,:,@,%,{};"+
|
"alt-a:execute@echo (,),[,],/,:,;,%,{}@,alt-b:execute;echo (,),[,],/,:,@,%,{};"+
|
||||||
",,:abort,::accept,X:execute:\nfoobar,Y:execute(baz)")
|
",,:abort,::accept,X:execute:\nfoobar,Y:execute(baz)")
|
||||||
if !toggleSort {
|
|
||||||
t.Errorf("toggleSort not set")
|
|
||||||
}
|
|
||||||
check(actKillLine, keymap[curses.CtrlA])
|
check(actKillLine, keymap[curses.CtrlA])
|
||||||
check(actToggleSort, keymap[curses.CtrlB])
|
check(actToggleSort, keymap[curses.CtrlB])
|
||||||
check(actPageUp, keymap[curses.AltZ+'c'])
|
check(actPageUp, keymap[curses.AltZ+'c'])
|
||||||
@@ -259,15 +260,11 @@ func TestBind(t *testing.T) {
|
|||||||
checkString("\nfoobar,Y:execute(baz)", execmap[curses.AltZ+'X'])
|
checkString("\nfoobar,Y:execute(baz)", execmap[curses.AltZ+'X'])
|
||||||
|
|
||||||
for idx, char := range []rune{'~', '!', '@', '#', '$', '%', '^', '&', '*', '|', ';', '/'} {
|
for idx, char := range []rune{'~', '!', '@', '#', '$', '%', '^', '&', '*', '|', ';', '/'} {
|
||||||
keymap, execmap, toggleSort =
|
parseKeymap(keymap, execmap, fmt.Sprintf("%d:execute%cfoobar%c", idx%10, char, char))
|
||||||
parseKeymap(keymap, execmap, false, fmt.Sprintf("%d:execute%cfoobar%c", idx%10, char, char))
|
|
||||||
checkString("foobar", execmap[curses.AltZ+int([]rune(fmt.Sprintf("%d", idx%10))[0])])
|
checkString("foobar", execmap[curses.AltZ+int([]rune(fmt.Sprintf("%d", idx%10))[0])])
|
||||||
}
|
}
|
||||||
|
|
||||||
keymap, execmap, toggleSort = parseKeymap(keymap, execmap, false, "f1:abort")
|
parseKeymap(keymap, execmap, "f1:abort")
|
||||||
if toggleSort {
|
|
||||||
t.Errorf("toggleSort set")
|
|
||||||
}
|
|
||||||
check(actAbort, keymap[curses.F1])
|
check(actAbort, keymap[curses.F1])
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -328,3 +325,53 @@ func TestParseNilTheme(t *testing.T) {
|
|||||||
t.Errorf("color should now be enabled and customized")
|
t.Errorf("color should now be enabled and customized")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestDefaultCtrlNP(t *testing.T) {
|
||||||
|
check := func(words []string, key int, expected actionType) {
|
||||||
|
opts := defaultOptions()
|
||||||
|
parseOptions(opts, words)
|
||||||
|
postProcessOptions(opts)
|
||||||
|
if opts.Keymap[key] != expected {
|
||||||
|
t.Error()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
check([]string{}, curses.CtrlN, actDown)
|
||||||
|
check([]string{}, curses.CtrlP, actUp)
|
||||||
|
|
||||||
|
check([]string{"--bind=ctrl-n:accept"}, curses.CtrlN, actAccept)
|
||||||
|
check([]string{"--bind=ctrl-p:accept"}, curses.CtrlP, actAccept)
|
||||||
|
|
||||||
|
hist := "--history=/tmp/foo"
|
||||||
|
check([]string{hist}, curses.CtrlN, actNextHistory)
|
||||||
|
check([]string{hist}, curses.CtrlP, actPreviousHistory)
|
||||||
|
|
||||||
|
check([]string{hist, "--bind=ctrl-n:accept"}, curses.CtrlN, actAccept)
|
||||||
|
check([]string{hist, "--bind=ctrl-n:accept"}, curses.CtrlP, actPreviousHistory)
|
||||||
|
|
||||||
|
check([]string{hist, "--bind=ctrl-p:accept"}, curses.CtrlN, actNextHistory)
|
||||||
|
check([]string{hist, "--bind=ctrl-p:accept"}, curses.CtrlP, actAccept)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestToggle(t *testing.T) {
|
||||||
|
optsFor := func(words ...string) *Options {
|
||||||
|
opts := defaultOptions()
|
||||||
|
parseOptions(opts, words)
|
||||||
|
postProcessOptions(opts)
|
||||||
|
return opts
|
||||||
|
}
|
||||||
|
|
||||||
|
opts := optsFor()
|
||||||
|
if opts.ToggleSort {
|
||||||
|
t.Error()
|
||||||
|
}
|
||||||
|
|
||||||
|
opts = optsFor("--bind=a:toggle-sort")
|
||||||
|
if !opts.ToggleSort {
|
||||||
|
t.Error()
|
||||||
|
}
|
||||||
|
|
||||||
|
opts = optsFor("--bind=a:toggle-sort", "--bind=a:up")
|
||||||
|
if opts.ToggleSort {
|
||||||
|
t.Error()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
171
src/pattern.go
171
src/pattern.go
@@ -36,17 +36,20 @@ type term struct {
|
|||||||
origText []rune
|
origText []rune
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type termSet []term
|
||||||
|
|
||||||
// Pattern represents search pattern
|
// Pattern represents search pattern
|
||||||
type Pattern struct {
|
type Pattern struct {
|
||||||
mode Mode
|
fuzzy bool
|
||||||
|
extended bool
|
||||||
caseSensitive bool
|
caseSensitive bool
|
||||||
forward bool
|
forward bool
|
||||||
text []rune
|
text []rune
|
||||||
terms []term
|
termSets []termSet
|
||||||
hasInvTerm bool
|
cacheable bool
|
||||||
delimiter Delimiter
|
delimiter Delimiter
|
||||||
nth []Range
|
nth []Range
|
||||||
procFun map[termType]func(bool, bool, []rune, []rune) (int, int)
|
procFun map[termType]func(bool, bool, []rune, []rune) algo.Result
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -63,7 +66,7 @@ func init() {
|
|||||||
|
|
||||||
func clearPatternCache() {
|
func clearPatternCache() {
|
||||||
// We can uniquely identify the pattern for a given string since
|
// We can uniquely identify the pattern for a given string since
|
||||||
// mode and caseMode do not change while the program is running
|
// search mode and caseMode do not change while the program is running
|
||||||
_patternCache = make(map[string]*Pattern)
|
_patternCache = make(map[string]*Pattern)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -72,14 +75,13 @@ func clearChunkCache() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// BuildPattern builds Pattern object from the given arguments
|
// BuildPattern builds Pattern object from the given arguments
|
||||||
func BuildPattern(mode Mode, caseMode Case, forward bool,
|
func BuildPattern(fuzzy bool, extended bool, caseMode Case, forward bool,
|
||||||
nth []Range, delimiter Delimiter, runes []rune) *Pattern {
|
nth []Range, delimiter Delimiter, runes []rune) *Pattern {
|
||||||
|
|
||||||
var asString string
|
var asString string
|
||||||
switch mode {
|
if extended {
|
||||||
case ModeExtended, ModeExtendedExact:
|
|
||||||
asString = strings.Trim(string(runes), " ")
|
asString = strings.Trim(string(runes), " ")
|
||||||
default:
|
} else {
|
||||||
asString = string(runes)
|
asString = string(runes)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -88,18 +90,23 @@ func BuildPattern(mode Mode, caseMode Case, forward bool,
|
|||||||
return cached
|
return cached
|
||||||
}
|
}
|
||||||
|
|
||||||
caseSensitive, hasInvTerm := true, false
|
caseSensitive, cacheable := true, true
|
||||||
terms := []term{}
|
termSets := []termSet{}
|
||||||
|
|
||||||
switch mode {
|
if extended {
|
||||||
case ModeExtended, ModeExtendedExact:
|
termSets = parseTerms(fuzzy, caseMode, asString)
|
||||||
terms = parseTerms(mode, caseMode, asString)
|
Loop:
|
||||||
for _, term := range terms {
|
for _, termSet := range termSets {
|
||||||
if term.inv {
|
for idx, term := range termSet {
|
||||||
hasInvTerm = true
|
// If the query contains inverse search terms or OR operators,
|
||||||
|
// we cannot cache the search scope
|
||||||
|
if idx > 0 || term.inv {
|
||||||
|
cacheable = false
|
||||||
|
break Loop
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
default:
|
}
|
||||||
|
} else {
|
||||||
lowerString := strings.ToLower(asString)
|
lowerString := strings.ToLower(asString)
|
||||||
caseSensitive = caseMode == CaseRespect ||
|
caseSensitive = caseMode == CaseRespect ||
|
||||||
caseMode == CaseSmart && lowerString != asString
|
caseMode == CaseSmart && lowerString != asString
|
||||||
@@ -109,15 +116,16 @@ func BuildPattern(mode Mode, caseMode Case, forward bool,
|
|||||||
}
|
}
|
||||||
|
|
||||||
ptr := &Pattern{
|
ptr := &Pattern{
|
||||||
mode: mode,
|
fuzzy: fuzzy,
|
||||||
|
extended: extended,
|
||||||
caseSensitive: caseSensitive,
|
caseSensitive: caseSensitive,
|
||||||
forward: forward,
|
forward: forward,
|
||||||
text: []rune(asString),
|
text: []rune(asString),
|
||||||
terms: terms,
|
termSets: termSets,
|
||||||
hasInvTerm: hasInvTerm,
|
cacheable: cacheable,
|
||||||
nth: nth,
|
nth: nth,
|
||||||
delimiter: delimiter,
|
delimiter: delimiter,
|
||||||
procFun: make(map[termType]func(bool, bool, []rune, []rune) (int, int))}
|
procFun: make(map[termType]func(bool, bool, []rune, []rune) algo.Result)}
|
||||||
|
|
||||||
ptr.procFun[termFuzzy] = algo.FuzzyMatch
|
ptr.procFun[termFuzzy] = algo.FuzzyMatch
|
||||||
ptr.procFun[termEqual] = algo.EqualMatch
|
ptr.procFun[termEqual] = algo.EqualMatch
|
||||||
@@ -129,9 +137,11 @@ func BuildPattern(mode Mode, caseMode Case, forward bool,
|
|||||||
return ptr
|
return ptr
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseTerms(mode Mode, caseMode Case, str string) []term {
|
func parseTerms(fuzzy bool, caseMode Case, str string) []termSet {
|
||||||
tokens := _splitRegex.Split(str, -1)
|
tokens := _splitRegex.Split(str, -1)
|
||||||
terms := []term{}
|
sets := []termSet{}
|
||||||
|
set := termSet{}
|
||||||
|
switchSet := false
|
||||||
for _, token := range tokens {
|
for _, token := range tokens {
|
||||||
typ, inv, text := termFuzzy, false, token
|
typ, inv, text := termFuzzy, false, token
|
||||||
lowerText := strings.ToLower(text)
|
lowerText := strings.ToLower(text)
|
||||||
@@ -141,20 +151,26 @@ func parseTerms(mode Mode, caseMode Case, str string) []term {
|
|||||||
text = lowerText
|
text = lowerText
|
||||||
}
|
}
|
||||||
origText := []rune(text)
|
origText := []rune(text)
|
||||||
if mode == ModeExtendedExact {
|
if !fuzzy {
|
||||||
typ = termExact
|
typ = termExact
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if text == "|" {
|
||||||
|
switchSet = false
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
if strings.HasPrefix(text, "!") {
|
if strings.HasPrefix(text, "!") {
|
||||||
inv = true
|
inv = true
|
||||||
text = text[1:]
|
text = text[1:]
|
||||||
}
|
}
|
||||||
|
|
||||||
if strings.HasPrefix(text, "'") {
|
if strings.HasPrefix(text, "'") {
|
||||||
if mode == ModeExtended {
|
// Flip exactness
|
||||||
|
if fuzzy {
|
||||||
typ = termExact
|
typ = termExact
|
||||||
text = text[1:]
|
text = text[1:]
|
||||||
} else if mode == ModeExtendedExact {
|
} else {
|
||||||
typ = termFuzzy
|
typ = termFuzzy
|
||||||
text = text[1:]
|
text = text[1:]
|
||||||
}
|
}
|
||||||
@@ -172,23 +188,31 @@ func parseTerms(mode Mode, caseMode Case, str string) []term {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if len(text) > 0 {
|
if len(text) > 0 {
|
||||||
terms = append(terms, term{
|
if switchSet {
|
||||||
|
sets = append(sets, set)
|
||||||
|
set = termSet{}
|
||||||
|
}
|
||||||
|
set = append(set, term{
|
||||||
typ: typ,
|
typ: typ,
|
||||||
inv: inv,
|
inv: inv,
|
||||||
text: []rune(text),
|
text: []rune(text),
|
||||||
caseSensitive: caseSensitive,
|
caseSensitive: caseSensitive,
|
||||||
origText: origText})
|
origText: origText})
|
||||||
|
switchSet = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return terms
|
if len(set) > 0 {
|
||||||
|
sets = append(sets, set)
|
||||||
|
}
|
||||||
|
return sets
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsEmpty returns true if the pattern is effectively empty
|
// IsEmpty returns true if the pattern is effectively empty
|
||||||
func (p *Pattern) IsEmpty() bool {
|
func (p *Pattern) IsEmpty() bool {
|
||||||
if p.mode == ModeFuzzy {
|
if !p.extended {
|
||||||
return len(p.text) == 0
|
return len(p.text) == 0
|
||||||
}
|
}
|
||||||
return len(p.terms) == 0
|
return len(p.termSets) == 0
|
||||||
}
|
}
|
||||||
|
|
||||||
// AsString returns the search query in string type
|
// AsString returns the search query in string type
|
||||||
@@ -198,15 +222,14 @@ func (p *Pattern) AsString() string {
|
|||||||
|
|
||||||
// CacheKey is used to build string to be used as the key of result cache
|
// CacheKey is used to build string to be used as the key of result cache
|
||||||
func (p *Pattern) CacheKey() string {
|
func (p *Pattern) CacheKey() string {
|
||||||
if p.mode == ModeFuzzy {
|
if !p.extended {
|
||||||
return p.AsString()
|
return p.AsString()
|
||||||
}
|
}
|
||||||
cacheableTerms := []string{}
|
cacheableTerms := []string{}
|
||||||
for _, term := range p.terms {
|
for _, termSet := range p.termSets {
|
||||||
if term.inv {
|
if len(termSet) == 1 && !termSet[0].inv && (p.fuzzy || termSet[0].typ == termExact) {
|
||||||
continue
|
cacheableTerms = append(cacheableTerms, string(termSet[0].origText))
|
||||||
}
|
}
|
||||||
cacheableTerms = append(cacheableTerms, string(term.origText))
|
|
||||||
}
|
}
|
||||||
return strings.Join(cacheableTerms, " ")
|
return strings.Join(cacheableTerms, " ")
|
||||||
}
|
}
|
||||||
@@ -217,7 +240,7 @@ func (p *Pattern) Match(chunk *Chunk) []*Item {
|
|||||||
|
|
||||||
// ChunkCache: Exact match
|
// ChunkCache: Exact match
|
||||||
cacheKey := p.CacheKey()
|
cacheKey := p.CacheKey()
|
||||||
if !p.hasInvTerm { // Because we're excluding Inv-term from cache key
|
if p.cacheable {
|
||||||
if cached, found := _cache.Find(chunk, cacheKey); found {
|
if cached, found := _cache.Find(chunk, cacheKey); found {
|
||||||
return cached
|
return cached
|
||||||
}
|
}
|
||||||
@@ -242,7 +265,7 @@ Loop:
|
|||||||
|
|
||||||
matches := p.matchChunk(space)
|
matches := p.matchChunk(space)
|
||||||
|
|
||||||
if !p.hasInvTerm {
|
if p.cacheable {
|
||||||
_cache.Add(chunk, cacheKey, matches)
|
_cache.Add(chunk, cacheKey, matches)
|
||||||
}
|
}
|
||||||
return matches
|
return matches
|
||||||
@@ -250,17 +273,18 @@ Loop:
|
|||||||
|
|
||||||
func (p *Pattern) matchChunk(chunk *Chunk) []*Item {
|
func (p *Pattern) matchChunk(chunk *Chunk) []*Item {
|
||||||
matches := []*Item{}
|
matches := []*Item{}
|
||||||
if p.mode == ModeFuzzy {
|
if !p.extended {
|
||||||
for _, item := range *chunk {
|
for _, item := range *chunk {
|
||||||
if sidx, eidx, tlen := p.fuzzyMatch(item); sidx >= 0 {
|
offset, bonus := p.basicMatch(item)
|
||||||
|
if sidx := offset[0]; sidx >= 0 {
|
||||||
matches = append(matches,
|
matches = append(matches,
|
||||||
dupItem(item, []Offset{Offset{int32(sidx), int32(eidx), int32(tlen)}}))
|
dupItem(item, []Offset{offset}, bonus))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for _, item := range *chunk {
|
for _, item := range *chunk {
|
||||||
if offsets := p.extendedMatch(item); len(offsets) == len(p.terms) {
|
if offsets, bonus := p.extendedMatch(item); len(offsets) == len(p.termSets) {
|
||||||
matches = append(matches, dupItem(item, offsets))
|
matches = append(matches, dupItem(item, offsets, bonus))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -269,46 +293,62 @@ func (p *Pattern) matchChunk(chunk *Chunk) []*Item {
|
|||||||
|
|
||||||
// MatchItem returns true if the Item is a match
|
// MatchItem returns true if the Item is a match
|
||||||
func (p *Pattern) MatchItem(item *Item) bool {
|
func (p *Pattern) MatchItem(item *Item) bool {
|
||||||
if p.mode == ModeFuzzy {
|
if !p.extended {
|
||||||
sidx, _, _ := p.fuzzyMatch(item)
|
offset, _ := p.basicMatch(item)
|
||||||
|
sidx := offset[0]
|
||||||
return sidx >= 0
|
return sidx >= 0
|
||||||
}
|
}
|
||||||
offsets := p.extendedMatch(item)
|
offsets, _ := p.extendedMatch(item)
|
||||||
return len(offsets) == len(p.terms)
|
return len(offsets) == len(p.termSets)
|
||||||
}
|
}
|
||||||
|
|
||||||
func dupItem(item *Item, offsets []Offset) *Item {
|
func dupItem(item *Item, offsets []Offset, bonus int32) *Item {
|
||||||
sort.Sort(ByOrder(offsets))
|
sort.Sort(ByOrder(offsets))
|
||||||
return &Item{
|
return &Item{
|
||||||
text: item.text,
|
text: item.text,
|
||||||
origText: item.origText,
|
origText: item.origText,
|
||||||
transformed: item.transformed,
|
transformed: item.transformed,
|
||||||
index: item.index,
|
|
||||||
offsets: offsets,
|
offsets: offsets,
|
||||||
|
bonus: bonus,
|
||||||
colors: item.colors,
|
colors: item.colors,
|
||||||
rank: Rank{0, 0, item.index}}
|
rank: buildEmptyRank(item.Index())}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Pattern) fuzzyMatch(item *Item) (int, int, int) {
|
func (p *Pattern) basicMatch(item *Item) (Offset, int32) {
|
||||||
input := p.prepareInput(item)
|
input := p.prepareInput(item)
|
||||||
|
if p.fuzzy {
|
||||||
return p.iter(algo.FuzzyMatch, input, p.caseSensitive, p.forward, p.text)
|
return p.iter(algo.FuzzyMatch, input, p.caseSensitive, p.forward, p.text)
|
||||||
}
|
}
|
||||||
|
return p.iter(algo.ExactMatchNaive, input, p.caseSensitive, p.forward, p.text)
|
||||||
|
}
|
||||||
|
|
||||||
func (p *Pattern) extendedMatch(item *Item) []Offset {
|
func (p *Pattern) extendedMatch(item *Item) ([]Offset, int32) {
|
||||||
input := p.prepareInput(item)
|
input := p.prepareInput(item)
|
||||||
offsets := []Offset{}
|
offsets := []Offset{}
|
||||||
for _, term := range p.terms {
|
var totalBonus int32
|
||||||
|
for _, termSet := range p.termSets {
|
||||||
|
var offset *Offset
|
||||||
|
var bonus int32
|
||||||
|
for _, term := range termSet {
|
||||||
pfun := p.procFun[term.typ]
|
pfun := p.procFun[term.typ]
|
||||||
if sidx, eidx, tlen := p.iter(pfun, input, term.caseSensitive, p.forward, term.text); sidx >= 0 {
|
off, pen := p.iter(pfun, input, term.caseSensitive, p.forward, term.text)
|
||||||
|
if sidx := off[0]; sidx >= 0 {
|
||||||
if term.inv {
|
if term.inv {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
offset, bonus = &off, pen
|
||||||
break
|
break
|
||||||
}
|
|
||||||
offsets = append(offsets, Offset{int32(sidx), int32(eidx), int32(tlen)})
|
|
||||||
} else if term.inv {
|
} else if term.inv {
|
||||||
offsets = append(offsets, Offset{0, 0, 0})
|
offset, bonus = &Offset{0, 0, 0}, 0
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return offsets
|
if offset != nil {
|
||||||
|
offsets = append(offsets, *offset)
|
||||||
|
totalBonus += bonus
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return offsets, totalBonus
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Pattern) prepareInput(item *Item) []Token {
|
func (p *Pattern) prepareInput(item *Item) []Token {
|
||||||
@@ -327,13 +367,16 @@ func (p *Pattern) prepareInput(item *Item) []Token {
|
|||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Pattern) iter(pfun func(bool, bool, []rune, []rune) (int, int),
|
func (p *Pattern) iter(pfun func(bool, bool, []rune, []rune) algo.Result,
|
||||||
tokens []Token, caseSensitive bool, forward bool, pattern []rune) (int, int, int) {
|
tokens []Token, caseSensitive bool, forward bool, pattern []rune) (Offset, int32) {
|
||||||
for _, part := range tokens {
|
for _, part := range tokens {
|
||||||
prefixLength := part.prefixLength
|
prefixLength := int32(part.prefixLength)
|
||||||
if sidx, eidx := pfun(caseSensitive, forward, part.text, pattern); sidx >= 0 {
|
if res := pfun(caseSensitive, forward, part.text, pattern); res.Start >= 0 {
|
||||||
return sidx + prefixLength, eidx + prefixLength, part.trimLength
|
var sidx int32 = res.Start + prefixLength
|
||||||
|
var eidx int32 = res.End + prefixLength
|
||||||
|
return Offset{sidx, eidx, int32(part.trimLength)}, res.Bonus
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return -1, -1, -1 // math.MaxUint16
|
// TODO: math.MaxUint16
|
||||||
|
return Offset{-1, -1, -1}, 0.0
|
||||||
}
|
}
|
||||||
|
@@ -8,21 +8,26 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestParseTermsExtended(t *testing.T) {
|
func TestParseTermsExtended(t *testing.T) {
|
||||||
terms := parseTerms(ModeExtended, CaseSmart,
|
terms := parseTerms(true, CaseSmart,
|
||||||
"aaa 'bbb ^ccc ddd$ !eee !'fff !^ggg !hhh$ ^iii$")
|
"| aaa 'bbb ^ccc ddd$ !eee !'fff !^ggg !hhh$ | ^iii$ ^xxx | 'yyy | | zzz$ | !ZZZ |")
|
||||||
if len(terms) != 9 ||
|
if len(terms) != 9 ||
|
||||||
terms[0].typ != termFuzzy || terms[0].inv ||
|
terms[0][0].typ != termFuzzy || terms[0][0].inv ||
|
||||||
terms[1].typ != termExact || terms[1].inv ||
|
terms[1][0].typ != termExact || terms[1][0].inv ||
|
||||||
terms[2].typ != termPrefix || terms[2].inv ||
|
terms[2][0].typ != termPrefix || terms[2][0].inv ||
|
||||||
terms[3].typ != termSuffix || terms[3].inv ||
|
terms[3][0].typ != termSuffix || terms[3][0].inv ||
|
||||||
terms[4].typ != termFuzzy || !terms[4].inv ||
|
terms[4][0].typ != termFuzzy || !terms[4][0].inv ||
|
||||||
terms[5].typ != termExact || !terms[5].inv ||
|
terms[5][0].typ != termExact || !terms[5][0].inv ||
|
||||||
terms[6].typ != termPrefix || !terms[6].inv ||
|
terms[6][0].typ != termPrefix || !terms[6][0].inv ||
|
||||||
terms[7].typ != termSuffix || !terms[7].inv ||
|
terms[7][0].typ != termSuffix || !terms[7][0].inv ||
|
||||||
terms[8].typ != termEqual || terms[8].inv {
|
terms[7][1].typ != termEqual || terms[7][1].inv ||
|
||||||
|
terms[8][0].typ != termPrefix || terms[8][0].inv ||
|
||||||
|
terms[8][1].typ != termExact || terms[8][1].inv ||
|
||||||
|
terms[8][2].typ != termSuffix || terms[8][2].inv ||
|
||||||
|
terms[8][3].typ != termFuzzy || !terms[8][3].inv {
|
||||||
t.Errorf("%s", terms)
|
t.Errorf("%s", terms)
|
||||||
}
|
}
|
||||||
for idx, term := range terms {
|
for idx, termSet := range terms[:8] {
|
||||||
|
term := termSet[0]
|
||||||
if len(term.text) != 3 {
|
if len(term.text) != 3 {
|
||||||
t.Errorf("%s", term)
|
t.Errorf("%s", term)
|
||||||
}
|
}
|
||||||
@@ -30,26 +35,31 @@ func TestParseTermsExtended(t *testing.T) {
|
|||||||
t.Errorf("%s", term)
|
t.Errorf("%s", term)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
for _, term := range terms[8] {
|
||||||
|
if len(term.origText) != 4 {
|
||||||
|
t.Errorf("%s", term)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParseTermsExtendedExact(t *testing.T) {
|
func TestParseTermsExtendedExact(t *testing.T) {
|
||||||
terms := parseTerms(ModeExtendedExact, CaseSmart,
|
terms := parseTerms(false, CaseSmart,
|
||||||
"aaa 'bbb ^ccc ddd$ !eee !'fff !^ggg !hhh$")
|
"aaa 'bbb ^ccc ddd$ !eee !'fff !^ggg !hhh$")
|
||||||
if len(terms) != 8 ||
|
if len(terms) != 8 ||
|
||||||
terms[0].typ != termExact || terms[0].inv || len(terms[0].text) != 3 ||
|
terms[0][0].typ != termExact || terms[0][0].inv || len(terms[0][0].text) != 3 ||
|
||||||
terms[1].typ != termFuzzy || terms[1].inv || len(terms[1].text) != 3 ||
|
terms[1][0].typ != termFuzzy || terms[1][0].inv || len(terms[1][0].text) != 3 ||
|
||||||
terms[2].typ != termPrefix || terms[2].inv || len(terms[2].text) != 3 ||
|
terms[2][0].typ != termPrefix || terms[2][0].inv || len(terms[2][0].text) != 3 ||
|
||||||
terms[3].typ != termSuffix || terms[3].inv || len(terms[3].text) != 3 ||
|
terms[3][0].typ != termSuffix || terms[3][0].inv || len(terms[3][0].text) != 3 ||
|
||||||
terms[4].typ != termExact || !terms[4].inv || len(terms[4].text) != 3 ||
|
terms[4][0].typ != termExact || !terms[4][0].inv || len(terms[4][0].text) != 3 ||
|
||||||
terms[5].typ != termFuzzy || !terms[5].inv || len(terms[5].text) != 3 ||
|
terms[5][0].typ != termFuzzy || !terms[5][0].inv || len(terms[5][0].text) != 3 ||
|
||||||
terms[6].typ != termPrefix || !terms[6].inv || len(terms[6].text) != 3 ||
|
terms[6][0].typ != termPrefix || !terms[6][0].inv || len(terms[6][0].text) != 3 ||
|
||||||
terms[7].typ != termSuffix || !terms[7].inv || len(terms[7].text) != 3 {
|
terms[7][0].typ != termSuffix || !terms[7][0].inv || len(terms[7][0].text) != 3 {
|
||||||
t.Errorf("%s", terms)
|
t.Errorf("%s", terms)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParseTermsEmpty(t *testing.T) {
|
func TestParseTermsEmpty(t *testing.T) {
|
||||||
terms := parseTerms(ModeExtended, CaseSmart, "' $ ^ !' !^ !$")
|
terms := parseTerms(true, CaseSmart, "' $ ^ !' !^ !$")
|
||||||
if len(terms) != 0 {
|
if len(terms) != 0 {
|
||||||
t.Errorf("%s", terms)
|
t.Errorf("%s", terms)
|
||||||
}
|
}
|
||||||
@@ -58,25 +68,25 @@ func TestParseTermsEmpty(t *testing.T) {
|
|||||||
func TestExact(t *testing.T) {
|
func TestExact(t *testing.T) {
|
||||||
defer clearPatternCache()
|
defer clearPatternCache()
|
||||||
clearPatternCache()
|
clearPatternCache()
|
||||||
pattern := BuildPattern(ModeExtended, CaseSmart, true,
|
pattern := BuildPattern(true, true, CaseSmart, true,
|
||||||
[]Range{}, Delimiter{}, []rune("'abc"))
|
[]Range{}, Delimiter{}, []rune("'abc"))
|
||||||
sidx, eidx := algo.ExactMatchNaive(
|
res := algo.ExactMatchNaive(
|
||||||
pattern.caseSensitive, pattern.forward, []rune("aabbcc abc"), pattern.terms[0].text)
|
pattern.caseSensitive, pattern.forward, []rune("aabbcc abc"), pattern.termSets[0][0].text)
|
||||||
if sidx != 7 || eidx != 10 {
|
if res.Start != 7 || res.End != 10 {
|
||||||
t.Errorf("%s / %d / %d", pattern.terms, sidx, eidx)
|
t.Errorf("%s / %d / %d", pattern.termSets, res.Start, res.End)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEqual(t *testing.T) {
|
func TestEqual(t *testing.T) {
|
||||||
defer clearPatternCache()
|
defer clearPatternCache()
|
||||||
clearPatternCache()
|
clearPatternCache()
|
||||||
pattern := BuildPattern(ModeExtended, CaseSmart, true, []Range{}, Delimiter{}, []rune("^AbC$"))
|
pattern := BuildPattern(true, true, CaseSmart, true, []Range{}, Delimiter{}, []rune("^AbC$"))
|
||||||
|
|
||||||
match := func(str string, sidxExpected int, eidxExpected int) {
|
match := func(str string, sidxExpected int32, eidxExpected int32) {
|
||||||
sidx, eidx := algo.EqualMatch(
|
res := algo.EqualMatch(
|
||||||
pattern.caseSensitive, pattern.forward, []rune(str), pattern.terms[0].text)
|
pattern.caseSensitive, pattern.forward, []rune(str), pattern.termSets[0][0].text)
|
||||||
if sidx != sidxExpected || eidx != eidxExpected {
|
if res.Start != sidxExpected || res.End != eidxExpected {
|
||||||
t.Errorf("%s / %d / %d", pattern.terms, sidx, eidx)
|
t.Errorf("%s / %d / %d", pattern.termSets, res.Start, res.End)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
match("ABC", -1, -1)
|
match("ABC", -1, -1)
|
||||||
@@ -86,17 +96,17 @@ func TestEqual(t *testing.T) {
|
|||||||
func TestCaseSensitivity(t *testing.T) {
|
func TestCaseSensitivity(t *testing.T) {
|
||||||
defer clearPatternCache()
|
defer clearPatternCache()
|
||||||
clearPatternCache()
|
clearPatternCache()
|
||||||
pat1 := BuildPattern(ModeFuzzy, CaseSmart, true, []Range{}, Delimiter{}, []rune("abc"))
|
pat1 := BuildPattern(true, false, CaseSmart, true, []Range{}, Delimiter{}, []rune("abc"))
|
||||||
clearPatternCache()
|
clearPatternCache()
|
||||||
pat2 := BuildPattern(ModeFuzzy, CaseSmart, true, []Range{}, Delimiter{}, []rune("Abc"))
|
pat2 := BuildPattern(true, false, CaseSmart, true, []Range{}, Delimiter{}, []rune("Abc"))
|
||||||
clearPatternCache()
|
clearPatternCache()
|
||||||
pat3 := BuildPattern(ModeFuzzy, CaseIgnore, true, []Range{}, Delimiter{}, []rune("abc"))
|
pat3 := BuildPattern(true, false, CaseIgnore, true, []Range{}, Delimiter{}, []rune("abc"))
|
||||||
clearPatternCache()
|
clearPatternCache()
|
||||||
pat4 := BuildPattern(ModeFuzzy, CaseIgnore, true, []Range{}, Delimiter{}, []rune("Abc"))
|
pat4 := BuildPattern(true, false, CaseIgnore, true, []Range{}, Delimiter{}, []rune("Abc"))
|
||||||
clearPatternCache()
|
clearPatternCache()
|
||||||
pat5 := BuildPattern(ModeFuzzy, CaseRespect, true, []Range{}, Delimiter{}, []rune("abc"))
|
pat5 := BuildPattern(true, false, CaseRespect, true, []Range{}, Delimiter{}, []rune("abc"))
|
||||||
clearPatternCache()
|
clearPatternCache()
|
||||||
pat6 := BuildPattern(ModeFuzzy, CaseRespect, true, []Range{}, Delimiter{}, []rune("Abc"))
|
pat6 := BuildPattern(true, false, CaseRespect, true, []Range{}, Delimiter{}, []rune("Abc"))
|
||||||
|
|
||||||
if string(pat1.text) != "abc" || pat1.caseSensitive != false ||
|
if string(pat1.text) != "abc" || pat1.caseSensitive != false ||
|
||||||
string(pat2.text) != "Abc" || pat2.caseSensitive != true ||
|
string(pat2.text) != "Abc" || pat2.caseSensitive != true ||
|
||||||
@@ -109,19 +119,19 @@ func TestCaseSensitivity(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestOrigTextAndTransformed(t *testing.T) {
|
func TestOrigTextAndTransformed(t *testing.T) {
|
||||||
pattern := BuildPattern(ModeExtended, CaseSmart, true, []Range{}, Delimiter{}, []rune("jg"))
|
pattern := BuildPattern(true, true, CaseSmart, true, []Range{}, Delimiter{}, []rune("jg"))
|
||||||
tokens := Tokenize([]rune("junegunn"), Delimiter{})
|
tokens := Tokenize([]rune("junegunn"), Delimiter{})
|
||||||
trans := Transform(tokens, []Range{Range{1, 1}})
|
trans := Transform(tokens, []Range{Range{1, 1}})
|
||||||
|
|
||||||
origRunes := []rune("junegunn.choi")
|
origRunes := []rune("junegunn.choi")
|
||||||
for _, mode := range []Mode{ModeFuzzy, ModeExtended} {
|
for _, extended := range []bool{false, true} {
|
||||||
chunk := Chunk{
|
chunk := Chunk{
|
||||||
&Item{
|
&Item{
|
||||||
text: []rune("junegunn"),
|
text: []rune("junegunn"),
|
||||||
origText: &origRunes,
|
origText: &origRunes,
|
||||||
transformed: trans},
|
transformed: trans},
|
||||||
}
|
}
|
||||||
pattern.mode = mode
|
pattern.extended = extended
|
||||||
matches := pattern.matchChunk(&chunk)
|
matches := pattern.matchChunk(&chunk)
|
||||||
if string(matches[0].text) != "junegunn" || string(*matches[0].origText) != "junegunn.choi" ||
|
if string(matches[0].text) != "junegunn" || string(*matches[0].origText) != "junegunn.choi" ||
|
||||||
matches[0].offsets[0][0] != 0 || matches[0].offsets[0][1] != 5 ||
|
matches[0].offsets[0][0] != 0 || matches[0].offsets[0][1] != 5 ||
|
||||||
@@ -130,3 +140,25 @@ func TestOrigTextAndTransformed(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestCacheKey(t *testing.T) {
|
||||||
|
test := func(extended bool, patStr string, expected string, cacheable bool) {
|
||||||
|
pat := BuildPattern(true, extended, CaseSmart, true, []Range{}, Delimiter{}, []rune(patStr))
|
||||||
|
if pat.CacheKey() != expected {
|
||||||
|
t.Errorf("Expected: %s, actual: %s", expected, pat.CacheKey())
|
||||||
|
}
|
||||||
|
if pat.cacheable != cacheable {
|
||||||
|
t.Errorf("Expected: %s, actual: %s (%s)", cacheable, pat.cacheable, patStr)
|
||||||
|
}
|
||||||
|
clearPatternCache()
|
||||||
|
}
|
||||||
|
test(false, "foo !bar", "foo !bar", true)
|
||||||
|
test(false, "foo | bar !baz", "foo | bar !baz", true)
|
||||||
|
test(true, "foo bar baz", "foo bar baz", true)
|
||||||
|
test(true, "foo !bar", "foo", false)
|
||||||
|
test(true, "foo !bar baz", "foo baz", false)
|
||||||
|
test(true, "foo | bar baz", "baz", false)
|
||||||
|
test(true, "foo | bar | baz", "", false)
|
||||||
|
test(true, "foo | bar !baz", "", false)
|
||||||
|
test(true, "| | | foo", "foo", true)
|
||||||
|
}
|
||||||
|
@@ -4,7 +4,6 @@ import (
|
|||||||
"bufio"
|
"bufio"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
|
||||||
|
|
||||||
"github.com/junegunn/fzf/src/util"
|
"github.com/junegunn/fzf/src/util"
|
||||||
)
|
)
|
||||||
@@ -59,7 +58,7 @@ func (r *Reader) readFromStdin() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r *Reader) readFromCommand(cmd string) {
|
func (r *Reader) readFromCommand(cmd string) {
|
||||||
listCommand := exec.Command("sh", "-c", cmd)
|
listCommand := util.ExecCommand(cmd)
|
||||||
out, err := listCommand.StdoutPipe()
|
out, err := listCommand.StdoutPipe()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
|
517
src/terminal.go
517
src/terminal.go
@@ -4,11 +4,9 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"regexp"
|
"regexp"
|
||||||
"sort"
|
"sort"
|
||||||
"strconv"
|
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"syscall"
|
"syscall"
|
||||||
@@ -20,12 +18,22 @@ import (
|
|||||||
"github.com/junegunn/go-runewidth"
|
"github.com/junegunn/go-runewidth"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type jumpMode int
|
||||||
|
|
||||||
|
const (
|
||||||
|
jumpDisabled jumpMode = iota
|
||||||
|
jumpEnabled
|
||||||
|
jumpAcceptEnabled
|
||||||
|
)
|
||||||
|
|
||||||
// Terminal represents terminal input/output
|
// Terminal represents terminal input/output
|
||||||
type Terminal struct {
|
type Terminal struct {
|
||||||
|
initDelay time.Duration
|
||||||
inlineInfo bool
|
inlineInfo bool
|
||||||
prompt string
|
prompt string
|
||||||
reverse bool
|
reverse bool
|
||||||
hscroll bool
|
hscroll bool
|
||||||
|
hscrollOff int
|
||||||
cx int
|
cx int
|
||||||
cy int
|
cy int
|
||||||
offset int
|
offset int
|
||||||
@@ -44,14 +52,22 @@ type Terminal struct {
|
|||||||
header []string
|
header []string
|
||||||
header0 []string
|
header0 []string
|
||||||
ansi bool
|
ansi bool
|
||||||
margin [4]string
|
margin [4]sizeSpec
|
||||||
marginInt [4]int
|
window *C.Window
|
||||||
|
bwindow *C.Window
|
||||||
|
pwindow *C.Window
|
||||||
count int
|
count int
|
||||||
progress int
|
progress int
|
||||||
reading bool
|
reading bool
|
||||||
|
jumping jumpMode
|
||||||
|
jumpLabels string
|
||||||
merger *Merger
|
merger *Merger
|
||||||
selected map[uint32]selectedItem
|
selected map[int32]selectedItem
|
||||||
reqBox *util.EventBox
|
reqBox *util.EventBox
|
||||||
|
preview previewOpts
|
||||||
|
previewing bool
|
||||||
|
previewTxt string
|
||||||
|
previewBox *util.EventBox
|
||||||
eventBox *util.EventBox
|
eventBox *util.EventBox
|
||||||
mutex sync.Mutex
|
mutex sync.Mutex
|
||||||
initFunc func()
|
initFunc func()
|
||||||
@@ -66,6 +82,11 @@ type selectedItem struct {
|
|||||||
|
|
||||||
type byTimeOrder []selectedItem
|
type byTimeOrder []selectedItem
|
||||||
|
|
||||||
|
type previewRequest struct {
|
||||||
|
ok bool
|
||||||
|
str string
|
||||||
|
}
|
||||||
|
|
||||||
func (a byTimeOrder) Len() int {
|
func (a byTimeOrder) Len() int {
|
||||||
return len(a)
|
return len(a)
|
||||||
}
|
}
|
||||||
@@ -80,15 +101,20 @@ func (a byTimeOrder) Less(i, j int) bool {
|
|||||||
|
|
||||||
var _spinner = []string{`-`, `\`, `|`, `/`, `-`, `\`, `|`, `/`}
|
var _spinner = []string{`-`, `\`, `|`, `/`, `-`, `\`, `|`, `/`}
|
||||||
var _runeWidths = make(map[rune]int)
|
var _runeWidths = make(map[rune]int)
|
||||||
|
var _tabStop int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
reqPrompt util.EventType = iota
|
reqPrompt util.EventType = iota
|
||||||
reqInfo
|
reqInfo
|
||||||
reqHeader
|
reqHeader
|
||||||
reqList
|
reqList
|
||||||
|
reqJump
|
||||||
reqRefresh
|
reqRefresh
|
||||||
reqRedraw
|
reqRedraw
|
||||||
reqClose
|
reqClose
|
||||||
|
reqPrintQuery
|
||||||
|
reqPreviewEnqueue
|
||||||
|
reqPreviewDisplay
|
||||||
reqQuit
|
reqQuit
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -124,14 +150,21 @@ const (
|
|||||||
actToggleAll
|
actToggleAll
|
||||||
actToggleDown
|
actToggleDown
|
||||||
actToggleUp
|
actToggleUp
|
||||||
|
actToggleIn
|
||||||
|
actToggleOut
|
||||||
actDown
|
actDown
|
||||||
actUp
|
actUp
|
||||||
actPageUp
|
actPageUp
|
||||||
actPageDown
|
actPageDown
|
||||||
|
actJump
|
||||||
|
actJumpAccept
|
||||||
|
actPrintQuery
|
||||||
actToggleSort
|
actToggleSort
|
||||||
|
actTogglePreview
|
||||||
actPreviousHistory
|
actPreviousHistory
|
||||||
actNextHistory
|
actNextHistory
|
||||||
actExecute
|
actExecute
|
||||||
|
actExecuteMulti
|
||||||
)
|
)
|
||||||
|
|
||||||
func defaultKeymap() map[int]actionType {
|
func defaultKeymap() map[int]actionType {
|
||||||
@@ -180,6 +213,7 @@ func defaultKeymap() map[int]actionType {
|
|||||||
|
|
||||||
keymap[C.Rune] = actRune
|
keymap[C.Rune] = actRune
|
||||||
keymap[C.Mouse] = actMouse
|
keymap[C.Mouse] = actMouse
|
||||||
|
keymap[C.DoubleClick] = actAccept
|
||||||
return keymap
|
return keymap
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -192,11 +226,24 @@ func NewTerminal(opts *Options, eventBox *util.EventBox) *Terminal {
|
|||||||
} else {
|
} else {
|
||||||
header = reverseStringArray(opts.Header)
|
header = reverseStringArray(opts.Header)
|
||||||
}
|
}
|
||||||
|
_tabStop = opts.Tabstop
|
||||||
|
var delay time.Duration
|
||||||
|
if opts.Tac {
|
||||||
|
delay = initialDelayTac
|
||||||
|
} else {
|
||||||
|
delay = initialDelay
|
||||||
|
}
|
||||||
|
var previewBox *util.EventBox
|
||||||
|
if len(opts.Preview.command) > 0 {
|
||||||
|
previewBox = util.NewEventBox()
|
||||||
|
}
|
||||||
return &Terminal{
|
return &Terminal{
|
||||||
|
initDelay: delay,
|
||||||
inlineInfo: opts.InlineInfo,
|
inlineInfo: opts.InlineInfo,
|
||||||
prompt: opts.Prompt,
|
prompt: opts.Prompt,
|
||||||
reverse: opts.Reverse,
|
reverse: opts.Reverse,
|
||||||
hscroll: opts.Hscroll,
|
hscroll: opts.Hscroll,
|
||||||
|
hscrollOff: opts.HscrollOff,
|
||||||
cx: len(input),
|
cx: len(input),
|
||||||
cy: 0,
|
cy: 0,
|
||||||
offset: 0,
|
offset: 0,
|
||||||
@@ -212,15 +259,20 @@ func NewTerminal(opts *Options, eventBox *util.EventBox) *Terminal {
|
|||||||
printQuery: opts.PrintQuery,
|
printQuery: opts.PrintQuery,
|
||||||
history: opts.History,
|
history: opts.History,
|
||||||
margin: opts.Margin,
|
margin: opts.Margin,
|
||||||
marginInt: [4]int{0, 0, 0, 0},
|
|
||||||
cycle: opts.Cycle,
|
cycle: opts.Cycle,
|
||||||
header: header,
|
header: header,
|
||||||
header0: header,
|
header0: header,
|
||||||
ansi: opts.Ansi,
|
ansi: opts.Ansi,
|
||||||
reading: true,
|
reading: true,
|
||||||
|
jumping: jumpDisabled,
|
||||||
|
jumpLabels: opts.JumpLabels,
|
||||||
merger: EmptyMerger,
|
merger: EmptyMerger,
|
||||||
selected: make(map[uint32]selectedItem),
|
selected: make(map[int32]selectedItem),
|
||||||
reqBox: util.NewEventBox(),
|
reqBox: util.NewEventBox(),
|
||||||
|
preview: opts.Preview,
|
||||||
|
previewing: previewBox != nil && !opts.Preview.hidden,
|
||||||
|
previewTxt: "",
|
||||||
|
previewBox: previewBox,
|
||||||
eventBox: eventBox,
|
eventBox: eventBox,
|
||||||
mutex: sync.Mutex{},
|
mutex: sync.Mutex{},
|
||||||
suppress: true,
|
suppress: true,
|
||||||
@@ -300,25 +352,29 @@ func (t *Terminal) output() bool {
|
|||||||
if !found {
|
if !found {
|
||||||
cnt := t.merger.Length()
|
cnt := t.merger.Length()
|
||||||
if cnt > 0 && cnt > t.cy {
|
if cnt > 0 && cnt > t.cy {
|
||||||
fmt.Println(t.merger.Get(t.cy).AsString(t.ansi))
|
fmt.Println(t.current())
|
||||||
found = true
|
found = true
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
sels := make([]selectedItem, 0, len(t.selected))
|
for _, sel := range t.sortSelected() {
|
||||||
for _, sel := range t.selected {
|
|
||||||
sels = append(sels, sel)
|
|
||||||
}
|
|
||||||
sort.Sort(byTimeOrder(sels))
|
|
||||||
for _, sel := range sels {
|
|
||||||
fmt.Println(*sel.text)
|
fmt.Println(*sel.text)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return found
|
return found
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (t *Terminal) sortSelected() []selectedItem {
|
||||||
|
sels := make([]selectedItem, 0, len(t.selected))
|
||||||
|
for _, sel := range t.selected {
|
||||||
|
sels = append(sels, sel)
|
||||||
|
}
|
||||||
|
sort.Sort(byTimeOrder(sels))
|
||||||
|
return sels
|
||||||
|
}
|
||||||
|
|
||||||
func runeWidth(r rune, prefixWidth int) int {
|
func runeWidth(r rune, prefixWidth int) int {
|
||||||
if r == '\t' {
|
if r == '\t' {
|
||||||
return 8 - prefixWidth%8
|
return _tabStop - prefixWidth%_tabStop
|
||||||
} else if w, found := _runeWidths[r]; found {
|
} else if w, found := _runeWidths[r]; found {
|
||||||
return w
|
return w
|
||||||
} else {
|
} else {
|
||||||
@@ -336,83 +392,140 @@ func displayWidth(runes []rune) int {
|
|||||||
return l
|
return l
|
||||||
}
|
}
|
||||||
|
|
||||||
const minWidth = 16
|
const (
|
||||||
const minHeight = 4
|
minWidth = 16
|
||||||
|
minHeight = 4
|
||||||
|
)
|
||||||
|
|
||||||
func (t *Terminal) calculateMargins() {
|
func calculateSize(base int, size sizeSpec, margin int, minSize int) int {
|
||||||
|
max := base - margin
|
||||||
|
if size.percent {
|
||||||
|
return util.Constrain(int(float64(base)*0.01*size.size), minSize, max)
|
||||||
|
}
|
||||||
|
return util.Constrain(int(size.size), minSize, max)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *Terminal) resizeWindows() {
|
||||||
screenWidth := C.MaxX()
|
screenWidth := C.MaxX()
|
||||||
screenHeight := C.MaxY()
|
screenHeight := C.MaxY()
|
||||||
for idx, str := range t.margin {
|
marginInt := [4]int{}
|
||||||
if str == "0" {
|
for idx, sizeSpec := range t.margin {
|
||||||
t.marginInt[idx] = 0
|
if sizeSpec.percent {
|
||||||
} else if strings.HasSuffix(str, "%") {
|
var max float64
|
||||||
num, _ := strconv.ParseFloat(str[:len(str)-1], 64)
|
|
||||||
var val float64
|
|
||||||
if idx%2 == 0 {
|
if idx%2 == 0 {
|
||||||
val = float64(screenHeight)
|
max = float64(screenHeight)
|
||||||
} else {
|
} else {
|
||||||
val = float64(screenWidth)
|
max = float64(screenWidth)
|
||||||
}
|
}
|
||||||
t.marginInt[idx] = int(val * num * 0.01)
|
marginInt[idx] = int(max * sizeSpec.size * 0.01)
|
||||||
} else {
|
} else {
|
||||||
num, _ := strconv.Atoi(str)
|
marginInt[idx] = int(sizeSpec.size)
|
||||||
t.marginInt[idx] = num
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
adjust := func(idx1 int, idx2 int, max int, min int) {
|
adjust := func(idx1 int, idx2 int, max int, min int) {
|
||||||
if max >= min {
|
if max >= min {
|
||||||
margin := t.marginInt[idx1] + t.marginInt[idx2]
|
margin := marginInt[idx1] + marginInt[idx2]
|
||||||
if max-margin < min {
|
if max-margin < min {
|
||||||
desired := max - min
|
desired := max - min
|
||||||
t.marginInt[idx1] = desired * t.marginInt[idx1] / margin
|
marginInt[idx1] = desired * marginInt[idx1] / margin
|
||||||
t.marginInt[idx2] = desired * t.marginInt[idx2] / margin
|
marginInt[idx2] = desired * marginInt[idx2] / margin
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
adjust(1, 3, screenWidth, minWidth)
|
minAreaWidth := minWidth
|
||||||
adjust(0, 2, screenHeight, minHeight)
|
minAreaHeight := minHeight
|
||||||
|
if t.isPreviewEnabled() {
|
||||||
|
switch t.preview.position {
|
||||||
|
case posUp, posDown:
|
||||||
|
minAreaHeight *= 2
|
||||||
|
case posLeft, posRight:
|
||||||
|
minAreaWidth *= 2
|
||||||
|
}
|
||||||
|
}
|
||||||
|
adjust(1, 3, screenWidth, minAreaWidth)
|
||||||
|
adjust(0, 2, screenHeight, minAreaHeight)
|
||||||
|
if t.window != nil {
|
||||||
|
t.window.Close()
|
||||||
|
}
|
||||||
|
if t.bwindow != nil {
|
||||||
|
t.bwindow.Close()
|
||||||
|
t.pwindow.Close()
|
||||||
|
}
|
||||||
|
|
||||||
|
width := screenWidth - marginInt[1] - marginInt[3]
|
||||||
|
height := screenHeight - marginInt[0] - marginInt[2]
|
||||||
|
if t.isPreviewEnabled() {
|
||||||
|
createPreviewWindow := func(y int, x int, w int, h int) {
|
||||||
|
t.bwindow = C.NewWindow(y, x, w, h, true)
|
||||||
|
t.pwindow = C.NewWindow(y+1, x+2, w-4, h-2, false)
|
||||||
|
}
|
||||||
|
switch t.preview.position {
|
||||||
|
case posUp:
|
||||||
|
pheight := calculateSize(height, t.preview.size, minHeight, 3)
|
||||||
|
t.window = C.NewWindow(
|
||||||
|
marginInt[0]+pheight, marginInt[3], width, height-pheight, false)
|
||||||
|
createPreviewWindow(marginInt[0], marginInt[3], width, pheight)
|
||||||
|
case posDown:
|
||||||
|
pheight := calculateSize(height, t.preview.size, minHeight, 3)
|
||||||
|
t.window = C.NewWindow(
|
||||||
|
marginInt[0], marginInt[3], width, height-pheight, false)
|
||||||
|
createPreviewWindow(marginInt[0]+height-pheight, marginInt[3], width, pheight)
|
||||||
|
case posLeft:
|
||||||
|
pwidth := calculateSize(width, t.preview.size, minWidth, 5)
|
||||||
|
t.window = C.NewWindow(
|
||||||
|
marginInt[0], marginInt[3]+pwidth, width-pwidth, height, false)
|
||||||
|
createPreviewWindow(marginInt[0], marginInt[3], pwidth, height)
|
||||||
|
case posRight:
|
||||||
|
pwidth := calculateSize(width, t.preview.size, minWidth, 5)
|
||||||
|
t.window = C.NewWindow(
|
||||||
|
marginInt[0], marginInt[3], width-pwidth, height, false)
|
||||||
|
createPreviewWindow(marginInt[0], marginInt[3]+width-pwidth, pwidth, height)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
t.window = C.NewWindow(
|
||||||
|
marginInt[0],
|
||||||
|
marginInt[3],
|
||||||
|
width,
|
||||||
|
height, false)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Terminal) move(y int, x int, clear bool) {
|
func (t *Terminal) move(y int, x int, clear bool) {
|
||||||
x += t.marginInt[3]
|
|
||||||
maxy := C.MaxY()
|
|
||||||
if !t.reverse {
|
if !t.reverse {
|
||||||
y = maxy - y - 1 - t.marginInt[2]
|
y = t.window.Height - y - 1
|
||||||
} else {
|
|
||||||
y += t.marginInt[0]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if clear {
|
if clear {
|
||||||
C.MoveAndClear(y, x)
|
t.window.MoveAndClear(y, x)
|
||||||
} else {
|
} else {
|
||||||
C.Move(y, x)
|
t.window.Move(y, x)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Terminal) placeCursor() {
|
func (t *Terminal) placeCursor() {
|
||||||
t.move(0, len(t.prompt)+displayWidth(t.input[:t.cx]), false)
|
t.move(0, displayWidth([]rune(t.prompt))+displayWidth(t.input[:t.cx]), false)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Terminal) printPrompt() {
|
func (t *Terminal) printPrompt() {
|
||||||
t.move(0, 0, true)
|
t.move(0, 0, true)
|
||||||
C.CPrint(C.ColPrompt, true, t.prompt)
|
t.window.CPrint(C.ColPrompt, true, t.prompt)
|
||||||
C.CPrint(C.ColNormal, true, string(t.input))
|
t.window.CPrint(C.ColNormal, true, string(t.input))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Terminal) printInfo() {
|
func (t *Terminal) printInfo() {
|
||||||
if t.inlineInfo {
|
if t.inlineInfo {
|
||||||
t.move(0, len(t.prompt)+displayWidth(t.input)+1, true)
|
t.move(0, displayWidth([]rune(t.prompt))+displayWidth(t.input)+1, true)
|
||||||
if t.reading {
|
if t.reading {
|
||||||
C.CPrint(C.ColSpinner, true, " < ")
|
t.window.CPrint(C.ColSpinner, true, " < ")
|
||||||
} else {
|
} else {
|
||||||
C.CPrint(C.ColPrompt, true, " < ")
|
t.window.CPrint(C.ColPrompt, true, " < ")
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
t.move(1, 0, true)
|
t.move(1, 0, true)
|
||||||
if t.reading {
|
if t.reading {
|
||||||
duration := int64(spinnerDuration)
|
duration := int64(spinnerDuration)
|
||||||
idx := (time.Now().UnixNano() % (duration * int64(len(_spinner)))) / duration
|
idx := (time.Now().UnixNano() % (duration * int64(len(_spinner)))) / duration
|
||||||
C.CPrint(C.ColSpinner, true, _spinner[idx])
|
t.window.CPrint(C.ColSpinner, true, _spinner[idx])
|
||||||
}
|
}
|
||||||
t.move(1, 2, false)
|
t.move(1, 2, false)
|
||||||
}
|
}
|
||||||
@@ -431,18 +544,14 @@ func (t *Terminal) printInfo() {
|
|||||||
if t.progress > 0 && t.progress < 100 {
|
if t.progress > 0 && t.progress < 100 {
|
||||||
output += fmt.Sprintf(" (%d%%)", t.progress)
|
output += fmt.Sprintf(" (%d%%)", t.progress)
|
||||||
}
|
}
|
||||||
C.CPrint(C.ColInfo, false, output)
|
t.window.CPrint(C.ColInfo, false, output)
|
||||||
}
|
|
||||||
|
|
||||||
func (t *Terminal) maxHeight() int {
|
|
||||||
return C.MaxY() - t.marginInt[0] - t.marginInt[2]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Terminal) printHeader() {
|
func (t *Terminal) printHeader() {
|
||||||
if len(t.header) == 0 {
|
if len(t.header) == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
max := t.maxHeight()
|
max := t.window.Height
|
||||||
var state *ansiState
|
var state *ansiState
|
||||||
for idx, lineStr := range t.header {
|
for idx, lineStr := range t.header {
|
||||||
line := idx + 2
|
line := idx + 2
|
||||||
@@ -452,13 +561,12 @@ func (t *Terminal) printHeader() {
|
|||||||
if line >= max {
|
if line >= max {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
trimmed, colors, newState := extractColor(lineStr, state)
|
trimmed, colors, newState := extractColor(lineStr, state, nil)
|
||||||
state = newState
|
state = newState
|
||||||
item := &Item{
|
item := &Item{
|
||||||
text: []rune(trimmed),
|
text: []rune(trimmed),
|
||||||
index: 0,
|
|
||||||
colors: colors,
|
colors: colors,
|
||||||
rank: Rank{0, 0, 0}}
|
rank: buildEmptyRank(0)}
|
||||||
|
|
||||||
t.move(line, 2, true)
|
t.move(line, 2, true)
|
||||||
t.printHighlighted(item, false, C.ColHeader, 0, false)
|
t.printHighlighted(item, false, C.ColHeader, 0, false)
|
||||||
@@ -477,27 +585,36 @@ func (t *Terminal) printList() {
|
|||||||
}
|
}
|
||||||
t.move(line, 0, true)
|
t.move(line, 0, true)
|
||||||
if i < count {
|
if i < count {
|
||||||
t.printItem(t.merger.Get(i+t.offset), i == t.cy-t.offset)
|
t.printItem(t.merger.Get(i+t.offset), i, i == t.cy-t.offset)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Terminal) printItem(item *Item, current bool) {
|
func (t *Terminal) printItem(item *Item, i int, current bool) {
|
||||||
_, selected := t.selected[item.index]
|
_, selected := t.selected[item.Index()]
|
||||||
|
label := " "
|
||||||
|
if t.jumping != jumpDisabled {
|
||||||
|
if i < len(t.jumpLabels) {
|
||||||
|
// Striped
|
||||||
|
current = i%2 == 0
|
||||||
|
label = t.jumpLabels[i : i+1]
|
||||||
|
}
|
||||||
|
} else if current {
|
||||||
|
label = ">"
|
||||||
|
}
|
||||||
|
t.window.CPrint(C.ColCursor, true, label)
|
||||||
if current {
|
if current {
|
||||||
C.CPrint(C.ColCursor, true, ">")
|
|
||||||
if selected {
|
if selected {
|
||||||
C.CPrint(C.ColSelected, true, ">")
|
t.window.CPrint(C.ColSelected, true, ">")
|
||||||
} else {
|
} else {
|
||||||
C.CPrint(C.ColCurrent, true, " ")
|
t.window.CPrint(C.ColCurrent, true, " ")
|
||||||
}
|
}
|
||||||
t.printHighlighted(item, true, C.ColCurrent, C.ColCurrentMatch, true)
|
t.printHighlighted(item, true, C.ColCurrent, C.ColCurrentMatch, true)
|
||||||
} else {
|
} else {
|
||||||
C.CPrint(C.ColCursor, true, " ")
|
|
||||||
if selected {
|
if selected {
|
||||||
C.CPrint(C.ColSelected, true, ">")
|
t.window.CPrint(C.ColSelected, true, ">")
|
||||||
} else {
|
} else {
|
||||||
C.Print(" ")
|
t.window.Print(" ")
|
||||||
}
|
}
|
||||||
t.printHighlighted(item, false, 0, C.ColMatch, false)
|
t.printHighlighted(item, false, 0, C.ColMatch, false)
|
||||||
}
|
}
|
||||||
@@ -540,18 +657,17 @@ func trimLeft(runes []rune, width int) ([]rune, int32) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (t *Terminal) printHighlighted(item *Item, bold bool, col1 int, col2 int, current bool) {
|
func (t *Terminal) printHighlighted(item *Item, bold bool, col1 int, col2 int, current bool) {
|
||||||
var maxe int32
|
var maxe int
|
||||||
for _, offset := range item.offsets {
|
for _, offset := range item.offsets {
|
||||||
if offset[1] > maxe {
|
maxe = util.Max(maxe, int(offset[1]))
|
||||||
maxe = offset[1]
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Overflow
|
// Overflow
|
||||||
text := make([]rune, len(item.text))
|
text := make([]rune, len(item.text))
|
||||||
copy(text, item.text)
|
copy(text, item.text)
|
||||||
offsets := item.colorOffsets(col2, bold, current)
|
offsets := item.colorOffsets(col2, bold, current)
|
||||||
maxWidth := C.MaxX() - 3 - t.marginInt[1] - t.marginInt[3]
|
maxWidth := t.window.Width - 3
|
||||||
|
maxe = util.Constrain(maxe+util.Min(maxWidth/2-2, t.hscrollOff), 0, len(text))
|
||||||
fullWidth := displayWidth(text)
|
fullWidth := displayWidth(text)
|
||||||
if fullWidth > maxWidth {
|
if fullWidth > maxWidth {
|
||||||
if t.hscroll {
|
if t.hscroll {
|
||||||
@@ -600,11 +716,11 @@ func (t *Terminal) printHighlighted(item *Item, bold bool, col1 int, col2 int, c
|
|||||||
e := util.Constrain32(offset.offset[1], index, maxOffset)
|
e := util.Constrain32(offset.offset[1], index, maxOffset)
|
||||||
|
|
||||||
substr, prefixWidth = processTabs(text[index:b], prefixWidth)
|
substr, prefixWidth = processTabs(text[index:b], prefixWidth)
|
||||||
C.CPrint(col1, bold, substr)
|
t.window.CPrint(col1, bold, substr)
|
||||||
|
|
||||||
if b < e {
|
if b < e {
|
||||||
substr, prefixWidth = processTabs(text[b:e], prefixWidth)
|
substr, prefixWidth = processTabs(text[b:e], prefixWidth)
|
||||||
C.CPrint(offset.color, offset.bold, substr)
|
t.window.CPrint(offset.color, offset.bold, substr)
|
||||||
}
|
}
|
||||||
|
|
||||||
index = e
|
index = e
|
||||||
@@ -614,10 +730,20 @@ func (t *Terminal) printHighlighted(item *Item, bold bool, col1 int, col2 int, c
|
|||||||
}
|
}
|
||||||
if index < maxOffset {
|
if index < maxOffset {
|
||||||
substr, _ = processTabs(text[index:], prefixWidth)
|
substr, _ = processTabs(text[index:], prefixWidth)
|
||||||
C.CPrint(col1, bold, substr)
|
t.window.CPrint(col1, bold, substr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (t *Terminal) printPreview() {
|
||||||
|
t.pwindow.Erase()
|
||||||
|
extractColor(t.previewTxt, nil, func(str string, ansi *ansiState) bool {
|
||||||
|
if ansi != nil && ansi.colored() {
|
||||||
|
return t.pwindow.CFill(str, ansi.fg, ansi.bg, ansi.bold)
|
||||||
|
}
|
||||||
|
return t.pwindow.Fill(str)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func processTabs(runes []rune, prefixWidth int) (string, int) {
|
func processTabs(runes []rune, prefixWidth int) (string, int) {
|
||||||
var strbuf bytes.Buffer
|
var strbuf bytes.Buffer
|
||||||
l := prefixWidth
|
l := prefixWidth
|
||||||
@@ -634,16 +760,24 @@ func processTabs(runes []rune, prefixWidth int) (string, int) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (t *Terminal) printAll() {
|
func (t *Terminal) printAll() {
|
||||||
t.calculateMargins()
|
t.resizeWindows()
|
||||||
t.printList()
|
t.printList()
|
||||||
t.printPrompt()
|
t.printPrompt()
|
||||||
t.printInfo()
|
t.printInfo()
|
||||||
t.printHeader()
|
t.printHeader()
|
||||||
|
if t.isPreviewEnabled() {
|
||||||
|
t.printPreview()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Terminal) refresh() {
|
func (t *Terminal) refresh() {
|
||||||
if !t.suppress {
|
if !t.suppress {
|
||||||
C.Refresh()
|
if t.isPreviewEnabled() {
|
||||||
|
t.bwindow.Refresh()
|
||||||
|
t.pwindow.Refresh()
|
||||||
|
}
|
||||||
|
t.window.Refresh()
|
||||||
|
C.DoUpdate()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -694,41 +828,44 @@ func (t *Terminal) rubout(pattern string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func keyMatch(key int, event C.Event) bool {
|
func keyMatch(key int, event C.Event) bool {
|
||||||
return event.Type == key || event.Type == C.Rune && int(event.Char) == key-C.AltZ
|
return event.Type == key ||
|
||||||
|
event.Type == C.Rune && int(event.Char) == key-C.AltZ ||
|
||||||
|
event.Type == C.Mouse && key == C.DoubleClick && event.MouseEvent.Double
|
||||||
}
|
}
|
||||||
|
|
||||||
func executeCommand(template string, current string) {
|
func quoteEntry(entry string) string {
|
||||||
command := strings.Replace(template, "{}", fmt.Sprintf("%q", current), -1)
|
return "'" + strings.Replace(entry, "'", "'\\''", -1) + "'"
|
||||||
cmd := exec.Command("sh", "-c", command)
|
}
|
||||||
|
|
||||||
|
func (t *Terminal) executeCommand(template string, replacement string) {
|
||||||
|
command := strings.Replace(template, "{}", replacement, -1)
|
||||||
|
cmd := util.ExecCommand(command)
|
||||||
cmd.Stdin = os.Stdin
|
cmd.Stdin = os.Stdin
|
||||||
cmd.Stdout = os.Stdout
|
cmd.Stdout = os.Stdout
|
||||||
cmd.Stderr = os.Stderr
|
cmd.Stderr = os.Stderr
|
||||||
C.Endwin()
|
C.Endwin()
|
||||||
cmd.Run()
|
cmd.Run()
|
||||||
C.Refresh()
|
t.refresh()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *Terminal) hasPreviewWindow() bool {
|
||||||
|
return t.previewBox != nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *Terminal) isPreviewEnabled() bool {
|
||||||
|
return t.previewBox != nil && t.previewing
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *Terminal) current() string {
|
||||||
|
return t.merger.Get(t.cy).AsString(t.ansi)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Loop is called to start Terminal I/O
|
// Loop is called to start Terminal I/O
|
||||||
func (t *Terminal) Loop() {
|
func (t *Terminal) Loop() {
|
||||||
<-t.startChan
|
<-t.startChan
|
||||||
{ // Late initialization
|
{ // Late initialization
|
||||||
t.mutex.Lock()
|
|
||||||
t.initFunc()
|
|
||||||
t.calculateMargins()
|
|
||||||
t.printPrompt()
|
|
||||||
t.placeCursor()
|
|
||||||
C.Refresh()
|
|
||||||
t.printInfo()
|
|
||||||
t.printHeader()
|
|
||||||
t.mutex.Unlock()
|
|
||||||
go func() {
|
|
||||||
timer := time.NewTimer(initialDelay)
|
|
||||||
<-timer.C
|
|
||||||
t.reqBox.Set(reqRefresh, nil)
|
|
||||||
}()
|
|
||||||
|
|
||||||
intChan := make(chan os.Signal, 1)
|
intChan := make(chan os.Signal, 1)
|
||||||
signal.Notify(intChan, os.Interrupt, os.Kill)
|
signal.Notify(intChan, os.Interrupt, os.Kill, syscall.SIGTERM)
|
||||||
go func() {
|
go func() {
|
||||||
<-intChan
|
<-intChan
|
||||||
t.reqBox.Set(reqQuit, nil)
|
t.reqBox.Set(reqQuit, nil)
|
||||||
@@ -743,6 +880,21 @@ func (t *Terminal) Loop() {
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
t.mutex.Lock()
|
||||||
|
t.initFunc()
|
||||||
|
t.resizeWindows()
|
||||||
|
t.printPrompt()
|
||||||
|
t.placeCursor()
|
||||||
|
t.refresh()
|
||||||
|
t.printInfo()
|
||||||
|
t.printHeader()
|
||||||
|
t.mutex.Unlock()
|
||||||
|
go func() {
|
||||||
|
timer := time.NewTimer(t.initDelay)
|
||||||
|
<-timer.C
|
||||||
|
t.reqBox.Set(reqRefresh, nil)
|
||||||
|
}()
|
||||||
|
|
||||||
// Keep the spinner spinning
|
// Keep the spinner spinning
|
||||||
go func() {
|
go func() {
|
||||||
for {
|
for {
|
||||||
@@ -758,6 +910,31 @@ func (t *Terminal) Loop() {
|
|||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if t.hasPreviewWindow() {
|
||||||
|
go func() {
|
||||||
|
for {
|
||||||
|
request := previewRequest{false, ""}
|
||||||
|
t.previewBox.Wait(func(events *util.Events) {
|
||||||
|
for req, value := range *events {
|
||||||
|
switch req {
|
||||||
|
case reqPreviewEnqueue:
|
||||||
|
request = value.(previewRequest)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
events.Clear()
|
||||||
|
})
|
||||||
|
if request.ok {
|
||||||
|
command := strings.Replace(t.preview.command, "{}", quoteEntry(request.str), -1)
|
||||||
|
cmd := util.ExecCommand(command)
|
||||||
|
out, _ := cmd.CombinedOutput()
|
||||||
|
t.reqBox.Set(reqPreviewDisplay, string(out))
|
||||||
|
} else {
|
||||||
|
t.reqBox.Set(reqPreviewDisplay, "")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
|
||||||
exit := func(code int) {
|
exit := func(code int) {
|
||||||
if code <= exitNoMatch && t.history != nil {
|
if code <= exitNoMatch && t.history != nil {
|
||||||
t.history.append(string(t.input))
|
t.history.append(string(t.input))
|
||||||
@@ -766,11 +943,12 @@ func (t *Terminal) Loop() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
|
focused := previewRequest{false, ""}
|
||||||
for {
|
for {
|
||||||
t.reqBox.Wait(func(events *util.Events) {
|
t.reqBox.Wait(func(events *util.Events) {
|
||||||
defer events.Clear()
|
defer events.Clear()
|
||||||
t.mutex.Lock()
|
t.mutex.Lock()
|
||||||
for req := range *events {
|
for req, value := range *events {
|
||||||
switch req {
|
switch req {
|
||||||
case reqPrompt:
|
case reqPrompt:
|
||||||
t.printPrompt()
|
t.printPrompt()
|
||||||
@@ -781,6 +959,24 @@ func (t *Terminal) Loop() {
|
|||||||
t.printInfo()
|
t.printInfo()
|
||||||
case reqList:
|
case reqList:
|
||||||
t.printList()
|
t.printList()
|
||||||
|
cnt := t.merger.Length()
|
||||||
|
var currentFocus previewRequest
|
||||||
|
if cnt > 0 && cnt > t.cy {
|
||||||
|
currentFocus = previewRequest{true, t.current()}
|
||||||
|
} else {
|
||||||
|
currentFocus = previewRequest{false, ""}
|
||||||
|
}
|
||||||
|
if currentFocus != focused {
|
||||||
|
focused = currentFocus
|
||||||
|
if t.isPreviewEnabled() {
|
||||||
|
t.previewBox.Set(reqPreviewEnqueue, focused)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case reqJump:
|
||||||
|
if t.merger.Length() == 0 {
|
||||||
|
t.jumping = jumpDisabled
|
||||||
|
}
|
||||||
|
t.printList()
|
||||||
case reqHeader:
|
case reqHeader:
|
||||||
t.printHeader()
|
t.printHeader()
|
||||||
case reqRefresh:
|
case reqRefresh:
|
||||||
@@ -796,6 +992,13 @@ func (t *Terminal) Loop() {
|
|||||||
exit(exitOk)
|
exit(exitOk)
|
||||||
}
|
}
|
||||||
exit(exitNoMatch)
|
exit(exitNoMatch)
|
||||||
|
case reqPreviewDisplay:
|
||||||
|
t.previewTxt = value.(string)
|
||||||
|
t.printPreview()
|
||||||
|
case reqPrintQuery:
|
||||||
|
C.Close()
|
||||||
|
fmt.Println(string(t.input))
|
||||||
|
exit(exitOk)
|
||||||
case reqQuit:
|
case reqQuit:
|
||||||
C.Close()
|
C.Close()
|
||||||
exit(exitInterrupt)
|
exit(exitInterrupt)
|
||||||
@@ -824,8 +1027,8 @@ func (t *Terminal) Loop() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
selectItem := func(item *Item) bool {
|
selectItem := func(item *Item) bool {
|
||||||
if _, found := t.selected[item.index]; !found {
|
if _, found := t.selected[item.Index()]; !found {
|
||||||
t.selected[item.index] = selectedItem{time.Now(), item.StringPtr(t.ansi)}
|
t.selected[item.Index()] = selectedItem{time.Now(), item.StringPtr(t.ansi)}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
@@ -833,7 +1036,7 @@ func (t *Terminal) Loop() {
|
|||||||
toggleY := func(y int) {
|
toggleY := func(y int) {
|
||||||
item := t.merger.Get(y)
|
item := t.merger.Get(y)
|
||||||
if !selectItem(item) {
|
if !selectItem(item) {
|
||||||
delete(t.selected, item.index)
|
delete(t.selected, item.Index())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
toggle := func() {
|
toggle := func() {
|
||||||
@@ -850,35 +1053,51 @@ func (t *Terminal) Loop() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
action := t.keymap[event.Type]
|
var doAction func(actionType, int) bool
|
||||||
mapkey := event.Type
|
doAction = func(action actionType, mapkey int) bool {
|
||||||
if event.Type == C.Rune {
|
|
||||||
mapkey = int(event.Char) + int(C.AltZ)
|
|
||||||
if act, prs := t.keymap[mapkey]; prs {
|
|
||||||
action = act
|
|
||||||
}
|
|
||||||
}
|
|
||||||
switch action {
|
switch action {
|
||||||
case actIgnore:
|
case actIgnore:
|
||||||
case actExecute:
|
case actExecute:
|
||||||
if t.cy >= 0 && t.cy < t.merger.Length() {
|
if t.cy >= 0 && t.cy < t.merger.Length() {
|
||||||
item := t.merger.Get(t.cy)
|
item := t.merger.Get(t.cy)
|
||||||
executeCommand(t.execmap[mapkey], item.AsString(t.ansi))
|
t.executeCommand(t.execmap[mapkey], quoteEntry(item.AsString(t.ansi)))
|
||||||
|
}
|
||||||
|
case actExecuteMulti:
|
||||||
|
if len(t.selected) > 0 {
|
||||||
|
sels := make([]string, len(t.selected))
|
||||||
|
for i, sel := range t.sortSelected() {
|
||||||
|
sels[i] = quoteEntry(*sel.text)
|
||||||
|
}
|
||||||
|
t.executeCommand(t.execmap[mapkey], strings.Join(sels, " "))
|
||||||
|
} else {
|
||||||
|
return doAction(actExecute, mapkey)
|
||||||
}
|
}
|
||||||
case actInvalid:
|
case actInvalid:
|
||||||
t.mutex.Unlock()
|
t.mutex.Unlock()
|
||||||
continue
|
return false
|
||||||
|
case actTogglePreview:
|
||||||
|
if t.hasPreviewWindow() {
|
||||||
|
t.previewing = !t.previewing
|
||||||
|
t.resizeWindows()
|
||||||
|
cnt := t.merger.Length()
|
||||||
|
if t.previewing && cnt > 0 && cnt > t.cy {
|
||||||
|
t.previewBox.Set(reqPreviewEnqueue, previewRequest{true, t.current()})
|
||||||
|
}
|
||||||
|
req(reqList, reqInfo)
|
||||||
|
}
|
||||||
case actToggleSort:
|
case actToggleSort:
|
||||||
t.sort = !t.sort
|
t.sort = !t.sort
|
||||||
t.eventBox.Set(EvtSearchNew, t.sort)
|
t.eventBox.Set(EvtSearchNew, t.sort)
|
||||||
t.mutex.Unlock()
|
t.mutex.Unlock()
|
||||||
continue
|
return false
|
||||||
case actBeginningOfLine:
|
case actBeginningOfLine:
|
||||||
t.cx = 0
|
t.cx = 0
|
||||||
case actBackwardChar:
|
case actBackwardChar:
|
||||||
if t.cx > 0 {
|
if t.cx > 0 {
|
||||||
t.cx--
|
t.cx--
|
||||||
}
|
}
|
||||||
|
case actPrintQuery:
|
||||||
|
req(reqPrintQuery)
|
||||||
case actAbort:
|
case actAbort:
|
||||||
req(reqQuit)
|
req(reqQuit)
|
||||||
case actDeleteChar:
|
case actDeleteChar:
|
||||||
@@ -918,7 +1137,7 @@ func (t *Terminal) Loop() {
|
|||||||
if t.multi {
|
if t.multi {
|
||||||
for i := 0; i < t.merger.Length(); i++ {
|
for i := 0; i < t.merger.Length(); i++ {
|
||||||
item := t.merger.Get(i)
|
item := t.merger.Get(i)
|
||||||
delete(t.selected, item.index)
|
delete(t.selected, item.Index())
|
||||||
}
|
}
|
||||||
req(reqList, reqInfo)
|
req(reqList, reqInfo)
|
||||||
}
|
}
|
||||||
@@ -934,6 +1153,16 @@ func (t *Terminal) Loop() {
|
|||||||
}
|
}
|
||||||
req(reqList, reqInfo)
|
req(reqList, reqInfo)
|
||||||
}
|
}
|
||||||
|
case actToggleIn:
|
||||||
|
if t.reverse {
|
||||||
|
return doAction(actToggleUp, mapkey)
|
||||||
|
}
|
||||||
|
return doAction(actToggleDown, mapkey)
|
||||||
|
case actToggleOut:
|
||||||
|
if t.reverse {
|
||||||
|
return doAction(actToggleDown, mapkey)
|
||||||
|
}
|
||||||
|
return doAction(actToggleUp, mapkey)
|
||||||
case actToggleDown:
|
case actToggleDown:
|
||||||
if t.multi && t.merger.Length() > 0 {
|
if t.multi && t.merger.Length() > 0 {
|
||||||
toggle()
|
toggle()
|
||||||
@@ -980,6 +1209,12 @@ func (t *Terminal) Loop() {
|
|||||||
case actPageDown:
|
case actPageDown:
|
||||||
t.vmove(-(t.maxItems() - 1))
|
t.vmove(-(t.maxItems() - 1))
|
||||||
req(reqList)
|
req(reqList)
|
||||||
|
case actJump:
|
||||||
|
t.jumping = jumpEnabled
|
||||||
|
req(reqJump)
|
||||||
|
case actJumpAccept:
|
||||||
|
t.jumping = jumpAcceptEnabled
|
||||||
|
req(reqJump)
|
||||||
case actBackwardWord:
|
case actBackwardWord:
|
||||||
t.cx = findLastMatch("[^[:alnum:]][[:alnum:]]", string(t.input[:t.cx])) + 1
|
t.cx = findLastMatch("[^[:alnum:]][[:alnum:]]", string(t.input[:t.cx])) + 1
|
||||||
case actForwardWord:
|
case actForwardWord:
|
||||||
@@ -1017,20 +1252,19 @@ func (t *Terminal) Loop() {
|
|||||||
mx, my := me.X, me.Y
|
mx, my := me.X, me.Y
|
||||||
if me.S != 0 {
|
if me.S != 0 {
|
||||||
// Scroll
|
// Scroll
|
||||||
if t.merger.Length() > 0 {
|
if t.window.Enclose(my, mx) && t.merger.Length() > 0 {
|
||||||
if t.multi && me.Mod {
|
if t.multi && me.Mod {
|
||||||
toggle()
|
toggle()
|
||||||
}
|
}
|
||||||
t.vmove(me.S)
|
t.vmove(me.S)
|
||||||
req(reqList)
|
req(reqList)
|
||||||
}
|
}
|
||||||
} else if mx >= t.marginInt[3] && mx < C.MaxX()-t.marginInt[1] &&
|
} else if t.window.Enclose(my, mx) {
|
||||||
my >= t.marginInt[0] && my < C.MaxY()-t.marginInt[2] {
|
mx -= t.window.Left
|
||||||
mx -= t.marginInt[3]
|
my -= t.window.Top
|
||||||
my -= t.marginInt[0]
|
mx = util.Constrain(mx-displayWidth([]rune(t.prompt)), 0, len(t.input))
|
||||||
mx = util.Constrain(mx-len(t.prompt), 0, len(t.input))
|
|
||||||
if !t.reverse {
|
if !t.reverse {
|
||||||
my = t.maxHeight() - my - 1
|
my = t.window.Height - my - 1
|
||||||
}
|
}
|
||||||
min := 2 + len(t.header)
|
min := 2 + len(t.header)
|
||||||
if t.inlineInfo {
|
if t.inlineInfo {
|
||||||
@@ -1040,7 +1274,7 @@ func (t *Terminal) Loop() {
|
|||||||
// Double-click
|
// Double-click
|
||||||
if my >= min {
|
if my >= min {
|
||||||
if t.vset(t.offset+my-min) && t.cy < t.merger.Length() {
|
if t.vset(t.offset+my-min) && t.cy < t.merger.Length() {
|
||||||
req(reqClose)
|
return doAction(t.keymap[C.DoubleClick], C.DoubleClick)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if me.Down {
|
} else if me.Down {
|
||||||
@@ -1057,7 +1291,34 @@ func (t *Terminal) Loop() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
changed := string(previousInput) != string(t.input)
|
return true
|
||||||
|
}
|
||||||
|
changed := false
|
||||||
|
mapkey := event.Type
|
||||||
|
if t.jumping == jumpDisabled {
|
||||||
|
action := t.keymap[mapkey]
|
||||||
|
if mapkey == C.Rune {
|
||||||
|
mapkey = int(event.Char) + int(C.AltZ)
|
||||||
|
if act, prs := t.keymap[mapkey]; prs {
|
||||||
|
action = act
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !doAction(action, mapkey) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
changed = string(previousInput) != string(t.input)
|
||||||
|
} else {
|
||||||
|
if mapkey == C.Rune {
|
||||||
|
if idx := strings.IndexRune(t.jumpLabels, event.Char); idx >= 0 && idx < t.maxItems() && idx < t.merger.Length() {
|
||||||
|
t.cy = idx + t.offset
|
||||||
|
if t.jumping == jumpAcceptEnabled {
|
||||||
|
req(reqClose)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
t.jumping = jumpDisabled
|
||||||
|
req(reqList)
|
||||||
|
}
|
||||||
t.mutex.Unlock() // Must be unlocked before touching reqBox
|
t.mutex.Unlock() // Must be unlocked before touching reqBox
|
||||||
|
|
||||||
if changed {
|
if changed {
|
||||||
@@ -1075,15 +1336,7 @@ func (t *Terminal) constrain() {
|
|||||||
diffpos := t.cy - t.offset
|
diffpos := t.cy - t.offset
|
||||||
|
|
||||||
t.cy = util.Constrain(t.cy, 0, count-1)
|
t.cy = util.Constrain(t.cy, 0, count-1)
|
||||||
|
t.offset = util.Constrain(t.offset, t.cy-height+1, t.cy)
|
||||||
if t.cy > t.offset+(height-1) {
|
|
||||||
// Ceil
|
|
||||||
t.offset = t.cy - (height - 1)
|
|
||||||
} else if t.offset > t.cy {
|
|
||||||
// Floor
|
|
||||||
t.offset = t.cy
|
|
||||||
}
|
|
||||||
|
|
||||||
// Adjustment
|
// Adjustment
|
||||||
if count-t.offset < height {
|
if count-t.offset < height {
|
||||||
t.offset = util.Max(0, count-height)
|
t.offset = util.Max(0, count-height)
|
||||||
@@ -1118,7 +1371,7 @@ func (t *Terminal) vset(o int) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (t *Terminal) maxItems() int {
|
func (t *Terminal) maxItems() int {
|
||||||
max := t.maxHeight() - 2 - len(t.header)
|
max := t.window.Height - 2 - len(t.header)
|
||||||
if t.inlineInfo {
|
if t.inlineInfo {
|
||||||
max++
|
max++
|
||||||
}
|
}
|
||||||
|
@@ -5,6 +5,7 @@ import "C"
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
"os/exec"
|
||||||
"time"
|
"time"
|
||||||
"unicode/utf8"
|
"unicode/utf8"
|
||||||
)
|
)
|
||||||
@@ -20,6 +21,14 @@ func Max(first int, items ...int) int {
|
|||||||
return max
|
return max
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Min returns the smallest integer
|
||||||
|
func Min(first int, second int) int {
|
||||||
|
if first <= second {
|
||||||
|
return first
|
||||||
|
}
|
||||||
|
return second
|
||||||
|
}
|
||||||
|
|
||||||
// Min32 returns the smallest 32-bit integer
|
// Min32 returns the smallest 32-bit integer
|
||||||
func Min32(first int32, second int32) int32 {
|
func Min32(first int32, second int32) int32 {
|
||||||
if first <= second {
|
if first <= second {
|
||||||
@@ -126,3 +135,12 @@ func TrimLen(runes []rune) int {
|
|||||||
}
|
}
|
||||||
return i - j + 1
|
return i - j + 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ExecCommand executes the given command with $SHELL
|
||||||
|
func ExecCommand(command string) *exec.Cmd {
|
||||||
|
shell := os.Getenv("SHELL")
|
||||||
|
if len(shell) == 0 {
|
||||||
|
shell = "sh"
|
||||||
|
}
|
||||||
|
return exec.Command(shell, "-c", command)
|
||||||
|
}
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
Execute (Setup):
|
Execute (Setup):
|
||||||
let g:dir = fnamemodify(g:vader_file, ':p:h')
|
let g:dir = fnamemodify(g:vader_file, ':p:h')
|
||||||
Log 'Test directory: ' . g:dir
|
Log 'Test directory: ' . g:dir
|
||||||
|
Save &acd
|
||||||
|
|
||||||
Execute (fzf#run with dir option):
|
Execute (fzf#run with dir option):
|
||||||
let cwd = getcwd()
|
let cwd = getcwd()
|
||||||
@@ -35,6 +36,39 @@ Execute (fzf#run with string source):
|
|||||||
let result = sort(fzf#run({ 'source': 'echo hi', 'options': '-f i' }))
|
let result = sort(fzf#run({ 'source': 'echo hi', 'options': '-f i' }))
|
||||||
AssertEqual ['hi'], result
|
AssertEqual ['hi'], result
|
||||||
|
|
||||||
|
Execute (fzf#run with dir option and noautochdir):
|
||||||
|
set noacd
|
||||||
|
let cwd = getcwd()
|
||||||
|
call fzf#run({'source': ['/foobar'], 'sink': 'e', 'dir': '/tmp', 'options': '-1'})
|
||||||
|
" No change in working directory
|
||||||
|
AssertEqual cwd, getcwd()
|
||||||
|
|
||||||
|
call fzf#run({'source': ['/foobar'], 'sink': 'tabe', 'dir': '/tmp', 'options': '-1'})
|
||||||
|
AssertEqual cwd, getcwd()
|
||||||
|
tabclose
|
||||||
|
AssertEqual cwd, getcwd()
|
||||||
|
|
||||||
|
Execute (Incomplete fzf#run with dir option and autochdir):
|
||||||
|
set acd
|
||||||
|
let cwd = getcwd()
|
||||||
|
call fzf#run({'source': [], 'sink': 'e', 'dir': '/tmp', 'options': '-0'})
|
||||||
|
" No change in working directory even if &acd is set
|
||||||
|
AssertEqual cwd, getcwd()
|
||||||
|
|
||||||
|
Execute (fzf#run with dir option and autochdir):
|
||||||
|
set acd
|
||||||
|
let cwd = getcwd()
|
||||||
|
call fzf#run({'source': ['/foobar'], 'sink': 'e', 'dir': '/tmp', 'options': '-1'})
|
||||||
|
" Working directory changed due to &acd
|
||||||
|
AssertEqual '/', getcwd()
|
||||||
|
|
||||||
|
Execute (fzf#run with dir option and autochdir when final cwd is same as dir):
|
||||||
|
set acd
|
||||||
|
cd /tmp
|
||||||
|
call fzf#run({'source': ['/foobar'], 'sink': 'e', 'dir': '/', 'options': '-1'})
|
||||||
|
" Working directory changed due to &acd
|
||||||
|
AssertEqual '/', getcwd()
|
||||||
|
|
||||||
Execute (Cleanup):
|
Execute (Cleanup):
|
||||||
unlet g:dir
|
unlet g:dir
|
||||||
Restore
|
Restore
|
||||||
|
607
test/test_go.rb
607
test/test_go.rb
@@ -6,9 +6,10 @@ require 'fileutils'
|
|||||||
|
|
||||||
DEFAULT_TIMEOUT = 20
|
DEFAULT_TIMEOUT = 20
|
||||||
|
|
||||||
|
FILE = File.expand_path(__FILE__)
|
||||||
base = File.expand_path('../../', __FILE__)
|
base = File.expand_path('../../', __FILE__)
|
||||||
Dir.chdir base
|
Dir.chdir base
|
||||||
FZF = "#{base}/bin/fzf"
|
FZF = "FZF_DEFAULT_OPTS= FZF_DEFAULT_COMMAND= #{base}/bin/fzf"
|
||||||
|
|
||||||
class NilClass
|
class NilClass
|
||||||
def include? str
|
def include? str
|
||||||
@@ -30,7 +31,7 @@ def wait
|
|||||||
return if yield
|
return if yield
|
||||||
sleep 0.05
|
sleep 0.05
|
||||||
end
|
end
|
||||||
throw 'timeout'
|
raise 'timeout'
|
||||||
end
|
end
|
||||||
|
|
||||||
class Shell
|
class Shell
|
||||||
@@ -89,6 +90,10 @@ class Tmux
|
|||||||
go("send-keys -t #{target} #{args}")
|
go("send-keys -t #{target} #{args}")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def paste str
|
||||||
|
%x[tmux setb '#{str.gsub("'", "'\\''")}' \\; pasteb -t #{win} \\; send-keys -t #{win} Enter]
|
||||||
|
end
|
||||||
|
|
||||||
def capture pane = 0
|
def capture pane = 0
|
||||||
File.unlink TEMPNAME while File.exists? TEMPNAME
|
File.unlink TEMPNAME while File.exists? TEMPNAME
|
||||||
wait do
|
wait do
|
||||||
@@ -142,8 +147,10 @@ class TestBase < Minitest::Test
|
|||||||
attr_reader :tmux
|
attr_reader :tmux
|
||||||
|
|
||||||
def tempname
|
def tempname
|
||||||
|
@temp_suffix ||= 0
|
||||||
[TEMPNAME,
|
[TEMPNAME,
|
||||||
caller_locations.map(&:label).find { |l| l =~ /^test_/ }].join '-'
|
caller_locations.map(&:label).find { |l| l =~ /^test_/ },
|
||||||
|
@temp_suffix].join '-'
|
||||||
end
|
end
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
@@ -157,6 +164,7 @@ class TestBase < Minitest::Test
|
|||||||
File.read(tempname)
|
File.read(tempname)
|
||||||
ensure
|
ensure
|
||||||
File.unlink tempname while File.exists?(tempname)
|
File.unlink tempname while File.exists?(tempname)
|
||||||
|
@temp_suffix += 1
|
||||||
tmux.prepare
|
tmux.prepare
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -203,17 +211,17 @@ class TestGoFZF < TestBase
|
|||||||
tmux.send_keys '99', 'C-a', '1', 'C-f', '3', 'C-b', 'C-h', 'C-u', 'C-e', 'C-y', 'C-k', 'Tab', 'BTab'
|
tmux.send_keys '99', 'C-a', '1', 'C-f', '3', 'C-b', 'C-h', 'C-u', 'C-e', 'C-y', 'C-k', 'Tab', 'BTab'
|
||||||
tmux.until { |lines| lines[-2] == ' 856/100000' }
|
tmux.until { |lines| lines[-2] == ' 856/100000' }
|
||||||
lines = tmux.capture
|
lines = tmux.capture
|
||||||
assert_equal '> 1391', lines[-4]
|
assert_equal '> 3910', lines[-4]
|
||||||
assert_equal ' 391', lines[-3]
|
assert_equal ' 391', lines[-3]
|
||||||
assert_equal ' 856/100000', lines[-2]
|
assert_equal ' 856/100000', lines[-2]
|
||||||
assert_equal '> 391', lines[-1]
|
assert_equal '> 391', lines[-1]
|
||||||
|
|
||||||
tmux.send_keys :Enter
|
tmux.send_keys :Enter
|
||||||
assert_equal '1391', readonce.chomp
|
assert_equal '3910', readonce.chomp
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_fzf_default_command
|
def test_fzf_default_command
|
||||||
tmux.send_keys "FZF_DEFAULT_COMMAND='echo hello' #{fzf}", :Enter
|
tmux.send_keys fzf.sub('FZF_DEFAULT_COMMAND=', "FZF_DEFAULT_COMMAND='echo hello'"), :Enter
|
||||||
tmux.until { |lines| lines.last =~ /^>/ }
|
tmux.until { |lines| lines.last =~ /^>/ }
|
||||||
|
|
||||||
tmux.send_keys :Enter
|
tmux.send_keys :Enter
|
||||||
@@ -353,12 +361,12 @@ class TestGoFZF < TestBase
|
|||||||
tmux.send_keys :BTab, :BTab, :BTab
|
tmux.send_keys :BTab, :BTab, :BTab
|
||||||
tmux.until { |lines| lines[-2].include?('(3)') }
|
tmux.until { |lines| lines[-2].include?('(3)') }
|
||||||
tmux.send_keys :Enter
|
tmux.send_keys :Enter
|
||||||
assert_equal ['5', '5', '15', '25'], readonce.split($/)
|
assert_equal ['5', '5', '50', '51'], readonce.split($/)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_query_unicode
|
def test_query_unicode
|
||||||
tmux.send_keys "(echo abc; echo 가나다) | #{fzf :query, '가다'}", :Enter
|
tmux.paste "(echo abc; echo 가나다) | #{fzf :query, '가다'}"
|
||||||
tmux.until { |lines| lines[-2].include? '1/2' }
|
tmux.until { |lines| lines[-2].include? '1/2' }
|
||||||
tmux.send_keys :Enter
|
tmux.send_keys :Enter
|
||||||
assert_equal ['가나다'], readonce.split($/)
|
assert_equal ['가나다'], readonce.split($/)
|
||||||
@@ -374,7 +382,7 @@ class TestGoFZF < TestBase
|
|||||||
tmux.send_keys :Enter
|
tmux.send_keys :Enter
|
||||||
tmux.until { |lines| lines[-1] == '>' }
|
tmux.until { |lines| lines[-1] == '>' }
|
||||||
tmux.send_keys 'C-K', :Enter
|
tmux.send_keys 'C-K', :Enter
|
||||||
assert_equal ['1919'], readonce.split($/)
|
assert_equal ['9090'], readonce.split($/)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_tac
|
def test_tac
|
||||||
@@ -390,6 +398,7 @@ class TestGoFZF < TestBase
|
|||||||
tmux.send_keys "seq 1 1000 | #{fzf :tac, :multi}", :Enter
|
tmux.send_keys "seq 1 1000 | #{fzf :tac, :multi}", :Enter
|
||||||
tmux.until { |lines| lines[-2].include? '1000/1000' }
|
tmux.until { |lines| lines[-2].include? '1000/1000' }
|
||||||
tmux.send_keys '99'
|
tmux.send_keys '99'
|
||||||
|
tmux.until { |lines| lines[-2].include? '28/1000' }
|
||||||
tmux.send_keys :BTab, :BTab, :BTab
|
tmux.send_keys :BTab, :BTab, :BTab
|
||||||
tmux.until { |lines| lines[-2].include?('(3)') }
|
tmux.until { |lines| lines[-2].include?('(3)') }
|
||||||
tmux.send_keys :Enter
|
tmux.send_keys :Enter
|
||||||
@@ -409,11 +418,12 @@ class TestGoFZF < TestBase
|
|||||||
|
|
||||||
def test_expect
|
def test_expect
|
||||||
test = lambda do |key, feed, expected = key|
|
test = lambda do |key, feed, expected = key|
|
||||||
tmux.send_keys "seq 1 100 | #{fzf :expect, key}", :Enter
|
tmux.send_keys "seq 1 100 | #{fzf :expect, key}; sync", :Enter
|
||||||
tmux.until { |lines| lines[-2].include? '100/100' }
|
tmux.until { |lines| lines[-2].include? '100/100' }
|
||||||
tmux.send_keys '55'
|
tmux.send_keys '55'
|
||||||
tmux.until { |lines| lines[-2].include? '1/100' }
|
tmux.until { |lines| lines[-2].include? '1/100' }
|
||||||
tmux.send_keys *feed
|
tmux.send_keys *feed
|
||||||
|
tmux.prepare
|
||||||
assert_equal [expected, '55'], readonce.split($/)
|
assert_equal [expected, '55'], readonce.split($/)
|
||||||
end
|
end
|
||||||
test.call 'ctrl-t', 'C-T'
|
test.call 'ctrl-t', 'C-T'
|
||||||
@@ -424,6 +434,10 @@ class TestGoFZF < TestBase
|
|||||||
test.call 'f3', 'f3'
|
test.call 'f3', 'f3'
|
||||||
test.call 'f2,f4', 'f2', 'f2'
|
test.call 'f2,f4', 'f2', 'f2'
|
||||||
test.call 'f2,f4', 'f4', 'f4'
|
test.call 'f2,f4', 'f4', 'f4'
|
||||||
|
test.call 'alt-/', [:Escape, :/]
|
||||||
|
%w[f5 f6 f7 f8 f9 f10].each do |key|
|
||||||
|
test.call 'f5,f6,f7,f8,f9,f10', key, key
|
||||||
|
end
|
||||||
test.call '@', '@'
|
test.call '@', '@'
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -458,8 +472,8 @@ class TestGoFZF < TestBase
|
|||||||
|
|
||||||
def test_unicode_case
|
def test_unicode_case
|
||||||
writelines tempname, %w[строКА1 СТРОКА2 строка3 Строка4]
|
writelines tempname, %w[строКА1 СТРОКА2 строка3 Строка4]
|
||||||
assert_equal %w[СТРОКА2 Строка4], `cat #{tempname} | #{FZF} -fС`.split($/)
|
assert_equal %w[СТРОКА2 Строка4], `#{FZF} -fС < #{tempname}`.split($/)
|
||||||
assert_equal %w[строКА1 СТРОКА2 строка3 Строка4], `cat #{tempname} | #{FZF} -fс`.split($/)
|
assert_equal %w[строКА1 СТРОКА2 строка3 Строка4], `#{FZF} -fс < #{tempname}`.split($/)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_tiebreak
|
def test_tiebreak
|
||||||
@@ -471,7 +485,7 @@ class TestGoFZF < TestBase
|
|||||||
]
|
]
|
||||||
writelines tempname, input
|
writelines tempname, input
|
||||||
|
|
||||||
assert_equal input, `cat #{tempname} | #{FZF} -ffoobar --tiebreak=index`.split($/)
|
assert_equal input, `#{FZF} -ffoobar --tiebreak=index < #{tempname}`.split($/)
|
||||||
|
|
||||||
by_length = %w[
|
by_length = %w[
|
||||||
----foobar--
|
----foobar--
|
||||||
@@ -479,8 +493,8 @@ class TestGoFZF < TestBase
|
|||||||
-------foobar-
|
-------foobar-
|
||||||
--foobar--------
|
--foobar--------
|
||||||
]
|
]
|
||||||
assert_equal by_length, `cat #{tempname} | #{FZF} -ffoobar`.split($/)
|
assert_equal by_length, `#{FZF} -ffoobar < #{tempname}`.split($/)
|
||||||
assert_equal by_length, `cat #{tempname} | #{FZF} -ffoobar --tiebreak=length`.split($/)
|
assert_equal by_length, `#{FZF} -ffoobar --tiebreak=length < #{tempname}`.split($/)
|
||||||
|
|
||||||
by_begin = %w[
|
by_begin = %w[
|
||||||
--foobar--------
|
--foobar--------
|
||||||
@@ -488,17 +502,175 @@ class TestGoFZF < TestBase
|
|||||||
-----foobar---
|
-----foobar---
|
||||||
-------foobar-
|
-------foobar-
|
||||||
]
|
]
|
||||||
assert_equal by_begin, `cat #{tempname} | #{FZF} -ffoobar --tiebreak=begin`.split($/)
|
assert_equal by_begin, `#{FZF} -ffoobar --tiebreak=begin < #{tempname}`.split($/)
|
||||||
assert_equal by_begin, `cat #{tempname} | #{FZF} -f"!z foobar" -x --tiebreak begin`.split($/)
|
assert_equal by_begin, `#{FZF} -f"!z foobar" -x --tiebreak begin < #{tempname}`.split($/)
|
||||||
|
|
||||||
assert_equal %w[
|
assert_equal %w[
|
||||||
-------foobar-
|
-------foobar-
|
||||||
----foobar--
|
----foobar--
|
||||||
-----foobar---
|
-----foobar---
|
||||||
--foobar--------
|
--foobar--------
|
||||||
], `cat #{tempname} | #{FZF} -ffoobar --tiebreak end`.split($/)
|
], `#{FZF} -ffoobar --tiebreak end < #{tempname}`.split($/)
|
||||||
|
|
||||||
assert_equal input, `cat #{tempname} | #{FZF} -f"!z" -x --tiebreak end`.split($/)
|
assert_equal input, `#{FZF} -f"!z" -x --tiebreak end < #{tempname}`.split($/)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Since 0.11.2
|
||||||
|
def test_tiebreak_list
|
||||||
|
input = %w[
|
||||||
|
f-o-o-b-a-r
|
||||||
|
foobar----
|
||||||
|
--foobar
|
||||||
|
----foobar
|
||||||
|
foobar--
|
||||||
|
--foobar--
|
||||||
|
foobar
|
||||||
|
]
|
||||||
|
writelines tempname, input
|
||||||
|
|
||||||
|
assert_equal %w[
|
||||||
|
foobar----
|
||||||
|
--foobar
|
||||||
|
----foobar
|
||||||
|
foobar--
|
||||||
|
--foobar--
|
||||||
|
foobar
|
||||||
|
f-o-o-b-a-r
|
||||||
|
], `#{FZF} -ffb --tiebreak=index < #{tempname}`.split($/)
|
||||||
|
|
||||||
|
by_length = %w[
|
||||||
|
foobar
|
||||||
|
--foobar
|
||||||
|
foobar--
|
||||||
|
foobar----
|
||||||
|
----foobar
|
||||||
|
--foobar--
|
||||||
|
f-o-o-b-a-r
|
||||||
|
]
|
||||||
|
assert_equal by_length, `#{FZF} -ffb < #{tempname}`.split($/)
|
||||||
|
assert_equal by_length, `#{FZF} -ffb --tiebreak=length < #{tempname}`.split($/)
|
||||||
|
|
||||||
|
assert_equal %w[
|
||||||
|
foobar
|
||||||
|
foobar--
|
||||||
|
--foobar
|
||||||
|
foobar----
|
||||||
|
--foobar--
|
||||||
|
----foobar
|
||||||
|
f-o-o-b-a-r
|
||||||
|
], `#{FZF} -ffb --tiebreak=length,begin < #{tempname}`.split($/)
|
||||||
|
|
||||||
|
assert_equal %w[
|
||||||
|
foobar
|
||||||
|
--foobar
|
||||||
|
foobar--
|
||||||
|
----foobar
|
||||||
|
--foobar--
|
||||||
|
foobar----
|
||||||
|
f-o-o-b-a-r
|
||||||
|
], `#{FZF} -ffb --tiebreak=length,end < #{tempname}`.split($/)
|
||||||
|
|
||||||
|
assert_equal %w[
|
||||||
|
foobar----
|
||||||
|
foobar--
|
||||||
|
foobar
|
||||||
|
--foobar
|
||||||
|
--foobar--
|
||||||
|
----foobar
|
||||||
|
f-o-o-b-a-r
|
||||||
|
], `#{FZF} -ffb --tiebreak=begin < #{tempname}`.split($/)
|
||||||
|
|
||||||
|
by_begin_end = %w[
|
||||||
|
foobar
|
||||||
|
foobar--
|
||||||
|
foobar----
|
||||||
|
--foobar
|
||||||
|
--foobar--
|
||||||
|
----foobar
|
||||||
|
f-o-o-b-a-r
|
||||||
|
]
|
||||||
|
assert_equal by_begin_end, `#{FZF} -ffb --tiebreak=begin,length < #{tempname}`.split($/)
|
||||||
|
assert_equal by_begin_end, `#{FZF} -ffb --tiebreak=begin,end < #{tempname}`.split($/)
|
||||||
|
|
||||||
|
assert_equal %w[
|
||||||
|
--foobar
|
||||||
|
----foobar
|
||||||
|
foobar
|
||||||
|
foobar--
|
||||||
|
--foobar--
|
||||||
|
foobar----
|
||||||
|
f-o-o-b-a-r
|
||||||
|
], `#{FZF} -ffb --tiebreak=end < #{tempname}`.split($/)
|
||||||
|
|
||||||
|
by_begin_end = %w[
|
||||||
|
foobar
|
||||||
|
--foobar
|
||||||
|
----foobar
|
||||||
|
foobar--
|
||||||
|
--foobar--
|
||||||
|
foobar----
|
||||||
|
f-o-o-b-a-r
|
||||||
|
]
|
||||||
|
assert_equal by_begin_end, `#{FZF} -ffb --tiebreak=end,begin < #{tempname}`.split($/)
|
||||||
|
assert_equal by_begin_end, `#{FZF} -ffb --tiebreak=end,length < #{tempname}`.split($/)
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_tiebreak_white_prefix
|
||||||
|
writelines tempname, [
|
||||||
|
'f o o b a r',
|
||||||
|
' foo bar',
|
||||||
|
' foobar',
|
||||||
|
'----foo bar',
|
||||||
|
'----foobar',
|
||||||
|
' foo bar',
|
||||||
|
' foobar--',
|
||||||
|
' foobar',
|
||||||
|
'--foo bar',
|
||||||
|
'--foobar',
|
||||||
|
'foobar',
|
||||||
|
]
|
||||||
|
|
||||||
|
assert_equal [
|
||||||
|
' foobar',
|
||||||
|
' foobar',
|
||||||
|
'foobar',
|
||||||
|
' foobar--',
|
||||||
|
'--foobar',
|
||||||
|
'----foobar',
|
||||||
|
' foo bar',
|
||||||
|
' foo bar',
|
||||||
|
'--foo bar',
|
||||||
|
'----foo bar',
|
||||||
|
'f o o b a r',
|
||||||
|
], `#{FZF} -ffb < #{tempname}`.split($/)
|
||||||
|
|
||||||
|
assert_equal [
|
||||||
|
' foobar',
|
||||||
|
' foobar--',
|
||||||
|
' foobar',
|
||||||
|
'foobar',
|
||||||
|
'--foobar',
|
||||||
|
'----foobar',
|
||||||
|
' foo bar',
|
||||||
|
' foo bar',
|
||||||
|
'--foo bar',
|
||||||
|
'----foo bar',
|
||||||
|
'f o o b a r',
|
||||||
|
], `#{FZF} -ffb --tiebreak=begin < #{tempname}`.split($/)
|
||||||
|
|
||||||
|
assert_equal [
|
||||||
|
' foobar',
|
||||||
|
' foobar',
|
||||||
|
'foobar',
|
||||||
|
' foobar--',
|
||||||
|
'--foobar',
|
||||||
|
'----foobar',
|
||||||
|
' foo bar',
|
||||||
|
' foo bar',
|
||||||
|
'--foo bar',
|
||||||
|
'----foo bar',
|
||||||
|
'f o o b a r',
|
||||||
|
], `#{FZF} -ffb --tiebreak=begin,length < #{tempname}`.split($/)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_tiebreak_length_with_nth
|
def test_tiebreak_length_with_nth
|
||||||
@@ -516,7 +688,7 @@ class TestGoFZF < TestBase
|
|||||||
123:hello
|
123:hello
|
||||||
1234567:h
|
1234567:h
|
||||||
]
|
]
|
||||||
assert_equal output, `cat #{tempname} | #{FZF} -fh`.split($/)
|
assert_equal output, `#{FZF} -fh < #{tempname}`.split($/)
|
||||||
|
|
||||||
output = %w[
|
output = %w[
|
||||||
1234567:h
|
1234567:h
|
||||||
@@ -524,7 +696,7 @@ class TestGoFZF < TestBase
|
|||||||
1:hell
|
1:hell
|
||||||
123:hello
|
123:hello
|
||||||
]
|
]
|
||||||
assert_equal output, `cat #{tempname} | #{FZF} -fh -n2 -d:`.split($/)
|
assert_equal output, `#{FZF} -fh -n2 -d: < #{tempname}`.split($/)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_tiebreak_length_with_nth_trim_length
|
def test_tiebreak_length_with_nth_trim_length
|
||||||
@@ -543,16 +715,16 @@ class TestGoFZF < TestBase
|
|||||||
"apple juice bottle 1",
|
"apple juice bottle 1",
|
||||||
"apple ui bottle 2",
|
"apple ui bottle 2",
|
||||||
]
|
]
|
||||||
assert_equal output, `cat #{tempname} | #{FZF} -fa -n1`.split($/)
|
assert_equal output, `#{FZF} -fa -n1 < #{tempname}`.split($/)
|
||||||
|
|
||||||
# len(1 ~ 2)
|
# len(1 ~ 2)
|
||||||
output = [
|
output = [
|
||||||
"apple ui bottle 2",
|
|
||||||
"app ic bottle 4",
|
"app ic bottle 4",
|
||||||
"apple juice bottle 1",
|
|
||||||
"app ice bottle 3",
|
"app ice bottle 3",
|
||||||
|
"apple ui bottle 2",
|
||||||
|
"apple juice bottle 1",
|
||||||
]
|
]
|
||||||
assert_equal output, `cat #{tempname} | #{FZF} -fai -n1..2`.split($/)
|
assert_equal output, `#{FZF} -fai -n1..2 < #{tempname}`.split($/)
|
||||||
|
|
||||||
# len(1) + len(2)
|
# len(1) + len(2)
|
||||||
output = [
|
output = [
|
||||||
@@ -561,17 +733,17 @@ class TestGoFZF < TestBase
|
|||||||
"apple ui bottle 2",
|
"apple ui bottle 2",
|
||||||
"apple juice bottle 1",
|
"apple juice bottle 1",
|
||||||
]
|
]
|
||||||
assert_equal output, `cat #{tempname} | #{FZF} -x -f"a i" -n1,2`.split($/)
|
assert_equal output, `#{FZF} -x -f"a i" -n1,2 < #{tempname}`.split($/)
|
||||||
|
|
||||||
# len(2)
|
# len(2)
|
||||||
output = [
|
output = [
|
||||||
"apple ui bottle 2",
|
|
||||||
"app ic bottle 4",
|
"app ic bottle 4",
|
||||||
"app ice bottle 3",
|
"app ice bottle 3",
|
||||||
|
"apple ui bottle 2",
|
||||||
"apple juice bottle 1",
|
"apple juice bottle 1",
|
||||||
]
|
]
|
||||||
assert_equal output, `cat #{tempname} | #{FZF} -fi -n2`.split($/)
|
assert_equal output, `#{FZF} -fi -n2 < #{tempname}`.split($/)
|
||||||
assert_equal output, `cat #{tempname} | #{FZF} -fi -n2,1..2`.split($/)
|
assert_equal output, `#{FZF} -fi -n2,1..2 < #{tempname}`.split($/)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_tiebreak_end_backward_scan
|
def test_tiebreak_end_backward_scan
|
||||||
@@ -581,8 +753,8 @@ class TestGoFZF < TestBase
|
|||||||
]
|
]
|
||||||
writelines tempname, input
|
writelines tempname, input
|
||||||
|
|
||||||
assert_equal input.reverse, `cat #{tempname} | #{FZF} -f fb`.split($/)
|
assert_equal input.reverse, `#{FZF} -f fb < #{tempname}`.split($/)
|
||||||
assert_equal input, `cat #{tempname} | #{FZF} -f fb --tiebreak=end`.split($/)
|
assert_equal input, `#{FZF} -f fb --tiebreak=end < #{tempname}`.split($/)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_invalid_cache
|
def test_invalid_cache
|
||||||
@@ -607,12 +779,19 @@ class TestGoFZF < TestBase
|
|||||||
assert_equal %w[4 5 6 9], readonce.split($/)
|
assert_equal %w[4 5 6 9], readonce.split($/)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_bind_print_query
|
||||||
|
tmux.send_keys "seq 1 1000 | #{fzf '-m --bind=ctrl-j:print-query'}", :Enter
|
||||||
|
tmux.until { |lines| lines[-2].end_with? '/1000' }
|
||||||
|
tmux.send_keys 'print-my-query', 'C-j'
|
||||||
|
assert_equal %w[print-my-query], readonce.split($/)
|
||||||
|
end
|
||||||
|
|
||||||
def test_long_line
|
def test_long_line
|
||||||
data = '.' * 256 * 1024
|
data = '.' * 256 * 1024
|
||||||
File.open(tempname, 'w') do |f|
|
File.open(tempname, 'w') do |f|
|
||||||
f << data
|
f << data
|
||||||
end
|
end
|
||||||
assert_equal data, `cat #{tempname} | #{FZF} -f .`.chomp
|
assert_equal data, `#{FZF} -f . < #{tempname}`.chomp
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_read0
|
def test_read0
|
||||||
@@ -694,25 +873,82 @@ class TestGoFZF < TestBase
|
|||||||
|
|
||||||
def test_execute
|
def test_execute
|
||||||
output = '/tmp/fzf-test-execute'
|
output = '/tmp/fzf-test-execute'
|
||||||
opts = %[--bind \\"alt-a:execute(echo '[{}]' >> #{output}),alt-b:execute[echo '({}), ({})' >> #{output}],C:execute:echo '({}), [{}], @{}@' >> #{output}\\"]
|
opts = %[--bind \\"alt-a:execute(echo [{}] >> #{output}),alt-b:execute[echo /{}{}/ >> #{output}],C:execute:echo /{}{}{}/ >> #{output}\\"]
|
||||||
tmux.send_keys "seq 100 | #{fzf opts}", :Enter
|
wait = lambda { |exp| tmux.until { |lines| lines[-2].include? exp } }
|
||||||
tmux.until { |lines| lines[-2].include? '100/100' }
|
writelines tempname, %w[foo'bar foo"bar foo$bar]
|
||||||
tmux.send_keys :Escape, :a, :Escape, :a
|
tmux.send_keys "cat #{tempname} | #{fzf opts}; sync", :Enter
|
||||||
|
wait['3/3']
|
||||||
|
tmux.send_keys :Escape, :a
|
||||||
|
wait['/3']
|
||||||
|
tmux.send_keys :Escape, :a
|
||||||
|
wait['/3']
|
||||||
tmux.send_keys :Up
|
tmux.send_keys :Up
|
||||||
tmux.send_keys :Escape, :b, :Escape, :b
|
tmux.send_keys :Escape, :b
|
||||||
|
wait['/3']
|
||||||
|
tmux.send_keys :Escape, :b
|
||||||
|
wait['/3']
|
||||||
tmux.send_keys :Up
|
tmux.send_keys :Up
|
||||||
tmux.send_keys :C
|
tmux.send_keys :C
|
||||||
tmux.send_keys 'foobar'
|
wait['3/3']
|
||||||
tmux.until { |lines| lines[-2].include? '0/100' }
|
tmux.send_keys 'barfoo'
|
||||||
tmux.send_keys :Escape, :a, :Escape, :b, :Escape, :c
|
wait['0/3']
|
||||||
|
tmux.send_keys :Escape, :a
|
||||||
|
wait['/3']
|
||||||
|
tmux.send_keys :Escape, :b
|
||||||
|
wait['/3']
|
||||||
tmux.send_keys :Enter
|
tmux.send_keys :Enter
|
||||||
readonce
|
readonce
|
||||||
assert_equal ['["1"]', '["1"]', '("2"), ("2")', '("2"), ("2")', '("3"), ["3"], @"3"@'],
|
assert_equal %w[[foo'bar] [foo'bar]
|
||||||
|
/foo"barfoo"bar/ /foo"barfoo"bar/
|
||||||
|
/foo$barfoo$barfoo$bar/],
|
||||||
File.readlines(output).map(&:chomp)
|
File.readlines(output).map(&:chomp)
|
||||||
ensure
|
ensure
|
||||||
File.unlink output rescue nil
|
File.unlink output rescue nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_execute_multi
|
||||||
|
output = '/tmp/fzf-test-execute-multi'
|
||||||
|
opts = %[--multi --bind \\"alt-a:execute-multi(echo {}/{} >> #{output}; sync)\\"]
|
||||||
|
writelines tempname, %w[foo'bar foo"bar foo$bar foobar]
|
||||||
|
tmux.send_keys "cat #{tempname} | #{fzf opts}", :Enter
|
||||||
|
tmux.until { |lines| lines[-2].include? '4/4' }
|
||||||
|
tmux.send_keys :Escape, :a
|
||||||
|
tmux.until { |lines| lines[-2].include? '/4' }
|
||||||
|
tmux.send_keys :BTab, :BTab, :BTab
|
||||||
|
tmux.send_keys :Escape, :a
|
||||||
|
tmux.until { |lines| lines[-2].include? '/4' }
|
||||||
|
tmux.send_keys :Tab, :Tab
|
||||||
|
tmux.send_keys :Escape, :a
|
||||||
|
tmux.until { |lines| lines[-2].include? '/4' }
|
||||||
|
tmux.send_keys :Enter
|
||||||
|
tmux.prepare
|
||||||
|
readonce
|
||||||
|
assert_equal [%[foo'bar/foo'bar],
|
||||||
|
%[foo'bar foo"bar foo$bar/foo'bar foo"bar foo$bar],
|
||||||
|
%[foo'bar foo"bar foobar/foo'bar foo"bar foobar]],
|
||||||
|
File.readlines(output).map(&:chomp)
|
||||||
|
ensure
|
||||||
|
File.unlink output rescue nil
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_execute_shell
|
||||||
|
# Custom script to use as $SHELL
|
||||||
|
output = tempname + '.out'
|
||||||
|
File.unlink output rescue nil
|
||||||
|
writelines tempname, ['#!/usr/bin/env bash', "echo $1 / $2 > #{output}", "sync"]
|
||||||
|
system "chmod +x #{tempname}"
|
||||||
|
|
||||||
|
tmux.send_keys "echo foo | SHELL=#{tempname} fzf --bind 'enter:execute:{}bar'", :Enter
|
||||||
|
tmux.until { |lines| lines[-2].include? '1/1' }
|
||||||
|
tmux.send_keys :Enter
|
||||||
|
tmux.until { |lines| lines[-2].include? '1/1' }
|
||||||
|
tmux.send_keys 'C-c'
|
||||||
|
tmux.prepare
|
||||||
|
assert_equal ["-c / 'foo'bar"], File.readlines(output).map(&:chomp)
|
||||||
|
ensure
|
||||||
|
File.unlink output rescue nil
|
||||||
|
end
|
||||||
|
|
||||||
def test_cycle
|
def test_cycle
|
||||||
tmux.send_keys "seq 8 | #{fzf :cycle}", :Enter
|
tmux.send_keys "seq 8 | #{fzf :cycle}", :Enter
|
||||||
tmux.until { |lines| lines[-2].include? '8/8' }
|
tmux.until { |lines| lines[-2].include? '8/8' }
|
||||||
@@ -739,12 +975,12 @@ class TestGoFZF < TestBase
|
|||||||
lines[-2].include?('/90') &&
|
lines[-2].include?('/90') &&
|
||||||
lines[-3] == ' 1' &&
|
lines[-3] == ' 1' &&
|
||||||
lines[-4] == ' 2' &&
|
lines[-4] == ' 2' &&
|
||||||
lines[-13] == '> 15'
|
lines[-13] == '> 50'
|
||||||
end
|
end
|
||||||
tmux.send_keys :Down
|
tmux.send_keys :Down
|
||||||
end
|
end
|
||||||
tmux.send_keys :Enter
|
tmux.send_keys :Enter
|
||||||
assert_equal '15', readonce.chomp
|
assert_equal '50', readonce.chomp
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_header_lines_reverse
|
def test_header_lines_reverse
|
||||||
@@ -754,12 +990,12 @@ class TestGoFZF < TestBase
|
|||||||
lines[1].include?('/90') &&
|
lines[1].include?('/90') &&
|
||||||
lines[2] == ' 1' &&
|
lines[2] == ' 1' &&
|
||||||
lines[3] == ' 2' &&
|
lines[3] == ' 2' &&
|
||||||
lines[12] == '> 15'
|
lines[12] == '> 50'
|
||||||
end
|
end
|
||||||
tmux.send_keys :Up
|
tmux.send_keys :Up
|
||||||
end
|
end
|
||||||
tmux.send_keys :Enter
|
tmux.send_keys :Enter
|
||||||
assert_equal '15', readonce.chomp
|
assert_equal '50', readonce.chomp
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_header_lines_overflow
|
def test_header_lines_overflow
|
||||||
@@ -785,8 +1021,8 @@ class TestGoFZF < TestBase
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_header
|
def test_header
|
||||||
tmux.send_keys "seq 100 | #{fzf "--header \\\"\\$(head -5 #{__FILE__})\\\""}", :Enter
|
tmux.send_keys "seq 100 | #{fzf "--header \\\"\\$(head -5 #{FILE})\\\""}", :Enter
|
||||||
header = File.readlines(__FILE__).take(5).map(&:strip)
|
header = File.readlines(FILE).take(5).map(&:strip)
|
||||||
tmux.until do |lines|
|
tmux.until do |lines|
|
||||||
lines[-2].include?('100/100') &&
|
lines[-2].include?('100/100') &&
|
||||||
lines[-7..-3].map(&:strip) == header
|
lines[-7..-3].map(&:strip) == header
|
||||||
@@ -794,8 +1030,8 @@ class TestGoFZF < TestBase
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_header_reverse
|
def test_header_reverse
|
||||||
tmux.send_keys "seq 100 | #{fzf "--header=\\\"\\$(head -5 #{__FILE__})\\\" --reverse"}", :Enter
|
tmux.send_keys "seq 100 | #{fzf "--header=\\\"\\$(head -5 #{FILE})\\\" --reverse"}", :Enter
|
||||||
header = File.readlines(__FILE__).take(5).map(&:strip)
|
header = File.readlines(FILE).take(5).map(&:strip)
|
||||||
tmux.until do |lines|
|
tmux.until do |lines|
|
||||||
lines[1].include?('100/100') &&
|
lines[1].include?('100/100') &&
|
||||||
lines[2..6].map(&:strip) == header
|
lines[2..6].map(&:strip) == header
|
||||||
@@ -803,8 +1039,8 @@ class TestGoFZF < TestBase
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_header_and_header_lines
|
def test_header_and_header_lines
|
||||||
tmux.send_keys "seq 100 | #{fzf "--header-lines 10 --header \\\"\\$(head -5 #{__FILE__})\\\""}", :Enter
|
tmux.send_keys "seq 100 | #{fzf "--header-lines 10 --header \\\"\\$(head -5 #{FILE})\\\""}", :Enter
|
||||||
header = File.readlines(__FILE__).take(5).map(&:strip)
|
header = File.readlines(FILE).take(5).map(&:strip)
|
||||||
tmux.until do |lines|
|
tmux.until do |lines|
|
||||||
lines[-2].include?('90/90') &&
|
lines[-2].include?('90/90') &&
|
||||||
lines[-7...-2].map(&:strip) == header &&
|
lines[-7...-2].map(&:strip) == header &&
|
||||||
@@ -813,8 +1049,8 @@ class TestGoFZF < TestBase
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_header_and_header_lines_reverse
|
def test_header_and_header_lines_reverse
|
||||||
tmux.send_keys "seq 100 | #{fzf "--reverse --header-lines 10 --header \\\"\\$(head -5 #{__FILE__})\\\""}", :Enter
|
tmux.send_keys "seq 100 | #{fzf "--reverse --header-lines 10 --header \\\"\\$(head -5 #{FILE})\\\""}", :Enter
|
||||||
header = File.readlines(__FILE__).take(5).map(&:strip)
|
header = File.readlines(FILE).take(5).map(&:strip)
|
||||||
tmux.until do |lines|
|
tmux.until do |lines|
|
||||||
lines[1].include?('90/90') &&
|
lines[1].include?('90/90') &&
|
||||||
lines[2...7].map(&:strip) == header &&
|
lines[2...7].map(&:strip) == header &&
|
||||||
@@ -822,7 +1058,7 @@ class TestGoFZF < TestBase
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_canel
|
def test_cancel
|
||||||
tmux.send_keys "seq 10 | #{fzf "--bind 2:cancel"}", :Enter
|
tmux.send_keys "seq 10 | #{fzf "--bind 2:cancel"}", :Enter
|
||||||
tmux.until { |lines| lines[-2].include?('10/10') }
|
tmux.until { |lines| lines[-2].include?('10/10') }
|
||||||
tmux.send_keys '123'
|
tmux.send_keys '123'
|
||||||
@@ -847,20 +1083,40 @@ class TestGoFZF < TestBase
|
|||||||
tmux.send_keys :Enter
|
tmux.send_keys :Enter
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_tabstop
|
||||||
|
writelines tempname, ["f\too\tba\tr\tbaz\tbarfooq\tux"]
|
||||||
|
{
|
||||||
|
1 => '> f oo ba r baz barfooq ux',
|
||||||
|
2 => '> f oo ba r baz barfooq ux',
|
||||||
|
3 => '> f oo ba r baz barfooq ux',
|
||||||
|
4 => '> f oo ba r baz barfooq ux',
|
||||||
|
5 => '> f oo ba r baz barfooq ux',
|
||||||
|
6 => '> f oo ba r baz barfooq ux',
|
||||||
|
7 => '> f oo ba r baz barfooq ux',
|
||||||
|
8 => '> f oo ba r baz barfooq ux',
|
||||||
|
9 => '> f oo ba r baz barfooq ux',
|
||||||
|
}.each do |ts, exp|
|
||||||
|
tmux.prepare
|
||||||
|
tmux.send_keys %[cat #{tempname} | fzf --tabstop=#{ts}], :Enter
|
||||||
|
tmux.until { |lines| exp.start_with? lines[-3].to_s.strip.sub(/\.\.$/, '') }
|
||||||
|
tmux.send_keys :Enter
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def test_with_nth
|
def test_with_nth
|
||||||
writelines tempname, ['hello world ', 'byebye']
|
writelines tempname, ['hello world ', 'byebye']
|
||||||
assert_equal 'hello world ', `cat #{tempname} | #{FZF} -f"^he hehe" -x -n 2.. --with-nth 2,1,1`.chomp
|
assert_equal 'hello world ', `#{FZF} -f"^he hehe" -x -n 2.. --with-nth 2,1,1 < #{tempname}`.chomp
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_with_nth_ansi
|
def test_with_nth_ansi
|
||||||
writelines tempname, ["\x1b[33mhello \x1b[34;1mworld\x1b[m ", 'byebye']
|
writelines tempname, ["\x1b[33mhello \x1b[34;1mworld\x1b[m ", 'byebye']
|
||||||
assert_equal 'hello world ', `cat #{tempname} | #{FZF} -f"^he hehe" -x -n 2.. --with-nth 2,1,1 --ansi`.chomp
|
assert_equal 'hello world ', `#{FZF} -f"^he hehe" -x -n 2.. --with-nth 2,1,1 --ansi < #{tempname}`.chomp
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_with_nth_no_ansi
|
def test_with_nth_no_ansi
|
||||||
src = "\x1b[33mhello \x1b[34;1mworld\x1b[m "
|
src = "\x1b[33mhello \x1b[34;1mworld\x1b[m "
|
||||||
writelines tempname, [src, 'byebye']
|
writelines tempname, [src, 'byebye']
|
||||||
assert_equal src, `cat #{tempname} | #{FZF} -fhehe -x -n 2.. --with-nth 2,1,1 --no-ansi`.chomp
|
assert_equal src, `#{FZF} -fhehe -x -n 2.. --with-nth 2,1,1 --no-ansi < #{tempname}`.chomp
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_exit_0_exit_code
|
def test_exit_0_exit_code
|
||||||
@@ -893,21 +1149,121 @@ class TestGoFZF < TestBase
|
|||||||
|
|
||||||
def test_exitstatus_empty
|
def test_exitstatus_empty
|
||||||
{ '99' => '0', '999' => '1' }.each do |query, status|
|
{ '99' => '0', '999' => '1' }.each do |query, status|
|
||||||
tmux.send_keys "seq 100 | #{FZF} -q #{query}", :Enter
|
tmux.send_keys "seq 100 | #{FZF} -q #{query}; echo --\\$?--", :Enter
|
||||||
tmux.until { |lines| lines[-2] =~ %r{ [10]/100} }
|
tmux.until { |lines| lines[-2] =~ %r{ [10]/100} }
|
||||||
tmux.send_keys :Enter
|
tmux.send_keys :Enter
|
||||||
|
|
||||||
tmux.send_keys 'echo --\$?--'
|
|
||||||
tmux.until { |lines| lines.last.include? "echo --$?--" }
|
|
||||||
tmux.send_keys :Enter
|
|
||||||
tmux.until { |lines| lines.last.include? "--#{status}--" }
|
tmux.until { |lines| lines.last.include? "--#{status}--" }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_default_extended
|
||||||
|
assert_equal '100', `seq 100 | #{FZF} -f "1 00$"`.chomp
|
||||||
|
assert_equal '', `seq 100 | #{FZF} -f "1 00$" +x`.chomp
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_exact
|
||||||
|
assert_equal 4, `seq 123 | #{FZF} -f 13`.lines.length
|
||||||
|
assert_equal 2, `seq 123 | #{FZF} -f 13 -e`.lines.length
|
||||||
|
assert_equal 4, `seq 123 | #{FZF} -f 13 +e`.lines.length
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_or_operator
|
||||||
|
assert_equal %w[1 5 10], `seq 10 | #{FZF} -f "1 | 5"`.lines.map(&:chomp)
|
||||||
|
assert_equal %w[1 10 2 3 4 5 6 7 8 9],
|
||||||
|
`seq 10 | #{FZF} -f '1 | !1'`.lines.map(&:chomp)
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_hscroll_off
|
||||||
|
writelines tempname, ['=' * 10000 + '0123456789']
|
||||||
|
[0, 3, 6].each do |off|
|
||||||
|
tmux.prepare
|
||||||
|
tmux.send_keys "#{FZF} --hscroll-off=#{off} -q 0 < #{tempname}", :Enter
|
||||||
|
tmux.until { |lines| lines[-3].end_with?((0..off).to_a.join + '..') }
|
||||||
|
tmux.send_keys '9'
|
||||||
|
tmux.until { |lines| lines[-3].end_with? '789' }
|
||||||
|
tmux.send_keys :Enter
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_partial_caching
|
||||||
|
tmux.send_keys 'seq 1000 | fzf -e', :Enter
|
||||||
|
tmux.until { |lines| lines[-2] == ' 1000/1000' }
|
||||||
|
tmux.send_keys 11
|
||||||
|
tmux.until { |lines| lines[-2] == ' 19/1000' }
|
||||||
|
tmux.send_keys 'C-a', "'"
|
||||||
|
tmux.until { |lines| lines[-2] == ' 28/1000' }
|
||||||
|
tmux.send_keys :Enter
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_jump
|
||||||
|
tmux.send_keys "seq 1000 | #{fzf "--multi --jump-labels 12345 --bind 'ctrl-j:jump'"}", :Enter
|
||||||
|
tmux.until { |lines| lines[-2] == ' 1000/1000' }
|
||||||
|
tmux.send_keys 'C-j'
|
||||||
|
tmux.until { |lines| lines[-7] == '5 5' }
|
||||||
|
tmux.until { |lines| lines[-8] == ' 6' }
|
||||||
|
tmux.send_keys '5'
|
||||||
|
tmux.until { |lines| lines[-7] == '> 5' }
|
||||||
|
tmux.send_keys :Tab
|
||||||
|
tmux.until { |lines| lines[-7] == ' >5' }
|
||||||
|
tmux.send_keys 'C-j'
|
||||||
|
tmux.until { |lines| lines[-7] == '5>5' }
|
||||||
|
tmux.send_keys '2'
|
||||||
|
tmux.until { |lines| lines[-4] == '> 2' }
|
||||||
|
tmux.send_keys :Tab
|
||||||
|
tmux.until { |lines| lines[-4] == ' >2' }
|
||||||
|
tmux.send_keys 'C-j'
|
||||||
|
tmux.until { |lines| lines[-7] == '5>5' }
|
||||||
|
|
||||||
|
# Press any key other than jump labels to cancel jump
|
||||||
|
tmux.send_keys '6'
|
||||||
|
tmux.until { |lines| lines[-3] == '> 1' }
|
||||||
|
tmux.send_keys :Tab
|
||||||
|
tmux.until { |lines| lines[-3] == '>>1' }
|
||||||
|
tmux.send_keys :Enter
|
||||||
|
assert_equal %w[5 2 1], readonce.split($/)
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_jump_accept
|
||||||
|
tmux.send_keys "seq 1000 | #{fzf "--multi --jump-labels 12345 --bind 'ctrl-j:jump-accept'"}", :Enter
|
||||||
|
tmux.until { |lines| lines[-2] == ' 1000/1000' }
|
||||||
|
tmux.send_keys 'C-j'
|
||||||
|
tmux.until { |lines| lines[-7] == '5 5' }
|
||||||
|
tmux.send_keys '3'
|
||||||
|
assert_equal '3', readonce.chomp
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_preview
|
||||||
|
tmux.send_keys %[seq 1000 | sed s/^2$// | #{FZF} --preview 'sleep 0.2; echo {{}-{}}' --bind ?:toggle-preview], :Enter
|
||||||
|
tmux.until { |lines| lines[1].include?(' {1-1}') }
|
||||||
|
tmux.send_keys :Up
|
||||||
|
tmux.until { |lines| lines[1].include?(' {-}') }
|
||||||
|
tmux.send_keys '555'
|
||||||
|
tmux.until { |lines| lines[1].include?(' {555-555}') }
|
||||||
|
tmux.send_keys '?'
|
||||||
|
tmux.until { |lines| !lines[1].include?(' {555-555}') }
|
||||||
|
tmux.send_keys '?'
|
||||||
|
tmux.until { |lines| lines[1].include?(' {555-555}') }
|
||||||
|
tmux.send_keys :BSpace
|
||||||
|
tmux.until { |lines| lines[-2].start_with? ' 28/1000' }
|
||||||
|
tmux.send_keys 'foobar'
|
||||||
|
tmux.until { |lines| !lines[1].include?('{') }
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_preview_hidden
|
||||||
|
tmux.send_keys %[seq 1000 | #{FZF} --preview 'echo {{}-{}}' --preview-window down:1:hidden --bind ?:toggle-preview], :Enter
|
||||||
|
tmux.until { |lines| lines[-1] == '>' }
|
||||||
|
tmux.send_keys '?'
|
||||||
|
tmux.until { |lines| lines[-2].include?(' {1-1}') }
|
||||||
|
tmux.send_keys '555'
|
||||||
|
tmux.until { |lines| lines[-2].include?(' {555-555}') }
|
||||||
|
tmux.send_keys '?'
|
||||||
|
tmux.until { |lines| lines[-1] == '> 555' }
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
def writelines path, lines
|
def writelines path, lines
|
||||||
File.unlink path while File.exists? path
|
File.unlink path while File.exists? path
|
||||||
File.open(path, 'w') { |f| f << lines.join($/) }
|
File.open(path, 'w') { |f| f << lines.join($/) + $/ }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -959,6 +1315,35 @@ module TestShell
|
|||||||
tmux.until(0) { |lines| lines[-1].include? '1 2 3' }
|
tmux.until(0) { |lines| lines[-1].include? '1 2 3' }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_ctrl_t_unicode
|
||||||
|
FileUtils.mkdir_p '/tmp/fzf-test'
|
||||||
|
tmux.paste 'cd /tmp/fzf-test; echo -n test1 > "fzf-unicode 테스트1"; echo -n test2 > "fzf-unicode 테스트2"'
|
||||||
|
tmux.prepare
|
||||||
|
tmux.send_keys 'cat ', 'C-t', pane: 0
|
||||||
|
tmux.until(1) { |lines| lines.item_count >= 1 }
|
||||||
|
tmux.send_keys 'fzf-unicode', pane: 1
|
||||||
|
tmux.until(1) { |lines| lines[-2].start_with? ' 2/' }
|
||||||
|
|
||||||
|
tmux.send_keys '1', pane: 1
|
||||||
|
tmux.until(1) { |lines| lines[-2].start_with? ' 1/' }
|
||||||
|
tmux.send_keys :BTab, pane: 1
|
||||||
|
tmux.until(1) { |lines| lines[-2].include? '(1)' }
|
||||||
|
|
||||||
|
tmux.send_keys :BSpace, pane: 1
|
||||||
|
tmux.until(1) { |lines| lines[-2].start_with? ' 2/' }
|
||||||
|
|
||||||
|
tmux.send_keys '2', pane: 1
|
||||||
|
tmux.until(1) { |lines| lines[-2].start_with? ' 1/' }
|
||||||
|
tmux.send_keys :BTab, pane: 1
|
||||||
|
tmux.until(1) { |lines| lines[-2].include? '(2)' }
|
||||||
|
|
||||||
|
tmux.send_keys :Enter, pane: 1
|
||||||
|
tmux.until { |lines| lines[-1].include?('cat') || lines[-2].include?('cat') }
|
||||||
|
tmux.until { |lines| lines[-1].include?('fzf-unicode') || lines[-2].include?('fzf-unicode') }
|
||||||
|
tmux.send_keys :Enter
|
||||||
|
tmux.until { |lines| lines[-1].include? 'test1test2' }
|
||||||
|
end
|
||||||
|
|
||||||
def test_alt_c
|
def test_alt_c
|
||||||
tmux.prepare
|
tmux.prepare
|
||||||
tmux.send_keys :Escape, :c, pane: 0
|
tmux.send_keys :Escape, :c, pane: 0
|
||||||
@@ -970,6 +1355,22 @@ module TestShell
|
|||||||
tmux.until { |lines| lines[-1].end_with?(expected) }
|
tmux.until { |lines| lines[-1].end_with?(expected) }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_alt_c_command
|
||||||
|
set_var 'FZF_ALT_C_COMMAND', 'echo /tmp'
|
||||||
|
|
||||||
|
tmux.prepare
|
||||||
|
tmux.send_keys 'cd /', :Enter
|
||||||
|
|
||||||
|
tmux.prepare
|
||||||
|
tmux.send_keys :Escape, :c, pane: 0
|
||||||
|
lines = tmux.until(1) { |lines| lines.item_count == 1 }
|
||||||
|
tmux.send_keys :Enter, pane: 1
|
||||||
|
|
||||||
|
tmux.prepare
|
||||||
|
tmux.send_keys :pwd, :Enter
|
||||||
|
tmux.until { |lines| lines[-1].end_with? '/tmp' }
|
||||||
|
end
|
||||||
|
|
||||||
def test_ctrl_r
|
def test_ctrl_r
|
||||||
tmux.prepare
|
tmux.prepare
|
||||||
tmux.send_keys 'echo 1st', :Enter; tmux.prepare
|
tmux.send_keys 'echo 1st', :Enter; tmux.prepare
|
||||||
@@ -999,6 +1400,8 @@ module CompletionTest
|
|||||||
tmux.prepare
|
tmux.prepare
|
||||||
tmux.send_keys 'cat /tmp/fzf-test/10**', :Tab, pane: 0
|
tmux.send_keys 'cat /tmp/fzf-test/10**', :Tab, pane: 0
|
||||||
tmux.until(1) { |lines| lines.item_count > 0 }
|
tmux.until(1) { |lines| lines.item_count > 0 }
|
||||||
|
tmux.send_keys ' !d'
|
||||||
|
tmux.until(1) { |lines| lines[-2].include?(' 2/') }
|
||||||
tmux.send_keys :BTab, :BTab
|
tmux.send_keys :BTab, :BTab
|
||||||
tmux.until(1) { |lines| lines[-2].include?('(2)') }
|
tmux.until(1) { |lines| lines[-2].include?('(2)') }
|
||||||
tmux.send_keys :Enter
|
tmux.send_keys :Enter
|
||||||
@@ -1034,17 +1437,34 @@ module CompletionTest
|
|||||||
tmux.send_keys 'C-u'
|
tmux.send_keys 'C-u'
|
||||||
tmux.send_keys 'cat /tmp/fzf\ test/**', :Tab, pane: 0
|
tmux.send_keys 'cat /tmp/fzf\ test/**', :Tab, pane: 0
|
||||||
tmux.until(1) { |lines| lines.item_count > 0 }
|
tmux.until(1) { |lines| lines.item_count > 0 }
|
||||||
tmux.send_keys :Enter
|
tmux.send_keys 'C-K', :Enter
|
||||||
tmux.until do |lines|
|
tmux.until do |lines|
|
||||||
tmux.send_keys 'C-L'
|
tmux.send_keys 'C-L'
|
||||||
lines[-1].end_with?('/tmp/fzf\ test/foobar')
|
lines[-1].end_with?('/tmp/fzf\ test/foobar')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Should include hidden files
|
||||||
|
(1..100).each { |i| FileUtils.touch "/tmp/fzf-test/.hidden-#{i}" }
|
||||||
|
tmux.send_keys 'C-u'
|
||||||
|
tmux.send_keys 'cat /tmp/fzf-test/hidden**', :Tab, pane: 0
|
||||||
|
tmux.until(1) do |lines|
|
||||||
|
tmux.send_keys 'C-L'
|
||||||
|
lines[-2].include?('100/') &&
|
||||||
|
lines[-3].include?('/tmp/fzf-test/.hidden-')
|
||||||
|
end
|
||||||
|
tmux.send_keys :Enter
|
||||||
ensure
|
ensure
|
||||||
['/tmp/fzf-test', '/tmp/fzf test', '~/.fzf-home', 'no~such~user'].each do |f|
|
['/tmp/fzf-test', '/tmp/fzf test', '~/.fzf-home', 'no~such~user'].each do |f|
|
||||||
FileUtils.rm_rf File.expand_path(f)
|
FileUtils.rm_rf File.expand_path(f)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_file_completion_root
|
||||||
|
tmux.send_keys 'ls /**', :Tab, pane: 0
|
||||||
|
tmux.until(1) { |lines| lines.item_count > 0 }
|
||||||
|
tmux.send_keys :Enter
|
||||||
|
end
|
||||||
|
|
||||||
def test_dir_completion
|
def test_dir_completion
|
||||||
tmux.send_keys 'mkdir -p /tmp/fzf-test/d{1..100}; touch /tmp/fzf-test/d55/xxx', :Enter
|
tmux.send_keys 'mkdir -p /tmp/fzf-test/d{1..100}; touch /tmp/fzf-test/d55/xxx', :Enter
|
||||||
tmux.prepare
|
tmux.prepare
|
||||||
@@ -1091,6 +1511,65 @@ module CompletionTest
|
|||||||
ensure
|
ensure
|
||||||
Process.kill 'KILL', pid.to_i rescue nil if pid
|
Process.kill 'KILL', pid.to_i rescue nil if pid
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_custom_completion
|
||||||
|
tmux.send_keys '_fzf_compgen_path() { echo "\$1"; seq 10; }', :Enter
|
||||||
|
tmux.prepare
|
||||||
|
tmux.send_keys 'ls /tmp/**', :Tab, pane: 0
|
||||||
|
tmux.until(1) { |lines| lines.item_count == 11 }
|
||||||
|
tmux.send_keys :BTab, :BTab, :BTab
|
||||||
|
tmux.until(1) { |lines| lines[-2].include? '(3)' }
|
||||||
|
tmux.send_keys :Enter
|
||||||
|
tmux.until do |lines|
|
||||||
|
tmux.send_keys 'C-L'
|
||||||
|
lines[-1] == "ls /tmp 1 2"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_unset_completion
|
||||||
|
tmux.send_keys 'export FOO=BAR', :Enter
|
||||||
|
tmux.prepare
|
||||||
|
|
||||||
|
# Using tmux
|
||||||
|
tmux.send_keys 'unset FOO**', :Tab, pane: 0
|
||||||
|
tmux.until(1) { |lines| lines[-2].include? ' 1/' }
|
||||||
|
tmux.send_keys :Enter
|
||||||
|
tmux.until { |lines| lines[-1] == 'unset FOO' }
|
||||||
|
tmux.send_keys 'C-c'
|
||||||
|
|
||||||
|
# FZF_TMUX=0
|
||||||
|
new_shell
|
||||||
|
tmux.send_keys 'unset FOO**', :Tab
|
||||||
|
tmux.until { |lines| lines[-2].include? ' 1/' }
|
||||||
|
tmux.send_keys :Enter
|
||||||
|
tmux.until { |lines| lines[-1] == 'unset FOO' }
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_file_completion_unicode
|
||||||
|
FileUtils.mkdir_p '/tmp/fzf-test'
|
||||||
|
tmux.paste 'cd /tmp/fzf-test; echo -n test3 > "fzf-unicode 테스트1"; echo -n test4 > "fzf-unicode 테스트2"'
|
||||||
|
tmux.prepare
|
||||||
|
tmux.send_keys 'cat fzf-unicode**', :Tab, pane: 0
|
||||||
|
tmux.until(1) { |lines| lines[-2].start_with? ' 2/' }
|
||||||
|
|
||||||
|
tmux.send_keys '1', pane: 1
|
||||||
|
tmux.until(1) { |lines| lines[-2].start_with? ' 1/' }
|
||||||
|
tmux.send_keys :BTab, pane: 1
|
||||||
|
tmux.until(1) { |lines| lines[-2].include? '(1)' }
|
||||||
|
|
||||||
|
tmux.send_keys :BSpace, pane: 1
|
||||||
|
tmux.until(1) { |lines| lines[-2].start_with? ' 2/' }
|
||||||
|
|
||||||
|
tmux.send_keys '2', pane: 1
|
||||||
|
tmux.until(1) { |lines| lines[-2].start_with? ' 1/' }
|
||||||
|
tmux.send_keys :BTab, pane: 1
|
||||||
|
tmux.until(1) { |lines| lines[-2].include? '(2)' }
|
||||||
|
|
||||||
|
tmux.send_keys :Enter, pane: 1
|
||||||
|
tmux.until { |lines| lines[-1].include?('cat') || lines[-2].include?('cat') }
|
||||||
|
tmux.send_keys :Enter
|
||||||
|
tmux.until { |lines| lines[-1].include? 'test3test4' }
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class TestBash < TestBase
|
class TestBash < TestBase
|
||||||
|
Reference in New Issue
Block a user