mirror of
https://github.com/junegunn/fzf.git
synced 2025-08-17 05:03:52 -07:00
Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
423e26b0c9 | ||
|
84921df0e3 | ||
|
6a5e1de6f3 | ||
|
90adda73b0 |
18
README.md
18
README.md
@@ -139,13 +139,25 @@ If you install fzf as a Vim plugin, `:FZF` command will be added.
|
|||||||
|
|
||||||
```vim
|
```vim
|
||||||
:FZF
|
:FZF
|
||||||
:FZF --no-sort
|
:FZF --no-sort -m
|
||||||
```
|
```
|
||||||
|
|
||||||
You can override the command which produces input to fzf.
|
You can override the source command which produces input to fzf.
|
||||||
|
|
||||||
```vim
|
```vim
|
||||||
let g:fzf_command = 'find . -type f'
|
let g:fzf_source = 'find . -type f'
|
||||||
|
```
|
||||||
|
|
||||||
|
And you can predefine default options to fzf command.
|
||||||
|
|
||||||
|
```vim
|
||||||
|
let g:fzf_options = '--no-color --extended'
|
||||||
|
```
|
||||||
|
|
||||||
|
For more advanced uses, you can call `fzf#run` function as follows.
|
||||||
|
|
||||||
|
```vim
|
||||||
|
:call fzf#run('tabedit', '-m +c')
|
||||||
```
|
```
|
||||||
|
|
||||||
Most of the time, you will prefer native Vim plugins with better integration
|
Most of the time, you will prefer native Vim plugins with better integration
|
||||||
|
37
fzf
37
fzf
@@ -137,21 +137,21 @@ class FZF
|
|||||||
NFC_END = NFC_BEGIN + CHOSUNGS * JUNGSUNGS * JONGSUNGS
|
NFC_END = NFC_BEGIN + CHOSUNGS * JUNGSUNGS * JONGSUNGS
|
||||||
|
|
||||||
def self.nfd str
|
def self.nfd str
|
||||||
ret = ''
|
str.split(//).map do |c|
|
||||||
str.split(//).each do |c|
|
|
||||||
cp = c.ord
|
cp = c.ord
|
||||||
if cp >= NFC_BEGIN && cp < NFC_END
|
if cp >= NFC_BEGIN && cp < NFC_END
|
||||||
|
chr = ''
|
||||||
idx = cp - NFC_BEGIN
|
idx = cp - NFC_BEGIN
|
||||||
cho = CHOSUNG + idx / JJCOUNT
|
cho = CHOSUNG + idx / JJCOUNT
|
||||||
jung = JUNGSUNG + (idx % JJCOUNT) / JONGSUNGS
|
jung = JUNGSUNG + (idx % JJCOUNT) / JONGSUNGS
|
||||||
jong = JONGSUNG + idx % JONGSUNGS
|
jong = JONGSUNG + idx % JONGSUNGS
|
||||||
ret << cho << jung
|
chr << cho << jung
|
||||||
ret << jong if jong != JONGSUNG
|
chr << jong if jong != JONGSUNG
|
||||||
|
chr
|
||||||
else
|
else
|
||||||
ret << c
|
c
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
ret
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.to_nfc arr
|
def self.to_nfc arr
|
||||||
@@ -214,8 +214,12 @@ class FZF
|
|||||||
end
|
end
|
||||||
|
|
||||||
class Matcher
|
class Matcher
|
||||||
def convert_query q
|
def query_chars q
|
||||||
UConv.nfd(q).split(//)
|
UConv.nfd(q)
|
||||||
|
end
|
||||||
|
|
||||||
|
def sanitize q
|
||||||
|
UConv.nfd(q).join
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
@@ -224,9 +228,13 @@ class FZF
|
|||||||
end
|
end
|
||||||
|
|
||||||
class Matcher
|
class Matcher
|
||||||
def convert_query q
|
def query_chars q
|
||||||
q.split(//)
|
q.split(//)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def sanitize q
|
||||||
|
q
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -747,9 +755,10 @@ class FZF
|
|||||||
def fuzzy_regex q
|
def fuzzy_regex q
|
||||||
@regexp[q] ||= begin
|
@regexp[q] ||= begin
|
||||||
q = q.downcase if @rxflag != 0
|
q = q.downcase if @rxflag != 0
|
||||||
Regexp.new(convert_query(q).inject('') { |sum, e|
|
Regexp.new(query_chars(q).inject('') { |sum, e|
|
||||||
e = Regexp.escape e
|
e = Regexp.escape e
|
||||||
sum << "#{e}[^#{e}]*?"
|
sum << (e.length > 1 ? "(?:#{e}).*?" : # FIXME: not equivalent
|
||||||
|
"#{e}[^#{e}]*?")
|
||||||
}, @rxflag)
|
}, @rxflag)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -804,13 +813,13 @@ class FZF
|
|||||||
nil
|
nil
|
||||||
when /^'/
|
when /^'/
|
||||||
w.length > 1 ?
|
w.length > 1 ?
|
||||||
Regexp.new(Regexp.escape(w[1..-1]), rxflag) : nil
|
Regexp.new(sanitize(Regexp.escape(w[1..-1])), rxflag) : nil
|
||||||
when /^\^/
|
when /^\^/
|
||||||
w.length > 1 ?
|
w.length > 1 ?
|
||||||
Regexp.new('^' << Regexp.escape(w[1..-1]), rxflag) : nil
|
Regexp.new('^' << sanitize(Regexp.escape(w[1..-1])), rxflag) : nil
|
||||||
when /\$$/
|
when /\$$/
|
||||||
w.length > 1 ?
|
w.length > 1 ?
|
||||||
Regexp.new(Regexp.escape(w[0..-2]) << '$', rxflag) : nil
|
Regexp.new(sanitize(Regexp.escape(w[0..-2])) << '$', rxflag) : nil
|
||||||
else
|
else
|
||||||
fuzzy_regex w
|
fuzzy_regex w
|
||||||
end, invert ]
|
end, invert ]
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
# coding: utf-8
|
# coding: utf-8
|
||||||
Gem::Specification.new do |spec|
|
Gem::Specification.new do |spec|
|
||||||
spec.name = 'fzf'
|
spec.name = 'fzf'
|
||||||
spec.version = '0.4.0'
|
spec.version = '0.4.2'
|
||||||
spec.authors = ['Junegunn Choi']
|
spec.authors = ['Junegunn Choi']
|
||||||
spec.email = ['junegunn.c@gmail.com']
|
spec.email = ['junegunn.c@gmail.com']
|
||||||
spec.description = %q{Fuzzy finder for your shell}
|
spec.description = %q{Fuzzy finder for your shell}
|
||||||
|
@@ -23,23 +23,25 @@
|
|||||||
|
|
||||||
let s:exec = expand('<sfile>:h:h').'/fzf'
|
let s:exec = expand('<sfile>:h:h').'/fzf'
|
||||||
|
|
||||||
function! s:fzf(args)
|
function! fzf#run(command, args)
|
||||||
try
|
try
|
||||||
let tf = tempname()
|
let tf = tempname()
|
||||||
let prefix = exists('g:fzf_command') ? g:fzf_command.'|' : ''
|
let prefix = exists('g:fzf_source') ? g:fzf_source.'|' : ''
|
||||||
let fzf = executable(s:exec) ? s:exec : 'fzf'
|
let fzf = executable(s:exec) ? s:exec : 'fzf'
|
||||||
execute "silent !".prefix.fzf." ".a:args." > ".tf
|
let options = empty(a:args) ? get(g:, 'fzf_options', '') : a:args
|
||||||
|
execute "silent !".prefix.fzf.' '.options." > ".tf
|
||||||
if !v:shell_error
|
if !v:shell_error
|
||||||
let file = join(readfile(tf), '')
|
for line in readfile(tf)
|
||||||
if !empty(file)
|
if !empty(line)
|
||||||
execute 'silent e '.file
|
execute a:command.' '.line
|
||||||
endif
|
endif
|
||||||
|
endfor
|
||||||
endif
|
endif
|
||||||
finally
|
finally
|
||||||
silent! call delete(tf)
|
|
||||||
redraw!
|
redraw!
|
||||||
|
silent! call delete(tf)
|
||||||
endtry
|
endtry
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
command! -nargs=* FZF call s:fzf(<q-args>)
|
command! -nargs=* FZF call fzf#run('silent e', <q-args>)
|
||||||
|
|
||||||
|
@@ -293,8 +293,25 @@ class TestFZF < MiniTest::Unit::TestCase
|
|||||||
def test_nfd
|
def test_nfd
|
||||||
nfc = '한글'
|
nfc = '한글'
|
||||||
nfd = FZF::UConv.nfd(nfc)
|
nfd = FZF::UConv.nfd(nfc)
|
||||||
assert_equal 6, nfd.length
|
assert_equal 2, nfd.length
|
||||||
assert_equal NFD, nfd
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user