mirror of
https://github.com/junegunn/fzf.git
synced 2025-08-01 12:42:01 -07:00
Compare commits
52 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
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 |
31
CHANGELOG.md
31
CHANGELOG.md
@@ -1,6 +1,37 @@
|
||||
CHANGELOG
|
||||
=========
|
||||
|
||||
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
|
||||
------
|
||||
|
||||
|
46
README.md
46
README.md
@@ -151,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
|
||||
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
|
||||
-----------------
|
||||
|
||||
@@ -191,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]`
|
||||
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
|
||||
---------------------------------
|
||||
|
||||
|
@@ -83,7 +83,7 @@ while [ $# -gt 0 ]; do
|
||||
shift
|
||||
done
|
||||
|
||||
if ! [ -n "$TMUX_PANE" -a $lines -gt 15 ]; then
|
||||
if ! [ -n "$TMUX" -a "$lines" -gt 15 ]; then
|
||||
fzf "${args[@]}"
|
||||
exit $?
|
||||
fi
|
||||
@@ -134,20 +134,22 @@ mkfifo -m o+w $fifo3
|
||||
# Build arguments to fzf
|
||||
opts=""
|
||||
for arg in "${args[@]}"; do
|
||||
arg="${arg//\\/\\\\}"
|
||||
arg="${arg//\"/\\\"}"
|
||||
arg="${arg//\`/\\\`}"
|
||||
arg="${arg//$/\\$}"
|
||||
opts="$opts \"$arg\""
|
||||
done
|
||||
|
||||
if [ -n "$term" -o -t 0 ]; then
|
||||
cat <<< "$fzf $opts > $fifo2; echo \$? > $fifo3 $close" > $argsf
|
||||
cat <<< "\"$fzf\" $opts > $fifo2; echo \$? > $fifo3 $close" > $argsf
|
||||
tmux set-window-option synchronize-panes off \;\
|
||||
set-window-option remain-on-exit off \;\
|
||||
split-window $opt "cd $(printf %q "$PWD");$envs bash $argsf" $swap \
|
||||
> /dev/null 2>&1
|
||||
else
|
||||
mkfifo $fifo1
|
||||
cat <<< "$fzf $opts < $fifo1 > $fifo2; echo \$? > $fifo3 $close" > $argsf
|
||||
cat <<< "\"$fzf\" $opts < $fifo1 > $fifo2; echo \$? > $fifo3 $close" > $argsf
|
||||
tmux set-window-option synchronize-panes off \;\
|
||||
set-window-option remain-on-exit off \;\
|
||||
split-window $opt "$envs bash $argsf" $swap \
|
||||
|
14
install
14
install
@@ -2,8 +2,8 @@
|
||||
|
||||
set -u
|
||||
|
||||
[[ "$@" =~ --pre ]] && version=0.12.1 pre=1 ||
|
||||
version=0.12.1 pre=0
|
||||
[[ "$@" =~ --pre ]] && version=0.13.2 pre=1 ||
|
||||
version=0.13.2 pre=0
|
||||
|
||||
auto_completion=
|
||||
key_bindings=
|
||||
@@ -230,10 +230,14 @@ if [ -n "$binary_error" ]; then
|
||||
if [ $binary_available -eq 0 ]; then
|
||||
echo "No prebuilt binary for $archi ..."
|
||||
if command -v go > /dev/null; then
|
||||
echo -n "Building binary (go get github.com/junegunn/fzf/src/fzf) ... "
|
||||
if go get github.com/junegunn/fzf/src/fzf; 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"
|
||||
link_fzf_in_path
|
||||
cp "$GOPATH/bin/fzf" "$fzf_base/bin/"
|
||||
else
|
||||
echo "Failed to build binary ..."
|
||||
install_ruby_fzf
|
||||
|
412
man/man1/fzf.1
412
man/man1/fzf.1
@@ -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
|
||||
THE SOFTWARE.
|
||||
..
|
||||
.TH fzf 1 "Apr 2016" "fzf 0.12.1" "fzf - a command-line fuzzy finder"
|
||||
.TH fzf 1 "Jun 2016" "fzf 0.13.2" "fzf - a command-line fuzzy finder"
|
||||
|
||||
.SH NAME
|
||||
fzf - a command-line fuzzy finder
|
||||
@@ -50,10 +50,10 @@ Case-sensitive match
|
||||
.TP
|
||||
.BI "-n, --nth=" "N[,..]"
|
||||
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
|
||||
.BI "--with-nth=" "N[,..]"
|
||||
Transform each item using index expressions within finder
|
||||
Transform the presentation of each line using field index expressions
|
||||
.TP
|
||||
.BI "-d, --delimiter=" "STR"
|
||||
Field delimiter regex for \fB--nth\fR and \fB--with-nth\fR (default: AWK-style)
|
||||
@@ -64,6 +64,7 @@ Do not sort the result
|
||||
.TP
|
||||
.B "--tac"
|
||||
Reverse the order of the input
|
||||
|
||||
.RS
|
||||
e.g. \fBhistory | fzf --tac --no-sort\fR
|
||||
.RE
|
||||
@@ -73,13 +74,13 @@ Comma-separated list of sort criteria to apply when the scores are tied.
|
||||
.br
|
||||
|
||||
.br
|
||||
.BR length " Prefers item with shorter length"
|
||||
.BR length " Prefers line with shorter length"
|
||||
.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 end " Prefers item with matched substring closer to the end"
|
||||
.BR end " Prefers line with matched substring closer to the end"
|
||||
.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
|
||||
@@ -90,16 +91,86 @@ Comma-separated list of sort criteria to apply when the scores are tied.
|
||||
- \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
|
||||
.TP
|
||||
.B "-m, --multi"
|
||||
Enable multi-select with tab/shift-tab
|
||||
.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"
|
||||
Enable processing of ANSI color codes
|
||||
.TP
|
||||
.B "--no-mouse"
|
||||
Disable mouse
|
||||
.BI "--tabstop=" SPACES
|
||||
Number of spaces for a tab character (default: 8)
|
||||
.TP
|
||||
.BI "--color=" "[BASE_SCHEME][,COLOR:ANSI]"
|
||||
Color configuration. The name of the base color scheme is followed by custom
|
||||
@@ -137,172 +208,7 @@ e.g. \fBfzf --color=bg+:24\fR
|
||||
.TP
|
||||
.B "--black"
|
||||
Use black background
|
||||
.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
|
||||
.BI "--tabstop=" SPACES
|
||||
Number of spaces for a tab character (default: 8)
|
||||
.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
|
||||
.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: (SYNONYMS)
|
||||
\fIctrl-[a-z]\fR
|
||||
\fIalt-[a-z]\fR
|
||||
\fIf[1-4]\fR
|
||||
\fIenter\fR (\fIreturn\fR \fIctrl-m\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
|
||||
\fIdouble-click\fR
|
||||
or any single character
|
||||
.RE
|
||||
|
||||
.RS
|
||||
\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
|
||||
\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-in\fR (\fB--reverse\fR ? \fBtoggle-up\fR : \fBtoggle-down\fR)
|
||||
\fBtoggle-out\fR (\fB--reverse\fR ? \fBtoggle-down\fR : \fBtoggle-up\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
|
||||
|
||||
\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 double-quoted strings of the
|
||||
selected entries separated by spaces.
|
||||
|
||||
.RE
|
||||
.SS History
|
||||
.TP
|
||||
.BI "--history=" "HISTORY_FILE"
|
||||
Load search history from the specified file and update the file on completion.
|
||||
@@ -312,17 +218,34 @@ When enabled, \fBCTRL-N\fR and \fBCTRL-P\fR are automatically remapped to
|
||||
.BI "--history-size=" "N"
|
||||
Maximum number of entries in the history file (default: 1000). The file is
|
||||
automatically truncated when the number of the lines exceeds the value.
|
||||
.SS Preview
|
||||
.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.
|
||||
.BI "--preview=" "COMMAND"
|
||||
Execute the given command for the current line and display the result on the
|
||||
preview window. \fB{}\fR is the placeholder for the quoted string of the
|
||||
current line.
|
||||
|
||||
.RS
|
||||
e.g. \fBfzf --preview="head -$LINES {}"\fR
|
||||
.RE
|
||||
.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.
|
||||
.BI "--preview-window=" "[POSITION][:SIZE[%]][:hidden]"
|
||||
Determine the layout of the preview window. If the argument ends with
|
||||
\fB:hidden\fR, the preview window will be hidden by default until
|
||||
\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
|
||||
.TP
|
||||
.BI "-q, --query=" "STR"
|
||||
@@ -347,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
|
||||
\fB--print-query\fR is also used). The line will be empty if fzf is completed
|
||||
with the default enter key.
|
||||
|
||||
.RS
|
||||
e.g. \fBfzf --expect=ctrl-v,ctrl-t,alt-s,f1,f2,~,@\fR
|
||||
.RE
|
||||
@@ -354,11 +278,12 @@ e.g. \fBfzf --expect=ctrl-v,ctrl-t,alt-s,f1,f2,~,@\fR
|
||||
.B "--sync"
|
||||
Synchronous search for multi-staged filtering. If specified, fzf will launch
|
||||
ncurses finder only after the input stream is complete.
|
||||
|
||||
.RS
|
||||
e.g. \fBfzf --multi | fzf --sync\fR
|
||||
.RE
|
||||
|
||||
.SH ENVIRONMENT
|
||||
.SH ENVIRONMENT VARIABLES
|
||||
.TP
|
||||
.B FZF_DEFAULT_COMMAND
|
||||
Default command to use when input is tty
|
||||
@@ -412,11 +337,11 @@ occurrences of the string.
|
||||
|
||||
.SS Anchored-match
|
||||
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.
|
||||
|
||||
.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.
|
||||
|
||||
.SS Exact-match by default
|
||||
@@ -431,6 +356,119 @@ query matches entries that start with \fBcore\fR and end with either \fBgo\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
|
||||
Junegunn Choi (\fIjunegunn.c@gmail.com\fR)
|
||||
|
||||
|
@@ -49,7 +49,7 @@ function! s:fzf_exec()
|
||||
throw 'fzf executable not found'
|
||||
endif
|
||||
endif
|
||||
return s:exec
|
||||
return s:shellesc(s:exec)
|
||||
endfunction
|
||||
|
||||
function! s:tmux_enabled()
|
||||
@@ -140,10 +140,10 @@ try
|
||||
else
|
||||
let prefix = ''
|
||||
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
|
||||
|
||||
if has('nvim')
|
||||
if has('nvim') && !tmux
|
||||
return s:execute_term(dict, command, temps)
|
||||
endif
|
||||
|
||||
@@ -179,7 +179,7 @@ function! s:fzf_tmux(dict)
|
||||
endif
|
||||
endfor
|
||||
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
|
||||
|
||||
function! s:splittable(dict)
|
||||
@@ -193,7 +193,7 @@ function! s:pushd(dict)
|
||||
return 1
|
||||
endif
|
||||
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()
|
||||
return 1
|
||||
endif
|
||||
@@ -214,7 +214,7 @@ function! s:popd(dict, lines)
|
||||
" directory is not expected and should be undone.
|
||||
if has_key(a:dict, 'prev_dir') &&
|
||||
\ (!&autochdir || (empty(a:lines) || len(a:lines) == 1 && empty(a:lines[0])))
|
||||
execute 'chdir' s:escape(remove(a:dict, 'prev_dir'))
|
||||
execute 'lcd' s:escape(remove(a:dict, 'prev_dir'))
|
||||
endif
|
||||
endfunction
|
||||
|
||||
@@ -298,7 +298,7 @@ function! s:split(dict)
|
||||
\ 'down': ['botright', 'resize', &lines],
|
||||
\ 'left': ['vertical topleft', 'vertical resize', &columns],
|
||||
\ 'right': ['vertical botright', 'vertical resize', &columns] }
|
||||
let s:ppos = s:getpos()
|
||||
let ppos = s:getpos()
|
||||
try
|
||||
for [dir, triple] in items(directions)
|
||||
let val = get(a:dict, dir, '')
|
||||
@@ -311,7 +311,7 @@ function! s:split(dict)
|
||||
endif
|
||||
execute cmd sz.'new'
|
||||
execute resz sz
|
||||
return {}
|
||||
return [ppos, {}]
|
||||
endif
|
||||
endfor
|
||||
if s:present(a:dict, 'window')
|
||||
@@ -319,36 +319,44 @@ function! s:split(dict)
|
||||
else
|
||||
execute (tabpagenr()-1).'tabnew'
|
||||
endif
|
||||
return { '&l:wfw': &l:wfw, '&l:wfh': &l:wfh }
|
||||
return [ppos, { '&l:wfw': &l:wfw, '&l:wfh': &l:wfh }]
|
||||
finally
|
||||
setlocal winfixwidth winfixheight
|
||||
endtry
|
||||
endfunction
|
||||
|
||||
function! s:execute_term(dict, command, temps) abort
|
||||
let winopts = s:split(a:dict)
|
||||
|
||||
let fzf = { 'buf': bufnr('%'), 'dict': a:dict, 'temps': a:temps, 'name': 'FZF', 'winopts': winopts }
|
||||
let s:command = a:command
|
||||
let [ppos, winopts] = s:split(a:dict)
|
||||
let fzf = { 'buf': bufnr('%'), 'ppos': ppos, 'dict': a:dict, 'temps': a:temps,
|
||||
\ 'name': 'FZF', 'winopts': winopts, 'command': a:command }
|
||||
function! fzf.switch_back(inplace)
|
||||
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)
|
||||
let pos = s:getpos()
|
||||
let inplace = pos == s:ppos " {'window': 'enew'}
|
||||
if inplace
|
||||
if s:getpos() == self.ppos " {'window': 'enew'}
|
||||
for [opt, val] in items(self.winopts)
|
||||
execute 'let' opt '=' val
|
||||
endfor
|
||||
call self.switch_back(1)
|
||||
else
|
||||
if bufnr('') == self.buf
|
||||
" We use close instead of bd! since Vim does not close the split when
|
||||
" there's no other listed buffer (nvim +'set nobuflisted')
|
||||
close
|
||||
endif
|
||||
if pos.tab == s:ppos.tab
|
||||
wincmd p
|
||||
endif
|
||||
execute 'tabnext' self.ppos.tab
|
||||
execute self.ppos.win.'wincmd w'
|
||||
endif
|
||||
|
||||
if !s:exit_handler(a:code, s:command, 1)
|
||||
if !s:exit_handler(a:code, self.command, 1)
|
||||
return
|
||||
endif
|
||||
|
||||
@@ -356,14 +364,7 @@ function! s:execute_term(dict, command, temps) abort
|
||||
let ret = []
|
||||
try
|
||||
let ret = s:callback(self.dict, self.temps)
|
||||
|
||||
if inplace && bufnr('') == self.buf
|
||||
execute "normal! \<c-^>"
|
||||
" No other listed buffer
|
||||
if bufnr('') == self.buf
|
||||
bd!
|
||||
endif
|
||||
endif
|
||||
call self.switch_back(s:getpos() == self.ppos)
|
||||
finally
|
||||
call s:popd(self.dict, ret)
|
||||
endtry
|
||||
|
@@ -221,6 +221,7 @@ _fzf_complete_telnet() {
|
||||
_fzf_complete_ssh() {
|
||||
_fzf_complete '+m' "$@" < <(
|
||||
cat <(cat ~/.ssh/config /etc/ssh/ssh_config 2> /dev/null | \grep -i '^host' | \grep -v '*') \
|
||||
<(\grep -oE '^[^ ]+' ~/.ssh/known_hosts | tr ',' '\n' | awk '{ print $1 " " $1 }') \
|
||||
<(\grep -v '^\s*\(#\|$\)' /etc/hosts | \grep -Fv '0.0.0.0') |
|
||||
awk '{if (length($2) > 0) {print $2}}' | sort -u
|
||||
)
|
||||
|
@@ -31,7 +31,7 @@ fi
|
||||
###########################################################
|
||||
|
||||
__fzf_generic_path_completion() {
|
||||
local base lbuf compgen 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"
|
||||
base=${(Q)1}
|
||||
lbuf=$2
|
||||
@@ -41,10 +41,7 @@ __fzf_generic_path_completion() {
|
||||
tail=$6
|
||||
[ ${FZF_TMUX:-1} -eq 1 ] && fzf="fzf-tmux -d ${FZF_TMUX_HEIGHT:-40%}" || fzf="fzf"
|
||||
|
||||
if ! setopt | \grep nonomatch > /dev/null; then
|
||||
nnm=1
|
||||
setopt nonomatch
|
||||
fi
|
||||
setopt localoptions nonomatch
|
||||
dir="$base"
|
||||
while [ 1 ]; do
|
||||
if [ -z "$dir" -o -d ${~dir} ]; then
|
||||
@@ -66,7 +63,6 @@ __fzf_generic_path_completion() {
|
||||
dir=$(dirname "$dir")
|
||||
dir=${dir%/}/
|
||||
done
|
||||
[ -n "$nnm" ] && unsetopt nonomatch
|
||||
}
|
||||
|
||||
_fzf_path_completion() {
|
||||
@@ -114,6 +110,7 @@ _fzf_complete_telnet() {
|
||||
_fzf_complete_ssh() {
|
||||
_fzf_complete '+m' "$@" < <(
|
||||
cat <(cat ~/.ssh/config /etc/ssh/ssh_config 2> /dev/null | \grep -i '^host' | \grep -v '*') \
|
||||
<(\grep -oE '^[^ ]+' ~/.ssh/known_hosts | tr ',' '\n' | awk '{ print $1 " " $1 }') \
|
||||
<(\grep -v '^\s*\(#\|$\)' /etc/hosts | \grep -Fv '0.0.0.0') |
|
||||
awk '{if (length($2) > 0) {print $2}}' | sort -u
|
||||
)
|
||||
@@ -184,8 +181,11 @@ fzf-completion() {
|
||||
fi
|
||||
}
|
||||
|
||||
[ -z "$fzf_default_completion" ] &&
|
||||
fzf_default_completion=$(bindkey '^I' | \grep -v undefined-key | awk '{print $2}')
|
||||
[ -z "$fzf_default_completion" ] && {
|
||||
binding=$(bindkey '^I')
|
||||
[[ $binding =~ 'undefined-key' ]] || fzf_default_completion=$binding[(w)2]
|
||||
unset binding
|
||||
}
|
||||
|
||||
zle -N fzf-completion
|
||||
bindkey '^I' fzf-completion
|
||||
|
@@ -5,7 +5,7 @@ __fzf_select__() {
|
||||
-o -type f -print \
|
||||
-o -type d -print \
|
||||
-o -type l -print 2> /dev/null | sed 1d | cut -b3-"}"
|
||||
eval "$cmd" | fzf -m | while read -r item; do
|
||||
eval "$cmd | fzf -m $FZF_CTRL_T_OPTS" | while read -r item; do
|
||||
printf '%q ' "$item"
|
||||
done
|
||||
echo
|
||||
@@ -26,7 +26,7 @@ __fzf_select_tmux__() {
|
||||
height="-l $height"
|
||||
fi
|
||||
|
||||
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") bash -c 'source \"${BASH_SOURCE[0]}\"; 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]}\"; tmux send-keys -t $TMUX_PANE \"\$(__fzf_select__)\"'"
|
||||
}
|
||||
|
||||
fzf-file-widget() {
|
||||
@@ -43,7 +43,7 @@ __fzf_cd__() {
|
||||
local cmd dir
|
||||
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-"}"
|
||||
dir=$(eval "$cmd" | $(__fzfcmd) +m) && printf 'cd %q' "$dir"
|
||||
dir=$(eval "$cmd | $(__fzfcmd) +m $FZF_ALT_C_OPTS") && printf 'cd %q' "$dir"
|
||||
}
|
||||
|
||||
__fzf_history__() (
|
||||
@@ -51,7 +51,7 @@ __fzf_history__() (
|
||||
shopt -u nocaseglob nocasematch
|
||||
line=$(
|
||||
HISTTIMEFORMAT= history |
|
||||
$(__fzfcmd) +s --tac +m -n2..,.. --tiebreak=index --toggle-sort=ctrl-r $FZF_CTRL_R_OPTS |
|
||||
eval "$(__fzfcmd) +s --tac +m -n2..,.. --tiebreak=index --toggle-sort=ctrl-r $FZF_CTRL_R_OPTS" |
|
||||
\grep '^ *[0-9]') &&
|
||||
if [[ $- =~ H ]]; then
|
||||
sed 's/^ *\([0-9]*\)\** .*/!\1/' <<< "$line"
|
||||
@@ -67,7 +67,7 @@ __fzf_use_tmux__() {
|
||||
[ $BASH_VERSINFO -gt 3 ] && __use_bind_x=1 || __use_bind_x=0
|
||||
__fzf_use_tmux__ && __use_tmux=1 || __use_tmux=0
|
||||
|
||||
if [[ $'\n'$(set -o) != *$'\n'vi*on* ]]; then
|
||||
if [[ ! -o vi ]]; then
|
||||
# Required to refresh the prompt after fzf
|
||||
bind '"\er": redraw-current-line'
|
||||
bind '"\e^": history-expand-line'
|
||||
@@ -82,10 +82,10 @@ if [[ $'\n'$(set -o) != *$'\n'vi*on* ]]; then
|
||||
fi
|
||||
|
||||
# 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
|
||||
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
|
||||
# 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,
|
||||
|
@@ -19,7 +19,7 @@ function fzf_key_bindings
|
||||
-o -type f -print \
|
||||
-o -type d -print \
|
||||
-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 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
|
||||
rm -f $TMPDIR/fzf.result
|
||||
@@ -37,7 +37,7 @@ function fzf_key_bindings
|
||||
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)
|
||||
eval "$FZF_ALT_C_COMMAND | "(__fzfcmd)" +m > $TMPDIR/fzf.result"
|
||||
eval "$FZF_ALT_C_COMMAND | "(__fzfcmd)" +m $FZF_ALT_C_OPTS > $TMPDIR/fzf.result"
|
||||
[ (cat $TMPDIR/fzf.result | wc -l) -gt 0 ]
|
||||
and cd (cat $TMPDIR/fzf.result)
|
||||
commandline -f repaint
|
||||
|
@@ -8,7 +8,7 @@ __fsel() {
|
||||
-o -type f -print \
|
||||
-o -type d -print \
|
||||
-o -type l -print 2> /dev/null | sed 1d | cut -b3-"}"
|
||||
eval "$cmd" | $(__fzfcmd) -m | while read item; do
|
||||
eval "$cmd | $(__fzfcmd) -m $FZF_CTRL_T_OPTS" | while read item; do
|
||||
echo -n "${(q)item} "
|
||||
done
|
||||
echo
|
||||
@@ -29,7 +29,7 @@ bindkey '^T' fzf-file-widget
|
||||
fzf-cd-widget() {
|
||||
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-"}"
|
||||
cd "${$(eval "$cmd" | $(__fzfcmd) +m):-.}"
|
||||
cd "${$(eval "$cmd | $(__fzfcmd) +m $FZF_ALT_C_OPTS"):-.}"
|
||||
zle reset-prompt
|
||||
}
|
||||
zle -N fzf-cd-widget
|
||||
@@ -38,7 +38,8 @@ bindkey '\ec' fzf-cd-widget
|
||||
# CTRL-R - Paste the selected command from history into the command line
|
||||
fzf-history-widget() {
|
||||
local selected num
|
||||
selected=( $(fc -l 1 | $(__fzfcmd) +s --tac +m -n2..,.. --tiebreak=index --toggle-sort=ctrl-r ${=FZF_CTRL_R_OPTS} -q "${LBUFFER//$/\\$}") )
|
||||
setopt localoptions noglobsubst
|
||||
selected=( $(fc -l 1 | eval "$(__fzfcmd) +s --tac +m -n2..,.. --tiebreak=index --toggle-sort=ctrl-r $FZF_CTRL_R_OPTS -q ${(q)LBUFFER}") )
|
||||
if [ -n "$selected" ]; then
|
||||
num=$selected[1]
|
||||
if [ -n "$num" ]; then
|
||||
|
37
src/Makefile
37
src/Makefile
@@ -7,10 +7,6 @@ else ifeq ($(UNAME_S),Linux)
|
||||
endif
|
||||
endif
|
||||
|
||||
ifneq ($(shell uname -m),x86_64)
|
||||
$(error "Build on $(UNAME_M) is not supported, yet.")
|
||||
endif
|
||||
|
||||
SOURCES := $(wildcard *.go */*.go)
|
||||
ROOTDIR := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
|
||||
BINDIR := $(shell dirname $(ROOTDIR))/bin
|
||||
@@ -26,15 +22,22 @@ 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: test build
|
||||
all: fzf/$(BINARY)
|
||||
|
||||
release: test fzf/$(BINARY32) fzf/$(BINARY64)
|
||||
-cd fzf && cp $(BINARY32) $(RELEASE32) && tar -czf $(RELEASE32).tgz $(RELEASE32)
|
||||
cd fzf && cp $(BINARY64) $(RELEASE64) && tar -czf $(RELEASE64).tgz $(RELEASE64) && \
|
||||
rm -f $(RELEASE32) $(RELEASE64)
|
||||
|
||||
build: fzf/$(BINARY32) fzf/$(BINARY64)
|
||||
|
||||
$(SRCDIR):
|
||||
mkdir -p $(shell dirname $(SRCDIR))
|
||||
ln -s $(ROOTDIR) $(SRCDIR)
|
||||
@@ -44,7 +47,7 @@ deps: $(SRCDIR) $(SOURCES)
|
||||
|
||||
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="-extldflags=-pie" -o $(BINARYARM7)
|
||||
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)
|
||||
|
||||
@@ -54,20 +57,20 @@ test: deps
|
||||
install: $(BINDIR)/fzf
|
||||
|
||||
uninstall:
|
||||
rm -f $(BINDIR)/fzf $(BINDIR)/$(BINARY64)
|
||||
rm -f $(BINDIR)/fzf $(BINDIR)/$(BINARY)
|
||||
|
||||
clean:
|
||||
cd fzf && rm -f fzf-*
|
||||
|
||||
fzf/$(BINARY32): deps
|
||||
cd fzf && GOARCH=386 CGO_ENABLED=1 go build -a -tags "$(TAGS)" -o $(BINARY32)
|
||||
cd fzf && GOARCH=386 CGO_ENABLED=1 go build -a -ldflags -w -tags "$(TAGS)" -o $(BINARY32)
|
||||
|
||||
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)
|
||||
cp -f fzf/$(BINARY64) $(BINDIR)
|
||||
cd $(BINDIR) && ln -sf $(BINARY64) fzf
|
||||
$(BINDIR)/fzf: fzf/$(BINARY) | $(BINDIR)
|
||||
cp -f fzf/$(BINARY) $(BINDIR)
|
||||
cd $(BINDIR) && ln -sf $(BINARY) fzf
|
||||
|
||||
$(BINDIR):
|
||||
mkdir -p $@
|
||||
@@ -98,7 +101,7 @@ centos: docker-centos
|
||||
|
||||
linux: docker-centos
|
||||
docker run $(DOCKEROPTS) junegunn/centos-sandbox \
|
||||
/bin/bash -ci 'cd /fzf/src; make TAGS=static'
|
||||
/bin/bash -ci 'cd /fzf/src; make TAGS=static release'
|
||||
|
||||
ubuntu-android: docker-android
|
||||
docker run $(DOCKEROPTS) junegunn/android-sandbox \
|
||||
@@ -108,6 +111,6 @@ android: docker-android
|
||||
docker run $(DOCKEROPTS) junegunn/android-sandbox \
|
||||
/bin/bash -ci 'cd /fzf/src; GOOS=android make android-build'
|
||||
|
||||
.PHONY: all build deps release test install uninstall clean \
|
||||
.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
|
||||
# Build fzf executables and tarballs
|
||||
make
|
||||
make release
|
||||
|
||||
# Install the executable to ../bin directory
|
||||
make install
|
||||
|
11
src/ansi.go
11
src/ansi.go
@@ -36,7 +36,7 @@ func init() {
|
||||
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 output bytes.Buffer
|
||||
|
||||
@@ -46,7 +46,11 @@ func extractColor(str string, state *ansiState) (string, []ansiOffset, *ansiStat
|
||||
|
||||
idx := 0
|
||||
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) {
|
||||
break
|
||||
}
|
||||
newState := interpretCode(str[offset[0]:offset[1]], 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()))
|
||||
}
|
||||
}
|
||||
if proc != nil {
|
||||
proc(rest, state)
|
||||
}
|
||||
return output.String(), offsets, state
|
||||
}
|
||||
|
||||
|
@@ -17,7 +17,7 @@ func TestExtractColor(t *testing.T) {
|
||||
var state *ansiState
|
||||
clean := "\x1b[0m"
|
||||
check := func(assertion func(ansiOffsets []ansiOffset, state *ansiState)) {
|
||||
output, ansiOffsets, newState := extractColor(src, state)
|
||||
output, ansiOffsets, newState := extractColor(src, state, nil)
|
||||
state = newState
|
||||
if output != "hello world" {
|
||||
t.Errorf("Invalid output: {}", output)
|
||||
|
@@ -8,7 +8,7 @@ import (
|
||||
|
||||
const (
|
||||
// Current version
|
||||
version = "0.12.1"
|
||||
version = "0.13.2"
|
||||
|
||||
// Core
|
||||
coordinatorDelayMax time.Duration = 100 * time.Millisecond
|
||||
@@ -36,6 +36,9 @@ const (
|
||||
|
||||
// History
|
||||
defaultHistoryMax int = 1000
|
||||
|
||||
// Jump labels
|
||||
defaultJumpLabels string = "asdfghjklqwertyuiopzxcvbnm1234567890ASDFGHJKLQWERTYUIOPZXCVBNM`~;:,<.>/?'\"!@#$%^&*()[{]}-_=+"
|
||||
)
|
||||
|
||||
// fzf events
|
||||
|
@@ -73,7 +73,7 @@ func Run(opts *Options) {
|
||||
if opts.Theme != nil {
|
||||
var state *ansiState
|
||||
ansiProcessor = func(data []byte) ([]rune, []ansiOffset) {
|
||||
trimmed, offsets, newState := extractColor(string(data), state)
|
||||
trimmed, offsets, newState := extractColor(string(data), state, nil)
|
||||
state = newState
|
||||
return []rune(trimmed), offsets
|
||||
}
|
||||
@@ -81,7 +81,7 @@ func Run(opts *Options) {
|
||||
// When color is disabled but ansi option is given,
|
||||
// we simply strip out ANSI codes from the input
|
||||
ansiProcessor = func(data []byte) ([]rune, []ansiOffset) {
|
||||
trimmed, _, _ := extractColor(string(data), nil)
|
||||
trimmed, _, _ := extractColor(string(data), nil, nil)
|
||||
return []rune(trimmed), nil
|
||||
}
|
||||
}
|
||||
|
@@ -80,7 +80,16 @@ const (
|
||||
F2
|
||||
F3
|
||||
F4
|
||||
F5
|
||||
F6
|
||||
F7
|
||||
F8
|
||||
F9
|
||||
F10
|
||||
|
||||
AltEnter
|
||||
AltSpace
|
||||
AltSlash
|
||||
AltBS
|
||||
AltA
|
||||
AltB
|
||||
@@ -104,11 +113,14 @@ const (
|
||||
ColCursor
|
||||
ColSelected
|
||||
ColHeader
|
||||
ColUser
|
||||
ColBorder
|
||||
ColUser // Should be the last entry
|
||||
)
|
||||
|
||||
const (
|
||||
doubleClickDuration = 500 * time.Millisecond
|
||||
colDefault = -1
|
||||
colUndefined = -2
|
||||
)
|
||||
|
||||
type ColorTheme struct {
|
||||
@@ -125,6 +137,7 @@ type ColorTheme struct {
|
||||
Cursor int16
|
||||
Selected int16
|
||||
Header int16
|
||||
Border int16
|
||||
}
|
||||
|
||||
type Event struct {
|
||||
@@ -159,6 +172,49 @@ var (
|
||||
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() {
|
||||
_prevDownTime = time.Unix(0, 0)
|
||||
_clickY = []int{}
|
||||
@@ -176,7 +232,8 @@ func init() {
|
||||
Info: C.COLOR_WHITE,
|
||||
Cursor: C.COLOR_RED,
|
||||
Selected: C.COLOR_MAGENTA,
|
||||
Header: C.COLOR_CYAN}
|
||||
Header: C.COLOR_CYAN,
|
||||
Border: C.COLOR_BLACK}
|
||||
Dark256 = &ColorTheme{
|
||||
UseDefault: true,
|
||||
Fg: 15,
|
||||
@@ -190,7 +247,8 @@ func init() {
|
||||
Info: 144,
|
||||
Cursor: 161,
|
||||
Selected: 168,
|
||||
Header: 109}
|
||||
Header: 109,
|
||||
Border: 59}
|
||||
Light256 = &ColorTheme{
|
||||
UseDefault: true,
|
||||
Fg: 15,
|
||||
@@ -204,7 +262,8 @@ func init() {
|
||||
Info: 101,
|
||||
Cursor: 161,
|
||||
Selected: 168,
|
||||
Header: 31}
|
||||
Header: 31,
|
||||
Border: 145}
|
||||
}
|
||||
|
||||
func attrColored(pair int, bold bool) C.int {
|
||||
@@ -280,44 +339,59 @@ func Init(theme *ColorTheme, black bool, mouse bool) {
|
||||
|
||||
if theme != nil {
|
||||
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
|
||||
} else {
|
||||
_color = attrMono
|
||||
}
|
||||
}
|
||||
|
||||
func initPairs(theme *ColorTheme, black bool) {
|
||||
fg := C.short(theme.Fg)
|
||||
bg := C.short(theme.Bg)
|
||||
func override(a int16, b int16) C.short {
|
||||
if b == colUndefined {
|
||||
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 {
|
||||
bg = C.COLOR_BLACK
|
||||
} else if theme.UseDefault {
|
||||
fg = -1
|
||||
bg = -1
|
||||
fg = colDefault
|
||||
bg = colDefault
|
||||
C.use_default_colors()
|
||||
}
|
||||
if theme.UseDefault {
|
||||
FG = -1
|
||||
BG = -1
|
||||
FG = colDefault
|
||||
BG = colDefault
|
||||
} else {
|
||||
FG = int(fg)
|
||||
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)
|
||||
DarkBG = int(theme.DarkBg)
|
||||
darkBG := C.short(DarkBG)
|
||||
C.init_pair(ColPrompt, C.short(theme.Prompt), bg)
|
||||
C.init_pair(ColMatch, C.short(theme.Match), bg)
|
||||
C.init_pair(ColCurrent, C.short(theme.Current), darkBG)
|
||||
C.init_pair(ColCurrentMatch, C.short(theme.CurrentMatch), darkBG)
|
||||
C.init_pair(ColSpinner, C.short(theme.Spinner), bg)
|
||||
C.init_pair(ColInfo, C.short(theme.Info), bg)
|
||||
C.init_pair(ColCursor, C.short(theme.Cursor), darkBG)
|
||||
C.init_pair(ColSelected, C.short(theme.Selected), darkBG)
|
||||
C.init_pair(ColHeader, C.short(theme.Header), bg)
|
||||
currentFG := override(baseTheme.Current, theme.Current)
|
||||
darkBG := override(baseTheme.DarkBg, theme.DarkBg)
|
||||
CurrentFG = int(currentFG)
|
||||
DarkBG = int(darkBG)
|
||||
C.init_pair(ColPrompt, override(baseTheme.Prompt, theme.Prompt), bg)
|
||||
C.init_pair(ColMatch, override(baseTheme.Match, theme.Match), bg)
|
||||
C.init_pair(ColCurrent, currentFG, darkBG)
|
||||
C.init_pair(ColCurrentMatch, override(baseTheme.CurrentMatch, theme.CurrentMatch), darkBG)
|
||||
C.init_pair(ColSpinner, override(baseTheme.Spinner, theme.Spinner), bg)
|
||||
C.init_pair(ColInfo, override(baseTheme.Info, theme.Info), bg)
|
||||
C.init_pair(ColCursor, override(baseTheme.Cursor, theme.Cursor), darkBG)
|
||||
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() {
|
||||
@@ -373,7 +447,9 @@ func mouseSequence(sz *int) Event {
|
||||
97, 101, 105, 113: // scroll-down / shift / cmd / ctrl
|
||||
mod := _buf[3] >= 100
|
||||
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}
|
||||
}
|
||||
@@ -384,6 +460,12 @@ func escSequence(sz *int) Event {
|
||||
}
|
||||
*sz = 2
|
||||
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:
|
||||
return Event{AltB, 0, nil}
|
||||
case 100:
|
||||
@@ -429,6 +511,20 @@ func escSequence(sz *int) Event {
|
||||
*sz = 4
|
||||
switch _buf[2] {
|
||||
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
|
||||
case 51:
|
||||
return Event{Del, 0, nil}
|
||||
@@ -442,6 +538,21 @@ func escSequence(sz *int) Event {
|
||||
switch _buf[3] {
|
||||
case 126:
|
||||
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:
|
||||
if len(_buf) != 6 {
|
||||
return Event{Invalid, 0, nil}
|
||||
@@ -511,17 +622,25 @@ func GetChar() Event {
|
||||
return Event{Rune, r, nil}
|
||||
}
|
||||
|
||||
func Move(y int, x int) {
|
||||
C.move(C.int(y), C.int(x))
|
||||
func (w *Window) Close() {
|
||||
C.delwin(w.win)
|
||||
}
|
||||
|
||||
func MoveAndClear(y int, x int) {
|
||||
Move(y, x)
|
||||
C.clrtoeol()
|
||||
func (w *Window) Enclose(y int, x int) bool {
|
||||
return bool(C.wenclose(w.win, C.int(y), C.int(x)))
|
||||
}
|
||||
|
||||
func Print(text string) {
|
||||
C.addstr(C.CString(strings.Map(func(r rune) rune {
|
||||
func (w *Window) Move(y int, x int) {
|
||||
C.wmove(w.win, C.int(y), C.int(x))
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
@@ -529,11 +648,11 @@ func Print(text string) {
|
||||
}, text)))
|
||||
}
|
||||
|
||||
func CPrint(pair int, bold bool, text string) {
|
||||
func (w *Window) CPrint(pair int, bold bool, text string) {
|
||||
attr := _color(pair, bold)
|
||||
C.attron(attr)
|
||||
Print(text)
|
||||
C.attroff(attr)
|
||||
C.wattron(w.win, attr)
|
||||
w.Print(text)
|
||||
C.wattroff(w.win, attr)
|
||||
}
|
||||
|
||||
func Clear() {
|
||||
@@ -548,6 +667,30 @@ func 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 {
|
||||
key := (fg << 8) + bg
|
||||
if found, prs := _colorMap[key]; prs {
|
||||
|
@@ -128,7 +128,7 @@ func (item *Item) AsString(stripAnsi bool) string {
|
||||
func (item *Item) StringPtr(stripAnsi bool) *string {
|
||||
if item.origText != nil {
|
||||
if stripAnsi {
|
||||
trimmed, _, _ := extractColor(string(*item.origText), nil)
|
||||
trimmed, _, _ := extractColor(string(*item.origText), nil, nil)
|
||||
return &trimmed
|
||||
}
|
||||
orig := string(*item.origText)
|
||||
|
218
src/options.go
218
src/options.go
@@ -1,6 +1,7 @@
|
||||
package fzf
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"regexp"
|
||||
"strconv"
|
||||
@@ -23,35 +24,47 @@ const usage = `usage: fzf [options]
|
||||
-n, --nth=N[,..] Comma-separated list of field index expressions
|
||||
for limiting search scope. Each can be a non-zero
|
||||
integer or a range expression ([BEGIN]..[END]).
|
||||
--with-nth=N[,..] Transform item using index expressions within finder
|
||||
-d, --delimiter=STR Field delimiter regex for --nth (default: AWK-style)
|
||||
--with-nth=N[,..] Transform the presentation of each line using
|
||||
field index expressions
|
||||
-d, --delimiter=STR Field delimiter regex (default: AWK-style)
|
||||
+s, --no-sort Do not sort the result
|
||||
--tac Reverse the order of the input
|
||||
--tiebreak=CRI[,..] Comma-separated list of sort criteria to apply
|
||||
when the scores are tied;
|
||||
[length|begin|end|index] (default: length)
|
||||
when the scores are tied [length|begin|end|index]
|
||||
(default: length)
|
||||
|
||||
Interface
|
||||
-m, --multi Enable multi-select with tab/shift-tab
|
||||
--ansi Enable processing of ANSI color codes
|
||||
--no-mouse Disable mouse
|
||||
--color=COLSPEC Base scheme (dark|light|16|bw) and/or custom colors
|
||||
--black Use black background
|
||||
--reverse Reverse orientation
|
||||
--margin=MARGIN Screen margin (TRBL / TB,RL / T,RL,B / T,R,B,L)
|
||||
--tabstop=SPACES Number of spaces for a tab character (default: 8)
|
||||
--bind=KEYBINDS Custom key bindings. Refer to the man page.
|
||||
--cycle Enable cyclic 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
|
||||
--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-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
|
||||
-q, --query=STR Start the finder with the given query
|
||||
-1, --select-1 Automatically select the only match
|
||||
@@ -87,8 +100,29 @@ const (
|
||||
byEnd
|
||||
)
|
||||
|
||||
func defaultMargin() [4]string {
|
||||
return [4]string{"0", "0", "0", "0"}
|
||||
type sizeSpec struct {
|
||||
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
|
||||
@@ -112,6 +146,7 @@ type Options struct {
|
||||
Hscroll bool
|
||||
HscrollOff int
|
||||
InlineInfo bool
|
||||
JumpLabels string
|
||||
Prompt string
|
||||
Query string
|
||||
Select1 bool
|
||||
@@ -121,24 +156,18 @@ type Options struct {
|
||||
Expect map[int]string
|
||||
Keymap map[int]actionType
|
||||
Execmap map[int]string
|
||||
Preview previewOpts
|
||||
PrintQuery bool
|
||||
ReadZero bool
|
||||
Sync bool
|
||||
History *History
|
||||
Header []string
|
||||
HeaderLines int
|
||||
Margin [4]string
|
||||
Margin [4]sizeSpec
|
||||
Tabstop int
|
||||
Version bool
|
||||
}
|
||||
|
||||
func defaultTheme() *curses.ColorTheme {
|
||||
if strings.Contains(os.Getenv("TERM"), "256") {
|
||||
return curses.Dark256
|
||||
}
|
||||
return curses.Default16
|
||||
}
|
||||
|
||||
func defaultOptions() *Options {
|
||||
return &Options{
|
||||
Fuzzy: true,
|
||||
@@ -153,13 +182,14 @@ func defaultOptions() *Options {
|
||||
Multi: false,
|
||||
Ansi: false,
|
||||
Mouse: true,
|
||||
Theme: defaultTheme(),
|
||||
Theme: curses.EmptyTheme(),
|
||||
Black: false,
|
||||
Reverse: false,
|
||||
Cycle: false,
|
||||
Hscroll: true,
|
||||
HscrollOff: 10,
|
||||
InlineInfo: false,
|
||||
JumpLabels: defaultJumpLabels,
|
||||
Prompt: "> ",
|
||||
Query: "",
|
||||
Select1: false,
|
||||
@@ -169,6 +199,7 @@ func defaultOptions() *Options {
|
||||
Expect: make(map[int]string),
|
||||
Keymap: make(map[int]actionType),
|
||||
Execmap: make(map[int]string),
|
||||
Preview: previewOpts{"", posRight, sizeSpec{50, true}, false},
|
||||
PrintQuery: false,
|
||||
ReadZero: false,
|
||||
Sync: false,
|
||||
@@ -322,6 +353,12 @@ func parseKeyChords(str string, message string) map[int]string {
|
||||
chord = curses.AltZ + int(' ')
|
||||
case "bspace", "bs":
|
||||
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":
|
||||
chord = curses.AltBS
|
||||
case "tab":
|
||||
@@ -346,12 +383,14 @@ func parseKeyChords(str string, message string) map[int]string {
|
||||
chord = curses.SRight
|
||||
case "double-click":
|
||||
chord = curses.DoubleClick
|
||||
case "f10":
|
||||
chord = curses.F10
|
||||
default:
|
||||
if len(key) == 6 && strings.HasPrefix(lkey, "ctrl-") && isAlphabet(lkey[5]) {
|
||||
chord = curses.CtrlA + int(lkey[5]) - 'a'
|
||||
} else if len(key) == 5 && strings.HasPrefix(lkey, "alt-") && isAlphabet(lkey[4]) {
|
||||
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'
|
||||
} else if utf8.RuneCountInString(key) == 1 {
|
||||
chord = curses.AltZ + int([]rune(key)[0])
|
||||
@@ -454,6 +493,8 @@ func parseTheme(defaultTheme *curses.ColorTheme, str string) *curses.ColorTheme
|
||||
theme.Match = ansi
|
||||
case "hl+":
|
||||
theme.CurrentMatch = ansi
|
||||
case "border":
|
||||
theme.Border = ansi
|
||||
case "prompt":
|
||||
theme.Prompt = ansi
|
||||
case "spinner":
|
||||
@@ -534,6 +575,8 @@ func parseKeymap(keymap map[int]actionType, execmap map[int]string, str string)
|
||||
keymap[key] = actAbort
|
||||
case "accept":
|
||||
keymap[key] = actAccept
|
||||
case "print-query":
|
||||
keymap[key] = actPrintQuery
|
||||
case "backward-char":
|
||||
keymap[key] = actBackwardChar
|
||||
case "backward-delete-char":
|
||||
@@ -554,6 +597,10 @@ func parseKeymap(keymap map[int]actionType, execmap map[int]string, str string)
|
||||
keymap[key] = actForwardChar
|
||||
case "forward-word":
|
||||
keymap[key] = actForwardWord
|
||||
case "jump":
|
||||
keymap[key] = actJump
|
||||
case "jump-accept":
|
||||
keymap[key] = actJumpAccept
|
||||
case "kill-line":
|
||||
keymap[key] = actKillLine
|
||||
case "kill-word":
|
||||
@@ -594,6 +641,8 @@ func parseKeymap(keymap map[int]actionType, execmap map[int]string, str string)
|
||||
keymap[key] = actPreviousHistory
|
||||
case "next-history":
|
||||
keymap[key] = actNextHistory
|
||||
case "toggle-preview":
|
||||
keymap[key] = actTogglePreview
|
||||
case "toggle-sort":
|
||||
keymap[key] = actToggleSort
|
||||
default:
|
||||
@@ -649,40 +698,86 @@ func strLines(str string) []string {
|
||||
return strings.Split(strings.TrimSuffix(str, "\n"), "\n")
|
||||
}
|
||||
|
||||
func parseMargin(margin string) [4]string {
|
||||
margins := strings.Split(margin, ",")
|
||||
checked := func(str string) string {
|
||||
if strings.HasSuffix(str, "%") {
|
||||
val := atof(str[:len(str)-1])
|
||||
if val < 0 {
|
||||
errorExit("margin must be non-negative")
|
||||
}
|
||||
if val > 100 {
|
||||
errorExit("margin too large")
|
||||
}
|
||||
} else {
|
||||
val := atoi(str)
|
||||
if val < 0 {
|
||||
errorExit("margin must be non-negative")
|
||||
}
|
||||
func parseSize(str string, maxPercent float64, label string) sizeSpec {
|
||||
var val float64
|
||||
percent := strings.HasSuffix(str, "%")
|
||||
if percent {
|
||||
val = atof(str[:len(str)-1])
|
||||
if val < 0 {
|
||||
errorExit(label + " must be non-negative")
|
||||
}
|
||||
return str
|
||||
if val > maxPercent {
|
||||
errorExit(fmt.Sprintf("%s too large (max: %d%%)", label, int(maxPercent)))
|
||||
}
|
||||
} else {
|
||||
if strings.Contains(str, ".") {
|
||||
errorExit(label + " (without %) must be a non-negative integer")
|
||||
}
|
||||
|
||||
val = float64(atoi(str))
|
||||
if val < 0 {
|
||||
errorExit(label + " must be non-negative")
|
||||
}
|
||||
}
|
||||
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) {
|
||||
case 1:
|
||||
m := checked(margins[0])
|
||||
return [4]string{m, m, m, m}
|
||||
return [4]sizeSpec{m, m, m, m}
|
||||
case 2:
|
||||
tb := checked(margins[0])
|
||||
rl := checked(margins[1])
|
||||
return [4]string{tb, rl, tb, rl}
|
||||
return [4]sizeSpec{tb, rl, tb, rl}
|
||||
case 3:
|
||||
t := checked(margins[0])
|
||||
rl := checked(margins[1])
|
||||
b := checked(margins[2])
|
||||
return [4]string{t, rl, b, rl}
|
||||
return [4]sizeSpec{t, rl, b, rl}
|
||||
case 4:
|
||||
return [4]string{
|
||||
return [4]sizeSpec{
|
||||
checked(margins[0]), checked(margins[1]),
|
||||
checked(margins[2]), checked(margins[3])}
|
||||
default:
|
||||
@@ -714,6 +809,7 @@ func parseOptions(opts *Options, allArgs []string) {
|
||||
opts.History.maxSize = historyMax
|
||||
}
|
||||
}
|
||||
validateJumpLabels := false
|
||||
for i := 0; i < len(allArgs); i++ {
|
||||
arg := allArgs[i]
|
||||
switch arg {
|
||||
@@ -745,7 +841,7 @@ func parseOptions(opts *Options, allArgs []string) {
|
||||
case "--color":
|
||||
spec := optionalNextString(allArgs, &i)
|
||||
if len(spec) == 0 {
|
||||
opts.Theme = defaultTheme()
|
||||
opts.Theme = curses.EmptyTheme()
|
||||
} else {
|
||||
opts.Theme = parseTheme(opts.Theme, spec)
|
||||
}
|
||||
@@ -805,6 +901,9 @@ func parseOptions(opts *Options, allArgs []string) {
|
||||
opts.InlineInfo = true
|
||||
case "--no-inline-info":
|
||||
opts.InlineInfo = false
|
||||
case "--jump-labels":
|
||||
opts.JumpLabels = nextString(allArgs, &i, "label characters required")
|
||||
validateJumpLabels = true
|
||||
case "-1", "--select-1":
|
||||
opts.Select1 = true
|
||||
case "+1", "--no-select-1":
|
||||
@@ -844,6 +943,13 @@ func parseOptions(opts *Options, allArgs []string) {
|
||||
case "--header-lines":
|
||||
opts.HeaderLines = atoi(
|
||||
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":
|
||||
opts.Margin = defaultMargin()
|
||||
case "--margin":
|
||||
@@ -886,12 +992,18 @@ func parseOptions(opts *Options, allArgs []string) {
|
||||
opts.Header = strLines(value)
|
||||
} else if match, value := optString(arg, "--header-lines="); match {
|
||||
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 {
|
||||
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 {
|
||||
errorExit("unknown option: " + arg)
|
||||
}
|
||||
@@ -909,6 +1021,18 @@ func parseOptions(opts *Options, allArgs []string) {
|
||||
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")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func postProcessOptions(opts *Options) {
|
||||
|
@@ -123,14 +123,14 @@ func TestIrrelevantNth(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) {
|
||||
if pairs[i] != s {
|
||||
t.Errorf("%s != %s", pairs[i], s)
|
||||
}
|
||||
}
|
||||
if len(pairs) != 9 {
|
||||
t.Error(9)
|
||||
if len(pairs) != 11 {
|
||||
t.Error(11)
|
||||
}
|
||||
check(curses.CtrlZ, "ctrl-z")
|
||||
check(curses.AltZ, "alt-z")
|
||||
@@ -141,6 +141,8 @@ func TestParseKeys(t *testing.T) {
|
||||
check(curses.CtrlA+'g'-'a', "ctrl-G")
|
||||
check(curses.AltZ+'J', "J")
|
||||
check(curses.AltZ+'g', "g")
|
||||
check(curses.AltEnter, "ALT-enter")
|
||||
check(curses.AltSpace, "alt-SPACE")
|
||||
|
||||
// Synonyms
|
||||
pairs = parseKeyChords("enter,Return,space,tab,btab,esc,up,down,left,right", "")
|
||||
|
373
src/terminal.go
373
src/terminal.go
@@ -7,7 +7,6 @@ import (
|
||||
"os/signal"
|
||||
"regexp"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"syscall"
|
||||
@@ -19,6 +18,14 @@ import (
|
||||
"github.com/junegunn/go-runewidth"
|
||||
)
|
||||
|
||||
type jumpMode int
|
||||
|
||||
const (
|
||||
jumpDisabled jumpMode = iota
|
||||
jumpEnabled
|
||||
jumpAcceptEnabled
|
||||
)
|
||||
|
||||
// Terminal represents terminal input/output
|
||||
type Terminal struct {
|
||||
initDelay time.Duration
|
||||
@@ -45,14 +52,22 @@ type Terminal struct {
|
||||
header []string
|
||||
header0 []string
|
||||
ansi bool
|
||||
margin [4]string
|
||||
marginInt [4]int
|
||||
margin [4]sizeSpec
|
||||
window *C.Window
|
||||
bwindow *C.Window
|
||||
pwindow *C.Window
|
||||
count int
|
||||
progress int
|
||||
reading bool
|
||||
jumping jumpMode
|
||||
jumpLabels string
|
||||
merger *Merger
|
||||
selected map[int32]selectedItem
|
||||
reqBox *util.EventBox
|
||||
preview previewOpts
|
||||
previewing bool
|
||||
previewTxt string
|
||||
previewBox *util.EventBox
|
||||
eventBox *util.EventBox
|
||||
mutex sync.Mutex
|
||||
initFunc func()
|
||||
@@ -67,6 +82,11 @@ type selectedItem struct {
|
||||
|
||||
type byTimeOrder []selectedItem
|
||||
|
||||
type previewRequest struct {
|
||||
ok bool
|
||||
str string
|
||||
}
|
||||
|
||||
func (a byTimeOrder) Len() int {
|
||||
return len(a)
|
||||
}
|
||||
@@ -88,9 +108,13 @@ const (
|
||||
reqInfo
|
||||
reqHeader
|
||||
reqList
|
||||
reqJump
|
||||
reqRefresh
|
||||
reqRedraw
|
||||
reqClose
|
||||
reqPrintQuery
|
||||
reqPreviewEnqueue
|
||||
reqPreviewDisplay
|
||||
reqQuit
|
||||
)
|
||||
|
||||
@@ -132,7 +156,11 @@ const (
|
||||
actUp
|
||||
actPageUp
|
||||
actPageDown
|
||||
actJump
|
||||
actJumpAccept
|
||||
actPrintQuery
|
||||
actToggleSort
|
||||
actTogglePreview
|
||||
actPreviousHistory
|
||||
actNextHistory
|
||||
actExecute
|
||||
@@ -205,6 +233,10 @@ func NewTerminal(opts *Options, eventBox *util.EventBox) *Terminal {
|
||||
} else {
|
||||
delay = initialDelay
|
||||
}
|
||||
var previewBox *util.EventBox
|
||||
if len(opts.Preview.command) > 0 {
|
||||
previewBox = util.NewEventBox()
|
||||
}
|
||||
return &Terminal{
|
||||
initDelay: delay,
|
||||
inlineInfo: opts.InlineInfo,
|
||||
@@ -227,15 +259,20 @@ func NewTerminal(opts *Options, eventBox *util.EventBox) *Terminal {
|
||||
printQuery: opts.PrintQuery,
|
||||
history: opts.History,
|
||||
margin: opts.Margin,
|
||||
marginInt: [4]int{0, 0, 0, 0},
|
||||
cycle: opts.Cycle,
|
||||
header: header,
|
||||
header0: header,
|
||||
ansi: opts.Ansi,
|
||||
reading: true,
|
||||
jumping: jumpDisabled,
|
||||
jumpLabels: opts.JumpLabels,
|
||||
merger: EmptyMerger,
|
||||
selected: make(map[int32]selectedItem),
|
||||
reqBox: util.NewEventBox(),
|
||||
preview: opts.Preview,
|
||||
previewing: previewBox != nil && !opts.Preview.hidden,
|
||||
previewTxt: "",
|
||||
previewBox: previewBox,
|
||||
eventBox: eventBox,
|
||||
mutex: sync.Mutex{},
|
||||
suppress: true,
|
||||
@@ -315,7 +352,7 @@ func (t *Terminal) output() bool {
|
||||
if !found {
|
||||
cnt := t.merger.Length()
|
||||
if cnt > 0 && cnt > t.cy {
|
||||
fmt.Println(t.merger.Get(t.cy).AsString(t.ansi))
|
||||
fmt.Println(t.current())
|
||||
found = true
|
||||
}
|
||||
} else {
|
||||
@@ -355,56 +392,113 @@ func displayWidth(runes []rune) int {
|
||||
return l
|
||||
}
|
||||
|
||||
const minWidth = 16
|
||||
const minHeight = 4
|
||||
const (
|
||||
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()
|
||||
screenHeight := C.MaxY()
|
||||
for idx, str := range t.margin {
|
||||
if str == "0" {
|
||||
t.marginInt[idx] = 0
|
||||
} else if strings.HasSuffix(str, "%") {
|
||||
num, _ := strconv.ParseFloat(str[:len(str)-1], 64)
|
||||
var val float64
|
||||
marginInt := [4]int{}
|
||||
for idx, sizeSpec := range t.margin {
|
||||
if sizeSpec.percent {
|
||||
var max float64
|
||||
if idx%2 == 0 {
|
||||
val = float64(screenHeight)
|
||||
max = float64(screenHeight)
|
||||
} else {
|
||||
val = float64(screenWidth)
|
||||
max = float64(screenWidth)
|
||||
}
|
||||
t.marginInt[idx] = int(val * num * 0.01)
|
||||
marginInt[idx] = int(max * sizeSpec.size * 0.01)
|
||||
} else {
|
||||
num, _ := strconv.Atoi(str)
|
||||
t.marginInt[idx] = num
|
||||
marginInt[idx] = int(sizeSpec.size)
|
||||
}
|
||||
}
|
||||
adjust := func(idx1 int, idx2 int, max int, min int) {
|
||||
if max >= min {
|
||||
margin := t.marginInt[idx1] + t.marginInt[idx2]
|
||||
margin := marginInt[idx1] + marginInt[idx2]
|
||||
if max-margin < min {
|
||||
desired := max - min
|
||||
t.marginInt[idx1] = desired * t.marginInt[idx1] / margin
|
||||
t.marginInt[idx2] = desired * t.marginInt[idx2] / margin
|
||||
marginInt[idx1] = desired * marginInt[idx1] / margin
|
||||
marginInt[idx2] = desired * marginInt[idx2] / margin
|
||||
}
|
||||
}
|
||||
}
|
||||
adjust(1, 3, screenWidth, minWidth)
|
||||
adjust(0, 2, screenHeight, minHeight)
|
||||
minAreaWidth := minWidth
|
||||
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) {
|
||||
x += t.marginInt[3]
|
||||
maxy := C.MaxY()
|
||||
if !t.reverse {
|
||||
y = maxy - y - 1 - t.marginInt[2]
|
||||
} else {
|
||||
y += t.marginInt[0]
|
||||
y = t.window.Height - y - 1
|
||||
}
|
||||
|
||||
if clear {
|
||||
C.MoveAndClear(y, x)
|
||||
t.window.MoveAndClear(y, x)
|
||||
} else {
|
||||
C.Move(y, x)
|
||||
t.window.Move(y, x)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -414,24 +508,24 @@ func (t *Terminal) placeCursor() {
|
||||
|
||||
func (t *Terminal) printPrompt() {
|
||||
t.move(0, 0, true)
|
||||
C.CPrint(C.ColPrompt, true, t.prompt)
|
||||
C.CPrint(C.ColNormal, true, string(t.input))
|
||||
t.window.CPrint(C.ColPrompt, true, t.prompt)
|
||||
t.window.CPrint(C.ColNormal, true, string(t.input))
|
||||
}
|
||||
|
||||
func (t *Terminal) printInfo() {
|
||||
if t.inlineInfo {
|
||||
t.move(0, displayWidth([]rune(t.prompt))+displayWidth(t.input)+1, true)
|
||||
if t.reading {
|
||||
C.CPrint(C.ColSpinner, true, " < ")
|
||||
t.window.CPrint(C.ColSpinner, true, " < ")
|
||||
} else {
|
||||
C.CPrint(C.ColPrompt, true, " < ")
|
||||
t.window.CPrint(C.ColPrompt, true, " < ")
|
||||
}
|
||||
} else {
|
||||
t.move(1, 0, true)
|
||||
if t.reading {
|
||||
duration := int64(spinnerDuration)
|
||||
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)
|
||||
}
|
||||
@@ -450,18 +544,14 @@ func (t *Terminal) printInfo() {
|
||||
if t.progress > 0 && t.progress < 100 {
|
||||
output += fmt.Sprintf(" (%d%%)", t.progress)
|
||||
}
|
||||
C.CPrint(C.ColInfo, false, output)
|
||||
}
|
||||
|
||||
func (t *Terminal) maxHeight() int {
|
||||
return C.MaxY() - t.marginInt[0] - t.marginInt[2]
|
||||
t.window.CPrint(C.ColInfo, false, output)
|
||||
}
|
||||
|
||||
func (t *Terminal) printHeader() {
|
||||
if len(t.header) == 0 {
|
||||
return
|
||||
}
|
||||
max := t.maxHeight()
|
||||
max := t.window.Height
|
||||
var state *ansiState
|
||||
for idx, lineStr := range t.header {
|
||||
line := idx + 2
|
||||
@@ -471,7 +561,7 @@ func (t *Terminal) printHeader() {
|
||||
if line >= max {
|
||||
continue
|
||||
}
|
||||
trimmed, colors, newState := extractColor(lineStr, state)
|
||||
trimmed, colors, newState := extractColor(lineStr, state, nil)
|
||||
state = newState
|
||||
item := &Item{
|
||||
text: []rune(trimmed),
|
||||
@@ -495,27 +585,36 @@ func (t *Terminal) printList() {
|
||||
}
|
||||
t.move(line, 0, true)
|
||||
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()]
|
||||
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 {
|
||||
C.CPrint(C.ColCursor, true, ">")
|
||||
if selected {
|
||||
C.CPrint(C.ColSelected, true, ">")
|
||||
t.window.CPrint(C.ColSelected, true, ">")
|
||||
} else {
|
||||
C.CPrint(C.ColCurrent, true, " ")
|
||||
t.window.CPrint(C.ColCurrent, true, " ")
|
||||
}
|
||||
t.printHighlighted(item, true, C.ColCurrent, C.ColCurrentMatch, true)
|
||||
} else {
|
||||
C.CPrint(C.ColCursor, true, " ")
|
||||
if selected {
|
||||
C.CPrint(C.ColSelected, true, ">")
|
||||
t.window.CPrint(C.ColSelected, true, ">")
|
||||
} else {
|
||||
C.Print(" ")
|
||||
t.window.Print(" ")
|
||||
}
|
||||
t.printHighlighted(item, false, 0, C.ColMatch, false)
|
||||
}
|
||||
@@ -567,7 +666,7 @@ func (t *Terminal) printHighlighted(item *Item, bold bool, col1 int, col2 int, c
|
||||
text := make([]rune, len(item.text))
|
||||
copy(text, item.text)
|
||||
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)
|
||||
if fullWidth > maxWidth {
|
||||
@@ -617,11 +716,11 @@ func (t *Terminal) printHighlighted(item *Item, bold bool, col1 int, col2 int, c
|
||||
e := util.Constrain32(offset.offset[1], index, maxOffset)
|
||||
|
||||
substr, prefixWidth = processTabs(text[index:b], prefixWidth)
|
||||
C.CPrint(col1, bold, substr)
|
||||
t.window.CPrint(col1, bold, substr)
|
||||
|
||||
if b < e {
|
||||
substr, prefixWidth = processTabs(text[b:e], prefixWidth)
|
||||
C.CPrint(offset.color, offset.bold, substr)
|
||||
t.window.CPrint(offset.color, offset.bold, substr)
|
||||
}
|
||||
|
||||
index = e
|
||||
@@ -631,10 +730,20 @@ func (t *Terminal) printHighlighted(item *Item, bold bool, col1 int, col2 int, c
|
||||
}
|
||||
if index < maxOffset {
|
||||
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) {
|
||||
var strbuf bytes.Buffer
|
||||
l := prefixWidth
|
||||
@@ -651,16 +760,24 @@ func processTabs(runes []rune, prefixWidth int) (string, int) {
|
||||
}
|
||||
|
||||
func (t *Terminal) printAll() {
|
||||
t.calculateMargins()
|
||||
t.resizeWindows()
|
||||
t.printList()
|
||||
t.printPrompt()
|
||||
t.printInfo()
|
||||
t.printHeader()
|
||||
if t.isPreviewEnabled() {
|
||||
t.printPreview()
|
||||
}
|
||||
}
|
||||
|
||||
func (t *Terminal) refresh() {
|
||||
if !t.suppress {
|
||||
C.Refresh()
|
||||
if t.isPreviewEnabled() {
|
||||
t.bwindow.Refresh()
|
||||
t.pwindow.Refresh()
|
||||
}
|
||||
t.window.Refresh()
|
||||
C.DoUpdate()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -717,10 +834,10 @@ func keyMatch(key int, event C.Event) bool {
|
||||
}
|
||||
|
||||
func quoteEntry(entry string) string {
|
||||
return fmt.Sprintf("%q", entry)
|
||||
return "'" + strings.Replace(entry, "'", "'\\''", -1) + "'"
|
||||
}
|
||||
|
||||
func executeCommand(template string, replacement string) {
|
||||
func (t *Terminal) executeCommand(template string, replacement string) {
|
||||
command := strings.Replace(template, "{}", replacement, -1)
|
||||
cmd := util.ExecCommand(command)
|
||||
cmd.Stdin = os.Stdin
|
||||
@@ -728,7 +845,19 @@ func executeCommand(template string, replacement string) {
|
||||
cmd.Stderr = os.Stderr
|
||||
C.Endwin()
|
||||
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
|
||||
@@ -753,10 +882,10 @@ func (t *Terminal) Loop() {
|
||||
|
||||
t.mutex.Lock()
|
||||
t.initFunc()
|
||||
t.calculateMargins()
|
||||
t.resizeWindows()
|
||||
t.printPrompt()
|
||||
t.placeCursor()
|
||||
C.Refresh()
|
||||
t.refresh()
|
||||
t.printInfo()
|
||||
t.printHeader()
|
||||
t.mutex.Unlock()
|
||||
@@ -781,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) {
|
||||
if code <= exitNoMatch && t.history != nil {
|
||||
t.history.append(string(t.input))
|
||||
@@ -789,11 +943,12 @@ func (t *Terminal) Loop() {
|
||||
}
|
||||
|
||||
go func() {
|
||||
focused := previewRequest{false, ""}
|
||||
for {
|
||||
t.reqBox.Wait(func(events *util.Events) {
|
||||
defer events.Clear()
|
||||
t.mutex.Lock()
|
||||
for req := range *events {
|
||||
for req, value := range *events {
|
||||
switch req {
|
||||
case reqPrompt:
|
||||
t.printPrompt()
|
||||
@@ -804,6 +959,24 @@ func (t *Terminal) Loop() {
|
||||
t.printInfo()
|
||||
case reqList:
|
||||
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:
|
||||
t.printHeader()
|
||||
case reqRefresh:
|
||||
@@ -819,6 +992,13 @@ func (t *Terminal) Loop() {
|
||||
exit(exitOk)
|
||||
}
|
||||
exit(exitNoMatch)
|
||||
case reqPreviewDisplay:
|
||||
t.previewTxt = value.(string)
|
||||
t.printPreview()
|
||||
case reqPrintQuery:
|
||||
C.Close()
|
||||
fmt.Println(string(t.input))
|
||||
exit(exitOk)
|
||||
case reqQuit:
|
||||
C.Close()
|
||||
exit(exitInterrupt)
|
||||
@@ -880,7 +1060,7 @@ func (t *Terminal) Loop() {
|
||||
case actExecute:
|
||||
if t.cy >= 0 && t.cy < t.merger.Length() {
|
||||
item := t.merger.Get(t.cy)
|
||||
executeCommand(t.execmap[mapkey], quoteEntry(item.AsString(t.ansi)))
|
||||
t.executeCommand(t.execmap[mapkey], quoteEntry(item.AsString(t.ansi)))
|
||||
}
|
||||
case actExecuteMulti:
|
||||
if len(t.selected) > 0 {
|
||||
@@ -888,13 +1068,23 @@ func (t *Terminal) Loop() {
|
||||
for i, sel := range t.sortSelected() {
|
||||
sels[i] = quoteEntry(*sel.text)
|
||||
}
|
||||
executeCommand(t.execmap[mapkey], strings.Join(sels, " "))
|
||||
t.executeCommand(t.execmap[mapkey], strings.Join(sels, " "))
|
||||
} else {
|
||||
return doAction(actExecute, mapkey)
|
||||
}
|
||||
case actInvalid:
|
||||
t.mutex.Unlock()
|
||||
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:
|
||||
t.sort = !t.sort
|
||||
t.eventBox.Set(EvtSearchNew, t.sort)
|
||||
@@ -906,6 +1096,8 @@ func (t *Terminal) Loop() {
|
||||
if t.cx > 0 {
|
||||
t.cx--
|
||||
}
|
||||
case actPrintQuery:
|
||||
req(reqPrintQuery)
|
||||
case actAbort:
|
||||
req(reqQuit)
|
||||
case actDeleteChar:
|
||||
@@ -1017,6 +1209,12 @@ func (t *Terminal) Loop() {
|
||||
case actPageDown:
|
||||
t.vmove(-(t.maxItems() - 1))
|
||||
req(reqList)
|
||||
case actJump:
|
||||
t.jumping = jumpEnabled
|
||||
req(reqJump)
|
||||
case actJumpAccept:
|
||||
t.jumping = jumpAcceptEnabled
|
||||
req(reqJump)
|
||||
case actBackwardWord:
|
||||
t.cx = findLastMatch("[^[:alnum:]][[:alnum:]]", string(t.input[:t.cx])) + 1
|
||||
case actForwardWord:
|
||||
@@ -1054,20 +1252,19 @@ func (t *Terminal) Loop() {
|
||||
mx, my := me.X, me.Y
|
||||
if me.S != 0 {
|
||||
// Scroll
|
||||
if t.merger.Length() > 0 {
|
||||
if t.window.Enclose(my, mx) && t.merger.Length() > 0 {
|
||||
if t.multi && me.Mod {
|
||||
toggle()
|
||||
}
|
||||
t.vmove(me.S)
|
||||
req(reqList)
|
||||
}
|
||||
} else if mx >= t.marginInt[3] && mx < C.MaxX()-t.marginInt[1] &&
|
||||
my >= t.marginInt[0] && my < C.MaxY()-t.marginInt[2] {
|
||||
mx -= t.marginInt[3]
|
||||
my -= t.marginInt[0]
|
||||
} else if t.window.Enclose(my, mx) {
|
||||
mx -= t.window.Left
|
||||
my -= t.window.Top
|
||||
mx = util.Constrain(mx-displayWidth([]rune(t.prompt)), 0, len(t.input))
|
||||
if !t.reverse {
|
||||
my = t.maxHeight() - my - 1
|
||||
my = t.window.Height - my - 1
|
||||
}
|
||||
min := 2 + len(t.header)
|
||||
if t.inlineInfo {
|
||||
@@ -1096,18 +1293,32 @@ func (t *Terminal) Loop() {
|
||||
}
|
||||
return true
|
||||
}
|
||||
action := t.keymap[event.Type]
|
||||
changed := false
|
||||
mapkey := event.Type
|
||||
if event.Type == C.Rune {
|
||||
mapkey = int(event.Char) + int(C.AltZ)
|
||||
if act, prs := t.keymap[mapkey]; prs {
|
||||
action = act
|
||||
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)
|
||||
}
|
||||
if !doAction(action, mapkey) {
|
||||
continue
|
||||
}
|
||||
changed := string(previousInput) != string(t.input)
|
||||
t.mutex.Unlock() // Must be unlocked before touching reqBox
|
||||
|
||||
if changed {
|
||||
@@ -1160,7 +1371,7 @@ func (t *Terminal) vset(o int) bool {
|
||||
}
|
||||
|
||||
func (t *Terminal) maxItems() int {
|
||||
max := t.maxHeight() - 2 - len(t.header)
|
||||
max := t.window.Height - 2 - len(t.header)
|
||||
if t.inlineInfo {
|
||||
max++
|
||||
}
|
||||
|
133
test/test_go.rb
133
test/test_go.rb
@@ -430,6 +430,10 @@ class TestGoFZF < TestBase
|
||||
test.call 'f3', 'f3'
|
||||
test.call 'f2,f4', 'f2', 'f2'
|
||||
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 '@', '@'
|
||||
end
|
||||
|
||||
@@ -771,6 +775,13 @@ class TestGoFZF < TestBase
|
||||
assert_equal %w[4 5 6 9], readonce.split($/)
|
||||
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
|
||||
data = '.' * 256 * 1024
|
||||
File.open(tempname, 'w') do |f|
|
||||
@@ -858,20 +869,34 @@ class TestGoFZF < TestBase
|
||||
|
||||
def test_execute
|
||||
output = '/tmp/fzf-test-execute'
|
||||
opts = %[--bind \\"alt-a:execute(echo '[{}]' >> #{output}),alt-b:execute[echo '({}), ({})' >> #{output}],C:execute:echo '({}), [{}], @{}@' >> #{output}\\"]
|
||||
tmux.send_keys "seq 100 | #{fzf opts}", :Enter
|
||||
tmux.until { |lines| lines[-2].include? '100/100' }
|
||||
tmux.send_keys :Escape, :a, :Escape, :a
|
||||
opts = %[--bind \\"alt-a:execute(echo [{}] >> #{output}),alt-b:execute[echo /{}{}/ >> #{output}],C:execute:echo /{}{}{}/ >> #{output}\\"]
|
||||
wait = lambda { |exp| tmux.until { |lines| lines[-2].include? exp } }
|
||||
writelines tempname, %w[foo'bar foo"bar foo$bar]
|
||||
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 :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 :C
|
||||
tmux.send_keys 'foobar'
|
||||
tmux.until { |lines| lines[-2].include? '0/100' }
|
||||
tmux.send_keys :Escape, :a, :Escape, :b, :Escape, :c
|
||||
wait['3/3']
|
||||
tmux.send_keys 'barfoo'
|
||||
wait['0/3']
|
||||
tmux.send_keys :Escape, :a
|
||||
wait['/3']
|
||||
tmux.send_keys :Escape, :b
|
||||
wait['/3']
|
||||
tmux.send_keys :Enter
|
||||
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)
|
||||
ensure
|
||||
File.unlink output rescue nil
|
||||
@@ -879,21 +904,24 @@ class TestGoFZF < TestBase
|
||||
|
||||
def test_execute_multi
|
||||
output = '/tmp/fzf-test-execute-multi'
|
||||
opts = %[--multi --bind \\"alt-a:execute-multi(echo '[{}], @{}@' >> #{output}; sync)\\"]
|
||||
tmux.send_keys "seq 100 | #{fzf opts}", :Enter
|
||||
tmux.until { |lines| lines[-2].include? '100/100' }
|
||||
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? '/100' }
|
||||
tmux.until { |lines| lines[-2].include? '/4' }
|
||||
tmux.send_keys :BTab, :BTab, :BTab
|
||||
tmux.send_keys :Escape, :a
|
||||
tmux.until { |lines| lines[-2].include? '/100' }
|
||||
tmux.until { |lines| lines[-2].include? '/4' }
|
||||
tmux.send_keys :Tab, :Tab
|
||||
tmux.send_keys :Escape, :a
|
||||
tmux.until { |lines| lines[-2].include? '/100' }
|
||||
tmux.until { |lines| lines[-2].include? '/4' }
|
||||
tmux.send_keys :Enter
|
||||
tmux.prepare
|
||||
readonce
|
||||
assert_equal ['["1"], @"1"@', '["1" "2" "3"], @"1" "2" "3"@', '["1" "2" "4"], @"1" "2" "4"@'],
|
||||
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
|
||||
@@ -912,7 +940,7 @@ class TestGoFZF < TestBase
|
||||
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)
|
||||
assert_equal ["-c / 'foo'bar"], File.readlines(output).map(&:chomp)
|
||||
ensure
|
||||
File.unlink output rescue nil
|
||||
end
|
||||
@@ -1026,7 +1054,7 @@ class TestGoFZF < TestBase
|
||||
end
|
||||
end
|
||||
|
||||
def test_canel
|
||||
def test_cancel
|
||||
tmux.send_keys "seq 10 | #{fzf "--bind 2:cancel"}", :Enter
|
||||
tmux.until { |lines| lines[-2].include?('10/10') }
|
||||
tmux.send_keys '123'
|
||||
@@ -1163,6 +1191,71 @@ class TestGoFZF < TestBase
|
||||
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
|
||||
def writelines path, lines
|
||||
File.unlink path while File.exists? path
|
||||
@@ -1229,7 +1322,7 @@ module TestShell
|
||||
tmux.send_keys :BTab, :BTab, pane: 1
|
||||
tmux.until(1) { |lines| lines[-2].include? '(2)' }
|
||||
tmux.send_keys :Enter, pane: 1
|
||||
tmux.until { |lines| lines[-1].include? 'cat' }
|
||||
tmux.until { |lines| lines[-1].include?('cat') || lines[-2].include?('cat') }
|
||||
tmux.send_keys :Enter
|
||||
tmux.until { |lines| lines[-1].include? 'test1test2' }
|
||||
end
|
||||
@@ -1444,7 +1537,7 @@ module CompletionTest
|
||||
tmux.send_keys :BTab, :BTab, pane: 1
|
||||
tmux.until(1) { |lines| lines[-2].include? '(2)' }
|
||||
tmux.send_keys :Enter, pane: 1
|
||||
tmux.until { |lines| lines[-1].include? 'cat' }
|
||||
tmux.until { |lines| lines[-1].include?('cat') || lines[-2].include?('cat') }
|
||||
tmux.send_keys :Enter
|
||||
tmux.until { |lines| lines[-1].include? 'test3test4' }
|
||||
end
|
||||
|
Reference in New Issue
Block a user