updates, especially for etiona
[distro-setup] / brc
diff --git a/brc b/brc
index b5d45969c67b9364d6dfc783d187be1873d27707..a85cd66db70995f727d010fd7194e9782ef171f6 100644 (file)
--- a/brc
+++ b/brc
@@ -3,6 +3,7 @@
 # SPDX-License-Identifier: AGPL-3.0-or-later
 # this gets sourced. shebang is just for file mode detection
 
+
 # Use source ~/.bashrc instead of doing bash -l when running a script
 # so this can set extdebug and avoid the bash debugger.
 if [[ -s /a/bin/errhandle/err ]]; then
@@ -317,7 +318,7 @@ cam() {
 
 
 ccat () { # config cat. see a config without extra lines.
-  grep '^\s*[^;[:space:]#]' "$@"
+  grep '^\s*[^;[:space:]#]' "$@" || [[ $? == 1 ]]
 }
 
 
@@ -478,7 +479,6 @@ ev() {
   done
 }
 
-
 ediff() {
   [[ ${#@} == 2 ]] || { echo "error: ediff requires 2 arguments"; return 1; }
   emacs --eval "(ediff-files \"$1\" \"$2\")"
@@ -768,11 +768,11 @@ lower() { # make first letter of filenames lowercase.
 
 
 k() { # history search
-  grep -P --binary-files=text "$@" ${HISTFILE:-~/.bash_history}  | tail -n 80;
+  grep -P --binary-files=text "$@" ${HISTFILE:-~/.bash_history}  | tail -n 80 || [[ $? == 1 ]];
 }
 
 ks() { # history search
-  grep -P --binary-files=text "$@" ${HISTFILE:-~/.bash_history}  | uniq;
+  grep -P --binary-files=text "$@" ${HISTFILE:-~/.bash_history}  | uniq || [[ $? == 1 ]];
 }
 
 
@@ -812,7 +812,7 @@ pkx() { # package extract
   c $(mktemp -d)
   pkg=$1
   # shellcheck disable=SC2012
-  cached=$(ls -t /var/cache/apt/archives/$pkg* | tail -n1 2>/dev/null)
+  cached=$(ls -t /var/cache/apt/archives/$pkg* | tail -n1 2>/dev/null) ||:
   if [[ $cached ]]; then
     cp $cached .
   else
@@ -888,7 +888,9 @@ q() { # start / launch a program in the backround and redir output to null
 
 # shellcheck disable=SC2120
 r() {
-  history -a # save history
+  if [[ $HISTFILE ]]; then
+    history -a # save history
+  fi
   trap ERR # this avoids a segfault
   exit ${1:0}
   # i had this redir, not sure why
@@ -1268,7 +1270,16 @@ if [[ $- == *i* ]]; then
     local ps_char ps_color
     unset IFS
 
-    history -a # save history
+    if [[ $HISTFILE ]]; then
+      history -a # save history
+    fi
+
+    if [[ $jr_pid ]]; then
+      if [[ -e /proc/$jr_pid ]]; then
+        kill $jr_pid
+      fi
+      unset jr_pid
+    fi
 
     case $return in
       0) ps_color="$term_purple"
@@ -1334,6 +1345,14 @@ unset IFS
 # shellcheck disable=SC1090
 [[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
 
+# I had this idea to start a bash shell which would run an initial
+# command passed through this env variable, then continue on
+# interactively. But the use case I had in mind went away.
+#
+# if [[ $MY_INIT_CMD ]]; then
+#   "${MY_INIT_CMD[@]}"
+#   unset MY_INIT_CMD
+# fi
 
 # ensure no bad programs appending to this file will have an affect
 return 0