Bash and Dash

I know, “bash and dash” sounds like a sadistic game for frat boys. But it rhymed and was so apropos.

Here’s a quick tip for Dash users. If you want to put Dash’s powerful browsing and search features to use from the command line, a couple quick shell aliases will make life that much more fun.

First an easy script to open any arguments as a search in Dash. (Thanks to kavu for the note about $* vs. $@).

# Open argument in Dash
function dash() {
	open "dash://$*"
}

With that combination, you can just type dash ruby:FileUtils cp_r on the command line and have Dash open your Ruby docset, locate the FileUtils class, and search the page for cp_r. Anything that works in the Dash search field works in a url.

One last quickie… I love being able to open man pages in Dash, search them, bookmark them, and have them float while I try things out in a Terminal window. Assuming you have the man page docset enabled (and your shortcut is man:), you can make a quick shortcut that will let you do dman sort and pop open the sort man page.

function dman() {
	open "dash://man:$*"
}

If you were so inclined, you could name it man and just have it replace the built-in man command, but that seems drastic. Note that you can start searches immediately from the command line as well: dman find -atime.

URL schemes are so much fun.

Ryan Irelan has produced a series of shell trick videos based on BrettTerpstra.com posts. Readers can get 10% off using the coupon code TERPSTRA.

Brett Terpstra

Brett is a writer and developer living in Minnesota, USA. You can follow him as ttscoff on Twitter, GitHub, and Mastodon. Keep up with this blog by subscribing in your favorite news reader.

This content is supported by readers like you.