Skip to content
Myr

Merge branch 'master' into devel

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Junegunn Choi · committed by Junegunn Choi · parents 34f16e5, 35d4070 · Browse files · 3 files+56 added−21 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+56 added−21 removed

  • tests:+18 added−0 removed
  • other:+38 added−21 removed

3 files+56 added−21 removed

modified:plugin/fzf.vim+36 added-19 removed
43 unmodified lines
44 let &shellslash = shellslash45 endtry46 endfunction4748 function! s:fzf_shellescape(path)49 return substitute(s:fzf_call('shellescape', a:path), '[^\\]\zs\\"$', '\\\\"', '')48 " Use utf-8 for fzf.vim commands49 " Return array of shell commands for cmd.exe50 function! s:wrap_cmds(cmds)51 return ['@echo off', 'for /f "tokens=4" %%a in (''chcp'') do set origchcp=%%a', 'chcp 65001 > nul'] +52 \ (type(a:cmds) == type([]) ? a:cmds : [a:cmds]) +53 \ ['chcp %origchcp% > nul']54 endfunction55else56 function! s:fzf_call(fn, ...)57 return call(a:fn, a:000)58 endfunction5956 function! s:fzf_shellescape(path)57 return shellescape(a:path)60 function! s:wrap_cmds(cmds)61 return a:cmds62 endfunction63endif6465function! s:shellesc_cmd(arg)66 let escaped = substitute(a:arg, '[&|<>()@^]', '^&', 'g')67 let escaped = substitute(escaped, '%', '%%', 'g')68 let escaped = substitute(escaped, '"', '\\^&', 'g')69 let escaped = substitute(escaped, '\\\+\(\\^\)', '\\\\\1', 'g')70 return '^"'.substitute(escaped, '[^\\]\zs\\$', '\\\\', '').'^"'71endfunction7273function! fzf#shellescape(arg, ...)74 let shell = get(a:000, 0, &shell)75 if shell =~# 'cmd.exe$'76 return s:shellesc_cmd(a:arg)77 endif78 return s:fzf_call('shellescape', a:arg)79endfunction8081function! s:fzf_getcwd()82 return s:fzf_call('getcwd')83endfunction84
42 unmodified lines
127 redraw128 throw 'fzf executable not found'129 endif130 endif111 return s:is_win ? s:exec : s:shellesc(s:exec)131 return fzf#shellescape(s:exec)132endfunction133134function! s:tmux_enabled()135 if has('gui_running')
11 unmodified lines
147 endif148 return s:tmux149endfunction150131function! s:shellesc(arg)132 return '"'.substitute(a:arg, '"', '\\"', 'g').'"'133endfunction134151function! s:escape(path)152 let escaped_chars = '$%#''"'153154 if has('unix')
110 unmodified lines
265endfunction266267function! s:evaluate_opts(options)268 return type(a:options) == type([]) ?253 \ join(map(copy(a:options), 's:fzf_shellescape(v:val)')) : a:options269 \ join(map(copy(a:options), 'fzf#shellescape(v:val)')) : a:options270endfunction271272" [name string,] [opts dict,] [fullscreen boolean]273function! fzf#wrap(...)
38 unmodified lines
312 let dir = s:fzf_expand(g:fzf_history_dir)313 if !isdirectory(dir)314 call mkdir(dir, 'p')315 endif300 let history = s:is_win ? s:fzf_shellescape(dir.'\'.name) : s:escape(dir.'/'.name)316 let history = fzf#shellescape(dir.'/'.name)317 let opts.options = join(['--history', history, opts.options])318 endif319320 " Action: g:fzf_action
42 unmodified lines
363 endif364365 if !has_key(dict, 'source') && !empty($FZF_DEFAULT_COMMAND)366 let temps.source = s:fzf_tempname().(s:is_win ? '.bat' : '')351 call writefile((s:is_win ? ['@echo off'] : []) + split($FZF_DEFAULT_COMMAND, "\n"), temps.source)352 let dict.source = (empty($SHELL) ? &shell : $SHELL) . (s:is_win ? ' /c ' : ' ') . s:shellesc(temps.source)367 call writefile(s:wrap_cmds(split($FZF_DEFAULT_COMMAND, "\n")), temps.source)368 let dict.source = (empty($SHELL) ? &shell : $SHELL) . (s:is_win ? ' /c ' : ' ') . fzf#shellescape(temps.source)369 endif370371 if has_key(dict, 'source')372 let source = dict.source
2 unmodified lines
375 let prefix = source.'|'376 elseif type == 3377 let temps.input = s:fzf_tempname()378 call writefile(source, temps.input)363 let prefix = (s:is_win ? 'type ' : 'cat ').s:shellesc(temps.input).'|'379 let prefix = (s:is_win ? 'type ' : 'cat ').fzf#shellescape(temps.input).'|'380 else381 throw 'Invalid source type'382 endif383 else
55 unmodified lines
439 break440 endif441 endfor442 return printf('LINES=%d COLUMNS=%d %s %s %s --',427 \ &lines, &columns, s:shellesc(s:fzf_tmux), size, (has_key(a:dict, 'source') ? '' : '-'))443 \ &lines, &columns, fzf#shellescape(s:fzf_tmux), size, (has_key(a:dict, 'source') ? '' : '-'))444endfunction445446function! s:splittable(dict)447 return s:present(a:dict, 'up', 'down') && &lines > 15 ||
60 unmodified lines
508 call s:pushd(a:dict)509 if has('unix') && !a:use_height510 silent! !clear 2> /dev/null511 endif496 let escaped = escape(substitute(a:command, '\n', '\\n', 'g'), '%#!')512 let escaped = (a:use_height || s:is_win) ? a:command : escape(substitute(a:command, '\n', '\\n', 'g'), '%#!')513 if has('gui_running')514 let Launcher = get(a:dict, 'launcher', get(g:, 'Fzf_launcher', get(g:, 'fzf_launcher', s:launcher)))515 let fmt = type(Launcher) == 2 ? call(Launcher, []) : Launcher516 if has('unix')517 let escaped = "'".substitute(escaped, "'", "'\"'\"'", 'g')."'"518 endif519 let command = printf(fmt, escaped)520 else505 let command = a:use_height ? a:command : escaped521 let command = escaped522 endif523 if s:is_win524 let batchfile = s:fzf_tempname().'.bat'509 call writefile(['@echo off', command], batchfile)525 call writefile(s:wrap_cmds(command), batchfile)526 let command = batchfile527 let a:temps.batchfile = batchfile528 if has('nvim')529 let s:dict = a:dict530 let s:temps = a:temps531 let fzf = {}
20 unmodified lines
552function! s:execute_tmux(dict, command, temps) abort553 let command = a:command554 if s:pushd(a:dict)555 " -c '#{pane_current_path}' is only available on tmux 1.9 or above539 let command = 'cd '.s:escape(a:dict.dir).' && '.command556 let command = join(['cd', fzf#shellescape(a:dict.dir), '&&', command])557 endif558559 call system(command)560 let exit_status = v:shell_error
216 unmodified lines
modified:test/fzf.vader+18 added
145 unmodified lines
146 let g:fzf_colors = { 'fg': ['fg', 'Error'] }147 let opts = fzf#wrap({})148 Assert opts.options =~ '^--color=fg:'149150Execute (fzf#shellescape with sh):151 AssertEqual '''''', fzf#shellescape('', 'sh')152 AssertEqual '''""''', fzf#shellescape('""', 'sh')153 AssertEqual '''foobar>''', fzf#shellescape('foobar>', 'sh')154 AssertEqual '''\"''', fzf#shellescape('\"', 'sh')155 AssertEqual '''echo ''\''''a''\'''' && echo ''\''''b''\''''''', fzf#shellescape('echo ''a'' && echo ''b''', 'sh')156157Execute (fzf#shellescape with cmd.exe):158 AssertEqual '^"^"', fzf#shellescape('', 'cmd.exe')159 AssertEqual '^"\^"\^"^"', fzf#shellescape('""', 'cmd.exe')160 AssertEqual '^"foobar^>^"', fzf#shellescape('foobar>', 'cmd.exe')161 AssertEqual '^"\\\^"\\^"', fzf#shellescape('\\\\\\\\"\', 'cmd.exe')162 AssertEqual '^"echo ''a'' ^&^& echo ''b''^"', fzf#shellescape('echo ''a'' && echo ''b''', 'cmd.exe')163164 AssertEqual '^"C:\Program Files ^(x86^)\\^"', fzf#shellescape('C:\Program Files (x86)\', 'cmd.exe')165 AssertEqual '^"C:/Program Files ^(x86^)/^"', fzf#shellescape('C:/Program Files (x86)/', 'cmd.exe')166 " AssertEqual '^"%%USERPROFILE%%^", fzf#shellescape('%USERPROFILE%', 'cmd.exe')167168Execute (Cleanup):169 unlet g:dir170 Restore
modified:README.md+2 added-2 removed
372 unmodified lines
373(`complete | grep _fzf` to see the list). But you can enable it for other374commands as well like follows.375376```sh377# There are also _fzf_path_completion and _fzf_dir_completion378complete -F _fzf_file_completion -o default -o bashdefault doge377complete -F _fzf_path_completion -o default -o bashdefault ag378complete -F _fzf_dir_completion -o default -o bashdefault tree379```380381Vim plugin382----------
86 unmodified lines