Introduction
From time to time, I want to search over my dotfiles, precisely those immediately
under my home directory ~/
. The problem of grep -R <regex>
is that it
quickly delves into an oceanic trench, full of caches, xml files or
databases. In other words, it uses a depth-first approach.
bfs-grep
The following shell function helps me greatly to deal with such a situation.
It employs a breadth-first search, i.e. level by level. It is written for
zsh
but should work for bash
or ksh93
1. The tput
commands are just
used to redden the level announcement. Further tweaks can be made such as
changing the dot .
(current directory) to a target directory or starting from
a specific level. But that’s enough for me.
|
|
Usage
bfs-grep
first argument is the maximum depth to search, starting from 1
for the
current level. The remaining arguments are fed to grep
.