Skip to content

Instantly share code, notes, and snippets.

@ifduyue
Created November 18, 2024 09:52
Show Gist options
  • Save ifduyue/13a3a38f0b7c453e0a94a184ab2c2e92 to your computer and use it in GitHub Desktop.
Save ifduyue/13a3a38f0b7c453e0a94a184ab2c2e92 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
set -euo pipefail
if [ -z ${NOTE_DIR+x} ]; then
echo "Error: Please configure and export NOTE_DIR environment variable."
exit 1
fi
function usage() {
echo "Usage: note.sh [action]"
echo
echo " actions:"
echo " grep [pattern]"
}
mkdir -p "$NOTE_DIR"
if [ $# -eq 0 ]; then
$EDITOR "$NOTE_DIR/$(date +'%Y-%m-%d').md"
else
case $1 in
grep)
grep -i -r --color "$2" "$NOTE_DIR"
;;
*)
usage
;;
esac
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment