Browse Source

sort by timestamp and remove redundant options to fzf as fields and sorting are done externally

Daniel Sheffield 3 tháng trước cách đây
mục cha
commit
c414d3f2fb
1 tập tin đã thay đổi với 26 bổ sung3 xóa
  1. 26 3
      recall.sh

+ 26 - 3
recall.sh

@@ -114,14 +114,14 @@ validate "$@"
 
 fzf_rw0_inplace_preview () {
 	# NOTE: to preview and select captured command directories
+	header_len="$1"
 	# shellcheck disable=SC2016
 	fzf \
 		--read0 --print0 \
 		-m \
 		--no-sort \
 		-d / \
-		--nth 1,2,3 \
-		--preview-window="~2" \
+		--preview-window="~$header_len" \
 		--preview='cat {}/info; head -n "$LINES" {}/dat' \
 	&& :
 }
@@ -160,8 +160,31 @@ awk_r0_add_prefix () {
 	&& :
 }
 
+sort_rw0 () {
+	# NOTE: sort by program, or timestamp
+	if [ "$1" = "prog" ]
+	then
+		sort -zrV
+	elif [ "$1" = "ts" ]
+	then
+		awk \
+			-v FS='/' -v RS='\0' \
+			-v OFS='/' -v ORS='\0' \
+			'{print $NF,$0}' \
+		| sort -zrV \
+		| awk_rw0_strip_first_path_part \
+		:
+	else
+		echo "unsupported sort option: $1" >&2
+		false
+	fi
+}
+
+
 if "$LIST_MODE"
 then
+	# TODO: make sort option configurable
+	sort_opt="ts"
 	find_name=()
 	if [ "${1:-}" ]
 	then
@@ -183,7 +206,7 @@ then
 				\) \
 			\) \
 			-print0 \
-		| sort -zrV \
+		| sort_rw0 "$sort_opt" \
 		| head -zn "${NUM:--0}" \
 		| fzf_rw0_inplace_preview "2" \
 		| awk_rw0_strip_first_path_part \