-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhuiyin.sh
executable file
·162 lines (131 loc) · 3.99 KB
/
huiyin.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
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
#!/bin/bash
source ~/Repositories/scripts/essential-functions
# generates current-theme in $usdd and symlinks program theme files
dir="$HOME/Repositories/dotfiles/themes"
thf="$usdd/current-theme"
function choose {
for j in $(esa "$dir"/*yaml)
do
cat "$j" | yq -r '.theme_name'
done | fzf --prompt 'choose theme: '
}
function generate {
theme_name="$(choose)"
theme_file="$(grep -l "theme_name: $theme_name$" "$dir/"*"yaml")"
[[ -z "$theme_name" ]] && exit
function extract {
cat "$theme_file" | yq -r "$1"
}
echolor green ":: Generating current-theme file..."
cat <<-EOF > "$thf"
#!/bin/bash
export lin_theme="$(extract '.theme_name')"
export lin_color1="$(extract '.colors.color1.hex')"
export lin_color2="$(extract '.colors.color2.hex')"
export lin_color3="$(extract '.colors.color3.hex')"
export lin_color4="$(extract '.colors.color4.hex')"
export lin_wallpaper="$(eval echo $(extract '.wallpaper.path'))"
EOF
echolor green ":: current-theme file generated!"
rofi_file="$(eval echo $(extract '.files.rofi'))"
polybar_file="$(eval echo $(extract '.files.polybar'))"
dunst_file="$(eval echo $(extract '.files.dunst'))"
if [[ ! -e "$rofi_file" ]] || [[ ! -e "$polybar_file" ]] || [[ ! -e "$dunst_file" ]]
then
echolor red ":: Unable to symlink. Exiting."
exit 1
fi
ln -sf "$rofi_file" "$HOME/.config/rofi/current-theme.rasi"
ln -sf "$polybar_file" "$HOME/.config/polybar/current-theme.ini"
ln -sf "$dunst_file" "$HOME/.config/dunst/dunstrc"
bspc wm -r
killall dunst
}
function create {
[[ -z "$1" ]] && {
echolor red ":: Please input theme name."
return
}
echo "$1" | grep -q " " && {
echolor red ":: Please input theme name with dashes instead of spaces."
return
}
[[ -e "$dir/$1.yaml" ]] && {
echolor red ":: A theme by this name already exists."
return
}
cp -n "$dir/.template.yaml" "$dir/$1.yaml"
newtheme="$dir/$1.yaml"
eval $EDITOR "$newtheme"
echolor green ":: Generating theme files for other programs..."
remake "$1"
}
function remake {
theme_name="$1"
theme_file="$dir/$1.yaml"
[[ ! -e "$theme_file" ]] && {
echolor red ":: No such a theme as ““$theme_name””."
return 1
}
function extract {
cat "$theme_file" | yq -r "$1"
}
color1="$(extract '.colors.color1.hex')"
color2="$(extract '.colors.color2.hex')"
color3="$(extract '.colors.color3.hex')"
color4="$(extract '.colors.color4.hex')"
color5="$(extract '.colors.color5.hex')"
function remake-rofi {
cat <<EOF > "$HOME/Repositories/dotfiles/rofi/themes/$theme_name.rasi"
* {
/* Theme colors */
color1: #$color1;
color2: #$color2;
color5: #$color5;
$(cat "$HOME/Repositories/dotfiles/rofi/themes/.boilerplate")
EOF
echolor green ":: ““rofi”” files remade for ““$theme_name””!"
}
function remake-polybar {
cat <<-EOF > "$HOME/Repositories/dotfiles/polybar/themes/$theme_name.ini"
[colors]
color1 = #$color1
color2 = #$color2
color3 = #$color3
color4 = #$color4
EOF
echolor green ":: ““polybar”” files remade for ““$theme_name””!"
}
function remake-dunst {
dunstdir="$HOME/Repositories/dotfiles/dunst/themes"
cat <<EOF > "$dunstdir/$theme_name"
$(cat "$dunstdir/.boilerplate1")
frame_color = "#$color2" #color2
$(cat "$dunstdir/.boilerplate2")
background = "#$color1" #color1
foreground = "#$color2" #color2
$(cat "$dunstdir/.boilerplate3")
EOF
echolor green ":: ““dunst”” files remade for ““$theme_name””!"
}
remake-rofi
remake-polybar
remake-dunst
}
function remake-all {
for j in $(esa "$dir" | grep "yaml")
do
echolor yellow ":: Remaking ““$j””"
remake "$(echo "$j" | awk -F '.yaml' '{print $1}')"
done
}
while getopts 'c:ar:' OPTION; do
case "$OPTION" in
'c') create "$OPTARG" ;;
'a') remake-all ;;
'r') remake "$OPTARG" ;;
*) echolor red ":: Incorrect option"
exit ;;
esac
done
(( $OPTIND == 1 )) && generate