No tab completion with asterisk *

I am not able to tab complete from the command line in gnome-terminal when I have an asterisk in the command line. Default shell is bash, using gnome-terminal. For example,

This works to copy a single file into a dir using tab-completion on the ~/files/ directory:

cp ~/file1 ~/files/

However this does not work using tab completion on the directory when I want to copy multiple files into a dir (I have to manually type out or paste ~/files/):

cp ~/file* ~/files/

(Assuming there exist the files file1, file2, file3 & file4)

And this does tab complete the directory (and works as I would expect regex to work, copying all of those files into ~/files/):

cp ~/file?* ~/files/

So I do have a workaround. But I know I have had this working before without having to use the ? and I'm not exactly sure how or when I lost it. As a heavy command line user I've been living with it, but it's been relatively annoying lately.

EDIT1+:

Output of $ compopt cp

compopt +o bashdefault +o default +o dirnames +o filenames +o nospace +o plusdirs cp

Output of $ set -x then $ cp ~/file* ~/file<tab>

+ (( COMP_CWORD += 1 ))
+ COMP_WORDS=(cp -i ${COMP_WORDS[@]:1})
+ (( COMP_POINT -= 17 ))
+ COMP_LINE='cp -i ./file* ./file'
+ (( COMP_POINT += 20 ))
+ _longopt
+ local cur prev words cword split
+ _init_completion -s
+ local exclude= flag outx errx inx OPTIND=1
+ getopts n:e:o:i:s flag -s
+ case $flag in
+ split=false
+ exclude+==
+ getopts n:e:o:i:s flag -s
+ COMPREPLY=()
+ local 'redir=@(?([0-9])<|?([0-9&])>?(>)|>&)'
+ _get_comp_words_by_ref -n '=<>&' cur prev words cword
+ local exclude flag i OPTIND=1
+ words=()
+ local cur cword words
+ upargs=()
+ upvars=()
+ local upargs upvars vcur vcword vprev vwords
+ getopts c:i:n:p:w: flag -n '=<>&' cur prev words cword
+ case $flag in
+ exclude='=<>&'
+ getopts c:i:n:p:w: flag -n '=<>&' cur prev words cword
+ [[ 6 -ge 3 ]]
+ case ${!OPTIND} in
+ vcur=cur
+ let 'OPTIND += 1'
+ [[ 6 -ge 4 ]]
+ case ${!OPTIND} in
+ vprev=prev
+ let 'OPTIND += 1'
+ [[ 6 -ge 5 ]]
+ case ${!OPTIND} in
+ vwords=words
+ let 'OPTIND += 1'
+ [[ 6 -ge 6 ]]
+ case ${!OPTIND} in
+ vcword=cword
+ let 'OPTIND += 1'
+ [[ 6 -ge 7 ]]
+ __get_cword_at_cursor_by_ref '=<>&' words cword cur
+ words=()
+ local cword words
+ __reassemble_comp_words_by_ref '=<>&' words cword
+ local exclude i j line ref
+ [[ -n =<>& ]]
+ exclude='=<>&'
+ eval cword=3
++ cword=3
+ [[ -n =<>& ]]
+ line='cp -i ./file* ./file'
+ (( i=0, j=0 ))
+ (( i < 8 ))
+ [[ 0 -gt 0 ]]
+ ref='words[0]'
+ eval 'words[0]=${!ref}${COMP_WORDS[i]}'
++ words[0]=cp
+ line=' -i ./file* ./file'
+ [[ 0 == 3 ]]
+ (( i++, j++ ))
+ (( i < 8 ))
+ [[ 1 -gt 0 ]]
+ [[ -i == +([=<>&]) ]]
+ ref='words[1]'
+ eval 'words[1]=${!ref}${COMP_WORDS[i]}'
++ words[1]=-i
+ line=' ./file* ./file'
+ [[ 1 == 3 ]]
+ (( i++, j++ ))
+ (( i < 8 ))
+ [[ 2 -gt 0 ]]
+ [[ ./file1 == +([=<>&]) ]]
+ ref='words[2]'
+ eval 'words[2]=${!ref}${COMP_WORDS[i]}'
++ words[2]=./file1
+ line=' ./file* ./file'
+ [[ 2 == 3 ]]
+ (( i++, j++ ))
+ (( i < 8 ))
+ [[ 3 -gt 0 ]]
+ [[ ./file2 == +([=<>&]) ]]
+ ref='words[3]'
+ eval 'words[3]=${!ref}${COMP_WORDS[i]}'
++ words[3]=./file2
+ line=' ./file* ./file'
+ [[ 3 == 3 ]]
+ eval cword=3
++ cword=3
+ (( i++, j++ ))
+ (( i < 8 ))
+ [[ 4 -gt 0 ]]
+ [[ ./file3 == +([=<>&]) ]]
+ ref='words[4]'
+ eval 'words[4]=${!ref}${COMP_WORDS[i]}'
++ words[4]=./file3
+ line=' ./file* ./file'
+ [[ 4 == 3 ]]
+ (( i++, j++ ))
+ (( i < 8 ))
+ [[ 5 -gt 0 ]]
+ [[ ./file4 == +([=<>&]) ]]
+ ref='words[5]'
+ eval 'words[5]=${!ref}${COMP_WORDS[i]}'
++ words[5]=./file4
+ line=' ./file* ./file'
+ [[ 5 == 3 ]]
+ (( i++, j++ ))
+ (( i < 8 ))
+ [[ 6 -gt 0 ]]
+ [[ ./files == +([=<>&]) ]]
+ ref='words[6]'
+ eval 'words[6]=${!ref}${COMP_WORDS[i]}'
++ words[6]=./files
+ line=' ./file* ./file'
+ [[ 6 == 3 ]]
+ (( i++, j++ ))
+ (( i < 8 ))
+ [[ 7 -gt 0 ]]
+ [[ ./file == +([=<>&]) ]]
+ ref='words[7]'
+ eval 'words[7]=${!ref}${COMP_WORDS[i]}'
++ words[7]=./file
+ line='* ./file'
+ [[ 7 == 3 ]]
+ (( i++, j++ ))
+ (( i < 8 ))
+ [[ 8 == 3 ]]
+ local i cur index=20 'lead=cp -i ./file* ./file'
+ [[ 20 -gt 0 ]]
+ [[ -n cp -i ./file* ./file ]]
+ [[ -n cp-i./file*./file ]]
+ cur='cp -i ./file* ./file'
+ (( i = 0 ))
+ (( i <= cword ))
+ [[ 20 -ge 2 ]]
+ [[ cp != \c\p ]]
+ [[ 0 -lt 3 ]]
+ local old_size=20
+ cur=' -i ./file* ./file'
+ local new_size=18
+ index=18
+ (( ++i ))
+ (( i <= cword ))
+ [[ 18 -ge 2 ]]
+ [[ - != \-\i ]]
+ cur='-i ./file* ./file'
+ (( index-- ))
+ [[ 17 -ge 2 ]]
+ [[ -i != \-\i ]]
+ [[ 1 -lt 3 ]]
+ local old_size=17
+ cur=' ./file* ./file'
+ local new_size=15
+ index=15
+ (( ++i ))
+ (( i <= cword ))
+ [[ 15 -ge 7 ]]
+ [[ ./file != \.\/\f\i\l\e\1 ]]
+ cur='./file* ./file'
+ (( index-- ))
+ [[ 14 -ge 7 ]]
+ [[ ./file* != \.\/\f\i\l\e\1 ]]
+ cur='/file* ./file'
+ (( index-- ))
+ [[ 13 -ge 7 ]]
+ [[ /file* != \.\/\f\i\l\e\1 ]]
+ cur='file* ./file'
+ (( index-- ))
+ [[ 12 -ge 7 ]]
+ [[ file* . != \.\/\f\i\l\e\1 ]]
+ cur='ile* ./file'
+ (( index-- ))
+ [[ 11 -ge 7 ]]
+ [[ ile* ./ != \.\/\f\i\l\e\1 ]]
+ cur='le* ./file'
+ (( index-- ))
+ [[ 10 -ge 7 ]]
+ [[ le* ./f != \.\/\f\i\l\e\1 ]]
+ cur='e* ./file'
+ (( index-- ))
+ [[ 9 -ge 7 ]]
+ [[ e* ./fi != \.\/\f\i\l\e\1 ]]
+ cur='* ./file'
+ (( index-- ))
+ [[ 8 -ge 7 ]]
+ [[ * ./fil != \.\/\f\i\l\e\1 ]]
+ cur=' ./file'
+ (( index-- ))
+ [[ 7 -ge 7 ]]
+ [[ ./file != \.\/\f\i\l\e\1 ]]
+ cur=./file
+ (( index-- ))
+ [[ 6 -ge 7 ]]
+ [[ 2 -lt 3 ]]
+ local old_size=6
+ cur=./file
+ local new_size=6
+ index=6
+ (( ++i ))
+ (( i <= cword ))
+ [[ 6 -ge 7 ]]
+ [[ 3 -lt 3 ]]
+ (( ++i ))
+ (( i <= cword ))
+ [[ -n ./file ]]
+ [[ ! -n ./file ]]
+ [[ 6 -lt 0 ]]
+ local words cword cur
+ _upvars -a8 words cp -i ./file1 ./file2 ./file3 ./file4 ./files ./file -v cword 3 -v cur ./file
+ (( 16 ))
+ (( 16 ))
+ case $1 in
+ [[ -n 8 ]]
+ printf %d 8
+ [[ -n words ]]
+ unset -v words
+ eval 'words=("${@:3:8}")'
++ words=("${@:3:8}")
+ shift 10
+ (( 6 ))
+ case $1 in
+ [[ -n cword ]]
+ unset -v cword
+ eval 'cword="$3"'
++ cword=3
+ shift 3
+ (( 3 ))
+ case $1 in
+ [[ -n cur ]]
+ unset -v cur
+ eval 'cur="$3"'
++ cur=./file
+ shift 3
+ (( 0 ))
+ [[ -n cur ]]
+ upvars+=("$vcur")
+ upargs+=(-v $vcur "$cur")
+ [[ -n cword ]]
+ upvars+=("$vcword")
+ upargs+=(-v $vcword "$cword")
+ [[ -n prev ]]
+ [[ 3 -ge 1 ]]
+ upvars+=("$vprev")
+ upargs+=(-v $vprev "${words[cword - 1]}")
+ [[ -n words ]]
+ upvars+=("$vwords")
+ upargs+=(-a${#words[@]} $vwords "${words[@]}")
+ (( 4 ))
+ local cur cword prev words
+ _upvars -v cur ./file -v cword 3 -v prev ./file1 -a8 words cp -i ./file1 ./file2 ./file3 ./file4 ./files ./file
+ (( 19 ))
+ (( 19 ))
+ case $1 in
+ [[ -n cur ]]
+ unset -v cur
+ eval 'cur="$3"'
++ cur=./file
+ shift 3
+ (( 16 ))
+ case $1 in
+ [[ -n cword ]]
+ unset -v cword
+ eval 'cword="$3"'
++ cword=3
+ shift 3
+ (( 13 ))
+ case $1 in
+ [[ -n prev ]]
+ unset -v prev
+ eval 'prev="$3"'
++ prev=./file1
+ shift 3
+ (( 10 ))
+ case $1 in
+ [[ -n 8 ]]
+ printf %d 8
+ [[ -n words ]]
+ unset -v words
+ eval 'words=("${@:3:8}")'
++ words=("${@:3:8}")
+ shift 10
+ (( 0 ))
+ _variables
+ [[ ./file =~ ^(\$\{?)([A-Za-z0-9_]*)$ ]]
+ return 1
+ [[ ./file == @(?([0-9])<|?([0-9&])>?(>)|>&)* ]]
+ [[ ./file1 == @(?([0-9])<|?([0-9&])>?(>)|>&) ]]
+ local i skip
+ (( i=1 ))
+ (( i < 8 ))
+ [[ -i == @(?([0-9])<|?([0-9&])>?(>)|>&)* ]]
+ i=2
+ (( 1 ))
+ (( i < 8 ))
+ [[ ./file1 == @(?([0-9])<|?([0-9&])>?(>)|>&)* ]]
+ i=3
+ (( 1 ))
+ (( i < 8 ))
+ [[ ./file2 == @(?([0-9])<|?([0-9&])>?(>)|>&)* ]]
+ i=4
+ (( 1 ))
+ (( i < 8 ))
+ [[ ./file3 == @(?([0-9])<|?([0-9&])>?(>)|>&)* ]]
+ i=5
+ (( 1 ))
+ (( i < 8 ))
+ [[ ./file4 == @(?([0-9])<|?([0-9&])>?(>)|>&)* ]]
+ i=6
+ (( 1 ))
+ (( i < 8 ))
+ [[ ./files == @(?([0-9])<|?([0-9&])>?(>)|>&)* ]]
+ i=7
+ (( 1 ))
+ (( i < 8 ))
+ [[ ./file == @(?([0-9])<|?([0-9&])>?(>)|>&)* ]]
+ i=8
+ (( 1 ))
+ (( i < 8 ))
+ [[ 3 -le 0 ]]
+ prev=./file1
+ [[ -n false ]]
+ _split_longopt
+ [[ ./file == --?*=* ]]
+ return 1
+ return 0
+ case "${prev,,}" in
+ false
+ [[ ./file == -* ]]
+ [[ '' == @(mk|rm)dir ]]
+ _filedir
+ local i 'IFS=
' xspec
+ _tilde ./file
+ local result=0
+ [[ ./file == \~* ]]
+ return 0
+ local -a toks
+ local quoted x tmp
+ _quote_readline_by_ref ./file quoted
+ '[' -z ./file ']'
+ [[ ./file == \'* ]]
+ [[ ./file == \~* ]]
+ printf -v quoted %q ./file
+ [[ ./file == *\\* ]]
+ [[ ./file == \$* ]]
++ compgen -d -- ./file
+ x=./files
+ read -r tmp
+ toks+=("$tmp")
+ read -r tmp
+ [[ '' != -d ]]
+ xspec=
++ compgen -f -X '' -- ./file
+ x='./file2
./file3
./files
./file1
./file4'
+ read -r tmp
+ toks+=("$tmp")
+ read -r tmp
+ toks+=("$tmp")
+ read -r tmp
+ toks+=("$tmp")
+ read -r tmp
+ toks+=("$tmp")
+ read -r tmp
+ toks+=("$tmp")
+ read -r tmp
+ [[ -n '' ]]
+ [[ 6 -ne 0 ]]
+ compopt -o filenames
+ COMPREPLY+=("${toks[@]}")

END EDIT1-


I have not changed my /etc/inputrc or added an ~/.inputrc.

The package bash-completion is installed.

I have uncommented in my .bashrc the section that enables tab-completion quite a long time ago (it works well in all other instances and this problem I now have WAS working before).

It does not work in any of the terminals I have installed in my system (Ubuntu 14.04). And in case someone is thinking this, no it's not a valid solution to re-install Ubuntu. :)

7

1 Answer

The solution was to comment out a function I had added to my ~/.bashrc. The function was used to do some funky tab-completion regarding alias's. (Found it on the interwebs, I won't get into it here)

I used justsomeguy's suggestion to do env -i bash --noprofile --norc. And completions worked normally.

I then did env -i bash --norc -- completions still normal.

Then did env -i bash and the completions were failing again. So I concluded that the problem was in my ~/.bashrc and troubleshot from there.

Thanks for the help!

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like