KISS

Keep It Simple Stupid

Ack in octopress's directory

| comments

You sure know one of the basic command-line tools used to search patterns in files, called grep (and egrep and similar ones). Recently I came across a better replacement of grep that is more suitable in 98% of cases. Behold: ack! Two main features why I like it are by-default ignoring of all the irrelevant files and directories (backup files, .git and .svn directories, etc.) and color highlighting of search results.

First, install it if you haven’t yet:

1
2
3
4
5
6
7
8
9
10
11
12
# Arch Linux
$ yaourt ack

# Ubuntu Linux
$ sudo apt-get install ack-grep

# OS X
$ brew install ack

# or
# Your distro
$ sudo I want ack now!

When I tried to do a search of $header-bg like this:

1
$ ack --ignore-dir=public/ '\$header-bg'

to change it, there were no results. How can that be if I’m 100% sure it’s defined in a style file? Little digging in the man page and using the -f switch revealed that ack searches in the files which type it knows only by default. The -a switch makes it look inside unknown files as well.

However, it’s better to tell ack that we want it to support .markdown and .scss text files too. Add the lines to your ~/.ackrc file:

~/.ackrc
1
2
3
--type-set=markdown=.markdown

--type-add=css=.scss

linux

Don't hesitate to leave a comment below. NB! If you don't see a comment form under the post, it's most likely that an extension (such as Ghostery, NoScript, or AdBlock) of your browser blocks the scripts from disqus.com, and you can unblock that.

« Zsh: search with Up/Down keys Need to get your perl fixed? »

Comments