30 lines
572 B
Bash
30 lines
572 B
Bash
|
#!/bin/sh
|
||
|
|
||
|
# Set Notes Directory Here
|
||
|
NOTES_DIR="$HOME/.notes"
|
||
|
|
||
|
# Default note name if no args are passed in
|
||
|
FILE_NAME="quicknote"
|
||
|
|
||
|
# If arg is passed, used arg as file name
|
||
|
if [ -n "$1" ]; then
|
||
|
FILE_NAME="$1"
|
||
|
fi
|
||
|
|
||
|
# Check if name exists, if it does append and increment
|
||
|
# COUNTER until no collision detected
|
||
|
COUNTER=2
|
||
|
TEMP_NAME=$FILE_NAME
|
||
|
while [ -e "$NOTES_DIR/$TEMP_NAME.md" ]; do
|
||
|
TEMP_NAME="$FILE_NAME$COUNTER"
|
||
|
COUNTER=$((COUNTER+1))
|
||
|
done
|
||
|
|
||
|
# prepend note directory and make a markdown file
|
||
|
FILE_NAME="$NOTES_DIR/$TEMP_NAME.md"
|
||
|
|
||
|
# open file in vim
|
||
|
vim "$FILE_NAME"
|
||
|
|
||
|
|