pub / plain_notes

Plain Text notes for GNULinux
git clone https://https://src.jayvii.de/pub/plain_notes.git
Home | Log | Files | Exports | Refs | README | RSS

notes.sh (1234B)


      1 #!/usr/bin/env bash
      2 # SPDX-FileCopyrightText: 2024 JayVii <jayvii[AT]posteo[DOT]de>
      3 # SPDX-License-Identifier: GPL-3.0-or-later
      4 
      5 # Config -----------------------------------------------------------------------
      6 ## Where is your notes folder?
      7 NOTES_DIR="$HOME/Notes"
      8 ## Default category for your notes (sub-folder in $NOTES_DIR)
      9 DEFAULT_CATEGORY="Work"
     10 ## Your Editor of choice (uses fallback, if $EDITOR is unset)
     11 if [ -z "$EDITOR" ]; then
     12     EDITOR="vi"
     13 fi
     14 
     15 # List all Notes files ---------------------------------------------------------
     16 
     17 ## List all present notes (remove full path from display)
     18 FILES=$(
     19     find "${NOTES_DIR}" -type f | \
     20     sed -e "s#${NOTES_DIR}/##g"
     21 )
     22 
     23 ## Add today's date as empty file
     24 FILES=$(
     25     printf "${DEFAULT_CATEGORY}/$(date +%Y_%m_%d).md\n${FILES}" | \
     26     sort --reverse | \
     27     uniq
     28 )
     29 
     30 # Select Notes file ------------------------------------------------------------
     31 CHOOSEN=$(
     32 	echo "$FILES" | \
     33 	fzf \
     34 	--preview="if [ -f ${NOTES_DIR}/{} ]; then cat ${NOTES_DIR}/{}; fi" \
     35 	--layout=reverse \
     36 	--query="${DEFAULT_CATEGORY}"
     37 )
     38 
     39 # Open Notes file --------------------------------------------------------------
     40 if [ ! -z "$CHOOSEN" ]; then
     41 	${EDITOR} "${NOTES_DIR}/${CHOOSEN}"
     42 fi
     43 
     44 # EOF notes.sh