Automating Jekyll with Fish

Last month, I wrote about my experiment with iOS and a remote server from Digital Ocean. It’s working very well, but Emacs can feel a bit sluggish at times, served up remotely over a crowded public wi-fi network. Vim is speedy, and since I use Evil on Emacs, it’s not too painful to switch occasionally. Any pain comes from the loss of the automation with all of those Emacs functions I’ve written and collected over the years.

I thought about writing some scripts in Elisp, but settled on functions in the Fish Shell. The first function creates an appropriately named Markdown file with YAML front-matter. The important parts come from Marc Ransome:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
function draft -d "Open default editor with date prepended filename and specified title for jekyll posts."

cd ~/Dropbox/blog-drafts

# Create file
  set title (date +"%Y-%m-%d")
  
  switch (count $argv) 
    case 0
      echo "No post title was specified."
      return 1
    case 1
      set lower_arg (echo $argv[1] | tr A-Z a-z)
      set title $title-$lower_arg.md
    case \*
      for arg in $argv
        set lower_arg (echo $arg | tr A-Z a-z)
        set title $title-$lower_arg
      end
      set title $title.md
  end
  
# Append YAML
echo "---" >> $title
echo "layout: post" >> $title
echo "title: " $argv >> $title
echo "tags:" >> $title
echo "- " >> $title
echo "comments: true" >> $title
echo "date:" (date +"%Y-%m-%d %H:%M:%S") >> $title
echo "---" >> $title

# Open file in VIM
  EDITOR $title
end

The other two functions were very simple – one to move a completed draft to the _posts folder, and another to commit the new post and push to Github with the imaginative commit message, “New post”:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
function post
   mv $argv ~/Sites/rlridenour.github.io/_posts
end

function publish
 cd ~/Sites/rlridenour.github.io
 git add .
 git commit -m "New post."
 git push
end