简体   繁体   English

自动完成多个目录中的文件

[英]Autocomplete files across multiple directories

I tried to write a bash-script for execute a command with a prefix ( "DRI_PRIME=1 glxspheres" for example). 我试图编写一个bash脚本来执行带有前缀的命令(例如, "DRI_PRIME=1 glxspheres" )。 This is my current script: 这是我当前的脚本:

#!/bin/bash

_graphic() {
    export IFS=":"
    PATHCONTENT=()
    for CONTENTPATH in $PATH; do
            PATHCONTENT+=$(ls $CONTENTPATH)
    done
    COMPREPLY=$PATHCONTENT;
}

complete -F _graphic graphic

DRI_PRIME=1 "$@"

But this script doesnt autocomplete the folders in the $PATH-variable. 但是此脚本不会自动完成$ PATH变量中的文件夹。 What is wrong with this? 这有什么问题?

I'm not 100% sure what the question is, but it seems that you want to have a way of telling 我不确定100%的问题是什么,但似乎您想使用一种方法

$ graphic my_app param blah

and it will actually run 它实际上会运行

$ DRI_PRIME=1 my_app param blah

If that is so, it's rather easy, bash itself does that for you: 如果是这样,那很简单,bash本身会为您做到这一点:

$ cat a.sh
function graphic {
        DRI_PRIME=1 "$@"
}

complete -A command graphic

complete -A command makes bash to suggest command names (you used complete -F _graphic which makes bash call function to obtain possible completions). complete -A命令使bash给出命令名称的建议(您使用了complete -F _graphic ,它使bash调用函数来获得可能的补全)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM