I am using Centos 7 and bash. I know on some machines, if there is only one subfolder (and some files) in current folder, when you type cd <tab> it will auto-complete the name of the subfolder. However, it doesn't work on my machine, although <tab> can do other auto-completion on my machine, e.g., less ab<tab> will auto-complete the filename starting with ab. How can I fix it?
Edit:
Another working machine has same Centos and bash. On my machine, cd <tab> does nothing but a beep. For cd <tab><tab>, it shows all files and the single subfolder in current folder. The single folders on both machine are proper (command ls -ld the_single_folder shows drwxrwxr-x 2 user user ...).
Some shell options (output of command shopt) are different. The output of diff shoptA shoptB is (my machine is B):
18c18
< extglob on
---
> extglob off
27c27
< hostcomplete off
---
> hostcomplete on
42a43
> syslog_history off
I tried to change those different options (extglob and hostcomplete) on my machine using commands shopt -s extglob and shopt -u hostcomplete. But it didn't work
Command complete -p cd on that machine output complete -o nospace -F _cd cd, on my machine output -bash: complete: cd: no completion specification.
Command type _cd on that machine output:
_cd is a function
_cd ()
{
local cur prev words cword;
_init_completion || return;
local IFS='
' i j k;
compopt -o filenames;
if [[ -z "${CDPATH:-}" || "$cur" == ?(.)?(.)/* ]]; then
_filedir -d;
return 0;
fi;
local -r mark_dirs=$(_rl_enabled mark-directories && echo y);
local -r mark_symdirs=$(_rl_enabled mark-symlinked-directories && echo y);
for i in ${CDPATH//:/'
'};
do
k="${#COMPREPLY[@]}";
for j in $( compgen -d $i/$cur );
do
if [[ ( -n $mark_symdirs && -h $j || -n $mark_dirs && ! -h $j ) && ! -d ${j#$i/} ]]; then
j+="/";
fi;
COMPREPLY[k++]=${j#$i/};
done;
done;
_filedir -d;
if [[ ${#COMPREPLY[@]} -eq 1 ]]; then
i=${COMPREPLY[0]};
if [[ "$i" == "$cur" && $i != "*/" ]]; then
COMPREPLY[0]="${i}/";
fi;
fi;
return 0
}
<tab><tab>?echo $SHELLmight be a quick way of figuring out.<tab><tab>showed all files and that subfolder on my machine, as most machines do. On another machine, it has same bash and Centos as shown by commandsps -p $$andcat /etc/os-release. But it works well.cd <tab><tab>in the folder you're expectingcd <tab>to work (but where it doesn't work) lists exactly one folder? Or none?cdcome withbashor you need extra package(s) maybe.