5 local line search_string0 search_string
8 case "$search_string0" in
10 while read -r line
; do
11 search_string
="${search_string} ${line}"
14 search_string
="$search_string0";;
17 firefox
--search "$search_string"
21 local -r word
=$
(fzf
< /usr
/share
/dict
/words
)
25 shell_activity_report
() {
26 # TODO: optional concrete number output
27 # TODO: optional combinations of granularities: hour, weekday, month, year
34 echo "Usage: $0 [mon|dow]" >&2
38 |
awk -v group_by
="$group_by" '
39 function date2dow(y, m, d, _t, _i) {
41 # y > 1752, 1 <= m <= 12.
44 # https://en.wikipedia.org/wiki/Determination_of_the_day_of_the_week#Sakamoto%27s_methods
58 _i = int(y + y/4 - y/100 + y/400 + _t[m - 1] + d) % 7
59 _i = _i == 0 ? 7 : _i # Make Sunday last
65 # NOTE: $2 & $3 are specific to oh-my-zsh history output
68 d_fields = split(date, d, "-")
69 t_fields = split(time, t, ":")
70 if (t_fields && d_fields) {
71 # +0 to coerce number from string
76 dow = date2dow(year, month, day)
77 g = group_by == "mon" ? month : dow # dow is default
106 n = group_by == "mon" ? 12 : 7 # dow is default
108 for (gid = 1; gid <= n; gid++) {
109 group = group_by == "mon" ? m[gid] : w[gid]
110 printf "%s\n", group;
111 for (hour=0; hour<24; hour++) {
114 for (i = 1; i <= (c * 100) / max; i++)
131 print count[cmd], cmd
138 c = count[NR] = $1 + 0 # + 0 to coerce number from string
144 for (i = 1; i <= NR; i++) {
146 printf "%s %d ", cmd[i], c
147 scaled = (c * 100) / max
148 for (j = 1; j <= scaled; j++)
156 # Top Disk-Using directories
157 # TODO: Consider using numfmt instead of awk
164 sub("^" $1 "\t+", "", path)
171 for (path in paths) {
173 pct = 100 * (size / max)
174 gb = size / 1024 / 1024
175 printf("%6.2f %3d%% %s\n", gb, pct, path)
182 # A slight optimization: head can exit before traversing the full input.
185 # Top Disk-Using Files
187 find "$1" -type f
-printf '%s\t%p\0' \
194 sub("^" $1 "\t+", "", path)
195 gb = size / 1024 / 1024 / 1024
196 printf("%f\t%s\n", gb, path)
200 # Most-recently modified file system objects
203 # - intentionally not quoting the parameters, so that some can be ignored
204 # if not passed, rather than be passed to find as an empty string;
205 # - %T+ is a GNU extension;
206 # - gawk is able to split records on \0, while awk cannot.
207 find $@
-printf '%T@ %T+ %p\0' \
208 |
tee >(gawk
-v RS
='\0' 'END { printf("[INFO] Total found: %d\n", NR); }') \
209 |
sort -z -k 1 -n -r \
210 |
head -n "$(stty size | awk 'NR == 1 {print $1 - 5}')" -z \
213 sub("^" $1 " +", "") # Remove epoch time
214 sub("+", " ") # Blank-out the default separator
215 sub("\\.[0-9]+", "") # Remove fractional seconds
229 pactl info |
awk '/^Default Sink:/ {print $3}'
233 curl
"https://xq-api.voidlinux.org/v1/query/x86_64?q=$1" | jq
'.data'
240 # me: end bold, blink and underline
242 # so: begin standout (reverse video)
245 # us: begin underline
248 LESS_TERMCAP_md
=$
'\e[01;30m' \
249 LESS_TERMCAP_me
=$
'\e[0m' \
250 LESS_TERMCAP_so
=$
'\e[01;44;33m' \
251 LESS_TERMCAP_se
=$
'\e[0m' \
252 LESS_TERMCAP_us
=$
'\e[01;33m' \
253 LESS_TERMCAP_ue
=$
'\e[0m' \
259 cd "$(~/bin/x $@)" ||
kill -INT $$
263 ledit
-l "$(stty size | awk '{print $2}')" ocaml $@
267 cat "$(find ~/arc/doc/HOWTOs -mindepth 1 -maxdepth 1 | sort | fzf)"
271 local -r base_dir
="$1"
275 local -r id
=$
(youtube-dlc
--get-id "$uri")
276 local -r title
=$
(youtube-dlc
--get-title "$uri" |
sed 's/[^А-Яа-яA-Za-z0-9._-]/_/g')
277 local -r dir
="${base_dir}/${title}--${id}"
280 cd "$dir" ||
kill -INT $$
282 youtube-dlc
$opts -c --write-description --write-info-json "$uri"
287 _yt
"${DIR_YOUTUBE_AUDIO}/individual" "$uri" '-f 140'
292 _yt
"${DIR_YOUTUBE_VIDEO}/individual" "$uri"
296 local -r user_type
="$1"
297 local -r user_name
="$2"
299 curl
"https://api.github.com/$user_type/$user_name/repos?page=1&per_page=10000"
303 local -r gh_user_type
="$1"
304 local -r gh_user_name
="$2"
306 local -r gh_dir
="${DIR_GITHUB}/${gh_user_name}"
308 cd "$gh_dir" ||
kill -INT $$
309 gh_fetch_repos
"$gh_user_type" "$gh_user_name" \
310 | jq
--raw-output '.[] | select(.fork | not) | .git_url' \
316 gh_clone
'users' "$1"
324 gh_username
=$
(echo "$1" |
awk -F / '"$1 == "https" && $3 == github.com" {print $4}')
325 gh_dir
="${DIR_GITHUB}/${gh_username}"
327 cd "$gh_dir" ||
kill -INT $$
331 work_log_template
() {
353 mkdir
-p "$DIR_WORK_LOG"
354 local -r file_work_log_today
="${DIR_WORK_LOG}/daily-$(date +%F).md"
355 if [ ! -f "$file_work_log_today" ]
357 work_log_template
> "$file_work_log_today"
359 vim
-c 'set spell' "$file_work_log_today"
364 mkdir
-p "$DIR_NOTES"
365 vim
-c 'set spell' "$DIR_NOTES/$(date +'%Y_%m_%d--%H_%M_%S%z')--$1.md"
369 local _weather_location
371 '') _weather_location
="$WEATHER_LOCATION";;
372 *) _weather_location
="$1"
374 curl
"http://wttr.in/$_weather_location?format=v2"
378 # grep's defintion of a line does not include \r, wile awk's does and
379 # which bluetoothctl outputs
380 awk '/^Device +/ {print $2}' \
381 |
xargs -I% sh
-c 'echo info % | bluetoothctl' \
382 |
awk '/^Device |^\t[A-Z][A-Za-z0-9]+: /'
386 echo 'paired-devices' | bluetoothctl | _bt_devs_infos
390 echo 'devices' | bluetoothctl | _bt_devs_infos
394 local -r stderr
="$(mktemp)"
398 $@
2> >(tee "$stderr")
401 0) urgency
='normal';;
402 *) urgency
='critical'
404 notify-send
-u "$urgency" "Job done: $code" "$(cat $stderr)"
412 width = width ? width : 80
413 ch_left = ch_left ? ch_left : "["
414 ch_right = ch_right ? ch_right : "]"
415 ch_blank = ch_blank ? ch_blank : "-"
416 ch_used = ch_used ? ch_used : "|"
426 cur_scaled = num_scale(cur, max, 1, width)
430 lab ? lab " " : "", \
431 num ? cur "/" max " " : "", \
432 pct ? sprintf("%3.0f%% ", cur / max * 100) : "", \
434 for (i=1; i<=width; i++) {
435 c = i <= cur_scaled ? ch_used : ch_blank
438 printf "%s\n", ch_right
441 function num_scale(src_cur, src_max, dst_min, dst_max) {
442 return dst_min + ((src_cur * (dst_max - dst_min)) / src_max)
455 pct = cur / max * 100
456 printf "%s%s %.2f%%", sep, name, pct
465 curl
--silent --show-error --max-time "${1:=1}" 'https://api.ipify.org' 2>&1
471 if which upower
> /dev
/null
480 / battery/ && device["path"] {
481 device["is_battery"] = 1
485 / percentage:/ && device["is_battery"] {
486 device["battery_percentage"] = $2
487 sub("%$", "", device["battery_percentage"])
492 if (device["is_battery"] && device["path"] == "/org/freedesktop/UPower/devices/DisplayDevice")
493 print device["battery_percentage"], 100, "batt"
503 awk -v unit
="$1" '{printf "%s%s\n", unit, $0}'
507 local -r indent_unit
=' '
517 printf '%stmux\n%ssessions %d, clients %d\n' \
519 "${indent_unit}${indent_unit}" \
520 "$(tmux list-sessions 2> /dev/null | wc -l)" \
521 "$(tmux list-clients 2> /dev/null | wc -l)"
525 printf '%sprocs by user\n' "${indent_unit}"
534 for (user in count_by_user)
535 print count_by_user[user], total, user
539 | indent
"${indent_unit}${indent_unit}"
545 free |
awk '$1 == "Mem:" {print $3, $2, "mem"}'
546 df ~ |
awk 'NR == 2 {print $3, $3 + $4, "disk"}'
549 | bar_gauge
-v width
=60 -v pct
=1 \
551 | indent
"$indent_unit"
555 printf '%smem by proc\n' "$indent_unit"
557 |
awk -v total
="$(free | awk '$1 == "Mem
:" {print $2; exit}')" '
565 for (proc in by_proc)
566 print by_proc[proc], total, proc
570 | indent
"${indent_unit}${indent_unit}"
574 local _dir temp_input label_file label
576 printf '%sthermal\n' "$indent_unit"
577 for _dir
in /sys
/class
/hwmon
/hwmon
*; do
579 find "$_dir"/ -name 'temp*_input' \
580 |
while read -r temp_input
; do
581 label_file
=${temp_input//_input/_label}
582 if [ -f "$label_file" ]; then
583 label
=$
(< "$label_file")
587 awk -v label
="$label" '{
589 label = sprintf(" (%s)", label)
590 printf("%.2f°C%s\n", $1 / 1000, label)
595 | indent
"$indent_unit"
597 | indent
"${indent_unit}${indent_unit}"
600 #local -r internet_addr=$(internet_addr 0.5)
601 #local -r internet_ptr=$(host -W 1 "$internet_addr" | awk 'NR == 1 {print $NF}' )
603 #echo "${indent_unit}internet"
604 #echo "${indent_unit}${indent_unit}$internet_addr $internet_ptr"
605 echo "${indent_unit}if"
606 (ifconfig
; iwconfig
) 2> /dev
/null \
610 sub(":$", "", device)
613 sub("^ESSID:\"", "", _essid)
614 sub("\"$", "", _essid)
615 essid[device] = _essid
620 /^ / && $1 == "inet" {
625 /^ +Link Quality=[0-9]+\/[0-9]+ +Signal level=/ {
626 split($2, lq_parts_eq, "=")
627 split(lq_parts_eq[2], lq_parts_slash, "/")
628 cur = lq_parts_slash[1]
629 max = lq_parts_slash[2]
630 link[device] = cur / max * 100
635 for (device in address)
636 if (device != "lo") {
639 l = l ? sprintf("%.0f%%", l) : "--"
641 print device, address[device], e, l
646 | indent
"${indent_unit}${indent_unit}"
648 # WARN: ensure: $USER ALL=(ALL) NOPASSWD:/bin/netstat
650 echo "${indent_unit}-->"
652 sudo
-n netstat
-tulnp \
653 |
awk -v indent
="${indent_unit}${indent_unit}" '
654 NR > 2 && ((/^tcp/ && proc = $7) || (/^udp/ && proc = $6)) {
657 port = a[split(addr, a, ":")]
658 name = p[split(proc, p, "/")]
660 protocols[protocol] = 1
661 if (!seen[protocol, name, port]++)
662 ports[protocol, name, ++seen[protocol, name]] = port
666 for (protocol in protocols) {
667 printf "%s%s\t", indent, toupper(protocol)
668 for (name in names) {
669 if (n = seen[protocol, name]) {
672 for (i = 1; i <= n; i++) {
673 printf "%s%d", sep, ports[protocol, name, i]
683 echo "${indent_unit}<->"
685 printf '%sTCP\t' "${indent_unit}${indent_unit}"
686 sudo
-n netstat
-tnp \
687 |
awk 'NR > 2 && $6 == "ESTABLISHED" {print $7}' \
688 |
awk '{sub("^[0-9]+/", ""); print}' \
693 # TODO: iptables summary
696 ssh_invalid_by_addr
() {
698 /: Invalid user/ && $5 ~ /^sshd/ {
699 addr=$10 == "port" ? $9 : $10
705 for (addr in by_addr)
706 if ((c = by_addr[addr]) > 1)
707 printf "%d %d %s\n", c, max, addr
711 /var
/log
/auth.log
.1 \
713 | bar_gauge
-v width
="$(stty size | awk '{print $2}')" -v num
=1 -v ch_right
=' ' -v ch_left
=' ' -v ch_blank
=' ' \
717 ssh_invalid_by_day
() {
734 /: Invalid user/ && $5 ~ /^sshd/ {
742 if ((c = by_day[day]) > 1)
743 printf "%d %d %s\n", c, max, day
747 /var
/log
/auth.log
.1 \
749 | bar_gauge
-v width
="$(stty size | awk '{print $2}')" -v num
=1 -v ch_right
=' ' -v ch_left
=' ' -v ch_blank
=' ' \
753 ssh_invalid_by_user
() {
755 /: Invalid user/ && $5 ~ /^sshd/ {
762 for (user in by_user)
763 if ((c = by_user[user]) > 1)
764 printf "%d %d %s\n", c, max, user
768 /var
/log
/auth.log
.1 \
770 | bar_gauge
-v width
="$(stty size | awk '{print $2}')" -v num
=1 -v ch_right
=' ' -v ch_left
=' ' -v ch_blank
=' ' \
778 sub(":$", "", prog[1]) # if there were no [], than : will is left behind
780 }' /var
/log
/syslog
/var
/log
/syslog
.1 \
783 n = split($1, path, "/") # prog may be in path form
791 print count[prog], total, prog
794 | bar_gauge
-v num
=1 -v ch_right
=' ' -v ch_left
=' ' -v ch_blank
=' ' \