various updates
[distro-setup] / brc
diff --git a/brc b/brc
index b0f8846bef148f95392839e8e32808ef66893b54..138fd896b26df6b2ae9361ba75709abd9855fe93 100644 (file)
--- a/brc
+++ b/brc
@@ -466,6 +466,10 @@ c() {
 }
 ccomp cd c
 
+bwm() {
+  s bwm-ng -T avg -d
+}
+
 b() {
   local topb
   if (( ${#_iankdirb[@]} == 0 )); then
@@ -683,7 +687,7 @@ chrbind() {
 chumount() {
   local d
   # dev/pts needed for pacman signature check
-  for d in dev proc sys dev/pts; do
+  for d in dev/pts dev proc sys; do
     [[ -d $d ]]
     if mountpoint $d &>/dev/null; then
       m s umount $d
@@ -779,6 +783,19 @@ despace() {
   done
 }
 
+# get ipv4 ip from HOST. or if it is already a number, return that
+hostip() {
+  local host="$1"
+  case $host in
+    [0-9:])
+      echo "$host"
+      ;;
+    *)
+      getent ahostsv4 "$host" | awk '{ print $1 }' | head -n1
+      ;;
+  esac
+}
+
 dig() {
   command dig +nostats +nocmd "$@"
 }
@@ -816,7 +833,10 @@ digdiff() {
 dt() {
   date "+%A, %B %d, %r" "$@"
 }
-ccomp date dt
+dtr() {
+  date -R "$@"
+}
+ccomp date dt dtr
 
 dus() { # du, sorted, default arg of
   du -sh ${@:-*} | sort -h
@@ -824,7 +844,7 @@ dus() { # du, sorted, default arg of
 ccomp du dus
 
 
-e() { echo "$@"; }
+e() { printf "%s\n" "$*"; }
 
 # echo args
 ea() {
@@ -860,7 +880,11 @@ ediff() {
 etail() {
   tail -F /var/log/exim4/mainlog -n 200 "$@"
 }
-ccomp tail etail
+etail2() {
+  tail -F /var/log/exim4/mymain -n 200 "$@"
+}
+
+ccomp tail etail etail2
 
 # print exim old pids
 eoldpids() {
@@ -920,14 +944,18 @@ eless() {
 }
 ccomp less eless
 eqcat() {
-  exiqgrep -i -o 60 | while read -r i; do
+  exiqgrep -ir.\* -o 60 | while read -r i; do
     hlm exim -Mvc $i
     echo
     hlm exigrep $i /var/log/exim4/mainlog | cat ||:
   done
 }
 eqrmf() {
-  exiqgrep -i | xargs exim -Mrm
+  # other ways to get the list of message ids:
+  # exim -bp | awk 'NF == 4 {print $3}'
+  # # this is slower 160ms, vs 60.
+  # exipick -i
+  exiqgrep -ir.\* | xargs exim -Mrm
 }
 
 econfdevnew() {
@@ -960,6 +988,14 @@ faf() { # find all files. use -L to follow symlinks
        -o -name .undo-tree-history -prune \) -type f 2>/dev/null
 }
 
+# full path without resolving symlinks
+fp() {
+  local dir base
+  base="${1##*/}"
+  dir="${1%$base}"
+  printf "%s/%s\n" $(cd $dir; pwd) "$base"
+}
+
 
 # mail related
 frozen() {
@@ -1371,7 +1407,15 @@ nags() {
 }
 
 nmt() {
-  s nmtui-connect "$@"
+  # cant use s because sudo -i doesnt work for passwordless sudo command
+  case $EUID in
+    0)
+      sudo nmtui-connect "$@"
+      ;;
+    *)
+      nmtui-connect "$@"
+      ;;
+  esac
 }
 
 nopanic() {
@@ -1539,7 +1583,7 @@ resolvcat() {
   grep '^ *hosts:' /etc/nsswitch.conf
   if systemctl is-enabled systemd-resolved &>/dev/null || [[ $(systemctl is-active systemd-resolved ||:) != inactive ]]; then
     hr; m ser status systemd-resolved | cat || :
-    hr; m systemd-resolve --status | cat
+    hr; m resolvectl status | cat
   fi
 
 }
@@ -1689,23 +1733,15 @@ sgu() {
 sk() {
 
 
-  # note, if you do something like this
-  # x=( prefix* )
-  # then disable the warning with:
-  # shellcheck disable=SC2206 # globbing is intended
-
-  # 2029: "unescaped, this expands on the client side.": yes, I know how ssh works
-  # 2164: "Use 'cd ... || exit' or 'cd ... || return' in case cd fails.": i have automatic error handling
-  # 2086: unquoted $var: Quoting every var I set is way too much quotes.
-  # 2068: Double quote array expansions to avoid re-splitting elements: same as above.
-  # 2033: command arg is a function name: too many false positives.
-
+  # disable a warning with:
+  # shellcheck disable=SC2206 # reasoning
 
-  # these ones I had disabled, but without a good written explanation, so enabling them temporarily
-  # 2046: unquoted $(cmd)
-  # 2119: Functions with optional args get bad warnings when none are passed.
+  # see bash-template/style-guide.md for justifications
 
-  shellcheck -W 999 -x -e 2029,2164,2086,2068,2033 "$@" || return $?
+  local quotes others
+  quotes=2048,2068,2086,2206
+  others=2029,2033,2054,2164
+  shellcheck -W 999 -x -e $quotes,$others "$@" || return $?
 }