226 字
1 分钟

启用 Tab 补全

2025-03-13
无标签
浏览量 加载中...

启用 Tab 补全#

1、安装 bash-completion 软件包

Terminal window
sudo apt install bash-completion

2、修改 /etc/bash.bashrc 文件(需要root权限,全局)或 ~/.bashrc 文件

/etc/bash.bashrc
# enable bash completion in interactive shells
# if ! shopt -oq posix; then // [!code --]
# if [ -f /usr/share/bash-completion/bash_completion ]; then // [!code --]
# . /usr/share/bash-completion/bash_completion // [!code --]
# elif [ -f /etc/bash_completion ]; then // [!code --]
# . /etc/bash_completion // [!code --]
# fi // [!code --]
# fi // [!code --]
if ! shopt -oq posix; then // [!code ++]
if [ -f /usr/share/bash-completion/bash_completion ]; then // [!code ++]
. /usr/share/bash-completion/bash_completion // [!code ++]
elif [ -f /etc/bash_completion ]; then // [!code ++]
. /etc/bash_completion // [!code ++]
fi // [!code ++]
fi // [!code ++]
~/.bashrc
# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
# if [ -f /etc/bash_completion ] && ! shopt -oq posix; then // [!code --]
# . /etc/bash_completion // [!code --]
# fi // [!code --]
if [ -f /etc/bash_completion ] && ! shopt -oq posix; then // [!code ++]
. /etc/bash_completion // [!code ++]
fi // [!code ++]

3、最后 source 重载 /etc/bash.bashrc 文件或用户目录 .bashrc 文件

Terminal window
source /etc/bash.bashrc
source .bashrc
启用 Tab 补全
https://www.satxm.top/posts/tab-completion/
作者
Satxm
发布于
2025-03-13
许可协议
CC BY-NC-SA 4.0
最后更新于 2025-03-13,距今已过 274 天

部分内容可能已过时

评论区

目录