aboutsummarylogtreecommitdiffstats
path: root/writedoc
blob: 658ef422890d1482d72b8ec9232953f2d7f79135 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/bin/bash
# A fast way of creating and editing notes using neovim without defining a file path

# Function to display help message
usage() {
    echo "Usage: writedoc [-d DIRECTORY] FILENAME"
    echo "  -d, --directory    Directory where the file will be created (default: current directory)"
    echo "  FILENAME           Name of the markdown file (without extension)"
    exit 0
}

# Default directory to current working directory
DIRECTORY="./Documents"

# Parse command line options
while [[ "$#" -gt 0 ]]; do
    case $1 in
        -d|--directory) DIRECTORY="$2"; shift ;;  # Set directory to the next argument
        -h|--help) usage ;;  # Show help and exit
        *) FILENAME="$1" ;;  # The first non-option argument will be the filename
    esac
    shift
done

# Check if FILENAME is provided
if [ -z "$FILENAME" ]; then
    echo "Error: FILENAME is required."
    usage
fi

# Make sure the directory exists
if [ ! -d "$DIRECTORY" ]; then
    echo "Directory does not exist. Creating it now..."
    mkdir -p "$DIRECTORY"
fi

# Create the markdown file
FILEPATH="$DIRECTORY/$FILENAME.md"
echo "Creating File..."
echo "# $FILENAME" > "$FILEPATH"

# Open the file with nvim
echo "Opening file..."
nvim "$FILEPATH"