um last opens the file with emacsclient, except when run by um next or testing

This commit is contained in:
bth 2025-01-13 21:20:00 -08:00
commit afd5d3b2fe
3 changed files with 23 additions and 16 deletions

View file

@ -1,6 +1,6 @@
#!/bin/bash
# Get the last file name of any numbered series of text files.
# Get the last file name of any numbered series of text files and open it with emacs.
# file format:
# in regex terms:
@ -9,13 +9,20 @@
# [leading numbers with consistent width].[optional string descriptor and . separator][md|txt]
UMALLFILES=`ls | grep -E '^[[:digit:]].*\.(md|txt)'`
LASTSTATUS=$?
UMLASTSTATUS=$?
UMLASTFILE=''
# NOTE: if we don't stop and signal here, tail will exit 0
if [ "$LASTSTATUS" -ne 0 ]; then
echo "no files found" >&2
exit 1
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
# NOTE: if var isn't quoted echo will change newlines to spaces
echo "$UMALLFILES" | tail -n 1
if [ "$UMDISABLEEMACS" = true ] || [ "$UMTEST" = true ] ; then
echo $UMLASTFILE
exit 0
fi
echo "emacsclient -n $UMLASTFILE"
emacsclient -n $UMLASTFILE

View file

@ -23,8 +23,8 @@
#
# See https://git.bth.moi/bth/um#next
# NOTE: handle the exit 1 case of last.sh
LASTFILE=`$UMBASEPATH/last.sh || echo $UMDEFAULTINIT`
# 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`
@ -37,11 +37,12 @@ else
fi
# for testing and piping
if [ $UMNEXTPRINT ]; then
# 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 [ $UMNEXTTEST ]; then
elif [ "$UMTEST" = true ]; then
echo $UMELISP
else
# NOTE: emacs won't accept piped input as a file name, so we use --eval to run

View file

@ -13,11 +13,11 @@ setup() {
export ORIGPWD=`pwd`
cd $DIR/mockjournal
# so that we can run next.sh without dealing with emacsclient.
export UMNEXTTEST=true
export UMTEST=true
}
teardown() {
export UMNEXTTEST=false
export UMTEST=false
cd $ORIGPWD
git restore $DIR/mockjournal
}
@ -73,8 +73,7 @@ um_next_awk() {
@test "um last empty" {
cd foo
run um last
assert_failure
assert_output 'no files found'
assert_output '000.md'
}
@test "um cat" {