-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathawesome-widgets
executable file
·797 lines (682 loc) · 35.4 KB
/
awesome-widgets
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
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
#!/usr/bin/env bash
## By Davoud Arsalani
## https://github.com/davoudarsalani/scripts
## https://github.com/davoudarsalani/scripts/blob/master/awesome-widgets
## https://raw.githubusercontent.com/davoudarsalani/scripts/master/awesome-widgets
## https://davoudarsalani.ir
source "$HOME"/main/scripts/gb
threshhold=70
case "$1" in
rand_wall ) ## {{{
rand_wall_allowed_file=/tmp/rand_wall_allowed
[ -f "$rand_wall_allowed_file" ] && \
[ ! "$(pgrep 'vlc')" ] && \
[ ! "$(pgrep 'ffmpeg')" ] && \
! ps -f -u "$UID" | sed 1d | \grep -qv '\-remote' | \grep -q '[s]implescreenrecorder' && \
random_wallpaper || touch "$rand_wall_allowed_file" ;; ## ^^ exceptionally used ps because pgrep cannot find simplescreenrecorder
## }}}
jadi ) ## {{{
"$HOME"/main/scripts/jadi.py ;;
## }}}
restart_picom ) ## {{{
pkill picom && sleep 2 && picom -b ;;
## }}}
turn_off_scr_3 ) ## {{{
source "$HOME"/main/scripts/gb-screen
[ "$scr_3_name" ] && {
xrandr --output "$scr_3_name" --off ## https://superuser.com/questions/618127/disable-unplugged-displays-xrandr
msgn "turned off <span color=\"${orange}\">screen 3 (${scr_3_name})</span>"
} ;;
## }}}
move_screen_2_to_left ) ## {{{
source "$HOME"/main/scripts/gb-screen
[ "$scr_2_name" ] && {
xrandr --output "$scr_2_name" --left-of "$scr_1_name"
msgn "moved <span color=\"${orange}\">screen 2 (${scr_2_name}) to left</span>"
} ;;
## }}}
date_jdate ) ## {{{
message="$(printf '%s\n\n%s\n%s\n\n%s' \
"$(get_datetime 'jweekday')" \
"$(date +%Y-%m-%d)" \
"$(jdate +%Y-%m-%d)" \
"$(jdate +%H:%M:%S)"
)"
msgn "$message" ;;
## }}}
weather ) ## {{{
case "$2" in
update )
"$HOME"/main/scripts/weather.py 'update' ;;
forecast )
"$HOME"/main/scripts/weather.py 'forecast' ;;
esac ;;
## }}}
audio ) ## {{{
function update_variables {
source "$HOME"/main/scripts/gb-audio
}
update_variables
function mute_vol {
pactl set-sink-mute "$def_sink_index" 1 ## OR pactl set-sink-mute "$def_sink_index" true <--,
} ## |
## |
function unmute_vol { ## |
pactl set-sink-mute "$def_sink_index" 0 ## OR pactl set-sink-mute "$def_sink_index" false <--'-- pactl set-sink-mute "$def_sink_index" toggle
}
function mute_mic {
pactl set-source-mute "$def_source_index" 1
}
function unmute_mic {
pactl set-source-mute "$def_source_index" 0
}
# function mic_0 {
# pactl set-source-volume "$def_source_index" 0%
# }
# function mic_25 {
# pactl set-source-volume "$def_source_index" 25%
# }
function mute_mon {
pactl set-source-mute "$def_source_mon_index" 1
}
function unmute_mon {
pactl set-source-mute "$def_source_mon_index" 0
}
# function mon_0 {
# pactl set-source-volume "$def_source_mon_index" 0%
# }
# function mon_100 {
# pactl set-source-volume "$def_source_mon_index" 100%
# }
function connecttoheadset {
source "$HOME"/main/scripts/gb-fir-blu-batt
local output text
msgn "connecting to headset <span color=\"${orange}\">${headset_mac}</span>"
output="$(bluetoothctl connect "$headset_mac")"
if ! \grep -qi 'failed to connect' <<< "$output"; then
msgn "connected to <span color=\"${orange}\">${headset_mac}</span>"
else
text="$(printf "connecting to <span color=\"%s\">%s</span>\n%s\n" "$orange" "$headset_mac" "$output")"
msgc 'ERROR' "$text" "$HOME"/main/linux/themes/alert-w.png
fi
}
case "$2" in
vol_30 )
pactl set-sink-volume "$def_sink_index" 30% ;;
toggle_vol )
if [ "$vol_mute_status" == 'yes' ]; then
unmute_vol
else
mute_vol
fi ;;
vol_up )
pactl set-sink-volume "$def_sink_index" +5% ;;
vol_down )
pactl set-sink-volume "$def_sink_index" -5% ;;
# vol_100 )
# pactl set-sink-volume "$def_sink_index" 100% ;;
# vol_0 )
# pactl set-sink-volume "$def_sink_index" 0% ;;
toggle_mic )
if [ "$mic_mute_status" == 'yes' ]; then
unmute_mic
else
mute_mic
fi ;;
mic_up )
pactl set-source-volume "$def_source_index" +5% ;;
mic_down )
pactl set-source-volume "$def_source_index" -5% ;;
mic_100 )
pactl set-source-volume "$def_source_index" 100% ;;
mic_0 )
pactl set-source-volume "$def_source_index" 0% ;;
toggle_mon )
if [ "$mon_mute_status" == 'yes' ]; then
unmute_mon
else
mute_mon
fi ;;
mon_up )
pactl set-source-volume "$def_source_mon_index" +5% ;;
mon_down )
pactl set-source-volume "$def_source_mon_index" -5% ;;
mon_100 )
pactl set-source-volume "$def_source_mon_index" 100% ;;
mon_0 )
pactl set-source-volume "$def_source_mon_index" 0% ;;
connect_to_headset )
connecttoheadset ;;
full_info )
text="$(printf '%s\n' \
"<span color=\"${orange}\">Vol</span>
name: ${def_sink_name}
index: ${def_sink_index}
level: ${vol_level}
state: ${vol_state}
mute: ${vol_mute_status}
<span color=\"${orange}\">Mic</span>
name: ${def_source_name}
index: ${def_source_index}
level: ${mic_level}
state: ${mic_state}
mute: ${mic_mute_status}
<span color=\"${orange}\">Mon</span>
name: ${def_source_mon_name}
index: ${def_source_mon_index}
level: ${mon_level}
state: ${mon_state}
mute: ${mon_mute_status}
<span color=\"${orange}\">Active ports</span>
sink: ${active_sink_port}
source: ${active_source_port}")"
msgn "$text" ;;
esac
update_variables
[ "$vol_mute_status" == 'yes' ] && vol_on_off="<span color=\"${red}\">:OF</span>"
(( vol_level > 0 )) || vol_level="<span color=\"${red}\">${vol_level}</span>"
[ "$mic_mute_status" == 'no' ] && mic_on_off="<span color=\"${red}\">:ON</span>"
(( mic_level > 0 )) && mic_level="<span color=\"${red}\">${mic_level}</span>"
[ "$mon_mute_status" == 'no' ] && mon_on_off="<span color=\"${red}\">:ON</span>"
(( mon_level > 0 )) && mon_level="<span color=\"${red}\">${mon_level}</span>"
states_initials="${vol_state::1}${mic_state::1}${mon_state::1}" ## RSI
indeces="${def_sink_index}${def_source_index}${def_source_mon_index}" ## 010
headset_regex='bluez_sink*'
[[ "$def_sink_name" =~ $headset_regex ]] && headset_connectivity=' HE'
## previously: [ "$(printf '%s\n' "$def_sink_name" | \grep '^bluez_sink')" ] && headset_connectivity=' HE'
set_widget 'audio' 'markup' "${vol_level}${vol_on_off} ${mic_level}${mic_on_off} ${mon_level}${mon_on_off} ${states_initials} ${indeces}${headset_connectivity}" ;;
## }}}
battery ) ## {{{
source "$HOME"/main/scripts/gb-fir-blu-batt
if [ "$battery_level" ] && (( battery_level < 15 )); then ## <--,-- sometimes battery_level is not present and, in spite of that,
set_widget 'battery_ct' 'fg' "$red" ## |-- the (()) statement falsely returns true.
else ## '-- so we have to first check if battery_level is present
set_widget 'battery_ct' 'fg' "$fg_d"
fi
case "$battery_status" in
Full )
: ;;
Discharging )
: ;;
Charging )
ac_or_dc="<span color=\"${red}\">CH </span>" ;;
* )
ac_or_dc="?? " ;; ## TEMPORARY it should be: ac_or_dc="<span color=\"${red}\">?? </span>"
## but removed the color because now that the battery is screwd,
## the '??' is always present on topwibar which is annoying
esac
## get battery_temp_last
battery_temp_last_file="$HOME"/main/scripts/.last/battery_temp
battery_temp_last="$(< "$battery_temp_last_file")" || battery_temp_last=0 ## NOTE do NOT add 2>/dev/null
## save battery_temp as last for our next read
printf '%s\n' "$battery_temp" > "$battery_temp_last_file"
(( diff="battery_temp - battery_temp_last" ))
if (( diff > 0 )); then
pref="+${diff} "
elif (( diff < 0 )); then
pref="${diff} "
fi
[ "$battery_level" ] && battery_level="$battery_level "
[ "$battery_rem" ] && battery_rem="$battery_rem "
(( battery_temp > threshhold )) && battery_temp="<span color=\"${red}\">${battery_temp}</span>"
set_widget 'battery' 'markup' "${ac_or_dc}${battery_level}${battery_rem}${pref}${battery_temp}°" ;;
## }}}
memory_cpu ) ## {{{
source "$HOME"/main/scripts/gb-calculation
case "$2" in
intensives )
top_memory="$(ps axch -o cmd:15,%mem --sort=-%mem | head -n 10)" ## <--,-- 15 makes it only 15 characters long
top_cpu="$(ps axch -o cmd:15,%cpu --sort=-%cpu | head -n 10)" ## <--'
message_text="$(printf "<span color=\"%s\">Memory</span>\n%s\n\n<span color=\"%s\">CPU</span>\n%s\n" "$orange" "$top_memory" "$orange" "$top_cpu")"
msgn "$message_text" ;;
usage )
## NOTE JUMP_3 memory should be calculated at the end becuase IFS=$ in memory section interferes with the calculations in cpu and cpu temperature
## cpu (https://www.idnt.net/en-US/kb/941772)
## get last usage
cpu_last_file="$HOME"/main/scripts/.last/cpu
cpu_sum_last_file="$HOME"/main/scripts/.last/cpu_sum
cpu_temp_last_file="$HOME"/main/scripts/.last/cpu_temp
read -a cpu_last < "$cpu_last_file" || cpu_last=( cpu 0 0 0 0 0 0 0 0 0 0 ) ## JUMP_2
cpu_sum_last="$(< "$cpu_sum_last_file")" || cpu_sum_last=0 ## NOTE do NOT add 2>/dev/null
cpu_temp_last="$(< "$cpu_temp_last_file")" || cpu_temp_last=0 ## NOTE do NOT add 2>/dev/null
## get new usage
read -a cpu_now < /proc/stat ## get the first line with aggregate of all cpus
cpu_sum="${cpu_now[@]:1}" ## get all columns but skip the first (which is the 'cpu' string)
## ^^ cpu_sum is a str
(( cpu_sum="${cpu_sum// /+}" )) ## replace the column seperator (space) with +
(( cpu_delta="cpu_sum - cpu_sum_last" )) ## get the delta between two reads
(( cpu_idle="cpu_now[4] - cpu_last[4]" )) ## get the idle time delta
(( cpu_used="cpu_delta - cpu_idle" )) ## calc time spent working
cpu_perc="$(float_pad "100*${cpu_used}/${cpu_delta}" 1 2)"
## save these as last to compare in our next read
printf '%s ' "${cpu_now[@]}" > "$cpu_last_file" ## NOTE no \n
printf '\n' >> "$cpu_last_file" ## NOTE JUMP_2 have to append new line (because none was appended in the previous line) otherwise it will exit non-zero when creating cpu_last and therefore activating pipe
printf '%s\n' "$cpu_sum" > "$cpu_sum_last_file"
cpu_geater="$(compare_floats "$cpu_perc" ">" "$threshhold")"
[ "$cpu_geater" == 'true' ] && cpu_perc="<span color=\"${red}\">${cpu_perc}</span>"
## cpu temperature
cpu_temp="$(sensors | \grep 'Package' | cut -d '+' -f 2 | cut -d '.' -f 1)"
## save cpu_temp as last for our next read
printf '%s\n' "$cpu_temp" > "$cpu_temp_last_file"
(( diff="cpu_temp - cpu_temp_last" ))
if (( diff > 0 )); then
pref="+${diff} "
elif (( diff < 0 )); then
pref="${diff} "
fi
cpu_temp_greater="$(compare_floats "$cpu_temp" '>' "$threshhold")"
[ "$cpu_temp_greater" == 'true' ] && cpu_temp="<span color=\"${red}\">${cpu_temp}</span>"
## cpu governor
readarray -t cpu_governor < <(for file in /sys/devices/system/cpu/cpu{0..3}/cpufreq/scaling_governor; {
[ -f "$file" ] && [ -r "$file" ] || continue
cat "$file"
} | sort --unique)
[ "$(printf '%s\n' "${cpu_governor[@]}" | \grep -i 'powersave')" ] || cpu_gov=" <span color=\"${red}\">${cpu_governor[@]^^}</span>"
## cpu governors (https://wiki.archlinux.org/title/CPU_frequency_scaling):
## performance Run the CPU at the maximum frequency.
## powersave Run the CPU at the minimum frequency.
## userspace Run the CPU at user specified frequencies.
## ondemand Scales the frequency dynamically according to current load. Jumps to the highest frequency and then possibly back off as the idle time increases.
## conservative Scales the frequency dynamically according to current load. Scales the frequency more gradually than ondemand.
## schedutil Scheduler-driven CPU frequency selection [2], [3].
## memory ## NOTE JUMP_3 memory should be calculated at the end becuase IFS=$ in memory section interferes with the calculations in cpu and cpu temperature
IFS=$
mem_info="$(< /proc/meminfo)"
mem_total="$(printf '%s\n' "$mem_info" | \grep '^MemTotal' | awk '{print $2}')"
mem_free="$(printf '%s\n' "$mem_info" | \grep '^MemFree' | awk '{print $2}')"
mem_buffers="$(printf '%s\n' "$mem_info" | \grep '^Buffers' | awk '{print $2}')"
mem_cached="$(printf '%s\n' "$mem_info" | \grep '^Cached' | awk '{print $2}')"
mem_srec="$(printf '%s\n' "$mem_info" | \grep '^SReclaimable' | awk '{print $2}')"
(( mem_used="mem_total - mem_free - mem_buffers - mem_cached - mem_srec" ))
mem_perc="$(float_pad "${mem_used}/${mem_total}*100" 1 2)"
mem_geater="$(compare_floats "$mem_perc" '>' "$threshhold")"
[ "$mem_geater" == 'true' ] && mem_perc="<span color=\"${red}\">${mem_perc}</span>"
set_widget 'memory_cpu' 'markup' "${mem_perc} ${cpu_perc} ${pref}${cpu_temp}°${cpu_gov}" ;;
esac ;;
## }}}
harddisk ) ## {{{
source "$HOME"/main/scripts/gb-calculation
case "$2" in
partitions )
partitions_text="$(printf "<span color=\"%s\">lsblk</span>\n%s\n\n<span color=\"%s\">mounted drives</span>\n%s\n" "$orange" "$(lsblk_full)" "$orange" "$(mounted_drives 'human_readable')")"
msgn "$partitions_text" ;;
usage )
root_size="$(mounted_drives | \grep '\/$' | awk '{print $3}')"
root_used="$(mounted_drives | \grep '\/$' | awk '{print $4}')"
(( root_used > 0 )) && root_used="$(float_pad "${root_used}*100/${root_size}" 1 2)"
root_geater="$(compare_floats "$root_used" '>' "$threshhold")"
[ "$root_geater" == 'true' ] && root_used="<span color=\"${red}\">${root_used}</span>"
home_size="$(mounted_drives | \grep '\/home$' | awk '{print $3}')"
home_used="$(mounted_drives | \grep '\/home$' | awk '{print $4}')"
(( home_used > 0 )) && home_used="$(float_pad "${home_used}*100/${home_size}" 1 2)"
home_greater="$(compare_floats "$home_used" '>' "$threshhold")"
[ "$home_greater" == 'true' ] && home_used="<span color=\"${red}\">${home_used}</span>"
swap_size="$(swapon --summary | \grep -i 'partition' | awk '{print $3}')"
swap_used="$(swapon --summary | \grep -i 'partition' | awk '{print $4}')"
(( swap_used > 0 )) && swap_used="$(float_pad "${swap_used}*100/${swap_size}" 1 2)"
swap_geater="$(compare_floats "$swap_used" '>' "$threshhold")"
[ "$swap_geater" == 'true' ] && swap_used="<span color=\"${red}\">${swap_used}</span>"
hdd_temp_last_file="$HOME"/main/scripts/.last/hdd_temp
hdd_temp_last="$(< "$hdd_temp_last_file")" || hdd_temp_last=0 ## NOTE do NOT add 2>/dev/null
hdd_temp="$(sudo hddtemp /dev/sda --numeric)"
## save hdd_temp as last for our next read
printf '%s\n' "$hdd_temp" > "$hdd_temp_last_file"
(( diff="hdd_temp - hdd_temp_last" ))
if (( diff > 0 )); then
pref="+${diff} "
elif (( diff < 0 )); then
pref="${diff} "
fi
hdd_temp_geater="$(compare_floats "$hdd_temp" '>' "$threshhold")"
[ "$hdd_temp_geater" == 'true' ] && hdd_temp="<span color=\"${red}\">${hdd_temp}</span>"
set_widget 'harddisk' 'markup' "${root_used} ${home_used} ${swap_used} ${pref}${hdd_temp}°" ;;
esac ;;
## }}}
# gpu ) ## {{{
# active_gpu="$(optimus-manager --status | \grep 'Current GPU mode' | awk '{print $NF}')"
# active_gpu="${active_gpu::1}"
# [ "$active_gpu" == 'n' ] && active_gpu="<span color=\"${red}\">${active_gpu}</span>"
# set_widget 'gpu' 'markup' "$active_gpu" ;;
## }}}
# pkg_count ) ## {{{
# pkg_count="$(wc -l < <(pacman -Q))"
# set_widget 'pkg_count' 'markup' "$pkg_count" ;;
## }}}
processes ) ## {{{
## get last processes_count
processes_last_file="$HOME"/main/scripts/.last/processes
processes_count_last="$(< "$processes_last_file")" || processes_count_last=0 ## NOTE do NOT add 2>/dev/null
processes_count="$(wc -l < <(pgrep .))" ## previously: "$(wc -l < <(ps -aux))"
## save processes_count as last for our next read
printf '%s\n' "$processes_count" > "$processes_last_file"
## compare
(( diff="processes_count - processes_count_last" ))
if (( diff > 0 )); then
pref="+${diff} "
elif (( diff < 0 )); then
pref="${diff} "
fi
set_widget 'processes' 'markup' "${pref}${processes_count}" ;;
## }}}
# idle ) ## {{{
# source "$HOME"/main/scripts/gb-calculation
# weekday="$(get_datetime 'jweekday')"
# current_date="$(get_datetime 'jymd')"
# current_datetime="$(get_datetime 'jymdhms')"
# idle_file="$HOME"/main/linux/idle/idle-"$current_date" ## ,-- NOTE do NOT use printf '%02d\n' since it causes errors for 07 and 08 in convert_second function
# (( idle_secs="$(xprintidle) / 1000" )) ## <--'-- 103
# perc="$(float_pad "${idle_secs}*100/600" 1 2)"
# printf '%s\t%s\t%s\n' "$current_datetime" "$weekday" "$perc" >> "$idle_file"
# is_bigger="$(compare_floats "$perc" '>' 90)"
# [ "$is_bigger" == 'true' ] && perc="<span color=\"${red}\">${perc}</span>"
# set_widget 'idle' 'markup' "$perc" ;;
## }}}
# reputation ) ## {{{
# "$HOME"/main/scripts/reputation.py ;;
## }}}
visits ) ## {{{
"$HOME"/main/scripts/visits.py ;;
## }}}
status ) ## {{{
"$HOME"/main/scripts/status.py ;;
## }}}
youtube ) ## {{{
source "$HOME"/main/scripts/gb-screen
## determine if screen 2 is on right or left of screen 1
is_right_of='false'
is_left_of='false'
reg='^.*\+0\+0.*$'
scr_1_info="$(printf '%s\n' "$xrandr_output" | \grep "$scr_1_name")" ## eDP-1 connected primary 1366x768+1920+0 (normal left inverted right x axis y axis) 344mm x 193mm
[[ "$scr_1_info" =~ $reg ]] && is_right_of='true' || is_left_of='true'
cur_scr_index="$(awesome-client 'local awful = require("awful") ; return awful.screen.focused().index' | awk '{print $NF}')"
## calculate x
if [ "$is_right_of" == 'true' ]; then
if (( cur_scr_index == 1 )); then
(( x="scr_1_x / 2" ))
else
(( x="scr_1_x + (scr_2_x / 2)" ))
fi
elif [ "$is_left_of" == 'true' ]; then
if (( cur_scr_index == 1 )); then
(( x="scr_2_x + (scr_1_x / 2)" ))
else
(( x="scr_2_x / 2" ))
fi
else
exit
fi
y=300
"$HOME"/main/scripts/awesome-widgets audacious pause
xdotool mousemove "$x" "$y"
sleep 0.1
xdotool click --repeat 2 --delay 200 1
msgn 'fullscreen' ;;
## }}}
mbl_umbl ) ## {{{
get_mountable_umountable
m_count="${#mountable[@]}"; (( m_count > 0 )) && M="M:${m_count}"
u_count="${#umountable[@]}"; (( u_count > 0 )) && U="U:${u_count}"
(( m_count > 0 && u_count > 0 )) && seperator=','
(( m_count > 0 || u_count > 0 )) && text="<span color=\"${red}\">${M}${seperator}${U}</span>" || text='MU'
set_widget 'mbl_umbl' 'markup' "$text" ;;
## }}}
firewall ) ## {{{
function update_variables {
source "$HOME"/main/scripts/gb-fir-blu-batt
}
update_variables
case "$2" in
turn_on )
sudo ufw enable ;;
turn_off )
sudo ufw disable ;;
esac
update_variables
case "$firewall_status" in
active )
set_widget 'firewall' 'markup' 'FI' ;;
* )
set_widget 'firewall' 'markup' "<span color=\"${red}\">FI:OF</span>" ;;
esac ;;
## }}}
bluetooth ) ## {{{
function update_variables {
source "$HOME"/main/scripts/gb-fir-blu-batt
}
update_variables
case "$2" in
turn_on )
sudo rfkill unblock bluetooth ;;
turn_off )
sudo rfkill block bluetooth ;;
esac
update_variables
case "$bluetooth_status" in
yes )
set_widget 'bluetooth' 'markup' 'BL' ;;
* )
set_widget 'bluetooth' 'markup' "<span color=\"${red}\">BL:ON</span>" ;;
esac ;;
## }}}
ymail ) ## {{{
"$HOME"/main/scripts/e-mail.py 'ymail' ;;
## }}}
gmail ) ## {{{
sleep 10 ## only to prevent probable collision with ymail
"$HOME"/main/scripts/e-mail.py 'gmail' ;;
## }}}
webcam ) ## {{{
webcam_status="$(lsmod | \grep -i '^uvcvideo' | awk '{print $NF}')"
(( webcam_status > 0 )) && webcam_text="<span color=\"${red}\">WE:ON</span>" || webcam_text='WE'
set_widget 'webcam' 'markup' "$webcam_text" ;;
## }}}
git ) ## {{{
source "$HOME"/main/scripts/gb-git
modified_repos=''
set_widget 'git' 'markup' "$refresh_icon"
## FIXME cant use FZF_DEFAULT_COMMAND and FZF_ALT_C_COMMAND_GIT because they are apparently not accessible to this option
## FIXME a bit too slow
## synced with path flags for FZF_DEFAULT_COMMAND in /etc/bash.bashrc
path_flags_1="! -path '*.git/*' ! -path '*.cache/*' ! -path '*.venv*/*' ! -path '*kaddy/*' ! -path '*trash/*' 2>/dev/null"
## synced with path flags for FZF_ALT_C_COMMAND_GIT in /etc/bash.bashrc
path_flags_2="! -path '*.config/*' ! -path '*.vim/*' ! -path '*go/*' ! -path '*trash/*'"
find_cmd="find "$HOME"/main/ -type d $path_flags_1 $path_flags_2 -iname '.git' | sed 's#/\.git##' | sort"
readarray -t all_repos < <(eval "$find_cmd")
readarray -t non_public_repos < <(printf '%s\n' "${all_repos[@]/\~/$HOME}" | \grep -v 'public')
readarray -t public_repos < <(printf '%s\n' "${all_repos[@]/\~/$HOME}" | \grep 'public')
## non-public repos:
for non_public_repo in "${non_public_repos[@]}"; {
status_count="$(wc -l < <(git_status "$non_public_repo"))"
(( status_count > 0 )) && {
base="${non_public_repo##*/}"
modified_repos+="${base::1}${status_count},"
}
}
## public repos:
regex_status=' ST:'
regex_commits_ahead=' AH:'
for public_repo in "${public_repos[@]%/.git}"; {
base="${public_repo##*/}"
## check if repo is ahead of origin
commits_ahead="$(git_commits_ahead "$public_repo")"
(( commits_ahead > 0 )) && {
[[ "$modified_repos" =~ $regex_commits_ahead ]] || pref="$regex_commits_ahead"
modified_repos+=" ${pref}${base::1}${commits_ahead},"
unset pref
}
## check if there are changes
status_count="$(wc -l < <(git_status "$public_repo"))"
(( status_count > 0 )) && {
[[ "$modified_repos" =~ $regex_status ]] || pref="$regex_status"
modified_repos+=" ${pref}${base::1}${status_count},"
unset pref
}
}
[ "$modified_repos" ] && git_text="<span color=\"${red}\">GI:${modified_repos%,*}</span>" || git_text="GI" ## %,* is to remove the trailing , and everything coming after that (only one % mean non-greedy)
set_widget 'git' 'markup' "$git_text" ;;
## }}}
clipboard ) ## {{{
function check_status {
if_on="$(pgrep 'greenclip')"
}
check_status
case "$2" in
start )
if [ "$if_on" ]; then
msgn "<span color=\"${orange}\">greenclip</span> already on"
else
greenclip daemon &
msgn "<span color=\"${orange}\">greenclip</span> started"
fi ;;
stop )
pkill greenclip
msgn "<span color=\"${orange}\">greenclip</span> stopped" ;;
esac
[ "$if_on" ] && clipboard_text='CL' || clipboard_text="<span color=\"${red}\">CL:OF</span>"
set_widget 'clipboard' 'markup' "$clipboard_text" ;;
## }}}
# klgr ) ## {{{
# ## append current_datetime to the most recent log
# current_datetime="$(get_datetime 'jymdhms')"
# weekday="$(get_datetime 'jweekday')"
# most_recent_log="$(find "$HOME"/main/linux/keylogs/ -mindepth 1 -maxdepth 1 | sort | tail -n 1)"
# dashed="$(awk -v i=30 'BEGIN {OFS="-"; $i="-"; print}')" ## NOTE do NOT replace " with ' ## https://www.unix.com/shell-programming-and-scripting/235829-how-print-particular-character-n-number-times-line.html
# printf '%s\n%s\t%s\n' "$dashed" "$current_datetime" "$weekday" >> "$most_recent_log"
# ## check status (exceptionally used ps because pgrep cannot find this)
# keylogger_status="$(ps -f -u "$UID" | sed 1d | \grep -v '\-remote' | \grep '[k]eylogger')"
# [ "$keylogger_status" ] && keylogger_text='KE' || keylogger_text="<span color=\"${red}\">KE:OF</span>"
# set_widget 'keylogger' 'markup' "$keylogger_text" ;;
## }}}
established ) ## {{{
## we can add sudo in this case to get instances other than the user-related ones:
estab="$(sudo lsof -i -P -n | \grep 'ESTABLISHED' | awk '{print $1}' | sort --unique)" ## -i looks for listing ports, -P inhibits the conversion of port numbers to port names for network files, -n does not use DNS name (https://www.cyberciti.biz/faq/how-to-check-open-ports-in-linux-using-the-cli/)
estab_count="$(wc -l < <(printf '%s\n' "${estab:?'NONE'}"))" ## JUMP_1 --,--> expansion structure from https://stackoverflow.com/questions/3601515/how-to-check-if-a-variable-is-set-in-bash
## '--> throws non-skippable error when estab nat available
(( estab_count > 0 )) && estab_text="ES:${estab_count}" || estab_text='ES'
set_widget 'established' 'markup' "$estab_text"
case "$2" in
message )
(( estab_count > 0 )) && message_text="$(printf "<span color=\"%s\">Established</span>\n%s\n" "$orange" "$estab")" || message_text='No established connections'
msgn "$message_text" ;;
esac ;;
## }}}
open_ports ) ## {{{
## FIXME
open_ports="$(sudo lsof -i -P -n | \grep 'LISTEN')" ## -i looks for listing ports, -P inhibits the conversion of port numbers to port names for network files, -n does not use DNS name (https://www.cyberciti.biz/faq/how-to-check-open-ports-in-linux-using-the-cli/)
open_ports_count="$(wc -l < <(printf '%s\n' "${open_ports:?'NONE'}"))" ## JUMP_1 --,--> expansion structure from https://stackoverflow.com/questions/3601515/how-to-check-if-a-variable-is-set-in-bash
## '--> throws non-skippable error when open_ports nat available
(( open_ports_count > 0 )) && open_ports_text="<span color=\"${red}\">OP:${open_ports_count}</span>" || open_ports_text='OP'
set_widget 'open_ports' 'markup' "$open_ports_text"
case "$2" in
message )
(( open_ports_count > 0 )) && message_text="$(printf "<span color=\"%s\">Open ports</span>\n%s\n" "$orange" "$open_ports")" || message_text='No open ports'
msgn "$message_text" ;;
esac ;;
## }}}
tor ) ## {{{
case "$2" in
start )
sudo systemctl start tor && msgn "<span color=\"${orange}\">tor</span> started" ;;
stop )
sudo systemctl stop tor && msgn "<span color=\"${orange}\">tor</span> stopped" ;;
restart )
sudo systemctl restart tor && msgn "<span color=\"${orange}\">tor</span> restarted" ;;
is-tor )
"$HOME"/main/scripts/is-tor.py 'msg' ;;
esac
tor_status="$(pgrep 'tor')" ## why exceptionally used "$(sudo lsof -i -P -n | \grep 'LISTEN' | \grep '^tor')" instead of pgrep?
[ "$tor_status" ] && tor_status_text="<span color=\"${red}\">TO:ON</span>" || tor_status_text='TO'
set_widget 'tor' 'markup' "$tor_status_text" ;;
## }}}
ping ) ## {{{
ping_failed_file=/tmp/ping_failed
[ -f "$ping_failed_file" ] && set_widget 'ping' 'markup' "<span color=\"${red}\">$refresh_icon</span>" ## exceptionally colored refresh_icon
ping 8.8.8.8 -c 1 -W 2 &>/dev/null && {
stts=''
if [ -f "$ping_failed_file" ]; then
text="$(printf 'Connected back at\n%s\n' "$(jdate '+%Y-%m-%d %H:%M:%S')")"
# msgc "$text"
rm "$ping_failed_file"
fi
} || {
stts="<span color=\"${red}\">PI</span>" ## ◖◗
printf '%s\n' "$(get_datetime 'jymdhms')" > "$ping_failed_file"
}
set_widget 'ping' 'markup' "$stts" ;;
## }}}
audacious ) ## {{{
source "$HOME"/main/scripts/gb-calculation
source "$HOME"/main/scripts/gb-duration
function update_variables {
source "$HOME"/main/scripts/gb-audacious
}
csols_file="$HOME"/main/scripts/.last/csols
update_variables
if [ "$album" == 'speech' ]; then
audtool --equalizer-set 0 0 0 0 0 0 0 0 0 0 0
else
audtool --equalizer-set -2.10 -10.86 4.00 5.14 2.10 -0.19 -2.10 -2.86 -4.00 -4.00 -4.00
fi
case "$2" in
play_pause )
audtool --playback-playpause ;; ## OR audacious -t
pause )
[ "$play_status" == 'playing' ] && audtool --playback-pause ;;
main_window )
audtool --mainwin-show ;; ## OR audacious -H OR audacious -m
resume )
[ "$album" == 'speech' ] && audtool --playback-seek "$(< "$csols_file")" ;;
tog_shuff )
audtool --playlist-shuffle-toggle ;;
prev )
audtool --playlist-reverse ;; ## OR audacious -r
next )
audtool --playlist-advance ;; ## OR audacious -f
# forward )
# forward_length=120
# (( remaining_seconds="length_in_seconds - current_position_in_seconds" ))
# if (( remaining_seconds < forward_length )); then
# audtool --playlist-advance
# else
# audtool --playback-seek-relative "+${forward_length}"
# fi ;;
-60 )
audtool --playback-seek-relative -60 ;;
+60 )
audtool --playback-seek-relative +60 ;;
songs )
IFS=$'\n'
readarray -t current_songs < <(audtool --playlist-display)
selected_song="$(pipe_to_rofi "${current_songs[@]}" 'header=songs')" || exit 37
selected_song_index="$(printf '%s\n' "$selected_song" | awk '{print $1}')"
audtool --playlist-jump "$selected_song_index" ;;
esac
update_variables
if [ "$play_status" == 'stopped' ]; then
text=''
bar_position=0
else
## save currnt song output length seconds (csols) if speech
regex='^(playing|paused)$'
[[ "$play_status" =~ $regex ]] && [ "$album" == 'speech' ] && {
printf '%s\n' "$current_position_in_seconds" > "$csols_file"
# msgn 'saved csol' "<span color=\"${orange}\">${current_position}</span>"
}
[ "$play_status" == 'playing' ] || paused_text='PAUSED '
preamp_is_zero="$(compare_floats "$preamp" '=' 0)"
[ "$preamp_is_zero" == 'false' ] && equalizer='EQ '
[ "$shuffle_status" == 'on' ] && shuffle_text='SH '
order="${position_in_playlist}/${playlist_length}" ## 1/5
[ "$length" ] && timestamp="${current_position}/${length}" || timestamp='0:00/0:00' ## 2:24/18:54
(( bar_position > 99 )) && bar_position=1 || bar_position=0.${bar_position}
left="$(convert_second "$left_in_seconds")" ## 01:05:16
left="$(shorten_duration "$left")" ## 1:05:16
text="<span color=\"${grey}\">${paused_text}</span><span color=\"${fg_l}\">${equalizer}</span><span color=\"${fg_d}\">${shuffle_text}</span><span color=\"${fg_l}\">${order}</span> <span color=\"${fg_d}\">${timestamp} -${left}</span> <span color=\"${fg_l}\">${title}</span> <span color=\"${fg_d}\">${album}</span> <span color=\"${fg_l}\">${artist}</span>"
fi
set_widget 'audacious' 'markup' "$text"
set_widget 'audacious_bar' 'background_color' "$fg_l"
set_widget 'audacious_bar' 'color' "$fg_d"
awesome-client "audacious_bar.value = ${bar_position}" ## set_widget doesn't work properly for audacious_bar
;;
## }}}
esac