diff options
| author | Craig Jennings <c@cjennings.net> | 2025-11-11 17:41:12 -0600 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2025-11-11 17:41:12 -0600 |
| commit | 72537381b5d98c6295c999bdec3c39ec0a7e3d42 (patch) | |
| tree | 96326182d092c7fd52184771dfb220d2c9256502 | |
| parent | b7d755d69421fcdc59bd6002a7a1c2ed77e548cd (diff) | |
vc-config: add git clone from clipboard URL feature
Introduce `cj/git-clone-clipboard-url` function for quick cloning of
git repositories using a URL from the clipboard. Allows for
directory selection using prefix arguments and opens the README file
post-cloning if available. Adjust keymaps to include the new
function and refine version control menu organization.
| -rw-r--r-- | modules/vc-config.el | 67 |
1 files changed, 63 insertions, 4 deletions
diff --git a/modules/vc-config.el b/modules/vc-config.el index 141f6e17..7865d0f4 100644 --- a/modules/vc-config.el +++ b/modules/vc-config.el @@ -35,6 +35,13 @@ (setq magit-clone-set-remote.pushDefault 'ask) ;; ask if origin is default ) ;; end use-package magit +;; Git Clone from Clipboard +(defvar cj/git-clone-dirs + (list code-dir ;; Already configured in your init + "~/projects/" + user-emacs-directory) ;; For cloning Emacs packages + "List of directories to choose from when cloning with prefix argument.") + ;; --------------------------------- Git Gutter -------------------------------- ;; mark changed lines since last commit in the margin @@ -123,6 +130,49 @@ interactive selection to jump to any changed line in the buffer." (require 'git-gutter) (consult-line "^[+\\-]")) +;; ------------------------------ Git Clone Clipboard ----------------------------- +;; Quick git clone from clipboard URL +;; Based on: https://xenodium.com/bending-emacs-episode-3-git-clone-the-lazy-way + +(defun cj/git-clone-clipboard-url (url target-dir) + "Clone git repository from clipboard URL to TARGET-DIR. + +With no prefix argument: uses first directory in `cj/git-clone-dirs'. +With \\[universal-argument]: choose from `cj/git-clone-dirs'. +With \\[universal-argument] \\[universal-argument]: choose any directory. + +After cloning, opens the repository's README file if found." + (interactive + (list (current-kill 0) ;; Get URL from clipboard + (cond + ;; C-u C-u: Choose any directory + ((equal current-prefix-arg '(16)) + (read-directory-name "Clone to: " code-dir)) + ;; C-u: Choose from configured list + (current-prefix-arg + (completing-read "Clone to: " cj/git-clone-dirs nil t)) + ;; No prefix: Use default (first in list) + (t (car cj/git-clone-dirs))))) + + (let* ((default-directory target-dir) + (repo-name (file-name-sans-extension + (file-name-nondirectory url))) + (clone-dir (expand-file-name repo-name target-dir))) + + ;; Clone the repository + (message "Cloning %s to %s..." url target-dir) + (shell-command (format "git clone %s" (shell-quote-argument url))) + + ;; Find and open README + (when (file-directory-p clone-dir) + (let ((readme (seq-find + (lambda (file) + (string-match-p "^README" (upcase file))) + (directory-files clone-dir)))) + (if readme + (find-file (expand-file-name readme clone-dir)) + (dired clone-dir)))))) + ;; -------------------------------- Difftastic --------------------------------- ;; Structural diffs for better git change visualization ;; Requires: difft binary (installed via pacman -S difftastic) @@ -144,23 +194,32 @@ interactive selection to jump to any changed line in the buffer." ;; Ordering & sorting prefix and keymap (defvar-keymap cj/vc-map :doc "Keymap for version control operations" + "c" #'cj/git-clone-clipboard-url "d" #'cj/goto-git-gutter-diff-hunks - "c" #'cj/forge-create-issue "f" #'forge-pull - "i" #'forge-list-issues "n" #'git-gutter:next-hunk "p" #'git-gutter:previous-hunk "r" #'forge-list-pullreqs "t" #'cj/git-timemachine) +;; Issues submenu under C-; v i +(defvar-keymap cj/vc-issues-map + :doc "Keymap for forge issue operations" + "c" #'cj/forge-create-issue + "l" #'forge-list-issues) + +(keymap-set cj/vc-map "i" cj/vc-issues-map) + (keymap-set cj/custom-keymap "v" cj/vc-map) (with-eval-after-load 'which-key (which-key-add-key-based-replacements "C-; v" "version control menu" + "C-; v c" "clone from clipboard" "C-; v d" "goto diff hunks" - "C-; v c" "create issue" "C-; v f" "forge pull" - "C-; v i" "list issues" + "C-; v i" "issues menu" + "C-; v i c" "create issue" + "C-; v i l" "list issues" "C-; v n" "next hunk" "C-; v p" "previous hunk" "C-; v r" "list pull requests" |
