浏览代码

move find method into helper file

Daniel Sheffield 3 月之前
父节点
当前提交
0b1399fa91
共有 2 个文件被更改,包括 18 次插入8 次删除
  1. 16 0
      helpers/find.sh
  2. 2 8
      recall.sh

+ 16 - 0
helpers/find.sh

@@ -0,0 +1,16 @@
+#!/bin/bash
+# Copyright (c) Daniel Sheffield 2024 - 2025
+
+find_w0_leaf_directories (){
+	# NOTE: list all leaf directories in current working dir tree
+	#       excluding ts directories or links
+	find . \
+		\( -type l -o -type d \) -wholename './????????_??????_?????????' -prune -o -type d "${find_name[@]}" \( \
+			-links 2 \
+			-o \( \
+				-links 1 -exec bash -c '! [ "$(find "$1" -mindepth 1 -type d)" ]' find-bash {} \; \
+			\) \
+		\) \
+		-print0 \
+	&& :
+}

+ 2 - 8
recall.sh

@@ -10,6 +10,7 @@ fi
 
 . "${BASH_SOURCE[0]%/*}"/helpers/common.sh
 . "${BASH_SOURCE[0]%/*}"/helpers/awk.sh
+. "${BASH_SOURCE[0]%/*}"/helpers/find.sh
 . "${BASH_SOURCE[0]%/*}"/helpers/fzf.sh
 
 stderr_deps=/dev/null
@@ -186,14 +187,7 @@ then
 	fi
 	(
 		cd "$LOG_ROOT"
-		find . \
-			\( -type l -o -type d \) -wholename './????????_??????_?????????' -prune -o -type d "${find_name[@]}" \( \
-				-links 2 \
-				-o \( \
-					-links 1 -exec bash -c '! [ "$(find "$1" -mindepth 1 -type d)" ]' find-bash {} \; \
-				\) \
-			\) \
-			-print0 \
+		find_w0_leaf_directories \
 		| sort_rw0 "$sort_opt" \
 		| head -zn "${NUM:--0}" \
 		| fzf_rw0_inplace_preview "2" \