What's the most efficient way to export the functions/aliases defined in my .zshrc to be used anywhere. For example in my .zshrc
_foo() {
echo "bar"
}
And then invoke _foo in any script.
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.
Sign up to join this communityAs suggested in one of the comments, you could put them in the file /etc/zshenv
. However, on many distributions, this file is supplied by the OS. Besides that, /etc/zshenv
is sourced every time your system runs a Zsh script, even when it's not from an interactive shell. Putting too many customizations in /etc/zshenv
has the potential to significantly slow down your system or even break things.
Instead, if your custom functions and aliases are meant for interactive usage only, it is generally wiser to put them into /etc/zshrc
, which is sourced only for interactive shells.
Documentation: http://zsh.sourceforge.net/Doc/Release/Files.html#Startup_002fShutdown-Files
zsh
follow the conventionbash
uses, whereby you could have a globalrc
file such as/etc/zshrc
?/etc/zshenv
may be what you're looking for.