4 ms·
I customized grep-find on my setup. I have a shell script so that it does the following (in typescript-mode) first search ts, tsx, js, jsx files in the curren
by paddy_m 1y ago
I customized grep-find on my setup. I have a shell script so that it does the following (in typescript-mode)
first search ts, tsx, js, jsx files in the current project. Exclude .git, node_modules...
then search node_modules with the ts.. extensions, still exclude .git
finally search the whole tree for .py files still exclude .git, /dist...
This is coupled with consult-find-grep. I basically want to find a string in the most relevant file type. I never want a result from node_modules first in the results. It took some work, but the results are quite nice!
- kragen 1y agoOh, yeah, I wrote some Emacs Lisp that did that kind of project-specific thing for a Perl project I was working on for a couple of years in 02003 and 02004. One function key would search the whole project for occurrences of the identifier under the cursor, and another one would search for definitions.
- rrgok 1y agoWould you mind sharing how you did the prioritization of the sources when searching?
- kragen 1y agoNot the original poster, but if I were doing it with find rather than fd (or ag or rg, which I think can do it without fd or find) I'd do (untested) (find "$projroot" -name .git -prune -o -name node_modules -prune -o \ \( -name '*.[tj]s' -o -name '*.[tj]sx' \) -print0 ; find "$projroot"/node_modules \ \( -name '*.[tj]s' -o -name '*.[tj]sx' \) -print0 ; find "$projroot" -name .git -prune -o -name dist -prune -o \ \( -name '*.py' \) -print0 ) | xargs -0 grep /dev/null "$search_pattern" And, although that approach does work (and maybe even that script will work without any bug fixes) it probably goes a substantial distance toward showing why fd was written. Doing the three searches separately and exiting after one succeeds is only slightly more code.
- paddy_m 1y agohttps://github.com/paddymul/emacs-from-scratch/blob/master/personal/paddy-find-setup.el https://github.com/paddymul/emacs-from-scratch/blob/master/p... and https://github.com/paddymul/emacs-from-scratch/blob/master/personal/find_script.sh https://github.com/paddymul/emacs-from-scratch/blob/master/p... The emacs-lisp for changing the behaviour of consult-grep was quite complex and took a while to write.