Add "last" command

This commit is contained in:
Ivan R. 2023-03-13 00:16:14 +05:00
parent 62dabe79c1
commit ce4bee4a82
No known key found for this signature in database
GPG key ID: 56C7BAAE859B302C
2 changed files with 23 additions and 0 deletions

View file

@ -46,6 +46,19 @@ function list {
tree $BASE_DIR 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 { function help {
echo "Histd - How I Spent This Day" echo "Histd - How I Spent This Day"
echo "A simple personal diary app" 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 backup - create an archive of all notes"
echo "- histd.sh merge - print all notes" echo "- histd.sh merge - print all notes"
echo "- histd.sh list - list all notes" echo "- histd.sh list - list all notes"
echo "- histd.sh last - open last note"
echo "- histd.sh help - show this message" echo "- histd.sh help - show this message"
} }
@ -71,6 +85,8 @@ elif [[ $1 == "merge" ]]; then
merge merge
elif [[ $1 == "list" ]]; then elif [[ $1 == "list" ]]; then
list list
elif [[ $1 == "last" ]]; then
last
elif [[ $1 == "help" ]]; then elif [[ $1 == "help" ]]; then
help help
else else

View file

@ -39,6 +39,13 @@ Now you can create your first note:
./histd.sh ./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 ## Backup
To create an archive of all notes, run the following command: To create an archive of all notes, run the following command:
```bash ```bash