Joel, sometimes @jayroh

menu

Correctly Syntax Highlight Your Shell Scripts

04 Jan 2016

Not all shell scripts are created equal. You may have a do-something.sh script, or maybe you call it do-something? Maybe it uses the bourne shell? Maybe bash? Maybe zsh? I don't know. We all have opinions.

You're probably using vim to edit that thing though, right? If you're reading this, you probably do. Isn't it bothersome when you're editing that file and want it highlighted with the correct syntax? That's easy enough, if you use the .sh extension.

au BufRead,BufNewFile *.sh set ft=sh

It's less easy if you mix and match shells or don't use the file extension. I sometimes don't. In those cases I check for what's going on in the she-bang.

au BufRead,BufNewFile,BufWrite *
      \ if getline(1) =~ "#!/bin/bash" |
      \   set ft=sh |
      \ endif

au BufRead,BufNewFile,BufWrite *
      \ if getline(1) =~ "#!/bin/zsh" |
      \   set ft=zsh |
      \ endif

Maybe that's overkill. Have a better solution? I bet you do :). Let me know!

Writing in Markdown With Vim

02 Jan 2016

While writing a post yesterday I noticed there were some gaps in my vim setup for when I'm authoring a markdown file so here are a few tips for polishing up your markdown experience in vim, specifically for jekyll blogs.

Front Matter

Starting at the top, literally, with the front matter. It was looking a bit weird out of the box:

jekyll front matter better

It's rather inconsequential data compared to the meat of the document, the actual content. I found a helpful blog post with some details that worked for me. The heart of which is to parse between the ---s and consider this content a comment.

au BufNewFile,BufRead,BufWrite *.md syntax match Comment /\%^---\_.\{-}---$/

After, it looks a little less odd.

jekyll front matter after

Textwidth

I prefer a little more space when I'm writing so I change the width before text wraps to something slightly more than my default 80 character width - like 100 characters. In my autocommand group I place something like:

au FileType markdown setlocal textwidth=100

Fenced-in Languages

If you have many, or maybe super-specific, languages and syntaxes you commonly use in your markdown you can specify them in your vimrc to be interpreted as such.

let g:markdown_fenced_languages = ['javascript', 'ruby', 'sh', 'yaml', 'javascript', 'html', 'vim', 'coffee', 'json', 'diff']

Snippets

I use snipmate but I guess the same can be applied with something like UltiSnips? Probably. In any case, snippets are a lifesaver for the occasional piece of code or markup you can either never remember the exact syntax for, or are slightly awkward to type. For me it's more often the former.

~/.vim/snippets/markdown.snippets

snippet a
    [${1:text}](${2:http://})
snippet img
    ![${1:alt}](${2:http://})
snippet front
    ---
    title: ${1:Title}
    author: Joel
    layout: post
    permalink: `strftime("/%Y/%m/%d")`/${2:slug}.html
    ---

The first two are for links and image tags, respectively. I consistently confuse the two so why leave it to guessing? The front snippet is handy in that date for the permalink is automatically populated when the snippet is expanded.

Preview Your Markdown

A tweet from Ches asking about previewing documents piqued my curiosity so I decided to look into it a little further. His suggestion to try the QuickLook plugin was met with failure, as he mentioned, as there's some weirdness when you try to launch from terminal. From finder it seems to work just fine but that defeats the purpose of being vim-driven, right? The next best thing would be to leverage a native mac app to get a look at what our rendered markdown files look like. The app I prefer is called MacDown and has plenty of good features if you ever feel like dropping into a gui app instead of vim.

MacDown comes with a cli command you can use to open documents from the terminal but I've found that it doesn't retain your preferences and switches to the defaults once you use it. Using OS X's open command, however, does retain your preferences. So, about getting vim to play nice with this? Not so hard:

map <leader>pre :w<cr>:silent! !open -a MacDown % > /dev/null &<cr>:redraw!<cr>

So <leader>pre will now open up MacDown with the current document so I can get a good look. Not bad!

The changes to MacDown's preferences I've found useful:

  • General > Put editor on the right. I don't care much about the editor, so it gets shoved right.
  • Rendering > Detect Jekyll front-matter. For those of us jekyll users.

Helpful Plugins

  • goyo.vim plugin. A really nice distraction free writing plugin suggested by Thomas.
  • tpope's markdown plugin. Arguably unecessary but provides some fenced codeblock extras.
  • Chris Toomey's titlecase plugin. Teach Vim about titlecase, with support for motions and text objects
  • Chris Toomey's quicklink plugin. This is nothing short of beautiful. A Vim plugin for quickly looking up a topic in google and inserting the relevant link. Bonus video with some insight on these two plugins from Chris.

Adios 2015. You were alright.

01 Jan 2016

I'll get right into it - 2015 was a good year. And, there's no way around this, it was because of the birth of my son, Grayson.

That's pretty much it. That's the TLDR version of our year.

The Longer Version

There isn't a single event in the 38 years of my life that has had as profound an effect on my day to day life as the birth of this child. Most things people tell you – "There's you the day before, there's you the day after, they're night and day", etc – that's certainly true. You can't escape that. There are other adages that are a little less universally true ("It was the greatest day of my life!" ... actually, it was stressful), but we're all our own people, right? In any case, the incredible evolution in me personally has been this incredible shift philosophically where I can now consider the path in front of my son to be a clean slate. I no longer mull over what happened before, as that is history writ, instead I can concentrate moving forward on the wonderful future we, he, I, have ahead of us. My enthusiasm for this new year is unlike almost all before.

Elsewhere

Knowing that Sara and I were expecting Gray to join us I started 2015 with a bit of a resolve to work on a few things personally and emotionally. I can look back on the year and consider them a success as I feel better now than I did a year ago. My motivation this year was to work on some base fundamental parts of me that I had unintentionally neglected - my mind, my emotional state, my inner self. I guess the preparation for a baby had the cliche'd existential effect.

Of the behavioral changes I attempted the three that were most beneficial were, first, to see a therapist semi-regularly. I cannot recommend that, in particular, enough. Find someone you trust and can establish a healthy rapport with and see them once every other week, or once a month, or as often as you need. As complicated human beings sometimes the best medicine is to externalize and talk things out. Clarity has come to me more often than not by the time my 45 minutes is up.

The second is meditation. My practice is admittedly pretty sporadic and would probably not stand up to scrutiny of being called "practice". But of the times I notice that I need the time to stop and reflect, I spend 15 minutes with some guided meditation, either with headspace app, or my former company's app with Dan Harris and Joseph Goldstein- 10% Happier To call it effective, for me, would be a vast understatement. If you're wondering about it and think dipping your toes in with a bit of a skeptical bent is necessary I would highly recommend reading Dan's book of the same name "10% Happier". It's easily up there with my other favorite books of 2015.

Lastly, writing for myself. Writing for the public—as you can very well see elsewhere in this site—isn't my strongest suit. Writing for myself, to myself, when I need to let some thoughts out has been therapeutic. I've been using an app called Day One on both my laptop and my phone to keep these thoughts together in one place, synced, and at the tip of my fingers whenever the need strikes. I've been on the train riding home from work, struggling with something or other, and the time I take to write via stream of consciousness has been wonderful as a means of getting things off my chest. It's a more personal form of self therapy. I know no one else will see it (ha - false security much?) so I can get out whatever is on my mind. I highly recommend providing yourself an outlet to accomplish this.

Some of those may help you, some of them may not, most of them may not – but that's ok. There is no perscriptive for life and nothing works for everyone. If you're reading this and feel similarly I recommend exploring your options and, above all, be honest with, and kind to, yourself.

Furthermore

The clean slate metaphor applies in a few other facets of my life. I have recently, as of Thanksgiving, left my job at a small startup and spent most of December working exclusively on a project I've been chipping away at for months. I'm really excited about it and I'll be writing more about it here soon. I'll leave that for its own post, for now. I'm having conversations with friends and colleagues and looking forward to, most likely, some time contracting and freelancing. If you're interested in chatting (please, no full time inquiries) email or tweet at me.

Happy new year!

P.S.

This year's favorites.

Movies: a tie - Mad Max: Fury Road & Sicario.

Book: Station Eleven.

Tv: Fargo.

Music: I have no f'ing clue.

close
Joel Oliveira

Hi, I'm Joel.

I'm a software engineer in Boston. You can follow me on twitter at @jayroh. I tweet about beer, bulldogs, and writing code.

Articles from 2012

Articles from 2007