add action for counsel-find-file

This commit is contained in:
fuxialexander 2018-07-04 23:59:18 +08:00
parent c9ffa063e7
commit a906b82788
2 changed files with 31 additions and 0 deletions

View file

@ -198,6 +198,22 @@ search current file. See `+ivy-task-tags' to customize what this searches for."
(selected-window)))))) (selected-window))))))
;;;###autoload
(defun +ivy/reloading (cmd)
(lambda (x)
(funcall cmd x)
(ivy--reset-state ivy-last)))
;;;###autoload
(defun +ivy/given-file (cmd prompt)
(lambda (source)
(let ((target
(let ((enable-recursive-minibuffers t))
(read-file-name
(format "%s %s to:" prompt source)))))
(funcall cmd source target 1))))
;; ;;
;; File searching ;; File searching
;; ;;

View file

@ -98,6 +98,21 @@ immediately runs it on the current candidate (ending the ivy session)."
;; Dim recentf entries that are not in the current project. ;; Dim recentf entries that are not in the current project.
(ivy-set-display-transformer #'counsel-recentf #'+ivy-recentf-transformer) (ivy-set-display-transformer #'counsel-recentf #'+ivy-recentf-transformer)
;; Configure `counsel-find-file'
(ivy-add-actions
'counsel-find-file
`(("c" ,(+ivy/given-file #'copy-file "Copy file") "copy file")
("d" ,(+ivy/reloading #'+ivy/confirm-delete-file) "delete")
("r" (lambda (path) (rename-file path (read-string "New name: "))) "Rename")
("m" ,(+ivy/reloading (+ivy/given-file #'rename-file "Move")) "move")
("f" find-file-other-window "other window")
("p" (lambda (path) (with-ivy-window (insert (file-relative-name path default-directory)))) "Insert relative path")
("P" (lambda (path) (with-ivy-window (insert path))) "Insert absolute path")
("l" (lambda (path) "Insert org-link with relative path"
(with-ivy-window (insert (format "[[./%s]]" (file-relative-name path default-directory))))) "Insert org-link (rel. path)")
("L" (lambda (path) "Insert org-link with absolute path"
(with-ivy-window (insert (format "[[%s]]" path)))) "Insert org-link (abs. path)")))
;; Configure `counsel-rg', `counsel-ag' & `counsel-pt' ;; Configure `counsel-rg', `counsel-ag' & `counsel-pt'
(dolist (cmd '(counsel-ag counsel-rg counsel-pt)) (dolist (cmd '(counsel-ag counsel-rg counsel-pt))
(ivy-add-actions (ivy-add-actions