Skip to content

Instantly share code, notes, and snippets.

@CeleritasCelery
Last active August 31, 2018 15:10
Show Gist options
  • Save CeleritasCelery/d39f233dd272ed418eb1dff7cac78b1d to your computer and use it in GitHub Desktop.
Save CeleritasCelery/d39f233dd272ed418eb1dff7cac78b1d to your computer and use it in GitHub Desktop.
(defun $magit-status-in-dir (dir)
"limit magit status to directory"
(interactive "D")
(require 'magit)
(let* ((root (vc-git-root dir))
(dir (list (file-relative-name dir root)))
(magit-status-mode-hook (cons (lambda () (setq-local magit-diff-section-file-args dir))
magit-status-mode-hook)))
(magit-status-internal root)))
(defun $magit-status-current-dir ()
"run magit in current dir"
(interactive)
($magit-status-in-dir default-directory))
(defun $magit-clear-diff-args-if-not-dir-local ()
(unless (assq 'magit-diff-section-file-args dir-local-variables-alist)
(setq-local magit-diff-section-file-args nil)))
(advice-add 'magit-status :around
(defun $magit-remove-diff-args (fn &rest args)
(let ((magit-status-mode-hook (cons '$magit-clear-diff-args-if-not-dir-local
magit-status-mode-hook)))
(apply fn args))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment