Example .ackrc

Before using ack, let's get a good configuration going. The file ~/.ackrc contains a set of command line switches that ack will use when running. This annotated config makes it pretty cool.

# 
# Edoceo ~/.ackrc
--break
--color

# I'm tired of grouping
# --noheading

# mg
# --pager=less --long-prompt --no-init --no-lessopen --quiet --quit-if-one-screen --RAW-CONTROL-CHARS --line-numbers

# o
# --pager=less --no-init --no-lessopen --quit-if-one-screen --line-numbers
# --pager=less 

# --pager=less -iqRS

# only search with case sensitivity if there is mixed case
--smart-case

# Sort the files
--sort-files

--type-set=web=.css,.htm,.html,.php,.phtml,.js

Per Directory .ackrc

Usually, ack only checks your ~/.ackrc file for it’s default switches. Per directory ack settings can be enabled by adding this in your environment, maybe via .bash_profile:

export ACKRC=".ackrc"

Now a .ackrc file can be added to any directory to influence behaviour when ack-ing the directory.

Finding Patterns

Here are a bundle of examples of using the tool ack, which is better than grep.

Ack uses PCRE by default, sweet!

~ $ ack '/'

Formatting Outputs

Ack Type Shortcuts

Use these features when looking at large code base and only wanting to search specific files. For example, a webroot with some PHP and 1000s of images will be slow, unless you specify --php option.

ils-server server # ack --help type
Usage: ack [OPTION]... PATTERN [FILES]

The following is the list of filetypes supported by ack.  You can
specify a file type with the --type=TYPE format, or the --TYPE
format.  For example, both --type=perl and --perl work.

Note that some extensions may appear in multiple types.  For example,
.pod files are both Perl and Parrot.

    --[no]actionscript .as .mxml
    --[no]ada          .ada .adb .ads
    --[no]asm          .asm .s
    --[no]batch        .bat .cmd
    --[no]binary       Binary files, as defined by Perl's -B op (default: off)
    --[no]cc           .c .h .xs
    --[no]cfmx         .cfc .cfm .cfml
    --[no]clojure      .clj
    --[no]cpp          .cpp .cc .cxx .m .hpp .hh .h .hxx
    --[no]csharp       .cs
    --[no]css          .css
    --[no]delphi       .pas .int .dfm .nfm .dof .dpk .dproj .groupproj .bdsgroup .bdsproj
    --[no]elisp        .el
    --[no]erlang       .erl .hrl
    --[no]fortran      .f .f77 .f90 .f95 .f03 .for .ftn .fpp
    --[no]gentoo       .ebuild .eclass
    --[no]go           .go
    --[no]haskell      .hs .lhs
    --[no]hh           .h
    --[no]html         .htm .html .shtml .xhtml
    --[no]java         .java .properties
    --[no]js           .js
    --[no]jsp          .jsp .jspx .jhtm .jhtml
    --[no]lisp         .lisp .lsp
    --[no]lua          .lua
    --[no]make         Makefiles (including *.mk and *.mak)
    --[no]mason        .mas .mhtml .mpl .mtxt
    --[no]objc         .m .h
    --[no]objcpp       .mm .h
    --[no]ocaml        .ml .mli
    --[no]parrot       .pir .pasm .pmc .ops .pod .pg .tg
    --[no]perl         .pl .pm .pod .t
    --[no]php          .php .phpt .php3 .php4 .php5 .phtml
    --[no]plone        .pt .cpt .metadata .cpy .py
    --[no]python       .py
    --[no]rake         Rakefiles
    --[no]ruby         .rb .rhtml .rjs .rxml .erb .rake .spec
    --[no]scala        .scala
    --[no]scheme       .scm .ss
    --[no]shell        .sh .bash .csh .tcsh .ksh .zsh
    --[no]skipped      Files, but not directories, normally skipped by ack (default: off)
    --[no]smalltalk    .st
    --[no]sql          .sql .ctl
    --[no]tcl          .tcl .itcl .itk
    --[no]tex          .tex .cls .sty
    --[no]text         Text files, as defined by Perl's -T op (default: off)
    --[no]tt           .tt .tt2 .ttml
    --[no]vb           .bas .cls .frm .ctl .vb .resx
    --[no]verilog      .v .vh .sv
    --[no]vhdl         .vhd .vhdl
    --[no]vim          .vim
    --[no]xml          .xml .dtd .xsl .xslt .ent
    --[no]yaml         .yaml .yml