add second arg as tag to next.sh

This commit is contained in:
bth 2024-01-18 10:45:00 -08:00
commit a5c9e54b5a
3 changed files with 89 additions and 19 deletions

View file

@ -16,7 +16,17 @@ Conceptually, `um` is somewhat like org-roam, except without any database depend
This "database" depends on a few simple ideas:
1. A sequentially numbered filename specification which serves as unique id, like this: `001.foo.md`. The filesystem is the database. Note that the string descriptor is optional.
1. A sequentially numbered filename specification which serves as unique id, like this: `001.foo.md`. The filesystem is the database. Note that the string descriptor is optional. In regex terms:
```sh
ls | egrep '^[[:digit:]]+\.?.*\.md|txt'
```
In pseudocode:
```
[leadings numbers].[optional string descriptor and . separator][md|txt]
```
2. Placing that same id into the file header, so that concatenated files have reference back to their source - like this:
@ -37,13 +47,13 @@ This "database" depends on a few simple ideas:
Clone it:
```
```sh
git clone https://git.bth.moi/bth/um.git ~/um
```
Symlink the `um` CLI somewhere in your `PATH`:
```
```sh
ln -s ~/um/shell/um /usr/local/bin/um
```
@ -74,8 +84,8 @@ The "command line interface" is just a small set of convenient scripts: since th
2. Decide on a zero-width for your series and seed the first file:
```
touch 001.md
```sh
touch 01.md
```
The rest of the commands will now work with this width.
@ -84,21 +94,63 @@ The "command line interface" is just a small set of convenient scripts: since th
Create a new file, open it with emacsclient, and run `um-journal-header`:
```
```sh
um next
```
Yields:
```markdown
# 02.md
: 2024.01.14
```
Create a new file with an optional descriptor:
```
```sh
um next foo
```
Yields:
```markdown
# 03.foo.md
: 2024.01.14
```
Create a new file with an optional descriptor and tag:
```sh
um next foo bar
```
Yields:
```markdown
# 04.foo.md
: 2024.01.14
+ bar
```
Or just append `+` to add the descriptor as a tag:
```sh
um next foo +
```
Yields:
```markdown
# 05.foo.md
: 2024.01.14
+ foo
```
## last
`um last` will print the name of the last numbered file. This can be useful on its own, or like this:
```
```sh
um last | xargs emacs
```

View file

@ -1,23 +1,41 @@
# Get the file name in any numbered series of text files and open with emacs
#!/bin/bash
# Generate the next filename in any numbered series of text files and open with emacs.
# Usage:
# $ next [descriptor]
# $ next [descriptor] [tag]
# Handles an optional string descriptor. Like this:
# Handles optional string descriptor and tag. Like this:
# $ ls
# 011.blah.md
#
# $ next foo
# 012.foo.md
# File format:
# in regex terms:
# [0-9]+\.[.*\.]*md|txt
# in plain terms:
# [leadings numbers with consistent width].[optional string descriptor and . separator][md|txt]
#
# $ 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 the optional $1 arg passed to awk with -v:
NEXTFILE=`$UMBASEPATH/last.sh | awk -f $UMBASEPATH/next.awk -v arg=$1`
# tag is optional second arg to this script
TAGINSERT='(previous-line) (insert "+ %s\\n") (next-line)'
# + means insert the string descriptor as tag
if [ $2 = '+' ]; then
UMTAG=$(printf "$TAGINSERT" "$1")
elif [ $2 ]; then
UMTAG=$(printf "$TAGINSERT" "$2")
fi
# HACK: emacs won't accept piped input as a file name, so we use --eval to open
# the file via find-file.
emacsclient --eval "(progn (find-file \"$NEXTFILE\") (um-journal-header) (message \"creating $NEXTFILE\"))"
emacsclient --eval "(progn (find-file \"$NEXTFILE\") (um-journal-header) $UMTAG (message \"creating $NEXTFILE\"))"

View file

@ -6,7 +6,7 @@ export UMBASEPATH=`realpath $0 | xargs dirname`
# catch first arguments with $1
case "$1" in
next)
$UMBASEPATH/next.sh $2
$UMBASEPATH/next.sh $2 $3
;;
last)
$UMBASEPATH/last.sh