From a740a6687012e1173e625a7e7813785fe1de3aad Mon Sep 17 00:00:00 2001 From: yage Date: Wed, 10 Aug 2022 00:46:07 -0600 Subject: [PATCH] v2.4.0 ===================================================================== --- New Scripts -------------------------- zsh ) memo program; quickly take notes! - memo/open - memo/remove --- zsh/memo/common.zsh | 19 +++++++++++++++++++ zsh/memo/open | 32 ++++++++++++++++++++++++++++++++ zsh/memo/remove | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 83 insertions(+) create mode 100644 zsh/memo/common.zsh create mode 100755 zsh/memo/open create mode 100755 zsh/memo/remove diff --git a/zsh/memo/common.zsh b/zsh/memo/common.zsh new file mode 100644 index 0000000..32c8b7d --- /dev/null +++ b/zsh/memo/common.zsh @@ -0,0 +1,19 @@ +_DEPENDENCIES+=() +_REQUIRED_ENV+=() +source ${0:a:h}/../common.zsh +##################################################################### + +set +o noglob +MEMO__FILETYPE=md +MEMO__DIR="$SCWRYPTS_DATA_PATH/memo" +[ ! -d $MEMO__DIR ] && mkdir -p $MEMO__DIR + +LIST_MEMOS() { ls $MEMO__DIR | sed "s/\.$MEMO__FILETYPE$//" | sort; } + +# TODO : remove deprecated migration +[ -d $HOME/.memos ] && { + __Yn 'detected legacy memos folder; upgrade now?' && { + mv $HOME/.memos/* $MEMO__DIR + rmdir "$HOME/.memos" + } +} diff --git a/zsh/memo/open b/zsh/memo/open new file mode 100755 index 0000000..c7ba1f6 --- /dev/null +++ b/zsh/memo/open @@ -0,0 +1,32 @@ +#!/bin/zsh +_DEPENDENCIES+=() +_REQUIRED_ENV+=() +source ${0:a:h}/common.zsh +##################################################################### + +OPEN_MEMO() { + local MEMO_NAME=$(LIST_MEMOS | __FZF_TAIL 'select/create a memo') + [ ! "$MEMO_NAME" ] && __ABORT + + MEMO_FILE="$MEMO__DIR/$MEMO_NAME.$MEMO__FILETYPE" + + [ ! -f $MEMO_FILE ] && { + __STATUS "creating memo '$MEMO_NAME'" + echo "# $MEMO_NAME" > "$MEMO_FILE" \ + && __SUCCESS "created memo '$MEMO_NAME'" \ + || __FAIL 1 "failed to create '$MEMO_FILE'" \ + ; + } + + DATESTRING="## $(date '+%A, %B %-d, %Y')" + grep -q "$DATESTRING" "$MEMO_FILE" || echo "$DATESTRING" >> "$MEMO_FILE" + + __STATUS "opening memo '$MEMO_NAME' for editing" + __EDIT "$MEMO_FILE" + __SUCCESS "finished editing memo '$MEMO_NAME'" +} + + + +##################################################################### +OPEN_MEMO $@ diff --git a/zsh/memo/remove b/zsh/memo/remove new file mode 100755 index 0000000..c486854 --- /dev/null +++ b/zsh/memo/remove @@ -0,0 +1,32 @@ +#!/bin/zsh +_DEPENDENCIES+=() +_REQUIRED_ENV+=() +source ${0:a:h}/common.zsh +##################################################################### + +OPEN_MEMO() { + local MEMO_NAME=$(LIST_MEMOS | __FZF 'select a memo to delete') + local MEMO_FILE="$MEMO__DIR/$MEMO_NAME.$MEMO__FILETYPE" + [ "$MEMO_NAME" ] && [ -f "$MEMO_FILE" ] || __ABORT + + __STATUS "--- START OF MEMO ---------------------------------------------------" + cat "$MEMO_FILE" + __STATUS "--- END OF MEMO -----------------------------------------------------" + + __WARNING + __WARNING 'memos are not backed up by default; deletion is permanent!' + __WARNING + + __yN 'are you sure you want to delete this memo?' || __ABORT + + __STATUS "deleting memo '$MEMO_FILE'" + rm "$MEMO_FILE" \ + && __SUCCESS "removed memo '$MEMO_NAME'" \ + || __FAIL 1 "failed to remove memo '$MEMO_NAME'" \ + ; +} + + + +##################################################################### +OPEN_MEMO $@