File tree 2 files changed +26
-1
lines changed
2 files changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -4,7 +4,18 @@ _comp_cmd_cd__compgen_cdable_vars()
4
4
{
5
5
shopt -q cdable_vars || return 1
6
6
7
- _comp_compgen -- -v
7
+ local vars
8
+ _comp_compgen -v vars -- -v || return " $? "
9
+
10
+ # Remove variables that do not contain a valid directory path.
11
+ local _i
12
+ for _i in " ${! vars[@]} " ; do
13
+ # Note: ${!vars[_i]} produces the "nounset" error when vars[_i] is an
14
+ # empty array name.
15
+ [[ -d ${! vars[_i]-} ]] || unset -v ' vars[_i]'
16
+ done
17
+
18
+ _comp_compgen -U vars set " ${vars[@]} "
8
19
}
9
20
10
21
# This generator function observes the CDPATH variable, to additionally
Original file line number Diff line number Diff line change 1
1
import pytest
2
2
3
+ from conftest import assert_complete , bash_env_saved
4
+
3
5
4
6
@pytest .mark .bashcomp (ignore_env = r"^\+CDPATH=$" )
5
7
class TestCd :
@@ -28,3 +30,15 @@ def test_dir_at_point(self, completion):
28
30
@pytest .mark .complete ("cd -" )
29
31
def test_options (self , completion ):
30
32
assert completion
33
+
34
+ def test_cdable_vars (self , bash ):
35
+ with bash_env_saved (bash ) as bash_env :
36
+ bash_env .shopt ("cdable_vars" , True )
37
+ bash_env .write_variable ("foo1" , "shared" )
38
+ bash_env .write_variable ("foo2" , "shared/default" )
39
+ bash_env .write_variable ("foo3" , "nonexistent" )
40
+ bash_env .write_variable ("foo4" , "nonexistent" )
41
+ bash_env .write_variable ("foo5" , "shared/default/foo" )
42
+ bash_env .write_variable ("foo6" , "shared/default/bar" )
43
+ completion = assert_complete (bash , "cd f" )
44
+ assert completion == ["foo1" , "foo2" ]
You can’t perform that action at this time.
0 commit comments