From deb6f51b5746240b7eac21d7d59d31b23b71765c Mon Sep 17 00:00:00 2001 From: Corwin Brust Date: Sat, 9 May 2026 03:43:09 -0400 Subject: [PATCH] (identity) enable reate via set, add touch, non-emptyness checks --- ghostwheel.fn.sh | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/ghostwheel.fn.sh b/ghostwheel.fn.sh index 9e07b5d..5fe53c6 100755 --- a/ghostwheel.fn.sh +++ b/ghostwheel.fn.sh @@ -536,7 +536,7 @@ function c4.fa_src { ## where SOURCE is a readable file function c4.i.val { local src=$( c4.fa_src $@ ) - if test ! -r "$src" ; then + if test -z "$src" -o ! -r "$src" ; then # || test 0 == "$(file "$src" | grep text >2 2>&1; echo $?)" echo "WARN" "C4R${C4_RUN}${C4_TR}_VAL: missing SRC" >&2 # LOG return 1; @@ -548,7 +548,7 @@ function c4.i.val { ## where SOURCE is a readable file function c4.i.vals { local src=$( c4.fa_src $@ ) - if test ! -r "$src" ; then + if test -z "$src" -o ! -r "$src" ; then echo "WARN" "C4R${C4_RUN}${C4_TR}_VAL: missing SRC" >&2 # LOG return 1; fi @@ -559,7 +559,7 @@ function c4.i.vals { ## where SOURCE is a readable file function c4.i.for { local src=$( c4.fa_src $1 ) - if test ! -r "$src" ; then + if test -z "$src" -o ! -r "$src" ; then echo "WARN" "C4R${C4_RUN}${C4_TR}_FOR: missing SRC" >&2 # LOG return 1; fi @@ -574,7 +574,7 @@ function c4.i.autosave { || return; local src=$( c4.fa_src $1 ); shift - if test ! -r "$src" ; then + if test -z "$src" -o ! -r "$src" ; then echo "WARN" "C4R${C4_RUN}${C4_TR}_AUTOSAVE: missing SRC" >&2 # LOG return 1; fi @@ -582,9 +582,14 @@ function c4.i.autosave { cp $src $src~ } +function c4.i.touch { + local src=$( c4.fa_src $1 ); shift + test -z "$src" -o -n "$src" && touch $src +} + function c4.i.clear { local src=$( c4.fa_src $1 ); shift - if test ! -r "$src" ; then + if test -z "$src" -o ! -r "$src" ; then echo "WARN" "C4R${C4_RUN}${C4_TR}_CLEAR: missing SRC" >&2 # LOG return 1; fi @@ -594,20 +599,28 @@ function c4.i.clear { function c4.i.set { local src=$( c4.fa_src $1 ); shift - if test ! -r "$src" ; then + local d= + if test -r "$src" ; then + # identity dotfile exists + c4.i.clear $src # this handles autosave (when not inhibitied) + elif test -n "$src" \ + && $( d=$(dirname $src); + test -d "$d" -a -r "$d" ); then + # doesn't exist but path is a writable directory + c4.i.init $src + else echo "WARN" "C4R${C4_RUN}${C4_TR}_SET: missing SRC" >&2 # LOG return 1; fi - c4.i.clear $src # clear handles autosave (when not inhibitied) - local v; for v in "$@" ; do printf '%s'"\n" "$v" >>$src done } - +# Lab: breaking underbar sepeared words into wordlists +# declare -p | perl -pe 's/declare -\S+ ([^\s=]+).*$/$1/; s/^(\s|_)+//;' | grep -i ^_\\?c4 | cut --output-delimiter=' ' -d '_' -sf 1,2,3,4,5,6,7,8,9,10 ## return identity source of [[ [...]] query ## where QUERY (and CONTEXT1, etc, if provided) are words