George Jones 1 tahun lalu
induk
melakukan
fe5fe31e7b
4 mengubah file dengan 34 tambahan dan 2 penghapusan
  1. 11 1
      lib/bash/bashutils.sh
  2. 11 0
      rc.local/commands.sh
  3. 5 0
      rc.local/count.sh
  4. 7 1
      rc.local/latest.sh

+ 11 - 1
lib/bash/bashutils.sh

@@ -76,7 +76,17 @@ function error() { echo `date +%c` `stackfuncs`\: error: "$@" 1>&2; }
 # TODO
 #   have it check debug levels and or strings
 function debug() { [[ -v DEBUG ]] && echo `date +%c` `stackfuncs`\: debug: "$@" 1>&2 || true ; }
-function die()   { echo `date +%c` `stackfuncs`\: fatal: "$@" 1>&2 && exit 1; }
+function die()   {
+
+    exit_code=1
+    if [[ -v 2 ]]; then
+       exit_code="${1}"
+       shift;
+    fi
+
+    echo `date +%c` `stackfuncs`\: fatal: "$@" 1>&2 && exit "${exit_code}";
+}
+
 
 FALSE=1
 TRUE=0

+ 11 - 0
rc.local/commands.sh

@@ -0,0 +1,11 @@
+function commands () {
+    # list all aliases, functions, builtins and binaries on path
+    # https://stackoverflow.com/questions/64363600/bash-search-order-among-aliases-functions-binaries
+    # https://unix.stackexchange.com/questions/120786/list-all-binaries-from-path
+
+    compgen -a # aliases
+    compgen -A function # functions
+    compgen -b # builtins
+    compgen -k # keywords
+    compgen -c # binaries on path
+}

+ 5 - 0
rc.local/count.sh

@@ -0,0 +1,5 @@
+function count () (
+    # count uniq lines on stdin, sort results
+
+    uniq -c | sort -nr
+)

+ 7 - 1
rc.local/latest.sh

@@ -60,6 +60,7 @@ function latest ()
     MTIME=${MTIME:-7}
     WHERE=${WHERE:-.}
     TIMEOUT=30 # max run at 30 seconds
+    FIND_REGEX="-regex" # case sensitive by default
     which timeout > /dev/null || die "Timeout not found"
 
     # define filenames/paths to be ignored
@@ -144,6 +145,9 @@ $ latest .txt baz
 $ latest ~/Org .org DONE
 /home/gmj/Org/agenda-files/blogging.org:**** DONE g/re/p
 /home/gmj/Org/agenda-files/blogging.org:**** DONE Write next "40 years of walled garden & open platforms" article
+
+# Find the lastest .org and py files, 120 days old or les
+latest 120 '(\.py$|\.org$)'
 EOF2
         fi
 
@@ -184,6 +188,7 @@ EOF2
             REGEX="${1}";  { { [[ $# -gt 0 ]] && shift; } || die '--grep requires an argument'; }  ;;
         -i|--ignore-case)
             shift;
+            FIND_REGEX="-iregex"
             GREPFLAGS+=("-i");;
         -l|--files-with-matches)
             shift;
@@ -268,7 +273,7 @@ EOF2
         -mtime -"${MTIME}"\
         \
         $(: COMMENT restrict to files that match "$WHAT" in full pat) \
-        -regex ".*${WHAT}.*" \
+        ${FIND_REGEX} ".*${WHAT}.*" \
         \
         $(: COMMENT run grep if requested: "${GREPFLAGS[*]}") \
         ${GREPFLAGS[*]} && \
@@ -288,4 +293,5 @@ EOF2
     [[ -v DEBUG ]] && set +x
 )}
 
+# "see" where something is
 alias see=latest