Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: sharing environment between terminals.



On 18/11/12 10:35 AM, Bart Schaefer wrote:
On Nov 17,  4:39pm, Ray Andrews wrote:
}
} Is there a way to instantly share environment variables between running
} terminals?

Generally speaking, no.  The environment of each process is private to
that process, allocated by the operating system at the time the process
is forked.

If desperate enough, you could set up something using the zsh/tcp module
to have your shells cooperatively swap new environment strings around.
One shell (or an external daeamon of some kind -- condsider the model
used by ssh-agent) would have to control the "master" environment, and
hand out changes to the other shells on request.  The other shells would
check at opportune times (during precmd for example) whether changes are
available, and apply them.

Most of that sounds way above my head for the moment. But I did get it working quite well using, as you suggest, precmd(). Basically, I have a command that sets whatever env. variable and also writes a script that can set that variable. precmd() sources that script, which adds the variable to the local env of any xterm.

I use this to create shortcuts to the current directory on each xterm. '$t0' being automatically set to the current dir on 'pts/0', etc. I can then change to a different terminal and do stuff like:

cp ./* $t0
cd $t5
mv $t2/* $t3
etc.

... which saves a lot of typing.

Still, I would have thought that there would be an easy way to share stuff between xterms. I think of my xterms as different windows into the same house--I want them to share everything--history, environment, everything.




Messages sorted by: Reverse Date, Date, Thread, Author