shell-plugins
shell-plugins copied to clipboard
Use shell functions instead of aliases to avoid interfering with shell completion
op CLI version
2.24.0
Goal or desired behavior
I want to setup the homebrew shell plugin (as an example), and have shell completion work correctly for brew
, and also my custom shell alias (alias br=brew
).
This can be achieved by using a shell function in ~/.config/op/plugins.sh
instead of an alias:
brew() { op plugin run -- brew "$@"; }
Current behavior
Currently when you run op plugin init brew
, a shell alias is written to ~/.config/op/plugins.sh
, for example:
alias brew="op plugin run -- brew"
This results in the brew
command no longer having shell completions available on it, unless setopt completealiases
is used. But that breaks completion for shorthand aliases like alias br=brew
, because it will try to find completions for a command named br
.
Hence the shell function approach is the only one that works correctly in both scenarios.
Relevant log output
No response