forked from Daenyth/pkgtools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions
56 lines (47 loc) · 1.11 KB
/
functions
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/bin/bash
die () {
local ret=$1;
local warning="$2"; shift 2
warn "${warning:-Unknown error}" "$@"
quit ${ret:-1}
}
warn () {
local message="$1"; shift
printf "$message" "$@" 1>&2
}
quit () {
exit ${1:-0}
}
msg () {
local message="$1"
shift
printf "$message" $@
}
vmsg () {
[ $VERBOSE -ge 1 ] && msg "$@"
}
in_array() {
[ $# -lt 2 ] && return 1
needle=$1
shift
for item
do
[ "$item" = "$needle" ] && return 0
done
return 1
}
load_config() {
local conffile="$1"
if [[ -r $CONFIG_DIR/$conffile ]]; then
source "$CONFIG_DIR/$conffile"
fi
if [[ -r ${XDG_CONFIG_HOME}/pkgtools/$conffile ]]; then
source "${XDG_CONFIG_HOME}/pkgtools/$conffile"
elif [[ -r ${HOME}/.pkgtools/$conffile ]]; then
source "${HOME}/.pkgtools/$conffile"
warn 'Your %s is located in ~/.pkgtools. Pkgtools now uses $XDG_CONFIG_HOME.\n' "$conffile"
warn 'Make sure $XDG_CONFIG_DIR is set, then mv ~/.pkgtools into it\n'
warn ' mv ~/.pkgtools "$XDG_CONFIG_HOME/pkgtools"\n\n'
fi
}
# vim: set ts=4 sw=4 et: