Last active
March 5, 2023 21:06
-
-
Save brainfucksec/56acb77fba3b6001e5592bbf6350e0d3 to your computer and use it in GitHub Desktop.
KISS Terminal note taker
This file contains hidden or 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
| #!/usr/bin/env bash | |
| ########################################################################## | |
| # note.sh | |
| # | |
| # KISS Terminal note taker | |
| # | |
| # Copyright (C) 2019 Brainfuck | |
| # | |
| # DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE | |
| # | |
| # This work is free. You can redistribute it and/or modify it under the | |
| # terms of the Do What The Fuck You Want To Public License, Version 2, | |
| # as published by Sam Hocevar. See http://www.wtfpl.net/ for more details. | |
| # | |
| ########################################################################## | |
| # Program information | |
| readonly prog_name="note" | |
| readonly version="0.1" | |
| readonly signature="Copyright (C) 2019 Brainfuck" | |
| # Settings | |
| readonly note_dir="$HOME/documents/notes" | |
| readonly todofile="$note_dir/todo.md" | |
| readonly notefile="$note_dir/quicknote.txt" | |
| # Check if note directory exists | |
| checkdir() { | |
| if [[ ! -d $note_dir ]]; then | |
| echo "Error: note directory not exists :(" | |
| echo "Please read the instructions in the README file" | |
| exit 1 | |
| fi | |
| } | |
| # Edit/add todo (files will be opened with your $EDITOR) | |
| todo() { | |
| checkdir | |
| if [[ -f "$todofile" ]]; then | |
| "$EDITOR" "$todofile" | |
| exit 0 | |
| else | |
| echo "Error: todo file not exists :(" | |
| exit 1 | |
| fi | |
| } | |
| # Edit/add note | |
| quicknote() { | |
| checkdir | |
| if [[ -f "$notefile" ]]; then | |
| "$EDITOR" "$notefile" | |
| exit 0 | |
| else | |
| echo "Error: note file not exists :(" | |
| exit 1 | |
| fi | |
| } | |
| # help menù | |
| help_menu() { | |
| cat << EOF | |
| $prog_name $version | |
| KISS Terminal note taker | |
| Usage: $prog_name <argument> | |
| Arguments: | |
| -h, help Show this help menù and exit | |
| -t, todo Edit/add todo | |
| -m, mark Edit/add note (quick note) | |
| EOF | |
| } | |
| # Main function | |
| main() { | |
| if [[ "$#" == 0 ]]; then | |
| echo "$prog_name: please insert an argument" | |
| echo "Try '$prog_name help' for more information." | |
| exit 1 | |
| fi | |
| while [[ "$#" -gt 0 ]]; do | |
| case "$1" in | |
| -h | help) | |
| help_menu | |
| exit 0 | |
| ;; | |
| -t | todo) | |
| todo | |
| ;; | |
| -m | mark) | |
| quicknote | |
| ;; | |
| -* | *) | |
| echo "$prog_name: invalid argument!" | |
| echo "Try '$prog_name help' for more information." | |
| exit 1 | |
| ;; | |
| esac | |
| done | |
| } | |
| main "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment