1. ;; kudos to http://oremacs.com/2015/07/27/counsel-recoll/ author
  2. ;; I only change recoll command line
  3. (require 'counsel)
  4. (defun counsel-recoll-function (string &rest _unused)
  5. "Issue recallq for STRING."
  6. (if (< (length string) 3)
  7. (counsel-more-chars 3)
  8. (counsel--async-command
  9. (format "recoll -t -q '%s' | sed 's,\\[,,g;s,\\],,g' | awk '{ print $2 }' " string))
  10. nil))
  11. (defun counsel-recoll (&optional initial-input)
  12. "Search for a string in the recoll database.
  13. You'll be given a list of files that match.
  14. Selecting a file will launch `swiper' for that file.
  15. INITIAL-INPUT can be given as the initial minibuffer input."
  16. (interactive)
  17. (ivy-read "recoll: " 'counsel-recoll-function
  18. :initial-input initial-input
  19. :dynamic-collection t
  20. :history 'counsel-git-grep-history
  21. :action (lambda (x)
  22. (when (string-match "file://\\(.*\\)\\'" x)
  23. (let ((file-name (match-string 1 x)))
  24. (find-file file-name)
  25. (unless (string-match "pdf$" x)
  26. (swiper ivy-text)))))))
  27. (global-set-key (kbd "s-g") 'counsel-recoll)