# --- enable/disable this file --- SRC_ENABLED=true case "$SRC_ENABLED" in 1|true|yes|on) unset SRC_ENABLED ;; # enabled — clean up and continue *) unset SRC_ENABLED; return ;; # disabled — clean up and skip this file esac # --------------------------------- #!/bin/bash # Simple one-line notes manager # Compatible with bash 3.x (RHEL 5) and bash 4.1 (Debian Squeeze) # NOTE: this file must be SOURCED, not executed: # . ./notes.sh # source ./notes.sh NOTES_FILE="${NOTES_FILE:-$HOME/.notes}" note_add() { if [ $# -eq 0 ]; then echo "Usage: note_add " >&2 return 1 fi echo "$*" >> "$NOTES_FILE" } notes() { case "$1" in -h|--help) echo "Usage: notes" echo " List all saved notes with their line numbers." echo "" echo "Related commands:" echo " note_add Add a new note" echo " note_rm Remove a note by its number" echo "" echo "Notes are stored in: $NOTES_FILE" return 0 ;; esac if [ ! -f "$NOTES_FILE" ] || [ ! -s "$NOTES_FILE" ]; then echo "No notes yet." return 0 fi awk '{ printf "%d: %s\n", NR, $0 }' "$NOTES_FILE" } note_rm() { num="$1" if [ -z "$num" ]; then echo "Usage: note_rm " >&2 return 1 fi if ! echo "$num" | grep -Eq '^[0-9]+$'; then echo "Error: line number must be a positive integer" >&2 return 1 fi if [ ! -f "$NOTES_FILE" ]; then echo "Error: notes file not found" >&2 return 1 fi total=$(wc -l < "$NOTES_FILE" | tr -d ' ') if [ "$num" -lt 1 ] || [ "$num" -gt "$total" ]; then echo "Error: no note with that number" >&2 return 1 fi sed -i "${num}d" "$NOTES_FILE" echo "Deleted note $num" }