addNote


"/home/yossef/notes/git/scripts/addNote.md"

path: git/scripts/addNote.md

- **fileName**: addNote
- **Created on**: 2025-03-26 14:20:25

#!/usr/bin/bash

--------- for the notes function shortcuts -------------

#!/usr/bin/bash

# --------- for the notes function shortcuts ------------- 
# Function to add a new note
add_note() {
    # Ensure correct number of arguments
    if [ "$#" -ne 2 ]; then
        echo "Usage: add_note ~/notes/<folder> <name>"
        return 1
    fi
    # setup some local varible
    local folder="$1"
    local name="$2"
    local notes_dir="$HOME/notes/$folder"
    local file_path="$notes_dir/$name.md"
    local timestamp=$(date "+%Y-%m-%d %H:%M:%S")

  # Create the directory if it does not exist
  if ! mkdir -p "$notes_dir"; then
      echo "Error: Unable to create directory $notes_dir"
      #notify-send -u critical -h string:urgency:failure "Failure" "The operation failed"
      return 1
  fi

  # Check if the file already exists
  if [ -f "$file_path" ]; then
      echo "Error: File $file_path already exists"
      #notify-send -u critical -h string:urgency:failure "Failure" "The operation failed"
      return 1
  fi

  # Create the markdown file with the template
  cat <<EOL > "$file_path"
  ---
  dg-publish: true
  dg-home: false
  ---
  ---

  "$file_path"
  ># path: $folder/$name.md

  \`\`\`text
  - **fileName**: $name
  - **Created on**: $timestamp
  \`\`\`

  **continue**:[[]]
  **before**:[[]]

  EOL

  # Check if the file was created successfully
  if [ ! -f "$file_path" ]; then
      echo "Error: Unable to create file $file_path"
      #notify-send -u critical -h string:urgency:failure "Failure" "The operation failed"
      return 1
  fi

  # Open the file in Neovim
  nvim "$file_path"
  #notify-send "adding note: $file_path"
  #notify-send -u low -h string:urgency:success "Success" "adding note: $file_path":
}

# Function declaration check
add_note "$@"

continue:./nvim_switcher.md
before:./cpkm.md