|
@@ -17,6 +17,7 @@ LOG_ROOT="$HOME"/.local/var/log/shell # source this
|
|
|
|
|
|
EXIT_SUCCESS=false
|
|
|
LIST_MODE=false
|
|
|
+CMD_STRING=false
|
|
|
ORS='\n'
|
|
|
|
|
|
usage () {
|
|
@@ -51,10 +52,14 @@ the captured exit status.
|
|
|
- List paths null delimited for pipe (in case of paths with new line char)
|
|
|
|
|
|
${0##*/} -l -0 find | xargs -r -0 ls -lahd
|
|
|
+
|
|
|
+ - List last 30 command strings (bash escaped)
|
|
|
+
|
|
|
+ ${0##*/} -lsn 30
|
|
|
EOF
|
|
|
}
|
|
|
|
|
|
-OPTSTRING=":zhln:0"
|
|
|
+OPTSTRING=":zhln:s0"
|
|
|
parse_opt () {
|
|
|
case "${opt}" in
|
|
|
h)
|
|
@@ -78,6 +83,9 @@ parse_opt () {
|
|
|
z)
|
|
|
EXIT_SUCCESS=true
|
|
|
;;
|
|
|
+ s)
|
|
|
+ CMD_STRING=true
|
|
|
+ ;;
|
|
|
0)
|
|
|
ORS='\0'
|
|
|
;;
|
|
@@ -165,6 +173,20 @@ awk_r0_add_prefix () {
|
|
|
&& :
|
|
|
}
|
|
|
|
|
|
+awk_r0_add_suffix () {
|
|
|
+ # NOTE: some-string -> some-string<suffix> (null delimited)
|
|
|
+ : "${2?awk_r0_add_suffix requires exactly two positional args}"
|
|
|
+ : "${1:?awk_r0_add_suffix output record separator must be set and non-empty}"
|
|
|
+ [ "${1:+DefinedNotEmpty}" == "DefinedNotEmpty" ]
|
|
|
+ [ "${2+DefinedMaybeEmpty}" == "DefinedMaybeEmpty" ]
|
|
|
+ awk \
|
|
|
+ -v suffix="/$2" \
|
|
|
+ -v RS='\0' \
|
|
|
+ -v ORS="$1" \
|
|
|
+ '{print $0 suffix}' \
|
|
|
+ && :
|
|
|
+}
|
|
|
+
|
|
|
sort_rw0 () {
|
|
|
# NOTE: sort by program, or timestamp
|
|
|
if [ "$1" = "prog" ]
|
|
@@ -185,6 +207,23 @@ sort_rw0 () {
|
|
|
fi
|
|
|
}
|
|
|
|
|
|
+list_r0 (){
|
|
|
+ ors="$1"
|
|
|
+ if ! "$CMD_STRING"
|
|
|
+ then
|
|
|
+ awk_rw0_strip_first_path_part \
|
|
|
+ | awk_r0_add_prefix "$ors" "$LOG_ROOT" \
|
|
|
+ && :
|
|
|
+ else
|
|
|
+ awk_r0_add_suffix '\0' 'info' \
|
|
|
+ | xargs -r0n1 head -n1 \
|
|
|
+ | awk \
|
|
|
+ -v RS='\n' \
|
|
|
+ -v ORS="$ors" \
|
|
|
+ '{print $0}' \
|
|
|
+ && :
|
|
|
+ fi
|
|
|
+}
|
|
|
|
|
|
if "$LIST_MODE"
|
|
|
then
|
|
@@ -214,8 +253,7 @@ then
|
|
|
| sort_rw0 "$sort_opt" \
|
|
|
| head -zn "${NUM:--0}" \
|
|
|
| fzf_rw0_inplace_preview "2" \
|
|
|
- | awk_rw0_strip_first_path_part \
|
|
|
- | awk_r0_add_prefix "$ORS" "$LOG_ROOT" \
|
|
|
+ | list_r0 "$ORS" \
|
|
|
&& :
|
|
|
)
|
|
|
else
|