I have been using bash for years and would like to stay with it. But at the same time, there are utilities in zsh that are nice to use. Are there ports so those commands like zmv, zcalc or zparseopts live as individual /bin executables? Or I have to use tricks like this?
1 Answer
The strength of zsh's zmv resides in zsh's immensely superior globbing and parameter expansion operators. A similar bmv that would be limited to bash's globbing and parameter expansion operators would be nowhere as useful as zsh's zmv.
And if you had a zmv for bash that was using zsh-like operators, you'd still have to learn those, and would then be frustrated when using bash where you could not use those advanced operators for the rest.
In any case, you can always do the latter in bash with:
zmv() { zsh -c 'autoload zmv && zmv "$@"' zmv "$@" } zcalc() { zsh -c 'autoload zcalc && zcalc "$@"' zcalc "$@" } Which define zmv and zcalc as functions that run the corresponding zsh function within a new invocation of the zsh interpreter.
Note however that it's limited in that those functions don't have access to the internal variables of your bash shell obviously.
For instance, if you do pi = 4 * atan(1) in that zcalc, that $pi variable won't be available in your bash shell afterwards.
For that same reason, taking that approach for zparseopts would be completely useless.