lots of fixes, improvements, t12 stuff
[distro-setup] / brc
diff --git a/brc b/brc
index 8e1b3276f0358ac96cd038e9764c700e811a497e..4aacc47397e3e5502809c60229ad369035d4f41d 100644 (file)
--- a/brc
+++ b/brc
@@ -1041,16 +1041,13 @@ cf() {
   done
 }
 caf() {
-
   local file
   find -L "$@" -type f -not \( -name .svn -prune -o -name .git -prune \
        -o -name .hg -prune -o -name .editor-backups -prune \
        -o -name .undo-tree-history -prune \) -printf '%h\0%d\0%p\n' | sort -t '\0' -n \
     | awk -F '\0' '{print $3}' 2>/dev/null | while read -r file; do
-    hr
-    printf "%s\n" "$file"
-    hr
-    cat "$file"
+    hr "$file"
+    v "$file"
   done
 }
 ccomp cat cf caf
@@ -1733,10 +1730,21 @@ re() {
 
 # horizontal row. used to break up output
 hr() {
-  local blocks
-  # 180 is long enough.
-  blocks=██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████
-  printf "%s\n" "$(tput setaf 5 2>/dev/null ||:)${blocks:0:${COLUMNS:-180}}$(tput sgr0 2>/dev/null||:)"
+  local start end end_count arg
+  # 180 is long enough. 5 for start.
+  start=█████ end=█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████
+  end_count=$(( ${COLUMNS:-180} - 5 ))
+  arg="$*"
+  if [[ $arg ]]; then
+    end_count=$(( end_count - 2 - ${#arg} ))
+    start="$start $arg "
+  fi
+  if (( end_count >= 1 )); then
+    end=${end:0:$end_count}
+  else
+    end=
+  fi
+  printf "%s\n" "$(tput setaf 5 2>/dev/null ||:)$start$end$(tput sgr0 2>/dev/null||:)"
 }
 # highlight
 hl() {
@@ -2049,6 +2057,8 @@ ksu() { # history search unique
   grep -P --binary-files=text "$@" ${HISTFILE:-~/.bash_history}  | uniq || [[ $? == 1 ]];
 }
 
+# remove lines from history matching $1
+#
 # todo: id like to do maybe a daily or hourly cronjob to
 # check that my history file size is increasing. Ive had it
 # inexplicably truncated in the past.
@@ -2220,7 +2230,7 @@ grep ps and output in a nice format"
   fi
   x=$(ps -eF)
   # final grep is because some commands tend to have a lot of trailing spaces
-  y=$(echo "$x" | grep -iP "$@" | grep -o '.*[^ ]') ||:
+  y=$(echo "$x" | sed -r 's,//[^[:space:]:@/]+:[^[:space:]:@/]+@,//REDACTED_URL_USER@PASS/,g' | grep -iP "$@" | grep -o '.*[^ ]') ||:
   if [[ $y ]]; then
     echo "$x" | head -n 1 || [[ $? == 141 ]]
     echo "$y"
@@ -2541,10 +2551,10 @@ skq() {
   shellcheck -W 999 -x -e $others "$@" || return $?
 }
 
-# sk on all modified files in current git repo
+# sk on all modified & new files in current git repo. must git add for new files.
 skmodified() {
   local f
-  for f in $(i s | awk '$1 == "modified:" {print $2}'); do
+  for f in $(i s | awk '$1 == "modified:" {print $2}; $1 == "new" {print $3}'); do
     if sk-p "$f"; then
       sk $f ||:
     fi
@@ -3139,7 +3149,7 @@ spark()
 
   for n in $numbers
   do
-    _spark_echo -n ${ticks[$(( (((n-min)<<8)/f) ))]}
+    _spark_echo -n ${ticks[$(( ((n-min)<<8)/f ))]}
   done
   _spark_echo
 }
@@ -3345,10 +3355,17 @@ if [[ $- == *i* ]]; then
 
     if [[ $HISTFILE ]]; then
       history -a # save history
+      if [[ -e $HOME/.iank-stream-on ]]; then
+        if [[ $HISTFILE == $HOME/.bh ]]; then
+          ps_char="HISTP "
+        fi
+      elif [[ $HISTFILE == /a/bin/data/stream_hist ]]; then
+        ps_char="HISTS "
+      fi
     fi
 
     ps_color="$term_purple"
-    ps_char='\$'
+    ps_char="$ps_char"'\$'
     if [[ ! -O . ]]; then # not owner
       if [[ -w . ]]; then # writable
        ps_color="$term_bold$term_red"
@@ -3371,7 +3388,7 @@ if [[ $- == *i* ]]; then
     fi
     jobs_char=
     if [[ $(jobs -p) ]]; then
-      jobs_char='j\j '
+      jobs_char="$(jobs -p)"'j\j '
     fi
 
 
@@ -3471,6 +3488,7 @@ lp22viewers() {
       room=${rooms[i]}
       while read -r n; do
         v=$((v+n))
+        # shellcheck disable=SC2004 # false positive
         roomv[$i]=$(( ${roomv[$i]} + n ))
       done < <(printf "%s\n" "$out"  | grep -Po "$room.*?current[^0-9]*[0-9]*" | grep -o '[0-9]*$' )
     done
@@ -3493,6 +3511,16 @@ dsh() {
   command dsh -c "$@"
 }
 
+# cat or bat with color if we have it
+v() {
+  if type -t batcat >/dev/null; then
+    # note: another useful useful style is "header"
+    batcat --color always --style plain --theme Coldark-Cold -P "$@"
+  else
+    cat "$@"
+  fi
+}
+
 # * stuff that makes sense to be at the end