Apr 28 2011

man.vim dude

It turns out that Vim ships with a pretty sweet man page plugin included, which you’d discover if you edited man pages very often, but most of us don’t so it’s probably a lot more useful to us as a viewer.

Some of you Vim wise guys are saying, “But Vim already has a handy man page viewer, just press K in normal mode for the word under the cursor.” Sure. If you type ‘sh’ a lot in your code and docs maybe that’s great. I can count the number of times I’ve actually used it on one hand (except with plugins that remap it to language-specific doc lookups). Plus it just loads the page in a crummy pager.


runtime ftplugin/man.vim

Run that in command mode and observe that you now have a :Man command available. Think up some fun man page to browse and BOOM, you’re reading it in a split window just like :Man sh — that. Yeah, whoa.

This, my friends, is a bonafide Vim buffer. It’s pretty. It’s got syntax highlighting. But best of all, references to other man pages are tags. So when you’re reading that bash page and you’re like, “WTF isatty(3)?” you just put your cursor over that reference and with Ctrl-] you reach enlightenment.[1] When you see it’s libc and you tremble, Ctrl-t and you’re back to bash.

"This is swell!" you say. "It’d be cool if K used this for those five times in my life.”

nmap K :Man <cword><CR>

Put that in your .vimrc and smoke it.[2] Don’t forget to first runtime the plugin as above while you’re in there, to make it persistent.

Some folks like this so much they want to use it when they invoke man on the command line. I’m not drinking that kool aid yet but you might dig it.

[1] Or not. What a buzzkill. If you’re on a Mac or perhaps other platform and get an error, there’s this bug where a well-intentioned fellow fixed a problem but introduced a new one for others. Do `:e $VIMRUNTIME/ftplugin/man.vim` and comment out the `let $MANPAGER =”“` line about 20 lines in, and you should be sitting pretty.

[2] The plugin actually maps `<Leader>K` for you to do the same thing, if you want to just commit that to memory instead.

Oct 17 2010

Handy Bits for Mongoid with Rails 3

Rails 3 and Mongoid are just peachy. Here are a couple of development conveniences for using them together.

Pop this snippet in your ~/.irbrc to show the raw JavaScript queries that Mongoid is running as you play with your app in the Rails console (and/or SQL, when you’re using ActiveRecord). Formatting isn’t great for Mongo queries, but it’s helpful nonetheless.

Setting autocreate_indexes to false will spare you some log noise. It’s also worth noting that Hirb works nicely out of the box for Mongoid documents, and I heartily recommend it.

And here’s a db:console Rake task to stand in for the rails dbconsole command that won’t work with Mongoid:

Oct 15 2009

GNU screen Wrapper for SSH Agent Forwarding

This problem is well-documented around the web, this is just my personal reminder. Others have crafted various solutions varying in complexity. I like this one for the simplicity and easy portability—I don’t remember who to credit for it, unfortunately.

Without getting too deeply into the gory details, if you connect to a remote shell and run GNU screen there, then detach the screen and come back to it in a later SSH session, environment variables that SSH agent forwarding requires to function will have changed and your screen session is none the wiser. This is rather annoying if you frequently connect to a gateway server and use screen to do work on other servers inside of it—your public key will not be forwarded to the internal servers on subsequent connections.

Enter wrapper script to save new SSH variables when you connect again and resume your screen session:

# Wrapper script to set SSH env vars so agent forwarding works when
# resuming screen sessions. Place at ~/bin/screen and make sure
# your personal bin directory has priority in your PATH

    echo "export ${SSHVAR}=\"${!SSHVAR}\""
done > ~/.sshvars
/usr/bin/screen $*

Then, a simple alias for your .bashrc, to run once you’ve resumed screen:

# After reconnecting to a screen session, this restores env vars
# to allow agent forwarding to work again
alias fixssh='source ~/.sshvars'

Off you go to now to connect to those internal servers needing your forwarded key.

Oct 08 2009

Sanely Rebuild Corrupt Font Caches on OS X

For Leopard, at least:
# Clear user font caches
$ atsutil databases -removeUser

# And system cache
$ sudo atsutil databases -remove

# Restart the ATS server
$ atsutil server -shutdown
ATSServer shutdown
$ atsutil server -ping
ATSServer is running

# Check for filesystem activity (this is just generally cool)
$ sudo fs_usage | grep ATS
You might possibly still need to restart applications, log out and back in, or restart completely. Thanks to the fine people on this thread.
Jul 05 2009
The future is no more uncertain than the present.
— Walt Whitman
Dec 02 2008
I’m no good at those “guess how many jelly beans are in the jar” things though. Usually you just win the jar anyway, and who wants that many jelly beans?
Nov 06 2008


'clean blood stain' is probably one of those Web History moments where you want to make certain that you're logged out of your Google account.

Oct 03 2008

Um... Arrrr!!

  • Ches
  • I've switched Facebook to Pirate speak and it's pretty awesome
  • Sophie
  • You win! That's the most inane thing I've heard so far today
Jun 23 2008
Get the Ruby mysql gem to build with MySQL installed from 64-bit binary installer:

sudo env ARCHFLAGS=”-Os -arch x86_64 -fno-common” \
gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
Courtesy of synth @ Chris Cruft » Blog Archive » Ruby, Rails and MySQL with Leopard 10.5.2 and XCode 3.0
Apr 04 2008
  • Sophie
  • Do you know what I would have to do to make $65 an hour?
  • Ches
  • does it involve a pole and acrylic shoes?
Page 1 of 2