goodbye shell version of um

This commit is contained in:
bth 2026-01-22 12:28:46 -08:00
commit 222e5fd52f
21 changed files with 0 additions and 383 deletions

9
.gitmodules vendored
View file

@ -1,9 +0,0 @@
[submodule "shell/test/bats"]
path = shell/test/bats
url = https://github.com/bats-core/bats-core.git
[submodule "shell/test/test_helper/bats-support"]
path = shell/test/test_helper/bats-support
url = https://github.com/bats-core/bats-support.git
[submodule "shell/test/test_helper/bats-assert"]
path = shell/test/test_helper/bats-assert
url = https://github.com/bats-core/bats-assert.git

View file

@ -1,25 +0,0 @@
#!/bin/bash
# cat for Markdown in my ultralight writing database
# wherein concatenated filed need a "\n---\n\n" between them.
#############################################################################
# cat with file headers | replace with section string | remove first instance
# NOTE: only need to add one newline, because the header inserted by tail
# implicitly adds two : \n==> foo <==\n
tail -n +1 "$@" | sed 's/^==> .* <==$/---\n/g' | tail -n +3
##############################
# failed approaches
# find . -type f -name "$@" -exec cat {} \; -printf "\n---\n\n"
# this leaves one trailing, could cat the whole thing and then cut the tail off
# MDCATALL=`for i in "$@";
# do
# cat $i
# echo '\n---\n\n'
# done`
# echo $MDCATALL | head -n +2

View file

@ -1,28 +0,0 @@
#!/bin/bash
# Get the last file name of any numbered series of text files and open it with emacs.
# file format:
# in regex terms:
# [0-9]+\.[.*\.]*md|txt
# in plain terms:
# [leading numbers with consistent width].[optional string descriptor and . separator][md|txt]
UMALLFILES=`ls | grep -E '^[[:digit:]].*\.(md|txt)'`
UMLASTSTATUS=$?
UMLASTFILE=''
if [ "$UMLASTSTATUS" -ne 0 ]; then
UMLASTFILE="$UMDEFAULTINIT"
else
# NOTE: if var isn't quoted echo will change newlines to spaces
UMLASTFILE=`echo "$UMALLFILES" | tail -n 1`
fi
if [ "$UMDISABLEEMACS" = true ] || [ "$UMTEST" = true ] ; then
echo $UMLASTFILE
exit 0
fi
echo "emacsclient -n $UMLASTFILE"
emacsclient -n $UMLASTFILE

View file

@ -1,38 +0,0 @@
# awk script to increment the digits, preserve the zero prefix, add string descriptor if supplied, and add back extension
BEGIN {
# Builtin variable, "field seperator", blank by default. The neatness of this is
# the main reason I use awk to parse the filename.
FS = "."
}
{
# another reason why awk is great for this:
newnum = $1 + 1
# could I do this with a simpler regex to select all leading zeros?
nzeros = length($1) - length(int(newnum))
leadingzeros = ""
if (nzeros > 0)
for (i = 1; i <= nzeros; i++)
leadingzeros = sprintf("%s%s", leadingzeros, "0")
if (nzeros > 0)
newnum = sprintf("%s%s", leadingzeros, newnum)
# start by prefixing the number, now with leading zeros
finalstr = newnum
# allow an arg input to fill out descriptor string.
if (arg != "")
finalstr = sprintf("%s.%s", finalstr, arg)
# append last field by default
finalstr = sprintf("%s.%s", finalstr, $NF)
}
END {
print finalstr
}

View file

@ -1,53 +0,0 @@
#!/bin/bash
# Generate the next filename in any numbered series of text files and open with emacs.
# Usage:
# $ next [descriptor] [tag]
# Handles optional string descriptor and tag. Like this:
# $ ls
# 011.blah.md
#
# $ next foo
# 012.foo.md
#
# $ next foo bar
# 013.foo.md
#
# Which populates the file like this:
#
# # 13.foo.md
# : 2024.01.14
# + bar
#
# See https://git.bth.moi/bth/um#next
# NOTE: we only want the filename, not to run emacs yet.
LASTFILE=`UMDISABLEEMACS=true $UMBASEPATH/last.sh`
# NOTE: the optional $1 arg passed to awk with -v:
NEXTFILE=`echo $LASTFILE | awk -f $UMBASEPATH/next.awk -v arg=$1`
# tag is optional second arg to this script
if [ $2 ]; then
UMELISP=$(printf '(um-next "%s" "%s")' "$NEXTFILE" "$2")
else
UMELISP=$(printf '(um-next "%s")' "$NEXTFILE")
fi
# for testing and piping
# NOTE: bash booleans are such a pain, because they don't exist. https://stackoverflow.com/a/2953673
if [ "$UMNEXTPRINT" = true ]; then
# NOTE: printf instead of echo, because echo inserts a newline, and we pipe
# this back into elisp for um-next-shell:
printf $NEXTFILE
elif [ "$UMTEST" = true ]; then
echo $UMELISP
else
# NOTE: emacs won't accept piped input as a file name, so we use --eval to run
# um-next as elisp. Which also lets us add the header and tag.
emacsclient --eval "$UMELISP"
fi
exit 0

View file

@ -1,27 +0,0 @@
# generates a string of "oldname newname" from 2 records, for use with mv. Main
# problem solved here generating the newname string using the number prefix and
# filetype affix.
BEGIN {
FS="."
oldname = ""
num = ""
ext = ""
newname = ""
}
NR == 1 {
oldname = $0
num = $1
# important that this is the last field, not numbered, to allow for a file
# without a string descriptor.
ext = $NF
}
NR == 2 {
newname = sprintf("%s.%s.%s", num, $0, ext)
}
END {
print oldname, newname
}

View file

@ -1,34 +0,0 @@
#!/bin/bash
# rename : renames the string descriptor used in numbered series.
# Usage:
# > um rename 100.md foo
# or
# > um rename 100.foo.md bar
# or
# > um last | um rename baz
# is equivalent to:
# > mv 100.md 100.foo.md
# > mv 100.foo.md 100.bar.md
# > mv 100.bar.md 100.baz.md
# accept piped input
# https://unix.stackexchange.com/a/537581
if [[ ! -t 0 ]]; then
FROM=$(cat -)
TO=$1
else
FROM=$1
TO=$2
fi
# split the args by a newline so that awk reads them as separate "records"
mvcmd=`echo "$FROM
$TO" | awk -f $UMBASEPATH/rename.awk`
echo mv $mvcmd
mv $mvcmd

View file

@ -1,4 +0,0 @@
#!/bin/bash
# just list the files so we can pipe it.
grep -lE "\+ $@" *md

@ -1 +0,0 @@
Subproject commit 3d3f63d9772b98c88586ec0a66bd358a85d9b4a6

View file

@ -1,3 +0,0 @@
# 001
: 2024.01.14
+ foo

View file

@ -1,3 +0,0 @@
# 002.blah
: 2024.01.14
+ foo

@ -1 +0,0 @@
Subproject commit e2d855bc78619ee15b0c702b5c30fb074101159f

@ -1 +0,0 @@
Subproject commit 9bf10e876dd6b624fe44423f0b35e064225f7556

View file

@ -1,124 +0,0 @@
setup() {
load 'test_helper/bats-support/load'
load 'test_helper/bats-assert/load'
# get the containing directory of this file
# use $BATS_TEST_FILENAME instead of ${BASH_SOURCE[0]} or $0,
# as those will point to the bats executable's location or the preprocessed file respectively
DIR="$( cd "$( dirname "$BATS_TEST_FILENAME" )" >/dev/null 2>&1 && pwd )"
# make executables visible to PATH
# FIXME: why isn't this working?
# PATH="$DIR/../:$PATH"
# commands depend on being in the journal/ path.
export ORIGPWD=`pwd`
cd $DIR/mockjournal
# so that we can run next.sh without dealing with emacsclient.
export UMTEST=true
}
teardown() {
export UMTEST=false
cd $ORIGPWD
git restore $DIR/mockjournal
}
@test "um usage" {
run um
assert_output 'usage: um (next|last|cat|rename|tag)'
}
um_next_awk() {
echo "$1" | awk -f $DIR/../next.awk -v arg="$2"
}
@test "next.awk" {
run um_next_awk 01.md
assert_output '02.md'
run um_next_awk 01.md foo
assert_output '02.foo.md'
}
@test "um next empty" {
run um next
assert_output --partial '100.md'
}
@test "um next empty elisp" {
run um next
assert_output '(um-next "100.md")'
}
@test "um next descriptor" {
run um next foo
assert_output --partial '100.foo.md'
}
@test "um next descriptor tag" {
run um next foo bar
assert_output '(um-next "100.foo.md" "bar")'
}
# elisp handles this now:
@test "um next descriptor +" {
run um next foo +
assert_output '(um-next "100.foo.md" "+")'
}
@test "um last" {
run um last
assert_output '099.poo.md'
}
@test "um last empty" {
cd foo
run um last
assert_output '000.md'
}
@test "um cat" {
run um cat 001.md 002.blah.md
assert_output '# 001
: 2024.01.14
+ foo
---
# 002.blah
: 2024.01.14
+ foo'
}
@test "um rename" {
run um rename 001.md blah
run ls 001*
assert_output '001.blah.md'
mv 001.blah.md 001.md
}
# this doesn't work because bats doesn't handle stdin the way a tty does.
# @test "um rename piped" {
# run um last | um rename gloo
# run ls 099*
# assert_output '099.gloo.md'
# mv 099.gloo.md 099.poo.md
# }
um_rename_awk() {
echo "$1
$2" | awk -f $DIR/../rename.awk
}
@test "rename.awk" {
run um_rename_awk 01.md foo
assert_output '01.md 01.foo.md'
run um_rename_awk 01.foo.md bar
assert_output '01.foo.md 01.bar.md'
}
@test "um tag" {
run um tag foo
assert_output '001.md
002.blah.md'
}

View file

@ -1,32 +0,0 @@
#!/bin/bash
# export so that we can use it in subscripts.
export UMBASEPATH=`realpath $0 | xargs dirname`
# TODO: load a config file?
export UMDEFAULTINIT='000.md'
# TODO: decide if getopts would be better. positional args supposed to be bad.
# https://stackoverflow.com/a/28466267
# catch first arguments with $1
case "$1" in
next)
$UMBASEPATH/next.sh $2 $3
;;
last)
$UMBASEPATH/last.sh
;;
cat)
# all args but first
$UMBASEPATH/cat.sh "${@:2}"
;;
rename)
$UMBASEPATH/rename.sh $2 $3
;;
tag)
$UMBASEPATH/tag.sh $2
;;
*)
echo "usage: um (next|last|cat|rename|tag)"; exit 1
;;
esac