Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add counsel-bookmarked-directory #1657

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions counsel.el
Original file line number Diff line number Diff line change
Expand Up @@ -2063,6 +2063,57 @@ By default `counsel-bookmark' opens a dired buffer for directories."
("r" ,(counsel--apply-bookmark-fn #'counsel-find-file-as-root)
"open as root")))

;;** `counsel-bookmarked-directory'
(defun counsel-bookmarked-directory--candidates ()
"Get a list of bookmarked directories sorted by file path."
(bookmark-maybe-load-default-file)
(sort (cl-remove-if-not
#'ivy--dirname-p
(delq nil (mapcar #'bookmark-get-filename bookmark-alist)))
#'string<))

;;;###autoload
(defun counsel-bookmarked-directory-add (dir)
"Create a directory bookmark to DIR interactively.

This function prompts for the bookmark name, which defaults to the
abbreviate path of the directory.

When called-interactively, DIR defaults to the current value of
`default-directory'."
(interactive (list default-directory))
(setq dir (abbreviate-file-name (expand-file-name dir)))
(let ((name (read-string (format "Name of the new directory bookmark [%s]: " dir)
nil nil dir))
(record `((filename . ,(file-name-as-directory dir))
(front-context-string)
(rear-context-string))))
(bookmark-maybe-load-default-file)
(bookmark-store name record nil)))

;;;###autoload
(defun counsel-bookmarked-directory ()
"Ivy interface for bookmarked directories.

With a prefix argument, this command creates a new bookmark which points to the
current value of `default-directory'."
(interactive)
(if current-prefix-arg
(call-interactively #'counsel-bookmarked-directory-add)
(ivy-read "Bookmarked directory: "
(counsel-bookmarked-directory--candidates)
:caller 'counsel-bookmarked-directory
:action #'dired)))

(ivy-set-actions 'counsel-bookmarked-directory
'(("j" dired-other-window "other window")
("x" counsel-find-file-extern "open externally")
("r" counsel-find-file-as-root "open as root")
("f" (lambda (dir)
(let ((default-directory dir))
(call-interactively #'find-file)))
"find-file")))

;;** `counsel-file-register'
;;;###autoload
(defun counsel-file-register ()
Expand Down