I tried to write a bash-script for execute a command with a prefix ( "DRI_PRIME=1 glxspheres"
for example). 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. 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
$ 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:
$ 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).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.