相关疑难解决方法(0)

创建 bash 完成脚本以在等号后自动完成路径?

我想创建一个 bash 完成脚本,它识别表单--arg--some-arg=file.

阅读本教程和 中的一些示例后/usr/share/bash_completion/completions/,我编写了以下脚本(以节省使用 Chromium 键入一些标志的时间):

_chromium() 
{
    local cur prev opts
    COMPREPLY=()
    cur="${COMP_WORDS[COMP_CWORD]}"
    prev="${COMP_WORDS[COMP_CWORD-1]}"

    # Some interesting options
    opts="
--disable-web-security
--easy-off-store-extension-install
--incognito
--load-extension=
--pack-extension=
--pack-extension-key=
--user-data-dir=
"
    # Handle --xxxxxx=file
    if [[ ${cur} == "--"*"=" ]] ; then
        # Removed failures (is my logic OK?)
        return 0
    fi

    # Handle other options
    if [[ ${cur} == -* ]] ; then
        COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
        return 0
    fi …
Run Code Online (Sandbox Code Playgroud)

bash chrome autocomplete

12
推荐指数
1
解决办法
5962
查看次数

标签 统计

autocomplete ×1

bash ×1

chrome ×1