Update scripts to use DENOTE_9MOUNT filesystem access

This commit is contained in:
Levi Neely 2026-03-20 18:06:42 +01:00
parent 20bc5324a6
commit 3e25e94b1f
5 changed files with 45 additions and 108 deletions

View File

@ -1,27 +1,25 @@
#!/usr/bin/env rc
#!/usr/local/plan9/bin/rc
# Dbkp - Backup and restore denote directory
# Usage: Dbkp (create backup)
# Dbkp l (list backups)
# Dbkp YYYYMMddTHHmmss (restore backup)
# Configuration
backupdir=$HOME/Dbkp
mnt=$DENOTE_9MOUNT
if(~ $#mnt 0) mnt=$HOME/mnt/denote
# get denotedir
denotedir=`{9p read denote/dir}
denotedir=`{cat $mnt/dir}
if(~ $#denotedir 0 || ~ $denotedir '') {
echo 'error: could not read denote directory from server' >[1=2]
echo 'ensure denote server is running' >[1=2]
echo 'error: could not read denote directory' >[1=2]
exit 1
}
denotebase=`{basename $denotedir}
# create backupdir
mkdir -p $backupdir
# parse args
if(~ $#* 0) { # backup mode
if(~ $#* 0) {
# Backup mode
timestamp=`{9 date | awk 'BEGIN {
m["Jan"]=1; m["Feb"]=2; m["Mar"]=3; m["Apr"]=4
m["May"]=5; m["Jun"]=6; m["Jul"]=7; m["Aug"]=8
@ -32,13 +30,10 @@ if(~ $#* 0) { # backup mode
}'}
backupfile=$backupdir/$timestamp'-'$denotebase'-dbkp.tar.gz'
# create temporary directory and copy denote contents there
timestampdir=$backupdir/$timestamp
mkdir -p $timestampdir
cp -rf $denotedir/* $timestampdir
# build tarball and cleanup temp dir
echo 'Creating backup:' $backupfile
cd $backupdir
9 tar cvzf $backupfile $timestamp
@ -52,16 +47,12 @@ if(~ $#* 0) { # backup mode
exit 1
}
}
if not if(~ $#* 1) { # restore or list mode
# check for list mode
if not if(~ $#* 1) {
if(~ $1 l) {
ls $backupdir | awk -F'[-.]' '{print $1}' | awk -F'/' '{print $NF}'
exit 0
}
# validate timestamp argument
timestamp=$1
if(! echo $timestamp | 9 grep '^[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]T[0-9][0-9][0-9][0-9][0-9][0-9]$' >/dev/null >[2=1]) {
echo 'error: invalid timestamp format (expected YYYYMMddTHHmmss)' >[1=2]
@ -71,12 +62,10 @@ if not if(~ $#* 1) { # restore or list mode
backupfile=$backupdir/$timestamp'-'$denotebase'-dbkp.tar.gz'
if(! test -f $backupfile) {
echo 'error: backup file not found:' $backupfile >[1=2]
echo 'available backups:' >[1=2]
ls $backupdir/*-$denotebase-dbkp.tar.gz >[1=2]
exit 1
}
# extract tarball to restore directory
restoredir=$denotedir/restore
mkdir -p $restoredir
echo 'Restoring backup to:' $restoredir
@ -91,7 +80,6 @@ if not if(~ $#* 1) { # restore or list mode
exit 1
}
}
if not {
echo 'usage: Dbkp (create backup)' >[1=2]
echo ' Dbkp l (list backups)' >[1=2]

View File

@ -1,29 +1,25 @@
#!/usr/bin/env rc
#!/usr/local/plan9/bin/rc
# Journal interval: daily, weekly, monthly, yearly
interval=daily
# Title format: full, date, day, year
# Examples:
# full: "wednesday 12 november 2025 22:11"
# date: "wednesday 12 november 2025"
# day: "wednesday"
# year: "2025"
titleformat=full
# Signature (optional, added to filename as ==signature)
# Signature (optional)
signature=''
mnt=$DENOTE_9MOUNT
if(~ $#mnt 0) mnt=$HOME/mnt/denote
# Parse time offset argument (e.g., +2d, -3h, +15m)
offset=0
if(! ~ $#* 0) {
arg=$1
# Extract components using awk
sign=`{echo $arg | awk '{print substr($0,1,1)}'}
num=`{echo $arg | awk '{s=substr($0,2); sub(/[a-z]$/,"",s); print s}'}
unit=`{echo $arg | awk '{print substr($0,length($0))}'}
# Calculate offset in seconds
switch($unit) {
case d
offset=`{hoc -e 'int('$num' * 86400)'}
@ -33,23 +29,17 @@ if(! ~ $#* 0) {
offset=`{hoc -e 'int('$num' * 60)'}
}
# Apply sign
if(~ $sign '-') {
offset=`{hoc -e 'int(-1 * '$offset')'}
}
}
# Calculate reference timestamp based on interval
epoch=`{9 date -n}
# Adjust epoch to interval start if no offset provided
if(~ $#* 0) {
switch($interval) {
case weekly
# Get start of week (Monday)
# date outputs: Sun Nov 24 07:30:00 EST 2025
dow=`{9 date $epoch | awk '{print $1}'}
# Calculate days since Monday (Mon=0, Tue=1, ..., Sun=6)
daysback=0
switch($dow) {
case Mon; daysback=0
@ -62,13 +52,9 @@ if(~ $#* 0) {
}
epoch=`{hoc -e 'int('$epoch' - ('$daysback' * 86400))'}
case monthly
# Get start of month (day 1)
# Extract year, month from current date
yearmonth=`{9 date $epoch | awk '{print $6 " " $2}'}
# Use date with format: Nov 1 2025
epoch=`{9 date -n `{echo $yearmonth | awk '{print $2 " 1 " $1}'}}
case yearly
# Get start of year (Jan 1)
year=`{9 date $epoch | awk '{print $6}'}
epoch=`{9 date -n 'Jan 1 '^$year}
}
@ -76,7 +62,6 @@ if(~ $#* 0) {
targetepoch=`{hoc -e 'int('$epoch' + '$offset')'}
# Get formatted date (e.g., "Wednesday 12 November 2025 22:11")
datefull=`{9 date $targetepoch | awk '
BEGIN {
m["Jan"]="January"; m["Feb"]="February"; m["Mar"]="March"
@ -92,7 +77,6 @@ BEGIN {
print d[$1], $3, m[$2], $6, t[1]":"t[2]
}'}
# Format title based on titleformat setting
switch($titleformat) {
case full
title=`{echo $datefull | awk '{print tolower($0)}'}
@ -103,29 +87,27 @@ case day
case year
title=`{echo $datefull | awk '{print $4}'}
case *
# Default to full if invalid format specified
title=`{echo $datefull | awk '{print tolower($0)}'}
}
# Always filter by date only (ignore time) to find existing entries for the interval
filtertitle=`{echo $datefull | awk '{print tolower($1 " " $2 " " $3 " " $4)}'}
# Apply filter
echo 'filter title:'''$"filtertitle'''' | 9p write denote/ctl
echo 'filter title:'''$"filtertitle'''' > $mnt/ctl
# Check if there are any results
results=`{9p read denote/index}
results=`{cat $mnt/index}
# If no results, create new journal entry
if(~ $#results 0) {
if(! ~ $signature '') {
echo '''journal/:'$"title'=='^$signature''' journal' | 9p write denote/new
echo '''journal/:'$"title''' =='^$signature' journal' > $mnt/new
}
if not {
echo '''journal/:'$"title''' journal' | 9p write denote/new
echo '''journal/:'$"title''' journal' > $mnt/new
}
}
if not Denote 'denote:'$results(1)
# Clear filter
echo 'filter' | 9p write denote/ctl
echo 'filter' > $mnt/ctl

View File

@ -1,17 +1,14 @@
#!/usr/bin/env rc
#!/usr/local/plan9/bin/rc
# Merge - Merge notes or regions
# Dmerge - Merge notes or regions
# Usage: Dmerge <source-id> <dest-id> (file merge)
# Dmerge <dest-id> [format] (region merge, in acme)
# Formats: plain, plain-indented, org-src, org-quote, org-example, md-quote, md-fence
# Annotation for merged files (set to '' to disable)
annotation='MERGED FILE:'
# Annotation for merged regions (set to '' to disable)
regionannotation='MERGED REGION:'
mnt=$DENOTE_9MOUNT
if(~ $#mnt 0) mnt=$HOME/mnt/denote
# Check for selection if in acme
hasselection=0
if(! ~ $winid '') {
selection=`{9p read acme/$winid/rdsel}
@ -20,29 +17,22 @@ if(! ~ $winid '') {
}
}
# Parse arguments and determine mode
if(~ $#* 2) {
# Two args: region merge with format OR file merge
if(~ $hasselection 1) {
# Region merge with format
dst=$1
format=$2
mode=region
# Extract source note ID from window tag
tag=`{9p read acme/$winid/tag}
filename=`{echo $tag | awk '{for(i=1;i<=NF;i++) if($i ~ /[0-9]{8}T[0-9]{6}/) {print $i; exit}}'}
src=`{echo $filename | sed 's/--.*//'}
}
if not {
# File merge
src=$1
dst=$2
mode=file
}
}
if not if(~ $#* 1) {
# One arg: region merge (plain format)
if(~ $winid '') {
echo 'region merge requires running from acme window' >[1=2]
exit 1
@ -51,12 +41,9 @@ if not if(~ $#* 1) {
echo 'no text selected' >[1=2]
exit 1
}
dst=$1
format=plain
mode=region
# Extract source note ID from window tag
tag=`{9p read acme/$winid/tag}
filename=`{echo $tag | awk '{for(i=1;i<=NF;i++) if($i ~ /[0-9]{8}T[0-9]{6}/) {print $i; exit}}'}
src=`{echo $filename | sed 's/--.*//'}
@ -66,21 +53,16 @@ if not {
exit 1
}
# Branch based on mode
if(~ $mode file) {
# FILE MERGE MODE
# Read paths and titles
srcpath=`{9p read denote/n/$src/path}
dstpath=`{9p read denote/n/$dst/path}
srctitle=`{9p read denote/n/$src/title}
srcpath=`{cat $mnt/n/$src/path}
dstpath=`{cat $mnt/n/$dst/path}
srctitle=`{cat $mnt/n/$src/title}
if(~ $#srcpath 0 || ~ $#dstpath 0) {
echo 'error: note not found' >[1=2]
exit 1
}
# Verify file extensions
if(! ~ $srcpath *.md *.org *.txt) {
echo 'error: source must be .md, .org, or .txt file' >[1=2]
exit 1
@ -90,14 +72,12 @@ if(~ $mode file) {
exit 1
}
# Extract content without frontmatter (everything after first blank line)
awk '
BEGIN { found_blank = 0 }
found_blank { print }
!found_blank && /^$/ { found_blank = 1 }
' $srcpath > /tmp/content.$pid
# Append source content to destination with optional annotation
{
cat $dstpath
if(! ~ $annotation '') {
@ -112,13 +92,11 @@ if(~ $mode file) {
rm /tmp/content.$pid
# Update all backlinks pointing to source
for(linkid in `{9p read denote/n/$src/backlinks | awk -F'|' '{print $1}'}) {
for(linkid in `{cat $mnt/n/$src/backlinks | awk -F'|' '{print $1}'}) {
linkid=`{echo $linkid | awk '{gsub(/^ +| +$/, ""); print}'}
if(! ~ $#linkid 0) {
linkpath=`{9p read denote/n/$linkid/path}
linkpath=`{cat $mnt/n/$linkid/path}
if(! ~ $#linkpath 0) {
# Replace denote:src with denote:dst in the file
sed 's/denote:'$src'/denote:'$dst'/g' $linkpath > /tmp/relink.$pid
cp /tmp/relink.$pid $linkpath
rm /tmp/relink.$pid
@ -126,34 +104,27 @@ if(~ $mode file) {
}
}
# Write merged content to destination
cp /tmp/merge.$pid $dstpath
rm /tmp/merge.$pid
# Delete source note
echo 'd' | 9p write denote/n/$src/ctl
echo 'd' > $mnt/n/$src/ctl
echo 'Merged' $src 'into' $dst
}
if not if(~ $mode region) {
# REGION MERGE MODE
# Read destination path
dstpath=`{9p read denote/n/$dst/path}
dstpath=`{cat $mnt/n/$dst/path}
if(~ $#dstpath 0) {
echo 'error: destination note not found' >[1=2]
exit 1
}
# Verify file extension
if(! ~ $dstpath *.md *.org *.txt) {
echo 'error: destination must be .md, .org, or .txt file' >[1=2]
exit 1
}
# Apply formatting to selection
switch($format) {
case plain
formatted=$selection
@ -171,11 +142,9 @@ if not if(~ $mode region) {
formatted=`{echo '```'; echo $selection; echo '```'}
case *
echo 'unknown format:' $format >[1=2]
echo 'valid formats: plain, plain-indented, org-src, org-quote, org-example, md-quote, md-fence' >[1=2]
exit 1
}
# Append formatted selection to destination with optional annotation
{
cat $dstpath
if(! ~ $regionannotation '') {
@ -188,11 +157,9 @@ if not if(~ $mode region) {
echo $"formatted
} > /tmp/merge.$pid
# Write merged content to destination
cp /tmp/merge.$pid $dstpath
rm /tmp/merge.$pid
# Replace selection with link to destination
echo -n 'denote:'$dst | 9p write acme/$winid/wrsel
echo 'Region merged from' $src 'into' $dst '(format:' $format')'

View File

@ -1,8 +1,11 @@
#!/usr/local/plan9/bin/rc
# Drn - rename denote note metadata
# usage: Drn [identifier] 'title' [==signature] [tags]
rfork e
mnt=$DENOTE_9MOUNT
if(~ $#mnt 0) mnt=$HOME/mnt/denote
if(~ $#mnt 0) mnt=$HOME/mnt/denote
fn usage {
echo 'usage: Drn [identifier] ''title'' [==signature] [tags]' >[1=2]
@ -38,16 +41,13 @@ sig=''
title=''
tags=''
args=$"*
# Check for leading ==signature
if(~ $1 ==*) {
sig=`{echo $1 | sed 's/^==//'}
shift
args=$"*
}
# Title is first arg (should be quoted in input)
# Title is first arg
title=$1
shift
@ -66,7 +66,7 @@ for(a in $*) {
}
}
# Write to 9P
echo -n $title | 9p write denote/n/$id/title
echo -n $tags | 9p write denote/n/$id/keywords
echo -n $sig | 9p write denote/n/$id/signature
# Write to filesystem
echo -n $title > $mnt/n/$id/title
echo -n $tags > $mnt/n/$id/keywords
echo -n $sig > $mnt/n/$id/signature

View File

@ -1,28 +1,28 @@
#!/usr/bin/env rc
#!/usr/local/plan9/bin/rc
# Dsilo - Switch denote directory (silo)
# Usage: Dsilo <directory-path>
# Dsilo (no args - show current silo)
mnt=$DENOTE_9MOUNT
if(~ $#mnt 0) mnt=$HOME/mnt/denote
if(~ $#* 1) {
newdir=$1
# Validate directory exists
if(! test -d $newdir) {
echo 'error: directory does not exist:' $newdir >[1=2]
exit 1
}
# Get absolute path
absdir=`{cd $newdir && pwd}
# Write cd command to ctl file
echo 'cd '$absdir | 9p write denote/ctl && {
echo 'cd '$absdir > $mnt/ctl && {
echo 'Switched to silo:' $absdir '. You may have to refresh the Denote window.'
exit 0
}
}
if not {
echo 'Denote Directory:' `{9p read denote/dir}
echo 'Denote Directory:' `{cat $mnt/dir}
exit 0
}