TIL I can use:
grep -rnw . -e 'stringToSearch'
To recursively search a directory for any files containing the string I'm looking for. Super useful when I need to find a function but don't recall what file it's in.
@consoleaccess lol I've opened vscode on a directory just to use that kind of search before :p
Now alias that to something like `sif` for Search In File and it'll be perfect. Or maybe even put it into a script ;p
@brandon The alias is a great idea because I can guarantee that I won't remember the specifics of that command. In fact, half of the reason I made that toot is so that I would have a reference in the future. 😅
@consoleaccess just remember to backup the alias file or hell, your entire home directory :p
@consoleaccess you should check out ripgrep. You get -r, -n, and . by default, color output, ignores vcs-ignored files, too. Plus, it’s faster. VSCode integrated it, and the binary name is just rg, so you don’t really need an alias to use it well.
@consoleaccess another useful option for grep: -C <x>. It shows x number of lines around the match. It's great if you're searching a log for errors and getting the whole error, not just the first line ( also comes with -A (after) and -B (before) which also take a number and show that many lines after and before each match respectively)
Fosstodon is an English speaking Mastodon instance that is open to anyone who is interested in technology; particularly free & open source software.