I'm looking for a way to hook in a custom bash completion function. Problem is, I want this completion function not just for a specific command, but for all commands.
Is this even possible? Having looked around for a while, I couldn't find any resources online.
To reduce the problem to the most trivial case: would it be possible to always have tab-completion for the string 'foo'?
Meaning echo f<tab>
would expand into echo foo
, and ls fo<tab>
would expand into ls foo
For context: I'm trying to implement something similar to http://blog.plenz.com/2012-01/zsh-complete-words-from-tmux-pane.html in bash, but I'm starting to fear it's not possible.
You can do that with the -D
option of the complete
command:
suggest_hello()
{
COMPREPLY=( hello )
return 0
}
complete -D -F suggest_hello
Now whenever I type echo h<Tab>
, I get echo hello
.
$ help complete
complete: ...
...
-D apply the completions and actions as the default for commands
without any specific completion defined
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With