(identity) enable reate via set, add touch, non-emptyness checks

This commit is contained in:
Corwin Brust 2026-05-09 03:43:09 -04:00
parent 352e19c87b
commit deb6f51b57

View file

@ -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 [[ <context1> [...]] query
## where QUERY (and CONTEXT1, etc, if provided) are words