Skip to content

Instantly share code, notes, and snippets.

@daviderestivo
Created January 23, 2021 07:41
Show Gist options
  • Save daviderestivo/48fb7434c08c45caa191b8b160c61b48 to your computer and use it in GitHub Desktop.
Save daviderestivo/48fb7434c08c45caa191b8b160c61b48 to your computer and use it in GitHub Desktop.
Helm search function
(defun helm-search-doc-ag ()
"Search for a keyword in the Documents folder using ag"
(interactive)
(helm-do-ag "~/Documents"))
(global-set-key (kbd "<f5>") 'helm-search-doc-ag)
@AtomicNess123
Copy link

This does not search in subdirectories of ~/Documents. Do you know how to make it recursive? Thanks!

@daviderestivo
Copy link
Author

@AtomicNess123 I’m currently on holidays. Once I’m back I’ll add a comment on how to make the previous function recursive.

@AtomicNess123
Copy link

Thanks, and happy holidays!

@daviderestivo
Copy link
Author

daviderestivo commented Jun 27, 2022

You should set the following variable to allow recursive search of text files only

   ;; Allow to recursively search git repositories inside other
   ;; repository (text files only, binary files are ignored)
   (setq helm-ag-command-option "--all-text")

@AtomicNess123
Copy link

Thanks! Two questions:

  1. This would set this option for all helm-ag instances and not just for that particular function?
  2. This would only make it recursive for text files and not other files (PDF, DOC, etc.; I was interested in the latter)?

@AtomicNess123
Copy link

Another problem is that

(setq helm-ag-command-option "--option")

Only allows for one option.

If you try:

(setq helm-ag-command-option "--all-text, -g")

It won't work

@daviderestivo
Copy link
Author

daviderestivo commented Jun 29, 2022

Did you try to use?

(setq helm-ag-command-option "--all-text -g")

@AtomicNess123
Copy link

Thanks, it works!
One question though: According to the man page:

[-t](https://www.mankier.com/1/ag#-t) [--all-text](https://www.mankier.com/1/ag#--all-text)
Search all text files. This doesn´t include hidden files.

[-u](https://www.mankier.com/1/ag#-u) [--unrestricted](https://www.mankier.com/1/ag#--unrestricted)
Search all files. This ignores .ignore, .gitignore, etc. It searches binary and hidden files as well.

I wanted to search ALL files, and you suggested --all-text. Wouldn't it be -u (would search all files, not just text)?

@daviderestivo
Copy link
Author

@AtomicNess123 my previous comment was meant to show you how to concatenate options for ag. I didn't look at what -g does. If you wanna search all files you can use:

       -a --all-types
              Search all files. This doesn´t include hidden files, and doesn´t
              respect any ignore files.

or

       -u --unrestricted
              Search all files. This ignores .ignore, .gitignore, etc. It
              searches binary and hidden files as well.

depending if you want to exclude (-a) hidden files or you wanna include them (-u). I hope is more clear now :).

@AtomicNess123
Copy link

Thanks, excellent. So both of these options will include .gitignore files, I understand. Is there an equal option to search all files, hidden included, but not .gitignore files?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment