Git Product home page Git Product logo

Comments (16)

wpcarro avatar wpcarro commented on August 21, 2024 2

This is an excellent tool, but I'm surprised it's this difficult to search through hidden files. Am I wrong in thinking this should be easier to configure? Was imagining something like:

(setq deadgrep-search-hidden t)

from deadgrep.

kaushalmodi avatar kaushalmodi commented on August 21, 2024 1

May be "%s --color=ansi --line-number --no-heading --follow --with-filename %s %s %s %s -- %s ." in deadgrep--format-command be made a defcustom?

from deadgrep.

gizmomogwai avatar gizmomogwai commented on August 21, 2024 1

Putting those settings into variables also opens up the door for https://www.gnu.org/software/emacs/manual/html_node/emacs/Directory-Variables.html
so that you could configure the defaults on a per project basis.

from deadgrep.

kaushalmodi avatar kaushalmodi commented on August 21, 2024

Came here looking for this.

My VCS is centralized. So all files are symlinks to cached files in server.

I always need to add --follow option to the rg/ag/etc commands.

I also use the --ignore-file option in rg.

from deadgrep.

kaushalmodi avatar kaushalmodi commented on August 21, 2024

I ended up with this for now:

(defconst modi/deadgrep--rg-args
  `("--color=ansi"
    "--line-number"
    "--no-heading"
    "--with-filename"
    "--no-ignore-vcs"       ;Ignore files/dirs ONLY from `.ignore'
    "--follow"              ;Follow symlinks
    "%s"                    ;--fixed-strings and/or --word-regexp
    "%s"          ;--smart-case / --case-sensitive / --ignore-case
    "%s"          ;file type
    "%s"          ;context
    "--ignore-file" ,(expand-file-name ".ignore" (getenv "HOME")))
  "rg arguments used in the `deadgrep' package.")

;; Thu Aug 23 15:51:37 EDT 2018 - kmodi
;; Overriding the original `deadgrep--format-command' as I need to
;; add few extra `rg' options.
;; https://github.com/Wilfred/deadgrep/issues/24
(defun modi/deadgrep--format-command (search-term search-type case context)
  "Return a command string that we can execute in a shell
to obtain ripgrep results."
  (format
   (mapconcat #'identity
              (append '("%s")       ;`deadgrep-executable'
                      modi/deadgrep--rg-args
                      '("-- %s .")) ;search term
              " ")
   deadgrep-executable
   (cond
    ((eq search-type 'string)
     "--fixed-strings")
    ((eq search-type 'words)
     "--fixed-strings --word-regexp")
    ((eq search-type 'regexp)
     "")
    (t
     (error "Unknown search type: %s" search-type)))
   (cond
    ((eq case 'smart)
     "--smart-case")
    ((eq case 'sensitive)
     "--case-sensitive")
    ((eq case 'ignore)
     "--ignore-case")
    (t
     (error "Unknown case: %s" case)))
   ;; TODO: pass this as an argument.
   (cond
    ((eq deadgrep--file-type 'all)
     "")
    ((eq (car-safe deadgrep--file-type) 'type)
     (format "--type %s" (cdr deadgrep--file-type)))
    ((eq (car-safe deadgrep--file-type) 'glob)
     (format "--type-add 'custom:%s' --type custom"
             (cdr deadgrep--file-type)))
    (t
     (error "Unknown file-type: %S" deadgrep--file-type)))
   (if context
       (format "--before-context %s --after-context %s"
               (car context) (cdr context))
     "")
   (shell-quote-argument search-term)))
(advice-add 'deadgrep--format-command :override #'modi/deadgrep--format-command)

from deadgrep.

kaushalmodi avatar kaushalmodi commented on August 21, 2024

An even better way (for now):

(defconst modi/deadgrep--rg-extra-args
  `("--no-ignore-vcs"       ;Ignore files/dirs ONLY from `.ignore'
    "--follow"              ;Follow symlinks
    "--ignore-file" ,(expand-file-name ".ignore" (getenv "HOME")))
  "Extra rg arguments to be added to `deadgrep--format-command' output.")

;; Thu Aug 23 15:51:37 EDT 2018 - kmodi
;; Adding extra arguments to the ones
;; already in `deadgrep--format-command' --
;; https://github.com/Wilfred/deadgrep/issues/24
(defun modi/deadgrep--format-command-advice (orig-ret-val)
  "Add arguments from `modi/deadgrep--rg-extra-args' to ORIG-RET-VAL."
  (replace-regexp-in-string
   (format "\\`\\(%s \\)\\(.*\\)\\'" (regexp-quote deadgrep-executable))
   (concat "\\1"
           (mapconcat #'identity modi/deadgrep--rg-extra-args " ")
           " \\2")
   orig-ret-val))
(advice-add 'deadgrep--format-command :filter-return #'modi/deadgrep--format-command-advice)

Ref

from deadgrep.

Wilfred avatar Wilfred commented on August 21, 2024

OK, I think the best solution here is:

  • Provide a variable to allow users to provide additional arguments to ripgrep
  • Rename 'all' to 'any' in the UI, to avoid confusion (ripgrep still honours .gitignore)

I'm not sure whether the other ripgrep options make sense as being exposed in the UI. I do use --hidden or --unrestricted occasionally from the CLI, but not very often. It's a little complex because --glob overrides --no-hidden, and we already expose globbing.

I might proceed with the above, and if there's any interest in more options within the UI, we can follow up in another issue :)

from deadgrep.

sebasmonia avatar sebasmonia commented on August 21, 2024

Was looking for a way to add --hidden as a repository I'm working with has a .somethingsomething directory, and since this is under Windows, the authors didn't meant . as "hidden".

I think the defadvice above can get me what I need but it would be nice to have a defcustom or option in the UI for this.

from deadgrep.

sebasmonia avatar sebasmonia commented on August 21, 2024

@wpcarro for your reference this is the advice I ended up using:

(defun deadgrep--format-command-patch (rg-command)
  "Add --hidden to rg-command."
  (replace-regexp-in-string "^rg " "rg --hidden " rg-command))
(advice-add 'deadgrep--format-command :filter-return #'deadgrep--format-command-patch))

I have that in the config section of the use-package declaration.

from deadgrep.

wpcarro avatar wpcarro commented on August 21, 2024

@sebasmonia thanks for sharing. I'll need to use this for now. I'm still quite surprised that using advice is the recommended approach for something like toggling --hidden for a library this popular.

from deadgrep.

iquiw avatar iquiw commented on August 21, 2024

I think transient would fit for the purpose (providing user customizable command line arguments), and many are familiar with it through Magit. (I am not sure whether it meets the original request though)

@Wilfred What do you think about adding transient interface to deadgrep?

from deadgrep.

sebasmonia avatar sebasmonia commented on August 21, 2024

An idea, the C-u call could invoke the transient menu to tune parameters.
(Currently it opens the deadgrep buffer but doesn't run rg)

from deadgrep.

iquiw avatar iquiw commented on August 21, 2024

@sebasmonia Thanks for the comment.
I'm playing deadgrep+transient. For now, I'm considering to provide separate command with keeping the current interface as is.

from deadgrep.

beetleb avatar beetleb commented on August 21, 2024

I too am surprised by the lack of ability to specify options. I needed --ignore-file.

from deadgrep.

wandersoncferreira avatar wandersoncferreira commented on August 21, 2024

Since latest changes in the package, the workaround should be

(defun deadgrep--include-args (rg-args)
  (push "--hidden" rg-args) ;; consider hidden folders/files
  (push "--follow" rg-args) ;; follow symlink
  )

(advice-add 'deadgrep--arguments :filter-return #'deadgrep--include-args)

from deadgrep.

herbertjones avatar herbertjones commented on August 21, 2024

FYI you can override the .gitignore file using .rgignore for the purpose of allowing files to be searched by rg.

https://github.com/BurntSushi/ripgrep/blob/master/GUIDE.md#automatic-filtering

from deadgrep.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.