Jednoduchý poznámkovač

main
Petr Varkoček 2 months ago
parent 6665741686
commit bdc6478c30

@ -0,0 +1,76 @@
# --- 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 <text of note>" >&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 <text> Add a new note"
echo " note_rm <line_number> 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 <line_number>" >&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"
}

@ -0,0 +1,6 @@
alt + . # Cykluje parametry předchozích příkazů
^ck^kc^ # Nahradí ck za kc v předchozím příkazu a provede ho
!! # Předchozí příkaz
alias fuck="sudo $(history -p !!)" # Antistresové použití !!
mkdir -p tst/{1,2,3} # Vytvoří podadresáře 1 2 3 v adresáři tst
mkdir -ṕ tst/{1..10} # Vytvoří podadresáře 1 - 10 v adresáři tst
Loading…
Cancel
Save