tl;dr: Supercharge your Caps Lock key by making it Esc when tapped, and Ctrl when held
Caps Lock. A useless key sitting in prime keyboard real estate. Many software developers and power users repurpose the key by remapping it to Control.
After all, on old UNIX terminals, that’s exactly what the key to the left of “A” was:
Replacing the Caps Lock key with Ctrl makes a lot of keyboard shortcuts more convenient. But we need not stop there. Some true Men and Women of Genius came to the realization that, since Ctrl’s behavior is based around behind held down (a modifier key) and doesn’t do anything when pressed and released, it is possible to make Caps Lock do something else when tapped instead of held. For Vim users, the obvious choice is the Esc key.
We can do this in both Mac OS X and Linux.
If you want all Ctrl keys to behave like Esc when tapped
This is the easiest way, and the option I use. (I rarely find myself hitting the normal Ctrl keys anyway.)
First, open System Preferences –> Keyboard, and click Modifier Keys button. Click the Caps Lock drop-down and set it to Control:
Now, install Karabiner (formerly known as KeyRemap4MacBook). If you are a Homebrew user, you should check out Homebrew Cask and install Karabiner with $ brew cask install karabiner
Open Karabiner. Enable the first setting from the screenshot below:
The other option I have there, “Disable Escape Key”, is something I’ve done just to get myself in the habit of using the Caps Lock key for Esc. It is not required, it is just an option if you want to help train yourself to use the new key.
If you only want the Caps Lock key to behave like Esc when tapped
To do this, we’re going to take a slightly different approach. Instead of using OS X’s native Caps Lock remapping, we need to use another app, called Seil (from the same developer as Karabiner) to remap the Esc key to F19, and then use Karabiner to map F19 to our cool Ctrl/Esc hybrid key.
Install both Karabiner and Seil. (Here again, if you use Homebrew Cask, you can do this with $ brew cask install karabiner and $ brew cask install seil)
Open Seil. First, enable the “Change Caps Lock” option, and set the keycode to 80:
Next, in Karabiner, enable the “F19 for Escape and Control” option:
To accomplish the same setup in Linux, we need to use a tool called xcape.
Build and install xcape per the instructions on the project’s Wiki page. One additional step I take after building the app is copying the xcape executable to /usr/local/bin.
If you only want the Caps Lock key to behave like Esc when tapped
Note: If you use some other method of remapping the Caps Lock key to Ctrl (some desktop environments have it as an option in their Keyboard settings, much like OS X), then the Caps_Lock=Escape mapping may not do anything, and you will need to use the Control_L one.
One last little tidbit: Ubuntu 14.10 (“Utopic”) has xcape in the universe repos, at least as of the time of this writing. Hopefully it will be included in Ubuntu releases from here on out.
Now Your Caps Lock Key Rules
The most useless key on the keyboard (except maybe for Pause, when’s the last time you used that?) is now your Swiss Army knife. Vim’s keybindings will make a lot more sense now that you can use your pinky the way Bill Joy did on his old ADM3A terminal:
When changing the entire file, I’ve also added the command to change the filetype in the Vim buffer, for convenience.
That takes us from HTML/ERb to Haml, but what if we need to go back in the other direction? This is possible with the haml2erb tool. Unfortunately, this tool is not actively maintained the way html2haml is. For me, on Ruby 2.1.1, it was necessary to install the 0.3.0 prerelease version, as the last official version would not build. Once installed, though, it worked as expected.
We must explicitly indicate which version to install in order to install prerelease gems:
$ gem install haml2erb -v '0.3.0.pre.3'
The Vim bindings are much the same as the html2haml ones:
Finally got around to fixing the Archive page on this site.
If I recall correctly, what happened originally is that I was attempting to get rid of the “/blog/” part of the archive path, but got distracted halfway through and left it incomplete.
For reference: this part of the archive path is not a user-configurable part of Octopress per se. It is a default location for a file in Jekyll, which is in source/blog/archive in an Octopress site repository. Simply moving the archive/ folder out of blog/ and into the top level of source/ will make the archive page generate without the “/blog/” part of the page. (For further reference, see the workaround post on the issue on Github)
The regexes can probably be improved to fix some edge cases, and I’m certain there’s a way in Vim to make it so that I don’t have to define the All and Selected versions of RubyHashes as separate functions. But these do the job for me now, until I reach a higher plane of Vim mastery.
tl;dr: You want $TERM to be screen-256color when tmux is running, and you want it to be xterm-256color when tmux is not running. Also, launch tmux with -2 argument.
I love tmux. It is the primary reason why I switched from using gVim to console vim. I love having a fully terminal-based workflow. It beats switching between a GUI editor app and terminal window any day.
This switch, however, was not without some issues. Here are the solutions to two that I encountered.
Weirdness with zsh, tmux, and vim
when $TERM is screen-256color but tmux is not running, zsh will echo your command into the output when you hit Enter:
Notice how the output of the “ls” and “echo” commands repeat themselves in the output stream as soon as I switched to screen-256color.
when $TERM is xterm-256color while tmux is running, colors will not display properly in Vim:
vim /etc/default/grub while TERM=screen-256color:
vim /etc/default/grub while TERM=xterm-256color:
In my zsh config (~/.zshrc), I set xterm-256color to be the default TERM, but right after that, added a command that would re-export TERM as screen-256color if tmux is running:
No Vim colorschemes when tmux is launched by terminal app in place of shell
I ran into a specific set of circumstances where my Vim colorscheme would not display.
Terminal applications usually launch a shell by default, but some (like gnome-terminal) have the option of defining a command to be run rather instead of the shell.
If I set this command to tmux, tmux would indeed launch. However, if I then ran Vim, the colorscheme would not display correctly.
However, if I allowed gnome-terminal to launch a shell, and then ran tmux myself from that shell, Vim would display properly within that tmux session.
I got my clue from this StackOverflow post. Basically, what is happening is that, when running tmux from within my shell, which is configured for 256 colors, tmux would launch in 256 color mode. But when I had gnome-terminal launch tmux directly, it would not.
The easy way around this was to use the “-2” argument for tmux, making the command tmux -2.
With that command in place, tmux launches whenever firing up gnome-terminal, and does so in 256 color mode.
I tracked it down to this issue, which pointed out that the error was related to the hyphenated name ending with a Ruby reserved word.
By convention, Rails uses underscores for word separation in file names. Hyphens are not completely disallowed (the above works if I rename the file to end with a non-reserve word), but can lead to issues.
The issue linked above contains a pull request for a better error message, which was merged into Rails 4. But for those still on Rails 3 and earlier, if you see this vague error message, now you know why.
tl;dr: Things not behaving right in tmux on OS X? Install reattach-to-user-namespace
Are you a tmux + Mac OS X user? Have you had any of the following problems?
Running launchctl to start services fails with a message like launch_msg(): Socket is not connected
Using the OS X Pasteboard commands pbcopy and pbpaste and having them not work
Launching a GUI app from the terminal and getting a “ghost window”: the app window loads in the background, with no dock icon, cannot be Command-Tab’d to, and the app’s menu does not populate the top bar when the window gains focus
Why does this happen? Chris Johnsen has some details…
tmux uses the daemon(3) library function when starting its server process. In Mac OS X 10.5, Apple changed daemon(3) to move the resulting process from its original bootstrap namespace to the root bootstrap namespace. This means that the tmux server, and its children, will automatically and uncontrollably lose access to what would have been their original bootstrap namespace (i.e. the one that has access to the pasteboard service).
It turns out that Apple has patched the version of GNU screen that they distribute with OS X to avoid this problem. But this is 2013, and we UNIX geeks have moved on to tmux, right? Chris goes on in that README to explain why porting Apple’s screen patch to tmux would be tricky.
So, instead, he provides the reattach-to-user-namespace wrapper program. This allows us to launch a process and have that process be attached to the per-user bootstrap namespace, which, to put it simply, makes the program behave as we are expecting.
The “trick” is to configure tmux to launch its shells with the reattach-to-user-namespace wrapper. By doing that, the shells tmux launches, as well as everything those shells launch, will be attached to the user namespace, and the problems listed at the top of this post will no longer be issues. We can use the default-command option in ~/.tmux.conf to wrap our shell launching command.
First, we need to install reattach-to-user-namespace. If you use Homebrew or MacPorts, this is as easy as:
; with Homebrew
$ brew install reattach-to-user-namespace
; with MacPorts
$ port install tmux-pasteboard
I use the same dotfiles for Linux as well as OS X, so I only want to do this in the OS X environment. I accomplish this with the following:
" at the end of the fileif-shell'test "$(uname)" = "Darwin"''source ~/.tmux-osx.conf'
If you only use OS X, you can skip creating an external file, and just put the set-option line directly in your ~/.tmux.conf. Also, I am using zsh, so my command to reattach-to-user-namespace is zsh. If you’re using a different shell, change that to your shell’s name.
With this configuration in place, kill and re-launch tmux. The shells that tmux launches should now get attached to the user namespace, and namespace-related issues should be resolved.
My mother is an accountant. Walk by her office on any given day, and you’ll likely hear the mechanical sounds of an accounting calculator printing its results to a stream of paper.
I used to make fun of the endless crunch-crunch-crunch sound that echoed down the hallways. These days, she tells me, the ol’ hand calculator doesn’t get quite as much use as before. More and more of the accounting business is computerized.
It comes as little surprise. Computers were invented to crunch numbers. When computers became machines that fit on a desktop, the “killer apps” were all about numbers: the first two applications named in Wikipedia’s entry for killer applications are Visicalc and Lotus 1-2-3.
Accordingly, it did not take long for personal computer manufacturers to take inspiration from those hand calculators and add the number pad to the right of the typewriter key layout.
Personal computers, however, have moved well beyond the domain of the office desktop. Indeed, for most people, the computer is no longer thought of as a device for performing calculations. They are used for communication, and for accessing and storing data. I don’t have data to back it up, but I would wager that most computer users don’t punch in long sequences of numbers regularly.
And yet, while the computer has evolved, the number pad remains. Like the wings of a flightless bird. the vestigal number pad sits unused, eating up space on millions of desktops.
Oh sure, you use the number pad, you say. And perhaps you do. But do you really use it enough to dedicate 6 inches of desk width for it? More to the point, does every computer user? People are buying laptops and netbooks for their computing devices more and more, and I don’t ever hear people complaining about how much they miss the numpad.
And yet, the vast majority of keyboards for sale include the numpad. Finding keyboards without them takes some effort.
One of the few I became aware of when starting the search was the Happy Hacking Keyboard Lite.
It’s a nice, small deck. It uses a “UNIX” keyboard layout, like the ones on the old Sun boxes in one of the computer labs back at university.
Apple has come around on the idea of ditching the numpad. New iMacs come with a wireless keyboard that has no numpad.
I considered picking up one of these. And I actually did pick up a couple of Apple’s discontinued wired USB tenkeyless keyboards.
They’re not bad as spare keyboards to have around, but they were not going to be my primary keyboard. (My wife is using one on her desktop machine, though).
One keyboard I really want is the 84-key “Space Saving” version of the IBM Model M.
Sadly, they are awfully hard to come by. I watch for them on clickykeyboards.com but it’s just an endless list of SOLD boards.
But the keyboard that ended my search was the Leopold Tenkeyless Tactile Touch from EliteKeyboards. It combined my desire for a compact no-numpad keyboard with the desire to have a mechanical keyboard.
It’s been a couple of years now since I bought this keyboard, and while the idea of spending $100 on a keyboard was a tough pill to swallow at the time, I would not hesitate to do it again. The compact size make life nicer on my desk, and the action of the mechanical key switches is so much more enjoyable than mashing the rubber dome switches on a non-mechanical keyboard.
I have been running this blog on Wordpress since 2005. Back then, Wordpress was purely a blogging engine.
In the years since then, Wordpress has grown into something more akin to a CMS built around a blogging engine. At work, we have used it as such for a couple of smallstorefronts, built around the blog and the Wordpress e-Commerce shopping cart plugin.
Maintaining a full Wordpress installation for my personal blog, however, had become cumbersome. Particularly so since I am not running any other PHP code for personal projects. At Lone Star Ruby Conference, one of the talks finally convinced me that it was time to leave Wordpress behind, and to go with a static site compiled blog engine. I had previous experience with a static site compiler, nanoc, which we use at work for creating static websites. A more blog-aware tool that works similarly held plenty of appeal to me.
I also no longer wished to run this site on hosting that costs me money. I started with shared hosts like Dreamhost, graduated to a Linode VPS (more for experimenting with VPS hosting than for any actual traffic needs), and most recently ditched the VPS and hosted on NearlyFreeSpeech’s low-cost pay-as-you-use hosting. But for how low traffic the site is, paying even what I give to NearlyFreeSpeech seemed unnecessary. Heroku’s free single web dyno was staring me in the face, offering more than enough hosting power for a static version of my site, for $0.
Introducing Jekyll and Octopress
Octopress is a framework built around the Jekyll blogging engine. It provides various plugins and extensions, as well as a nice default theme, to make blogging on Jekyll a nice out-of-the-box experience.
Jekyll allows users to write blog posts in Markdown and compile them into static HTML pages. Instead of writing posts in a web-based panel, posts are created by adding a new Markdown file in the _posts folder, and writing the post in there using the user’s editor of choice. Finally, I am blogging with Vim.
Octopress provides out-of-the-box support for Disqus commenting, recent Twitter tweets in the sidebar, Google Analytics, and a whole host of other added functionality.
Importing Content from Wordpress
My strategy for importing my Wordpress content into a Jekyll blog reolved around Exitwp. Exitwp will parse a Wordpress export file and generate a Jekyll blog with the same content.
The Exitwp Github page has instructions for installing dependencies on Ubuntu, but on Homebrew on OS X, the commands were:
(Important: make sure /usr/local/share/python is in $PATH.)
Next, I needed to go into my Wordpress admin page and generate a Wordpress export XML file. As of the time of this writing, this is done in Wordpress by logging in to the dashboard as an admin, and going to Tools –> Export.
With the export XML file generated and on my desktop, I set Exitwp to work:
$ python exitwp.py name-of-export-file.xml
One important thing to note: images require some handling. You can make Exitwp download your blog’s images by editing the Exitwp config.yaml file and setting…
… however, this will only download the image files. It will not edit the posts themselves to point to new image locations.
I did not relish the idea of going through all of my old posts and editing each of the image URLs. Instead, what I did was create a wp-content/uploads folder in my Octopress blog’s source/ folder, and copied the contents of wp-content/uploads from my Wordpress blog into there. Since I am hosting the new blog on the same domain, the result is that all of those image files will still be on the same URL. Having a wp-content folder inside my new blog is slightly ugly, but it solves the problem for now, and allows me to gradually move images over and edit image paths on old posts.
Also important to note: comments have to be dealt with separately, too. As a static site has no capacity for comment handling itself, comments on Jekyll/Octopress blogs are handled by Disqus. Fortunately, in my case, I had already moved my Wordpress site to using Disqus commenting. For me, that meant that my comments would carry over to the new site, so long as my post URLs did not change. In my case, this meant making just a small tweak to the config file of the Jekyll blog once it was generated, so that the URL structure would mirror my old Wordpress site’s.
Setting up Octopress
After running Exitwp, I have my old blog exported into a raw Jekyll blog. But now, I have to get that blog into Octopress.
This part confused me for a while. It seems like something everyone else just glossed over.
For starters, I knew I wanted to store this blog in Git. The Octopress instructions would have me clone the Octopress repository, but I don’t want Octopress to be the origin on my blog repo. Instead, I did much like this blog post demonstrates – I made my own blank repository, and I added the Octopress repo as a remote head.
So, now I had Git set up, and I had Octopress checked out locally by virtue of having run git pull octopress master. The part that wasn’t immediately obvious to me was how I was to take my Exitwp-generated Jekyll blog and put that in there.
Exitwp put my generated blog in exitwp/build/jekyll/blog-name. I copied the contents of this folder, and pasted it into octopress/source. Now, my Jekyll content was where it needed to be in Octopress.
To update my remote repo’s copy of the site, I check everything in, and run
$ git push origin master
And whenever I want to pull in the latest updates from Octopress, it’s
$ git pull octopress master
Deploying to Heroku
Adding to the Git setup even more was the fact that I wanted to deploy this to Heroku. For that setup, I basically followed these instructions starting at the “Deploy to Heroku” section. I had never deployed an app to Heroku, but it was very straightforward.
Since Heroku acts as a Git server, I could have skipped the part where I made my own repository host, and just cloned from Heroku whenever I wanted to access the repo on another machine. But I prefer having a copy of the site in my own Git hosting account (on Bitbucket, for the record), and it’s hardly any additional bother. My Bitbucket repo is on “origin”, the Octopress repo is on “octopress”, and Heroku is on “heroku”.
Whenever I want to push updates to deploy to Heroku, I simply do
I haven’t used Octopress for very long yet, but a few thoughts:
Writing posts in Vim and in Markdown syntax has made me realize how much of a drag using the Wordpress post editor was on my blog writing. I write code all day in Vim, and writing my blog posts there too is much less of a context switch. Flicking back and forth between Vim buffers is a lot less of a hassle. It makes offline blogging a lot easier, too.
I never found a code formatting plugin for Wordpress that I did not hate. Octopress comes with code formatting styling out-of-the-box and it works very well. I’m not a huge fan of the Solarized theme it uses by default, and I may see about changing that in the future. But the important thing is that it works.
Not having to worry about Wordpress updates is a big relief. I can’t say that I stayed on top of updates nearly as much as I needed to. And I don’t have to worry about database backups, either. There’s a “weight off my shoulders” feeling with making this move.
There’s something comforting about having my entire blog history as a series of Markdown files, instead of posts locked away in a Wordpress database table in MySQL.
There are a lot of neat Octopress plugins that I haven’t really delved into yet. But the default out-of-the-box experience is pretty much awesome. Even if, for now, my blog looks just like a bunch of other Octopress blogs.
Tip: Use IFTTT to tweet new posts
One of the plugins I used with Wordpress would add tweets to my Twitter feed, informing followers of new posts to the blog.
Without the server-side component, Octopress lacks this ability. However, thanks to the fact that Octopress generates an RSS feed file, we can use an external service to accomplish the same thing.
IFTTT is a service that allows you to write “triggers” that perform various actions. In this case, I have IFTTT watching my blog’s RSS feed, and whenever it detects a new feed item, it makes a post to my Twitter, as well as one to my Facebook wall.
Tip: Use Pow on OS X for easy testing
By default, users can run rake preview to make Octopress spin up a web server at http://0.0.0.0:4000 and listen for changes to files to automatically rebuild the site for easy previewing.
This process can be made a little nicer with Pow, a handy little Rack webserver for OS X.
Just add a symlink your site folder in to ~/.pow/, and your system will run that site, and configure it to be reachable at http://symlink-name.dev. Then, run rake watch to make Octopress listen for changes and rebuild pages.
Gotcha: Drafts aren’t imported by Exitwp
I had accumulated many half-written posts in my Wordpress install over the years. Posts that I totally intend to finish.
Exitwp did not import these (or, more likely, the Wordpress export functionality did not include them in the export. I’m not sure which it is.)
I ended up fetching these manually.
Gotcha: zsh and square bracket commands
From that point on, I just followed the Octopress documentation to get up and running. I did, however, run into an annoying issue.
Octopress command-line commands often use square brackets, such as:
$ rake new_post["My new post's title"]
Run it in zsh, though, and you get:
$ rake new_post["My new post's title"]
zsh: no matches found: new_post[My new post's title]
The problem is that square brackets are a glob operator in zsh. This blog post pointed me in the right direction. The “solution” is to escape the square bracket characters.
$ rake new_post\["My new post's title"\]
Alternately, zsh users can disable zsh’s GLOB option. From the Octopress Github issue on this problem, though, it sounds like some tweaks will be added to Octopress to address the issue.
Thankfully, jailbreaking iOS users can now add Nitro support to Chrome (and other apps) with the new Nitrous app on the Cydia store.
Nitrous adds a menu to the iOS Settings app, which allows users to selectively flag applications to use Nitro, thus allowing that app’s web views to perform as they do in mobile Safari.
Enabling Nitro on non-Safari web browsers is great enough, but it also allows enabling Nitro on other apps that make use of UIWebViews, such as client apps for Reddit, Twitter, and Facebook.
While it’s not quite the same thing as Chrome being able to include V8 in iOS Chrome, the ability to use Nitro in Chrome takes away one of the two major disadvantages Chrome has on iOS. (The other disadvantage – not being the default browser – can be solved with the Browser Chooser app, allowing users to elevate Chrome to the iOS default browser).