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
Provenance
- Commit
f4731c0- Tree
e3d5e0c- Author
Junegunn Choi <junegunn.c@gmail.com>- Committer
Junegunn Choi <junegunn.c@gmail.com>- Parent 1
34f16e5- Parent 2
35d4070
3 files changed+56 added−21 removed
modified:plugin/fzf.vim+36 added-19 removed
43 unmodified lines44 let &shellslash = shellslash45 endtry46 endfunction47 48- 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 endfunction55 else56 function! s:fzf_call(fn, ...)57 return call(a:fn, a:000)58 endfunction59 56- function! s:fzf_shellescape(path)57- return shellescape(a:path)60+ function! s:wrap_cmds(cmds)61+ return a:cmds62 endfunction63 endif64 65+function! 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\\$', '\\\\', '').'^"'71+endfunction72+73+function! 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)79+endfunction80+81 function! s:fzf_getcwd()82 return s:fzf_call('getcwd')83 endfunction84 42 unmodified lines127 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)132 endfunction133 134 function! s:tmux_enabled()135 if has('gui_running')11 unmodified lines147 endif148 return s:tmux149 endfunction150 131-function! s:shellesc(arg)132- return '"'.substitute(a:arg, '"', '\\"', 'g').'"'133-endfunction134-151 function! s:escape(path)152 let escaped_chars = '$%#''"'153 154 if has('unix')110 unmodified lines265 endfunction266 267 function! 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:options270 endfunction271 272 " [name string,] [opts dict,] [fullscreen boolean]273 function! fzf#wrap(...)38 unmodified lines312 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 endif319 320 " Action: g:fzf_action42 unmodified lines363 endif364 365 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 endif370 371 if has_key(dict, 'source')372 let source = dict.source2 unmodified lines375 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 else55 unmodified lines439 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') ? '' : '-'))444 endfunction445 446 function! s:splittable(dict)447 return s:present(a:dict, 'up', 'down') && &lines > 15 ||60 unmodified lines508 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 lines552 function! 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 endif558 559 call system(command)560 let exit_status = v:shell_error216 unmodified linesmodified:test/fzf.vader+18 added
145 unmodified lines146 let g:fzf_colors = { 'fg': ['fg', 'Error'] }147 let opts = fzf#wrap({})148 Assert opts.options =~ '^--color=fg:'149 150+Execute (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')156+157+Execute (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')163+164+ 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')167+168 Execute (Cleanup):169 unlet g:dir170 Restoremodified:README.md+2 added-2 removed
372 unmodified lines373 (`complete | grep _fzf` to see the list). But you can enable it for other374 commands as well like follows.375 376 ```sh377-# There are also _fzf_path_completion and _fzf_dir_completion378-complete -F _fzf_file_completion -o default -o bashdefault doge377+complete -F _fzf_path_completion -o default -o bashdefault ag378+complete -F _fzf_dir_completion -o default -o bashdefault tree379 ```380 381 Vim plugin382 ----------86 unmodified lines