Last active
August 29, 2015 14:13
-
-
Save anonymous/c395c3c1d7a0cc3c8060 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
;; Get the keys under the given registry path via WINDOWS\System32\reg.exe. | |
;; Only keys with the REG_SZ type will be returned. | |
(defun reg-keys-with-strings (regpath) | |
"read a path in the Windows registry. This probably works for string | |
values only. If the path does not exist, it returns nil. " | |
(let* ((reg.exe (concat (getenv "windir") "\\system32\\reg.exe")) | |
(reg (shell-command-to-string (concat reg.exe " query " regpath))) | |
(lines (split-string reg "\n" t " +")) | |
(registry-matching-lines | |
(mapcar | |
(lambda (line) | |
(let ((parts (split-string line " +" t))) | |
(and (= (length parts) 3) (string= (nth 1 parts) "REG_SZ") (nth 0 parts)))) lines))) | |
(delq nil registry-matching-lines))) | |
;; Turn a putty registry key, which looks like "rsa2@22:hostname", into a list | |
;; of (nil hostname). If we could parse a username here, we could provide | |
;; it as the first element of the list for use in completion. | |
(defun format-putty-reg-key (key) | |
(list nil (nth 1 (split-string key ":")))) | |
;; Combine the above to produce hosts for TRAMP completion. | |
(defun ssh-putty-hosts () | |
(mapcar 'format-putty-reg-key (reg-keys-with-strings "HKCU\\Software\\SimonTatham\\PuTTY\\SshHostKeys"))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment