From b56b0d3ca316395a903ed1c7a040bda0ae321c36 Mon Sep 17 00:00:00 2001 From: claw0ry Date: Wed, 11 Dec 2024 13:58:21 +0100 Subject: fresh start --- scripts/note | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100755 scripts/note (limited to 'scripts/note') diff --git a/scripts/note b/scripts/note new file mode 100755 index 0000000..1e0188d --- /dev/null +++ b/scripts/note @@ -0,0 +1,67 @@ +#!/bin/bash + +# Owner: claw0ry +# Description: Take notes using vim. Theres a lot of assumptions here, so it might not fit your setup. +# Assumptions: +# - Your notes directory is in your $HOME +# - Your home directory is '/home//' +# - Your notes should be in markdown + +_list_files() { + find "$1" -mindepth 1 -type f | while read file; do + echo "$file" | cut -d'/' -f5- + done +} + +_remove_file() { + if [[ -f "$1" ]]; then + rm -v "$1" + else + echo "ERR: file not found" + return 1 + fi +} + +_open_file() { + # inject template if files does not already exist + if [[ ! -f "$1" ]]; then + local now=$(date -R) + local templ="# TITLE\n\nDate: $now\n\n" + + # opens a new vim buffer with $templ and sets the filename to $1 without writing to it + echo -e $templ | $EDITOR - -c ':set ft=markdown' +"file ${1}" + else + $EDITOR "$1" + fi +} + +_print_usage() { + echo "usage: note [COMMAND] []" + echo "Commands:" + echo " list" + echo " List all notes" + echo " rm" + echo " Delete all notes" + echo " help" + echo " Prints usage" +} + +note() { + if [[ -z "$1" ]]; then + _print_usage + return 1 + fi + + case "$1" in + "list") + _list_files "$HOME/notes";; + "rm") + _remove_file "$HOME/notes/$2";; + "help") + _print_usage;; + *) + _open_file "$HOME/notes/$1";; + esac +} + +note "$@" -- cgit v1.2.3