I am currently working on a path shortcut manager CLI, which enables users to abbreviate paths with short labels. To make those labels easy to use, I wanted my custom bash commands to autocomplete the labels by pressing tab. This is the broad structure of my solution:
function _custom_command(){
# load labels into COMPREPLY
}
complete -F _custom_command custom_command
Currently, my completion function loads every single existing label into COMPREPLY
, which means that those should get matched for tab completion.
Given this situation, the tab completion does not work properly.
Even though I am typing a prefix of a label as the first argument of my custom command, it never does get matched / replaced by the label.
This behaviour can be reproduced by the following simple code:
function hello(){
echo "hello"
}
function _hello(){
COMPREPLY=("hey")
COMPREPLY+=("cool")
}
complete -F _hello hello
This seems to be the root of the problem, as adding two strings to COMPREPLY leads to the same behaviour specified above.
E.g.:
$hello c[Tab]
cool hey
Am I missing any options / specification of complete
or is my usage of this command faulty?
Also feel free to leave any feedback on this question, as is it my first.
Thank you :)