Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Alias for subcommands



On Fri, Jun 18, 2021 at 11:14 PM Jörg Sommer <joerg@xxxxxxxx> wrote:
>
> would it be possible to have aliases for subcommands?

It's not really possible to have aliases for multiple-word constructs,
but you can create a function that "knows about" subcommands and then
alias the base command to pass through that function.

Very roughly (on the fly, certainly needs work, likely better naming):

use_subcommand_aliases() {
  local -a subcommand_expansion
  zstyle -a subcommand_alias:$1 $2 subcommand_expansion &&
    argv[2]=($subcommand_expansion)
  "$@"
}
alias restic="use_subcommand_aliases restic"
zstyle subcommand_alias:restic mount mount --allow-other
--no-default-permissions




Messages sorted by: Reverse Date, Date, Thread, Author