From bdc6478c30e00c283aa03ca67e68fd03cb54205f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Varko=C4=8Dek?= Date: Tue, 18 Aug 2026 15:41:47 +0200 Subject: [PATCH] =?UTF-8?q?Jednoduch=C3=BD=20pozn=C3=A1mkova=C4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .bashrc.d/40_notes.sh | 76 +++++++++++++++++++++++++++++++++++++++++++++++++++ .notes | 6 ++++ 2 files changed, 82 insertions(+) create mode 100644 .bashrc.d/40_notes.sh create mode 100644 .notes diff --git a/.bashrc.d/40_notes.sh b/.bashrc.d/40_notes.sh new file mode 100644 index 0000000..f036a7f --- /dev/null +++ b/.bashrc.d/40_notes.sh @@ -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 " >&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" +} diff --git a/.notes b/.notes new file mode 100644 index 0000000..89a9109 --- /dev/null +++ b/.notes @@ -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