Hey Nicholas,

Thank you for the detailed write up. I've read it a couple times, and will
need to read it a couple times more to fully comprehend. I'm still a tmux
noob.

I'll posts any useful results to the list.

Thanks again for all the help!

-m

On Thu, Oct 3, 2019 at 6:08 AM Nicholas Marriott <
[email protected]> wrote:

> On Wed, Oct 02, 2019 at 03:25:33PM -0500, Matt Zagrabelny wrote:
> >    Thanks for the answers Nicholas!
> >    Perhaps I should just state what I currently do and see if there is a
> more
> >    optimal way of achieving what I think I want.
> >    Right now for all of my computers I have tmux spawn when a shell is
> >    exec'ed. It is very nice to always have tmux running whenever I am in
> a
> >    shell and to not have to type: "tmux".
> >    The problem is when I ssh to other systems I then have two tmuxes
> running
> >    and I'd rather just have the one running on the remote system - so
> when I
> >    split a pane, I am doing all of my tmux commands on the "most remote"
> >    system and not have "more local" tmuxes interfere with the escape
> keys and
> >    not have to remember how many times I need to hit the escape sequence
> to
> >    get it to reach the "most remote" system.
> >    For instance:
> >    laptop (tmux) $ ssh workstation
> >    laptop (tmux) workstation (tmux) $ ssh home_server
> >    laptop (tmux) workstation (tmux) home_server (tmux) $
> >    So that is three tmuxes I have running when really I just want:
> >    laptop workstation home_server (tmux) $
> >    Or I would like my escape key binding to (default to?) send 3 escape
> keys
> >    if I have three tmuxes running.
>
> You could do this but it would take some work.
>
> The easiest way is to have a key binding to swap your local tmux prefix
> to a different prefix and back, something like:
>
>     set -g prefix2 C-a
>     bind F1 if -F '#{==:#{prefix},C-b}' 'set -g prefix None' 'set -g
> prefix C-b'
>
> So normally you can use C-a or C-b for your local tmux, but when you
> know you have an inner tmux, you press C-b F1 to remove C-b from the
> local tmux so you can use it for the inner tmux. When you are done you
> use the second prefix and press C-a F1 to toggle it back.
>
> It is more difficult to do it automatically, because the local tmux
> doesn't know you are running tmux remotely, so it will need some way to
> work it out.
>
> If you are always running tmux every time you ssh somewhere you could
> just make the prefix key pass through if pane_current_command is ssh, so
> something like:
>
>     set -g prefix None
>     bind -n C-b if -F '#{==:#{pane_current_command},ssh}' 'send C-b'
> 'switchc -Tprefix'
>
> (It is probably worth also setting prefix2 to some other key so you have
> a way to control the inner tmux if it gets confused and C-b doesn't
> work.)
>
> If you are not always running tmux when you ssh, you need the inner tmux
> to tell the local tmux. The only possible ways to do this are using the
> pane title or window name.
>
> The pane title is probably better because it will work even if you have
> multiple panes in the local tmux, some with tmux and some without. You
> can make tmux set the title itself (with set-titles/set-titles-string)
> but since it can't clear it when it detachs you will need a shell
> wrapper to do that and it might as well set the title as well, something
> like this on the remote host:
>
>     xtmux {
>         printf "\033]2;TMUX\007'
>         tmux "$@"
>         printf "\033]2;\007"
>     }
>     alias tmux=xtmux
>
> Then in the local tmux:
>
>     set -g prefix None
>     bind -n C-b if -F '#{==:#{pane_title},TMUX}' 'send C-b' 'switchc
> -Tprefix'
>
> If you want to make the title more useful than "TMUX" you could use the
> m format modifier instead of == to make it detect whatever pattern means
> "tmux running".
>
> I didn't test any of this but it should give you the idea.
>
> >    Any ideas or suggestions regarding my scenarios?
> >    Thanks!
> >    -m
> >    On Wed, Oct 2, 2019 at 2:46 PM Nicholas Marriott
> >    <[email protected]> wrote:
> >
> >      Hi
> >
> >      tmux can't change the environment of other processes, including its
> >      parent.
> >
> >      You could possibly do it yourself with a script that detaches tmux,
> >      usese tmux showenv and pane_current_path to update the parent shell,
> >      then kills tmux.
> >
> >      Alternatively it would possible to add a feature where tmux replaced
> >      itself with a new shell with the updated environment but I don't see
> >      much use for this so there is little chance of it being implemented.
> >
> >      On Wed, Oct 02, 2019 at 10:09:23AM -0500, Matt Zagrabelny wrote:
> >      >A  A  Greetings,
> >      >A  A  Is there a way to leave tmux, but somehow seed the
> environment
> >      (history,
> >      >A  A  CWD, etc.) with everything that was part of the tmux
> environment?
> >      >A  A  Sort of like:
> >      >A  A  tmux
> >      >A  A  # do stuff
> >      >A  A  tmux --copy-environment-exec-shell
> >      >A  A  # now the shell is running without tmux
> >      >A  A  What do you folks think?
> >      >A  A  Thanks for any help!
> >      >A  A  -m
> >      >
> >      >A  A  --
> >      >A  A  You received this message because you are subscribed to the
> >      Google Groups
> >      >A  A  "tmux-users" group.
> >      >A  A  To unsubscribe from this group and stop receiving emails
> from it,
> >      send an
> >      >A  A  email to [email protected].
> >      >A  A  To view this discussion on the web, visit
> >      >A  A
> >
> https://groups.google.com/d/msgid/tmux-users/CAOLfK3V%2BVMY4br1fKfvXbjukAcdzV5pCAMjrHoq%2BuWkMqC%3D5nw%40mail.gmail.com
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"tmux-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web, visit 
https://groups.google.com/d/msgid/tmux-users/CAOLfK3X_RgWDsK6hrM3H5E2n-wET3%2BDBSgqAojZq%3DW0FwD0qVQ%40mail.gmail.com.

Reply via email to