X-Spam-Check-By: sourceware.org
Message-ID: <44F4C2C4.6080807@lapo.it>
Date: Wed, 30 Aug 2006 00:42:12 +0200
From: Lapo Luchini <lapo@lapo.it>
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US; rv:1.8.0.5) Gecko/20060719 Thunderbird/1.5.0.5 Mnenhy/0.7.4.0
MIME-Version: 1.0
To: "[ML] CygWin " <cygwin@cygwin.com>
Subject: ssh-agent variables available to any user process
OpenPGP: id=C8F252FB
Content-Type: multipart/mixed;  boundary="------------040601010006070600050403"
Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe@cygwin.com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin@cygwin.com>
List-Help: <mailto:cygwin-help@cygwin.com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner@cygwin.com
Mail-Followup-To: cygwin@cygwin.com
Delivered-To: mailing list cygwin@cygwin.com

--------------040601010006070600050403
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit

Under FreeBSD, I launch ssh-agent in my .xsession script and its
environment is automatically inherited by every shell I then open in my
X11 session.
No such luck with Windows, but I found a way to propagate a environment
variable to any (future) user process after the user is already logged.
(or, at the very least...) Works for me.

Variables will be then available on any shell and program opened after
the attached script is executed.
(put it in "Startup" menu in order to execute it at logon time)

-- 
Lapo Luchini
lapo@lapo.it (OpenPGP & X.509)
www.lapo.it (Jabber, ICQ, MSN)

--------------040601010006070600050403
Content-Type: application/x-javascript;
 name="ssh-agent.js"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="ssh-agent.js"

var sh = new ActiveXObject("WScript.Shell");
// execute ssh-agent and store its output
var agent = sh.Exec("C:\\cygwin\\bin\\ssh-agent.exe -s");
var out = agent.StdOut.ReadAll();
// parse output
var re = /([^=]+)=([^;]+); export \1;/g;
while ((arr = re.exec(out)) != null) {
  // put the value in a volatile user variable
  sh.Environment("VOLATILE")(arr[1]) = arr[2];
}
// SETX a dummy variable for the side effect of broadcasting a WM_SETTINGCHANGE
sh.Run("setx XYZZYX 1", 0, true);
// remove the user variable set by SETX
sh.Environment("USER")("XYZZYX") = "2";  // let it know the value changed
sh.Environment("USER").Remove("XYZZYX"); // ...else this would fail


--------------040601010006070600050403
Content-Type: text/plain; charset=us-ascii

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/
--------------040601010006070600050403--
