Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
F
fzf
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to JiHu GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
KMSCAKKSCFKA AKFACAMADCAS
fzf
Commits
8aab0fc1
Commit
8aab0fc1
authored
7 years ago
by
Jan Edmund Lazo
Committed by
Junegunn Choi
7 years ago
Browse files
Options
Downloads
Patches
Plain Diff
[vim] Replace s:fzf_shellescape and s:shellesc with fzf#shellescape (#916)
parent
21d664d6
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
plugin/fzf.vim
+24
-20
24 additions, 20 deletions
plugin/fzf.vim
test/fzf.vader
+18
-0
18 additions, 0 deletions
test/fzf.vader
with
42 additions
and
20 deletions
plugin/fzf.vim
+
24
−
20
View file @
8aab0fc1
...
...
@@ -44,20 +44,28 @@ if s:is_win
let
&
shellslash
=
shellslash
endtry
endfunction
function
!
s:fzf_shellescape
(
path
)
return
substitute
(
s:fzf_call
(
'shellescape'
,
a:path
),
'[^\\]\zs\\"$'
,
'\\\\"'
,
''
)
endfunction
else
function
!
s:fzf_call
(
fn
,
...)
return
call
(
a:fn
,
a:000
)
endfunction
function
!
s:fzf_shellescape
(
path
)
return
shellescape
(
a:path
)
endfunction
endif
function
!
s:shellesc_cmd
(
arg
)
let
escaped
=
substitute
(
a:arg
,
'[&|<>()@^]'
,
'^&'
,
'g'
)
let
escaped
=
substitute
(
escaped
,
'%'
,
'%%'
,
'g'
)
let
escaped
=
substitute
(
escaped
,
'"'
,
'\\^&'
,
'g'
)
let
escaped
=
substitute
(
escaped
,
'\\\+\(\\^\)'
,
'\\\\\1'
,
'g'
)
return
'^"'
.
substitute
(
escaped
,
'[^\\]\zs\\$'
,
'\\\\'
,
''
).
'^"'
endfunction
function
!
fzf#
shellescape
(
arg
,
...)
let
shell
=
get
(
a:000
,
0
,
&
shell
)
if
shell
=~
#
'cmd.exe$'
return
s:shellesc_cmd
(
a:arg
)
endif
return
s:fzf_call
(
'shellescape'
,
a:arg
)
endfunction
function
!
s:fzf_getcwd
()
return
s:fzf_call
(
'getcwd'
)
endfunction
...
...
@@ -108,7 +116,7 @@ function! s:fzf_exec()
throw
'fzf executable not found'
endif
endif
return
s:is_win
?
s:exec
:
s:
shellesc
(
s:exec
)
return
s:is_win
?
s:exec
:
fzf#
shellesc
ape
(
s:exec
)
endfunction
function
!
s:tmux_enabled
()
...
...
@@ -128,10 +136,6 @@ function! s:tmux_enabled()
return
s:tmux
endfunction
function
!
s:shellesc
(
arg
)
return
'"'
.
substitute
(
a:arg
,
'"'
,
'\\"'
,
'g'
).
'"'
endfunction
function
!
s:escape
(
path
)
let
escaped_chars
=
'$%#''"'
...
...
@@ -250,7 +254,7 @@ endfunction
function
!
s:evaluate_opts
(
options
)
return
type
(
a:options
)
==
type
([])
?
\
join
(
map
(
copy
(
a:options
),
'
s:
fzf
_
shellescape(v:val)'
))
:
a:options
\
join
(
map
(
copy
(
a:options
),
'fzf
#
shellescape(v:val)'
))
:
a:options
endfunction
" [name string,] [opts dict,] [fullscreen boolean]
...
...
@@ -297,7 +301,7 @@ function! fzf#wrap(...)
if
!
isdirectory
(
dir
)
call
mkdir
(
dir
,
'p'
)
endif
let
history
=
s:is_win
?
s:
fzf
_
shellescape
(
dir
.
'\'.name) : s:escape(dir.'
/'
.
name
)
let
history
=
s:is_win
? fzf
#
shellescape
(
dir
.
'\'.name) : s:escape(dir.'
/'
.
name
)
let
opts
.
options
=
join
([
'--history'
,
history
,
opts
.
options
])
endif
...
...
@@ -349,7 +353,7 @@ try
if
!
has_key
(
dict
,
'source'
)
&&
!
empty
(
$FZF_DEFAULT_COMMAND
)
let
temps
.
source
=
s:fzf_tempname
().(
s:is_win
?
'.bat'
:
''
)
call
writefile
((
s:is_win
?
[
'@echo off'
]
:
[])
+
split
(
$FZF_DEFAULT_COMMAND
,
"\n"
),
temps
.
source
)
let
dict
.
source
=
(
empty
(
$SHELL
)
? &
shell
:
$SHELL
)
.
(
s:is_win
?
' /c '
:
' '
)
.
s:
shellesc
(
temps
.
source
)
let
dict
.
source
=
(
empty
(
$SHELL
)
? &
shell
:
$SHELL
)
.
(
s:is_win
?
' /c '
:
' '
)
.
fzf#
shellesc
ape
(
temps
.
source
)
endif
if
has_key
(
dict
,
'source'
)
...
...
@@ -360,7 +364,7 @@ try
elseif
type
==
3
let
temps
.
input
=
s:fzf_tempname
()
call
writefile
(
source
,
temps
.
input
)
let
prefix
=
(
s:is_win
?
'type '
:
'cat '
).
s:
shellesc
(
temps
.
input
).
'|'
let
prefix
=
(
s:is_win
?
'type '
:
'cat '
).
fzf#
shellesc
ape
(
temps
.
input
).
'|'
else
throw
'Invalid source type'
endif
...
...
@@ -424,7 +428,7 @@ function! s:fzf_tmux(dict)
endif
endfor
return
printf
(
'LINES=%d COLUMNS=%d %s %s %s --'
,
\
&
lines
,
&
columns
,
s:
shellesc
(
s:fzf_tmux
),
size
,
(
has_key
(
a:dict
,
'source'
)
?
''
:
'-'
))
\
&
lines
,
&
columns
,
fzf#
shellesc
ape
(
s:fzf_tmux
),
size
,
(
has_key
(
a:dict
,
'source'
)
?
''
:
'-'
))
endfunction
function
!
s:splittable
(
dict
)
...
...
@@ -493,7 +497,7 @@ function! s:execute(dict, command, use_height, temps) abort
if
has
(
'unix'
)
&&
!
a:use_height
silent
!
!
clear
2
>
/dev/
null
endif
let
escaped
=
escape
(
substitute
(
a:command
,
'\n'
,
'\\n'
,
'g'
),
'%#!'
)
let
escaped
=
(
a:use_height
||
s:is_win
)
?
a:command
:
escape
(
substitute
(
a:command
,
'\n'
,
'\\n'
,
'g'
),
'%#!'
)
if
has
(
'gui_running'
)
let
Launcher
=
get
(
a:dict
,
'launcher'
,
get
(
g
:,
'Fzf_launcher'
,
get
(
g
:,
'fzf_launcher'
,
s:launcher
)))
let
fmt
=
type
(
Launcher
)
==
2
?
call
(
Launcher
,
[])
:
Launcher
...
...
@@ -502,7 +506,7 @@ function! s:execute(dict, command, use_height, temps) abort
endif
let
command
=
printf
(
fmt
,
escaped
)
else
let
command
=
a:use_height
?
a:command
:
escaped
let
command
=
escaped
endif
if
s:is_win
let
batchfile
=
s:fzf_tempname
().
'.bat'
...
...
This diff is collapsed.
Click to expand it.
test/fzf.vader
+
18
−
0
View file @
8aab0fc1
...
...
@@ -147,6 +147,24 @@ Execute (fzf#wrap):
let opts = fzf#wrap({})
Assert opts.options =~ '^--color=fg:'
Execute (fzf#shellescape with sh):
AssertEqual '''''', fzf#shellescape('', 'sh')
AssertEqual '''""''', fzf#shellescape('""', 'sh')
AssertEqual '''foobar>''', fzf#shellescape('foobar>', 'sh')
AssertEqual '''\"''', fzf#shellescape('\"', 'sh')
AssertEqual '''echo ''\''''a''\'''' && echo ''\''''b''\''''''', fzf#shellescape('echo ''a'' && echo ''b''', 'sh')
Execute (fzf#shellescape with cmd.exe):
AssertEqual '^"^"', fzf#shellescape('', 'cmd.exe')
AssertEqual '^"\^"\^"^"', fzf#shellescape('""', 'cmd.exe')
AssertEqual '^"foobar^>^"', fzf#shellescape('foobar>', 'cmd.exe')
AssertEqual '^"\\\^"\\^"', fzf#shellescape('\\\\\\\\"\', 'cmd.exe')
AssertEqual '^"echo ''a'' ^&^& echo ''b''^"', fzf#shellescape('echo ''a'' && echo ''b''', 'cmd.exe')
AssertEqual '^"C:\Program Files ^(x86^)\\^"', fzf#shellescape('C:\Program Files (x86)\', 'cmd.exe')
AssertEqual '^"C:/Program Files ^(x86^)/^"', fzf#shellescape('C:/Program Files (x86)/', 'cmd.exe')
" AssertEqual '^"%%USERPROFILE%%^", fzf#shellescape('%USERPROFILE%', 'cmd.exe')
Execute (Cleanup):
unlet g:dir
Restore
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment