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

Re: Best practices for managing aliases in ohmyzsh?

Yikes, I'm missing something fundamental.  In my head, executing a
script is identical to sourcing it.  It's not a binary, so what else
can there be than interpreting the file?  If a function is declared
(yes I know, wrong word but you get my meaning) then the function
enters memory, otherwise it's interpret-and-forget until next time,
no?  If 'chmod +x' then you don't hafta 'say' 'source me', it's
automatic, and it will be found if on the path, etc, but I'm laboring
under the idea that nothing else is different.  Is this going to
hurt?  I don't understand the lesson of Roman's example, so I think it
is going to hurt.

The way I think about it is sourcing is basically like including the body of the text that's in the sourced file into your configuration file (or whatever file is sourcing it). After everything is sourced, it all gets dumped into memory. Nothing is executed, unless, of course, you actually have a bit of code in your sourced files that runs some commands which will get executed during the sourcing process.

Scripts should not be sourced at all. Those have commands that will be executed. Roman is just saying to call those scripts directly. For example, I plan on calling them from aliases. His argument is that the hassle of setting up functions is too high and it's much easier just to use scripts which can use any programming language rather than having to be written in zsh. This also makes it much easier to switch to another shell.

I believe functions are not stored in memory until they are called at least once in zsh if they are loaded with "autoload." I could be entirely wrong on this so someone please tell me if I am.

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