Skip to content

Commit a1969bd

Browse files
author
ianmacd
committed
mark-directories and mark-symlinked-directories are very convenient readline settings which append a slash to a completed directory/symlinked directory. Unfortunately, this doesn't work with directories found by looking at $CDPATH. There is now also a slash appended if the user completes on an unambiguous directory found by looking at $CDPATH. Patch by Claudio Bley <[email protected]>.
1 parent 7b68bd1 commit a1969bd

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

bash_completion

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# bash_completion - some programmable completion functions for bash 2.05b
22
#
3-
# $Id: bash_completion,v 1.728 2004/07/04 00:56:08 ianmacd Exp $
3+
# $Id: bash_completion,v 1.729 2004/07/04 01:15:29 ianmacd Exp $
44
#
55
# Copyright (C) Ian Macdonald <[email protected]>
66
#
@@ -2785,19 +2785,30 @@ _cd()
27852785
return 0
27862786
fi
27872787

2788-
IFS=$'\t\n'
2788+
local -r mark_dirs=$(_rl_enabled mark-directories && echo y)
2789+
local -r mark_symdirs=$(_rl_enabled mark-symlinked-directories && echo y)
2790+
27892791
# we have a CDPATH, so loop on its contents
27902792
for i in ${CDPATH//:/$'\t'}; do
27912793
# create an array of matched subdirs
27922794
k=${#COMPREPLY[@]}
27932795
for j in $( compgen -d $i/$cur ); do
2794-
COMPREPLY[$k]=${j#$i/}
2795-
k=$((++k))
2796+
if [[ ( $mark_symdirs && -h $j || $mark_dirs && ! -h $j ) && ! -d ${j#$i/} ]]; then
2797+
j="${j}/"
2798+
fi
2799+
COMPREPLY[k++]=${j#$i/}
27962800
done
27972801
done
27982802

27992803
_filedir -d
28002804

2805+
if [[ ${#COMPREPLY[@]} -eq 1 ]]; then
2806+
i=${COMPREPLY[0]}
2807+
if [ "$i" == "$cur" ] && [[ $i != "*/" ]]; then
2808+
COMPREPLY[0]="${i}/"
2809+
fi
2810+
fi
2811+
28012812
return 0
28022813
}
28032814
if shopt -q cdable_vars; then

0 commit comments

Comments
 (0)