aboutsummarylogtreecommitdiffstats
path: root/nerdfonts_installer.sh
blob: e82bbdfa4ecaf3fe32780d68f12cc10afb750637 (plain)
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#!/usr/bin/sh

# Function to detect the OS and set the package manager
detect_os_and_set_package_manager() {
    if [ -f /etc/os-release ]; then
        . /etc/os-release
        case "$ID" in
            ubuntu|debian)
                PKG_MANAGER="sudo apt-get update && sudo apt-get install -y"
                ;;
            fedora)
                PKG_MANAGER="sudo dnf install -y"
                ;;
            centos|rhel)
                PKG_MANAGER="sudo yum install -y"
                ;;
            arch)
                PKG_MANAGER="sudo pacman -Syu --noconfirm"
                ;;
            *)
                printf "%b\n" '\033[0;31mUnsupported OS: '"$ID"'\033[0m'  
                exit 1
                ;;
        esac
    else
        printf "%b\n" '\033[0;31mOS detection failed. Please install curl, tar, and fontconfig manually.\033[0m'  
        exit 1
    fi
}

# Function to check and install dependencies
install_dependencies() {
    if ! command -v curl >/dev/null 2>&1; then
        printf "%b\n" '\033[0;33mcurl not found. Installing curl...\033[0m'  
        $PKG_MANAGER curl
    fi

    if ! command -v tar >/dev/null 2>&1; then
        printf "%b\n" '\033[0;33mtar not found. Installing tar...\033[0m'  
        $PKG_MANAGER tar
    fi

    if ! command -v fc-cache >/dev/null 2>&1; then
        printf "%b\n" '\033[0;33mfontconfig (fc-cache) not found. Installing fontconfig...\033[0m'  
        $PKG_MANAGER fontconfig
    fi
}

# Detect OS and set package manager
detect_os_and_set_package_manager

# Check and install dependencies
install_dependencies

# Create directory for fonts
mkdir -p "$HOME/.local/share/fonts"

# Create tmp directory if it doesn't exist
mkdir -p "$HOME/tmp"

# List of available fonts
fonts="
0xProto Nerd Font
3270 Nerd Font
Agave Nerd Font
AnonymicePro Nerd Font
Arimo Nerd Font
AurulentSansMono Nerd Font
BigBlueTerminal Nerd Font
BitstromWera Nerd Font
BlexMono Nerd Font
CaskaydiaCove Nerd Font
CaskaydiaMono Nerd Font
CodeNewRoman Nerd Font
ComicShannsMono Nerd Font
CommitMono Nerd Font
Cousine Nerd Font
D2Coding Nerd Font
DaddyTimeMono Nerd Font
DejaVuSansMono Nerd Font
DroidSansMono Nerd Font
EnvyCodeR Nerd Font
FantasqueSansMono Nerd Font
FiraCode Nerd Font
FiraMono Nerd Font
GeistMono Nerd Font
GoMono Nerd Font
Gohu Nerd Font
Hack Nerd Font
Hasklug Nerd Font
HeavyDataMono Nerd Font
Hurmit Nerd Font
iM-Writing Nerd Font
Inconsolata Nerd Font
InconsolataGo Nerd Font
InconsolataLGC Nerd Font
IntoneMono Nerd Font
Iosevka Nerd Font
IosevkaTerm Nerd Font
IosevkaTermSlab Nerd Font
JetBrainsMono Nerd Font
Lekton Nerd Font
Literation Nerd Font
Lilex Nerd Font
MartianMono Nerd Font
Meslo Nerd Font
Monaspice Nerd Font
Monofur Nerd Font
Monoid Nerd Font
Mononoki Nerd Font
M+ Nerd Font
Noto Nerd Font
OpenDyslexic Nerd Font
Overpass Nerd Font
ProFont Nerd Font
ProggyClean Nerd Font
RecMono Nerd Font
RobotoMono Nerd Font
SauceCodePro Nerd Font
ShureTechMono Nerd Font
SpaceMono Nerd Font
Terminess Nerd Font
Tinos Nerd Font
Ubuntu Nerd Font
UbuntuMono Nerd Font
VictorMono Nerd Font
ZedMono Nerd Font
"

# Format the font list into three columns
format_fonts_into_columns() {
    printf "%b\n" "$fonts" | nl | awk '{printf "%-40s", $0; if (NR%3==0) printf "\n"} END {if (NR%3!=0) printf "\n"}'
}

# Display menu of available fonts in three columns with 'more'
printf "%b\n" '\033[0;32mSelect fonts to install (separate with spaces):\033[0m'  
printf "%b\n" "---------------------------------------------"
format_fonts_into_columns | more  # Use 'more' to paginate font list in three columns
printf "%b\n" "---------------------------------------------"

# Prompt user to select fonts and validate input
while true; do
    printf "%b\n" '\033[0;36mEnter the numbers of the fonts to install (e.g., "1 2 3"): \033[0m'  
    read -r font_selection

    # Check if user has made a selection
    if [ -n "$font_selection" ]; then
        break  # Exit loop if input is not empty
    else
        printf "%b\n" '\033[0;31mPlease select at least one font.\033[0m'  
    fi
done

# Download and install selected fonts
for selection in $font_selection; do
    font=$(printf "%b\n" "$fonts" | sed -n "${selection}p")  # Extract font based on user selection
    if [ -z "$font" ]; then
        printf "%b\n" '\033[0;31mInvalid selection: '"$selection"'\033[0m'  
        continue
    fi
    printf "%b\n" '\033[0;34mDownloading and installing '"$font"'\033[0m'  
    font_name=$(printf "%b\n" "$font" | awk '{print $1}')
    curl -sSLo "$HOME/tmp/$font_name.tar.xz" "https://github.com/ryanoasis/nerd-fonts/releases/latest/download/$font_name.tar.xz"
    tar -xf "$HOME/tmp/$font_name.tar.xz" -C "$HOME/.local/share/fonts"
    rm "$HOME/tmp/$font_name.tar.xz"
done

# Update font cache
fc-cache -vf