-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
===================================================================== --- New Scripts -------------------------- zsh ) memo program; quickly take notes! - memo/open - memo/remove
- Loading branch information
Showing
3 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 $@ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 $@ |