Bash Tab Completion of file names after arguments

I recently migrated from Scientific Linux 6 to CentOS 7 and I had a problem completing the bash tab on the new OS.

Software version

$ 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 file) with a name ./run_prog.shthat takes a configuration file on the command line using the -c option (or long --config =).

An example of a complete 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 managed to populate the full directory and file names after -c = construct.

An example of the expected tab is completed (how it works 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 on CentOS 7 will not populate file names after the -c = short option.

Example of ending a broken tab in CentOS 7:

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

However, if I separate -c with a space, the file shutdown works as expected.

An example of a working tab with a 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

bash , bash?

Edit

script short -c, --config. .

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

, bash - (-c) .

bash -

$ 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

bash_completion

$ 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
+4
1
+3

Source: https://habr.com/ru/post/1615261/


All Articles