#!/bin/bash # Add the metadata if the answer is not empty # Usage: # append_to_metadata file_name metadata_name append_to_metadata() { if [ $# -eq 2 ]; then echo -n "$2 : " read answer if [ -n "$answer" ]; then echo "$2: ""$answer" >> "content/articles/$1" else echo "Empty answer, nothing was appended" fi fi } echo -n "Filename : " read filename append_to_metadata "$filename" "Title" append_to_metadata "$filename" "Date" append_to_metadata "$filename" "Category" append_to_metadata "$filename" "Tags" append_to_metadata "$filename" "Lang" append_to_metadata "$filename" "Slug" append_to_metadata "$filename" "Summary" echo -e "\n" >> content/articles/"$filename" # Try to get the default editor from alternatives EDITOR=${EDITOR:-$(update-alternatives --list editor | head -n1)} # If not present set it to vi EDITOR=${EDITOR:-vi} # Open the newly created file, openfully in the chosen editor $EDITOR content/articles/"$filename"