zsh-users
 help / color / mirror / code / Atom feed
* [OT] export http_proxy
@ 2000-06-15 16:34 Shao Zhang
  2000-06-15 21:42 ` Bart Schaefer
  0 siblings, 1 reply; 5+ messages in thread
From: Shao Zhang @ 2000-06-15 16:34 UTC (permalink / raw)
  To: ZSH Mail List

Hi,
    Sorry for the Off Topic question, it is not really zsh related, but
    shell related.

    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?

Regards,


Shao.

-- 
____________________________________________________________________________
Shao Zhang - Running Debian 2.1  ___ _               _____
Department of Communications    / __| |_  __ _ ___  |_  / |_  __ _ _ _  __ _ 
University of New South Wales   \__ \ ' \/ _` / _ \  / /| ' \/ _` | ' \/ _` |
Sydney, Australia               |___/_||_\__,_\___/ /___|_||_\__,_|_||_\__, |
Email: shao@cia.com.au                                                  |___/ 
_____________________________________________________________________________


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [OT] export http_proxy
  2000-06-15 16:34 [OT] export http_proxy Shao Zhang
@ 2000-06-15 21:42 ` Bart Schaefer
  2000-06-21 15:51   ` Shao Zhang
  0 siblings, 1 reply; 5+ messages in thread
From: Bart Schaefer @ 2000-06-15 21:42 UTC (permalink / raw)
  To: Shao Zhang; +Cc: ZSH Mail List

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?


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [OT] export http_proxy
  2000-06-15 21:42 ` Bart Schaefer
@ 2000-06-21 15:51   ` Shao Zhang
  2000-06-21 16:12     ` Shao Zhang
  0 siblings, 1 reply; 5+ messages in thread
From: Shao Zhang @ 2000-06-21 15:51 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: ZSH Mail List

Bart Schaefer [schaefer@brasslantern.com] wrote:
> 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).

    Thanks. I don't know both preexec and periodic before, it is very
    usefull to know for my other stuff. But preexec is a bit expensive,
    and periodic does not really fit well since I only really need to
    update the proxy settings once.

> 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.

    Thanks again. This is my perfect solution. Putting an extra line
    killall -USR2 zsh in the ip-up script made it all happen.

    Also, I am just wondering, are all these features unique to zsh, or
    other shells have got them as well?

    Thanks.

Shao.

-- 
____________________________________________________________________________
Shao Zhang - Running Debian 2.1  ___ _               _____
Department of Communications    / __| |_  __ _ ___  |_  / |_  __ _ _ _  __ _ 
University of New South Wales   \__ \ ' \/ _` / _ \  / /| ' \/ _` | ' \/ _` |
Sydney, Australia               |___/_||_\__,_\___/ /___|_||_\__,_|_||_\__, |
Email: shao@cia.com.au                                                  |___/ 
_____________________________________________________________________________


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [OT] export http_proxy
  2000-06-21 15:51   ` Shao Zhang
@ 2000-06-21 16:12     ` Shao Zhang
  2000-06-21 16:39       ` Bart Schaefer
  0 siblings, 1 reply; 5+ messages in thread
From: Shao Zhang @ 2000-06-21 16:12 UTC (permalink / raw)
  To: ZSH Mail List; +Cc: Bart Schaefer

Hi,
    Sorry, I thought I had a perfect solution, but I am still not quite
    there yet. My problem is, when I do a killall -USR2 zsh, all the
    existing zsh shells will be able to catch the signal and then export
    the http_proxy properly. 
    
    Now, this fails when I open up a new xterm, is there anyway to allow
    all the zsh process to share certain shell variables?

    THanks.

Shao.

Shao Zhang [shao@linux.cia.com.au] wrote:
> Bart Schaefer [schaefer@brasslantern.com] wrote:
> > 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).
> 
>     Thanks. I don't know both preexec and periodic before, it is very
>     usefull to know for my other stuff. But preexec is a bit expensive,
>     and periodic does not really fit well since I only really need to
>     update the proxy settings once.
> 
> > 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.
> 
>     Thanks again. This is my perfect solution. Putting an extra line
>     killall -USR2 zsh in the ip-up script made it all happen.
> 
>     Also, I am just wondering, are all these features unique to zsh, or
>     other shells have got them as well?
> 
>     Thanks.
> 
> Shao.
> 
> -- 
> ____________________________________________________________________________
> Shao Zhang - Running Debian 2.1  ___ _               _____
> Department of Communications    / __| |_  __ _ ___  |_  / |_  __ _ _ _  __ _ 
> University of New South Wales   \__ \ ' \/ _` / _ \  / /| ' \/ _` | ' \/ _` |
> Sydney, Australia               |___/_||_\__,_\___/ /___|_||_\__,_|_||_\__, |
> Email: shao@cia.com.au                                                  |___/ 
> _____________________________________________________________________________

-- 
____________________________________________________________________________
Shao Zhang - Running Debian 2.1  ___ _               _____
Department of Communications    / __| |_  __ _ ___  |_  / |_  __ _ _ _  __ _ 
University of New South Wales   \__ \ ' \/ _` / _ \  / /| ' \/ _` | ' \/ _` |
Sydney, Australia               |___/_||_\__,_\___/ /___|_||_\__,_|_||_\__, |
Email: shao@cia.com.au                                                  |___/ 
_____________________________________________________________________________


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [OT] export http_proxy
  2000-06-21 16:12     ` Shao Zhang
@ 2000-06-21 16:39       ` Bart Schaefer
  0 siblings, 0 replies; 5+ messages in thread
From: Bart Schaefer @ 2000-06-21 16:39 UTC (permalink / raw)
  To: Shao Zhang, ZSH Mail List

On Jun 22,  1:51am, Shao Zhang wrote:
} Subject: Re: [OT] export http_proxy
}
} Bart Schaefer [schaefer@brasslantern.com] wrote:
} > On Fri, 16 Jun 2000, Shao Zhang wrote:
} > 
} > 	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
} 
}     Thanks again. This is my perfect solution. Putting an extra line
}     killall -USR2 zsh in the ip-up script made it all happen.
} 
}     Also, I am just wondering, are all these features unique to zsh, or
}     other shells have got them as well?

All Bourne-shell-like shells have the "trap" command.  As far as I know,
zsh is the only one that uses magically-named TRAPxxx functions.

Csh-like shells generally handle only INT and TERM signals, and then only
in scripts, not interactively.

On Jun 22,  2:12am, Shao Zhang wrote:
}
}     Now, this fails when I open up a new xterm, is there anyway to allow
}     all the zsh process to share certain shell variables?

Why not simply execute the trap handler code (e.g. the "case" above) in
your .zshenv file, to set the variable properly as each shell starts?

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2000-06-21 16:40 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-06-15 16:34 [OT] export http_proxy Shao Zhang
2000-06-15 21:42 ` Bart Schaefer
2000-06-21 15:51   ` Shao Zhang
2000-06-21 16:12     ` Shao Zhang
2000-06-21 16:39       ` Bart Schaefer

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).