improvements
[distro-setup] / brc
diff --git a/brc b/brc
index 7c89382ca6906cf5712fd360bd08b9511cd619c0..1f3aeeaab6660836781125fad776d9a74e947f9a 100644 (file)
--- a/brc
+++ b/brc
@@ -303,7 +303,7 @@ fpst() { # file paste
 
 _khfix_common() {
   local host ip port
-  read -r host ip port < <(timeout -s 9 2 ssh -oBatchMode=yes -oControlMaster=no -oControlPath=/ -v $1 |& sed -rn "s/debug1: Connecting to ([^ ]+) \[([^\]*)] port ([0-9]+).*/\1 \2 \3/p" || [[ $? == 124 ]])
+  read -r host ip port < <(timeout -s 9 2 ssh -oBatchMode=yes -oControlMaster=no -oControlPath=/ -v $1 |& sed -rn "s/debug1: Connecting to ([^ ]+) \[([^\]*)] port ([0-9]+).*/\1 \2 \3/p" ||)
   if [[ ! $ip ]]; then
     echo "khfix: ssh failed"
     return 1
@@ -316,10 +316,11 @@ _khfix_common() {
     host_entry=$host
   fi
   if [[ $host != $ip ]]; then
-    ssh-keygen -R "$host_entry" -f $(readlink -f ~/.ssh/known_hosts)
+    m ssh-keygen -R "$host_entry" -f $(readlink -f ~/.ssh/known_hosts)
+    ll ~/.ssh/known_hosts
   fi
-  echo "khfix: removing key for $ip_entry"
-  ssh-keygen -R "$ip_entry" -f $(readlink -f ~/.ssh/known_hosts)
+  m ssh-keygen -R "$ip_entry" -f $(readlink -f ~/.ssh/known_hosts)
+  ll ~/.ssh/known_hosts
   rootsshsync
 }
 khfix() { # known hosts fix
@@ -403,7 +404,7 @@ cam() {
 }
 
 ccat () { # config cat. see a config without extra lines.
-  grep '^\s*[^;[:space:]#]' "$@" || [[ $? == 1 ]]
+  sed -r '/^[[:space:]]*([;#]|--|\/\/|$)/d' "$@"
 }
 ccomp grep ccat
 
@@ -1133,7 +1134,7 @@ grep ps and output in a nice format"
     echo "$help"
     return
   fi
-  x=$(ps -eF)
+  x=$(ps -eF)
   # final grep is because some commands tend to have a lot of trailing spaces
   y=$(echo "$x" | grep -iP "$@" | grep -o '.*[^ ]') ||:
   if [[ $y ]]; then
@@ -1174,7 +1175,7 @@ randport() {
 import secrets
 print(secrets.SystemRandom().randrange(10002,65500))
 EOF
-  }
+}
 
 # reapply bashrc
 reb() {
@@ -1318,8 +1319,12 @@ sd() {
 
 ser() {
   if type -p systemctl &>/dev/null; then
-    s systemctl $1 $2
+    s systemctl "$@"
   else
+    if (( $# >= 3 )); then
+      echo iank: ser expected 2 or less arguments
+      return 1
+    fi
     s service $2 $1
   fi
 }