On Tue, 23 Jun 2020 Victor Sudakov wrote:
davidson wrote:
[Victor Sudakov OP wrote:]
I'm trying to switch from screen to tmux
[snip]

I've thought about the same thing, but inertia is seductive, and I
have remained --so far-- unaware of specific reasons to bother
changing.

The first line below changes the command key from Ctrl-b to Ctrl-a,
to emulate Gnu screen.

  $ cat ~/.tmux.conf
  set-option -g prefix C-a

This is a nice feature, but not quite sufficient. You won't be able to
send a literal C-a to the terminal if you have just this one line.

Oof. Yeah, that's no good at all.

I have 3 lines doing the same job:

set-option -g prefix C-a
unbind-key C-b
bind-key C-a send-prefix

Thank you. That is much better.

I notice that this will make

  Ctrl-a Ctrl-a

the key sequence for passing Ctrl-a to the application running in a
window pane.

In my Gnu screen setup, the corresponding key sequence (unchanged from
package defaults in this respect, afaict) is

  Ctrl-a a

And so to emulate that I would probably replace this line

  bind-key C-a send-prefix

with this one instead

  bind-key a send-prefix

so that old muscle-memory would remain useful.

I started my first session with this command:

  $ tmux attach

It is quite counter-intuitive to start a *first* session with "tmux
attach",

I agree, but I'm not sure how much my intuition, or my expectations of
what constitutes "normal behavior" for a terminal multiplexer, has
been shaped/warped by habituation to Gnu screen idioms.

It looks like tmux works a little differently. In particular, it uses
its config files a little differently than Gnu screen uses ~/.screenrc

Try the following, with the ~/.tmux.conf that specifies
MyFirstTmuxSession:

 $ tmux kill-server # make sure your user has no tmux sessions

 $ tmux list-sessions # verify that this is so
 no server running on /tmp/tmux-1000/default

 $ tmux start-server # start the server that manages your sessions

 $ tmux list-sessions # see what sessions you have now
 MyFirstTmuxSession: 4 windows (created Tue Jun 23 17:18:33 2020) [80x24]

And now, of course, if you cared to, you could attach that session to
some terminal.

This made more sense to me when I read more carefully in tmux(1)
(somewhat weirdly, under section DESCRIPTION instead of OPTIONS) about
the '-f' command line option that lets you explicitly specify a
configuration file.

Surprisingly, it's full of information about how (and when) the
configuration file actually gets used:

  -f file

     Specify an alternative configuration file.  By default, tmux
     loads the system configuration file from /etc/tmux.conf, if
     present, then looks for a user configuration file at
     ~/.tmux.conf.

     The configuration file is a set of tmux commands which are
     executed in sequence when the server is first started.  tmux
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
     loads configuration files once when the server process has
     started.  The source-file command may be used to load a file
     later.

     tmux shows any error messages from commands in configuration
     files in the first session created, and continues to process the
     rest of the configuration file.

Sometimes you don't actually want your customary mancave full of
windows running applications like text editor, or tail --follow -ing
logs, or dedicated shell window for backgrounding fifty man pages or
whatever.

Sometimes you just want your terminal multiplexer to start up a plain
old one-window session --a brand new one-- and attach it to your
terminal.

And that is exactly what happens when you invoke tmux with no
arguments, like this:

 $ tmux

But first, before it can give you your plain-old one-window session,
(if the your user's tmux server isn't already started) it has to start
the server up, so that the session can be managed. And it is at *that*
point, server start-up time, that your ~/.tmux.conf file gets read.

If you've specified a mancave session in there, a mancave session will
be started for you. Whatever is in ~/.tmux.conf is just part of
setting up the server.

And then tmux can go about doing the specific task that the user who
issued plain old

 $ tmux

asked it to do: create a plain-old one-window session and attach it to
your terminal.

but your setup works, and thank you very much for that.

You are as surprised as I was/am.

I would have never been able to think of such a variant.

Me neither! It was just hiding under /usr/share/doc/tmux,
treacherously, in obfuscated form!

And when I detach it, I can resume it again with the same command.

I based the config file above off the following example config, after
some hunting around in the man page.

  $ tail -n12 /usr/share/doc/tmux/example_tmux.conf
  # Create a single default session, because a session is created here, tmux
  # should be started with "tmux attach" rather than "tmux new"

Well I never!

I tried the new-window command in .tmux.conf, but it always created
windows somewhere below the event horizon.

I think it's kind of like this:

 1. No sessions without a server.
 2. No windows without a session.

Thank you again!

Mutually. Been wondering about tmux for a while. But inertia...so
lazy.

--
Firstly, you must always implicitly obey orders, without attempting to
form any opinion of your own respecting their propriety. Secondly, you
must consider every man your enemy who speaks ill of your king; and
thirdly, you must hate a Frenchman, as you do the devil. --H. Nelson

Reply via email to