Skip to content

Commit

Permalink
v2.4.0
Browse files Browse the repository at this point in the history
=====================================================================

--- New Scripts --------------------------

zsh )
  memo program; quickly take notes!
   - memo/open
   - memo/remove
  • Loading branch information
wrynegade committed Aug 10, 2022
1 parent 96992e9 commit a740a66
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 0 deletions.
19 changes: 19 additions & 0 deletions zsh/memo/common.zsh
Original file line number Diff line number Diff line change
@@ -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"
}
}
32 changes: 32 additions & 0 deletions zsh/memo/open
Original file line number Diff line number Diff line change
@@ -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 $@
32 changes: 32 additions & 0 deletions zsh/memo/remove
Original file line number Diff line number Diff line change
@@ -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 $@

0 comments on commit a740a66

Please sign in to comment.