File tree 12 files changed +53
-15
lines changed
12 files changed +53
-15
lines changed Original file line number Diff line number Diff line change @@ -390,6 +390,14 @@ _comp_expand_glob()
390
390
return 0
391
391
}
392
392
393
+ # Check if the argument looks like a path.
394
+ # @param $1 thing to check
395
+ # @return True (0) if it does, False (> 0) otherwise
396
+ _comp_looks_like_path ()
397
+ {
398
+ [[ ${1-} == @ (* /| [.~])* ]]
399
+ }
400
+
393
401
# Reassemble command line words, excluding specified characters from the
394
402
# list of word completion separators (COMP_WORDBREAKS).
395
403
# @param $1 chars Characters out of $COMP_WORDBREAKS which should
Original file line number Diff line number Diff line change @@ -39,7 +39,7 @@ _apt_get()
39
39
awk ' $1 == "Source:" { print $2 }' | sort -u) " -- " $cur " ) )
40
40
;;
41
41
install | reinstall)
42
- if [[ $cur == * / * ]] ; then
42
+ if _comp_looks_like_path " $cur " ; then
43
43
_filedir deb
44
44
return
45
45
elif [[ $cur == * = * ]]; then
@@ -58,7 +58,7 @@ _apt_get()
58
58
;;&
59
59
build-dep)
60
60
_filedir -d
61
- [[ $cur != * / * ]] || return
61
+ _comp_looks_like_path " $cur " && return
62
62
;;&
63
63
* )
64
64
COMPREPLY+=($( _comp_xfunc apt-cache packages) )
Original file line number Diff line number Diff line change 17
17
if (( cword == 1 )) ; then
18
18
local IFS
19
19
compopt -o filenames
20
- if [[ $cur == * / * ]] ; then
20
+ if _comp_looks_like_path " $cur " ; then
21
21
# compgen -c works as expected if $cur contains any slashes.
22
22
IFS=$' \n '
23
23
COMPREPLY=($( PATH=" $PATH :." compgen -d -c -- " $cur " ) )
Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ _kldload()
7
7
local cur prev words cword
8
8
_init_completion || return
9
9
10
- if [[ " $cur " == * / * ]] ; then
10
+ if _comp_looks_like_path " $cur " ; then
11
11
_filedir ko
12
12
return
13
13
fi
Original file line number Diff line number Diff line change 52
52
fi
53
53
54
54
# file based completion if parameter looks like a path
55
- if [[ $cur == @ ( * / | [.~]) * ]] ; then
55
+ if _comp_looks_like_path " $cur " ; then
56
56
_filedir " $manext "
57
57
return
58
58
fi
Original file line number Diff line number Diff line change @@ -24,7 +24,7 @@ _pydoc()
24
24
25
25
COMPREPLY=($( compgen -W ' keywords topics modules' -- " $cur " ) )
26
26
27
- if [[ $cur != @ (. | * /) * ]] ; then
27
+ if ! _comp_looks_like_path " $cur " ; then
28
28
local python=python
29
29
[[ ${1##*/ } == * 3* ]] && python=python3
30
30
_comp_xfunc python modules $python
Original file line number Diff line number Diff line change @@ -107,7 +107,7 @@ _pylint()
107
107
return
108
108
fi
109
109
110
- [[ $cur == @ (. | * /) * ]] || _comp_xfunc python modules $python
110
+ _comp_looks_like_path " $cur " || _comp_xfunc python modules $python
111
111
_filedir py
112
112
} &&
113
113
complete -F _pylint pylint pylint-2 pylint-3
Original file line number Diff line number Diff line change @@ -9,7 +9,7 @@ _removepkg()
9
9
return
10
10
fi
11
11
12
- if [[ $cur == * / * ]] ; then
12
+ if _comp_looks_like_path " $cur " ; then
13
13
_filedir
14
14
return
15
15
fi
Original file line number Diff line number Diff line change 92
92
;;
93
93
--whatenhances | --whatprovides | --whatrecommends | --whatrequires | \
94
94
--whatsuggests | --whatsupplements)
95
- if [[ $cur == * / * ]] ; then
95
+ if _comp_looks_like_path " $cur " ; then
96
96
_filedir
97
97
else
98
98
# complete on capabilities
Original file line number Diff line number Diff line change @@ -580,12 +580,11 @@ _scp()
580
580
COMPREPLY=(" ${COMPREPLY[@]/%/ } " )
581
581
return
582
582
;;
583
- * /* | [.~]* )
584
- # not a known host, pass through
585
- ;;
586
583
* )
587
- _known_hosts_real ${ipvx-} -c -a \
588
- ${configfile: +-F " $configfile " } -- " $cur "
584
+ if ! _comp_looks_like_path " $cur " ; then
585
+ _known_hosts_real ${ipvx-} -c -a \
586
+ ${configfile: +-F " $configfile " } -- " $cur "
587
+ fi
589
588
;;
590
589
esac
591
590
fi
Original file line number Diff line number Diff line change @@ -61,7 +61,7 @@ _vpnc()
61
61
62
62
if [[ $cur == -* ]]; then
63
63
COMPREPLY=($( compgen -W ' $(_parse_help "$1" --long-help)' -- " $cur " ) )
64
- elif [[ $cur == * / * ]] ; then
64
+ elif _comp_looks_like_path " $cur " ; then
65
65
# explicit filename
66
66
_filedir conf
67
67
else
Original file line number Diff line number Diff line change
1
+ import pytest
2
+
3
+ from conftest import TestUnitBase , assert_bash_exec
4
+
5
+
6
+ @pytest .mark .bashcomp (cmd = None )
7
+ class TestUnitQuote (TestUnitBase ):
8
+ @pytest .mark .parametrize (
9
+ "thing_looks_like" ,
10
+ (
11
+ ("" , False ),
12
+ ("foo" , False ),
13
+ ("/foo" , True ),
14
+ ("foo/" , True ),
15
+ ("foo/bar" , True ),
16
+ ("." , True ),
17
+ ("../" , True ),
18
+ ("~" , True ),
19
+ ("~foo" , True ),
20
+ ),
21
+ )
22
+ def test_1 (self , bash , thing_looks_like ):
23
+ thing , looks_like = thing_looks_like
24
+ output = assert_bash_exec (
25
+ bash ,
26
+ f"_comp_looks_like_path '{ thing } '; printf %s $?" ,
27
+ want_output = True ,
28
+ want_newline = False ,
29
+ )
30
+ is_zero = output .strip () == "0"
31
+ assert (looks_like and is_zero ) or (not looks_like and not is_zero )
You can’t perform that action at this time.
0 commit comments