+## p : string -> unit
+p() {
+ awk \
+ -v _s="$1" \
+ '
+ BEGIN {_s = tolower(_s)}
+
+ /^[a-zA-Z]/ && tolower($1) ~ _s && NF >= 2 {
+ n++
+ s = $1
+ p = $NF
+ if (NF == 2) {
+ e = ""
+ u = ""
+ } else if (NF == 3) {
+ e = $2
+ u = ""
+ } else {
+ e = $2
+ u = $3
+ } # TODO What would NF > 4 mean?
+
+ printf("%d [O] s:\"%s\", e:\"%s\", u:\"%s\"\n", n, s, e, u) > "/dev/stderr"
+ if (match(u, "@")) {
+ tmp = e
+ e = u
+ u = tmp
+ printf("%d [C] s:\"%s\", e:\"%s\", u:\"%s\"\n", n, s, e, u) > "/dev/stderr"
+ }
+
+ printf "%s", p # XXX Intentionally avoiding newline in the result.
+ }
+ ' \
+ ~/._p/p \
+ | xsel -i -b -t 30000
+}
+
+## web search
+## ws : string -> unit
+ local line search_string0 search_string
+
+ search_string0="$*"
+ case "$search_string0" in
+ '')
+ while read -r line; do
+ search_string="${search_string} ${line}"
+ done;;
+ *)
+ search_string="$search_string0";;
+ esac
+
+ firefox --search "$search_string"
shell_activity_report() {
# TODO: optional concrete number output
# TODO: optional combinations of granularities: hour, weekday, month, year
shell_activity_report() {
# TODO: optional concrete number output
# TODO: optional combinations of granularities: hour, weekday, month, year
-# Top Disk-Using directories
-# TODO: Consider using numfmt instead of awk
+## Top Disk-Using directories
+## TODO: Consider using numfmt instead of awk
+## tdu : path-string -> (size:number * directory:path-string) list
# - %T+ is a GNU extension;
# - gawk is able to split records on \0, while awk cannot.
# - %T+ is a GNU extension;
# - gawk is able to split records on \0, while awk cannot.
| tee >(gawk -v RS='\0' 'END { printf("[INFO] Total found: %d\n", NR); }') \
| sort -z -k 1 -n -r \
| head -n "$(stty size | awk 'NR == 1 {print $1 - 5}')" -z \
| tee >(gawk -v RS='\0' 'END { printf("[INFO] Total found: %d\n", NR); }') \
| sort -z -k 1 -n -r \
| head -n "$(stty size | awk 'NR == 1 {print $1 - 5}')" -z \
_bt_devs_infos() {
# grep's defintion of a line does not include \r, wile awk's does and
# which bluetoothctl outputs
_bt_devs_infos() {
# grep's defintion of a line does not include \r, wile awk's does and
# which bluetoothctl outputs
sudo -n netstat -tulnp \
| awk -v indent="${indent_unit}${indent_unit}" '
NR > 2 && ((/^tcp/ && proc = $7) || (/^udp/ && proc = $6)) {
sudo -n netstat -tulnp \
| awk -v indent="${indent_unit}${indent_unit}" '
NR > 2 && ((/^tcp/ && proc = $7) || (/^udp/ && proc = $6)) {
- protocol = $1
- addr = $4
- port = a[split(addr, a, ":")]
- name = p[split(proc, p, "/")]
- names[name] = 1
- protocols[protocol] = 1
- if (!seen[protocol, name, port]++)
- ports[protocol, name, ++seen[protocol, name]] = port
- }
-
- END {
- for (protocol in protocols) {
- printf "%s%s\t", indent, toupper(protocol)
- for (name in names) {
- if (n = seen[protocol, name]) {
- sep = ""
- printf "%s:", name
- for (i = 1; i <= n; i++) {
- printf "%s%d", sep, ports[protocol, name, i]
- sep = ","
- }
- printf " "
- }
- }
- printf "\n"
- }
- }'
+ protocol = $1
+ addr = $4
+ port = a[split(addr, a, ":")]
+ name = p[split(proc, p, "/")]
+ names[name] = 1
+ protocols[protocol] = 1
+ if (!seen[protocol, name, port]++)
+ ports[protocol, name, ++seen[protocol, name]] = port
+ }
+
+ END {
+ for (protocol in protocols) {
+ printf "%s%s\t", indent, toupper(protocol)
+ for (name in names) {
+ if (n = seen[protocol, name]) {
+ sep = ""
+ printf "%s:", name
+ for (i = 1; i <= n; i++) {
+ printf "%s%d", sep, ports[protocol, name, i]
+ sep = ","
+ }
+ printf " "
+ }
+ }
+ printf "\n"
+ }
+ }'
- BEGIN {
- m["Jan"] = "01"
- m["Feb"] = "02"
- m["Mar"] = "03"
- m["Apr"] = "04"
- m["May"] = "05"
- m["Jun"] = "06"
- m["Jul"] = "07"
- m["Aug"] = "08"
- m["Sep"] = "09"
- m["Oct"] = "10"
- m["Nov"] = "11"
- m["Dec"] = "12"
- }
-
- /: Invalid user/ && $5 ~ /^sshd/ {
- day = m[$1] "-" $2
- max++
- by_day[day]++
- }
-
- END {
- for (day in by_day)
- if ((c = by_day[day]) > 1)
- printf "%d %d %s\n", c, max, day
- }
+ BEGIN {
+ m["Jan"] = "01"
+ m["Feb"] = "02"
+ m["Mar"] = "03"
+ m["Apr"] = "04"
+ m["May"] = "05"
+ m["Jun"] = "06"
+ m["Jul"] = "07"
+ m["Aug"] = "08"
+ m["Sep"] = "09"
+ m["Oct"] = "10"
+ m["Nov"] = "11"
+ m["Dec"] = "12"
+ }
+
+ /: Invalid user/ && $5 ~ /^sshd/ {
+ day = m[$1] "-" $2
+ max++
+ by_day[day]++
+ }
+
+ END {
+ for (day in by_day)
+ if ((c = by_day[day]) > 1)
+ printf "%d %d %s\n", c, max, day
+ }