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