fixes, new features like initial debbugs
[distro-setup] / brc
diff --git a/brc b/brc
index b2bac5b43edcc7eae11bfb3a9e6f37a011939c1d..d54570eff2246ce397daf069d25f5bf11fa92e95 100644 (file)
--- a/brc
+++ b/brc
@@ -242,6 +242,7 @@ export SL_FILES_DIR=/b/ds/sl/.iank
 export SL_INFO_DIR=/p/sshinfo
 
 
+
 # * include files
 
 if [[ -s $bashrc_dir/path-add-function ]]; then
@@ -302,6 +303,15 @@ mysrc /a/bin/distro-functions/src/package-manager-abstractions
 
 ### begin FSF section ###
 
+# use for temporary functions
+y() {
+  m "${@//spring/fall}"
+}
+h() {
+  e "${@//spring/fall}"
+}
+
+
 # Comments before functions are meant to be good useful
 # documentation. If they fail at that, please improve them or send Ian a
 # note.
@@ -1766,8 +1776,12 @@ profsrc() {
 prof() {
   command prof &>/dev/null &
 }
-
-
+# self chat
+sc() {
+  while read -r l; do
+    printf '\033[1A\033[K'; printf "%s\n" "$l"| ts "%F %T" | tee -a /p/self-chat.log
+  done
+}
 
 nmt() {
   # cant use s because sudo -i doesnt work for passwordless sudo command
@@ -1820,15 +1834,15 @@ 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 .
+    cp $cached .
   else
-    aptitude download $pkg || return 1
+    aptitude download $pkg || return 1
   fi
   tmp=(*); f=${tmp[0]} # only 1 expected
-  ex $f
-  rm -f $f
+  ex $f
+  rm -f $f
 }
 
 # pgrep and kill
@@ -2750,6 +2764,45 @@ on-bat() {
   fi
 }
 
+# make vim work with my light colortheme terminal.
+vim() {
+  if [[ -e ~/.vimrc ]]; then
+    command vim "$@"
+  else
+    command vim -c ':colorscheme peachpuff' "$@"
+  fi
+}
+
+# ls count. usage: pass a directory, get the number of files.
+# https://unix.stackexchange.com/questions/90106/whats-the-most-resource-efficient-way-to-count-how-many-files-are-in-a-director
+lsc() {
+  ls -Uq "$@"|wc -l
+}
+
+# run then notify. close notification after the next prompt.
+rn() {
+  "$@"
+  dunstify -u critical "$*"
+  _psrun=(dunstctl close-all)
+}
+n() {
+  dunstify -u critical n
+}
+
+catnew() {
+  local dir file
+  dir="$1"
+  inotifywait -m "$dir" -e create -e moved_to | while read -r _ _ file; do
+    hr
+    cat "$dir/$file"
+  done
+}
+# cat mail
+cm() {
+  catnew /m/md/$1/new
+}
+
+
 # * misc stuff
 
 
@@ -2840,6 +2893,26 @@ if [[ $- == *i* ]]; then
     if [[ $(jobs -p) ]]; then
       jobs_char='j\j '
     fi
+
+
+    # allow a function to specify a command to run after we run the next
+    # command. Use case: a function makes a persistent notification. If
+    # we happen to be using that terminal, we can just keep working by
+    # entering our next command, even a noop in order to dismiss the
+    # notification, instead of having to explicitly dismiss it.
+    if [[ ${_psrun[@]} ]]; then
+      if (( _psrun_count >= 1 )); then
+
+        "${_psrun[@]}" ||:
+        _psrun_count=0
+        unset _psrun
+      else
+        _psrun_count=$(( _psrun_count + 1 ))
+      fi
+    else
+      _psrun_count=0
+    fi
+
     # We could test if sudo is active with sudo -nv
     # but then we get an email and log of lots of failed sudo commands.
     # We could turn those off, but seems better not to.
@@ -2851,6 +2924,15 @@ if [[ $- == *i* ]]; then
     fi
     PS1="${PS1%"${PS1#*[wW]}"} $jobs_char$psudo\[$ps_color\]$ps_char\[$term_nocolor\] "
 
+    # copy of what is automatically added by guix.
+    # adds [env] to PS1 if GUIX_ENVIRONMENT is set and PS1 contains '$';
+    if [ -n "$GUIX_ENVIRONMENT" ]; then
+      if [[ $PS1 =~ (.*)"\\$" ]]; then
+        PS1="${BASH_REMATCH[1]} [env]\\\$ "
+      fi
+    fi
+
+
     # set titlebar. instead, using more advanced
     # titelbar below
     #echo -ne "$_title_escape $HOSTNAME ${PWD/#$HOME/~}  \007"