Skip to content

Instantly share code, notes, and snippets.

@so1tsuda
Last active February 6, 2017 09:07
Show Gist options
  • Save so1tsuda/65071ebdbfcdb69da2ebc4b278ecdf46 to your computer and use it in GitHub Desktop.
Save so1tsuda/65071ebdbfcdb69da2ebc4b278ecdf46 to your computer and use it in GitHub Desktop.
#!/bin/sh
# Time-stamp: <Sun Feb 05 19:51:49 Eur 2017>
# ----- Config ----------------------------------------------------------
# Directory where markdown files are stored
HUGO_DIR="$USERPROFILE/Dropbox/log/"
# A path to hugo binary
HUGO_BIN="/usr/local/bin/hugo"
# Theme file
HUGO_THEME="ghostwriter"
# Editor
MY_EDITOR="/cygdrive/c/cygwin64/usr/local/emacs/bin/runemacs.exe "
# Browser
MY_BROWSER="/cygdrive/c/Program\ Files\ \(x86\)/Mozilla\ Firefox/firefox.exe "
# -----------------------------------------------------------------------
# Ask what to do
echo -n "
What to do?
a. Write a journal
b. Open an existing journal
c. Add a todo
d. Write a memo
Choose (a-d): "
read choice
# set today's date
today=`date +%Y-%m-%d`
# Open file
cd "$HUGO_DIR"
case $choice in
[aA]* )
echo -n "Use today's date as file name? ([y]/n)"
read yn
# if $yn is empty, use a default value ("y")
# http://qiita.com/knqyf263/items/54814e5331770f28582d
case ${yn:-y} in
[n]* ) # use specified date
echo -n "Type date [$today]:"
read input_date
filename=${input_date:-$today}
;;
[y]* ) # use today's date
filename=$today
;;
* )
echo -n "Please answer y or n: "
;;
esac
# add title (optinal)
echo -n "Title for the log? (optional) "
read title
# if title is not empty, add it to filename.
if [ ! -z "$1" ]; then
# convert all spaces into hyphens (just in case)
title=`echo $title | sed s/\ /-/g`
# set filename
filename="$filename-$title"
fi
# add a link to a new file in index.md, if it doesn't exist
entry=`grep $filename content/index.md | wc -l`
if [ $entry = 0 ]; then
# add a link in index.md and create a new file
echo " * [$filename](post/$filename/)" >> content/index.md
echo "# $filename" >> $filename.md
#echo "Time-stamp: <>" >> $filename.md # for Emacs --- doesn't work with markdown-mode!
fi
# create a file using hugo
$HUGO_BIN new post/$filename.md
echo "\n\n # $today" >> $filename.md
# open the new file and index.md
$MY_EDITOR content/post/$filename.md content/index.md &
;;
[bB]* )
# Open the directory (asumming Emacs dired mode)
$MY_EDITOR content/post/ &
;;
[cC]* )
echo "Opening todo.md...."
$MY_EDITOR content/post/todo.md &
;;
[dD]* )
echo "Opening memo.md...."
$MY_EDITOR content/post/memo.md &
;;
* )
echo "Please choose from a to e.";;
esac
# start hugo server if not running
entry=`ps aux | grep $HUGO_BIN | wc -l`
if [ $entry = 0 ]; then
$HUGO_BIN server -t $HUGO_THEME -D --watch &
fi
$MY_BROWSER localhost:1313 &
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment