Skip to content

Instantly share code, notes, and snippets.

@swflint
Created May 17, 2019 16:03
Show Gist options
  • Save swflint/300a830a79ade0b2f463179a6b107ae1 to your computer and use it in GitHub Desktop.
Save swflint/300a830a79ade0b2f463179a6b107ae1 to your computer and use it in GitHub Desktop.
Git Annex and Dired Integration
;; Note: Requires dired-hacks, specifically dired-open
(defun my/in-annex-repo-p ()
(= 0 (call-process "git" nil nil nil "annex" "status")))
(defun my/dired-try-git-annex-get (filename)
(if (not (my/in-annex-repo-p))
(signal 'error "File is a symlink to a nonexistent target")
(with-help-window "*git-annex-get status*"
(call-process "git" nil (get-buffer "*git-annex-get status*") t "annex" "get" filename)
(with-current-buffer (get-buffer "*git-annex-get status*")
(beginning-of-buffer)
(while (re-search-forward "\C-M" nil t)
(replace-match ""))))))
(defun my/dired-around-dired-find-file (original-function &rest args)
(condition-case err
(apply original-function args)
(error
(if (string= (cadr err) "File is a symlink to a nonexistent target")
(progn
(my/dired-try-git-annex-get (dired-get-filename nil t))
(call-interactively #'dired-open-file))
(signal (car err) (cdr err))))))
(advice-add 'dired-find-file :around #'my/dired-around-dired-find-file)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment