forked from getnf/getnf
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathapplynf
64 lines (53 loc) · 2.22 KB
/
applynf
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
#!/bin/bash
# Function to apply font on Termux
termux() {
cd $FONT_DIR || { echo "${RED}Failed to access font directory.${RESET}"; exit 1; }
# Function to list and arrange files
arrange_files() {
# Check if any .ttf files exist
if ls *.ttf 1>/dev/null 2>&1; then
# List only .ttf files if they exist
files=(*.ttf)
else
# Otherwise, list all files
files=(*)
fi
# List the files numerically
echo "${BLUE}List of Installed Fonts:${RESET}"
for i in "${!files[@]}"; do
echo "${BLUE}$((i+1)). ${files[$i]}${RESET}"
done
}
# Activate the function to list files
arrange_files
# Function to select and apply a font file
select_file() {
# Prompt the user to select a file
read -p "${BLUE}Enter the number of the file:${RESET} " choice
# Validate the user input
if [[ $choice =~ ^[0-9]+$ ]] && [ $choice -ge 1 ] && [ $choice -le ${#files[@]} ]; then
selected_file="${files[$((choice-1))]}"
# Check if the selected file is a directory
if [ -d "$selected_file" ]; then
cd "$selected_file" || { echo "${RED}Failed to enter directory $selected_file${RESET}"; exit 1; }
arrange_files # Arrange files in the selected directory
select_file # Prompt the user to select a file again
else
# Copy the selected file to Termux's font directory
cp "$selected_file" "$HOME/.termux/font.ttf" || { echo "${RED}Failed to apply font${RESET}"; exit 1; }
# Reload Termux settings
echo " ${BLUE}[${RED}*${BLUE}] ${BLUE}Reloading Settings..."
am broadcast --user 0 -a com.termux.app.reload_style com.termux > /dev/null
echo " ${BLUE}[${RED}*${BLUE}] ${GREEN}Applied Successfully.${RESET}"
echo
fi
else
echo "${RED}Invalid choice. Please enter a valid number.${RESET}"
select_file # Prompt again for a valid input
fi
}
# Activate the function to select a file
select_file
}
# Call the main function to start the process
termux