mirror of
https://github.com/junegunn/fzf.git
synced 2025-11-15 06:43:47 -05:00
Compare commits
26 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
61ba8d5a11 | ||
|
|
4a3a5ee70d | ||
|
|
f58a53a001 | ||
|
|
65c1b53275 | ||
|
|
0b43f988c7 | ||
|
|
f8e357fa19 | ||
|
|
c3a4e4cd23 | ||
|
|
9dac12cb32 | ||
|
|
d76a3646b7 | ||
|
|
d7c734acd6 | ||
|
|
ed13fc8618 | ||
|
|
edcd7c6aa6 | ||
|
|
b0fdd6db99 | ||
|
|
edf27f47f2 | ||
|
|
3b218b77eb | ||
|
|
1e02471940 | ||
|
|
1b9dadb3d3 | ||
|
|
c3827dea10 | ||
|
|
6a1b916598 | ||
|
|
a2c7b001d5 | ||
|
|
3c6e938bb1 | ||
|
|
5a0afc5fea | ||
|
|
f37be006c3 | ||
|
|
459c332351 | ||
|
|
153a87d84a | ||
|
|
05da892cd2 |
124
README.md
124
README.md
@@ -65,8 +65,9 @@ usage: fzf [options]
|
|||||||
-e, --extended-exact Extended-search mode (exact match)
|
-e, --extended-exact Extended-search mode (exact match)
|
||||||
-i Case-insensitive match (default: smart-case match)
|
-i Case-insensitive match (default: smart-case match)
|
||||||
+i Case-sensitive match
|
+i Case-sensitive match
|
||||||
-n, --nth=[-]N[,..] Comma-separated list of field indexes for limiting
|
-n, --nth=N[,..] Comma-separated list of field index expressions
|
||||||
search scope (positive or negative integers)
|
for limiting search scope. Each can be a non-zero
|
||||||
|
integer or a range expression ([BEGIN]..[END])
|
||||||
-d, --delimiter=STR Field delimiter regex for --nth (default: AWK-style)
|
-d, --delimiter=STR Field delimiter regex for --nth (default: AWK-style)
|
||||||
|
|
||||||
Search result
|
Search result
|
||||||
@@ -123,6 +124,7 @@ The following readline key bindings should also work as expected.
|
|||||||
|
|
||||||
- CTRL-A / CTRL-E
|
- CTRL-A / CTRL-E
|
||||||
- CTRL-B / CTRL-F
|
- CTRL-B / CTRL-F
|
||||||
|
- CTRL-H / CTRL-D
|
||||||
- CTRL-W / CTRL-U / CTRL-Y
|
- CTRL-W / CTRL-U / CTRL-Y
|
||||||
- ALT-B / ALT-F
|
- ALT-B / ALT-F
|
||||||
|
|
||||||
@@ -173,12 +175,6 @@ fd() {
|
|||||||
cd "$dir"
|
cd "$dir"
|
||||||
}
|
}
|
||||||
|
|
||||||
# fda - including hidden directories
|
|
||||||
fda() {
|
|
||||||
local dir
|
|
||||||
dir=$(find ${1:-.} -type d 2> /dev/null | fzf +m) && cd "$dir"
|
|
||||||
}
|
|
||||||
|
|
||||||
# fh - repeat history
|
# fh - repeat history
|
||||||
fh() {
|
fh() {
|
||||||
eval $(([ -n "$ZSH_NAME" ] && fc -l 1 || history) | fzf +s | sed 's/ *[0-9]* *//')
|
eval $(([ -n "$ZSH_NAME" ] && fc -l 1 || history) | fzf +s | sed 's/ *[0-9]* *//')
|
||||||
@@ -188,33 +184,6 @@ fh() {
|
|||||||
fkill() {
|
fkill() {
|
||||||
ps -ef | sed 1d | fzf -m | awk '{print $2}' | xargs kill -${1:-9}
|
ps -ef | sed 1d | fzf -m | awk '{print $2}' | xargs kill -${1:-9}
|
||||||
}
|
}
|
||||||
|
|
||||||
# fbr - checkout git branch
|
|
||||||
fbr() {
|
|
||||||
local branches branch
|
|
||||||
branches=$(git branch) &&
|
|
||||||
branch=$(echo "$branches" | fzf +s +m) &&
|
|
||||||
git checkout $(echo "$branch" | sed "s/.* //")
|
|
||||||
}
|
|
||||||
|
|
||||||
# fco - checkout git commit
|
|
||||||
fco() {
|
|
||||||
local commits commit
|
|
||||||
commits=$(git log --pretty=oneline --abbrev-commit --reverse) &&
|
|
||||||
commit=$(echo "$commits" | fzf +s +m -e) &&
|
|
||||||
git checkout $(echo "$commit" | sed "s/ .*//")
|
|
||||||
}
|
|
||||||
|
|
||||||
# ftags - search ctags
|
|
||||||
ftags() {
|
|
||||||
local line
|
|
||||||
[ -e tags ] &&
|
|
||||||
line=$(
|
|
||||||
awk 'BEGIN { FS="\t" } !/^!/ {print toupper($4)"\t"$1"\t"$2"\t"$3}' tags |
|
|
||||||
cut -c1-80 | fzf --nth=1,2
|
|
||||||
) && $EDITOR $(cut -f3 <<< "$line") -c "set nocst" \
|
|
||||||
-c "silent tag $(cut -f2 <<< "$line")"
|
|
||||||
}
|
|
||||||
```
|
```
|
||||||
|
|
||||||
For more examples, see [the wiki
|
For more examples, see [the wiki
|
||||||
@@ -318,7 +287,7 @@ TODO :smiley:
|
|||||||
Usage as Vim plugin
|
Usage as Vim plugin
|
||||||
-------------------
|
-------------------
|
||||||
|
|
||||||
(fzf is a command-line utility, naturally it is only accessible in terminal Vim)
|
(Note: To use fzf in GVim, an external terminal emulator is required.)
|
||||||
|
|
||||||
### `:FZF[!]`
|
### `:FZF[!]`
|
||||||
|
|
||||||
@@ -342,6 +311,17 @@ If you're on a tmux session, `:FZF` will launch fzf in a new split-window whose
|
|||||||
height can be adjusted with `g:fzf_tmux_height` (default: '40%'). However, the
|
height can be adjusted with `g:fzf_tmux_height` (default: '40%'). However, the
|
||||||
bang version (`:FZF!`) will always start in fullscreen.
|
bang version (`:FZF!`) will always start in fullscreen.
|
||||||
|
|
||||||
|
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'
|
||||||
|
```
|
||||||
|
|
||||||
### `fzf#run([options])`
|
### `fzf#run([options])`
|
||||||
|
|
||||||
For more advanced uses, you can call `fzf#run()` function which returns the list
|
For more advanced uses, you can call `fzf#run()` function which returns the list
|
||||||
@@ -349,16 +329,17 @@ of the selected items.
|
|||||||
|
|
||||||
`fzf#run()` may take an options-dictionary:
|
`fzf#run()` may take an options-dictionary:
|
||||||
|
|
||||||
| Option name | Type | Description |
|
| Option name | Type | Description |
|
||||||
| ------------- | ------------- | ------------------------------------------------------------------ |
|
| --------------- | ------------- | ------------------------------------------------------------------ |
|
||||||
| `source` | string | External command to generate input to fzf (e.g. `find .`) |
|
| `source` | string | External command to generate input to fzf (e.g. `find .`) |
|
||||||
| `source` | list | Vim list as input to fzf |
|
| `source` | list | Vim list as input to fzf |
|
||||||
| `sink` | string | Vim command to handle the selected item (e.g. `e`, `tabe`) |
|
| `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 | Reference to function to process each selected item |
|
||||||
| `options` | string | Options to fzf |
|
| `options` | string | Options to fzf |
|
||||||
| `dir` | string | Working directory |
|
| `dir` | string | Working directory |
|
||||||
| `tmux_width` | number/string | Use tmux vertical split with the given height (e.g. `20`, `50%`) |
|
| `tmux_width` | number/string | Use tmux vertical split with the given height (e.g. `20`, `50%`) |
|
||||||
| `tmux_height` | number/string | Use tmux horizontal split with the given height (e.g. `20`, `50%`) |
|
| `tmux_height` | number/string | Use tmux horizontal split with the given height (e.g. `20`, `50%`) |
|
||||||
|
| `launcher` | string | External terminal emulator to start fzf with (Only used in GVim) |
|
||||||
|
|
||||||
#### Examples
|
#### Examples
|
||||||
|
|
||||||
@@ -386,7 +367,8 @@ nnoremap <silent> <Leader>C :call fzf#run({
|
|||||||
\ "substitute(fnamemodify(v:val, ':t'), '\\..\\{-}$', '', '')"),
|
\ "substitute(fnamemodify(v:val, ':t'), '\\..\\{-}$', '', '')"),
|
||||||
\ 'sink': 'colo',
|
\ 'sink': 'colo',
|
||||||
\ 'options': '+m',
|
\ 'options': '+m',
|
||||||
\ 'tmux_width': 20
|
\ 'tmux_width': 20,
|
||||||
|
\ 'launcher': 'xterm -geometry 20x30 -e bash -ic %s'
|
||||||
\ })<CR>
|
\ })<CR>
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -395,20 +377,20 @@ handy mapping that selects an open buffer.
|
|||||||
|
|
||||||
```vim
|
```vim
|
||||||
" List of buffers
|
" List of buffers
|
||||||
function! g:buflist()
|
function! BufList()
|
||||||
redir => ls
|
redir => ls
|
||||||
silent ls
|
silent ls
|
||||||
redir END
|
redir END
|
||||||
return split(ls, '\n')
|
return split(ls, '\n')
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! g:bufopen(e)
|
function! BufOpen(e)
|
||||||
execute 'buffer '. matchstr(a:e, '^[ 0-9]*')
|
execute 'buffer '. matchstr(a:e, '^[ 0-9]*')
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
nnoremap <silent> <Leader><Enter> :call fzf#run({
|
nnoremap <silent> <Leader><Enter> :call fzf#run({
|
||||||
\ 'source': reverse(g:buflist()),
|
\ 'source': reverse(BufList()),
|
||||||
\ 'sink': function('g:bufopen'),
|
\ 'sink': function('BufOpen'),
|
||||||
\ 'options': '+m',
|
\ 'options': '+m',
|
||||||
\ 'tmux_height': '40%'
|
\ 'tmux_height': '40%'
|
||||||
\ })<CR>
|
\ })<CR>
|
||||||
@@ -487,6 +469,39 @@ fzf() {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Using fzf with tmux splits
|
||||||
|
|
||||||
|
It isn't too hard to write your own fzf-tmux combo like the default
|
||||||
|
CTRL-T key binding. (Or is it?)
|
||||||
|
|
||||||
|
```sh
|
||||||
|
# This is a helper function that splits the current pane to start the given
|
||||||
|
# command ($1) and sends its output back to the original pane with any number of
|
||||||
|
# optional keys (shift; $*).
|
||||||
|
fzf_tmux_helper() {
|
||||||
|
[ -n "$TMUX_PANE" ] || return
|
||||||
|
local cmd=$1
|
||||||
|
shift
|
||||||
|
tmux split-window -p 40 \
|
||||||
|
"bash -c \"\$(tmux send-keys -t $TMUX_PANE \"\$(source ~/.fzf.bash; $cmd)\" $*)\""
|
||||||
|
}
|
||||||
|
|
||||||
|
# This is the function we are going to run in the split pane.
|
||||||
|
# - "find" to list the directories
|
||||||
|
# - "sed" will escape spaces in the paths.
|
||||||
|
# - "paste" will join the selected paths into a single line
|
||||||
|
fzf_tmux_dir() {
|
||||||
|
fzf_tmux_helper \
|
||||||
|
'find * -path "*/\.*" -prune -o -type d -print 2> /dev/null |
|
||||||
|
fzf --multi |
|
||||||
|
sed "s/ /\\\\ /g" |
|
||||||
|
paste -sd" " -' Space
|
||||||
|
}
|
||||||
|
|
||||||
|
# Bind CTRL-X-CTRL-D to fzf_tmux_dir
|
||||||
|
bind '"\C-x\C-d": "$(fzf_tmux_dir)\e\C-e"'
|
||||||
|
```
|
||||||
|
|
||||||
### Fish shell
|
### Fish shell
|
||||||
|
|
||||||
It's [a known bug of fish](https://github.com/fish-shell/fish-shell/issues/1362)
|
It's [a known bug of fish](https://github.com/fish-shell/fish-shell/issues/1362)
|
||||||
@@ -516,6 +531,13 @@ fzf works on [Cygwin](http://www.cygwin.com/) and
|
|||||||
[MSYS2](http://sourceforge.net/projects/msys2/). You may need to use `--black`
|
[MSYS2](http://sourceforge.net/projects/msys2/). You may need to use `--black`
|
||||||
option on MSYS2 to avoid rendering issues.
|
option on MSYS2 to avoid rendering issues.
|
||||||
|
|
||||||
|
### Handling UTF-8 NFD paths on OSX
|
||||||
|
|
||||||
|
Use iconv to convert NFD paths to NFC:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
find . | iconv -f utf-8-mac -t utf8//ignore | fzf
|
||||||
|
```
|
||||||
|
|
||||||
License
|
License
|
||||||
-------
|
-------
|
||||||
|
|||||||
182
fzf
182
fzf
@@ -7,7 +7,7 @@
|
|||||||
# / __/ / /_/ __/
|
# / __/ / /_/ __/
|
||||||
# /_/ /___/_/ Fuzzy finder for your shell
|
# /_/ /___/_/ Fuzzy finder for your shell
|
||||||
#
|
#
|
||||||
# Version: 0.8.4 (May 17, 2014)
|
# Version: 0.8.5 (Jun 15, 2014)
|
||||||
#
|
#
|
||||||
# Author: Junegunn Choi
|
# Author: Junegunn Choi
|
||||||
# URL: https://github.com/junegunn/fzf
|
# URL: https://github.com/junegunn/fzf
|
||||||
@@ -133,10 +133,9 @@ class FZF
|
|||||||
when /^-f(.*)$/, /^--filter=(.*)$/
|
when /^-f(.*)$/, /^--filter=(.*)$/
|
||||||
@filter = $1
|
@filter = $1
|
||||||
when '-n', '--nth'
|
when '-n', '--nth'
|
||||||
usage 1, 'field number required' unless nth = argv.shift
|
usage 1, 'field expression required' unless nth = argv.shift
|
||||||
usage 1, 'invalid field number' if nth.to_i == 0
|
|
||||||
@nth = parse_nth nth
|
@nth = parse_nth nth
|
||||||
when /^-n([0-9,-]+)$/, /^--nth=([0-9,-]+)$/
|
when /^-n([0-9,-\.]+)$/, /^--nth=([0-9,-\.]+)$/
|
||||||
@nth = parse_nth $1
|
@nth = parse_nth $1
|
||||||
when '-d', '--delimiter'
|
when '-d', '--delimiter'
|
||||||
usage 1, 'delimiter required' unless delim = argv.shift
|
usage 1, 'delimiter required' unless delim = argv.shift
|
||||||
@@ -179,10 +178,20 @@ class FZF
|
|||||||
end
|
end
|
||||||
|
|
||||||
def parse_nth nth
|
def parse_nth nth
|
||||||
nth.split(',').map { |n|
|
nth.split(',').map { |expr|
|
||||||
ni = n.to_i
|
x = proc { usage 1, "invalid field expression: #{expr}" }
|
||||||
usage 1, "invalid field number: #{n}" if ni == 0
|
first, second = expr.split('..', 2)
|
||||||
ni
|
x.call if !first.empty? && first.to_i == 0 ||
|
||||||
|
second && !second.empty? && (second.to_i == 0 || second.include?('.'))
|
||||||
|
|
||||||
|
first = first.empty? ? 1 : first.to_i
|
||||||
|
second = case second
|
||||||
|
when nil then first
|
||||||
|
when '' then -1
|
||||||
|
else second.to_i
|
||||||
|
end
|
||||||
|
|
||||||
|
Range.new(*[first, second].map { |e| e > 0 ? e - 1 : e })
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -281,8 +290,9 @@ class FZF
|
|||||||
-e, --extended-exact Extended-search mode (exact match)
|
-e, --extended-exact Extended-search mode (exact match)
|
||||||
-i Case-insensitive match (default: smart-case match)
|
-i Case-insensitive match (default: smart-case match)
|
||||||
+i Case-sensitive match
|
+i Case-sensitive match
|
||||||
-n, --nth=[-]N[,..] Comma-separated list of field indexes for limiting
|
-n, --nth=N[,..] Comma-separated list of field index expressions
|
||||||
search scope (positive or negative integers)
|
for limiting search scope. Each can be a non-zero
|
||||||
|
integer or a range expression ([BEGIN]..[END])
|
||||||
-d, --delimiter=STR Field delimiter regex for --nth (default: AWK-style)
|
-d, --delimiter=STR Field delimiter regex for --nth (default: AWK-style)
|
||||||
|
|
||||||
Search result
|
Search result
|
||||||
@@ -309,121 +319,6 @@ class FZF
|
|||||||
exit x
|
exit x
|
||||||
end
|
end
|
||||||
|
|
||||||
case RUBY_PLATFORM
|
|
||||||
when /darwin/
|
|
||||||
module UConv
|
|
||||||
CHOSUNG = 0x1100
|
|
||||||
JUNGSUNG = 0x1161
|
|
||||||
JONGSUNG = 0x11A7
|
|
||||||
CHOSUNGS = 19
|
|
||||||
JUNGSUNGS = 21
|
|
||||||
JONGSUNGS = 28
|
|
||||||
JJCOUNT = JUNGSUNGS * JONGSUNGS
|
|
||||||
NFC_BEGIN = 0xAC00
|
|
||||||
NFC_END = NFC_BEGIN + CHOSUNGS * JUNGSUNGS * JONGSUNGS
|
|
||||||
|
|
||||||
def self.nfd str
|
|
||||||
str.split(//).map do |c|
|
|
||||||
cp = c.ord
|
|
||||||
if cp >= NFC_BEGIN && cp < NFC_END
|
|
||||||
chr = ''
|
|
||||||
idx = cp - NFC_BEGIN
|
|
||||||
cho = CHOSUNG + idx / JJCOUNT
|
|
||||||
jung = JUNGSUNG + (idx % JJCOUNT) / JONGSUNGS
|
|
||||||
jong = JONGSUNG + idx % JONGSUNGS
|
|
||||||
chr << cho << jung
|
|
||||||
chr << jong if jong != JONGSUNG
|
|
||||||
chr
|
|
||||||
else
|
|
||||||
c
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.to_nfc arr
|
|
||||||
[NFC_BEGIN + arr[0] * JJCOUNT +
|
|
||||||
(arr[1] || 0) * JONGSUNGS +
|
|
||||||
(arr[2] || 0)].pack('U*')
|
|
||||||
end
|
|
||||||
|
|
||||||
if String.method_defined?(:each_char)
|
|
||||||
def self.split str
|
|
||||||
str.each_char.to_a
|
|
||||||
end
|
|
||||||
else
|
|
||||||
def self.split str
|
|
||||||
str.split('')
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.nfc str, offsets = []
|
|
||||||
ret = ''
|
|
||||||
omap = []
|
|
||||||
pend = []
|
|
||||||
split(str).each_with_index do |c, idx|
|
|
||||||
cp =
|
|
||||||
begin
|
|
||||||
c.ord
|
|
||||||
rescue Exception
|
|
||||||
next
|
|
||||||
end
|
|
||||||
omap << ret.length
|
|
||||||
unless pend.empty?
|
|
||||||
if cp >= JUNGSUNG && cp < JUNGSUNG + JUNGSUNGS
|
|
||||||
pend << cp - JUNGSUNG
|
|
||||||
next
|
|
||||||
elsif cp >= JONGSUNG && cp < JONGSUNG + JONGSUNGS
|
|
||||||
pend << cp - JONGSUNG
|
|
||||||
next
|
|
||||||
else
|
|
||||||
omap[-1] = omap[-1] + 1
|
|
||||||
ret << to_nfc(pend)
|
|
||||||
pend.clear
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if cp >= CHOSUNG && cp < CHOSUNG + CHOSUNGS
|
|
||||||
pend << cp - CHOSUNG
|
|
||||||
else
|
|
||||||
ret << c
|
|
||||||
end
|
|
||||||
end
|
|
||||||
ret << to_nfc(pend) unless pend.empty?
|
|
||||||
return [ret,
|
|
||||||
offsets.map { |pair|
|
|
||||||
b, e = pair
|
|
||||||
[omap[b] || 0, omap[e] || ((omap.last || 0) + 1)] }]
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def convert_item item
|
|
||||||
UConv.nfc(*item)
|
|
||||||
end
|
|
||||||
|
|
||||||
class Matcher
|
|
||||||
def query_chars q
|
|
||||||
UConv.nfd(q)
|
|
||||||
end
|
|
||||||
|
|
||||||
def sanitize q
|
|
||||||
UConv.nfd(q).join
|
|
||||||
end
|
|
||||||
end
|
|
||||||
else
|
|
||||||
def convert_item item
|
|
||||||
item
|
|
||||||
end
|
|
||||||
|
|
||||||
class Matcher
|
|
||||||
def query_chars q
|
|
||||||
q.split(//)
|
|
||||||
end
|
|
||||||
|
|
||||||
def sanitize q
|
|
||||||
q
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def emit event
|
def emit event
|
||||||
@mtx.synchronize do
|
@mtx.synchronize do
|
||||||
@events[event] = yield
|
@events[event] = yield
|
||||||
@@ -558,7 +453,7 @@ class FZF
|
|||||||
width = width str
|
width = width str
|
||||||
diff = 0
|
diff = 0
|
||||||
while width > len
|
while width > len
|
||||||
width -= (left ? str[0, 1] : str[-1, 1]) =~ @@wrx ? 2 : 1
|
width -= ((left ? str[0, 1] : str[-1, 1]) =~ @@wrx ? 2 : 1) rescue 1
|
||||||
str = left ? str[1..-1] : str[0...-1]
|
str = left ? str[1..-1] : str[0...-1]
|
||||||
diff += 1
|
diff += 1
|
||||||
end
|
end
|
||||||
@@ -734,7 +629,10 @@ class FZF
|
|||||||
found.concat(q.empty? ? list :
|
found.concat(q.empty? ? list :
|
||||||
matcher.match(list, q, q[0, cx], q[cx..-1]))
|
matcher.match(list, q, q[0, cx], q[cx..-1]))
|
||||||
end
|
end
|
||||||
next if skip
|
if skip
|
||||||
|
sleep 0.1
|
||||||
|
next
|
||||||
|
end
|
||||||
matches = @sort ? found : found.reverse
|
matches = @sort ? found : found.reverse
|
||||||
if !empty && @sort && matches.length <= @sort
|
if !empty && @sort && matches.length <= @sort
|
||||||
matches = FZF.sort(matches)
|
matches = FZF.sort(matches)
|
||||||
@@ -792,7 +690,7 @@ class FZF
|
|||||||
row = cursor_y(idx + 2)
|
row = cursor_y(idx + 2)
|
||||||
chosen = idx == vcursor
|
chosen = idx == vcursor
|
||||||
selected = @selects.include?([*item][0])
|
selected = @selects.include?([*item][0])
|
||||||
line, offsets = convert_item item
|
line, offsets = item
|
||||||
tokens = format line, maxc, offsets
|
tokens = format line, maxc, offsets
|
||||||
print_item row, tokens, chosen, selected
|
print_item row, tokens, chosen, selected
|
||||||
end
|
end
|
||||||
@@ -911,7 +809,7 @@ class FZF
|
|||||||
|
|
||||||
ord =
|
ord =
|
||||||
case read_nb(1, :esc)
|
case read_nb(1, :esc)
|
||||||
when 91
|
when 91, 79
|
||||||
case read_nb(1, nil)
|
case read_nb(1, nil)
|
||||||
when 68 then ctrl(:b)
|
when 68 then ctrl(:b)
|
||||||
when 67 then ctrl(:f)
|
when 67 then ctrl(:f)
|
||||||
@@ -996,7 +894,13 @@ class FZF
|
|||||||
}
|
}
|
||||||
actions = {
|
actions = {
|
||||||
:esc => proc { exit 1 },
|
:esc => proc { exit 1 },
|
||||||
ctrl(:d) => proc { exit 1 if input.empty? },
|
ctrl(:d) => proc {
|
||||||
|
if input.empty?
|
||||||
|
exit 1
|
||||||
|
elsif cursor < input.length
|
||||||
|
input = input[0...cursor] + input[(cursor + 1)..-1]
|
||||||
|
end
|
||||||
|
},
|
||||||
ctrl(:m) => proc {
|
ctrl(:m) => proc {
|
||||||
got = pick
|
got = pick
|
||||||
exit 0
|
exit 0
|
||||||
@@ -1053,6 +957,7 @@ class FZF
|
|||||||
case event
|
case event
|
||||||
when :click, :release
|
when :click, :release
|
||||||
x, y, shift = val.values_at :x, :y, :shift
|
x, y, shift = val.values_at :x, :y, :shift
|
||||||
|
y = @reverse ? (C.lines - 1 - y) : y
|
||||||
if y == cursor_y
|
if y == cursor_y
|
||||||
cursor = [0, [input.length, x - 2].min].max
|
cursor = [0, [input.length, x - 2].min].max
|
||||||
elsif x > 1 && y <= max_items
|
elsif x > 1 && y <= max_items
|
||||||
@@ -1120,7 +1025,7 @@ class FZF
|
|||||||
end
|
end
|
||||||
|
|
||||||
def initialize nth, delim
|
def initialize nth, delim
|
||||||
@nth = nth && nth.map { |n| n > 0 ? n - 1 : n }
|
@nth = nth
|
||||||
@delim = delim
|
@delim = delim
|
||||||
@tokens_cache = {}
|
@tokens_cache = {}
|
||||||
end
|
end
|
||||||
@@ -1142,8 +1047,9 @@ class FZF
|
|||||||
prefix_length, tokens = tokenize str
|
prefix_length, tokens = tokenize str
|
||||||
|
|
||||||
@nth.each do |n|
|
@nth.each do |n|
|
||||||
if (token = tokens[n]) && (md = token.match(pat) rescue nil)
|
if (range = tokens[n]) && (token = range.join) &&
|
||||||
prefix_length += (tokens[0...n] || []).join.length
|
(md = token.sub(/\s+$/, '').match(pat) rescue nil)
|
||||||
|
prefix_length += (tokens[0...(n.begin)] || []).join.length
|
||||||
offset = md.offset(0).map { |o| o + prefix_length }
|
offset = md.offset(0).map { |o| o + prefix_length }
|
||||||
return MatchData.new(offset)
|
return MatchData.new(offset)
|
||||||
end
|
end
|
||||||
@@ -1176,7 +1082,7 @@ class FZF
|
|||||||
def fuzzy_regex q
|
def fuzzy_regex q
|
||||||
@regexp[q] ||= begin
|
@regexp[q] ||= begin
|
||||||
q = q.downcase if @rxflag == Regexp::IGNORECASE
|
q = q.downcase if @rxflag == Regexp::IGNORECASE
|
||||||
Regexp.new(query_chars(q).inject('') { |sum, e|
|
Regexp.new(q.split(//).inject('') { |sum, e|
|
||||||
e = Regexp.escape e
|
e = Regexp.escape e
|
||||||
sum << (e.length > 1 ? "(?:#{e}).*?" : # FIXME: not equivalent
|
sum << (e.length > 1 ? "(?:#{e}).*?" : # FIXME: not equivalent
|
||||||
"#{e}[^#{e}]*?")
|
"#{e}[^#{e}]*?")
|
||||||
@@ -1234,7 +1140,7 @@ class FZF
|
|||||||
when ''
|
when ''
|
||||||
nil
|
nil
|
||||||
when /^\^(.*)\$$/
|
when /^\^(.*)\$$/
|
||||||
Regexp.new('^' << sanitize(Regexp.escape($1)) << '$', rxflag_for(w))
|
Regexp.new('^' << Regexp.escape($1) << '$', rxflag_for(w))
|
||||||
when /^'/
|
when /^'/
|
||||||
if @mode == :fuzzy && w.length > 1
|
if @mode == :fuzzy && w.length > 1
|
||||||
exact_regex w[1..-1]
|
exact_regex w[1..-1]
|
||||||
@@ -1243,10 +1149,10 @@ class FZF
|
|||||||
end
|
end
|
||||||
when /^\^/
|
when /^\^/
|
||||||
w.length > 1 ?
|
w.length > 1 ?
|
||||||
Regexp.new('^' << sanitize(Regexp.escape(w[1..-1])), rxflag_for(w)) : nil
|
Regexp.new('^' << Regexp.escape(w[1..-1]), rxflag_for(w)) : nil
|
||||||
when /\$$/
|
when /\$$/
|
||||||
w.length > 1 ?
|
w.length > 1 ?
|
||||||
Regexp.new(sanitize(Regexp.escape(w[0..-2])) << '$', rxflag_for(w)) : nil
|
Regexp.new(Regexp.escape(w[0..-2]) << '$', rxflag_for(w)) : nil
|
||||||
else
|
else
|
||||||
@mode == :fuzzy ? fuzzy_regex(w) : exact_regex(w)
|
@mode == :fuzzy ? fuzzy_regex(w) : exact_regex(w)
|
||||||
end, invert ]
|
end, invert ]
|
||||||
@@ -1254,7 +1160,7 @@ class FZF
|
|||||||
end
|
end
|
||||||
|
|
||||||
def exact_regex w
|
def exact_regex w
|
||||||
Regexp.new(sanitize(Regexp.escape(w)), rxflag_for(w))
|
Regexp.new(Regexp.escape(w), rxflag_for(w))
|
||||||
end
|
end
|
||||||
|
|
||||||
def match list, q, prefix, suffix
|
def match list, q, prefix, suffix
|
||||||
|
|||||||
14
install
14
install
@@ -140,7 +140,7 @@ if [ -z "$(set -o | grep '^vi.*on')" ]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# CTRL-R - Paste the selected command from history into the command line
|
# CTRL-R - Paste the selected command from history into the command line
|
||||||
bind '"\C-r": " \C-e\C-u$(HISTTIMEFORMAT= history | fzf +s | sed \"s/ *[0-9]* *//\")\e\C-e\er"'
|
bind '"\C-r": " \C-e\C-u$(HISTTIMEFORMAT= history | fzf +s +m -n..,1,2.. | sed \"s/ *[0-9]* *//\")\e\C-e\er"'
|
||||||
|
|
||||||
# ALT-C - cd into the selected directory
|
# ALT-C - cd into the selected directory
|
||||||
bind '"\ec": " \C-e\C-u$(__fcd)\e\C-e\er\C-m"'
|
bind '"\ec": " \C-e\C-u$(__fcd)\e\C-e\er\C-m"'
|
||||||
@@ -157,7 +157,7 @@ else
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# CTRL-R - Paste the selected command from history into the command line
|
# CTRL-R - Paste the selected command from history into the command line
|
||||||
bind '"\C-r": "\eddi$(HISTTIMEFORMAT= history | fzf +s | sed \"s/ *[0-9]* *//\")\C-x\C-e\e$a\C-x\C-r"'
|
bind '"\C-r": "\eddi$(HISTTIMEFORMAT= history | fzf +s +m -n..,1,2.. | sed \"s/ *[0-9]* *//\")\C-x\C-e\e$a\C-x\C-r"'
|
||||||
|
|
||||||
# ALT-C - cd into the selected directory
|
# ALT-C - cd into the selected directory
|
||||||
bind '"\ec": "\eddi$(__fcd)\C-x\C-e\C-x\C-r\C-m"'
|
bind '"\ec": "\eddi$(__fcd)\C-x\C-e\C-x\C-r\C-m"'
|
||||||
@@ -198,7 +198,7 @@ if [ -n "$TMUX_PANE" -a ${FZF_TMUX:-1} -ne 0 -a ${LINES:-40} -gt 15 ]; then
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
fzf-file-widget() {
|
fzf-file-widget() {
|
||||||
LBUFFER="${LBUFFER%% #}$(__fsel)"
|
LBUFFER="${LBUFFER}$(__fsel)"
|
||||||
zle redisplay
|
zle redisplay
|
||||||
}
|
}
|
||||||
fi
|
fi
|
||||||
@@ -216,7 +216,7 @@ bindkey '\ec' fzf-cd-widget
|
|||||||
|
|
||||||
# CTRL-R - Paste the selected command from history into the command line
|
# CTRL-R - Paste the selected command from history into the command line
|
||||||
fzf-history-widget() {
|
fzf-history-widget() {
|
||||||
LBUFFER=$(fc -l 1 | fzf +s | sed "s/ *[0-9]* *//")
|
LBUFFER=$(fc -l 1 | fzf +s +m -n..,1,2.. | sed "s/ *[0-9*]* *//")
|
||||||
zle redisplay
|
zle redisplay
|
||||||
}
|
}
|
||||||
zle -N fzf-history-widget
|
zle -N fzf-history-widget
|
||||||
@@ -241,7 +241,7 @@ function fzf
|
|||||||
$fzf_cmd \$argv
|
$fzf_cmd \$argv
|
||||||
end
|
end
|
||||||
EOFZF
|
EOFZF
|
||||||
echo "ok"
|
echo "OK"
|
||||||
|
|
||||||
if [ $key_bindings -eq 0 ]; then
|
if [ $key_bindings -eq 0 ]; then
|
||||||
echo -n "Generate ~/.config/fish/functions/fzf_key_bindings.fish ... "
|
echo -n "Generate ~/.config/fish/functions/fzf_key_bindings.fish ... "
|
||||||
@@ -310,7 +310,7 @@ function fzf_key_bindings
|
|||||||
bind \ec '__fzf_alt_c'
|
bind \ec '__fzf_alt_c'
|
||||||
end
|
end
|
||||||
EOFZF
|
EOFZF
|
||||||
echo "ok"
|
echo "OK"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -345,7 +345,7 @@ Finished. Restart your shell or reload config file.
|
|||||||
EOF
|
EOF
|
||||||
[ $has_fish -eq 1 ] && echo " fzf_key_bindings # fish"; cat << EOF
|
[ $has_fish -eq 1 ] && echo " fzf_key_bindings # fish"; cat << EOF
|
||||||
|
|
||||||
To uninstall fzf, simply remove the added lines.
|
Use uninstall script to remove fzf.
|
||||||
|
|
||||||
For more information, see: https://github.com/junegunn/fzf
|
For more information, see: https://github.com/junegunn/fzf
|
||||||
EOF
|
EOF
|
||||||
|
|||||||
@@ -24,6 +24,7 @@
|
|||||||
let s:min_tmux_width = 10
|
let s:min_tmux_width = 10
|
||||||
let s:min_tmux_height = 3
|
let s:min_tmux_height = 3
|
||||||
let s:default_tmux_height = '40%'
|
let s:default_tmux_height = '40%'
|
||||||
|
let s:launcher = 'xterm -e bash -ic %s'
|
||||||
|
|
||||||
let s:cpo_save = &cpo
|
let s:cpo_save = &cpo
|
||||||
set cpo&vim
|
set cpo&vim
|
||||||
@@ -42,6 +43,10 @@ else
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
function! s:tmux_enabled()
|
function! s:tmux_enabled()
|
||||||
|
if has('gui_running')
|
||||||
|
return 0
|
||||||
|
endif
|
||||||
|
|
||||||
if exists('s:tmux')
|
if exists('s:tmux')
|
||||||
return s:tmux
|
return s:tmux
|
||||||
endif
|
endif
|
||||||
@@ -63,11 +68,6 @@ function! s:escape(path)
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! fzf#run(...) abort
|
function! fzf#run(...) abort
|
||||||
if has('gui_running')
|
|
||||||
echohl Error
|
|
||||||
echo 'GVim is not supported'
|
|
||||||
return []
|
|
||||||
endif
|
|
||||||
let dict = exists('a:1') ? a:1 : {}
|
let dict = exists('a:1') ? a:1 : {}
|
||||||
let temps = { 'result': tempname() }
|
let temps = { 'result': tempname() }
|
||||||
let optstr = get(dict, 'options', '')
|
let optstr = get(dict, 'options', '')
|
||||||
@@ -118,9 +118,17 @@ endfunction
|
|||||||
function! s:execute(dict, command, temps)
|
function! s:execute(dict, command, temps)
|
||||||
call s:pushd(a:dict)
|
call s:pushd(a:dict)
|
||||||
silent !clear
|
silent !clear
|
||||||
execute 'silent !'.a:command
|
if has('gui_running')
|
||||||
|
let launcher = get(a:dict, 'launcher', get(g:, 'fzf_launcher', s:launcher))
|
||||||
|
let command = printf(launcher, "'".substitute(a:command, "'", "'\"'\"'", 'g')."'")
|
||||||
|
else
|
||||||
|
let command = a:command
|
||||||
|
endif
|
||||||
|
execute 'silent !'.command
|
||||||
redraw!
|
redraw!
|
||||||
if v:shell_error
|
if v:shell_error
|
||||||
|
echohl Error
|
||||||
|
echo 'Error running ' . command
|
||||||
return []
|
return []
|
||||||
else
|
else
|
||||||
return s:callback(a:dict, a:temps, 0)
|
return s:callback(a:dict, a:temps, 0)
|
||||||
|
|||||||
120
test/test_fzf.rb
120
test/test_fzf.rb
@@ -60,7 +60,7 @@ class TestFZF < MiniTest::Unit::TestCase
|
|||||||
assert_equal true, fzf.select1
|
assert_equal true, fzf.select1
|
||||||
assert_equal true, fzf.exit0
|
assert_equal true, fzf.exit0
|
||||||
assert_equal true, fzf.reverse
|
assert_equal true, fzf.reverse
|
||||||
assert_equal [3, -1, 2], fzf.nth
|
assert_equal [2..2, -1..-1, 1..1], fzf.nth
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_option_parser
|
def test_option_parser
|
||||||
@@ -80,7 +80,7 @@ class TestFZF < MiniTest::Unit::TestCase
|
|||||||
assert_equal true, fzf.exit0
|
assert_equal true, fzf.exit0
|
||||||
assert_equal 'howdy', fzf.filter
|
assert_equal 'howdy', fzf.filter
|
||||||
assert_equal :exact, fzf.extended
|
assert_equal :exact, fzf.extended
|
||||||
assert_equal [1], fzf.nth
|
assert_equal [0..0], fzf.nth
|
||||||
assert_equal true, fzf.reverse
|
assert_equal true, fzf.reverse
|
||||||
|
|
||||||
# Long opts (left-to-right)
|
# Long opts (left-to-right)
|
||||||
@@ -101,7 +101,7 @@ class TestFZF < MiniTest::Unit::TestCase
|
|||||||
assert_equal false, fzf.select1
|
assert_equal false, fzf.select1
|
||||||
assert_equal false, fzf.exit0
|
assert_equal false, fzf.exit0
|
||||||
assert_equal nil, fzf.extended
|
assert_equal nil, fzf.extended
|
||||||
assert_equal [-2], fzf.nth
|
assert_equal [-2..-2], fzf.nth
|
||||||
assert_equal false, fzf.reverse
|
assert_equal false, fzf.reverse
|
||||||
|
|
||||||
# Short opts
|
# Short opts
|
||||||
@@ -114,7 +114,7 @@ class TestFZF < MiniTest::Unit::TestCase
|
|||||||
assert_equal 'hello', fzf.query.get
|
assert_equal 'hello', fzf.query.get
|
||||||
assert_equal 'howdy', fzf.filter
|
assert_equal 'howdy', fzf.filter
|
||||||
assert_equal :fuzzy, fzf.extended
|
assert_equal :fuzzy, fzf.extended
|
||||||
assert_equal [3], fzf.nth
|
assert_equal [2..2], fzf.nth
|
||||||
assert_equal true, fzf.select1
|
assert_equal true, fzf.select1
|
||||||
assert_equal true, fzf.exit0
|
assert_equal true, fzf.exit0
|
||||||
|
|
||||||
@@ -134,23 +134,28 @@ class TestFZF < MiniTest::Unit::TestCase
|
|||||||
assert_equal false, fzf.exit0
|
assert_equal false, fzf.exit0
|
||||||
assert_equal 'world', fzf.filter
|
assert_equal 'world', fzf.filter
|
||||||
assert_equal nil, fzf.extended
|
assert_equal nil, fzf.extended
|
||||||
assert_equal [4, 5], fzf.nth
|
assert_equal [3..3, 4..4], fzf.nth
|
||||||
rescue SystemExit => e
|
rescue SystemExit => e
|
||||||
assert false, "Exited"
|
assert false, "Exited"
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_invalid_option
|
def test_invalid_option
|
||||||
[%w[--unknown], %w[yo dawg]].each do |argv|
|
[
|
||||||
|
%w[--unknown],
|
||||||
|
%w[yo dawg],
|
||||||
|
%w[--nth=0],
|
||||||
|
%w[-n 0],
|
||||||
|
%w[-n 1..2..3],
|
||||||
|
%w[-n 1....],
|
||||||
|
%w[-n ....3],
|
||||||
|
%w[-n 1....3],
|
||||||
|
%w[-n 1..0],
|
||||||
|
%w[--nth ..0],
|
||||||
|
].each do |argv|
|
||||||
assert_raises(SystemExit) do
|
assert_raises(SystemExit) do
|
||||||
fzf = FZF.new argv
|
fzf = FZF.new argv
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
assert_raises(SystemExit) do
|
|
||||||
fzf = FZF.new %w[--nth=0]
|
|
||||||
end
|
|
||||||
assert_raises(SystemExit) do
|
|
||||||
fzf = FZF.new %w[-n 0]
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# FIXME Only on 1.9 or above
|
# FIXME Only on 1.9 or above
|
||||||
@@ -450,58 +455,11 @@ class TestFZF < MiniTest::Unit::TestCase
|
|||||||
assert_equal 2, exact.match(list, "-fuzzy", '', '').length
|
assert_equal 2, exact.match(list, "-fuzzy", '', '').length
|
||||||
end
|
end
|
||||||
|
|
||||||
if RUBY_PLATFORM =~ /darwin/
|
|
||||||
NFD = '한글'
|
|
||||||
def test_nfc
|
|
||||||
assert_equal 6, NFD.length
|
|
||||||
assert_equal ["한글", [[0, 1], [1, 2]]],
|
|
||||||
FZF::UConv.nfc(NFD, [[0, 3], [3, 6]])
|
|
||||||
|
|
||||||
nfd2 = 'before' + NFD + 'after'
|
|
||||||
assert_equal 6 + 6 + 5, nfd2.length
|
|
||||||
|
|
||||||
nfc, offsets = FZF::UConv.nfc(nfd2, [[4, 14], [9, 13]])
|
|
||||||
o1, o2 = offsets
|
|
||||||
assert_equal 'before한글after', nfc
|
|
||||||
assert_equal 're한글af', nfc[(o1.first...o1.last)]
|
|
||||||
assert_equal '글a', nfc[(o2.first...o2.last)]
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_nfd
|
|
||||||
nfc = '한글'
|
|
||||||
nfd = FZF::UConv.nfd(nfc)
|
|
||||||
assert_equal 2, nfd.length
|
|
||||||
assert_equal 6, nfd.join.length
|
|
||||||
assert_equal NFD, nfd.join
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_nfd_fuzzy_matcher
|
|
||||||
matcher = FZF::FuzzyMatcher.new 0
|
|
||||||
assert_equal [], matcher.match([NFD + NFD], '할', '', '')
|
|
||||||
match = matcher.match([NFD + NFD], '글글', '', '')
|
|
||||||
assert_equal [[NFD + NFD, [[3, 12]]]], match
|
|
||||||
assert_equal ['한글한글', [[1, 4]]], FZF::UConv.nfc(*match.first)
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_nfd_extended_fuzzy_matcher
|
|
||||||
matcher = FZF::ExtendedFuzzyMatcher.new 0
|
|
||||||
assert_equal [], matcher.match([NFD], "'글글", '', '')
|
|
||||||
match = matcher.match([NFD], "'한글", '', '')
|
|
||||||
assert_equal [[NFD, [[0, 6]]]], match
|
|
||||||
assert_equal ['한글', [[0, 2]]], FZF::UConv.nfc(*match.first)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_split
|
|
||||||
assert_equal ["a", "b", "c", "\xFF", "d", "e", "f"],
|
|
||||||
FZF::UConv.split("abc\xFFdef")
|
|
||||||
end
|
|
||||||
|
|
||||||
# ^$ -> matches empty item
|
# ^$ -> matches empty item
|
||||||
def test_format_empty_item
|
def test_format_empty_item
|
||||||
fzf = FZF.new []
|
fzf = FZF.new []
|
||||||
item = ['', [[0, 0]]]
|
item = ['', [[0, 0]]]
|
||||||
line, offsets = fzf.convert_item item
|
line, offsets = item
|
||||||
tokens = fzf.format line, 80, offsets
|
tokens = fzf.format line, 80, offsets
|
||||||
assert_equal [], tokens
|
assert_equal [], tokens
|
||||||
end
|
end
|
||||||
@@ -534,43 +492,67 @@ class TestFZF < MiniTest::Unit::TestCase
|
|||||||
[list[0], [[2, 5]]],
|
[list[0], [[2, 5]]],
|
||||||
[list[1], [[9, 17]]]], matcher.match(list, 'is', '', '')
|
[list[1], [[9, 17]]]], matcher.match(list, 'is', '', '')
|
||||||
|
|
||||||
matcher = FZF::FuzzyMatcher.new Regexp::IGNORECASE, [2]
|
matcher = FZF::FuzzyMatcher.new Regexp::IGNORECASE, [1..1]
|
||||||
assert_equal [[list[1], [[8, 9]]]], matcher.match(list, 'f', '', '')
|
assert_equal [[list[1], [[8, 9]]]], matcher.match(list, 'f', '', '')
|
||||||
assert_equal [[list[0], [[8, 9]]]], matcher.match(list, 's', '', '')
|
assert_equal [[list[0], [[8, 9]]]], matcher.match(list, 's', '', '')
|
||||||
|
|
||||||
matcher = FZF::FuzzyMatcher.new Regexp::IGNORECASE, [3]
|
matcher = FZF::FuzzyMatcher.new Regexp::IGNORECASE, [2..2]
|
||||||
assert_equal [[list[0], [[19, 20]]]], matcher.match(list, 'r', '', '')
|
assert_equal [[list[0], [[19, 20]]]], matcher.match(list, 'r', '', '')
|
||||||
|
|
||||||
# Comma-separated
|
# Comma-separated
|
||||||
matcher = FZF::FuzzyMatcher.new Regexp::IGNORECASE, [3, 1]
|
matcher = FZF::FuzzyMatcher.new Regexp::IGNORECASE, [2..2, 0..0]
|
||||||
assert_equal [[list[0], [[19, 20]]], [list[1], [[3, 4]]]], matcher.match(list, 'r', '', '')
|
assert_equal [[list[0], [[19, 20]]], [list[1], [[3, 4]]]], matcher.match(list, 'r', '', '')
|
||||||
|
|
||||||
# Ordered
|
# Ordered
|
||||||
matcher = FZF::FuzzyMatcher.new Regexp::IGNORECASE, [1, 3]
|
matcher = FZF::FuzzyMatcher.new Regexp::IGNORECASE, [0..0, 2..2]
|
||||||
assert_equal [[list[0], [[3, 4]]], [list[1], [[3, 4]]]], matcher.match(list, 'r', '', '')
|
assert_equal [[list[0], [[3, 4]]], [list[1], [[3, 4]]]], matcher.match(list, 'r', '', '')
|
||||||
|
|
||||||
regex = FZF.build_delim_regex "\t"
|
regex = FZF.build_delim_regex "\t"
|
||||||
matcher = FZF::FuzzyMatcher.new Regexp::IGNORECASE, [1], regex
|
matcher = FZF::FuzzyMatcher.new Regexp::IGNORECASE, [0..0], regex
|
||||||
assert_equal [[list[0], [[3, 10]]]], matcher.match(list, 're', '', '')
|
assert_equal [[list[0], [[3, 10]]]], matcher.match(list, 're', '', '')
|
||||||
|
|
||||||
matcher = FZF::FuzzyMatcher.new Regexp::IGNORECASE, [2], regex
|
matcher = FZF::FuzzyMatcher.new Regexp::IGNORECASE, [1..1], regex
|
||||||
assert_equal [], matcher.match(list, 'r', '', '')
|
assert_equal [], matcher.match(list, 'r', '', '')
|
||||||
assert_equal [[list[1], [[9, 17]]]], matcher.match(list, 'is', '', '')
|
assert_equal [[list[1], [[9, 17]]]], matcher.match(list, 'is', '', '')
|
||||||
|
|
||||||
# Negative indexing
|
# Negative indexing
|
||||||
matcher = FZF::FuzzyMatcher.new Regexp::IGNORECASE, [-1], regex
|
matcher = FZF::FuzzyMatcher.new Regexp::IGNORECASE, [-1..-1], regex
|
||||||
assert_equal [[list[0], [[3, 6]]]], matcher.match(list, 'rt', '', '')
|
assert_equal [[list[0], [[3, 6]]]], matcher.match(list, 'rt', '', '')
|
||||||
assert_equal [[list[0], [[2, 5]]], [list[1], [[9, 17]]]], matcher.match(list, 'is', '', '')
|
assert_equal [[list[0], [[2, 5]]], [list[1], [[9, 17]]]], matcher.match(list, 'is', '', '')
|
||||||
|
|
||||||
# Regex delimiter
|
# Regex delimiter
|
||||||
regex = FZF.build_delim_regex "[ \t]+"
|
regex = FZF.build_delim_regex "[ \t]+"
|
||||||
matcher = FZF::FuzzyMatcher.new Regexp::IGNORECASE, [1], regex
|
matcher = FZF::FuzzyMatcher.new Regexp::IGNORECASE, [0..0], regex
|
||||||
assert_equal [list[1]], matcher.match(list, 'f', '', '').map(&:first)
|
assert_equal [list[1]], matcher.match(list, 'f', '', '').map(&:first)
|
||||||
|
|
||||||
matcher = FZF::FuzzyMatcher.new Regexp::IGNORECASE, [2], regex
|
matcher = FZF::FuzzyMatcher.new Regexp::IGNORECASE, [1..1], regex
|
||||||
assert_equal [[list[0], [[1, 2]]], [list[1], [[8, 9]]]], matcher.match(list, 'f', '', '')
|
assert_equal [[list[0], [[1, 2]]], [list[1], [[8, 9]]]], matcher.match(list, 'f', '', '')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_nth_match_range
|
||||||
|
list = [
|
||||||
|
' first second third',
|
||||||
|
'fourth fifth sixth',
|
||||||
|
]
|
||||||
|
|
||||||
|
matcher = FZF::FuzzyMatcher.new Regexp::IGNORECASE, [1..2]
|
||||||
|
assert_equal [[list[0], [[8, 20]]]], matcher.match(list, 'sr', '', '')
|
||||||
|
assert_equal [], matcher.match(list, 'fo', '', '')
|
||||||
|
|
||||||
|
matcher = FZF::FuzzyMatcher.new Regexp::IGNORECASE, [1..-1, 0..0]
|
||||||
|
assert_equal [[list[0], [[8, 20]]]], matcher.match(list, 'sr', '', '')
|
||||||
|
assert_equal [[list[1], [[0, 2]]]], matcher.match(list, 'fo', '', '')
|
||||||
|
|
||||||
|
matcher = FZF::ExtendedFuzzyMatcher.new Regexp::IGNORECASE, :fuzzy, [0..0, 1..2]
|
||||||
|
assert_equal [], matcher.match(list, '^t', '', '')
|
||||||
|
|
||||||
|
matcher = FZF::ExtendedFuzzyMatcher.new Regexp::IGNORECASE, :fuzzy, [0..1, 2..2]
|
||||||
|
assert_equal [[list[0], [[16, 17]]]], matcher.match(list, '^t', '', '')
|
||||||
|
|
||||||
|
matcher = FZF::ExtendedFuzzyMatcher.new Regexp::IGNORECASE, :fuzzy, [1..-1]
|
||||||
|
assert_equal [[list[0], [[8, 9]]]], matcher.match(list, '^s', '', '')
|
||||||
|
end
|
||||||
|
|
||||||
def stream_for str
|
def stream_for str
|
||||||
StringIO.new(str).tap do |sio|
|
StringIO.new(str).tap do |sio|
|
||||||
sio.instance_eval do
|
sio.instance_eval do
|
||||||
|
|||||||
70
uninstall
Executable file
70
uninstall
Executable file
@@ -0,0 +1,70 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
confirm() {
|
||||||
|
while [ 1 ]; do
|
||||||
|
read -p "$1" -n 1 -r
|
||||||
|
echo
|
||||||
|
if [[ "$REPLY" =~ ^[Yy] ]]; then
|
||||||
|
return 0
|
||||||
|
elif [[ "$REPLY" =~ ^[Nn] ]]; then
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
remove() {
|
||||||
|
echo "Remove $1"
|
||||||
|
rm -f "$1"
|
||||||
|
}
|
||||||
|
|
||||||
|
remove_line() {
|
||||||
|
src=$(readlink "$2")
|
||||||
|
if [ $? -eq 0 ]; then
|
||||||
|
echo "Remove from $2 ($src):"
|
||||||
|
else
|
||||||
|
src=$2
|
||||||
|
echo "Remove from $2:"
|
||||||
|
fi
|
||||||
|
|
||||||
|
line_no=1
|
||||||
|
match=0
|
||||||
|
while [ 1 ]; do
|
||||||
|
line=$(sed -n "$line_no,\$p" "$src" | grep -m1 -nF "$1") || break
|
||||||
|
line_no=$(( $(sed 's/:.*//' <<< "$line") + line_no - 1 ))
|
||||||
|
content=$(sed 's/^[0-9]*://' <<< "$line")
|
||||||
|
match=1
|
||||||
|
echo " - Line #$line_no: $content"
|
||||||
|
[ "$content" = "$1" ] || confirm " - Remove (y/n) ? "
|
||||||
|
if [ $? -eq 0 ]; then
|
||||||
|
awk -v n=$line_no 'NR == n {next} {print}' "$src" > "$src.bak" &&
|
||||||
|
mv "$src.bak" "$src" || break
|
||||||
|
echo " - Removed"
|
||||||
|
else
|
||||||
|
echo " - Skipped"
|
||||||
|
line_no=$(( line_no + 1 ))
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
[ $match -eq 0 ] && echo " - Nothing found"
|
||||||
|
echo
|
||||||
|
}
|
||||||
|
|
||||||
|
for shell in bash zsh; do
|
||||||
|
remove ~/.fzf.${shell}
|
||||||
|
remove_line "source ~/.fzf.${shell}" ~/.${shell}rc
|
||||||
|
done
|
||||||
|
|
||||||
|
bind_file=~/.config/fish/functions/fish_user_key_bindings.fish
|
||||||
|
if [ -f "$bind_file" ]; then
|
||||||
|
remove_line "fzf_key_bindings" "$bind_file"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -d ~/.config/fish/functions ]; then
|
||||||
|
remove ~/.config/fish/functions/fzf.fish
|
||||||
|
|
||||||
|
if [ "$(ls -A ~/.config/fish/functions)" ]; then
|
||||||
|
echo "Can't delete non-empty directory: \"~/.config/fish/functions\""
|
||||||
|
else
|
||||||
|
rmdir ~/.config/fish/functions
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
Reference in New Issue
Block a user