I find that very frequently I write a wrapper for some CLI tool, say "foobar".
Let's say lives at e.g. /usr/local/bin/foobar, and $path is ( ... ~/bin ... /usr/local/bin ).
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.
As best I can tell, there are three ways to make this work neatly:
- Implement "my" foobar as a function, and use "command foobar"
- How do I make this an autoloadable module, which doesn't need to use e.g.
"autoload foobar && foobar"
- Remove ~/bin from $path, and add it to the end
- This might break other things where system binaries take over
- Some cool tricks with /usr/bin/env and such I haven't thought of
I've already adopted autoloadable functions via $fpath and using "command foobar" inside the function, but I was curious if there's another way. I expect that removing ${0:h} and ${0:A:h} from $path are the most obvious answers, but I didn't know if there's anything easier.