Created
November 18, 2024 09:52
-
-
Save ifduyue/13a3a38f0b7c453e0a94a184ab2c2e92 to your computer and use it in GitHub Desktop.
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
#!/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