Doom-emacs: Search hidden files when searching Project

Created on 21 May 2020  Â·  9Comments  Â·  Source: hlissner/doom-emacs

Describe the feature
Using SPC s p should invoke rg with --hidden to search hidden files in the project too. It seems that it uses counsel-rg-base-command variable which is set to "rg" "-L" "--search-zip" "--no-heading" "--color=never"

System information


((emacs
(version . "26.1")
(features . "XPM JPEG TIFF GIF PNG RSVG IMAGEMAGICK SOUND GPM DBUS GSETTINGS NOTIFY ACL LIBSELINUX GNUTLS LIBXML2 FREETYPE M17N_FLT LIBOTF XFT ZLIB TOOLKIT_SCROLL_BARS GTK3 X11 THREADS LIBSYSTEMD LCMS2")
(build . "Sep 09, 2019")
(buildopts "--build x86_64-linux-gnu --prefix=/usr --sharedstatedir=/var/lib --libexecdir=/usr/lib --localstatedir=/var/lib --infodir=/usr/share/info --mandir=/usr/share/man --enable-libsystemd --with-pop=yes --enable-locallisppath=/etc/emacs:/usr/local/share/emacs/26.1/site-lisp:/usr/local/share/emacs/site-lisp:/usr/share/emacs/26.1/site-lisp:/usr/share/emacs/site-lisp --with-sound=alsa --without-gconf --with-mailutils --build x86_64-linux-gnu --prefix=/usr --sharedstatedir=/var/lib --libexecdir=/usr/lib --localstatedir=/var/lib --infodir=/usr/share/info --mandir=/usr/share/man --enable-libsystemd --with-pop=yes --enable-locallisppath=/etc/emacs:/usr/local/share/emacs/26.1/site-lisp:/usr/local/share/emacs/site-lisp:/usr/share/emacs/26.1/site-lisp:/usr/share/emacs/site-lisp --with-sound=alsa --without-gconf --with-mailutils --with-x=yes --with-x-toolkit=gtk3 --with-toolkit-scroll-bars 'CFLAGS=-g -O2 -fdebug-prefix-map=/build/emacs-iJm1BQ/emacs-26.1+1=. -fstack-protector-strong -Wformat -Werror=format-security -Wall' 'CPPFLAGS=-Wdate-time -D_FORTIFY_SOURCE=2' LDFLAGS=-Wl,-z,relro")
(windowsys . batch)
(daemonp . server-running))
(doom
(version . "2.0.9")
(build . "HEAD -> develop 265e80123 2020-05-19 05:35:03 -0400")
(dir . "~/.doom.d/"))
(system
(type . gnu/linux)
(config . "x86_64-pc-linux-gnu")
(shell . "/bin/bash")
(uname . "Linux 5.5.0-2-amd64 #1 SMP Debian 5.5.17-1 (2020-04-15) x86_64")
(path "~/.npm-packages/bin" "~/.gems/bin" "~/git/adr-tools/src" "~/.cargo/bin" "~/.local/bin" "~/bin/" "~/node_modules/.bin/" "~/git/git-tools/" "/usr/local/sbin" "/usr/local/bin" "~/.cargo/bin" "~/bin" "/usr/local/bin" "/usr/bin" "/bin" "/usr/local/games" "/usr/games" "/snap/bin" "/usr/lib/emacs/26.1/x86_64-linux-gnu"))
(config
(envfile . envvar-file)
(elc-files . 0)
(modules :completion company ivy :ui doom doom-dashboard hl-todo indent-guides modeline ophints (popup +defaults) vc-gutter vi-tilde-fringe workspaces :editor (evil +everywhere) file-templates fold word-wrap :emacs (dired +icons +ranger) electric undo vc :term eshell :checkers syntax spell :tools ansible docker editorconfig (eval +overlay) lookup magit terraform :lang data emacs-lisp json javascript markdown (org +dragndrop +journal) python sh web yaml :email mu4e :config (default +bindings +smartparens))
(packages (magit) (forge))
(unpin "n/a")
(elpa "org" "htmlize")))

:completion helm :completion ivy question resolved

Most helpful comment

You can tack on arguments for rg after a -- in your search query. e.g.

search terms -- -uu

-u = don't respect .gitignore or .ignore files
-uu = same as -u _and_ show hidden files
-uuu = same as -uu _and_ search binary files

All 9 comments

I don't think --hidden should be enabled by default. When was the last time you wanted to find something in the .git directory? It might slow searching down significantly in some cases.
You can send arguments to ripgrep with -- ARGUMENTS appended to your search, so e.g hello -- --hidden would search "hello" in hidden files too.

You can tack on arguments for rg after a -- in your search query. e.g.

search terms -- -uu

-u = don't respect .gitignore or .ignore files
-uu = same as -u _and_ show hidden files
-uuu = same as -uu _and_ search binary files

Agreed about no wanting to search .git but it's very common to have configuration files on the root level of the project like .travis.yaml or .gitlab-ci.yaml which are not searched by default.

Having -- is very helpful, I still argue that searching hidden by default is the right thing to do here while excluding .git with -g !.git

Which would be the best way to make it so in my personal config?

Agreed about no wanting to search .git but it's very common to have configuration files on the root level of the project like .travis.yaml or .gitlab-ci.yaml which are not searched by default.

That makes sense. I'm tempted to add --hidden to counsel-rg-base-command's default value, but I think this should be suggested to swiper, upstream. What do you think?

Though, I don't think rg searches .git directories, with or without --hidden.

Which would be the best way to make it so in my personal config?

Add this to ~/.doom.d/config.el:

(after! counsel
  (setq counsel-rg-base-command
        "rg -M 240 --hidden --with-filename --no-heading --line-number --color never %s"))

With --hidden it does search .git

See also https://github.com/BurntSushi/ripgrep/issues/340

but I think this should be suggested to swiper, upstream. What do you think?

Happy to file an issue upstream but I'm unsure if that should be part of the broader swiper package or only enabled when in a project (thus projectile?) (Or I could be messing things up b/c it's vague where one package ends and where the other begins.)

Another similar case: sometimes I want to find file (or its content) that's ignored in .gitignore (some local config file, for example). So, it's difficult to make a single universal command that works in all scenarios.

Unfortunately, AFAIK, ivy doesn't provide any interface for "toggles". It'd be great to have some ivy+transient-like interface. It's probably doable with hydra, but it's not as nice as it could be.

Hi,

If it helps, I have done this on a given key binding to always add specific params, this way I m sur I do not miss any update on counsel-rg-base-command

  (let ((counsel-rg-base-command (concat counsel-rg-base-command " -w --case-sensitive")))
    (+default/search-project-for-symbol-at-point symbol arg))

Just got bit by this one. For large projects I don't think "--hidden" is a good default. Can we make it more readily customizable?

Was this page helpful?
0 / 5 - 0 ratings