Source of multiple wildcard .zshrc files

I use the z shell through "oh my zsh". I would like to load several alias files from my .zshrc file so that I can keep everything well organized. I prefix the alias files with .alias_so that I can load them. But the call source ~/.alias_*only downloads the first file. How can I download script source files?

Examples of file names: .alias_git, .alias_local, .alias_server...

+5
source share
2 answers

Option 1

You can use the for loop:

for file in ~/.alias_*; do
    source "$file"
done

Option 2

Another option is to build an array of all the files you want to use, and then iterate over the array using a for loop.

typeset -a aliases

aliases+="~/.alias_foo"
aliases+="~/.aliases_bar"
# etc...

for file in $aliases[@]; do
    if [[ -a "$file" ]]; then
        source "$file"
    fi
done

zshrc.

+3

ZSH- ( setopt EXTENDED_GLOB):

alias_src=(
.alias_git
.alias_local
.alias_server
)
for f ($^alias_src(.N)) source $f
unset alias_src

^ glob .

(.N) :

  • .:
  • N: setopt NULL_GLOB, , , ,
+2

All Articles