-
Notifications
You must be signed in to change notification settings - Fork 1
/
install_font.sh
executable file
·136 lines (119 loc) · 3.47 KB
/
install_font.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#!/bin/sh
#############################################################
# Set development environment on Linux/macOS/Cygwin quickly.
# Author: Maririn312 <[email protected]>
# URL: https://github.com/maririn312/dotfiles
#############################################################
# Get OS name
SYSTEM=`uname -s`
# Use colors, but only if connected to a terminal, and that terminal
# supports them.
if command -v tput >/dev/null 2>&1; then
ncolors=$(tput colors)
fi
if [ -t 1 ] && [ -n "$ncolors" ] && [ "$ncolors" -ge 8 ]; then
RED="$(tput setaf 1)"
GREEN="$(tput setaf 2)"
YELLOW="$(tput setaf 3)"
BLUE="$(tput setaf 4)"
BOLD="$(tput bold)"
NORMAL="$(tput sgr0)"
else
RED=""
GREEN=""
YELLOW=""
BLUE=""
BOLD=""
NORMAL=""
fi
YES=0
NO=1
promote_yn() {
eval ${2}=$NO
read -p "$1 [y/N]: " yn
case $yn in
[Yy]* ) eval ${2}=$YES;;
[Nn]*|'' ) eval ${2}=$NO;;
*) eval ${2}=$NO;;
esac
}
# Sync repository
sync_repo() {
local repo_uri="$1"
local repo_path="$2"
local repo_branch="$3"
if [ -z "$repo_branch" ]; then
repo_branch="master"
fi
if [ ! -e "$repo_path" ]; then
mkdir -p "$repo_path"
git clone --depth 1 --branch $repo_branch "https://github.com/$repo_uri.git" "$repo_path"
else
cd "$repo_path" && git pull --rebase --stat origin $repo_branch; cd - >/dev/null
fi
}
function check {
if ! command -v git >/dev/null 2>&1; then
echo "${RED}Error: git is not installed${NORMAL}" >&2
exit 1
fi
if [ "$OSTYPE" = "cygwin" ]; then
echo "${RED}Error: Cygwin is not supported${NORMAL}" >&2
exit 1
fi
}
function install {
printf "${BLUE} ➜ Installing fonts...${NORMAL}\n"
if [ "$SYSTEM" = "Darwin" ]; then
# macOS
font_dir="$HOME/Library/Fonts"
fonts=(
# font-source-code-pro
# font-dejavu-sans
# font-inconsolata
font-cascadia-code
font-fira-code
font-hack-nerd-font
)
if [ ! -f "${font_dir}/SourceCodePro-Regular.otf" ]; then
for f in ${fonts[@]}; do
brew install ${f}
done
fi
brew cleanup
elif [ "$SYSTEM" = "Linux" ]; then
# Linux
font_dir="$HOME/.local/share/fonts"
mkdir -p $font_dir
# Source Code Pro
if [ ! -f "${font_dir}/SourceCodePro-Regular.otf" ]; then
sync_repo adobe-fonts/source-code-pro $font_dir/source-code-pro release
echo "Copying fonts..."
find "$font_dir/source-code-pro" \( -name "$prefix*.[ot]tf" -or -name "$prefix*.pcf.gz" \) -type f -print0 | xargs -0 -n1 -I % cp "%" "$font_dir/"
rm -rf $font_dir/source-code-pro
fc-cache -f $font_dir
fi
if command -v apt-get >/dev/null 2>&1; then
# Ubuntu/Debian
fonts=(
fonts-hack-ttf
fonts-powerline
fonts-wqy-microhei
fonts-wqy-zenhei
# ttf-mscorefonts-installer
)
for f in ${fonts[@]}; do
sudo apt-get upgrade -y ${f}
done
else
if [ ! -f "${font_dir}/Hack Regular Nerd Font Complete.ttf" ]; then
sh -c "$(curl -fsSL https://github.com/ryanoasis/nerd-fonts/raw/master/install.sh) Hack"
fi
fi
fi
}
function main {
check
install
}
main