Created
April 6, 2020 21:24
-
-
Save benozol/3ed34c712fc750b75dc4da73a51566b3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; Open the file in the current buffer in another git worktree | |
(defun my/magit-open-file-in-worktree () | |
(interactive) | |
(flet ((worktrees () | |
(mapcar | |
(lambda (x) (cons (nth 3 x) (nth 0 x))) | |
(magit-list-worktrees))) | |
(open-buffer (repo-path) | |
(let* ((file-path (file-relative-name buffer-file-name (magit-toplevel))) | |
(filename (concat (file-name-as-directory repo-path) file-path))) | |
(find-file filename)))) | |
(helm :sources '((name . "Git worktrees") | |
(candidates . worktrees) | |
(action . open-buffer))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment