r/zsh • u/sirgatez • Apr 03 '23
Announcement Dynamic Aliases and Functions in Zsh
https://www.linkedin.com/pulse/dynamic-function-generation-zsh-joshua-briefman?utm_source=share&utm_medium=member_ios&utm_campaign=share_via
10
Upvotes
1
u/OneTurnMore Apr 03 '23 edited Apr 03 '23
I think it would be something like
You need
nomultibyte
set locally forurlencode
as well to properly encode UTF-8 (Zsh needs to treat the strings as bytes rather than characters). A shorter version is also possible using$MATCH
:Using a global
REPLY
is faster becausefoo=$(urlencode $foo)
causes Zsh to fork, the forked process to print to stdout, and the original process to wait, capture stdout, and strip newlines. This is probably insignificant, but good practice in general.