Last active
March 14, 2023 12:51
-
-
Save sathishmanohar/f6bfd7db60c180d47203caba86021599 to your computer and use it in GitHub Desktop.
Simple note taking app on terminal
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 | |
# Create a dated text file at a specific location and append text to it. | |
# | |
# Usage: | |
# $ notes something you want to jot down (appends that text to the file) | |
# $ xclip -o | notes (appends your clipboard to the file) | |
# $ notes (opens the file in your editor) | |
# | |
# This script is almost completely copied from nickjj's below project | |
# https://github.com/nickjj/notes | |
# Settings | |
readonly NOTES_DIRECTORY="${NOTES_DIRECTORY:-"${HOME}/notes"}" | |
readonly NOTES_EDITOR="nvim" | |
# Create notes directory if doesn't exist | |
if [ ! -d "${NOTES_DIRECTORY}" ]; then | |
while true; do | |
printf "%s does not exist, do you want to create it? (y/n) " "${NOTES_DIRECTORY}" | |
read -r yn | |
case "${yn}" in | |
[Yy]* ) mkdir -p "${NOTES_DIRECTORY}"; break;; | |
[Nn]* ) exit;; | |
* ) printf "Please answer y or n\n\n";; | |
esac | |
done | |
fi | |
# Touch file with todays date | |
file="$(date +'%d-%b-%Y').txt" | |
NOTES_PATH=${NOTES_DIRECTORY}/$file | |
touch -a $NOTES_PATH | |
# If no argument is supplied open today's note in editor | |
# If there are notes given as arguments append to today's note | |
if [ $# -eq 0 ] | |
then | |
eval "${NOTES_EDITOR}" "${NOTES_PATH}" | |
else | |
printf "%s\n\n" "${*}" >> $NOTES_PATH | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment