如何在 Google Compute Engine 上启用 bash 完成?

如何在 Google Compute Engine 上启用 bash 完成?

我运行的计算实例是 Debian Buster。通常情况下,它存在一个/etc/bash_completion文件。但是对于 GCE,它缺失了。他们甚至在默认设置中添加了一个部分~/.bashrc来引用 bash 完成文件,但这些文件都不存在。

if ! shopt -oq posix; then
  if [ -f /usr/share/bash-completion/bash_completion ]; then
    . /usr/share/bash-completion/bash_completion
  elif [ -f /etc/bash_completion ]; then
    . /etc/bash_completion
  fi
fi

答案1

你是对的,它不是默认安装的,我在自己的项目中尝试创建一个新的 Debian Buster VM 实例,但/etc/bash_completion不存在。

/etc$ ls -l bash_completion
ls: cannot access 'bash_completion': No such file or directory

只有在安装 bash-completion 后,该 /etc/bash_completion文件才会出现。

sudo apt-get install bash-completion
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following NEW packages will be installed:
  bash-completion
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 208 kB of archives.
After this operation, 1397 kB of additional disk space will be used.
Get:1 http://deb.debian.org/debian buster/main amd64 bash-completion all 1:2.8-6 [208 kB]
Fetched 208 kB in 0s (960 kB/s)     
Selecting previously unselected package bash-completion.
(Reading database ... 37801 files and directories currently installed.)
Preparing to unpack .../bash-completion_1%3a2.8-6_all.deb ...
Unpacking bash-completion (1:2.8-6) ...
Setting up bash-completion (1:2.8-6) ...
Processing triggers for man-db (2.8.5-2) ...

安装后:

/etc$ ls -l bash_completion
-rw-r--r-- 1 root root 45 Feb 11  2019 bash_completion

相关内容