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

Re: Command wrappers in $PATH, and re-executing the "correct" value



On 5/21/22, Roman Perepelitsa <roman.perepelitsa@xxxxxxxxx> wrote:
> On Sat, May 21, 2022 at 8:30 AM Zach Riggle <zachriggle@xxxxxxxxx> wrote:
>>
>> I find that very frequently I write a wrapper for some CLI tool, say
>> "foobar".
>>
>> I have a wrapper script ~/bin/foobar, which will be invoked for the
>> command "foobar".  What my wrapper script does is immaterial, but
>> it eventually executes the /usr/local/bin/foobar with some set of
>> arguments.
>
> You can try this:
>
>     #!/usr/bin/zsh
>     #
>     # usage: next-command <command> [arg]..
>
>     path=(${path:#${commands[$1]:h}}) "$@"

I'm using this in mine (wrapper script of same name as target binary),
path[(R)$0:h]=() exec $0:t "$@"

-- 
Mikael Magnusson




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