Skip to content

Instantly share code, notes, and snippets.

@runswithd6s
Created April 5, 2018 14:06
Show Gist options
  • Save runswithd6s/35b265cb0a7ae717732eae05c5d80e48 to your computer and use it in GitHub Desktop.
Save runswithd6s/35b265cb0a7ae717732eae05c5d80e48 to your computer and use it in GitHub Desktop.
SSH Authentication Sock for Emacs
;; -*- mode: lisp-interactive -*-
;;;; Set the SSH authentication sock file for processes in Emacs to find for
;;;; TRAMP and git operations...
;; What we want to happen
(setenv "SSH_AUTH_SOCK" "/run/user/1000/keyring/ssh")
;; Getting my user id
(user-real-uid)
;; Represent as a string
(number-to-string (user-real-uid))
;; Ways to build a string
(concat "/run/user/" (number-to-string(user-real-uid)) "/keyring/ssh")
(format "/run/user/%i/keyring/ssh" (user-real-uid))
;; put it in a variable
(setq ssh_auth_sock (format "/run/user/%i/keyring/ssh" (user-real-uid)))
;; Conditional to see if the file exists and execute what we want
(if (file-exists-p ssh_auth_sock)
(setenv "SSH_AUTH_SOCK" ssh_auth_sock))
;; That's probably good enough for now. Later, functions, lists of possible
;; directories to look for, and process checking.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment