v2.4.0
===================================================================== --- New Scripts -------------------------- zsh ) memo program; quickly take notes! - memo/open - memo/remove
This commit is contained in:
parent
96992e9344
commit
a740a66870
19
zsh/memo/common.zsh
Normal file
19
zsh/memo/common.zsh
Normal file
@ -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
zsh/memo/open
Executable file
32
zsh/memo/open
Executable file
@ -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
zsh/memo/remove
Executable file
32
zsh/memo/remove
Executable file
@ -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 $@
|
Loading…
Reference in New Issue
Block a user