diff --git a/src/main.sh b/src/main.sh index f6b4e23..118931c 100755 --- a/src/main.sh +++ b/src/main.sh @@ -308,6 +308,15 @@ if [ -z "${WEEKLY_DATA_FILE:-}" ]; then export WEEKLY_DATA_FILE fi +if [ "${1:-}" = "--help" ]; then + echo "Usage: $0 [OPTION]" + echo "" + echo "You may specify at most one option." + echo " --help Show this help and exit" + echo " --new Create new entry" + exit +fi + if [ "${1:-}" = "--new" ]; then collection=$(echo "$COLLECTION_LABELS" | tr ';' '\n' | $FZF --delimiter='=' --with-nth=2 --accept-nth=1) fpath="" @@ -355,6 +364,31 @@ if [ "${1:-}" = "--preview" ]; then exit fi +if [ "${1:-}" = "--delete" ]; then + fpath=$(echo "$2" | cut -d '|' -f 4 | sed "s/ /|/g") + if [ -n "$fpath" ]; then + fpath="$ROOT/$fpath" + summary=$(awk -v field="SUMMARY" "$AWK_GET" "$fpath") + while true; do + printf "Do you want to delete the entry with the title \"%s\"? (yes/no): " "$summary" >/dev/tty + read -r yn + case $yn in + "yes") + rm -v "$fpath" + break + ;; + "no") + break + ;; + *) + echo "Please answer \"yes\" or \"no\"." >/dev/tty + ;; + esac + done + fi + exec $0 --day "$DISPLAY_DATE" +fi + if [ "${1:-}" = "--day-reload" ]; then __show_day exit @@ -379,7 +413,8 @@ if [ "${1:-}" = "--day" ]; then --accept-nth='1,2,3,4' \ --preview="$0 --preview {}" \ --expect="ctrl-n" \ - --bind="ctrl-s:execute($SYNC_CMD ; printf 'Press to continue.'; read -r tmp)" + --bind="ctrl-s:execute($SYNC_CMD ; printf 'Press to continue.'; read -r tmp)" \ + --bind="ctrl-alt-d:become($0 --delete {})" ) key=$(echo "$selection" | head -1) line=$(echo "$selection" | tail -1)