There are times I find that even though Visual Studio Code (VSC) does its own incredible job of searching and locating files in the search bar, it doesn’t truly give me any relevant context how some source code matches were written not just in one domain of abstraction, but also is used in other several layers of application abstraction anywhere in a typical full-stack web application.
For instance, it could be something about certain software design pattern that’s currently implemented in one area of the module but you want to affirm whether that same design pattern could be also used in other parts of the application as well.
But where can you begin to figure out where and how heavily the design patterns are used and their overall prevalence within an application, if editor tools such as VSC can’t give you the straight answers?
I found this.
Essentially, it’s another type of a Linux-based
But it’s built mainly for programmers working on source code repositories.
Typically, as software developers/engineers, we always spent a considerable proportion of our time navigating and locating source code files we need to work on when building features for our clients before we get to even type our first line of code. Naturally, we won’t always know the depth of the entire application structure upfront when given on any particular task development to do. But, even if you do, there’s always a great chance certain features are in the constant pace of change thus technologies and design decisions don’t always stand idle against the sands of time - even more so if you work on a larger development team.
As a consequence of such factors, we search for file/folders to make those necessary changes.
For a while, we got things like
grep or built-in file-search patterns editor tools to do the job for us. But as your codebase grows over time, so do their file-search algorithms’ O(N) runtimes to grow exponentially and we don’t want our development time to be stalled by such impending condition.
Now, we get to learn another awesome trick with
ack that will take our file searching duties to the next level.
To start off, install
ack onto your dev machine by looking at your specific OS environments.
As I’m using MacBooks, I do the following using HomeBrew.
Once installed, you can interact with its command shell using your favourite terminal program by typing
Let’s say, as an example, I decide that I want to do some site changes on my blog site.
I want to enhance the look and feel of my embedded video link by modifying its CSS/SASS properties.
1 2 3 4 5 6 7 8 9 10 11 12
With this change, I’d expect that any blog post content pages I wrote some months back that has embedded videos to be impacted by such modification.
However, I do not necessarily know or remember which of the same content pages upfront be in my blog repo. I want to not only how quickly I want to find out where changes are going to be, but also its context of use as well.
ack, I do the following
I get the following back
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
From this, I found out where my
embed-video-container class is being used in their respective file/folder locations. I see that it’s in
- Ruby files
- Sass files
- HTML files
Great! But I may decide I’m not interested in its use in Ruby or SASS files. I want to see which HTML files that make heavy use of the embedded widget.
So how do I filter it?
We do this.
By entering the
html flag, I get back only HTML files that contain the class name that matches with my keywords.
Now, using the same results, I want to inspect which lines of the files this snippet content sits; and understand its breadth and depth of use as a context.
Again - simple.
We do either of the following.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
B switches do is that
A is set to show me lines of content after the
embed-video-container keyword pattern whilst
B is set to show me lines of content before the same keyword pattern.
You can even combine both switches to show you what comes before and after the same keywords in one resultset.
This is sick!! 💪💪💪💪💪
With such incredible power, this toolset provides us, it’s also brazenly lightning fast to get these results compared to what VSC/grep can give you.
Not only that, if you use the terminal within your VSC executing the commands above, you can even take advantage of VSC’s
CMD+click to open up files from your ACK results set and change their content from there.
To top it off, you can use either Bash, Zsh or Fish shell to trim and abstract away your ACK commands a step further.
1 2 3 4 5 6 7 8 9
ACK commands + VSC terminal environment + Bash/Zsh/Fish = Hackers (👨💻👩💻👨💻👩💻) in GOD mode
That’s how slick ACK really is.
This is just the tip of the iceberg.
As it is a regex pattern engine powered by PERL, I can see how why I see its feedback can come off lightning quick when running them.
The key advantages I found with this tool are
- Comes with powerful recursion file/folder search algorithm with such omnipotence.
- More regex options that
grepcould never perform to match such speed and accuracy.
- It works on nearly all modern programming languages you can imagine as well as upcoming new ones.
- Good community support behind its core development in stages, so it’s live and thriving well.
For the 3rd reason, it’s a fantastic tool for polyglot engineers like me. 🖥⌨️🖱
I highly recommended that you add this to one of your arsenal developer’s toolkit.
Give it a go! You won’t regret it.
Till then, Happy Coding!