小编bep*_*ter的帖子

bash 脚本可以包含自己的自动完成吗?

有许多可用资源(123)解释了如何利用 bash 自动完成命令和参数的能力,但所有这些资源都需要向用户添加代码,~/.bash_profile或者/etc/bash_completion.d/*有没有办法使一个脚本及其可用的完成是独立的?作为一个粗略和不完整的例子:

~/bin/script-with-integrated-autocomplete.sh

#!/usr/bin/env bash

function _completions {
  complete ...
}

if [ "$1" == "completions" ]; then
  _completions
  exit 0
fi

# (Whatever the script really does goes here.)
# ...
# ...
Run Code Online (Sandbox Code Playgroud)

交易破坏者(在这个问题的上下文中)是上面的例子仍然需要你添加类似的东西~/bin/script-with-integrated-autocomplete.sh completions.profile完成。

有没有办法让单个 bash 脚本(文件)声明自己的完成并让 bash在调用时识别它们(理想情况下没有额外的系统或环境设置)?

bash autocomplete compgen

5
推荐指数
1
解决办法
654
查看次数

标签 统计

autocomplete ×1

bash ×1

compgen ×1