MJN All Blog Cheatsheets Elasticsearch GCP JS LinuxBash Misc Notes Other ShortcutKeys / - Search

Home / LinuxBash / Script n - Record and query notes


#!/bin/bash
help_text="
NAME
  n - Notes

USAGE
  n [options] <text - consider wrapping in quotes>

OPTIONS
  -h|--help
    Show this help message.

  -a|--add
    Add the <text> as a new note.

  -e|--edit
    Edit the notes text file.

DESCRIPTION
  Record and query notes.

AUTHOR
  mjnurse - 2023
"

help_line="Record and query notes"
web_desc_line="Record and query notes"

nf=~/.notes.txt

if [[ "$1" == "" ]]; then
  echo ' _  _     _'
  echo '| \| |___| |_ ___ ___'
  echo '| .` / _ \  _/ -_|_-<'
  echo '|_|\_\___/\__\___/__/'
  echo
  cat "$nf"
  echo
  echo "Usage: n [options] <text - consider wrapping in quotes>"
  echo "Try:  \"n -h\" for more information."
  exit
fi

case ${1-} in
  -a|--add)
    shift
    echo "$*" >> "$nf"
    ;;
  -e|--edit)
    vi "$nf"
    ;;
  -h|--help)
    echo "$help_text"
    exit
    ;;
  *)
    echo "NOTES"
    echo "-----"
    grep --color=auto "$1" "$nf"
    exit
    ;;
esac

sort "$nf"| sed '/^$/d' > "$nf".tmp
awk '
    {
        split($0, words, " ")
        if (NR == 1) {
            prev = words[1]
            print
        } else {
            if (words[1] != prev) {
            print ""
            prev = words[1]
            }
            print
        }
    }' "$nf".tmp > "$nf"
    rm -f "$nf".tmp

This page was generated by GitHub Pages. Page last modified: 25/04/17 10:38