From ce4bee4a82b3d99d162d5f2be3d4e01c4dc2237a Mon Sep 17 00:00:00 2001 From: Ivan Reshetnikov Date: Mon, 13 Mar 2023 00:16:14 +0500 Subject: [PATCH] Add "last" command --- histd.sh | 16 ++++++++++++++++ readme.md | 7 +++++++ 2 files changed, 23 insertions(+) diff --git a/histd.sh b/histd.sh index 8d8eec2..ffe4164 100755 --- a/histd.sh +++ b/histd.sh @@ -46,6 +46,19 @@ function list { tree $BASE_DIR } +function last { + # Check editor + if [[ $EDITOR == "" ]]; then + echo EDITOR is undefined + return + fi + + LAST_FILE=$(ls -t $BASE_DIR/**/**/* | head -1) + cd $BASE_DIR + $EDITOR $LAST_FILE + cd - > /dev/null +} + function help { echo "Histd - How I Spent This Day" echo "A simple personal diary app" @@ -55,6 +68,7 @@ function help { echo "- histd.sh backup - create an archive of all notes" echo "- histd.sh merge - print all notes" echo "- histd.sh list - list all notes" + echo "- histd.sh last - open last note" echo "- histd.sh help - show this message" } @@ -71,6 +85,8 @@ elif [[ $1 == "merge" ]]; then merge elif [[ $1 == "list" ]]; then list +elif [[ $1 == "last" ]]; then + last elif [[ $1 == "help" ]]; then help else diff --git a/readme.md b/readme.md index d92a7fd..444acd4 100644 --- a/readme.md +++ b/readme.md @@ -39,6 +39,13 @@ Now you can create your first note: ./histd.sh ``` +This command can be run as many times as you want, it will open the same file until the day is over. + +You can open the last note with the command: +```bash +./histd.sh last +``` + ## Backup To create an archive of all notes, run the following command: ```bash