Bash选项卡在参数后完成文件名

时间:2015-11-10 14:45:20

标签: linux bash autocomplete centos7

我最近从Scientific Linux 6迁移到CentOS 7,并且在新操作系统中遇到bash tab完成问题。

软件版本

$ 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)

我有一个名为./run_prog.sh的bash脚本(可执行文件),它使用-c选项(或long -config =)在命令行中获取配置文件。

完整命令示例:

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

在以前版本的bash中,我能够在-c =构造之后标记完整的目录和文件名。

预期标签完成的示例(在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

CentOS 7中新版本的bash在-c = short选项后不会完成任何文件名。

CentOS 7中完成标签损坏的示例:

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

但是,如果我将-c与空格分开,则文件名完成按预期工作。

使用空格完成制表选项的示例:

./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呢?

修改

此脚本的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

1 个答案:

答案 0 :(得分:3)

谷歌搜索后(以及朋友的帮助)我找到了解决方案!

要修复文件名自动完成,请将以下内容添加到~/.bashrc文件中:

complete -D -o default

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

相关问题