-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathterminal_config.sh
executable file
·131 lines (122 loc) · 3.19 KB
/
terminal_config.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
#!/usr/bin/env bash
#> +----------------------+
#> | terminal-config.sh |
#> +----------------------+
#-
#- SYNOPSIS
#-
#- ./terminal-config.sh [-h]
#-
#- OPTIONS
#-
#- -y, all accept.
#- -h, --help print help information.
#-
#- EXAMPLES
#-
#- $ ./terminal-config.sh -y
#====================================================
# Part 1. Option Tool
#====================================================
# Print script help
function show_script_help(){
echo
head -17 $0 | # find this file top 16 lines.
grep "^#[-|>]" | # show the line that include "#-" or "#>".
sed -e "s/^#[-|>]*//1" # use nothing to replace "#-" or "#>" that the first keyword in every line.
echo
}
# Receive arguments in slient mode.
all_accept=0
if [ "$#" -gt 0 ]; then
while [ "$#" -gt 0 ]; do
case "$1" in
# Help
"-h"|"--help")
show_script_help
exit 1
;;
# All Accept
"-y")
all_accept=1
shift 1
;;
esac
done
fi
function Echo_Color(){
case $1 in
r* | R* )
COLOR='\033[0;31m'
;;
g* | G* )
COLOR='\033[0;32m'
;;
y* | Y* )
COLOR='\033[0;33m'
;;
b* | B* )
COLOR='\033[0;34m'
;;
*)
echo "$COLOR Wrong COLOR keyword!\033[0m"
;;
esac
echo -e "$COLOR$2\033[0m"
}
function Ask_yn(){
printf "\033[0;33m$1\033[0m\033[0;33m [y/n] \033[0m"
if [ $all_accept = 1 ]; then
echo '-y'
return 1
fi
read respond
if [ "$respond" = "y" -o "$respond" = "Y" -o "$respond" = "" ]; then
return 1
elif [ "$respond" = "n" -o "$respond" = "N" ]; then
return 0
else
Echo_Color r 'wrong command!!'
Ask_yn $1
return $?
fi
unset respond
}
#====================================================
# Part 2. Main
#====================================================
# terminal theme setting
Ask_yn "Do you want to use customized terminal theme setting?"; result=$? # get Ask_yn()
if [ $result = 1 ]; then
sudo mkdir ~/.local/share/fonts
sudo cp ./ttf/*ttf ~/.local/share/fonts
fc-cache -f -v
dconf load /org/gnome/terminal/ < ./config/gnome_terminal_settings_backup.txt
fi
Ask_yn "Do you want to set English be your default language for terminal?"; result=$? # get Ask_yn()
if [ $result = 1 ]; then
case $SHELL in
*zsh )
profile=~/.zshrc
;;
*bash )
profile=~/.bashrc
;;
*ksh )
profile=~/.profile
;;
* )
Echo_Color r "Unknow shell, need to manually add 'export LANG=C.UTF-8' on your shell profile!!"
;;
esac
if grep -n "^export LANG*" $profile; then
Echo_Color y "You were already config LANG before, if you still want to config it, please manually edit $profile."
else
printf "\n#Setting English for terminal\nexport LANG=C.UTF-8\n" >> $profile
Echo_Color g "Done config!!"
if [[ $SHELL == *bash ]]; then
source $profile
fi
fi
fi
Echo_Color g "Done!! $0"