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
149 sub("^" $1 "\t+", "", path)
150 gb = size / 1024 / 1024
151 printf("%f\t%s\n", gb, path)
155 # Top Disk-Using Files
157 find "$1" -type f
-printf '%s\t%p\0' \
164 sub("^" $1 "\t+", "", path)
165 gb = size / 1024 / 1024 / 1024
166 printf("%f\t%s\n", gb, path)
170 # Most-recently modified file system objects
173 # - intentionally not quoting the parameters, so that some can be ignored
174 # if not passed, rather than be passed to find as an empty string;
175 # - %T+ is a GNU extension;
176 # - gawk is able to split records on \0, while awk cannot.
177 find $@
-printf '%T@ %T+ %p\0' \
178 |
tee >(gawk
-v RS
='\0' 'END { printf("[INFO] Total found: %d\n", NR); }') \
179 |
sort -z -k 1 -n -r \
180 |
head -n "$(stty size | awk 'NR == 1 {print $1 - 5}')" -z \
183 sub("^" $1 " +", "") # Remove epoch time
184 sub("+", " ") # Blank-out the default separator
185 sub("\\.[0-9]+", "") # Remove fractional seconds
199 pactl info |
awk '/^Default Sink:/ {print $3}'
203 curl
"https://xq-api.voidlinux.org/v1/query/x86_64?q=$1" | jq
'.data'
210 # me: end bold, blink and underline
212 # so: begin standout (reverse video)
215 # us: begin underline
218 LESS_TERMCAP_md
=$
'\e[01;30m' \
219 LESS_TERMCAP_me
=$
'\e[0m' \
220 LESS_TERMCAP_so
=$
'\e[01;44;33m' \
221 LESS_TERMCAP_se
=$
'\e[0m' \
222 LESS_TERMCAP_us
=$
'\e[01;33m' \
223 LESS_TERMCAP_ue
=$
'\e[0m' \
229 cd "$(~/bin/x $@)" ||
kill -INT $$
233 ledit
-l "$(stty size | awk '{print $2}')" ocaml $@
237 cat "$(find ~/arc/doc/HOWTOs -mindepth 1 -maxdepth 1 | sort | fzf)"
241 local -r base_dir
="$1"
245 local -r id
=$
(youtube-dlc
--get-id "$uri")
246 local -r title
=$
(youtube-dlc
--get-title "$uri" |
sed 's/[^A-Za-z0-9._-]/_/g')
247 local -r dir
="${base_dir}/${title}--${id}"
250 cd "$dir" ||
kill -INT $$
252 youtube-dlc
$opts -c --write-description --write-info-json "$uri"
257 _yt
"${DIR_YOUTUBE_AUDIO}/individual" "$uri" '-f 140'
262 _yt
"${DIR_YOUTUBE_VIDEO}/individual" "$uri"
266 local -r user_type
="$1"
267 local -r user_name
="$2"
269 curl
"https://api.github.com/$user_type/$user_name/repos?page=1&per_page=10000"
273 local -r gh_user_type
="$1"
274 local -r gh_user_name
="$2"
276 local -r gh_dir
="${DIR_GITHUB}/${gh_user_name}"
278 cd "$gh_dir" ||
kill -INT $$
279 gh_fetch_repos
"$gh_user_type" "$gh_user_name" \
280 | jq
--raw-output '.[] | select(.fork | not) | .git_url' \
286 gh_clone
'users' "$1"
294 gh_username
=$
(echo "$1" |
awk -F / '"$1 == "https" && $3 == github.com" {print $4}')
295 gh_dir
="${DIR_GITHUB}/${gh_username}"
297 cd "$gh_dir" ||
kill -INT $$
301 work_log_template
() {
323 mkdir
-p "$DIR_WORK_LOG"
324 local -r file_work_log_today
="${DIR_WORK_LOG}/$(date +%F).md"
325 if [ ! -f "$file_work_log_today" ]
327 work_log_template
> "$file_work_log_today"
329 vim
-c 'set spell' "$file_work_log_today"
334 mkdir
-p "$DIR_NOTES"
335 vim
-c 'set spell' "$DIR_NOTES/$(date +'%Y_%m_%d--%H_%M_%S%z')--$1.md"
339 local _weather_location
341 '') _weather_location
="$WEATHER_LOCATION";;
342 *) _weather_location
="$1"
344 curl
"http://wttr.in/$_weather_location?format=v2"
348 # grep's defintion of a line does not include \r, wile awk's does and
349 # which bluetoothctl outputs
350 awk '/^Device +/ {print $2}' \
351 |
xargs -I% sh
-c 'echo info % | bluetoothctl' \
352 |
awk '/^Device |^\t[A-Z][A-Za-z0-9]+: /'
356 echo 'paired-devices' | bluetoothctl | _bt_devs_infos
360 echo 'devices' | bluetoothctl | _bt_devs_infos
364 local -r stderr
="$(mktemp)"
368 $@
2> >(tee "$stderr")
371 0) urgency
='normal';;
372 *) urgency
='critical'
374 notify-send
-u "$urgency" "Job done: $code" "$(cat $stderr)"
382 width = width ? width : 80
383 ch_left = ch_left ? ch_left : "["
384 ch_right = ch_right ? ch_right : "]"
385 ch_blank = ch_blank ? ch_blank : "-"
386 ch_used = ch_used ? ch_used : "|"
396 cur_scaled = num_scale(cur, max, 1, width)
400 lab ? lab " " : "", \
401 num ? cur "/" max " " : "", \
402 pct ? sprintf("%3.0f%% ", cur / max * 100) : "", \
404 for (i=1; i<=width; i++) {
405 c = i <= cur_scaled ? ch_used : ch_blank
408 printf "%s\n", ch_right
411 function num_scale(src_cur, src_max, dst_min, dst_max) {
412 return dst_min + ((src_cur * (dst_max - dst_min)) / src_max)
425 pct = cur / max * 100
426 printf "%s%s %.2f%%", sep, name, pct
435 curl
--silent --show-error --max-time "${1:=1}" 'https://api.ipify.org' 2>&1
441 if which upower
> /dev
/null
450 / battery/ && device["path"] {
451 device["is_battery"] = 1
455 / percentage:/ && device["is_battery"] {
456 device["battery_percentage"] = $2
457 sub("%$", "", device["battery_percentage"])
462 if (device["is_battery"] && device["path"] == "/org/freedesktop/UPower/devices/DisplayDevice")
463 print device["battery_percentage"], 100, "batt"
473 awk -v unit
="$1" '{printf "%s%s\n", unit, $0}'
477 local -r indent_unit
=' '
487 printf '%stmux\n%ssessions %d, clients %d\n' \
489 "${indent_unit}${indent_unit}" \
490 "$(tmux list-sessions 2> /dev/null | wc -l)" \
491 "$(tmux list-clients 2> /dev/null | wc -l)"
495 printf '%sprocs by user\n' "${indent_unit}"
504 for (user in count_by_user)
505 print count_by_user[user], total, user
509 | indent
"${indent_unit}${indent_unit}"
515 free |
awk '$1 == "Mem:" {print $3, $2, "mem"}'
516 df ~ |
awk 'NR == 2 {print $3, $3 + $4, "disk"}'
519 | bar_gauge
-v width
=60 -v pct
=1 \
521 | indent
"$indent_unit"
525 printf '%smem by proc\n' "$indent_unit"
527 |
awk -v total
="$(free | awk '$1 == "Mem
:" {print $2; exit}')" '
531 n = split(cmd, path, "/") # _may_ be a path
537 for (proc in by_proc)
538 print by_proc[proc], total, proc
542 | indent
"${indent_unit}${indent_unit}"
546 printf '%sthermal\n' "$indent_unit"
547 for _dir
in /sys
/class
/thermal
/thermal_zone
*
549 printf '%s %.2f C\n' \
550 $
(cat "$_dir"/type) \
551 $
(( $
(cat "$_dir"/temp
) / 1000 ))
554 | indent
"${indent_unit}${indent_unit}"
557 local -r internet_addr
=$
(internet_addr
0.5)
558 local -r internet_ptr
=$
(host -W 1 "$internet_addr" |
awk 'NR == 1 {print $NF}' )
560 echo "${indent_unit}internet"
561 echo "${indent_unit}${indent_unit}$internet_addr $internet_ptr"
562 echo "${indent_unit}if"
563 (ifconfig
; iwconfig
) 2> /dev
/null \
567 sub(":$", "", device)
570 sub("^ESSID:\"", "", _essid)
571 sub("\"$", "", _essid)
572 essid[device] = _essid
577 /^ / && $1 == "inet" {
582 /^ +Link Quality=[0-9]+\/[0-9]+ +Signal level=/ {
583 split($2, lq_parts_eq, "=")
584 split(lq_parts_eq[2], lq_parts_slash, "/")
585 cur = lq_parts_slash[1]
586 max = lq_parts_slash[2]
587 link[device] = cur / max * 100
592 for (device in address)
593 if (device != "lo") {
596 l = l ? sprintf("%.0f%%", l) : "--"
598 print device, address[device], e, l
603 | indent
"${indent_unit}${indent_unit}"
605 # WARN: ensure: $USER ALL=(ALL) NOPASSWD:/bin/netstat
607 echo "${indent_unit}-->"
609 sudo
-n netstat
-tulnp \
610 |
awk -v indent
="${indent_unit}${indent_unit}" '
611 NR > 2 && ((/^tcp/ && proc = $7) || (/^udp/ && proc = $6)) {
614 port = a[split(addr, a, ":")]
615 name = p[split(proc, p, "/")]
617 protocols[protocol] = 1
618 if (!seen[protocol, name, port]++)
619 ports[protocol, name, ++seen[protocol, name]] = port
623 for (protocol in protocols) {
624 printf "%s%s\t", indent, toupper(protocol)
625 for (name in names) {
626 if (n = seen[protocol, name]) {
629 for (i = 1; i <= n; i++) {
630 printf "%s%d", sep, ports[protocol, name, i]
640 echo "${indent_unit}<->"
642 printf '%sTCP: ' "${indent_unit}${indent_unit}"
643 sudo
-n netstat
-tnp \
644 |
awk 'NR > 2 && $6 == "ESTABLISHED" {print $7}' \
645 |
awk -F/ '{print $2}' \
650 # TODO: iptables summary
653 ssh_invalid_attempts_from
() {
655 /: Invalid user/ && $5 ~ /^sshd/ {
657 addr=$10 == "port" ? $9 : $10
664 if ((c = curr[addr]) > 1)
669 /var
/log
/auth.log
.1 \
671 | bar_gauge
-v width
="$(stty size | awk '{print $2}')" -v num
=1 -v ch_right
=' ' -v ch_left
=' ' -v ch_blank
=' ' \
679 sub(":$", "", prog[1]) # if there were no [], than : will is left behind
681 }' /var
/log
/syslog
/var
/log
/syslog
.1 \
684 n = split($1, path, "/") # prog may be in path form
692 print count[prog], total, prog
695 | bar_gauge
-v num
=1 -v ch_right
=' ' -v ch_left
=' ' -v ch_blank
=' ' \