|
|
|
@ -455,15 +455,17 @@ endfunction
|
|
|
|
|
function! s:pushd(dict)
|
|
|
|
|
if s:present(a:dict, 'dir')
|
|
|
|
|
let cwd = s:fzf_getcwd()
|
|
|
|
|
if get(a:dict, 'prev_dir', '') ==# cwd
|
|
|
|
|
return 1
|
|
|
|
|
endif
|
|
|
|
|
let a:dict.prev_dir = cwd
|
|
|
|
|
let w:fzf_pushd = {
|
|
|
|
|
\ 'command': haslocaldir() ? 'lcd' : (exists(':tcd') && haslocaldir(-1) ? 'tcd' : 'cd'),
|
|
|
|
|
\ 'origin': cwd
|
|
|
|
|
\ }
|
|
|
|
|
execute 'lcd' s:escape(a:dict.dir)
|
|
|
|
|
let a:dict.dir = s:fzf_getcwd()
|
|
|
|
|
return 1
|
|
|
|
|
let cwd = s:fzf_getcwd()
|
|
|
|
|
let w:fzf_pushd.dir = cwd
|
|
|
|
|
let a:dict.pushd = w:fzf_pushd
|
|
|
|
|
return cwd
|
|
|
|
|
endif
|
|
|
|
|
return 0
|
|
|
|
|
return ''
|
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
|
augroup fzf_popd
|
|
|
|
@ -472,11 +474,11 @@ augroup fzf_popd
|
|
|
|
|
augroup END
|
|
|
|
|
|
|
|
|
|
function! s:dopopd()
|
|
|
|
|
if !exists('w:fzf_dir') || s:fzf_getcwd() != w:fzf_dir[1]
|
|
|
|
|
if !exists('w:fzf_pushd')
|
|
|
|
|
return
|
|
|
|
|
endif
|
|
|
|
|
execute 'lcd' s:escape(w:fzf_dir[0])
|
|
|
|
|
unlet w:fzf_dir
|
|
|
|
|
execute w:fzf_pushd.command s:escape(w:fzf_pushd.origin)
|
|
|
|
|
unlet w:fzf_pushd
|
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
|
function! s:xterm_launcher()
|
|
|
|
@ -534,9 +536,7 @@ function! s:execute(dict, command, use_height, temps) abort
|
|
|
|
|
let fzf.dict = a:dict
|
|
|
|
|
let fzf.temps = a:temps
|
|
|
|
|
function! fzf.on_exit(job_id, exit_status, event) dict
|
|
|
|
|
if s:present(self.dict, 'dir')
|
|
|
|
|
execute 'lcd' s:escape(self.dict.dir)
|
|
|
|
|
endif
|
|
|
|
|
call s:pushd(self.dict)
|
|
|
|
|
let lines = s:collect(self.temps)
|
|
|
|
|
call s:callback(self.dict, lines)
|
|
|
|
|
endfunction
|
|
|
|
@ -563,9 +563,10 @@ endfunction
|
|
|
|
|
|
|
|
|
|
function! s:execute_tmux(dict, command, temps) abort
|
|
|
|
|
let command = a:command
|
|
|
|
|
if s:pushd(a:dict)
|
|
|
|
|
let cwd = s:pushd(a:dict)
|
|
|
|
|
if len(cwd)
|
|
|
|
|
" -c '#{pane_current_path}' is only available on tmux 1.9 or above
|
|
|
|
|
let command = join(['cd', fzf#shellescape(a:dict.dir), '&&', command])
|
|
|
|
|
let command = join(['cd', fzf#shellescape(cwd), '&&', command])
|
|
|
|
|
endif
|
|
|
|
|
|
|
|
|
|
call system(command)
|
|
|
|
@ -686,9 +687,7 @@ function! s:execute_term(dict, command, temps) abort
|
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
if s:present(a:dict, 'dir')
|
|
|
|
|
execute 'lcd' s:escape(a:dict.dir)
|
|
|
|
|
endif
|
|
|
|
|
call s:pushd(a:dict)
|
|
|
|
|
if s:is_win
|
|
|
|
|
let fzf.temps.batchfile = s:fzf_tempname().'.bat'
|
|
|
|
|
call writefile(s:wrap_cmds(a:command), fzf.temps.batchfile)
|
|
|
|
@ -706,9 +705,7 @@ function! s:execute_term(dict, command, temps) abort
|
|
|
|
|
endif
|
|
|
|
|
endif
|
|
|
|
|
finally
|
|
|
|
|
if s:present(a:dict, 'dir')
|
|
|
|
|
lcd -
|
|
|
|
|
endif
|
|
|
|
|
call s:dopopd()
|
|
|
|
|
endtry
|
|
|
|
|
setlocal nospell bufhidden=wipe nobuflisted nonumber
|
|
|
|
|
setf fzf
|
|
|
|
@ -738,10 +735,10 @@ function! s:callback(dict, lines) abort
|
|
|
|
|
" And it will be an array of a single empty string when fzf was finished
|
|
|
|
|
" without a match. In these cases, we presume that the change of the
|
|
|
|
|
" directory is not expected and should be undone.
|
|
|
|
|
let popd = has_key(a:dict, 'prev_dir') &&
|
|
|
|
|
let popd = has_key(a:dict, 'pushd') &&
|
|
|
|
|
\ (!&autochdir || (empty(a:lines) || len(a:lines) == 1 && empty(a:lines[0])))
|
|
|
|
|
if popd
|
|
|
|
|
let w:fzf_dir = [a:dict.prev_dir, a:dict.dir]
|
|
|
|
|
let w:fzf_pushd = a:dict.pushd
|
|
|
|
|
endif
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
@ -765,7 +762,7 @@ function! s:callback(dict, lines) abort
|
|
|
|
|
|
|
|
|
|
" We may have opened a new window or tab
|
|
|
|
|
if popd
|
|
|
|
|
let w:fzf_dir = [a:dict.prev_dir, a:dict.dir]
|
|
|
|
|
let w:fzf_pushd = a:dict.pushd
|
|
|
|
|
call s:dopopd()
|
|
|
|
|
endif
|
|
|
|
|
endfunction
|
|
|
|
|