mirror of
https://github.com/Llewellynvdm/fzf.git
synced 2024-11-22 21:05:09 +00:00
0f281ef894
When 'dir' option is passed to fzf#run(), the current working directory is temporarily changed to the given directory, and restored at the end. However, this behavior is not compatible with &autochdir. This commit introduces a heuristic to determine whether or not to restore the previous working directory. Related: https://github.com/junegunn/fzf.vim/issues/70
70 lines
2.3 KiB
Plaintext
70 lines
2.3 KiB
Plaintext
Execute (Setup):
|
|
let g:dir = fnamemodify(g:vader_file, ':p:h')
|
|
Log 'Test directory: ' . g:dir
|
|
Save &acd
|
|
|
|
Execute (fzf#run with dir option):
|
|
let cwd = getcwd()
|
|
let result = fzf#run({ 'options': '--filter=vdr', 'dir': g:dir })
|
|
AssertEqual ['fzf.vader'], result
|
|
AssertEqual getcwd(), cwd
|
|
|
|
let result = sort(fzf#run({ 'options': '--filter e', 'dir': g:dir }))
|
|
AssertEqual ['fzf.vader', 'test_go.rb'], result
|
|
AssertEqual getcwd(), cwd
|
|
|
|
Execute (fzf#run with Funcref command):
|
|
let g:ret = []
|
|
function! g:FzfTest(e)
|
|
call add(g:ret, a:e)
|
|
endfunction
|
|
let result = sort(fzf#run({ 'sink': function('g:FzfTest'), 'options': '--filter e', 'dir': g:dir }))
|
|
AssertEqual ['fzf.vader', 'test_go.rb'], result
|
|
AssertEqual ['fzf.vader', 'test_go.rb'], sort(g:ret)
|
|
|
|
Execute (fzf#run with string source):
|
|
let result = sort(fzf#run({ 'source': 'echo hi', 'options': '-f i' }))
|
|
AssertEqual ['hi'], result
|
|
|
|
Execute (fzf#run with list source):
|
|
let result = sort(fzf#run({ 'source': ['hello', 'world'], 'options': '-f e' }))
|
|
AssertEqual ['hello'], result
|
|
let result = sort(fzf#run({ 'source': ['hello', 'world'], 'options': '-f o' }))
|
|
AssertEqual ['hello', 'world'], result
|
|
|
|
Execute (fzf#run with string source):
|
|
let result = sort(fzf#run({ 'source': 'echo hi', 'options': '-f i' }))
|
|
AssertEqual ['hi'], result
|
|
|
|
Execute (fzf#run with dir option and noautochdir):
|
|
set noacd
|
|
let cwd = getcwd()
|
|
call fzf#run({'source': ['/foobar'], 'sink': 'e', 'dir': '/tmp', 'options': '-1'})
|
|
" No change in working directory
|
|
AssertEqual cwd, getcwd()
|
|
|
|
Execute (Incomplete fzf#run with dir option and autochdir):
|
|
set acd
|
|
let cwd = getcwd()
|
|
call fzf#run({'source': [], 'sink': 'e', 'dir': '/tmp', 'options': '-0'})
|
|
" No change in working directory even if &acd is set
|
|
AssertEqual cwd, getcwd()
|
|
|
|
Execute (fzf#run with dir option and autochdir):
|
|
set acd
|
|
let cwd = getcwd()
|
|
call fzf#run({'source': ['/foobar'], 'sink': 'e', 'dir': '/tmp', 'options': '-1'})
|
|
" Working directory changed due to &acd
|
|
AssertEqual '/', getcwd()
|
|
|
|
Execute (fzf#run with dir option and autochdir when final cwd is same as dir):
|
|
set acd
|
|
cd /tmp
|
|
call fzf#run({'source': ['/foobar'], 'sink': 'e', 'dir': '/', 'options': '-1'})
|
|
" Working directory changed due to &acd
|
|
AssertEqual '/', getcwd()
|
|
|
|
Execute (Cleanup):
|
|
unlet g:dir
|
|
Restore
|