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

Re: Best practices for managing aliases in ohmyzsh?



Hi Steve,

On 30.08.2021 20:13, Steve Dondley wrote:
I switched to zsh last week and learning the ropes. My .zshrc is quickly growing out of hand.

I basically went all-in on the Oh My Zsh approach and created my own theme and my own set of plugins. I basically have this:

orcus ~ [0:0]> \ls -d .oh-my-zsh.custom/*
.oh-my-zsh.custom/oh-my-zsh.custom.sh
.oh-my-zsh.custom/plugins
.oh-my-zsh.custom/themes
.oh-my-zsh.custom/tools

I have my own theme "mklemm" that defines the prompt style and the general behavior of my Zsh instances.

The plugins folder then has a few plugins that I wrote to easily absorb different machines (or where I create a "fork" of the original Zsh plugin for myself):

orcus ~ [0:0]> \ls -d .oh-my-zsh.custom/plugins/*
.oh-my-zsh.custom/plugins/anaconda
.oh-my-zsh.custom/plugins/autosuggestions
.oh-my-zsh.custom/plugins/conda-zsh-completion
.oh-my-zsh.custom/plugins/direnv
.oh-my-zsh.custom/plugins/extract
.oh-my-zsh.custom/plugins/fastfile
.oh-my-zsh.custom/plugins/fritzbox
.oh-my-zsh.custom/plugins/history-search-multi-word
.oh-my-zsh.custom/plugins/k
.oh-my-zsh.custom/plugins/mklemm
.oh-my-zsh.custom/plugins/slurm
.oh-my-zsh.custom/plugins/zsh-completions
.oh-my-zsh.custom/plugins/zsh-syntax-highlighting

In my .zshrc, I then have this:

if [[ -e "${HOME}/.myzshrc.local.zsh" ]]; then
    source "${HOME}/.myzshrc.local.zsh"
fi
export ZSH_CUSTOM="${HOME}/.oh-my-zsh.custom"
export ZSH_THEME="mklemm"

plugins=(
  autosuggestions
  colorize
  [...]
  $local_plugins
)

source $HOME/.oh-my-zsh.custom/oh-my-zsh.custom.sh
source $HOME/.oh-my-zsh/oh-my-zsh.sh

The way this works is that if there's a "${HOME}/.myzshrc.local.zsh" it is sourced and does some machine-specific adjustments that are not contained in the general .zshrc file. That local script can also set local_plugins to a list with plugins that I only want/need on that machine (e.g., a plugin to work with the SLURM job scheduler on an HPC system).


Now I'm wondering if there is some similar mechanism for adding aliases with ohmyzsh. 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?

Most aliases with Oh My Zsh are coming from plugins, so my mklemm plugin has an alias.sh file that defines that aliases that I want on top of those imported from all the plugins.


Kind regards,
        -michael



Attachment: smime.p7s
Description: S/MIME Cryptographic Signature



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