I think many more than once faced such a problem as the need to find a file in the folder with files (and sometimes subfolders, in which it would also be nice to search) a file, knowing a piece of its text (well, or guessing about it). I, too, many times stumbled about this need and now, finally, I got together and wrote a small bash script that performs this task.
')
The script is called by string. textfind %name% You can also set a template for the file name (second argument) and color that will display the names of the files in which the required excerpt is found (green by default, you need to install the set_color utility to enable the color, under sudo apt-get install fish).
Here is the actual script itself:
#!/bin/bash cmd="find -type f -print " set_color_cmd="set_color" if [ $2 ]; then cmd="$cmd -name \"$2\""; fi color="green" if [ $3 ]; then color=$3; fi
is_colored=1 hh=$(which "$set_color_cmd") if [ $? -ne 0 ]; then is_colored=''; fi
$cmd | while read f; do cnt=$(grep -c "$1" "$f") if [ $cnt -gt 0 ]; then if [ $is_colored ]; then "$set_color_cmd" "$color"; fi echo "$f" if [ $is_colored ]; then "$set_color_cmd" normal; fi grep -n "$1" "$f" fi done