From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 25962 invoked from network); 15 Jun 2000 21:42:56 -0000 Received: from sunsite.auc.dk (130.225.51.30) by ns1.primenet.com.au with SMTP; 15 Jun 2000 21:42:56 -0000 Received: (qmail 103 invoked by alias); 15 Jun 2000 21:42:40 -0000 Mailing-List: contact zsh-users-help@sunsite.auc.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 3169 Received: (qmail 95 invoked from network); 15 Jun 2000 21:42:39 -0000 Date: Thu, 15 Jun 2000 14:42:30 -0700 (PDT) From: Bart Schaefer Sender: schaefer@aztec.zanshin.com Reply-To: Bart Schaefer To: Shao Zhang cc: ZSH Mail List Subject: Re: [OT] export http_proxy In-Reply-To: <20000616023433.A7142@localhost> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII On Fri, 16 Jun 2000, Shao Zhang wrote: > I have a couple of isps on my linux box, and some of them need a > proxy setting. So nearly everytime I dial up, I have to export the > http_proxy in order to use it. Now is there an easy/smart way to do > this rather than doing it manually? Use the `preexec' user-defined function. You need to devise a test that zsh can use to determine to which ISP you're presently connected; perhaps something like function preexec() { case ${${(M)$(ifconfig ppp0):#addr:*}#addr:} in 192.168.68.1) export HTTP_PROXY=192.168.68.215;; 192.168.86.9) typeset +x HTTP_PROXY; unset HTTP_PROXY;; and-so-on) export HTTP_PROXY=and-so-forth;; esac } However, it might be a bit expensive to run ifconfig before each and every command, so you might instead try putting it in the `periodic' function (so it gets updated every $PERIOD seconds, which you also need to set). Or you could put it in a trap handler for e.g the USR2 signal and have a script that runs when PPP comes up that does a "killall -USR2 zsh" to cause all shells to update their environment. To explain those hierographics (PWS's word) a bit: $(ifconfig ppp0) Run ifconfig and return its output as an array of words :#addr:* Select the word matching addr:* (M) Keep only the selected (`M'atching) word, rather than deleting it #addr: Remove leading addr: from that word leaving just the IP address Simple, no?