Added alejandra input (for now) Reformatted all NIX files On branch main Your branch is up to date with 'origin/main'. Changes to be committed: modified: flake.lock modified: flake.nix modified: hosts/default/default.nix modified: hosts/default/hardware.nix modified: hosts/nixstation/default.nix modified: hosts/nixstation/hardware.nix modified: hosts/nixstation/host-packages.nix modified: hosts/zaneyos-24-vm/default.nix modified: hosts/zaneyos-24-vm/hardware.nix modified: hosts/zaneyos-oem/default.nix modified: hosts/zaneyos-oem/hardware.nix modified: modules/core/boot.nix modified: modules/core/cachix.nix modified: modules/core/default.nix modified: modules/core/flatpak.nix modified: modules/core/fonts.nix modified: modules/core/greetd.nix modified: modules/core/hardware.nix modified: modules/core/network.nix modified: modules/core/nfs.nix modified: modules/core/nh.nix modified: modules/core/overlays.nix modified: modules/core/printing.nix modified: modules/core/quickshell.nix modified: modules/core/sddm.nix modified: modules/core/services.nix modified: modules/core/starfish.nix modified: modules/core/steam.nix modified: modules/core/stylix.nix modified: modules/core/syncthing.nix modified: modules/core/thunar.nix modified: modules/core/user.nix modified: modules/core/virtualisation.nix modified: modules/core/xserver.nix modified: modules/drivers/amd-drivers.nix modified: modules/drivers/default.nix modified: modules/drivers/intel-drivers.nix modified: modules/drivers/local-hardware-clock.nix modified: modules/drivers/nvidia-amd-hybrid.nix modified: modules/drivers/nvidia-drivers.nix modified: modules/drivers/nvidia-prime-drivers.nix modified: modules/drivers/vm-guest-services.nix modified: modules/home/bash.nix modified: modules/home/bashrc-personal.nix modified: modules/home/cli/bat.nix modified: modules/home/cli/bottom.nix modified: modules/home/cli/btop.nix modified: modules/home/cli/cava.nix modified: modules/home/cli/fzf.nix modified: modules/home/cli/gh.nix modified: modules/home/cli/git.nix modified: modules/home/cli/htop.nix modified: modules/home/cli/lazygit.nix modified: modules/home/editors/antigravity.nix modified: modules/home/editors/doom-emacs-install.nix modified: modules/home/editors/doom-emacs.nix modified: modules/home/editors/evil-helix.nix modified: modules/home/editors/nvf.nix modified: modules/home/emoji.nix modified: modules/home/gtk.nix modified: modules/home/hyprland/animations-def.nix modified: modules/home/hyprland/animations-dynamic.nix modified: modules/home/hyprland/animations-end4.nix modified: modules/home/hyprland/animations-moving.nix modified: modules/home/hyprland/default.nix modified: modules/home/hyprland/env.nix modified: modules/home/hyprland/hypridle.nix modified: modules/home/hyprland/hyprland.nix modified: modules/home/hyprland/hyprlock.nix modified: modules/home/hyprland/pyprland.nix modified: modules/home/noctalia.nix modified: modules/home/obs-studio.nix modified: modules/home/overview.nix modified: modules/home/qt.nix modified: modules/home/rofi/config-long.nix modified: modules/home/rofi/default.nix modified: modules/home/rofi/rofi.nix modified: modules/home/scripts/default.nix modified: modules/home/scripts/emopicker9000.nix modified: modules/home/scripts/gemini-cli.nix modified: modules/home/scripts/hm-find.nix modified: modules/home/scripts/keybinds.nix modified: modules/home/scripts/note-from-clipboard.nix modified: modules/home/scripts/note.nix modified: modules/home/scripts/nvidia-offload.nix modified: modules/home/scripts/rofi-launcher.nix modified: modules/home/scripts/screenshootin.nix modified: modules/home/scripts/squirtle.nix modified: modules/home/scripts/task-waybar.nix modified: modules/home/scripts/wallsetter.nix modified: modules/home/scripts/web-search.nix modified: modules/home/scripts/zcli.nix modified: modules/home/starship-ddubs-1.nix modified: modules/home/starship.nix modified: modules/home/swappy.nix modified: modules/home/swaync.nix modified: modules/home/tealdeer.nix modified: modules/home/terminals/ghostty.nix modified: modules/home/terminals/kitty.nix modified: modules/home/terminals/wezterm.nix modified: modules/home/virtmanager.nix modified: modules/home/waybar/waybar-curved.nix modified: modules/home/waybar/waybar-ddubs-2.nix modified: modules/home/waybar/waybar-ddubs.nix modified: modules/home/waybar/waybar-dwm-2.nix modified: modules/home/waybar/waybar-jerry.nix modified: modules/home/waybar/waybar-nekodyke.nix modified: modules/home/waybar/waybar-simple.nix modified: modules/home/wlogout/default.nix modified: modules/home/xdg.nix modified: modules/home/yazi/default.nix modified: modules/home/yazi/keymap.nix modified: modules/home/yazi/theme.nix modified: modules/home/yazi/yazi.nix modified: modules/home/zoxide.nix modified: modules/home/zsh/default.nix modified: modules/home/zsh/zshrc-personal.nix modified: profiles/amd-hybrid/default.nix modified: profiles/amd/default.nix modified: profiles/intel/default.nix modified: profiles/nvidia-laptop/default.nix modified: profiles/nvidia/default.nix modified: profiles/vm/default.nix
244 lines
7.1 KiB
Nix
244 lines
7.1 KiB
Nix
{pkgs, ...}:
|
||
pkgs.writeShellScriptBin "note" ''
|
||
|
||
# Colors for nice output
|
||
RED='\033[0;31m'
|
||
GREEN='\033[0;32m'
|
||
YELLOW='\033[0;33m'
|
||
BLUE='\033[0;34m'
|
||
MAGENTA='\033[0;35m'
|
||
CYAN='\033[0;36m'
|
||
WHITE='\033[1;37m'
|
||
GRAY='\033[0;37m'
|
||
BOLD='\033[1m'
|
||
NC='\033[0m' # No Color
|
||
|
||
# XDG-compliant notes directory and file
|
||
NOTES_DIR="$HOME/.local/share/notes"
|
||
NOTES_FILE="$NOTES_DIR/notes.txt"
|
||
|
||
# Create notes directory if it doesn't exist
|
||
mkdir -p "$NOTES_DIR"
|
||
|
||
# Function to display usage
|
||
show_usage() {
|
||
echo -e "''${BOLD}''${BLUE}📝 Note Manager''${NC}"
|
||
echo -e "''${GRAY}Usage:''${NC}"
|
||
echo -e " ''${CYAN}note''${NC} ''${YELLOW}<text>''${NC} - Add a new note"
|
||
echo -e " ''${CYAN}note''${NC} - Display all notes"
|
||
echo -e " ''${CYAN}note del''${NC} ''${YELLOW}<number>''${NC} - Delete note by number"
|
||
echo -e " ''${CYAN}note clear''${NC} - Clear all notes"
|
||
echo -e " ''${CYAN}echo 'text' | note''${NC} - Add note from stdin"
|
||
echo -e " ''${CYAN}cat file | note''${NC} - Add file contents as note"
|
||
echo ""
|
||
echo -e "''${GRAY}Examples:''${NC}"
|
||
echo -e " ''${GREEN}note call plumber tomorrow''${NC}"
|
||
echo -e " ''${GREEN}cat todo.txt | note''${NC}"
|
||
echo -e " ''${GREEN}note del 3''${NC}"
|
||
}
|
||
|
||
# Function to add a note
|
||
add_note() {
|
||
local note_text="$1"
|
||
local timestamp=$(date '+%Y-%m-%d %H:%M:%S')
|
||
local date_only=$(date '+%Y-%m-%d')
|
||
|
||
# Create notes file if it doesn't exist
|
||
touch "$NOTES_FILE"
|
||
|
||
# Get next note number
|
||
local note_num=1
|
||
if [ -f "$NOTES_FILE" ] && [ -s "$NOTES_FILE" ]; then
|
||
note_num=$(grep -E "^#[0-9]+" "$NOTES_FILE" | sed 's/^#\([0-9]*\).*/\1/' | sort -n | tail -1)
|
||
note_num=$((note_num + 1))
|
||
fi
|
||
|
||
# Add the note with proper formatting
|
||
{
|
||
echo "#$note_num [$timestamp]"
|
||
echo "$note_text"
|
||
echo ""
|
||
} >> "$NOTES_FILE"
|
||
|
||
echo -e "''${GREEN}✓''${NC} Note #$note_num added ''${GRAY}($date_only)''${NC}"
|
||
}
|
||
|
||
# Function to display all notes
|
||
display_notes() {
|
||
if [ ! -f "$NOTES_FILE" ] || [ ! -s "$NOTES_FILE" ]; then
|
||
echo -e "''${YELLOW}📝 No notes found''${NC}"
|
||
echo -e "''${GRAY}Use ''${CYAN}note <text>''${GRAY} to add your first note''${NC}"
|
||
return
|
||
fi
|
||
|
||
echo -e "''${BOLD}''${BLUE}📝 Your Notes''${NC}"
|
||
echo -e "''${GRAY}📁 $NOTES_FILE''${NC}"
|
||
echo -e "''${GRAY}$(printf '%.0s─' {1..50})''${NC}"
|
||
|
||
local in_note=false
|
||
local note_content=""
|
||
|
||
while IFS= read -r line; do
|
||
# Check if line starts with # followed by numbers and space and [
|
||
if echo "$line" | grep -q "^#[0-9][0-9]* \["; then
|
||
# Print previous note content if exists
|
||
if [ "$in_note" = true ] && [ -n "$note_content" ]; then
|
||
echo -e "$note_content"
|
||
echo ""
|
||
fi
|
||
|
||
# Extract note number and timestamp
|
||
local num=$(echo "$line" | sed 's/^#\([0-9]*\) \[.*/\1/')
|
||
local timestamp=$(echo "$line" | sed 's/^#[0-9]* \[\(.*\)\]/\1/')
|
||
local date_part=$(echo "$timestamp" | cut -d' ' -f1)
|
||
local time_part=$(echo "$timestamp" | cut -d' ' -f2)
|
||
|
||
echo -e "''${BOLD}''${CYAN}#$num''${NC} ''${GRAY}[$date_part ''${YELLOW}$time_part''${GRAY}]''${NC}"
|
||
in_note=true
|
||
note_content=""
|
||
elif [ -n "$line" ] && [ "$in_note" = true ]; then
|
||
# Accumulate note content
|
||
if [ -z "$note_content" ]; then
|
||
note_content="''${WHITE}$line''${NC}"
|
||
else
|
||
note_content="$note_content\n''${WHITE}$line''${NC}"
|
||
fi
|
||
elif [ -z "$line" ] && [ "$in_note" = true ]; then
|
||
# End of current note
|
||
if [ -n "$note_content" ]; then
|
||
echo -e "$note_content"
|
||
echo ""
|
||
fi
|
||
in_note=false
|
||
note_content=""
|
||
fi
|
||
done < "$NOTES_FILE"
|
||
|
||
# Print last note if file doesn't end with empty line
|
||
if [ "$in_note" = true ] && [ -n "$note_content" ]; then
|
||
echo -e "$note_content"
|
||
echo ""
|
||
fi
|
||
|
||
local total_notes=$(grep -c "^#[0-9]" "$NOTES_FILE")
|
||
echo -e "''${GRAY}$(printf '%.0s─' {1..50})''${NC}"
|
||
echo -e "''${GRAY}Total: ''${BOLD}$total_notes''${NC} ''${GRAY}notes''${NC}"
|
||
}
|
||
|
||
# Function to delete a note
|
||
delete_note() {
|
||
local note_num="$1"
|
||
|
||
if [ ! -f "$NOTES_FILE" ] || [ ! -s "$NOTES_FILE" ]; then
|
||
echo -e "''${RED}✗''${NC} No notes found"
|
||
return 1
|
||
fi
|
||
|
||
if ! echo "$note_num" | grep -q "^[0-9][0-9]*$"; then
|
||
echo -e "''${RED}✗''${NC} Invalid note number: $note_num"
|
||
return 1
|
||
fi
|
||
|
||
# Check if note exists
|
||
if ! grep -q "^#$note_num " "$NOTES_FILE"; then
|
||
echo -e "''${RED}✗''${NC} Note #$note_num not found"
|
||
return 1
|
||
fi
|
||
|
||
# Create temporary file without the specified note
|
||
local temp_file=$(mktemp)
|
||
local skip_lines=false
|
||
|
||
while IFS= read -r line; do
|
||
if echo "$line" | grep -q "^#[0-9][0-9]* "; then
|
||
local current_num=$(echo "$line" | sed 's/^#\([0-9]*\) .*/\1/')
|
||
if [ "$current_num" = "$note_num" ]; then
|
||
skip_lines=true
|
||
continue
|
||
else
|
||
skip_lines=false
|
||
fi
|
||
fi
|
||
|
||
if [ "$skip_lines" = false ]; then
|
||
echo "$line" >> "$temp_file"
|
||
elif [ -z "$line" ]; then
|
||
# Stop skipping when we hit an empty line (end of note)
|
||
skip_lines=false
|
||
fi
|
||
done < "$NOTES_FILE"
|
||
|
||
mv "$temp_file" "$NOTES_FILE"
|
||
echo -e "''${GREEN}✓''${NC} Note #$note_num deleted"
|
||
}
|
||
|
||
# Function to clear all notes
|
||
clear_notes() {
|
||
if [ ! -f "$NOTES_FILE" ] || [ ! -s "$NOTES_FILE" ]; then
|
||
echo -e "''${YELLOW}📝 No notes to clear''${NC}"
|
||
return
|
||
fi
|
||
|
||
local total_notes=$(grep -c "^#[0-9]" "$NOTES_FILE")
|
||
echo -e "''${YELLOW}⚠''${NC} This will delete all $total_notes notes. Are you sure? ''${GRAY}[y/N]''${NC}"
|
||
read -r confirmation
|
||
|
||
if echo "$confirmation" | grep -qi "^y"; then
|
||
> "$NOTES_FILE"
|
||
echo -e "''${GREEN}✓''${NC} All notes cleared"
|
||
else
|
||
echo -e "''${BLUE}ℹ''${NC} Operation cancelled"
|
||
fi
|
||
}
|
||
|
||
# Main script logic
|
||
main() {
|
||
# Check if input is being piped
|
||
if [ ! -t 0 ]; then
|
||
# Read from stdin (pipe)
|
||
local piped_content=""
|
||
while IFS= read -r line; do
|
||
if [ -z "$piped_content" ]; then
|
||
piped_content="$line"
|
||
else
|
||
piped_content="$piped_content"$'\n'"$line"
|
||
fi
|
||
done
|
||
|
||
if [ -n "$piped_content" ]; then
|
||
add_note "$piped_content"
|
||
else
|
||
echo -e "''${RED}✗''${NC} No input received from pipe"
|
||
exit 1
|
||
fi
|
||
return
|
||
fi
|
||
|
||
# Handle command line arguments
|
||
case "$1" in
|
||
"")
|
||
display_notes
|
||
;;
|
||
"del")
|
||
if [ -z "$2" ]; then
|
||
echo -e "''${RED}✗''${NC} Please specify note number to delete"
|
||
echo -e "''${GRAY}Usage: ''${CYAN}note del <number>''${NC}"
|
||
exit 1
|
||
fi
|
||
delete_note "$2"
|
||
;;
|
||
"clear")
|
||
clear_notes
|
||
;;
|
||
"help"|"--help"|"-h")
|
||
show_usage
|
||
;;
|
||
*)
|
||
# Everything else is treated as note content
|
||
add_note "$*"
|
||
;;
|
||
esac
|
||
}
|
||
|
||
main "$@"
|
||
''
|