@@ -850,12 +850,17 @@ _comp_get_words()
850
850
(( ${# upvars[@]} )) && local " ${upvars[@]} " && _comp_upvars " ${upargs[@]} "
851
851
}
852
852
853
- # If the word-to-complete contains a colon (:), left-trim COMPREPLY items with
854
- # word-to-complete.
855
- # With a colon in COMP_WORDBREAKS, words containing
856
- # colons are always completed as entire words if the word to complete contains
857
- # a colon. This function fixes this, by removing the colon-containing-prefix
858
- # from COMPREPLY items.
853
+ # Generate the specified items after left-trimming with the word-to-complete
854
+ # containing a colon (:). If the word-to-complete does not contain a colon,
855
+ # this generates the specified items without modifications.
856
+ # @param $@ items to generate
857
+ # @var[in] cur current word to complete
858
+ #
859
+ # @remarks In Bash, with a colon in COMP_WORDBREAKS, words containing colons
860
+ # are always completed as entire words if the word to complete contains a
861
+ # colon. This function fixes this behavior by removing the
862
+ # colon-containing-prefix from the items.
863
+ #
859
864
# The preferred solution is to remove the colon (:) from COMP_WORDBREAKS in
860
865
# your .bashrc:
861
866
#
@@ -864,19 +869,32 @@ _comp_get_words()
864
869
#
865
870
# See also: Bash FAQ - E13) Why does filename completion misbehave if a colon
866
871
# appears in the filename? - https://tiswww.case.edu/php/chet/bash/FAQ
872
+ #
873
+ # @since 2.12
874
+ _comp_compgen_ltrim_colon ()
875
+ {
876
+ (( $# )) || return 0
877
+ local -a tmp
878
+ tmp=(" $@ " )
879
+ if [[ $cur == * :* && $COMP_WORDBREAKS == * :* ]]; then
880
+ # Remove colon-word prefix from items
881
+ local colon_word=${cur% " ${cur##*: } " }
882
+ tmp=(" ${tmp[@]# " $colon_word " } " )
883
+ fi
884
+ _comp_compgen -R -- -W ' "${tmp[@]}"'
885
+ }
886
+
887
+ # If the word-to-complete contains a colon (:), left-trim COMPREPLY items with
888
+ # word-to-complete.
889
+ #
867
890
# @param $1 current word to complete (cur)
868
- # @modifies global array $ COMPREPLY
891
+ # @var[in,out] COMPREPLY
869
892
#
870
893
# @since 2.12
871
894
_comp_ltrim_colon_completions ()
872
895
{
873
- local i=${# COMPREPLY[*]}
874
- (( i == 0 )) && return 0
875
- if [[ $1 == * :* && $COMP_WORDBREAKS == * :* ]]; then
876
- # Remove colon-word prefix from COMPREPLY items
877
- local colon_word=${1% " ${1##*: } " }
878
- COMPREPLY=(" ${COMPREPLY[@]# " $colon_word " } " )
879
- fi
896
+ (( ${# COMPREPLY[@]} )) || return 0
897
+ _comp_compgen -c " $1 " ltrim_colon " ${COMPREPLY[@]} "
880
898
} # _comp_ltrim_colon_completions()
881
899
882
900
# This function quotes the argument in a way so that readline dequoting
0 commit comments