Last active
March 20, 2023 04:00
-
-
Save Sanix-Darker/c34bbe6be92b505efc773391bd100dd4 to your computer and use it in GitHub Desktop.
note: a simple command line for fast todo topic oriented
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
#!/bin/bash | |
# To take note about something really quickly | |
# Requirements : fzf and ag | |
# | |
# $ note topic note to my self... # will add a new note for the topic | |
# $ note topic # will seach for notes on this topic | |
# $ note # will list for you all notes taken globally | |
note(){ | |
NOTES_DIR=$HOME/notes/ | |
CONTENT_VIEW="cat $NOTES_DIR/{1}-notes.md" | |
TODAY_NOTE_FILE="$NOTES_DIR/$(date '+%Y-%m-%d')-notes.md" | |
ENTER_COMMAND="nvim $NOTES_DIR/{1}-notes.md" | |
# We create the notes directory if it doesn't exist | |
if [ ! -d "$NOTES_DIR" ]; then mkdir -p $NOTES_DIR; fi; | |
# We browse context (topic) elements if only one argument is passed | |
if [ "$#" = "1" ]; then ls $NOTES_DIR | ag $1 $NOTES_DIR; fi; | |
# We browse the content of notes if no arguments are passed | |
if [ -z $1 ]; then | |
# if fzf is installed, use it as a live browser, otherwise, | |
# cat the list of note from today | |
if [! command -v fzf &> /dev/null ]; then cat $TODAY_NOTE_FILE; else | |
ls $NOTES_DIR | sed 's/-notes.md//g' | fzf --header "NOTES LIST" \ | |
--preview "${CONTENT_VIEW}" --preview-window "right:70" \ | |
--bind "enter:execute:${ENTER_COMMAND}" \ | |
--bind "ctrl-d:preview-down,ctrl-u:preview-up" \ | |
--tac; # for the reverse order | |
fi | |
else | |
CONTENT_MESSAGE="${@:2}" | |
# We only save a > 3 note | |
if [ ${#CONTENT_MESSAGE} -ge 3 ]; then | |
echo -e "- **$(date '+%H:%M:%S')** > [$1] $CONTENT_MESSAGE \n" >> $TODAY_NOTE_FILE; | |
fi; | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment