Today I want to introduce one of my favorite little console tools Ack!
The first time had a contact with Ack, was as I started learning vim.
Ack doest similar things as unix grep basically just text searching for a certain string. What we usually do as programmers ist something like “I want to see all occurrences for the bean named MyBean in all xml files”.
If you are already in the folder that contains all your files you want to search through, you would do just this:
ack MyBean –xml
Installation, as usual with homebrew
brew install ack
now, just go to one of your projects on the console and try it
ack mystring1 –java
ack mystring2 –ruby
ack mystring3 –xml
Important: by giving a file type, you basically talk about a file group, so if you give –html => .htm .html .shtml .xhtml are included.
All this is fine, but what brought me to write this blogpost is the need to define your own file extension or extend a present one.
So say I have another file type, that is not known to ack. e.g its called impex ( a hybris fixtures file type).
What I ended up doing is:
1. Create an .ackrc in your home folder
with the content:
This will define a complete new type for ack, called impex including all *.impex and all *.csv files.
Now I can search fast trough my java projects without opening eclipse for it 🙂
This is one more step to more console and lightweight work, avoiding heavy IDE’s .