From c533bba79f11302c6256d5c893cf0ab172c54139 Mon Sep 17 00:00:00 2001 From: Konstantin Nazarov Date: Sun, 22 Aug 2021 17:04:50 +0100 Subject: [PATCH] Allow to export note to stdout --- notes.sh | 12 ++++++++++-- test.sh | 14 ++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/notes.sh b/notes.sh index 353f075..2ad4654 100755 --- a/notes.sh +++ b/notes.sh @@ -533,7 +533,15 @@ export_note() { FILENAME="$(assert_find_file_by_id "$ID")" DIR="$2" - unpack_mime "$FILENAME" "$DIR" + if [ -z "$DIR" ]; then + DIR="$(mktemp -d)" + unpack_mime "$FILENAME" "$DIR" + + cat "$DIR/note.md" + rm -rf "$DIR" + else + unpack_mime "$FILENAME" "$DIR" + fi } get_raw_graph() { @@ -620,7 +628,7 @@ while (( "$#" )); do exit 0 ;; -E|--export) - if [ -z "$2" ] || [ -z "$3" ]; then + if [ -z "$2" ]; then echo "Misssing arguments for $1" exit 1 fi diff --git a/test.sh b/test.sh index 3db1f40..8550b67 100755 --- a/test.sh +++ b/test.sh @@ -147,6 +147,19 @@ export_note() { assert 'cat out/note.md | grep Subject' "Subject: header1" } +export_note_stdout() { + "$BASE_DIR/notes.sh" -n <<- EOF + Subject: header1 + + # This is a body + EOF + NOTE_ID="$(cat "$(pwd)/notes/cur"/* | grep X-Note-Id | cut -d ' ' -f 2)" + + MD="$("$BASE_DIR/notes.sh" -E "$NOTE_ID")" + + assert 'echo "$MD" | grep Subject' "Subject: header1" +} + edit_note() { "$BASE_DIR/notes.sh" -n <<- EOF Subject: header1 @@ -460,6 +473,7 @@ testcase new_note_from_file testcase new_note_from_dir testcase list_notes testcase export_note +testcase export_note_stdout testcase edit_note testcase edit_note_add_file testcase edit_note_no_modifications