um last opens the file with emacsclient, except when run by um next or testing
This commit is contained in:
parent
5170cc3724
commit
afd5d3b2fe
3 changed files with 23 additions and 16 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
#!/bin/bash
|
#!/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:
|
# file format:
|
||||||
# in regex terms:
|
# in regex terms:
|
||||||
|
|
@ -9,13 +9,20 @@
|
||||||
# [leading numbers with consistent width].[optional string descriptor and . separator][md|txt]
|
# [leading numbers with consistent width].[optional string descriptor and . separator][md|txt]
|
||||||
|
|
||||||
UMALLFILES=`ls | grep -E '^[[:digit:]].*\.(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 [ "$UMLASTSTATUS" -ne 0 ]; then
|
||||||
if [ "$LASTSTATUS" -ne 0 ]; then
|
UMLASTFILE="$UMDEFAULTINIT"
|
||||||
echo "no files found" >&2
|
else
|
||||||
exit 1
|
# NOTE: if var isn't quoted echo will change newlines to spaces
|
||||||
|
UMLASTFILE=`echo "$UMALLFILES" | tail -n 1`
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# NOTE: if var isn't quoted echo will change newlines to spaces
|
if [ "$UMDISABLEEMACS" = true ] || [ "$UMTEST" = true ] ; then
|
||||||
echo "$UMALLFILES" | tail -n 1
|
echo $UMLASTFILE
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "emacsclient -n $UMLASTFILE"
|
||||||
|
emacsclient -n $UMLASTFILE
|
||||||
|
|
|
||||||
|
|
@ -23,8 +23,8 @@
|
||||||
#
|
#
|
||||||
# See https://git.bth.moi/bth/um#next
|
# See https://git.bth.moi/bth/um#next
|
||||||
|
|
||||||
# NOTE: handle the exit 1 case of last.sh
|
# NOTE: we only want the filename, not to run emacs yet.
|
||||||
LASTFILE=`$UMBASEPATH/last.sh || echo $UMDEFAULTINIT`
|
LASTFILE=`UMDISABLEEMACS=true; $UMBASEPATH/last.sh`
|
||||||
|
|
||||||
# NOTE: the optional $1 arg passed to awk with -v:
|
# NOTE: the optional $1 arg passed to awk with -v:
|
||||||
NEXTFILE=`echo $LASTFILE | awk -f $UMBASEPATH/next.awk -v arg=$1`
|
NEXTFILE=`echo $LASTFILE | awk -f $UMBASEPATH/next.awk -v arg=$1`
|
||||||
|
|
@ -37,11 +37,12 @@ else
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# for testing and piping
|
# 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
|
# NOTE: printf instead of echo, because echo inserts a newline, and we pipe
|
||||||
# this back into elisp for um-next-shell:
|
# this back into elisp for um-next-shell:
|
||||||
printf $NEXTFILE
|
printf $NEXTFILE
|
||||||
elif [ $UMNEXTTEST ]; then
|
elif [ "$UMTEST" = true ]; then
|
||||||
echo $UMELISP
|
echo $UMELISP
|
||||||
else
|
else
|
||||||
# NOTE: emacs won't accept piped input as a file name, so we use --eval to run
|
# NOTE: emacs won't accept piped input as a file name, so we use --eval to run
|
||||||
|
|
|
||||||
|
|
@ -13,11 +13,11 @@ setup() {
|
||||||
export ORIGPWD=`pwd`
|
export ORIGPWD=`pwd`
|
||||||
cd $DIR/mockjournal
|
cd $DIR/mockjournal
|
||||||
# so that we can run next.sh without dealing with emacsclient.
|
# so that we can run next.sh without dealing with emacsclient.
|
||||||
export UMNEXTTEST=true
|
export UMTEST=true
|
||||||
}
|
}
|
||||||
|
|
||||||
teardown() {
|
teardown() {
|
||||||
export UMNEXTTEST=false
|
export UMTEST=false
|
||||||
cd $ORIGPWD
|
cd $ORIGPWD
|
||||||
git restore $DIR/mockjournal
|
git restore $DIR/mockjournal
|
||||||
}
|
}
|
||||||
|
|
@ -73,8 +73,7 @@ um_next_awk() {
|
||||||
@test "um last empty" {
|
@test "um last empty" {
|
||||||
cd foo
|
cd foo
|
||||||
run um last
|
run um last
|
||||||
assert_failure
|
assert_output '000.md'
|
||||||
assert_output 'no files found'
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "um cat" {
|
@test "um cat" {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue