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)
156 # Top Disk-Using Files
158 find "$1" -type f
-printf '%s\t%p\0' \
165 sub("^" $1 "\t+", "", path)
166 gb = size / 1024 / 1024 / 1024
167 printf("%f\t%s\n", gb, path)
171 # Most-recently modified file system objects
174 # - intentionally not quoting the parameters, so that some can be ignored
175 # if not passed, rather than be passed to find as an empty string;
176 # - %T+ is a GNU extension;
177 # - gawk is able to split records on \0, while awk cannot.
178 find $@
-printf '%T@ %T+ %p\0' \
179 |
tee >(gawk
-v RS
='\0' 'END { printf("[INFO] Total found: %d\n", NR); }') \
180 |
sort -z -k 1 -n -r \
181 |
head -n "$(stty size | awk 'NR == 1 {print $1 - 5}')" -z \
184 sub("^" $1 " +", "") # Remove epoch time
185 sub("+", " ") # Blank-out the default separator
186 sub("\\.[0-9]+", "") # Remove fractional seconds
200 pactl info |
awk '/^Default Sink:/ {print $3}'
204 curl
"https://xq-api.voidlinux.org/v1/query/x86_64?q=$1" | jq
'.data'
211 # me: end bold, blink and underline
213 # so: begin standout (reverse video)
216 # us: begin underline
219 LESS_TERMCAP_md
=$
'\e[01;30m' \
220 LESS_TERMCAP_me
=$
'\e[0m' \
221 LESS_TERMCAP_so
=$
'\e[01;44;33m' \
222 LESS_TERMCAP_se
=$
'\e[0m' \
223 LESS_TERMCAP_us
=$
'\e[01;33m' \
224 LESS_TERMCAP_ue
=$
'\e[0m' \
229 cd "$(~/bin/experiment $@)" ||
kill -INT $$
233 ledit
-l "$(stty size | awk '{print $2}')" ocaml $@
237 cat "$(find ~/Archives/Documents/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" '-f 140' "$uri"
262 _yt
"${DIR_YOUTUBE_VIDEO}/individual" "$uri"
266 curl
"https://api.github.com/$1/$2/repos?page=1&per_page=10000"
270 local -r gh_user_type
="$1"
271 local -r gh_user_name
="$2"
273 local -r gh_dir
="${DIR_GITHUB}/${gh_user_name}"
275 cd "$gh_dir" ||
kill -INT $$
276 gh_fetch_repos
"$gh_user_type" "$gh_user_name" \
277 | jq
--raw-output '.[] | select(.fork | not) | .git_url' \
283 gh_clone
'users' "$1"
291 gh_username
=$
(echo "$1" |
awk -F / '"$1 == "https" && $3 == github.com" {print $4}')
292 gh_dir
="${DIR_GITHUB}/${gh_username}"
294 cd "$gh_dir" ||
kill -INT $$
298 work_log_template
() {
320 mkdir
-p "$DIR_WORK_LOG"
321 local -r file_work_log_today
="${DIR_WORK_LOG}/$(date +%F).md"
322 if [ ! -f "$file_work_log_today" ]
324 work_log_template
> "$file_work_log_today"
326 vim
-c 'set spell' "$file_work_log_today"
331 mkdir
-p "$DIR_NOTES"
332 vim
-c 'set spell' "$DIR_NOTES/$(date +'%Y_%m_%d--%H_%M_%S%z')--$1.md"
336 local _weather_location
338 '') _weather_location
="$WEATHER_LOCATION";;
339 *) _weather_location
="$1"
341 curl
"http://wttr.in/$_weather_location?format=v2"
345 bluetoothctl
-- paired-devices \
347 |
xargs bluetoothctl
-- info
351 bluetoothctl
-- devices \
353 |
xargs bluetoothctl
-- info
357 local -r stderr
="$(mktemp)"
361 $@
2> >(tee "$stderr")
364 0) urgency
='normal';;
365 *) urgency
='critical'
367 notify-send
-u "$urgency" "Job done: $code" "$(cat $stderr)"
374 awk -v width
="$width" '
380 u = num_scale(cur, max, 1, width)
382 printf "%s%s[", lab, lab ? " " : ""
383 for (i=1; i<=width; i++) {
384 c = i <= u ? "|" : "-"
390 function num_scale(src_cur, src_max, dst_min, dst_max) {
391 return dst_min + ((src_cur * (dst_max - dst_min)) / src_max)
406 / battery/ && device["path"] {
407 device["is_battery"] = 1
411 / percentage:/ && device["is_battery"] {
412 device["battery_percentage"] = $2
413 sub("%$", "", device["battery_percentage"])
418 if (device["is_battery"] && device["path"] == "/org/freedesktop/UPower/devices/DisplayDevice")
419 print device["battery_percentage"], 100, "batt"
428 awk -v unit
="$1" '{printf "%s%s\n", unit, $0}'
432 local -r bar_width
='60'
433 local -r indent_unit
=' '
441 printf 'tmux sessions: %d\n' "$(tmux ls 2> /dev/null | wc -l)"
447 free |
awk '$1 == "Mem:" {print $3, $2, "mem"}'
448 df ~ |
awk 'NR == 2 {print $3, $3 + $4, "disk"}'
451 | bar_gauge
"$bar_width" \
453 | indent
"$indent_unit"
458 echo "${indent_unit}if"
459 (ifconfig
; iwconfig
) 2> /dev
/null \
463 sub(":$", "", device)
466 sub("^ESSID:\"", "", _essid)
467 sub("\"$", "", _essid)
468 essid[device] = _essid
473 /^ / && $1 == "inet" {
478 /^ +Link Quality=[0-9]+\/[0-9]+ +Signal level=/ {
479 split($2, lq_parts_eq, "=")
480 split(lq_parts_eq[2], lq_parts_slash, "/")
481 cur = lq_parts_slash[1]
482 max = lq_parts_slash[2]
483 link[device] = cur / max * 100
488 for (device in address)
489 if (device != "lo") {
492 l = l ? sprintf("%.0f%%", l) : "--"
494 print device, address[device], e, l
499 | indent
"${indent_unit}${indent_unit}"
501 # WARN: ensure: $USER ALL=(ALL) NOPASSWD:/bin/netstat
503 echo "${indent_unit}-->"
505 printf '%sUDP: ' "${indent_unit}${indent_unit}"
506 sudo
-n netstat
-ulnp \
507 |
awk 'NR > 2 {print $6}' \
508 |
awk -F/ '{print $2}' \
513 printf '%sTCP: ' "${indent_unit}${indent_unit}"
514 sudo
-n netstat
-tlnp \
515 |
awk 'NR > 2 {print $7}' \
516 |
awk -F/ '{print $2}' \
521 echo "${indent_unit}<->"
523 printf '%sTCP: ' "${indent_unit}${indent_unit}"
524 sudo
-n netstat
-tnp \
525 |
awk 'NR > 2 && $6 == "ESTABLISHED" {print $7}' \
526 |
awk -F/ '{print $2}' \
This page took 0.157339 seconds and 5 git commands to generate.