bash - 如何不使用 bash 中的波浪号和制表符完成来解决所有用户
问题描述
要进入我的主文件夹的某个子文件夹,我键入cd ~/sub[tab]
. 这样就完成了cd ~/subfolder
。一切安好。
如果我不小心忘记了斜线并键入cd ~sub[tab]
所有用户,则将搜索匹配项。这需要一些时间,因为在我们公司,我们有一个中央用户服务器和很多用户。
我可以关闭所有用户的解析,但仍然使用波浪号~
吗?
我使用 bash 版本 4.3.0。
我永远不需要通过cd ~someUser
.
解决方案
打开文件/usr/share/bash-completion/bash_completion
并找到函数tilde()
(在第 941 行附近)。在这里,只需注释掉行号946
。最后,该函数应如下所示:
# Perform tilde (~) completion
# @return True (0) if completion needs further processing,
# False (> 0) if tilde is followed by a valid username, completions
# are put in COMPREPLY and no further processing is necessary.
_tilde()
{
local result=0
if [[ $1 == \~* && $1 != */* ]]; then
# Try generate ~username completions
#COMPREPLY=( $( compgen -P '~' -u "${1#\~}" ) )
result=${#COMPREPLY[@]}
# 2>/dev/null for direct invocation, e.g. in the _tilde unit test
[[ $result -gt 0 ]] && compopt -o filenames 2>/dev/null
fi
return $result
}
试试看。
推荐阅读
- c++ - 在 C++14 中初始化唯一指针向量的正确方法
- jquery - 像电视频道一样连续播放视频列表
- swift - 按照数学数学规则对值进行四舍五入
- postgresql - 使用非唯一键的 Postgres 分页?
- c# - DAO 的类级错误处理程序
- android - 使用 Google Nearby Connection 的多点连接
- ios - MapKit:集群未调用 calloutAccessoryControlTapped
- html - 默认情况下在 Select 中未选择任何内容 - 如何解决此问题?
- c - 是否有一个静态 C 分析器可以检测未初始化的静态变量?
- python - 使用 Django 运行 bash 脚本