X-Git-Url: https://code.delx.au/dotemacs/blobdiff_plain/bed83966f185a6b1284851e93b27e79bb2c96f47..3e7a640e8fb03c4d88ae3d4bc1d8703bd573ff3b:/lisp/my-ivy.el diff --git a/lisp/my-ivy.el b/lisp/my-ivy.el index d58dcf1..c3e57a6 100644 --- a/lisp/my-ivy.el +++ b/lisp/my-ivy.el @@ -4,6 +4,9 @@ (require 'ivy) (require 'swiper) +(ivy-mode 1) +(counsel-mode 1) + (setq ivy-wrap t) (setq ivy-extra-directories '("./")) (setq ivy-count-format "%d/%d ") @@ -11,9 +14,34 @@ (setq counsel-find-file-at-point t) (setq counsel-find-file-ignore-regexp "\\(?:\\`[#.]\\)\\|\\(?:[#~]\\'\\)") -(setq counsel-git-cmd "git ls-files --full-name --cached --others --exclude-standard --") -(setq counsel-git-grep-cmd-default "git --no-pager grep --full-name -n --no-color --untracked -i -e \"%s\"") +(setq counsel-grep-base-command "grep -E -n -i -e %s %s") +(setq counsel-rg-base-command "rg -S --no-heading --line-number --color never --hidden --ignore-file ~/.emacs.d/rg-ignore %s .") +(defvar counsel-rg-files-command "rg --files --hidden --ignore-file ~/.emacs.d/rg-ignore") -(setq counsel-grep-base-command "grep -niE %s %s") - -(ivy-mode 1) +(defun counsel-rg-jump (&optional initial-input initial-directory) + "Jump to a file below the current directory. +List all files within the current directory or any of its subdirectories. +INITIAL-INPUT can be given as the initial minibuffer input. +INITIAL-DIRECTORY, if non-nil, is used as the root directory for search." + (interactive + (list nil + (when current-prefix-arg + (read-directory-name "From directory: ")))) + (counsel-require-program "rg") + (let ((default-directory (or initial-directory + (locate-dominating-file default-directory ".git") + default-directory))) + (ivy-read "rg --files: " + (split-string + (shell-command-to-string counsel-rg-files-command) + "\n" t) + :matcher #'counsel--find-file-matcher + :initial-input initial-input + :action (lambda (x) + (with-ivy-window + (find-file (expand-file-name x ivy--directory)))) + :preselect (counsel--preselect-file) + :require-match 'confirm-after-completion + :history 'file-name-history + :keymap counsel-find-file-map + :caller 'counsel-rg-jump)))