#!/usr/bin/env bashtag_candidates=('Mac''Linux''Windows''Raspberry''Raspberry Pi''Ubuntu''Arduino''AzatAI''Books''Turkey''Trading''Finance''Quant''Backend''Frontend''Python''Django''Flutter''C''C++''STM32''HTML''CSS''Java''JavaScript''JavaScript''typescript''Database''SQL''SQL Server''Dart''Map''Go''PostgreSQL''Postgres''Unix''AI''ML''Learning''UNEPG''UniSat''Satellite''Nuxt''Vuetify''Docker''Kubernets''UI''UX''Design''Typora''Shell''Bash''Markdown')# put current date as yyyy-mm-dd in $datedate=$(date'+%Y-%m-%d')current_dir=$(pwd)posts_dir="$current_dir/_posts"# template strings for new markdown file break="---"toc="toc: true"mathjax="mathjax: true"modify_date="modify_date: $date"# read arguments from the command lineargs="$*"
do_tags(){# let's check whether the title includes the tag candidatesempty_tag=""length=${#tag_candidates[@]}for i in"${tag_candidates[@]}";do
if[[$args=~ $i]];then
empty_tag="$empty_tag$i"fi
done
return 0
}# conditions while we might not have passed any argumentsif[[-z"$args"]];then
file_name="$posts_dir/$date-new.md"title="title: Post title"key="key: k_$(echo$RANDOM | head-c 5;echo;)"tags="tags: Some Tags"elif[[-n"$args"]];then
file_name_new=${args//' '/'-'}#replace all spaces with dashlower=$(echo"$file_name_new" | tr'[:upper:]''[:lower:]')file_name="$posts_dir/$date-$lower.md"title="title: $args"key="key: $lower"
do_tags
tags="tags: $empty_tag"fi# generate the file# first line is the break
create_file(){echo"$break">$file_name#will creates the fileecho"$title">>$file_nameecho"$key">>$file_nameecho"$tags">>$file_nameecho"$toc">>$file_nameecho"$mathjax">>$file_nameecho"$modify_date">>$file_nameecho"$break">>$file_namereturn 0
}# create the file on the diskif create_file;then
echo"success"else
echo"failure"fi
open -a typora $file_name