I'm sure that there are nicer ways to do this than with shell commands, but sometimes it's fun to tinker.

Walkthrough

I'll use the string 'Saλuton Mondo! @123' as an example, because it contains mixed case and some symbols and unicode.

Opening Vim and Sending in Commands

You can pass commands into Vim during launch with the syntax below. This example opens Vim and reads in the contents of templates/post.md which is a basic template for a new blog post. <filename> will be a generated string:

$ vim +':r templates/post.md' <filename>

Slugifying the Filename

Sed is a stream editor that is useful for quick text substition on the command line.

You can pipe strings into Sed like this:

$ echo 'Saλuton Mondo @123' | sed -e 's/[^[:alnum:]]/-/g'

The 's/foo/bar/g' syntax is just a search and replace using a regular expression.

That example takes the string and replaces anything that is not alphanumerica with a dash. Running it produces this result, which is not exactly what is wanted:

Saλuton-Mondo--123

Duplicate dashes can be removed with the translate (tr) command using the -s (squeeze repeats) option: