8

I have recently moved from Scientific Linux 6 to CentOS 7 and am having an issue with bash tab completion in the new OS.

Software Versions

$ cat /etc/redhat-release
CentOS Linux release 7.1.1503 (Core)

$ uname -r
3.10.0-229.14.1.el7.x86_64

$ bash --version
GNU bash, version 4.2.46(1)-release (x86_64-redhat-linux-gnu)

I have a bash script (executable) named ./run_prog.sh that takes a configuration file on the command line using the -c option (or long --config=).

Example of full command:

./run_prog.sh -c=./config/test-new-feature.conf
## or
./run_prog.sh --config=./config/test-new-feature.conf

In previous versions of bash i was able to tab complete directory and filenames after the -c= construct.

Example of expected tab complete (how it worked in SL6):

./run_prog.sh -c=./conf[TAB]
 ## completes to
./run_prog.sh -c=./config/
 ## then type
./run_prog.sh -c=./config/test-n[TAB]
 ## completes to
./run_prog.sh -c=./config/test-new-feature.conf

The new version of bash in CentOS 7 will not complete any filenames after the -c= short option.

Example of broken tab completion in CentOS 7:

./run_prog.sh -c=./conf[TAB]
 ## doesn't complete anything
./run_prog.sh -c=./conf

However if i separate the -c with a space the filename completion works as expected.

Example of working tab completion with space:

./run_prog.sh -c ./conf[TAB]
 ## completes to
./run_prog.sh -c ./config/
 ## then type
./run_prog.sh -c ./config/test-n[TAB]
 ## completes to
./run_prog.sh -c ./config/test-new-feature.conf

Question

How can i get the new version of bash to tab complete filenames like the old version of bash did?

Edit

This script has an long version for the short -c option that is --config. The long version doesn't work either.

./run_prog.sh --config=./conf[TAB]
 ## doesn't complete anything
./run_prog.sh --config=./conf

This makes me thing that bash is getting confused by the lack of spacing between the option switch (-c) and the option value.

My old bash-completion directory

$ ls -1 /media/old_hd/etc/bash_completion.d/
bzr
createrepo.bash
dkms
fcoeadm
fcoemon
gdbus-bash-completion.sh
git
gvfs-bash-completion.sh
lldpad
lldptool
perf
phoronix-test-suite
pk-completion.bash
rpmdevtools.bash-completion
subversion
yum.bash
yum-utils.bash

My new bash_completion directory

$ ls -1 /etc/bash_completion.d/
createrepo
dkms
fcoeadm
fcoemon
genpkgmetadata.py
git
lldpad
lldptool
mergerepo
mergerepo.py
modifyrepo
modifyrepo.py
redefine_filedir
scl.bash
yum
yummain.py
yum-utils.bash
nick
  • 513
  • 1
  • 8
  • 12
  • 1
    I don't have an answer to the question but I thought I'd mention that a short option that takes an `=` is fairly unusual. Normally short options either take a second argument or `-cValue` and long options take `--long-opt=Value` (or a second argument). – Etan Reisner Nov 10 '15 at 15:16
  • Have you tried to compare the bash completion versions/code between the two versions? – Etan Reisner Nov 10 '15 at 15:16
  • @EtanReisner I tried both -c./con[TAB] and --config=./con[TAB] and neither work. This makes me thing that it's bash getting confused by lack of space between the option switch and the value. I have updated the original question to reflect this. – nick Nov 10 '15 at 15:24
  • Oh, sure, my point wasn't that your choice of attempt was the problem. I was just pointing out that that is an unusual argument format to use/support/expect to work. Completion is absolutely at fault and is clearly not splitting on `=` the way you want it to be. That might be a generic completion issue or it might be that completion isn't tuned correctly for your script. I don't know. If you still have the SL machine you could check the active completions on there. – Etan Reisner Nov 10 '15 at 15:26
  • Added an ls of my old and new /etc/bash_completion.d. Hopefully that's what you meant by "active completions"? – nick Nov 11 '15 at 16:04

1 Answers1

9

After googling (and help from friends) i've found the solution!

To fix filename auto completion add the following to your ~/.bashrc file:

complete -D -o default

Reference: Bash completion for path in argument (with equals sign present)

Grisha Levit
  • 8,194
  • 2
  • 38
  • 53
nick
  • 513
  • 1
  • 8
  • 12