-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfetch
executable file
·270 lines (236 loc) · 5.46 KB
/
fetch
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
#!/bin/sh
LC_ALL=C
LANG=C
COLS=$(tput cols)
fg_c() {
tput setaf "$1"
}
bg_c(){
tput setab "$1"
}
fg_t(){
printf '\e[38;2;%s;%s;%s'"m" "$@"
}
bg_t(){
printf '\e[48;2;%1;%2;%3'"m" "$@"
}
up () {
printf "\e[%dA" "$1"
# line=$((line-$1))
}
down () {
printf "\e[%dB" "$1"
# line=$((line+$1))
}
left () {
printf "\e[%dD" "$1"
}
right () {
printf "\e[%dC" "$1"
}
BOLD=$(tput bold)
ITALIC=$(tput sitm)
BLACK=239
WHITE=15
B_BG=$(bg_c $BLACK)
B_FG=$(fg_c $BLACK)
NORMAL="$(printf "\e[m")"
W_BG=$(bg_c $WHITE)
W_FG=$(fg_c $WHITE)
get_packages () {
if command -v apt 1> /dev/null
then
package_data="${package_data}$(apt list --installed 2>&- | wc -l) (apt) "
fi
if command -v nix 1> /dev/null
then
_package_count=0
if command -v home-manager 1>/dev/null
then
_package_count="$((_package_count+$(nix-store -q -R ~/.local/state/home-manager/gcroots/current-home | wc -l)))"
fi
if command -v nixos-rebuild 1> /dev/null || command -v darwin-rebuild 1> /dev/null
then
_package_count="$((_package_count+$(nix-store -q -R /run/current-system/sw | wc -l)))"
fi
package_data="${package_data}$_package_count (nix) "
# package_data="${packages+ }$(wc -l < /etc/current-system-packages) (nix)"
fi
if command -v pacman 1> /dev/null
then
package_data="${package_data}$(pacman -Q | wc -l) (pacman) "
fi
if command -v brew 1> /dev/null
then
package_data="${package_data}$(brew list | wc -l) (brew) "
fi
printf "%s" "$package_data"
}
if [[ $OSTYPE == "darwin"* ]]
then
os="$(sw_vers | grep "ProductVersion" | awk -F ":" '{print $2}' | uniq)"
os="${os#"${os%%[![:space:]]*}"}"
case $os in
15*)
os="Sequoia $os"
;;
esac
os="macOS $os"
cpu="$(system_profiler SPHardwareDataType | grep Chip | awk -F ":" '{print $2}' )"
else
os="$(. /etc/os-release && printf "%s" "$PRETTY_NAME")"
cpu="$(grep "model name" /proc/cpuinfo | awk -F ":" '{ print $2}' | uniq)"
command -v lspci >/dev/null && {
gpu=$(lspci -mm | grep -i 'vga\|display')
gpu=${gpu##*Corporation\"}
gpu=${gpu#*\[AMD/ATI\]}
gpu=${gpu%%\]*}
gpu=${gpu##*\[}
gpu=" ${gpu#*\"}"
# set -- "${gpu%%\"*}"
# case $* in
# */*Mobile*) gpu=" $1 $2 Mobile";;
# */*) gpu=" $1 $2";;
# *) gpu=" $*";;
# esac
}
fi
get_kernel () {
case $OSTYPE in
darwin*)
echo ""
;;
linux*)
uname -r
;;
esac
}
cpu="${cpu#"${cpu%%[![:space:]]*}"}"
lyric="$( shuf -n 1 < ~/Music/phoebe/lyricslist 2>&- )"
lyric=${lyric:-"phoebe bridgers"}
case $OSTYPE in
darwin*)
memused="$(top -l 1 -s 0 | awk '/PhysMem/ {print $2}')"
memfree="$(top -l 1 -s 0 | awk '/PhysMem/ {print $8}')"
;;
linux*)
memused="$(free -m | awk '/Mem/ {print $3}')"
memtotal="$(free -m | awk '/Mem/ {print $2}')"
;;
esac
#main_color="$(fg_t 255 216 158)"
main_color="$(fg_t 158 203 219 )"
category="$main_color$BOLD"
eye_color="$(fg_c 236)"
if [ -n "$(playerctl metadata title 2>&- )" ]; then
song=$(playerctl metadata --format "{{title}} - {{artist}}")
else
song="${ITALIC}always listening to phoebe bridgers${NORMAL}"
fi
wm=$DESKTOP_SESSION
time=$(date "+%I:%M %p")
date=$(date "+%a %d %b %G")
uptime="$(uptime | awk -F ',' '{print $1}' | awk -F 'up' '{print $2}')"
small () {
_small=""
HEIGHT=6
WIDTH=14
cat <<EOF
${W_FG}▄▄▄▄▄${NORMAL}
${W_BG} ${NORMAL}
${W_BG} ${eye_color} ${W_BG} ${eye_color} ${W_BG} ${NORMAL} ${NORMAL}
${W_BG}${B_FG} ${NORMAL}
${W_BG}${B_FG} , , ${NORMAL}
${W_BG}${B_FG} ${NORMAL}
${W_BG}${B_FG} , , , ${NORMAL}
EOF
}
large () {
HEIGHT=14
WIDTH=15
down 1
cat << EOF
${W_FG}▄▄▄▄▄${NORMAL}
${W_BG} ${NORMAL}
${W_BG} ${eye_color} ${W_BG} ${eye_color} ${W_BG} ${NORMAL}
${W_BG}${B_FG} ${NORMAL}
${W_BG}${B_FG} , , ${NORMAL}
${W_BG}${B_FG} ${NORMAL}
${W_BG}${B_FG} , , , ${NORMAL}
${W_BG}${B_FG} ${NORMAL}
${W_BG}${B_FG} , , ${NORMAL}
${W_BG}${B_FG} | ${NORMAL}
${W_BG}${B_FG} , | , ${NORMAL}
${W_BG}${B_FG} , , ${NORMAL}
${W_BG}${B_FG} ${NORMAL}
${W_BG}${B_FG} ${NORMAL}
${W_BG}${B_FG} | | | ${NORMAL}
EOF
down 1
}
print_phoebe () {
down 1
right 1
WIDTH=27
# HEIGHT=50
# wezterm imgcat --width $WIDTH ~/backgrounds/phoeb.png
HEIGHT=14
wezterm imgcat --width $WIDTH ~/backgrounds/sadbridgers.png
# wezterm imgcat --height $HEIGHT ~/backgrounds/sadbridgers.png
}
case $1 in
-s)
small
;;
-p)
print_phoebe;;
*)
large
;;
esac
line=$HEIGHT
up_c () {
up "$1"
line=$((line-$1))
}
down_c() {
down "$1"
line=$((line+$1))
}
offset () {
printf '\e[%dG' "$((WIDTH+7))"
}
segment () {
offset
printf "%s" "$1"
down_c 1
}
data () {
_variable="$1"
_variable_value=${2:-" $(eval "get_$1")"}
if [ -n "${_variable_value# }" ]
then
segment "$category$_variable:$NORMAL$_variable_value"
fi
}
up_c $HEIGHT
segment "$ITALIC$main_color$lyric$NORMAL"
if [ -z ${_small+x} ];
then
data "date" " $date"
else
segment "${category}$time"
fi
data "os" " $os"
data "cpu" " $cpu"
data "mem" " ${memused}MB / ${memtotal}MB"
if [ -z ${_small+x} ]; then
data "packages"
data "gpu" " $gpu"
data "kernel"
data "wm" " $wm"
data "song" " $song"
data "uptime" " $uptime"
fi
down $((HEIGHT-line))
printf "\n"