-
Notifications
You must be signed in to change notification settings - Fork 0
/
fonts.sh
executable file
·88 lines (71 loc) · 1.52 KB
/
fonts.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/bin/bash
declare -a homebrew_fonts=(
font-geist-mono
font-geist-mono-nerd-font
font-roboto-mono-nerd-font
)
declare -a github_fonts=(
RobotMono
GeistMono
)
cmd_exists() {
command -v "$1" >/dev/null 2>&1 && return 0
return 1
}
check=0
fonts_dir="$HOME/.local/share/fonts"
while true; do
case "$1" in
-c | --check)
check=1
;;
-d | --dir)
shift
fonts_dir="$1"
;;
"")
break
;;
esac
shift
done
run_cmd() {
[ "$check" = 1 ] && exit 1
echo ""
echo "$1"
if ! eval "$1"; then exit 1; fi
}
if cmd_exists "brew"; then
if ! brew tap | grep 'bramstein/webfonttools' >/dev/null 2>&1; then
run_cmd "brew tap bramstein/webfonttools"
fi
for font in "${homebrew_fonts[@]}"; do
if brew info "$font" | grep "Not installed" >/dev/null 2>&1; then
run_cmd "brew install $font"
fi
done
else
changed=0
for font in "${github_fonts[@]}"; do
if fc-list | grep "$font" >/dev/null 2>&1; then
continue
fi
[ "$check" = 1 ] && exit 1
zip="$font.zip"
url="https://github.com/ryanoasis/nerd-fonts/releases/latest/download/$zip"
if [[ ! -d "$fonts_dir" ]]; then
if ! mkdir -p "$fonts_dir"; then exit 1; fi
fi
echo "Downloading $url"
if ! wget "$url"; then exit 1; fi
echo "Unzipping $font"
if ! unzip "$zip" -d "$fonts_dir"; then exit 1; fi
if ! rm "$zip"; then exit 1; fi
changed=1
done
if [ "$changed" = 1 ]; then
if ! fc-cache -fv; then exit 1; fi
fi
fi
echo ""
echo "All fonts downloaded successfully"