Skip to content

Instantly share code, notes, and snippets.

@daichirata
Last active March 19, 2022 13:26
Show Gist options
  • Save daichirata/1c2939adc41c0351b91fa0ea98710788 to your computer and use it in GitHub Desktop.
Save daichirata/1c2939adc41c0351b91fa0ea98710788 to your computer and use it in GitHub Desktop.
(defun consult-git-status--git-status ()
(let ((status (with-output-to-string
(with-current-buffer standard-output
(process-file "git" nil t nil "status" "--porcelain")))))
(cl-remove-if #'string-blank-p (split-string status "\n"))))
(defun consult-git-status--file-path (line)
(let ((path (car (last (split-string line " ")))))
(concat (expand-file-name (project-root (project-current))) path)))
(defun consult-git-status--file-action (line)
(consult--buffer-action
(find-file-noselect (consult-git-status--file-path line))))
(defvar consult-git-status--source-git-status
`(:name "Git status"
:narrow (?g . "Git status")
:category file
:face consult-file
:history file-name-history
:action ,#'consult-git-status--file-action
:enabled ,#'project-current
:items ,#'consult-git-status--git-status))
(add-to-list 'consult-project-buffer-sources consult-git-status--source-git-status))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment