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

Re: Best practices for managing aliases in ohmyzsh?



On Mon, Aug 30, 2021, at 7:22 PM, Steve Dondley wrote:
> >> Now I'm wondering if there is some similar mechanism for adding 
> >> aliases with ohmyzsh.

Note that oh-my-zsh is a separate project that is not affiliated
with this one.  There might be someone on this list who is familiar
with how it works, but it's hardly a guarantee.

> >> If not, what's everyone else doing who has a 
> >> couple hundred aliases. Are you just throwing them all into .zshrc or 
> >> doing something to help manage all your aliases?
> 
> > I'm the least qualified guy on the list, but I can tell you that you
> > can take advantage of all the built in complexities that zsh offers or
> > you can make it as dead simple as you desire.  

I don't use any aliases, and only a couple of functions.  But, as
Ray said, you can organize things however you like.  One rudimentary
method is to just separate your alias definitions into their own
file and source it from $ZDOTDIR/.zshrc:

    ### $ZDOTDIR/zsh_aliases ###
    alias foo='one thing'
    alias bar='another thing'

    ### $ZDOTDIR/.zshrc ###
    . $ZDOTDIR/zsh_aliases

Going further, you could use multiple files, organize them in a
directory hierarchy, etc.

> Yes, I spent about 2 hours today figuring out how to get my old bash 
> functions automatically loaded. Previously, I was just using 'source' to 
> load the old bash files which, from what I gathered, is not the best way 
> with zsh.

In general, zsh will not run bash code 100% correctly unless it is
written *extremely* portably.  Your old functions almost certainly
need to be tweaked to one degree or another.

> Now you've got me wondering. While I was bumbling around today, I 
> noticed I had an ~/.oh-my-zsh/.zshrc file. I'm only using the ~/.zshrc 
> file, though. It has just one line: 
> ZSH_THEME="powerlevel9k/powerlevel9k". I'm guessing that's the default 
> because I don't remember editing it.

I don't use any zsh configuration frameworks, but in my experience
they don't love it when you work with one foot inside their black
box and the other outside of it.

> So what is the "real" .zszhrc supposed to be?

Whatever you want it to be.  The distribution usually includes the
"zsh-newuser-install" function, which is intended to interactively
guide you through creating a .zshrc file.

https://zsh.sourceforge.io/Doc/Release/User-Contributions.html#User-Configuration-Functions


-- 
vq




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