-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathshellexrc.in
38 lines (35 loc) · 1.1 KB
/
shellexrc.in
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# 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
# 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)
)
# 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 ) )
# source each file from the first of:
# 1. $XDG_CONFIG_HOME/.shellex (typically $HOME/.config/shellex)
# 2. $HOME/.shellex
# 3. @SYSCONFDIR@/shellex
for f in $uniquified
do
# -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 ]]
then
source $HOME/.shellex/$f
else
source @SYSCONFDIR@/shellex/$f
fi
done