Skip to content

Commit

Permalink
Merge pull request #116 from psibi/ssh-resolve
Browse files Browse the repository at this point in the history
Ability to resolve using OpenSSH client configuration file
  • Loading branch information
sshaw committed Mar 3, 2024
2 parents aded958 + df41160 commit 81b4eb8
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion git-link.el
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,11 @@ See its docs."
:type 'boolean
:group 'git-link)

(defcustom git-link-consider-ssh-config nil
"Consider ssh configuration file for resolving hostnames."
:type 'boolean
:group 'git-link)

(defcustom git-link-remote-alist
'(("git.sr.ht" git-link-sourcehut)
("codeberg.org" git-link-codeberg)
Expand Down Expand Up @@ -431,10 +436,16 @@ return (FILENAME . REVISION) otherwise nil."
(when (string-match ":" host)
(let ((parts (split-string host ":" t))
(case-fold-search t))
(string-match (concat (car parts) ":\\(" (cadr parts) "\\)/") url)
(string-match (concat (regexp-quote (car parts)) ":\\(" (cadr parts) "\\)/") url)
(setq host (car parts)
path (concat (match-string 1 url) "/" path))))


(when git-link-consider-ssh-config
(let* ((ssh-resolved-host (git-link--ssh-resolve-hostname host)))
(when ssh-resolved-host
(setq host ssh-resolved-host))))

;; Fix-up Azure SSH URLs
(when (string= "ssh.dev.azure.com" host)
(setq host "dev.azure.com")
Expand Down Expand Up @@ -471,6 +482,15 @@ return (FILENAME . REVISION) otherwise nil."

(list host path))))

(defun git-link--ssh-resolve-hostname (hostname)
"Resolve HOSTNAME using ssh client."
(let ((output (shell-command-to-string (format "ssh -G %s" hostname)))
(host nil))
(dolist (line (split-string output "\n"))
(when (string-match "^hostname \\(.*\\)" line)
(setq host (match-string 1 line))))
host))

(defun git-link--using-git-timemachine ()
(and (boundp 'git-timemachine-revision)
git-timemachine-revision))
Expand Down

0 comments on commit 81b4eb8

Please sign in to comment.