improvements and fixes
[distro-setup] / brc
diff --git a/brc b/brc
index bd76bb4c8265890c517bdff5f501556ed0d76bcb..2a770ae0e416297add55e9293f1779907f44681e 100644 (file)
--- a/brc
+++ b/brc
@@ -426,15 +426,17 @@ utcl() { # utc 24 hour time to local hour 24 hour time
 }
 
 # c. better cd
-if type -p wcd &>/dev/null; then
-  if [[ $LC_INSIDE_EMACS ]]; then
-    c() { wcd -c -z 50 -o "$@"; }
+if ! type -t c &>/dev/null; then
+  if type -p wcd &>/dev/null; then
+    if [[ $LC_INSIDE_EMACS ]]; then
+      c() { wcd -c -z 50 -o "$@"; }
+    else
+      # lets see what the fancy terminal does from time to time
+      c() { wcd -c -z 50 "$@"; }
+    fi
   else
-    # lets see what the fancy terminal does from time to time
-    c() { wcd -c -z 50 "$@"; }
+    c() { cd "$@"; }
   fi
-else
-  c() { cd "$@"; }
 fi
 ccomp cd c
 
@@ -1118,7 +1120,7 @@ low() {  # make filenames lowercase, remove bad chars
     fi
     f="${arg##*/}"
     new="${f,,}" # downcase
-    new="${new//[^[:alnum:]._-]/_}" # sub bad chars
+    new="${new//[^a-zA-Z0-9._-]/_}" # sub bad chars
     new="${new#"${new%%[[:alnum:]]*}"}" # remove leading/trailing non-alnum
     new="${new%"${new##*[[:alnum:]]}"}"
     # remove bad underscores, like __ and _._
@@ -1378,6 +1380,10 @@ rmstrips() {
   ssh fencepost head -n 300 /gd/gnuorg/EventAndTravelInfo/rms-current-trips.txt | less
 }
 
+sudo () {
+  command sudo "$@" || return $?
+  DID_SUDO=true
+}
 s() {
   # background
   # I use a function because otherwise we cant use in a script,
@@ -1900,6 +1906,12 @@ psnetns() {
       if [[ $x ]]; then echo "$x"; else echo $l; fi;
     done
 }
+nonet() {
+  if ! s ip netns list | grep -Fx nonet &>/dev/null; then
+    s ip netns add nonet
+  fi
+  sudo -E env /sbin/ip netns exec nonet sudo -E -u iank /bin/bash
+}
 
 m() { printf "%s\n" "$*";  "$@"; }