On 13/08/13 11:56, Aaron Schrab wrote:
> Commands running in tmux windows have the values for the variables that
> were set when the command was started, but those values can change such
> as when a new tmux client attaches.
>
> My main use case for this is that I run mutt inside of tmux to read my
> mail.  I'll often leave a single instance of mutt running for weeks at a
> time, while connecting to that via ssh from different client computers.
> When a new client connects I need to use different values for variables
> like DISPLAY, XAUTHORITY, and various SSH_* variables in order for some
> programs started from mutt to be able to work properly.  To help with
> this I have a `twrap` script which I prefix to all commands run from
> mutt (like setting the $editor option to `twrap vim`).  That script
> checks if it's being run from within tmux and if so sources the output
> from `tmux showenv -s`, after that it runs the command specified by the
> remaining arguments.

I use this code in zsh to do the same thing without having to patch
tmux. The preexec variable is an array of functions that get called
before each interactive command execution. I don't think such a variable
exists in bash, but you could hack something together with
prompt_command. This way I don't have to ever think about updating the
environment.

   # update session environment variables if they got changed after 
re-attaching
   # a tmux session
   if [[ -n "$TMUX" ]]; then
       _update_from_tmux() {
           VARS="$(tmux show-environment)"
           for VAR in ${(f)VARS}; do
               # only export non-removed variables
               if [[ "${VAR#-}" == "${VAR}" ]]; then
                   export "$VAR"
               fi
           done
       }
       add-zsh-hook preexec _update_from_tmux
   fi


Jan


------------------------------------------------------------------------------
Get 100% visibility into Java/.NET code with AppDynamics Lite!
It's a free troubleshooting tool designed for production.
Get down to code-level detail for bottlenecks, with <2% overhead. 
Download for free and get started troubleshooting in minutes. 
http://pubads.g.doubleclick.net/gampad/clk?id=48897031&iu=/4140/ostg.clktrk
_______________________________________________
tmux-users mailing list
tmux-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tmux-users

Reply via email to