]> code.delx.au - dotemacs/blob - lisp/my-ivy.el
Moved emacs temp files to ~/.cache
[dotemacs] / lisp / my-ivy.el
1 ;;; -*- lexical-binding: t -*-
2
3 (require 'counsel)
4 (require 'ivy)
5 (require 'swiper)
6
7 (ivy-mode 1)
8 (counsel-mode 1)
9
10 (setq ivy-wrap t)
11 (setq ivy-extra-directories '("./"))
12 (setq ivy-count-format "%d/%d ")
13
14 (setq counsel-find-file-at-point t)
15 (setq counsel-find-file-ignore-regexp "\\(?:\\`[#.]\\)\\|\\(?:[#~]\\'\\)")
16
17 (setq counsel-grep-base-command "grep -E -n -i -e %s %s")
18 (setq counsel-rg-base-command "rg -S --no-heading --line-number --color never --hidden --ignore-file ~/.emacs.d/rg-ignore %s .")
19 (defvar counsel-rg-files-command "rg --files --hidden --ignore-file ~/.emacs.d/rg-ignore")
20
21 (defun counsel-rg-jump (&optional initial-input initial-directory)
22 "Jump to a file below the current directory.
23 List all files within the current directory or any of its subdirectories.
24 INITIAL-INPUT can be given as the initial minibuffer input.
25 INITIAL-DIRECTORY, if non-nil, is used as the root directory for search."
26 (interactive
27 (list nil
28 (when current-prefix-arg
29 (read-directory-name "From directory: "))))
30 (counsel-require-program "rg")
31 (let ((default-directory (or initial-directory
32 (locate-dominating-file default-directory ".git")
33 default-directory)))
34 (ivy-read "rg --files: "
35 (split-string
36 (shell-command-to-string counsel-rg-files-command)
37 "\n" t)
38 :matcher #'counsel--find-file-matcher
39 :initial-input initial-input
40 :action (lambda (x)
41 (with-ivy-window
42 (find-file (expand-file-name x ivy--directory))))
43 :preselect (counsel--preselect-file)
44 :require-match 'confirm-after-completion
45 :history 'file-name-history
46 :keymap counsel-find-file-map
47 :caller 'counsel-rg-jump)))