shellexrc.in 1.1 KB
Newer Older
1 2 3 4 5 6 7
# vim:ft=zsh
# Source all conf files
# © 2016 Paul Seyfert and contributors (see also: LICENSE)

# get array of all relevant files
# http://stackoverflow.com/a/10981499
# http://unix.stackexchange.com/a/26825
Paul Seyfert's avatar
Paul Seyfert committed
8 9 10 11 12 13 14 15 16
# parentheses after * steer zsh's globbing
#  . means "only regular files"
#  -. means "regular files and symlinks pointing to regular files"
#  N means "empty list in case of no matches"
thefiles=(
  @SYSCONFDIR@/shellex/*
  ${XDG_CONFIG_HOME:-$HOME/.config}/shellex/*(-.N)
  $HOME/.shellex/*(-.N)
)
17 18 19 20 21

# get the basenames of all files and make unique list
# http://stackoverflow.com/a/9516801
uniquified=( $( for f in "${thefiles[@]}" ; do basename $f ; done | sort -u ) )

Paul Seyfert's avatar
Paul Seyfert committed
22 23 24 25
# source each file from the first of:
# 1. $XDG_CONFIG_HOME/.shellex (typically $HOME/.config/shellex)
# 2. $HOME/.shellex
# 3. @SYSCONFDIR@/shellex
26 27
for f in $uniquified
do
Paul Seyfert's avatar
Paul Seyfert committed
28 29 30 31 32
  # -r checks if file exists and is readable
  if [[ -r ${XDG_CONFIG_HOME:-$HOME/.config}/shellex/$f ]]
  then
    source $HOME/.config/shellex/$f
  elif [[ -r $HOME/.shellex/$f ]]
33 34 35 36 37 38
  then
    source $HOME/.shellex/$f
  else
    source @SYSCONFDIR@/shellex/$f
  fi
done