-
Notifications
You must be signed in to change notification settings - Fork 9
/
lib.sh
executable file
·68 lines (56 loc) · 1.23 KB
/
lib.sh
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
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env bash
dotfiles_dir="$(dirname "$0")"
isFunction() { declare -F -- "$@" >/dev/null; }
path() {
mkdir -p "$(dirname "$1")"
echo "$(
cd "$(dirname "$1")" || exit
pwd
)/$(basename "$1")"
}
link() {
create_link "$dotfiles_dir/$1" "${HOME}/$1"
}
create_link() {
real_file="$(path "$1")"
link_file="$(path "$2")"
rm -rf "$link_file"
ln -s "$real_file" "$link_file"
echo "$real_file <-> $link_file"
}
gem_install_or_update() {
if gem list "$1" --installed >/dev/null; then
gem update "${@}"
else
gem install "${@}"
# rbenv rehash
fi
}
git_clone_or_update() {
if ! [ -x "$(command -v git)" ]; then
echo 'You need to install git!' >&2
exit 1
fi
echo ">>> $(basename "$2")"
if [ ! -d "${2}" ]; then
git clone "${1}" "${2}"
else
cd "${2}" || exit
git pull
cd "${INSTALLDIR}" || exit
fi
}
installPkgList() {
while IFS='' read -r PKG; do
[[ -z ${PKG} ]] && continue
[[ ${PKG} =~ ^#.*$ ]] && continue
[[ ${PKG} =~ ^\\s*$ ]] && continue
echo ">>> ${PKG}"
cmd=$(printf '%s %s' "${1}" "${PKG}")
eval "${cmd}"
done <"${2}"
cd "${INSTALLDIR}" || exit
}
getNerdFont() {
getFromRawGithub 'ryanoasis/nerd-fonts/' "patched-fonts/${1}" 'latest'
}