mirror of
https://github.com/junegunn/fzf.git
synced 2025-11-16 07:13:48 -05:00
Compare commits
24 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2d61691bb2 | ||
|
|
eba9e04e2e | ||
|
|
33f32de690 | ||
|
|
93b8f61551 | ||
|
|
7f17a9d1b4 | ||
|
|
d34e4cf698 | ||
|
|
6b592137b9 | ||
|
|
d5e72bf55d | ||
|
|
5677e5e133 | ||
|
|
7a11a06cbd | ||
|
|
a5862d4b9c | ||
|
|
a50909e806 | ||
|
|
7c8f7d3f20 | ||
|
|
9078197446 | ||
|
|
0fe07cf9fe | ||
|
|
2216169ca1 | ||
|
|
50e989ca85 | ||
|
|
fa1fc3d855 | ||
|
|
bbe696e925 | ||
|
|
5d12f523a3 | ||
|
|
d295d20dc4 | ||
|
|
2ba10071c9 | ||
|
|
505dc0491b | ||
|
|
54a4ab0f26 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -4,3 +4,4 @@ gopath
|
|||||||
pkg
|
pkg
|
||||||
Gemfile.lock
|
Gemfile.lock
|
||||||
.DS_Store
|
.DS_Store
|
||||||
|
doc/tags
|
||||||
|
|||||||
@@ -1,6 +1,13 @@
|
|||||||
CHANGELOG
|
CHANGELOG
|
||||||
=========
|
=========
|
||||||
|
|
||||||
|
0.16.7
|
||||||
|
------
|
||||||
|
- Added support for `ctrl-alt-[a-z]` key chords
|
||||||
|
- CTRL-Z (SIGSTOP) now works with fzf
|
||||||
|
- fzf will export `$FZF_PREVIEW_WINDOW` so that the scripts can use it
|
||||||
|
- Bug fixes and improvements in Vim plugin and shell extensions
|
||||||
|
|
||||||
0.16.6
|
0.16.6
|
||||||
------
|
------
|
||||||
- Minor bug fixes and improvements
|
- Minor bug fixes and improvements
|
||||||
|
|||||||
155
README-VIM.md
Normal file
155
README-VIM.md
Normal file
@@ -0,0 +1,155 @@
|
|||||||
|
FZF Vim integration
|
||||||
|
===================
|
||||||
|
|
||||||
|
This repository only enables basic integration with Vim. If you're looking for
|
||||||
|
more, check out [fzf.vim](https://github.com/junegunn/fzf.vim) project.
|
||||||
|
|
||||||
|
(Note: To use fzf in GVim, an external terminal emulator is required.)
|
||||||
|
|
||||||
|
`:FZF[!]`
|
||||||
|
---------
|
||||||
|
|
||||||
|
If you have set up fzf for Vim, `:FZF` command will be added.
|
||||||
|
|
||||||
|
```vim
|
||||||
|
" Look for files under current directory
|
||||||
|
:FZF
|
||||||
|
|
||||||
|
" Look for files under your home directory
|
||||||
|
:FZF ~
|
||||||
|
|
||||||
|
" With options
|
||||||
|
:FZF --no-sort --reverse --inline-info /tmp
|
||||||
|
|
||||||
|
" Bang version starts fzf in fullscreen mode
|
||||||
|
:FZF!
|
||||||
|
```
|
||||||
|
|
||||||
|
Similarly to [ctrlp.vim](https://github.com/kien/ctrlp.vim), use enter key,
|
||||||
|
`CTRL-T`, `CTRL-X` or `CTRL-V` to open selected files in the current window,
|
||||||
|
in new tabs, in horizontal splits, or in vertical splits respectively.
|
||||||
|
|
||||||
|
Note that the environment variables `FZF_DEFAULT_COMMAND` and
|
||||||
|
`FZF_DEFAULT_OPTS` also apply here.
|
||||||
|
|
||||||
|
### Configuration
|
||||||
|
|
||||||
|
- `g:fzf_action`
|
||||||
|
- Customizable extra key bindings for opening selected files in different ways
|
||||||
|
- `g:fzf_layout`
|
||||||
|
- Determines the size and position of fzf window (tmux pane or Neovim split)
|
||||||
|
- `g:fzf_colors`
|
||||||
|
- Customizes fzf colors to match the current color scheme
|
||||||
|
- `g:fzf_history_dir`
|
||||||
|
- Enables history feature
|
||||||
|
- `g:fzf_launcher`
|
||||||
|
- (Only in GVim) Terminal emulator to open fzf with
|
||||||
|
- `g:Fzf_launcher` for function reference
|
||||||
|
|
||||||
|
#### Examples
|
||||||
|
|
||||||
|
```vim
|
||||||
|
" This is the default extra key bindings
|
||||||
|
let g:fzf_action = {
|
||||||
|
\ 'ctrl-t': 'tab split',
|
||||||
|
\ 'ctrl-x': 'split',
|
||||||
|
\ 'ctrl-v': 'vsplit' }
|
||||||
|
|
||||||
|
" Default fzf layout
|
||||||
|
" - down / up / left / right
|
||||||
|
let g:fzf_layout = { 'down': '~40%' }
|
||||||
|
|
||||||
|
" In Neovim, you can set up fzf window using a Vim command
|
||||||
|
let g:fzf_layout = { 'window': 'enew' }
|
||||||
|
let g:fzf_layout = { 'window': '-tabnew' }
|
||||||
|
let g:fzf_layout = { 'window': '10split enew' }
|
||||||
|
|
||||||
|
" Customize fzf colors to match your color scheme
|
||||||
|
let g:fzf_colors =
|
||||||
|
\ { 'fg': ['fg', 'Normal'],
|
||||||
|
\ 'bg': ['bg', 'Normal'],
|
||||||
|
\ 'hl': ['fg', 'Comment'],
|
||||||
|
\ 'fg+': ['fg', 'CursorLine', 'CursorColumn', 'Normal'],
|
||||||
|
\ 'bg+': ['bg', 'CursorLine', 'CursorColumn'],
|
||||||
|
\ 'hl+': ['fg', 'Statement'],
|
||||||
|
\ 'info': ['fg', 'PreProc'],
|
||||||
|
\ 'prompt': ['fg', 'Conditional'],
|
||||||
|
\ 'pointer': ['fg', 'Exception'],
|
||||||
|
\ 'marker': ['fg', 'Keyword'],
|
||||||
|
\ 'spinner': ['fg', 'Label'],
|
||||||
|
\ 'header': ['fg', 'Comment'] }
|
||||||
|
|
||||||
|
" Enable per-command history.
|
||||||
|
" CTRL-N and CTRL-P will be automatically bound to next-history and
|
||||||
|
" previous-history instead of down and up. If you don't like the change,
|
||||||
|
" explicitly bind the keys to down and up in your $FZF_DEFAULT_OPTS.
|
||||||
|
let g:fzf_history_dir = '~/.local/share/fzf-history'
|
||||||
|
```
|
||||||
|
|
||||||
|
`fzf#run`
|
||||||
|
---------
|
||||||
|
|
||||||
|
For more advanced uses, you can use `fzf#run([options])` function with the
|
||||||
|
following options.
|
||||||
|
|
||||||
|
| Option name | Type | Description |
|
||||||
|
| -------------------------- | ------------- | ---------------------------------------------------------------- |
|
||||||
|
| `source` | string | External command to generate input to fzf (e.g. `find .`) |
|
||||||
|
| `source` | list | Vim list as input to fzf |
|
||||||
|
| `sink` | string | Vim command to handle the selected item (e.g. `e`, `tabe`) |
|
||||||
|
| `sink` | funcref | Reference to function to process each selected item |
|
||||||
|
| `sink*` | funcref | Similar to `sink`, but takes the list of output lines at once |
|
||||||
|
| `options` | string/list | Options to fzf |
|
||||||
|
| `dir` | string | Working directory |
|
||||||
|
| `up`/`down`/`left`/`right` | number/string | Use tmux pane with the given size (e.g. `20`, `50%`) |
|
||||||
|
| `window` (*Neovim only*) | string | Command to open fzf window (e.g. `vertical aboveleft 30new`) |
|
||||||
|
| `launcher` | string | External terminal emulator to start fzf with (GVim only) |
|
||||||
|
| `launcher` | funcref | Function for generating `launcher` string (GVim only) |
|
||||||
|
|
||||||
|
`options` entry can be either a string or a list. For simple cases, string
|
||||||
|
should suffice, but prefer to use list type if you're concerned about escaping
|
||||||
|
issues on different platforms.
|
||||||
|
|
||||||
|
```vim
|
||||||
|
call fzf#run({'options': '--reverse --prompt "C:\\Program Files\\"'})
|
||||||
|
call fzf#run({'options': ['--reverse', '--prompt', 'C:\Program Files\']})
|
||||||
|
```
|
||||||
|
|
||||||
|
`fzf#wrap`
|
||||||
|
----------
|
||||||
|
|
||||||
|
`fzf#wrap([name string,] [opts dict,] [fullscreen boolean])` is a helper
|
||||||
|
function that decorates the options dictionary so that it understands
|
||||||
|
`g:fzf_layout`, `g:fzf_action`, `g:fzf_colors`, and `g:fzf_history_dir` like
|
||||||
|
`:FZF`.
|
||||||
|
|
||||||
|
```vim
|
||||||
|
command! -bang MyStuff
|
||||||
|
\ call fzf#run(fzf#wrap('my-stuff', {'dir': '~/my-stuff'}, <bang>0))
|
||||||
|
```
|
||||||
|
|
||||||
|
GVim
|
||||||
|
----
|
||||||
|
|
||||||
|
In GVim, you need an external terminal emulator to start fzf with. `xterm`
|
||||||
|
command is used by default, but you can customize it with `g:fzf_launcher`.
|
||||||
|
|
||||||
|
```vim
|
||||||
|
" This is the default. %s is replaced with fzf command
|
||||||
|
let g:fzf_launcher = 'xterm -e bash -ic %s'
|
||||||
|
|
||||||
|
" Use urxvt instead
|
||||||
|
let g:fzf_launcher = 'urxvt -geometry 120x30 -e sh -c %s'
|
||||||
|
```
|
||||||
|
|
||||||
|
If you're running MacVim on OSX, I recommend you to use iTerm2 as the
|
||||||
|
launcher. Refer to the [this wiki page][macvim-iterm2] to see how to set up.
|
||||||
|
|
||||||
|
[macvim-iterm2]: https://github.com/junegunn/fzf/wiki/On-MacVim-with-iTerm2
|
||||||
|
|
||||||
|
[License](LICENSE)
|
||||||
|
------------------
|
||||||
|
|
||||||
|
The MIT License (MIT)
|
||||||
|
|
||||||
|
Copyright (c) 2017 Junegunn Choi
|
||||||
94
README.md
94
README.md
@@ -1,4 +1,4 @@
|
|||||||
<img src="https://raw.githubusercontent.com/junegunn/i/master/fzf.png" height="170" alt="fzf - a command-line fuzzy finder"> [](https://travis-ci.org/junegunn/fzf)
|
<img src="https://raw.githubusercontent.com/junegunn/i/master/fzf.png" height="170" alt="fzf - a command-line fuzzy finder"> [](https://travis-ci.org/junegunn/fzf) [](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=EKYAW9PGKPD2N)
|
||||||
===
|
===
|
||||||
|
|
||||||
fzf is a general-purpose command-line fuzzy finder.
|
fzf is a general-purpose command-line fuzzy finder.
|
||||||
@@ -53,7 +53,7 @@ brew install fzf
|
|||||||
/usr/local/opt/fzf/install
|
/usr/local/opt/fzf/install
|
||||||
```
|
```
|
||||||
|
|
||||||
### Vim plugin
|
### As Vim plugin
|
||||||
|
|
||||||
You can manually add the directory to `&runtimepath` as follows,
|
You can manually add the directory to `&runtimepath` as follows,
|
||||||
|
|
||||||
@@ -74,10 +74,18 @@ Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }
|
|||||||
|
|
||||||
### Windows
|
### Windows
|
||||||
|
|
||||||
Pre-built binaries for Windows can be downloaded [here][bin]. However, other
|
Pre-built binaries for Windows can be downloaded [here][bin]. fzf is also
|
||||||
components of the project may not work on Windows. You might want to consider
|
available as a [Chocolatey package][choco].
|
||||||
installing fzf on [Windows Subsystem for Linux][wsl] where everything runs
|
|
||||||
flawlessly.
|
[choco]: https://chocolatey.org/packages/fzf
|
||||||
|
|
||||||
|
```sh
|
||||||
|
choco install fzf
|
||||||
|
```
|
||||||
|
|
||||||
|
However, other components of the project may not work on Windows. You might
|
||||||
|
want to consider installing fzf on [Windows Subsystem for Linux][wsl] where
|
||||||
|
everything runs flawlessly.
|
||||||
|
|
||||||
[wsl]: https://blogs.msdn.microsoft.com/wsl/
|
[wsl]: https://blogs.msdn.microsoft.com/wsl/
|
||||||
|
|
||||||
@@ -90,6 +98,7 @@ method used.
|
|||||||
|
|
||||||
- git: `cd ~/.fzf && git pull && ./install`
|
- git: `cd ~/.fzf && git pull && ./install`
|
||||||
- brew: `brew update; brew reinstall fzf`
|
- brew: `brew update; brew reinstall fzf`
|
||||||
|
- chocolatey: `choco upgrade fzf`
|
||||||
- vim-plug: `:PlugUpdate fzf`
|
- vim-plug: `:PlugUpdate fzf`
|
||||||
|
|
||||||
Building fzf
|
Building fzf
|
||||||
@@ -100,7 +109,7 @@ See [BUILD.md](BUILD.md).
|
|||||||
Usage
|
Usage
|
||||||
-----
|
-----
|
||||||
|
|
||||||
fzf will launch curses-based finder, read the list from STDIN, and write the
|
fzf will launch interactive finder, read the list from STDIN, and write the
|
||||||
selected item to STDOUT.
|
selected item to STDOUT.
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
@@ -336,75 +345,10 @@ commands as well like follows.
|
|||||||
complete -F _fzf_file_completion -o default -o bashdefault doge
|
complete -F _fzf_file_completion -o default -o bashdefault doge
|
||||||
```
|
```
|
||||||
|
|
||||||
Usage as Vim plugin
|
Vim plugin
|
||||||
-------------------
|
----------
|
||||||
|
|
||||||
This repository only enables basic integration with Vim. If you're looking for
|
See [README-VIM.md](README-VIM.md).
|
||||||
more, check out [fzf.vim](https://github.com/junegunn/fzf.vim) project.
|
|
||||||
|
|
||||||
(Note: To use fzf in GVim, an external terminal emulator is required.)
|
|
||||||
|
|
||||||
#### `:FZF[!]`
|
|
||||||
|
|
||||||
If you have set up fzf for Vim, `:FZF` command will be added.
|
|
||||||
|
|
||||||
```vim
|
|
||||||
" Look for files under current directory
|
|
||||||
:FZF
|
|
||||||
|
|
||||||
" Look for files under your home directory
|
|
||||||
:FZF ~
|
|
||||||
|
|
||||||
" With options
|
|
||||||
:FZF --no-sort --reverse --inline-info /tmp
|
|
||||||
|
|
||||||
" Bang version starts fzf in fullscreen mode
|
|
||||||
:FZF!
|
|
||||||
```
|
|
||||||
|
|
||||||
Similarly to [ctrlp.vim](https://github.com/kien/ctrlp.vim), use enter key,
|
|
||||||
`CTRL-T`, `CTRL-X` or `CTRL-V` to open selected files in the current window,
|
|
||||||
in new tabs, in horizontal splits, or in vertical splits respectively.
|
|
||||||
|
|
||||||
Note that the environment variables `FZF_DEFAULT_COMMAND` and
|
|
||||||
`FZF_DEFAULT_OPTS` also apply here. Refer to [the wiki page][fzf-config] for
|
|
||||||
customization.
|
|
||||||
|
|
||||||
[fzf-config]: https://github.com/junegunn/fzf/wiki/Configuring-Vim-plugin
|
|
||||||
|
|
||||||
#### `fzf#run`
|
|
||||||
|
|
||||||
For more advanced uses, you can use `fzf#run([options])` function with the
|
|
||||||
following options.
|
|
||||||
|
|
||||||
| Option name | Type | Description |
|
|
||||||
| -------------------------- | ------------- | ---------------------------------------------------------------- |
|
|
||||||
| `source` | string | External command to generate input to fzf (e.g. `find .`) |
|
|
||||||
| `source` | list | Vim list as input to fzf |
|
|
||||||
| `sink` | string | Vim command to handle the selected item (e.g. `e`, `tabe`) |
|
|
||||||
| `sink` | funcref | Reference to function to process each selected item |
|
|
||||||
| `sink*` | funcref | Similar to `sink`, but takes the list of output lines at once |
|
|
||||||
| `options` | string | Options to fzf |
|
|
||||||
| `dir` | string | Working directory |
|
|
||||||
| `up`/`down`/`left`/`right` | number/string | Use tmux pane with the given size (e.g. `20`, `50%`) |
|
|
||||||
| `window` (*Neovim only*) | string | Command to open fzf window (e.g. `vertical aboveleft 30new`) |
|
|
||||||
| `launcher` | string | External terminal emulator to start fzf with (GVim only) |
|
|
||||||
| `launcher` | funcref | Function for generating `launcher` string (GVim only) |
|
|
||||||
|
|
||||||
Examples can be found on [the wiki
|
|
||||||
page](https://github.com/junegunn/fzf/wiki/Examples-(vim)).
|
|
||||||
|
|
||||||
#### `fzf#wrap`
|
|
||||||
|
|
||||||
`fzf#wrap([name string,] [opts dict,] [fullscreen boolean])` is a helper
|
|
||||||
function that decorates the options dictionary so that it understands
|
|
||||||
`g:fzf_layout`, `g:fzf_action`, `g:fzf_colors`, and `g:fzf_history_dir` like
|
|
||||||
`:FZF`.
|
|
||||||
|
|
||||||
```vim
|
|
||||||
command! -bang MyStuff
|
|
||||||
\ call fzf#run(fzf#wrap('my-stuff', {'dir': '~/my-stuff'}, <bang>0))
|
|
||||||
```
|
|
||||||
|
|
||||||
Tips
|
Tips
|
||||||
----
|
----
|
||||||
|
|||||||
16
bin/fzf-tmux
16
bin/fzf-tmux
@@ -121,7 +121,7 @@ args+=("--no-height")
|
|||||||
if tmux list-panes -F '#F' | grep -q Z; then
|
if tmux list-panes -F '#F' | grep -q Z; then
|
||||||
zoomed=1
|
zoomed=1
|
||||||
original_window=$(tmux display-message -p "#{window_id}")
|
original_window=$(tmux display-message -p "#{window_id}")
|
||||||
tmp_window=$(tmux new-window -d -P -F "#{window_id}" "bash -c 'while :; do for c in \\| / - \\\\; do sleep 0.2; printf \"\\r\$c fzf-tmux is running\\r\"; done; done'")
|
tmp_window=$(tmux new-window -d -P -F "#{window_id}" "bash -c 'while :; do for c in \\| / - '\\;' do sleep 0.2; printf \"\\r\$c fzf-tmux is running\\r\"; done; done'")
|
||||||
tmux swap-pane -t $tmp_window \; select-window -t $tmp_window
|
tmux swap-pane -t $tmp_window \; select-window -t $tmp_window
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -144,8 +144,12 @@ cleanup() {
|
|||||||
kill-window -t $tmp_window \; \
|
kill-window -t $tmp_window \; \
|
||||||
resize-pane -Z
|
resize-pane -Z
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [ $# -gt 0 ]; then
|
||||||
|
exit 130
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
trap cleanup EXIT SIGINT SIGTERM
|
trap 'cleanup 1' SIGUSR1
|
||||||
|
|
||||||
envs="env TERM=$TERM "
|
envs="env TERM=$TERM "
|
||||||
[[ -n "$FZF_DEFAULT_OPTS" ]] && envs="$envs FZF_DEFAULT_OPTS=$(printf %q "$FZF_DEFAULT_OPTS")"
|
[[ -n "$FZF_DEFAULT_OPTS" ]] && envs="$envs FZF_DEFAULT_OPTS=$(printf %q "$FZF_DEFAULT_OPTS")"
|
||||||
@@ -164,18 +168,22 @@ for arg in "${args[@]}"; do
|
|||||||
opts="$opts \"$arg\""
|
opts="$opts \"$arg\""
|
||||||
done
|
done
|
||||||
|
|
||||||
|
pppid=$$
|
||||||
|
trap_set="trap 'kill -SIGUSR1 $pppid' EXIT SIGINT SIGTERM"
|
||||||
|
trap_unset="trap - EXIT SIGINT SIGTERM"
|
||||||
|
|
||||||
if [[ -n "$term" ]] || [[ -t 0 ]]; then
|
if [[ -n "$term" ]] || [[ -t 0 ]]; then
|
||||||
cat <<< "\"$fzf\" $opts > $fifo2; echo \$? > $fifo3 $close" > $argsf
|
cat <<< "\"$fzf\" $opts > $fifo2; echo \$? > $fifo3 $close" > $argsf
|
||||||
TMUX=$(echo $TMUX | cut -d , -f 1,2) tmux set-window-option synchronize-panes off \;\
|
TMUX=$(echo $TMUX | cut -d , -f 1,2) tmux set-window-option synchronize-panes off \;\
|
||||||
set-window-option remain-on-exit off \;\
|
set-window-option remain-on-exit off \;\
|
||||||
split-window $opt "cd $(printf %q "$PWD");$envs bash $argsf" $swap \
|
split-window $opt "$trap_set;cd $(printf %q "$PWD");$envs bash $argsf;$trap_unset" $swap \
|
||||||
> /dev/null 2>&1
|
> /dev/null 2>&1
|
||||||
else
|
else
|
||||||
mkfifo $fifo1
|
mkfifo $fifo1
|
||||||
cat <<< "\"$fzf\" $opts < $fifo1 > $fifo2; echo \$? > $fifo3 $close" > $argsf
|
cat <<< "\"$fzf\" $opts < $fifo1 > $fifo2; echo \$? > $fifo3 $close" > $argsf
|
||||||
TMUX=$(echo $TMUX | cut -d , -f 1,2) tmux set-window-option synchronize-panes off \;\
|
TMUX=$(echo $TMUX | cut -d , -f 1,2) tmux set-window-option synchronize-panes off \;\
|
||||||
set-window-option remain-on-exit off \;\
|
set-window-option remain-on-exit off \;\
|
||||||
split-window $opt "$envs bash $argsf" $swap \
|
split-window $opt "$trap_set;$envs bash $argsf;$trap_unset" $swap \
|
||||||
> /dev/null 2>&1
|
> /dev/null 2>&1
|
||||||
cat <&0 > $fifo1 &
|
cat <&0 > $fifo1 &
|
||||||
fi
|
fi
|
||||||
|
|||||||
182
doc/fzf.txt
Normal file
182
doc/fzf.txt
Normal file
@@ -0,0 +1,182 @@
|
|||||||
|
fzf.txt fzf Last change: April 28 2017
|
||||||
|
FZF - TABLE OF CONTENTS *fzf* *fzf-toc*
|
||||||
|
==============================================================================
|
||||||
|
|
||||||
|
FZF Vim integration
|
||||||
|
:FZF[!]
|
||||||
|
Configuration
|
||||||
|
Examples
|
||||||
|
fzf#run
|
||||||
|
fzf#wrap
|
||||||
|
GVim
|
||||||
|
License
|
||||||
|
|
||||||
|
FZF VIM INTEGRATION *fzf-vim-integration*
|
||||||
|
==============================================================================
|
||||||
|
|
||||||
|
This repository only enables basic integration with Vim. If you're looking for
|
||||||
|
more, check out {fzf.vim}{1} project.
|
||||||
|
|
||||||
|
(Note: To use fzf in GVim, an external terminal emulator is required.)
|
||||||
|
|
||||||
|
{1} https://github.com/junegunn/fzf.vim
|
||||||
|
|
||||||
|
|
||||||
|
:FZF[!]
|
||||||
|
==============================================================================
|
||||||
|
|
||||||
|
*:FZF*
|
||||||
|
|
||||||
|
If you have set up fzf for Vim, `:FZF` command will be added.
|
||||||
|
>
|
||||||
|
" Look for files under current directory
|
||||||
|
:FZF
|
||||||
|
|
||||||
|
" Look for files under your home directory
|
||||||
|
:FZF ~
|
||||||
|
|
||||||
|
" With options
|
||||||
|
:FZF --no-sort --reverse --inline-info /tmp
|
||||||
|
|
||||||
|
" Bang version starts fzf in fullscreen mode
|
||||||
|
:FZF!
|
||||||
|
<
|
||||||
|
Similarly to {ctrlp.vim}{2}, use enter key, CTRL-T, CTRL-X or CTRL-V to open
|
||||||
|
selected files in the current window, in new tabs, in horizontal splits, or in
|
||||||
|
vertical splits respectively.
|
||||||
|
|
||||||
|
Note that the environment variables `FZF_DEFAULT_COMMAND` and
|
||||||
|
`FZF_DEFAULT_OPTS` also apply here.
|
||||||
|
|
||||||
|
{2} https://github.com/kien/ctrlp.vim
|
||||||
|
|
||||||
|
|
||||||
|
< Configuration >_____________________________________________________________~
|
||||||
|
*fzf-configuration*
|
||||||
|
|
||||||
|
*g:fzf_action* *g:fzf_layout* *g:fzf_colors* *g:fzf_history_dir* *g:fzf_launcher*
|
||||||
|
*g:Fzf_launcher*
|
||||||
|
|
||||||
|
- `g:fzf_action`
|
||||||
|
- Customizable extra key bindings for opening selected files in different
|
||||||
|
ways
|
||||||
|
- `g:fzf_layout`
|
||||||
|
- Determines the size and position of fzf window (tmux pane or Neovim split)
|
||||||
|
- `g:fzf_colors`
|
||||||
|
- Customizes fzf colors to match the current color scheme
|
||||||
|
- `g:fzf_history_dir`
|
||||||
|
- Enables history feature
|
||||||
|
- `g:fzf_launcher`
|
||||||
|
- (Only in GVim) Terminal emulator to open fzf with
|
||||||
|
- `g:Fzf_launcher` for function reference
|
||||||
|
|
||||||
|
|
||||||
|
Examples~
|
||||||
|
*fzf-examples*
|
||||||
|
>
|
||||||
|
" This is the default extra key bindings
|
||||||
|
let g:fzf_action = {
|
||||||
|
\ 'ctrl-t': 'tab split',
|
||||||
|
\ 'ctrl-x': 'split',
|
||||||
|
\ 'ctrl-v': 'vsplit' }
|
||||||
|
|
||||||
|
" Default fzf layout
|
||||||
|
" - down / up / left / right
|
||||||
|
let g:fzf_layout = { 'down': '~40%' }
|
||||||
|
|
||||||
|
" In Neovim, you can set up fzf window using a Vim command
|
||||||
|
let g:fzf_layout = { 'window': 'enew' }
|
||||||
|
let g:fzf_layout = { 'window': '-tabnew' }
|
||||||
|
let g:fzf_layout = { 'window': '10split enew' }
|
||||||
|
|
||||||
|
" Customize fzf colors to match your color scheme
|
||||||
|
let g:fzf_colors =
|
||||||
|
\ { 'fg': ['fg', 'Normal'],
|
||||||
|
\ 'bg': ['bg', 'Normal'],
|
||||||
|
\ 'hl': ['fg', 'Comment'],
|
||||||
|
\ 'fg+': ['fg', 'CursorLine', 'CursorColumn', 'Normal'],
|
||||||
|
\ 'bg+': ['bg', 'CursorLine', 'CursorColumn'],
|
||||||
|
\ 'hl+': ['fg', 'Statement'],
|
||||||
|
\ 'info': ['fg', 'PreProc'],
|
||||||
|
\ 'prompt': ['fg', 'Conditional'],
|
||||||
|
\ 'pointer': ['fg', 'Exception'],
|
||||||
|
\ 'marker': ['fg', 'Keyword'],
|
||||||
|
\ 'spinner': ['fg', 'Label'],
|
||||||
|
\ 'header': ['fg', 'Comment'] }
|
||||||
|
|
||||||
|
" Enable per-command history.
|
||||||
|
" CTRL-N and CTRL-P will be automatically bound to next-history and
|
||||||
|
" previous-history instead of down and up. If you don't like the change,
|
||||||
|
" explicitly bind the keys to down and up in your $FZF_DEFAULT_OPTS.
|
||||||
|
let g:fzf_history_dir = '~/.local/share/fzf-history'
|
||||||
|
<
|
||||||
|
|
||||||
|
FZF#RUN *fzf#run*
|
||||||
|
==============================================================================
|
||||||
|
|
||||||
|
For more advanced uses, you can use `fzf#run([options])` function with the
|
||||||
|
following options.
|
||||||
|
|
||||||
|
---------------------------+---------------+--------------------------------------------------------------
|
||||||
|
Option name | Type | Description ~
|
||||||
|
---------------------------+---------------+--------------------------------------------------------------
|
||||||
|
`source` | string | External command to generate input to fzf (e.g. `find .` )
|
||||||
|
`source` | list | Vim list as input to fzf
|
||||||
|
`sink` | string | Vim command to handle the selected item (e.g. `e` , `tabe` )
|
||||||
|
`sink` | funcref | Reference to function to process each selected item
|
||||||
|
`sink*` | funcref | Similar to `sink` , but takes the list of output lines at once
|
||||||
|
`options` | string/list | Options to fzf
|
||||||
|
`dir` | string | Working directory
|
||||||
|
`up` / `down` / `left` / `right` | number/string | Use tmux pane with the given size (e.g. `20` , `50%` )
|
||||||
|
`window` (Neovim only) | string | Command to open fzf window (e.g. `vertical aboveleft 30new` )
|
||||||
|
`launcher` | string | External terminal emulator to start fzf with (GVim only)
|
||||||
|
`launcher` | funcref | Function for generating `launcher` string (GVim only)
|
||||||
|
---------------------------+---------------+--------------------------------------------------------------
|
||||||
|
|
||||||
|
`options` entry can be either a string or a list. For simple cases, string
|
||||||
|
should suffice, but prefer to use list type if you're concerned about escaping
|
||||||
|
issues on different platforms.
|
||||||
|
>
|
||||||
|
call fzf#run({'options': '--reverse --prompt "C:\\Program Files\\"'})
|
||||||
|
call fzf#run({'options': ['--reverse', '--prompt', 'C:\Program Files\']})
|
||||||
|
<
|
||||||
|
|
||||||
|
FZF#WRAP *fzf#wrap*
|
||||||
|
==============================================================================
|
||||||
|
|
||||||
|
`fzf#wrap([name string,] [opts dict,] [fullscreen boolean])` is a helper
|
||||||
|
function that decorates the options dictionary so that it understands
|
||||||
|
`g:fzf_layout`, `g:fzf_action`, `g:fzf_colors`, and `g:fzf_history_dir` like
|
||||||
|
`:FZF`.
|
||||||
|
>
|
||||||
|
command! -bang MyStuff
|
||||||
|
\ call fzf#run(fzf#wrap('my-stuff', {'dir': '~/my-stuff'}, <bang>0))
|
||||||
|
<
|
||||||
|
|
||||||
|
GVIM *fzf-gvim*
|
||||||
|
==============================================================================
|
||||||
|
|
||||||
|
In GVim, you need an external terminal emulator to start fzf with. `xterm`
|
||||||
|
command is used by default, but you can customize it with `g:fzf_launcher`.
|
||||||
|
>
|
||||||
|
" This is the default. %s is replaced with fzf command
|
||||||
|
let g:fzf_launcher = 'xterm -e bash -ic %s'
|
||||||
|
|
||||||
|
" Use urxvt instead
|
||||||
|
let g:fzf_launcher = 'urxvt -geometry 120x30 -e sh -c %s'
|
||||||
|
<
|
||||||
|
If you're running MacVim on OSX, I recommend you to use iTerm2 as the
|
||||||
|
launcher. Refer to the {this wiki page}{3} to see how to set up.
|
||||||
|
|
||||||
|
{3} https://github.com/junegunn/fzf/wiki/On-MacVim-with-iTerm2
|
||||||
|
|
||||||
|
|
||||||
|
LICENSE *fzf-license*
|
||||||
|
==============================================================================
|
||||||
|
|
||||||
|
The MIT License (MIT)
|
||||||
|
|
||||||
|
Copyright (c) 2017 Junegunn Choi
|
||||||
|
|
||||||
|
==============================================================================
|
||||||
|
vim:tw=78:sw=2:ts=2:ft=help:norl:nowrap:
|
||||||
24
install
24
install
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
set -u
|
set -u
|
||||||
|
|
||||||
version=0.16.6
|
version=0.16.7
|
||||||
auto_completion=
|
auto_completion=
|
||||||
key_bindings=
|
key_bindings=
|
||||||
update_config=2
|
update_config=2
|
||||||
@@ -99,11 +99,11 @@ link_fzf_in_path() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try_curl() {
|
try_curl() {
|
||||||
command -v curl > /dev/null && curl -fL $1 | tar -xz
|
command -v curl > /dev/null && curl -fL $1 | tar -xzf -
|
||||||
}
|
}
|
||||||
|
|
||||||
try_wget() {
|
try_wget() {
|
||||||
command -v wget > /dev/null && wget -O - $1 | tar -xz
|
command -v wget > /dev/null && wget -O - $1 | tar -xzf -
|
||||||
}
|
}
|
||||||
|
|
||||||
download() {
|
download() {
|
||||||
@@ -297,6 +297,17 @@ append_line() {
|
|||||||
set +e
|
set +e
|
||||||
}
|
}
|
||||||
|
|
||||||
|
create_file() {
|
||||||
|
local file="$1"
|
||||||
|
shift
|
||||||
|
echo "Create $file:"
|
||||||
|
for line in "$@"; do
|
||||||
|
echo " $line"
|
||||||
|
echo "$line" >> "$file"
|
||||||
|
done
|
||||||
|
echo
|
||||||
|
}
|
||||||
|
|
||||||
if [ $update_config -eq 2 ]; then
|
if [ $update_config -eq 2 ]; then
|
||||||
echo
|
echo
|
||||||
ask "Do you want to update your shell configuration files?"
|
ask "Do you want to update your shell configuration files?"
|
||||||
@@ -310,8 +321,15 @@ done
|
|||||||
|
|
||||||
if [ $key_bindings -eq 1 ] && [ $has_fish -eq 1 ]; then
|
if [ $key_bindings -eq 1 ] && [ $has_fish -eq 1 ]; then
|
||||||
bind_file=~/.config/fish/functions/fish_user_key_bindings.fish
|
bind_file=~/.config/fish/functions/fish_user_key_bindings.fish
|
||||||
|
if [ ! -e "$bind_file" ]; then
|
||||||
|
create_file "$bind_file" \
|
||||||
|
'function fish_user_key_bindings' \
|
||||||
|
' fzf_key_bindings' \
|
||||||
|
'end'
|
||||||
|
else
|
||||||
append_line $update_config "fzf_key_bindings" "$bind_file"
|
append_line $update_config "fzf_key_bindings" "$bind_file"
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
if [ $update_config -eq 1 ]; then
|
if [ $update_config -eq 1 ]; then
|
||||||
echo 'Finished. Restart your shell or reload config file.'
|
echo 'Finished. Restart your shell or reload config file.'
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
THE SOFTWARE.
|
THE SOFTWARE.
|
||||||
..
|
..
|
||||||
.TH fzf-tmux 1 "Mar 2017" "fzf 0.16.6" "fzf-tmux - open fzf in tmux split pane"
|
.TH fzf-tmux 1 "Apr 2017" "fzf 0.16.7" "fzf-tmux - open fzf in tmux split pane"
|
||||||
|
|
||||||
.SH NAME
|
.SH NAME
|
||||||
fzf-tmux - open fzf in tmux split pane
|
fzf-tmux - open fzf in tmux split pane
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
THE SOFTWARE.
|
THE SOFTWARE.
|
||||||
..
|
..
|
||||||
.TH fzf 1 "Mar 2017" "fzf 0.16.6" "fzf - a command-line fuzzy finder"
|
.TH fzf 1 "Apr 2017" "fzf 0.16.7" "fzf - a command-line fuzzy finder"
|
||||||
|
|
||||||
.SH NAME
|
.SH NAME
|
||||||
fzf - a command-line fuzzy finder
|
fzf - a command-line fuzzy finder
|
||||||
@@ -352,6 +352,9 @@ ncurses finder only after the input stream is complete.
|
|||||||
.RS
|
.RS
|
||||||
e.g. \fBfzf --multi | fzf --sync\fR
|
e.g. \fBfzf --multi | fzf --sync\fR
|
||||||
.RE
|
.RE
|
||||||
|
.TP
|
||||||
|
.B "--version"
|
||||||
|
Display version information and exit
|
||||||
|
|
||||||
.SH ENVIRONMENT VARIABLES
|
.SH ENVIRONMENT VARIABLES
|
||||||
.TP
|
.TP
|
||||||
@@ -436,6 +439,7 @@ e.g. \fBfzf --bind=ctrl-j:accept,ctrl-k:kill-line\fR
|
|||||||
.B AVAILABLE KEYS: (SYNONYMS)
|
.B AVAILABLE KEYS: (SYNONYMS)
|
||||||
\fIctrl-[a-z]\fR
|
\fIctrl-[a-z]\fR
|
||||||
\fIctrl-space\fR
|
\fIctrl-space\fR
|
||||||
|
\fIctrl-alt-[a-z]\fR
|
||||||
\fIalt-[a-z]\fR
|
\fIalt-[a-z]\fR
|
||||||
\fIalt-[0-9]\fR
|
\fIalt-[0-9]\fR
|
||||||
\fIf[1-12]\fR
|
\fIf[1-12]\fR
|
||||||
|
|||||||
145
plugin/fzf.vim
145
plugin/fzf.vim
@@ -26,10 +26,56 @@ if exists('g:loaded_fzf')
|
|||||||
endif
|
endif
|
||||||
let g:loaded_fzf = 1
|
let g:loaded_fzf = 1
|
||||||
|
|
||||||
|
let s:is_win = has('win32') || has('win64')
|
||||||
|
if s:is_win && &shellslash
|
||||||
|
set noshellslash
|
||||||
|
let s:base_dir = expand('<sfile>:h:h')
|
||||||
|
set shellslash
|
||||||
|
else
|
||||||
|
let s:base_dir = expand('<sfile>:h:h')
|
||||||
|
endif
|
||||||
|
if s:is_win
|
||||||
|
function! s:fzf_call(fn, ...)
|
||||||
|
let shellslash = &shellslash
|
||||||
|
try
|
||||||
|
set noshellslash
|
||||||
|
return call(a:fn, a:000)
|
||||||
|
finally
|
||||||
|
let &shellslash = shellslash
|
||||||
|
endtry
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! s:fzf_shellescape(path)
|
||||||
|
return substitute(s:fzf_call('shellescape', a:path), '[^\\]\zs\\"$', '\\\\"', '')
|
||||||
|
endfunction
|
||||||
|
else
|
||||||
|
function! s:fzf_call(fn, ...)
|
||||||
|
return call(a:fn, a:000)
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! s:fzf_shellescape(path)
|
||||||
|
return shellescape(a:path)
|
||||||
|
endfunction
|
||||||
|
endif
|
||||||
|
|
||||||
|
function! s:fzf_getcwd()
|
||||||
|
return s:fzf_call('getcwd')
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! s:fzf_fnamemodify(fname, mods)
|
||||||
|
return s:fzf_call('fnamemodify', a:fname, a:mods)
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! s:fzf_expand(fmt)
|
||||||
|
return s:fzf_call('expand', a:fmt)
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
function! s:fzf_tempname()
|
||||||
|
return s:fzf_call('tempname')
|
||||||
|
endfunction
|
||||||
|
|
||||||
let s:default_layout = { 'down': '~40%' }
|
let s:default_layout = { 'down': '~40%' }
|
||||||
let s:layout_keys = ['window', 'up', 'down', 'left', 'right']
|
let s:layout_keys = ['window', 'up', 'down', 'left', 'right']
|
||||||
let s:is_win = has('win32') || has('win64')
|
|
||||||
let s:base_dir = expand('<sfile>:h:h')
|
|
||||||
let s:fzf_go = s:base_dir.'/bin/fzf'
|
let s:fzf_go = s:base_dir.'/bin/fzf'
|
||||||
let s:fzf_tmux = s:base_dir.'/bin/fzf-tmux'
|
let s:fzf_tmux = s:base_dir.'/bin/fzf-tmux'
|
||||||
let s:install = s:base_dir.'/install'
|
let s:install = s:base_dir.'/install'
|
||||||
@@ -41,7 +87,7 @@ set cpo&vim
|
|||||||
function! s:fzf_exec()
|
function! s:fzf_exec()
|
||||||
if !exists('s:exec')
|
if !exists('s:exec')
|
||||||
if executable(s:fzf_go)
|
if executable(s:fzf_go)
|
||||||
let s:exec = s:fzf_go
|
let s:exec = s:fzf_expand(s:fzf_go)
|
||||||
elseif executable('fzf')
|
elseif executable('fzf')
|
||||||
let s:exec = 'fzf'
|
let s:exec = 'fzf'
|
||||||
elseif s:is_win
|
elseif s:is_win
|
||||||
@@ -62,7 +108,7 @@ function! s:fzf_exec()
|
|||||||
throw 'fzf executable not found'
|
throw 'fzf executable not found'
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
return s:shellesc(s:exec)
|
return s:is_win ? s:exec : s:shellesc(s:exec)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:tmux_enabled()
|
function! s:tmux_enabled()
|
||||||
@@ -133,7 +179,7 @@ function! s:has_any(dict, keys)
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:open(cmd, target)
|
function! s:open(cmd, target)
|
||||||
if stridx('edit', a:cmd) == 0 && fnamemodify(a:target, ':p') ==# expand('%:p')
|
if stridx('edit', a:cmd) == 0 && s:fzf_fnamemodify(a:target, ':p') ==# s:fzf_expand('%:p')
|
||||||
return
|
return
|
||||||
endif
|
endif
|
||||||
execute a:cmd s:escape(a:target)
|
execute a:cmd s:escape(a:target)
|
||||||
@@ -148,11 +194,11 @@ function! s:common_sink(action, lines) abort
|
|||||||
if len(a:lines) > 1
|
if len(a:lines) > 1
|
||||||
augroup fzf_swap
|
augroup fzf_swap
|
||||||
autocmd SwapExists * let v:swapchoice='o'
|
autocmd SwapExists * let v:swapchoice='o'
|
||||||
\| call s:warn('fzf: E325: swap file exists: '.expand('<afile>'))
|
\| call s:warn('fzf: E325: swap file exists: '.s:fzf_expand('<afile>'))
|
||||||
augroup END
|
augroup END
|
||||||
endif
|
endif
|
||||||
try
|
try
|
||||||
let empty = empty(expand('%')) && line('$') == 1 && empty(getline(1)) && !&modified
|
let empty = empty(s:fzf_expand('%')) && line('$') == 1 && empty(getline(1)) && !&modified
|
||||||
let autochdir = &autochdir
|
let autochdir = &autochdir
|
||||||
set noautochdir
|
set noautochdir
|
||||||
for item in a:lines
|
for item in a:lines
|
||||||
@@ -202,6 +248,11 @@ function! s:validate_layout(layout)
|
|||||||
return a:layout
|
return a:layout
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
function! s:evaluate_opts(options)
|
||||||
|
return type(a:options) == type([]) ?
|
||||||
|
\ join(map(copy(a:options), 's:fzf_shellescape(v:val)')) : a:options
|
||||||
|
endfunction
|
||||||
|
|
||||||
" [name string,] [opts dict,] [fullscreen boolean]
|
" [name string,] [opts dict,] [fullscreen boolean]
|
||||||
function! fzf#wrap(...)
|
function! fzf#wrap(...)
|
||||||
let args = ['', {}, 0]
|
let args = ['', {}, 0]
|
||||||
@@ -238,15 +289,16 @@ function! fzf#wrap(...)
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
" Colors: g:fzf_colors
|
" Colors: g:fzf_colors
|
||||||
let opts.options = s:defaults() .' '. get(opts, 'options', '')
|
let opts.options = s:defaults() .' '. s:evaluate_opts(get(opts, 'options', ''))
|
||||||
|
|
||||||
" History: g:fzf_history_dir
|
" History: g:fzf_history_dir
|
||||||
if len(name) && len(get(g:, 'fzf_history_dir', ''))
|
if len(name) && len(get(g:, 'fzf_history_dir', ''))
|
||||||
let dir = expand(g:fzf_history_dir)
|
let dir = s:fzf_expand(g:fzf_history_dir)
|
||||||
if !isdirectory(dir)
|
if !isdirectory(dir)
|
||||||
call mkdir(dir, 'p')
|
call mkdir(dir, 'p')
|
||||||
endif
|
endif
|
||||||
let opts.options = join(['--history', s:escape(dir.'/'.name), opts.options])
|
let history = s:is_win ? s:fzf_shellescape(dir.'\'.name) : s:escape(dir.'/'.name)
|
||||||
|
let opts.options = join(['--history', history, opts.options])
|
||||||
endif
|
endif
|
||||||
|
|
||||||
" Action: g:fzf_action
|
" Action: g:fzf_action
|
||||||
@@ -262,19 +314,6 @@ function! fzf#wrap(...)
|
|||||||
return opts
|
return opts
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! fzf#shellescape(path)
|
|
||||||
if s:is_win
|
|
||||||
let shellslash = &shellslash
|
|
||||||
try
|
|
||||||
set noshellslash
|
|
||||||
return shellescape(a:path)
|
|
||||||
finally
|
|
||||||
let &shellslash = shellslash
|
|
||||||
endtry
|
|
||||||
endif
|
|
||||||
return shellescape(a:path)
|
|
||||||
endfunction
|
|
||||||
|
|
||||||
function! fzf#run(...) abort
|
function! fzf#run(...) abort
|
||||||
try
|
try
|
||||||
let oshell = &shell
|
let oshell = &shell
|
||||||
@@ -287,13 +326,16 @@ try
|
|||||||
set shell=sh
|
set shell=sh
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if has('nvim') && len(filter(range(1, bufnr('$')), 'bufname(v:val) =~# ";#FZF"'))
|
if has('nvim')
|
||||||
call s:warn('FZF is already running!')
|
let running = filter(range(1, bufnr('$')), "bufname(v:val) =~# ';#FZF'")
|
||||||
|
if len(running)
|
||||||
|
call s:warn('FZF is already running (in buffer '.join(running, ', ').')!')
|
||||||
return []
|
return []
|
||||||
endif
|
endif
|
||||||
|
endif
|
||||||
let dict = exists('a:1') ? s:upgrade(a:1) : {}
|
let dict = exists('a:1') ? s:upgrade(a:1) : {}
|
||||||
let temps = { 'result': tempname() }
|
let temps = { 'result': s:fzf_tempname() }
|
||||||
let optstr = get(dict, 'options', '')
|
let optstr = s:evaluate_opts(get(dict, 'options', ''))
|
||||||
try
|
try
|
||||||
let fzf_exec = s:fzf_exec()
|
let fzf_exec = s:fzf_exec()
|
||||||
catch
|
catch
|
||||||
@@ -301,11 +343,11 @@ try
|
|||||||
endtry
|
endtry
|
||||||
|
|
||||||
if has('nvim') && !has_key(dict, 'dir')
|
if has('nvim') && !has_key(dict, 'dir')
|
||||||
let dict.dir = getcwd()
|
let dict.dir = s:fzf_getcwd()
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if !has_key(dict, 'source') && !empty($FZF_DEFAULT_COMMAND)
|
if !has_key(dict, 'source') && !empty($FZF_DEFAULT_COMMAND)
|
||||||
let temps.source = tempname().(s:is_win ? '.bat' : '')
|
let temps.source = s:fzf_tempname().(s:is_win ? '.bat' : '')
|
||||||
call writefile((s:is_win ? ['@echo off'] : []) + split($FZF_DEFAULT_COMMAND, "\n"), temps.source)
|
call writefile((s:is_win ? ['@echo off'] : []) + split($FZF_DEFAULT_COMMAND, "\n"), temps.source)
|
||||||
let dict.source = (empty($SHELL) ? &shell : $SHELL) . (s:is_win ? ' /c ' : ' ') . s:shellesc(temps.source)
|
let dict.source = (empty($SHELL) ? &shell : $SHELL) . (s:is_win ? ' /c ' : ' ') . s:shellesc(temps.source)
|
||||||
endif
|
endif
|
||||||
@@ -316,7 +358,7 @@ try
|
|||||||
if type == 1
|
if type == 1
|
||||||
let prefix = source.'|'
|
let prefix = source.'|'
|
||||||
elseif type == 3
|
elseif type == 3
|
||||||
let temps.input = tempname()
|
let temps.input = s:fzf_tempname()
|
||||||
call writefile(source, temps.input)
|
call writefile(source, temps.input)
|
||||||
let prefix = (s:is_win ? 'type ' : 'cat ').s:shellesc(temps.input).'|'
|
let prefix = (s:is_win ? 'type ' : 'cat ').s:shellesc(temps.input).'|'
|
||||||
else
|
else
|
||||||
@@ -330,14 +372,15 @@ try
|
|||||||
let use_height = has_key(dict, 'down') &&
|
let use_height = has_key(dict, 'down') &&
|
||||||
\ !(has('nvim') || s:is_win || s:present(dict, 'up', 'left', 'right')) &&
|
\ !(has('nvim') || s:is_win || s:present(dict, 'up', 'left', 'right')) &&
|
||||||
\ executable('tput') && filereadable('/dev/tty')
|
\ executable('tput') && filereadable('/dev/tty')
|
||||||
let use_term = has('nvim')
|
let use_term = has('nvim') && !s:is_win
|
||||||
let use_tmux = (!use_height && !use_term || prefer_tmux) && s:tmux_enabled() && s:splittable(dict)
|
let use_tmux = (!use_height && !use_term || prefer_tmux) && s:tmux_enabled() && s:splittable(dict)
|
||||||
if prefer_tmux && use_tmux
|
if prefer_tmux && use_tmux
|
||||||
let use_height = 0
|
let use_height = 0
|
||||||
let use_term = 0
|
let use_term = 0
|
||||||
endif
|
endif
|
||||||
if use_height
|
if use_height
|
||||||
let optstr .= ' --height='.s:calc_size(&lines, dict.down, dict)
|
let height = s:calc_size(&lines, dict.down, dict)
|
||||||
|
let optstr .= ' --height='.height
|
||||||
elseif use_term
|
elseif use_term
|
||||||
let optstr .= ' --no-height'
|
let optstr .= ' --no-height'
|
||||||
endif
|
endif
|
||||||
@@ -391,13 +434,13 @@ endfunction
|
|||||||
|
|
||||||
function! s:pushd(dict)
|
function! s:pushd(dict)
|
||||||
if s:present(a:dict, 'dir')
|
if s:present(a:dict, 'dir')
|
||||||
let cwd = getcwd()
|
let cwd = s:fzf_getcwd()
|
||||||
if get(a:dict, 'prev_dir', '') ==# cwd
|
if get(a:dict, 'prev_dir', '') ==# cwd
|
||||||
return 1
|
return 1
|
||||||
endif
|
endif
|
||||||
let a:dict.prev_dir = cwd
|
let a:dict.prev_dir = cwd
|
||||||
execute 'lcd' s:escape(a:dict.dir)
|
execute 'lcd' s:escape(a:dict.dir)
|
||||||
let a:dict.dir = getcwd()
|
let a:dict.dir = s:fzf_getcwd()
|
||||||
return 1
|
return 1
|
||||||
endif
|
endif
|
||||||
return 0
|
return 0
|
||||||
@@ -461,6 +504,23 @@ function! s:execute(dict, command, use_height, temps) abort
|
|||||||
else
|
else
|
||||||
let command = a:use_height ? a:command : escaped
|
let command = a:use_height ? a:command : escaped
|
||||||
endif
|
endif
|
||||||
|
if s:is_win
|
||||||
|
let batchfile = s:fzf_tempname().'.bat'
|
||||||
|
call writefile(['@echo off', command], batchfile)
|
||||||
|
let command = batchfile
|
||||||
|
if has('nvim')
|
||||||
|
let s:dict = a:dict
|
||||||
|
let s:temps = a:temps
|
||||||
|
let fzf = {}
|
||||||
|
function! fzf.on_exit(job_id, exit_status, event) dict
|
||||||
|
let lines = s:collect(s:temps)
|
||||||
|
call s:callback(s:dict, lines)
|
||||||
|
endfunction
|
||||||
|
let cmd = 'start /wait cmd /c '.command
|
||||||
|
call jobstart(cmd, fzf)
|
||||||
|
return []
|
||||||
|
endif
|
||||||
|
endif
|
||||||
if a:use_height
|
if a:use_height
|
||||||
let stdin = has_key(a:dict, 'source') ? '' : '< /dev/tty'
|
let stdin = has_key(a:dict, 'source') ? '' : '< /dev/tty'
|
||||||
call system(printf('tput cup %d > /dev/tty; tput cnorm > /dev/tty; %s %s 2> /dev/tty', &lines, command, stdin))
|
call system(printf('tput cup %d > /dev/tty; tput cnorm > /dev/tty; %s %s 2> /dev/tty', &lines, command, stdin))
|
||||||
@@ -672,19 +732,24 @@ let s:default_action = {
|
|||||||
|
|
||||||
function! s:shortpath()
|
function! s:shortpath()
|
||||||
let short = pathshorten(fnamemodify(getcwd(), ':~:.'))
|
let short = pathshorten(fnamemodify(getcwd(), ':~:.'))
|
||||||
return empty(short) ? '~/' : short . (short =~ '/$' ? '' : '/')
|
let slash = (s:is_win && !&shellslash) ? '\' : '/'
|
||||||
|
return empty(short) ? '~'.slash : short . (short =~ slash.'$' ? '' : slash)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:cmd(bang, ...) abort
|
function! s:cmd(bang, ...) abort
|
||||||
let args = copy(a:000)
|
let args = copy(a:000)
|
||||||
let opts = { 'options': '--multi ' }
|
let opts = { 'options': ['--multi'] }
|
||||||
if len(args) && isdirectory(expand(args[-1]))
|
if len(args) && isdirectory(expand(args[-1]))
|
||||||
let opts.dir = substitute(substitute(remove(args, -1), '\\\(["'']\)', '\1', 'g'), '[/\\]*$', '/', '')
|
let opts.dir = substitute(substitute(remove(args, -1), '\\\(["'']\)', '\1', 'g'), '[/\\]*$', '/', '')
|
||||||
let opts.options .= ' --prompt '.fzf#shellescape(opts.dir)
|
if s:is_win && !&shellslash
|
||||||
else
|
let opts.dir = substitute(opts.dir, '/', '\\', 'g')
|
||||||
let opts.options .= ' --prompt '.fzf#shellescape(s:shortpath())
|
|
||||||
endif
|
endif
|
||||||
let opts.options .= ' '.join(args)
|
let prompt = opts.dir
|
||||||
|
else
|
||||||
|
let prompt = s:shortpath()
|
||||||
|
endif
|
||||||
|
call extend(opts.options, ['--prompt', prompt])
|
||||||
|
call extend(opts.options, args)
|
||||||
call fzf#run(fzf#wrap('FZF', opts, a:bang))
|
call fzf#run(fzf#wrap('FZF', opts, a:bang))
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
|||||||
@@ -234,7 +234,7 @@ _fzf_complete_telnet() {
|
|||||||
_fzf_complete_ssh() {
|
_fzf_complete_ssh() {
|
||||||
_fzf_complete '+m' "$@" < <(
|
_fzf_complete '+m' "$@" < <(
|
||||||
cat <(cat ~/.ssh/config /etc/ssh/ssh_config 2> /dev/null | command grep -i '^host' | command grep -v '*') \
|
cat <(cat ~/.ssh/config /etc/ssh/ssh_config 2> /dev/null | command grep -i '^host' | command grep -v '*') \
|
||||||
<(command grep -oE '^[a-z0-9.,-]+' ~/.ssh/known_hosts | tr ',' '\n' | awk '{ print $1 " " $1 }') \
|
<(command grep -oE '^[a-z0-9.,:-]+' ~/.ssh/known_hosts | tr ',' '\n' | awk '{ print $1 " " $1 }') \
|
||||||
<(command grep -v '^\s*\(#\|$\)' /etc/hosts | command grep -Fv '0.0.0.0') |
|
<(command grep -v '^\s*\(#\|$\)' /etc/hosts | command grep -Fv '0.0.0.0') |
|
||||||
awk '{if (length($2) > 0) {print $2}}' | sort -u
|
awk '{if (length($2) > 0) {print $2}}' | sort -u
|
||||||
)
|
)
|
||||||
@@ -304,7 +304,7 @@ done
|
|||||||
|
|
||||||
# Directory
|
# Directory
|
||||||
for cmd in $d_cmds; do
|
for cmd in $d_cmds; do
|
||||||
_fzf_defc "$cmd" _fzf_dir_completion "-o nospace -o plusdirs"
|
_fzf_defc "$cmd" _fzf_dir_completion "-o nospace -o dirnames"
|
||||||
done
|
done
|
||||||
|
|
||||||
unset _fzf_defc
|
unset _fzf_defc
|
||||||
|
|||||||
@@ -117,7 +117,7 @@ _fzf_complete_telnet() {
|
|||||||
_fzf_complete_ssh() {
|
_fzf_complete_ssh() {
|
||||||
_fzf_complete '+m' "$@" < <(
|
_fzf_complete '+m' "$@" < <(
|
||||||
command cat <(cat ~/.ssh/config /etc/ssh/ssh_config 2> /dev/null | command grep -i '^host' | command grep -v '*') \
|
command cat <(cat ~/.ssh/config /etc/ssh/ssh_config 2> /dev/null | command grep -i '^host' | command grep -v '*') \
|
||||||
<(command grep -oE '^[a-z0-9.,-]+' ~/.ssh/known_hosts | tr ',' '\n' | awk '{ print $1 " " $1 }') \
|
<(command grep -oE '^[a-z0-9.,:-]+' ~/.ssh/known_hosts | tr ',' '\n' | awk '{ print $1 " " $1 }') \
|
||||||
<(command grep -v '^\s*\(#\|$\)' /etc/hosts | command grep -Fv '0.0.0.0') |
|
<(command grep -v '^\s*\(#\|$\)' /etc/hosts | command grep -Fv '0.0.0.0') |
|
||||||
awk '{if (length($2) > 0) {print $2}}' | sort -u
|
awk '{if (length($2) > 0) {print $2}}' | sort -u
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import (
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
// Current version
|
// Current version
|
||||||
version = "0.16.6"
|
version = "0.16.7"
|
||||||
|
|
||||||
// Core
|
// Core
|
||||||
coordinatorDelayMax time.Duration = 100 * time.Millisecond
|
coordinatorDelayMax time.Duration = 100 * time.Millisecond
|
||||||
|
|||||||
2
src/deps
2
src/deps
@@ -14,5 +14,5 @@ reset() (
|
|||||||
|
|
||||||
reset github.com/junegunn/go-isatty 66b8e73f3f5cda9f96b69efd03dd3d7fc4a5cdb8
|
reset github.com/junegunn/go-isatty 66b8e73f3f5cda9f96b69efd03dd3d7fc4a5cdb8
|
||||||
reset github.com/junegunn/go-runewidth 14207d285c6c197daabb5c9793d63e7af9ab2d50
|
reset github.com/junegunn/go-runewidth 14207d285c6c197daabb5c9793d63e7af9ab2d50
|
||||||
reset github.com/junegunn/go-shellwords 33bd8f1ebe16d6e5eb688cc885749a63059e9167
|
reset github.com/junegunn/go-shellwords 02e3cf038dcea8290e44424da473dd12be796a8a
|
||||||
reset golang.org/x/crypto abc5fa7ad02123a41f02bf1391c9760f7586e608
|
reset golang.org/x/crypto abc5fa7ad02123a41f02bf1391c9760f7586e608
|
||||||
|
|||||||
@@ -86,6 +86,7 @@ const usage = `usage: fzf [options]
|
|||||||
--read0 Read input delimited by ASCII NUL characters
|
--read0 Read input delimited by ASCII NUL characters
|
||||||
--print0 Print output delimited by ASCII NUL characters
|
--print0 Print output delimited by ASCII NUL characters
|
||||||
--sync Synchronous search for multi-staged filtering
|
--sync Synchronous search for multi-staged filtering
|
||||||
|
--version Display version information and exit
|
||||||
|
|
||||||
Environment variables
|
Environment variables
|
||||||
FZF_DEFAULT_COMMAND Default command to use when input is tty
|
FZF_DEFAULT_COMMAND Default command to use when input is tty
|
||||||
@@ -400,7 +401,7 @@ func parseKeyChords(str string, message string) map[int]string {
|
|||||||
case "ctrl-space":
|
case "ctrl-space":
|
||||||
chord = tui.CtrlSpace
|
chord = tui.CtrlSpace
|
||||||
case "alt-enter", "alt-return":
|
case "alt-enter", "alt-return":
|
||||||
chord = tui.AltEnter
|
chord = tui.CtrlAltM
|
||||||
case "alt-space":
|
case "alt-space":
|
||||||
chord = tui.AltSpace
|
chord = tui.AltSpace
|
||||||
case "alt-/":
|
case "alt-/":
|
||||||
@@ -436,7 +437,9 @@ func parseKeyChords(str string, message string) map[int]string {
|
|||||||
case "f12":
|
case "f12":
|
||||||
chord = tui.F12
|
chord = tui.F12
|
||||||
default:
|
default:
|
||||||
if len(key) == 6 && strings.HasPrefix(lkey, "ctrl-") && isAlphabet(lkey[5]) {
|
if len(key) == 10 && strings.HasPrefix(lkey, "ctrl-alt-") && isAlphabet(lkey[9]) {
|
||||||
|
chord = tui.CtrlAltA + int(lkey[9]) - 'a'
|
||||||
|
} else if len(key) == 6 && strings.HasPrefix(lkey, "ctrl-") && isAlphabet(lkey[5]) {
|
||||||
chord = tui.CtrlA + int(lkey[5]) - 'a'
|
chord = tui.CtrlA + int(lkey[5]) - 'a'
|
||||||
} else if len(key) == 5 && strings.HasPrefix(lkey, "alt-") && isAlphabet(lkey[4]) {
|
} else if len(key) == 5 && strings.HasPrefix(lkey, "alt-") && isAlphabet(lkey[4]) {
|
||||||
chord = tui.AltA + int(lkey[4]) - 'a'
|
chord = tui.AltA + int(lkey[4]) - 'a'
|
||||||
|
|||||||
@@ -125,14 +125,14 @@ func TestIrrelevantNth(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestParseKeys(t *testing.T) {
|
func TestParseKeys(t *testing.T) {
|
||||||
pairs := parseKeyChords("ctrl-z,alt-z,f2,@,Alt-a,!,ctrl-G,J,g,ALT-enter,alt-SPACE", "")
|
pairs := parseKeyChords("ctrl-z,alt-z,f2,@,Alt-a,!,ctrl-G,J,g,ctrl-alt-a,ALT-enter,alt-SPACE", "")
|
||||||
check := func(i int, s string) {
|
check := func(i int, s string) {
|
||||||
if pairs[i] != s {
|
if pairs[i] != s {
|
||||||
t.Errorf("%s != %s", pairs[i], s)
|
t.Errorf("%s != %s", pairs[i], s)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if len(pairs) != 11 {
|
if len(pairs) != 12 {
|
||||||
t.Error(11)
|
t.Error(12)
|
||||||
}
|
}
|
||||||
check(tui.CtrlZ, "ctrl-z")
|
check(tui.CtrlZ, "ctrl-z")
|
||||||
check(tui.AltZ, "alt-z")
|
check(tui.AltZ, "alt-z")
|
||||||
@@ -143,7 +143,8 @@ func TestParseKeys(t *testing.T) {
|
|||||||
check(tui.CtrlA+'g'-'a', "ctrl-G")
|
check(tui.CtrlA+'g'-'a', "ctrl-G")
|
||||||
check(tui.AltZ+'J', "J")
|
check(tui.AltZ+'J', "J")
|
||||||
check(tui.AltZ+'g', "g")
|
check(tui.AltZ+'g', "g")
|
||||||
check(tui.AltEnter, "ALT-enter")
|
check(tui.CtrlAltA, "ctrl-alt-a")
|
||||||
|
check(tui.CtrlAltM, "ALT-enter")
|
||||||
check(tui.AltSpace, "alt-SPACE")
|
check(tui.AltSpace, "alt-SPACE")
|
||||||
|
|
||||||
// Synonyms
|
// Synonyms
|
||||||
|
|||||||
@@ -59,6 +59,7 @@ type Terminal struct {
|
|||||||
inlineInfo bool
|
inlineInfo bool
|
||||||
prompt string
|
prompt string
|
||||||
reverse bool
|
reverse bool
|
||||||
|
fullscreen bool
|
||||||
hscroll bool
|
hscroll bool
|
||||||
hscrollOff int
|
hscrollOff int
|
||||||
wordRubout string
|
wordRubout string
|
||||||
@@ -141,6 +142,7 @@ const (
|
|||||||
reqList
|
reqList
|
||||||
reqJump
|
reqJump
|
||||||
reqRefresh
|
reqRefresh
|
||||||
|
reqReinit
|
||||||
reqRedraw
|
reqRedraw
|
||||||
reqClose
|
reqClose
|
||||||
reqPrintQuery
|
reqPrintQuery
|
||||||
@@ -210,6 +212,7 @@ const (
|
|||||||
actExecute
|
actExecute
|
||||||
actExecuteSilent
|
actExecuteSilent
|
||||||
actExecuteMulti // Deprecated
|
actExecuteMulti // Deprecated
|
||||||
|
actSigStop
|
||||||
)
|
)
|
||||||
|
|
||||||
func toActions(types ...actionType) []action {
|
func toActions(types ...actionType) []action {
|
||||||
@@ -246,6 +249,9 @@ func defaultKeymap() map[int][]action {
|
|||||||
keymap[tui.CtrlU] = toActions(actUnixLineDiscard)
|
keymap[tui.CtrlU] = toActions(actUnixLineDiscard)
|
||||||
keymap[tui.CtrlW] = toActions(actUnixWordRubout)
|
keymap[tui.CtrlW] = toActions(actUnixWordRubout)
|
||||||
keymap[tui.CtrlY] = toActions(actYank)
|
keymap[tui.CtrlY] = toActions(actYank)
|
||||||
|
if !util.IsWindows() {
|
||||||
|
keymap[tui.CtrlZ] = toActions(actSigStop)
|
||||||
|
}
|
||||||
|
|
||||||
keymap[tui.AltB] = toActions(actBackwardWord)
|
keymap[tui.AltB] = toActions(actBackwardWord)
|
||||||
keymap[tui.SLeft] = toActions(actBackwardWord)
|
keymap[tui.SLeft] = toActions(actBackwardWord)
|
||||||
@@ -295,7 +301,8 @@ func NewTerminal(opts *Options, eventBox *util.EventBox) *Terminal {
|
|||||||
strongAttr = tui.AttrRegular
|
strongAttr = tui.AttrRegular
|
||||||
}
|
}
|
||||||
var renderer tui.Renderer
|
var renderer tui.Renderer
|
||||||
if opts.Height.size == 0 || opts.Height.percent && opts.Height.size == 100 {
|
fullscreen := opts.Height.size == 0 || opts.Height.percent && opts.Height.size == 100
|
||||||
|
if fullscreen {
|
||||||
if tui.HasFullscreenRenderer() {
|
if tui.HasFullscreenRenderer() {
|
||||||
renderer = tui.NewFullscreenRenderer(opts.Theme, opts.Black, opts.Mouse)
|
renderer = tui.NewFullscreenRenderer(opts.Theme, opts.Black, opts.Mouse)
|
||||||
} else {
|
} else {
|
||||||
@@ -337,6 +344,7 @@ func NewTerminal(opts *Options, eventBox *util.EventBox) *Terminal {
|
|||||||
inlineInfo: opts.InlineInfo,
|
inlineInfo: opts.InlineInfo,
|
||||||
prompt: opts.Prompt,
|
prompt: opts.Prompt,
|
||||||
reverse: opts.Reverse,
|
reverse: opts.Reverse,
|
||||||
|
fullscreen: fullscreen,
|
||||||
hscroll: opts.Hscroll,
|
hscroll: opts.Hscroll,
|
||||||
hscrollOff: opts.HscrollOff,
|
hscrollOff: opts.HscrollOff,
|
||||||
wordRubout: wordRubout,
|
wordRubout: wordRubout,
|
||||||
@@ -572,6 +580,7 @@ func (t *Terminal) resizeWindows() {
|
|||||||
pwidth += 1
|
pwidth += 1
|
||||||
}
|
}
|
||||||
t.pwindow = t.tui.NewWindow(y+1, x+2, pwidth, h-2, tui.BorderNone)
|
t.pwindow = t.tui.NewWindow(y+1, x+2, pwidth, h-2, tui.BorderNone)
|
||||||
|
os.Setenv("FZF_PREVIEW_HEIGHT", strconv.Itoa(h-2))
|
||||||
}
|
}
|
||||||
switch t.preview.position {
|
switch t.preview.position {
|
||||||
case posUp:
|
case posUp:
|
||||||
@@ -1170,6 +1179,12 @@ func replacePlaceholder(template string, stripAnsi bool, delimiter Delimiter, fo
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (t *Terminal) redraw() {
|
||||||
|
t.tui.Clear()
|
||||||
|
t.tui.Refresh()
|
||||||
|
t.printAll()
|
||||||
|
}
|
||||||
|
|
||||||
func (t *Terminal) executeCommand(template string, forcePlus bool, background bool) {
|
func (t *Terminal) executeCommand(template string, forcePlus bool, background bool) {
|
||||||
valid, list := t.buildPlusList(template, forcePlus)
|
valid, list := t.buildPlusList(template, forcePlus)
|
||||||
if !valid {
|
if !valid {
|
||||||
@@ -1181,12 +1196,10 @@ func (t *Terminal) executeCommand(template string, forcePlus bool, background bo
|
|||||||
cmd.Stdin = os.Stdin
|
cmd.Stdin = os.Stdin
|
||||||
cmd.Stdout = os.Stdout
|
cmd.Stdout = os.Stdout
|
||||||
cmd.Stderr = os.Stderr
|
cmd.Stderr = os.Stderr
|
||||||
t.tui.Pause()
|
t.tui.Pause(true)
|
||||||
cmd.Run()
|
cmd.Run()
|
||||||
if t.tui.Resume() {
|
t.tui.Resume(true)
|
||||||
t.tui.Clear()
|
t.redraw()
|
||||||
t.printAll()
|
|
||||||
}
|
|
||||||
t.refresh()
|
t.refresh()
|
||||||
} else {
|
} else {
|
||||||
cmd.Run()
|
cmd.Run()
|
||||||
@@ -1244,6 +1257,15 @@ func (t *Terminal) Loop() {
|
|||||||
t.reqBox.Set(reqQuit, nil)
|
t.reqBox.Set(reqQuit, nil)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
contChan := make(chan os.Signal, 1)
|
||||||
|
notifyOnCont(contChan)
|
||||||
|
go func() {
|
||||||
|
for {
|
||||||
|
<-contChan
|
||||||
|
t.reqBox.Set(reqReinit, nil)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
resizeChan := make(chan os.Signal, 1)
|
resizeChan := make(chan os.Signal, 1)
|
||||||
notifyOnResize(resizeChan) // Non-portable
|
notifyOnResize(resizeChan) // Non-portable
|
||||||
go func() {
|
go func() {
|
||||||
@@ -1352,10 +1374,11 @@ func (t *Terminal) Loop() {
|
|||||||
t.printHeader()
|
t.printHeader()
|
||||||
case reqRefresh:
|
case reqRefresh:
|
||||||
t.suppress = false
|
t.suppress = false
|
||||||
|
case reqReinit:
|
||||||
|
t.tui.Resume(t.fullscreen)
|
||||||
|
t.redraw()
|
||||||
case reqRedraw:
|
case reqRedraw:
|
||||||
t.tui.Clear()
|
t.redraw()
|
||||||
t.tui.Refresh()
|
|
||||||
t.printAll()
|
|
||||||
case reqClose:
|
case reqClose:
|
||||||
t.tui.Close()
|
t.tui.Close()
|
||||||
if t.output() {
|
if t.output() {
|
||||||
@@ -1654,6 +1677,15 @@ func (t *Terminal) Loop() {
|
|||||||
t.input = []rune(t.history.next())
|
t.input = []rune(t.history.next())
|
||||||
t.cx = len(t.input)
|
t.cx = len(t.input)
|
||||||
}
|
}
|
||||||
|
case actSigStop:
|
||||||
|
p, err := os.FindProcess(os.Getpid())
|
||||||
|
if err == nil {
|
||||||
|
t.tui.Clear()
|
||||||
|
t.tui.Pause(t.fullscreen)
|
||||||
|
notifyStop(p)
|
||||||
|
t.mutex.Unlock()
|
||||||
|
return false
|
||||||
|
}
|
||||||
case actMouse:
|
case actMouse:
|
||||||
me := event.MouseEvent
|
me := event.MouseEvent
|
||||||
mx, my := me.X, me.Y
|
mx, my := me.X, me.Y
|
||||||
|
|||||||
@@ -11,3 +11,11 @@ import (
|
|||||||
func notifyOnResize(resizeChan chan<- os.Signal) {
|
func notifyOnResize(resizeChan chan<- os.Signal) {
|
||||||
signal.Notify(resizeChan, syscall.SIGWINCH)
|
signal.Notify(resizeChan, syscall.SIGWINCH)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func notifyStop(p *os.Process) {
|
||||||
|
p.Signal(syscall.SIGSTOP)
|
||||||
|
}
|
||||||
|
|
||||||
|
func notifyOnCont(resizeChan chan<- os.Signal) {
|
||||||
|
signal.Notify(resizeChan, syscall.SIGCONT)
|
||||||
|
}
|
||||||
|
|||||||
@@ -9,3 +9,11 @@ import (
|
|||||||
func notifyOnResize(resizeChan chan<- os.Signal) {
|
func notifyOnResize(resizeChan chan<- os.Signal) {
|
||||||
// TODO
|
// TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func notifyStop(p *os.Process) {
|
||||||
|
// NOOP
|
||||||
|
}
|
||||||
|
|
||||||
|
func notifyOnCont(resizeChan chan<- os.Signal) {
|
||||||
|
// NOOP
|
||||||
|
}
|
||||||
|
|||||||
@@ -26,12 +26,12 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func (r *FullscreenRenderer) Init() {}
|
func (r *FullscreenRenderer) Init() {}
|
||||||
func (r *FullscreenRenderer) Pause() {}
|
func (r *FullscreenRenderer) Pause(bool) {}
|
||||||
|
func (r *FullscreenRenderer) Resume(bool) {}
|
||||||
func (r *FullscreenRenderer) Clear() {}
|
func (r *FullscreenRenderer) Clear() {}
|
||||||
func (r *FullscreenRenderer) Refresh() {}
|
func (r *FullscreenRenderer) Refresh() {}
|
||||||
func (r *FullscreenRenderer) Close() {}
|
func (r *FullscreenRenderer) Close() {}
|
||||||
|
|
||||||
func (r *FullscreenRenderer) Resume() bool { return false }
|
|
||||||
func (r *FullscreenRenderer) DoesAutoWrap() bool { return false }
|
func (r *FullscreenRenderer) DoesAutoWrap() bool { return false }
|
||||||
func (r *FullscreenRenderer) IsOptimized() bool { return false }
|
func (r *FullscreenRenderer) IsOptimized() bool { return false }
|
||||||
func (r *FullscreenRenderer) GetChar() Event { return Event{} }
|
func (r *FullscreenRenderer) GetChar() Event { return Event{} }
|
||||||
|
|||||||
@@ -344,9 +344,10 @@ func (r *LightRenderer) escSequence(sz *int) Event {
|
|||||||
return Event{ESC, 0, nil}
|
return Event{ESC, 0, nil}
|
||||||
}
|
}
|
||||||
*sz = 2
|
*sz = 2
|
||||||
|
if r.buffer[1] >= 1 && r.buffer[1] <= 'z'-'a'+1 {
|
||||||
|
return Event{int(CtrlAltA + r.buffer[1] - 1), 0, nil}
|
||||||
|
}
|
||||||
switch r.buffer[1] {
|
switch r.buffer[1] {
|
||||||
case 13:
|
|
||||||
return Event{AltEnter, 0, nil}
|
|
||||||
case 32:
|
case 32:
|
||||||
return Event{AltSpace, 0, nil}
|
return Event{AltSpace, 0, nil}
|
||||||
case 47:
|
case 47:
|
||||||
@@ -521,8 +522,9 @@ func (r *LightRenderer) rmcup() {
|
|||||||
r.csi("?1049l")
|
r.csi("?1049l")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *LightRenderer) Pause() {
|
func (r *LightRenderer) Pause(clear bool) {
|
||||||
terminal.Restore(r.fd(), r.origState)
|
terminal.Restore(r.fd(), r.origState)
|
||||||
|
if clear {
|
||||||
if r.fullscreen {
|
if r.fullscreen {
|
||||||
r.rmcup()
|
r.rmcup()
|
||||||
} else {
|
} else {
|
||||||
@@ -531,17 +533,24 @@ func (r *LightRenderer) Pause() {
|
|||||||
}
|
}
|
||||||
r.flush()
|
r.flush()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (r *LightRenderer) Resume() bool {
|
func (r *LightRenderer) Resume(clear bool) {
|
||||||
terminal.MakeRaw(r.fd())
|
terminal.MakeRaw(r.fd())
|
||||||
|
if clear {
|
||||||
if r.fullscreen {
|
if r.fullscreen {
|
||||||
r.smcup()
|
r.smcup()
|
||||||
} else {
|
} else {
|
||||||
r.rmcup()
|
r.rmcup()
|
||||||
}
|
}
|
||||||
r.flush()
|
r.flush()
|
||||||
// Should redraw
|
} else if !r.fullscreen && r.mouse {
|
||||||
return true
|
// NOTE: Resume(false) is only called on SIGCONT after SIGSTOP.
|
||||||
|
// And It's highly likely that the offset we obtained at the beginning will
|
||||||
|
// no longer be correct, so we simply disable mouse input.
|
||||||
|
r.csi("?1000l")
|
||||||
|
r.mouse = false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *LightRenderer) Clear() {
|
func (r *LightRenderer) Clear() {
|
||||||
|
|||||||
@@ -176,12 +176,11 @@ func initPairs(theme *ColorTheme) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *FullscreenRenderer) Pause() {
|
func (r *FullscreenRenderer) Pause(bool) {
|
||||||
C.endwin()
|
C.endwin()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *FullscreenRenderer) Resume() bool {
|
func (r *FullscreenRenderer) Resume(bool) {
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *FullscreenRenderer) Close() {
|
func (r *FullscreenRenderer) Close() {
|
||||||
@@ -353,7 +352,7 @@ func escSequence() Event {
|
|||||||
case C.ERR:
|
case C.ERR:
|
||||||
return Event{ESC, 0, nil}
|
return Event{ESC, 0, nil}
|
||||||
case CtrlM:
|
case CtrlM:
|
||||||
return Event{AltEnter, 0, nil}
|
return Event{CtrlAltM, 0, nil}
|
||||||
case '/':
|
case '/':
|
||||||
return Event{AltSlash, 0, nil}
|
return Event{AltSlash, 0, nil}
|
||||||
case ' ':
|
case ' ':
|
||||||
|
|||||||
@@ -221,61 +221,68 @@ func (r *FullscreenRenderer) GetChar() Event {
|
|||||||
// process keyboard:
|
// process keyboard:
|
||||||
case *tcell.EventKey:
|
case *tcell.EventKey:
|
||||||
alt := (ev.Modifiers() & tcell.ModAlt) > 0
|
alt := (ev.Modifiers() & tcell.ModAlt) > 0
|
||||||
|
keyfn := func(r rune) int {
|
||||||
|
if alt {
|
||||||
|
return CtrlAltA - 'a' + int(r)
|
||||||
|
}
|
||||||
|
return CtrlA - 'a' + int(r)
|
||||||
|
}
|
||||||
switch ev.Key() {
|
switch ev.Key() {
|
||||||
case tcell.KeyCtrlA:
|
case tcell.KeyCtrlA:
|
||||||
return Event{CtrlA, 0, nil}
|
return Event{keyfn('a'), 0, nil}
|
||||||
case tcell.KeyCtrlB:
|
case tcell.KeyCtrlB:
|
||||||
return Event{CtrlB, 0, nil}
|
return Event{keyfn('b'), 0, nil}
|
||||||
case tcell.KeyCtrlC:
|
case tcell.KeyCtrlC:
|
||||||
return Event{CtrlC, 0, nil}
|
return Event{keyfn('c'), 0, nil}
|
||||||
case tcell.KeyCtrlD:
|
case tcell.KeyCtrlD:
|
||||||
return Event{CtrlD, 0, nil}
|
return Event{keyfn('d'), 0, nil}
|
||||||
case tcell.KeyCtrlE:
|
case tcell.KeyCtrlE:
|
||||||
return Event{CtrlE, 0, nil}
|
return Event{keyfn('e'), 0, nil}
|
||||||
case tcell.KeyCtrlF:
|
case tcell.KeyCtrlF:
|
||||||
return Event{CtrlF, 0, nil}
|
return Event{keyfn('f'), 0, nil}
|
||||||
case tcell.KeyCtrlG:
|
case tcell.KeyCtrlG:
|
||||||
return Event{CtrlG, 0, nil}
|
return Event{keyfn('g'), 0, nil}
|
||||||
|
case tcell.KeyCtrlH:
|
||||||
|
return Event{keyfn('h'), 0, nil}
|
||||||
|
case tcell.KeyCtrlI:
|
||||||
|
return Event{keyfn('i'), 0, nil}
|
||||||
case tcell.KeyCtrlJ:
|
case tcell.KeyCtrlJ:
|
||||||
return Event{CtrlJ, 0, nil}
|
return Event{keyfn('j'), 0, nil}
|
||||||
case tcell.KeyCtrlK:
|
case tcell.KeyCtrlK:
|
||||||
return Event{CtrlK, 0, nil}
|
return Event{keyfn('k'), 0, nil}
|
||||||
case tcell.KeyCtrlL:
|
case tcell.KeyCtrlL:
|
||||||
return Event{CtrlL, 0, nil}
|
return Event{keyfn('l'), 0, nil}
|
||||||
case tcell.KeyCtrlM:
|
case tcell.KeyCtrlM:
|
||||||
if alt {
|
return Event{keyfn('m'), 0, nil}
|
||||||
return Event{AltEnter, 0, nil}
|
|
||||||
}
|
|
||||||
return Event{CtrlM, 0, nil}
|
|
||||||
case tcell.KeyCtrlN:
|
case tcell.KeyCtrlN:
|
||||||
return Event{CtrlN, 0, nil}
|
return Event{keyfn('n'), 0, nil}
|
||||||
case tcell.KeyCtrlO:
|
case tcell.KeyCtrlO:
|
||||||
return Event{CtrlO, 0, nil}
|
return Event{keyfn('o'), 0, nil}
|
||||||
case tcell.KeyCtrlP:
|
case tcell.KeyCtrlP:
|
||||||
return Event{CtrlP, 0, nil}
|
return Event{keyfn('p'), 0, nil}
|
||||||
case tcell.KeyCtrlQ:
|
case tcell.KeyCtrlQ:
|
||||||
return Event{CtrlQ, 0, nil}
|
return Event{keyfn('q'), 0, nil}
|
||||||
case tcell.KeyCtrlR:
|
case tcell.KeyCtrlR:
|
||||||
return Event{CtrlR, 0, nil}
|
return Event{keyfn('r'), 0, nil}
|
||||||
case tcell.KeyCtrlS:
|
case tcell.KeyCtrlS:
|
||||||
return Event{CtrlS, 0, nil}
|
return Event{keyfn('s'), 0, nil}
|
||||||
case tcell.KeyCtrlT:
|
case tcell.KeyCtrlT:
|
||||||
return Event{CtrlT, 0, nil}
|
return Event{keyfn('t'), 0, nil}
|
||||||
case tcell.KeyCtrlU:
|
case tcell.KeyCtrlU:
|
||||||
return Event{CtrlU, 0, nil}
|
return Event{keyfn('u'), 0, nil}
|
||||||
case tcell.KeyCtrlV:
|
case tcell.KeyCtrlV:
|
||||||
return Event{CtrlV, 0, nil}
|
return Event{keyfn('v'), 0, nil}
|
||||||
case tcell.KeyCtrlW:
|
case tcell.KeyCtrlW:
|
||||||
return Event{CtrlW, 0, nil}
|
return Event{keyfn('w'), 0, nil}
|
||||||
case tcell.KeyCtrlX:
|
case tcell.KeyCtrlX:
|
||||||
return Event{CtrlX, 0, nil}
|
return Event{keyfn('x'), 0, nil}
|
||||||
case tcell.KeyCtrlY:
|
case tcell.KeyCtrlY:
|
||||||
return Event{CtrlY, 0, nil}
|
return Event{keyfn('y'), 0, nil}
|
||||||
case tcell.KeyCtrlZ:
|
case tcell.KeyCtrlZ:
|
||||||
return Event{CtrlZ, 0, nil}
|
return Event{keyfn('z'), 0, nil}
|
||||||
case tcell.KeyCtrlSpace:
|
case tcell.KeyCtrlSpace:
|
||||||
return Event{CtrlSpace, 0, nil}
|
return Event{CtrlSpace, 0, nil}
|
||||||
case tcell.KeyBackspace, tcell.KeyBackspace2:
|
case tcell.KeyBackspace2:
|
||||||
if alt {
|
if alt {
|
||||||
return Event{AltBS, 0, nil}
|
return Event{AltBS, 0, nil}
|
||||||
}
|
}
|
||||||
@@ -301,8 +308,6 @@ func (r *FullscreenRenderer) GetChar() Event {
|
|||||||
case tcell.KeyPgDn:
|
case tcell.KeyPgDn:
|
||||||
return Event{PgDn, 0, nil}
|
return Event{PgDn, 0, nil}
|
||||||
|
|
||||||
case tcell.KeyTab:
|
|
||||||
return Event{Tab, 0, nil}
|
|
||||||
case tcell.KeyBacktab:
|
case tcell.KeyBacktab:
|
||||||
return Event{BTab, 0, nil}
|
return Event{BTab, 0, nil}
|
||||||
|
|
||||||
@@ -359,13 +364,12 @@ func (r *FullscreenRenderer) GetChar() Event {
|
|||||||
return Event{Invalid, 0, nil}
|
return Event{Invalid, 0, nil}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *FullscreenRenderer) Pause() {
|
func (r *FullscreenRenderer) Pause(bool) {
|
||||||
_screen.Fini()
|
_screen.Fini()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *FullscreenRenderer) Resume() bool {
|
func (r *FullscreenRenderer) Resume(bool) {
|
||||||
r.initScreen()
|
r.initScreen()
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *FullscreenRenderer) Close() {
|
func (r *FullscreenRenderer) Close() {
|
||||||
|
|||||||
@@ -75,7 +75,6 @@ const (
|
|||||||
F11
|
F11
|
||||||
F12
|
F12
|
||||||
|
|
||||||
AltEnter
|
|
||||||
AltSpace
|
AltSpace
|
||||||
AltSlash
|
AltSlash
|
||||||
AltBS
|
AltBS
|
||||||
@@ -91,6 +90,8 @@ const ( // Reset iota
|
|||||||
AltE
|
AltE
|
||||||
AltF
|
AltF
|
||||||
AltZ = AltA + 'z' - 'a'
|
AltZ = AltA + 'z' - 'a'
|
||||||
|
CtrlAltA = AltZ + 1
|
||||||
|
CtrlAltM = CtrlAltA + 'm' - 'a'
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -205,8 +206,8 @@ const (
|
|||||||
|
|
||||||
type Renderer interface {
|
type Renderer interface {
|
||||||
Init()
|
Init()
|
||||||
Pause()
|
Pause(clear bool)
|
||||||
Resume() bool
|
Resume(clear bool)
|
||||||
Clear()
|
Clear()
|
||||||
RefreshWindows(windows []Window)
|
RefreshWindows(windows []Window)
|
||||||
Refresh()
|
Refresh()
|
||||||
|
|||||||
Reference in New Issue
Block a user