[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Eval environment variables using Lisp code
From: |
Phillip Lord |
Subject: |
Re: Eval environment variables using Lisp code |
Date: |
Wed, 19 Apr 2006 12:10:07 +0100 |
User-agent: |
Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (windows-nt) |
>>>>> "IVT" == Ismael Valladolid Torres <ivalladolidt@terra.es> writes:
IVT> In my setup, I run ssh-agent making it create a script that can
IVT> be sourced from any shell giving it access to the agent:
IVT> $ ssh-agent -a /tmp/.ssh-socket >/tmp/.ssh-script $ cat
IVT> /tmp/.ssh-script SSH_AUTH_SOCK=/tmp/.ssh-socket; export
IVT> SSH_AUTH_SOCK; SSH_AGENT_PID=148; export SSH_AGENT_PID; echo
IVT> Agent pid 148;
IVT> To be able to use Tramp, I'd need emacs to eval that shell code
IVT> so environment variables are properly defined. Can this be done
IVT> via Lisp code in my .emacs?
IVT> This is NT Emacs and ssh is the Cygwin version. So running
IVT> ssh-agent via the window manager is not an option, and making
IVT> ssh not use the agent and ask for a password instead isn't,
IVT> either. If I eval that code on a Bash shell and run emacs from
IVT> it, it works, but I'd like it to work when using the Emacs
IVT> icon.
IVT> Thanks in advance for any idea.
I had the same problem; actually it happens with linux as well, when
launching from the desktop icon rather than elsewhere.
I use the following, rather horrible, approach. First, I use keychain
rather than ssh-agent directly. This drops a similar script into
.keychain/hostname-sh. I just parse this out with emacs, and use
setenv to set the environment variables. Not very neat, but it works.
You'll need to fiddle the lisp to get it to work without keychain, but
it should be straight forward.
(defun phil-parse-keychain()
"Parse keychain files, and set environment variables appropriately."
(interactive)
(with-temp-buffer
(insert-file
(concat "~/.keychain/" (downcase (system-name))
"-sh"))
(switch-to-buffer (current-buffer))
(phil-parse-keychain-split-line)
(forward-line)
(phil-parse-keychain-split-line)))
(defun phil-parse-keychain-split-line()
(let ((env
(split-string (buffer-substring-no-properties
(line-beginning-position) (line-end-position))
"[=;]")))
(setenv (nth 0 env) (nth 1 env))))
(phil-parse-keychain)
Cheers
Phil