From b531606ad16750f7aaee3db5e0aeec1153be58a0 Mon Sep 17 00:00:00 2001 From: nek0 Date: Fri, 4 Mar 2016 16:42:36 +0100 Subject: [PATCH] changed script to bash --- newpost.lua | 39 --------------------------------------- newpost.sh | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 39 deletions(-) delete mode 100755 newpost.lua create mode 100755 newpost.sh diff --git a/newpost.lua b/newpost.lua deleted file mode 100755 index d891232..0000000 --- a/newpost.lua +++ /dev/null @@ -1,39 +0,0 @@ -#! /usr/bin/env lua - -date = io.popen("date --rfc-3339=date"):read() -title = "null" -author = nil - - -function input() - print("Enter post title:") - title = io.read() - - print("Enter author name:") - author = io.read() -end - -function confirmation() - print("Is the following correct?") - print("title:",title) - print("author:",author) - print("y/n") -end - -function main() - repeat - input() - confirmation() - until io.read() == "y" - local postname = "./posts/" .. date .. "-" .. title:gsub(" ", "-") .. ".md" - local metatab ="---\ntitle: " .. title .. "\nauthor: " .. author .. "\ntags: \ndescription: \n---" - if os.execute("touch " .. postname) then - os.execute("echo '" .. metatab .. "' >> ".. postname) - os.execute("vim " .. postname) - else - print("some error occured. exiting") - os.exit(1) - end -end - -main() diff --git a/newpost.sh b/newpost.sh new file mode 100755 index 0000000..29e238d --- /dev/null +++ b/newpost.sh @@ -0,0 +1,37 @@ +#! /bin/bash + +date=$(date --rfc-3339=date) +title= +author= + +function input { + echo "Enter post title:" + read title + echo "Enter author name:" + read author +} + +function confirmation { + echo "Is the following correct?" + echo "title: $title" + echo "author: $author" + echo "y/n" +} + +function main { + local conf="n" + while [ "$conf" != "y" ] + do + input + confirmation + read conf + done + set -x + postname="./posts/$date-${title// /-}.md" + echo -e "---\ntitle: ${title}\nauthor: ${author}\ntags: \ndescription: \n---" >> $postname + vim $postname +} + +main + +unset date title author