4 local -r word
=$
(fzf
< /usr
/share
/dict
/words
)
8 shell_activity_report
() {
9 # TODO: optional concrete number output
10 # TODO: optional combinations of granularities: hour, weekday, month, year
17 echo "Usage: $0 [mon|dow]" >&2
21 |
awk -v group_by
="$group_by" '
22 function date2dow(y, m, d, _t, _i) {
24 # y > 1752, 1 <= m <= 12.
27 # https://en.wikipedia.org/wiki/Determination_of_the_day_of_the_week#Sakamoto%27s_methods
41 _i = int(y + y/4 - y/100 + y/400 + _t[m - 1] + d) % 7
42 _i = _i == 0 ? 7 : _i # Make Sunday last
48 # NOTE: $2 & $3 are specific to oh-my-zsh history output
51 d_fields = split(date, d, "-")
52 t_fields = split(time, t, ":")
53 if (t_fields && d_fields) {
54 # +0 to coerce number from string
59 dow = date2dow(year, month, day)
60 g = group_by == "mon" ? month : dow # dow is default
89 n = group_by == "mon" ? 12 : 7 # dow is default
91 for (gid = 1; gid <= n; gid++) {
92 group = group_by == "mon" ? m[gid] : w[gid]
94 for (hour=0; hour<24; hour++) {
97 for (i = 1; i <= (c * 100) / max; i++)
114 print count[cmd], cmd
121 c = count[NR] = $1 + 0 # + 0 to coerce number from string
127 for (i = 1; i <= NR; i++) {
129 printf "%s %d ", cmd[i], c
130 scaled = (c * 100) / max
131 for (j = 1; j <= scaled; j++)
139 # Top Disk-Using directories
140 # TODO: Consider using numfmt instead of awk
147 sub("^" $1 "\t+", "", path)
154 for (path in paths) {
156 pct = 100 * (size / max)
157 gb = size / 1024 / 1024
158 printf("%6.2f %3d%% %s\n", gb, pct, path)
165 # A slight optimization: head can exit before traversing the full input.
168 # Top Disk-Using Files
170 find "$1" -type f
-printf '%s\t%p\0' \
177 sub("^" $1 "\t+", "", path)
178 gb = size / 1024 / 1024 / 1024
179 printf("%f\t%s\n", gb, path)
183 # Most-recently modified file system objects
186 # - intentionally not quoting the parameters, so that some can be ignored
187 # if not passed, rather than be passed to find as an empty string;
188 # - %T+ is a GNU extension;
189 # - gawk is able to split records on \0, while awk cannot.
190 find $@
-printf '%T@ %T+ %p\0' \
191 |
tee >(gawk
-v RS
='\0' 'END { printf("[INFO] Total found: %d\n", NR); }') \
192 |
sort -z -k 1 -n -r \
193 |
head -n "$(stty size | awk 'NR == 1 {print $1 - 5}')" -z \
196 sub("^" $1 " +", "") # Remove epoch time
197 sub("+", " ") # Blank-out the default separator
198 sub("\\.[0-9]+", "") # Remove fractional seconds
212 pactl info |
awk '/^Default Sink:/ {print $3}'
216 curl
"https://xq-api.voidlinux.org/v1/query/x86_64?q=$1" | jq
'.data'
223 # me: end bold, blink and underline
225 # so: begin standout (reverse video)
228 # us: begin underline
231 LESS_TERMCAP_md
=$
'\e[01;30m' \
232 LESS_TERMCAP_me
=$
'\e[0m' \
233 LESS_TERMCAP_so
=$
'\e[01;44;33m' \
234 LESS_TERMCAP_se
=$
'\e[0m' \
235 LESS_TERMCAP_us
=$
'\e[01;33m' \
236 LESS_TERMCAP_ue
=$
'\e[0m' \
242 cd "$(~/bin/x $@)" ||
kill -INT $$
246 ledit
-l "$(stty size | awk '{print $2}')" ocaml $@
250 cat "$(find ~/arc/doc/HOWTOs -mindepth 1 -maxdepth 1 | sort | fzf)"
254 local -r base_dir
="$1"
258 local -r id
=$
(youtube-dlc
--get-id "$uri")
259 local -r title
=$
(youtube-dlc
--get-title "$uri" |
sed 's/[^А-Яа-яA-Za-z0-9._-]/_/g')
260 local -r dir
="${base_dir}/${title}--${id}"
263 cd "$dir" ||
kill -INT $$
265 youtube-dlc
$opts -c --write-description --write-info-json "$uri"
270 _yt
"${DIR_YOUTUBE_AUDIO}/individual" "$uri" '-f 140'
275 _yt
"${DIR_YOUTUBE_VIDEO}/individual" "$uri"
279 local -r user_type
="$1"
280 local -r user_name
="$2"
282 curl
"https://api.github.com/$user_type/$user_name/repos?page=1&per_page=10000"
286 local -r gh_user_type
="$1"
287 local -r gh_user_name
="$2"
289 local -r gh_dir
="${DIR_GITHUB}/${gh_user_name}"
291 cd "$gh_dir" ||
kill -INT $$
292 gh_fetch_repos
"$gh_user_type" "$gh_user_name" \
293 | jq
--raw-output '.[] | select(.fork | not) | .git_url' \
299 gh_clone
'users' "$1"
307 gh_username
=$
(echo "$1" |
awk -F / '"$1 == "https" && $3 == github.com" {print $4}')
308 gh_dir
="${DIR_GITHUB}/${gh_username}"
310 cd "$gh_dir" ||
kill -INT $$
314 work_log_template
() {
336 mkdir
-p "$DIR_WORK_LOG"
337 local -r file_work_log_today
="${DIR_WORK_LOG}/daily-$(date +%F).md"
338 if [ ! -f "$file_work_log_today" ]
340 work_log_template
> "$file_work_log_today"
342 vim
-c 'set spell' "$file_work_log_today"
347 mkdir
-p "$DIR_NOTES"
348 vim
-c 'set spell' "$DIR_NOTES/$(date +'%Y_%m_%d--%H_%M_%S%z')--$1.md"
352 local _weather_location
354 '') _weather_location
="$WEATHER_LOCATION";;
355 *) _weather_location
="$1"
357 curl
"http://wttr.in/$_weather_location?format=v2"
361 # grep's defintion of a line does not include \r, wile awk's does and
362 # which bluetoothctl outputs
363 awk '/^Device +/ {print $2}' \
364 |
xargs -I% sh
-c 'echo info % | bluetoothctl' \
365 |
awk '/^Device |^\t[A-Z][A-Za-z0-9]+: /'
369 echo 'paired-devices' | bluetoothctl | _bt_devs_infos
373 echo 'devices' | bluetoothctl | _bt_devs_infos
377 local -r stderr
="$(mktemp)"
381 $@
2> >(tee "$stderr")
384 0) urgency
='normal';;
385 *) urgency
='critical'
387 notify-send
-u "$urgency" "Job done: $code" "$(cat $stderr)"
395 width = width ? width : 80
396 ch_left = ch_left ? ch_left : "["
397 ch_right = ch_right ? ch_right : "]"
398 ch_blank = ch_blank ? ch_blank : "-"
399 ch_used = ch_used ? ch_used : "|"
409 cur_scaled = num_scale(cur, max, 1, width)
413 lab ? lab " " : "", \
414 num ? cur "/" max " " : "", \
415 pct ? sprintf("%3.0f%% ", cur / max * 100) : "", \
417 for (i=1; i<=width; i++) {
418 c = i <= cur_scaled ? ch_used : ch_blank
421 printf "%s\n", ch_right
424 function num_scale(src_cur, src_max, dst_min, dst_max) {
425 return dst_min + ((src_cur * (dst_max - dst_min)) / src_max)
438 pct = cur / max * 100
439 printf "%s%s %.2f%%", sep, name, pct
448 curl
--silent --show-error --max-time "${1:=1}" 'https://api.ipify.org' 2>&1
454 if which upower
> /dev
/null
463 / battery/ && device["path"] {
464 device["is_battery"] = 1
468 / percentage:/ && device["is_battery"] {
469 device["battery_percentage"] = $2
470 sub("%$", "", device["battery_percentage"])
475 if (device["is_battery"] && device["path"] == "/org/freedesktop/UPower/devices/DisplayDevice")
476 print device["battery_percentage"], 100, "batt"
486 awk -v unit
="$1" '{printf "%s%s\n", unit, $0}'
490 local -r indent_unit
=' '
500 printf '%stmux\n%ssessions %d, clients %d\n' \
502 "${indent_unit}${indent_unit}" \
503 "$(tmux list-sessions 2> /dev/null | wc -l)" \
504 "$(tmux list-clients 2> /dev/null | wc -l)"
508 printf '%sprocs by user\n' "${indent_unit}"
517 for (user in count_by_user)
518 print count_by_user[user], total, user
522 | indent
"${indent_unit}${indent_unit}"
528 free |
awk '$1 == "Mem:" {print $3, $2, "mem"}'
529 df ~ |
awk 'NR == 2 {print $3, $3 + $4, "disk"}'
532 | bar_gauge
-v width
=60 -v pct
=1 \
534 | indent
"$indent_unit"
538 printf '%smem by proc\n' "$indent_unit"
540 |
awk -v total
="$(free | awk '$1 == "Mem
:" {print $2; exit}')" '
544 n = split(cmd, path, "/") # _may_ be a path
550 for (proc in by_proc)
551 print by_proc[proc], total, proc
555 | indent
"${indent_unit}${indent_unit}"
559 local _dir temp_input label_file label
561 printf '%sthermal\n' "$indent_unit"
562 for _dir
in /sys
/class
/hwmon
/hwmon
*; do
564 find "$_dir"/ -name 'temp*_input' \
565 |
while read -r temp_input
; do
566 label_file
=${temp_input//_input/_label}
567 if [ -f "$label_file" ]; then
568 label
=$
(< "$label_file")
572 awk -v label
="$label" '{
574 label = sprintf(" (%s)", label)
575 printf("%.2f°C%s\n", $1 / 1000, label)
580 | indent
"$indent_unit"
582 | indent
"${indent_unit}${indent_unit}"
585 #local -r internet_addr=$(internet_addr 0.5)
586 #local -r internet_ptr=$(host -W 1 "$internet_addr" | awk 'NR == 1 {print $NF}' )
588 #echo "${indent_unit}internet"
589 #echo "${indent_unit}${indent_unit}$internet_addr $internet_ptr"
590 echo "${indent_unit}if"
591 (ifconfig
; iwconfig
) 2> /dev
/null \
595 sub(":$", "", device)
598 sub("^ESSID:\"", "", _essid)
599 sub("\"$", "", _essid)
600 essid[device] = _essid
605 /^ / && $1 == "inet" {
610 /^ +Link Quality=[0-9]+\/[0-9]+ +Signal level=/ {
611 split($2, lq_parts_eq, "=")
612 split(lq_parts_eq[2], lq_parts_slash, "/")
613 cur = lq_parts_slash[1]
614 max = lq_parts_slash[2]
615 link[device] = cur / max * 100
620 for (device in address)
621 if (device != "lo") {
624 l = l ? sprintf("%.0f%%", l) : "--"
626 print device, address[device], e, l
631 | indent
"${indent_unit}${indent_unit}"
633 # WARN: ensure: $USER ALL=(ALL) NOPASSWD:/bin/netstat
635 echo "${indent_unit}-->"
637 sudo
-n netstat
-tulnp \
638 |
awk -v indent
="${indent_unit}${indent_unit}" '
639 NR > 2 && ((/^tcp/ && proc = $7) || (/^udp/ && proc = $6)) {
642 port = a[split(addr, a, ":")]
643 name = p[split(proc, p, "/")]
645 protocols[protocol] = 1
646 if (!seen[protocol, name, port]++)
647 ports[protocol, name, ++seen[protocol, name]] = port
651 for (protocol in protocols) {
652 printf "%s%s\t", indent, toupper(protocol)
653 for (name in names) {
654 if (n = seen[protocol, name]) {
657 for (i = 1; i <= n; i++) {
658 printf "%s%d", sep, ports[protocol, name, i]
668 echo "${indent_unit}<->"
670 printf '%sTCP: ' "${indent_unit}${indent_unit}"
671 sudo
-n netstat
-tnp \
672 |
awk 'NR > 2 && $6 == "ESTABLISHED" {print $7}' \
673 |
awk -F/ '{print $2}' \
678 # TODO: iptables summary
681 ssh_invalid_by_addr
() {
683 /: Invalid user/ && $5 ~ /^sshd/ {
684 addr=$10 == "port" ? $9 : $10
690 for (addr in by_addr)
691 if ((c = by_addr[addr]) > 1)
692 printf "%d %d %s\n", c, max, addr
696 /var
/log
/auth.log
.1 \
698 | bar_gauge
-v width
="$(stty size | awk '{print $2}')" -v num
=1 -v ch_right
=' ' -v ch_left
=' ' -v ch_blank
=' ' \
702 ssh_invalid_by_day
() {
719 /: Invalid user/ && $5 ~ /^sshd/ {
727 if ((c = by_day[day]) > 1)
728 printf "%d %d %s\n", c, max, day
732 /var
/log
/auth.log
.1 \
734 | bar_gauge
-v width
="$(stty size | awk '{print $2}')" -v num
=1 -v ch_right
=' ' -v ch_left
=' ' -v ch_blank
=' ' \
738 ssh_invalid_by_user
() {
740 /: Invalid user/ && $5 ~ /^sshd/ {
747 for (user in by_user)
748 if ((c = by_user[user]) > 1)
749 printf "%d %d %s\n", c, max, user
753 /var
/log
/auth.log
.1 \
755 | bar_gauge
-v width
="$(stty size | awk '{print $2}')" -v num
=1 -v ch_right
=' ' -v ch_left
=' ' -v ch_blank
=' ' \
763 sub(":$", "", prog[1]) # if there were no [], than : will is left behind
765 }' /var
/log
/syslog
/var
/log
/syslog
.1 \
768 n = split($1, path, "/") # prog may be in path form
776 print count[prog], total, prog
779 | bar_gauge
-v num
=1 -v ch_right
=' ' -v ch_left
=' ' -v ch_blank
=' ' \