Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Generate a unique identifier for plain text file names, including optional title and opening in target app
#!/bin/bash
#
# Bash script to generate a unique identifier for file name
# Used for a Plain Text Writing, Knowledge or Notes System
#
# Allows for following Options:
# -o: opening file in a target program
# Additional Title or name appended to end of file name
#
# Examples
# ./zettelnote.bash # creates file like 201902111415.md
# ./zettelnote.bash -o # create and open file
# ./zettelnote.bash test # creates file like 201902111415_test.md
file_date=$( date '+%Y%m%d%H%M' )
if [[ $1 = "-o" ]]; then
TARGET_NAME=${2}
else
TARGET_NAME=${1}
fi
if [[ -z "$TARGET_NAME" ]]; then
filename="$file_date.md"
else
filename="$file_date""_$TARGET_NAME.md"
fi
if [ -f $filename ]
then
echo "File already exists. Skipping."
else
echo "Creating Note File: " $filename
touch $filename
fi
if [[ $1 = "-o" ]]; then
echo "Opening file"
open -a typora $filename
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.