History log of /openbsd-current/usr.bin/tmux/tmux.c
Revision (<<< Hide revision tags) (Show revision tags >>>) Date Author Comments
# 1.212 15-May-2024 nicm

Use default-shell for command prompt #() and popups as well


Revision tags: OPENBSD_7_4_BASE OPENBSD_7_5_BASE
# 1.211 17-Apr-2023 nicm

It seems silly to use progname for version, just always say tmux.


Revision tags: OPENBSD_7_3_BASE
# 1.210 10-Nov-2022 jmc

- sort options; from josiah frentsos
ok nicm

- add -N to SYNOPSIS

- sort usage()


Revision tags: OPENBSD_7_0_BASE OPENBSD_7_1_BASE OPENBSD_7_2_BASE
# 1.209 23-Aug-2021 nicm

Fix a few memory leaks.


# 1.208 06-Jul-2021 nicm

Improve error reporting when the tmux /tmp directory cannot be created
or used, GitHub issue 2765 from Uwe Kleine-Koenig.


# 1.207 10-Jun-2021 nicm

Do not expand the file given with -f so it can contain :s.


Revision tags: OPENBSD_6_9_BASE
# 1.206 22-Feb-2021 nicm

expand_paths needs the global environment to be set up, do that first.


# 1.205 22-Feb-2021 nicm

Move config file path expansion much earlier, keep the list of paths
around rather than freeing later, and add a config_files format variable
containing it. Suggested by kn@ a while back.


# 1.204 17-Jan-2021 nicm

Add -N flag to never start server even if command would normally do so,
GitHub issue 2523.


Revision tags: OPENBSD_6_8_BASE
# 1.203 22-Sep-2020 nicm

Fix warnings on some platforms with %llx and add a new message to handle
64-bit client flags.


# 1.202 02-Jun-2020 nicm

Use CLOCK_MONOTONIC for timer measurement and add a timestamp to control
mode %output blocks.


# 1.201 16-May-2020 nicm

Add a -D flag to ask tmux not to daemonize, useful both for running a
debugger (lldb does not have follow-fork-mode) and for running with a
managed supervisor init system. GitHub issue 2190.


# 1.200 16-May-2020 nicm

Add 'e' key in buffer mode to open the buffer in an editor.


# 1.199 16-May-2020 nicm

Build list of paths and weed out duplicates before loading configs, and
add TMUX_SOCK like TMUX_PATH for the socket directory.


Revision tags: OPENBSD_6_7_BASE
# 1.198 20-Apr-2020 nicm

Tidy up the terminal detection and feature code and add named sets of
terminal features, each of which are defined in one place and map to a
builtin set of terminfo(5) capabilities. Features can be specified based
on TERM with a new terminal-features option or with the -T flag when
running tmux. tmux will also detect a few common terminals from the DA
and DSR responses.

This is intended to make it easier to configure tmux's use of
terminfo(5) even in the presence of outdated ncurses(3) or terminfo(5)
databases or for features which do not yet have a terminfo(5) entry.
Instead of having to grok terminfo(5) capability names and what they
should be set to in the terminal-overrides option, the user can
hopefully just give tmux a feature name and let it do the right thing.

The terminal-overrides option remains both for backwards compatibility
and to allow tweaks of individual capabilities.

tmux already did much of this already, this makes it tidier and simpler
to configure.


# 1.197 16-Apr-2020 nicm

Show signal name when process exits rather than number.


# 1.196 09-Apr-2020 nicm

More style nits.


# 1.195 31-Mar-2020 nicm

Add a way to mark environment variables as "hidden" so they can be used
by tmux but are not passed into the environment of new panes.


# 1.194 17-Mar-2020 nicm

Ignore default-shell (and use /bin/sh) if it invalid not just if it is
tmux itself, also refuse to set the option to something invalid in the
first place. GitHub issue 2120.


# 1.193 12-Mar-2020 nicm

When the server socket is given by the user with -S, create it with
umask 177 instead of 117 because it may not be in a safe directory like
the default directory in /tmp. The user can chmod it more open after it
is created if they want.


# 1.192 28-Jan-2020 nicm

-V also needs to go in usage.


# 1.191 28-Jan-2020 nicm

Reduce a difference with portable tmux by adding the -V flag and
#{version} format; on OpenBSD these just report the OpenBSD version.


# 1.190 14-Oct-2019 nicm

Memory leaks, from Igor Wong in GitHub issue 1934.


Revision tags: OPENBSD_6_6_BASE
# 1.189 20-Jun-2019 nicm

Add a per-pane option set. Pane options inherit from window options (so
there should be no change to existing behaviour) and are set and shown
with set-option -p and show-options -p.

Change remain-on-exit and window-style/window-active-style to be pane
options (some others will be changed later).

This makes select-pane -P and -g unnecessary so no longer document them
(they still work) and no longer document set-window-option and
show-window-options in favour of set-option -w and show-options -w.


# 1.188 26-Apr-2019 nicm

Merge hooks into options and make each one an array option. This allows
multiple commands to be easily bound to one hook. set-hook and
show-hooks remain but they are now variants of set-option and
show-options. show-options now has a -H flag to show hooks (by default
they are not shown).


Revision tags: OPENBSD_6_5_BASE
# 1.187 22-Nov-2018 nicm

Do not use PWD unless it actually matches the real working directory.


Revision tags: OPENBSD_6_3_BASE OPENBSD_6_4_BASE
# 1.186 12-Jan-2018 nicm

Improve error message if creating socket parent directory fails, from
Thomas Adam for GitHub issue 1215.


# 1.185 01-Jan-2018 nicm

Prefer PWD for current directory if present in client, from Wei Zhao in
GitHub issue 1183.


Revision tags: OPENBSD_6_2_BASE
# 1.184 12-Jul-2017 nicm

Make shell_command a global like other stuff rather than making it an
exception and using callback argument.


# 1.183 03-Jul-2017 nicm

Try C.UTF-8 which is also a commonly useful locale on some platforms,
from Romain Francoise.


# 1.182 22-Apr-2017 nicm

Do not need getopt.h.


# 1.181 20-Apr-2017 nicm

Use fdforkpty() instead of our own unwrapped versions.


# 1.180 19-Apr-2017 nicm

Style nits and a missing cast.


# 1.179 16-Apr-2017 nicm

Memory leak, from David CARLIER.


Revision tags: OPENBSD_6_1_BASE
# 1.178 21-Mar-2017 nicm

Use uid_t for UID not u_int.


# 1.177 16-Feb-2017 nicm

Style nits.


# 1.176 23-Jan-2017 nicm

Open /dev/ptm before pledge() and save it to be used for PTMGET later
(this means inlining forkpty()).

ok deraadt


# 1.175 15-Jan-2017 nicm

Major tidy up and rework of options tree and set-option/show-options
commands this pushes more of the code into options.c and ties it more
closely to the options table rather than having an unnecessary
split. Also add support for array options (will be used later). Only
(intentional) user visible change is that show-options output is now
passed through vis(3) with VIS_DQ so quotes are escaped.


# 1.174 12-Jan-2017 nicm

Simplify appending to string options.


# 1.173 09-Dec-2016 nicm

Spacing nits.


# 1.172 11-Oct-2016 nicm

Add static in window-*.c and move some internal functions out of tmux.h.


# 1.171 10-Oct-2016 nicm

Loads more static, except for cmd-*.c and window-*.c.


Revision tags: OPENBSD_6_0_BASE
# 1.170 27-May-2016 nicm

Use getprogname() instead of __progname to make portability easier.


# 1.169 04-May-2016 nicm

Fix up a couple of long lines.


# 1.168 05-Mar-2016 nicm

If setlocale("en_US.UTF-8") succeeds, then don't do the check for UTF-8
locale since if it isn't UTF-8 the system is broken anyway. If it fails,
try "" and check for UTF-8 with nl_langinfo(CODESET) rather than
wcwidth(). Based on a diff from schwarze@, nl_langinfo also suggested by
stsp@.


# 1.167 05-Mar-2016 nicm

Although we always have en_US.UTF-8 on OpenBSD, some platforms do not,
so fall back to setlocale(LC_CTYPE, ""). tmux requires a UTF-8 locale,
so check with wcwidth() on a UTF-8 character after setlocale().


# 1.166 01-Mar-2016 nicm

Remove unused variables, from Michal Mazurek.


# 1.165 01-Mar-2016 nicm

Use system wcwidth() instead of carrying around UTF-8 width tables.


Revision tags: OPENBSD_5_9_BASE
# 1.164 19-Jan-2016 nicm

I no longer use my SourceForge address so replace it.


# 1.163 08-Dec-2015 nicm

Add hooks infrastructure, basic commands (set-hook, show-hooks) and a
couple of not very useful client hooks. This will eventually let
commands be run at various points and on notifications. Joint work with
Thomas Adam.


# 1.162 24-Nov-2015 nicm

Make environ_set va_args and use it to tidy up some calls. Also add a
missing word in manpage (from jmc).


# 1.161 24-Nov-2015 nicm

Shell command from -c doesn't have to be global, pass it as an argument.


# 1.160 24-Nov-2015 nicm

Tidy the code that works out the socket path, and just use the full path
in the global socket_path rather than copying it.


# 1.159 24-Nov-2015 nicm

Remove malloc_options DEBUG bit.


# 1.158 24-Nov-2015 nicm

Remove the -I part of show-messages which isn't really that useful; the
server start time can now be accessed with a new start_time format (use:
tmux display -p '#{t:start_time}')


# 1.157 24-Nov-2015 nicm

Make the log stuff a bit tidier with some helper functions.


# 1.156 22-Nov-2015 nicm

Add getpw to pledge, makes tmux work in YP environments, discovered by
matthieu, ok deraadt


# 1.155 20-Nov-2015 nicm

Instead of separate tables for different types of options, give each
option a scope type (server, session, window) in one table.


# 1.154 15-Nov-2015 nicm

Accidentally turned off pledge, turn it back on.


# 1.153 14-Nov-2015 nicm

Push stdout and stderr to clients more aggressively, and add an event to
continue if the send fails.


# 1.152 12-Nov-2015 nicm

tmux is UTF-8, so if $TMUX is set (tmux running in tmux), the client is
UTF-8. Also try to make the existing checks more readable.


# 1.151 12-Nov-2015 nicm

Nuke the utf8 and status-utf8 options and make tmux only a UTF-8
terminal. We still support non-UTF-8 terminals outside tmux, but inside
it is always UTF-8 (as when the utf8 and status-utf8 options were on).


# 1.150 11-Nov-2015 nicm

Drop mouse-utf8 option and always turn on UTF-8 mouse if the client says
it supports UTF-8.


# 1.149 28-Oct-2015 nicm

Like options, move the environ struct into environ.c.


# 1.148 27-Oct-2015 nicm

Move struct options into options.c.


# 1.147 27-Oct-2015 nicm

Break the common process set up, event loop and imsg dispatch code
between server and client out into a separate internal API. This will
make it easier to add another process.


# 1.146 25-Oct-2015 deraadt

Let's see if anyone screams about not being able to specify $TMPDIR
for their tmux sockets.

(Over the years, I have seen $TMPDIR set up worse than /tmp many times,
and don't know how this practice infected other parts of the system.
Nothing uses tmpdir(3), nor a huge-temporary-file program like sort.)
ok nicm


# 1.145 23-Oct-2015 nicm

tmux can call pledge() in main with large set and then reduce it
slightly in the server to "stdio rpath wpath cpath fattr unix recvfd
proc exec tty ps".


# 1.144 14-Sep-2015 nicm

Move tzset() from log_open to main.


# 1.143 03-Sep-2015 nicm

A couple of style nits.


# 1.142 01-Sep-2015 nicm

Work out config file when needed not at startup.


# 1.141 30-Aug-2015 nicm

Path from $TMUX does not need to be global anymore.


# 1.140 30-Aug-2015 nicm

Login shell can be a client flag, and move the exec code into client.c.


# 1.139 30-Aug-2015 nicm

Event base does not need to be global.


# 1.138 30-Aug-2015 nicm

Some style nits and dead assignments.


Revision tags: OPENBSD_5_8_BASE
# 1.137 20-Jul-2015 nicm

Add an option (history-file) for a file to save/restore command prompt
history, from Olof-Joachim Frahm.


# 1.136 04-Jun-2015 jmc

tweak SYNOPSIS and usage();


Revision tags: OPENBSD_5_7_BASE
# 1.135 19-Jan-2015 nicm

Make a tmux-%u directory under TMUX_TMPDIR, like TMPDIR.


# 1.134 19-Jan-2015 nicm

Only care about other permissions, allow group to be set.


# 1.133 19-Jan-2015 nicm

Remove unnecessary duplicate S_ISDIR check, from Dmitri Paduchikh.


# 1.132 20-Oct-2014 nicm

Tidy up some includes.


Revision tags: OPENBSD_5_6_BASE
# 1.131 17-Apr-2014 nicm

Remove the "info" message mechanism, this was only used for about five
mostly useless and annoying messages. Change those commands to silence
on success like all the others. Still accept the -q command line flag
and "quiet" server option for now.


# 1.130 31-Mar-2014 nicm

Remove log_debug2 as well and simplify log.c.


Revision tags: OPENBSD_5_5_BASE
# 1.129 16-Feb-2014 nicm

Leftovers from removing 88 colour support, from Theo Buehler.


# 1.128 15-Jan-2014 nicm

Do not attempt to read .tmux.conf if we can't figure out a home
directory, from Tiago Cunha.


# 1.127 09-Jan-2014 nicm

Three small changes from Tiago Cunha:

- Check for truncation when copying path.
- Don't need to use a temporary buffer in screen_set_title.
- Include strerror in output when connecting to server fails.


# 1.126 10-Oct-2013 nicm

We accidentally haven't been using $TMUX to work out the session for a
while and in fact it is less useful that using the client ttyname. So
don't bother and don't pass it from the client. If we need it in future
it is in c->environ.


# 1.125 10-Oct-2013 nicm

Alter how tmux handles the working directory to internally use file
descriptors rather than strings.

- Each session still has a current working directory.

- New sessions still get their working directory from the client that
created them or its attached session if any.

- New windows are created by default in the session working directory.

- The -c flag to new, neww, splitw allows the working directory to be
overridden.

- The -c flag to attach let's the session working directory be changed.

- The default-path option has been removed.

To get the equivalent to default-path '.', do:

bind c neww -c $PWD

To get the equivalent of default-path '~', do:

bind c neww -c ~

This also changes the client identify protocol to be a set of messages rather
than one as well as some other changes that should make it easier to make
backwards-compatible protocol changes in future.


# 1.124 10-Oct-2013 nicm

Merge IDENTIFY_* flags with CLIENT_* flags.


# 1.123 10-Oct-2013 nicm

Don't treat TMUX_TMPDIR as a potential file

The point of setting TMUX_TMPDIR is to then make any labels from -L go
to that directory. In the case of makesocketpath() with no TMUX_TMPDIR
set, would set both the path and the default socket to a file. The
checking of the permissions on the file worked fine in that case, but
when TMUX_TMPDIR is set, won't work on a directory.

This fixes the problem by ensuring the check on the permissions is
performed on directories only.

By Thomas Adam.


# 1.122 05-Oct-2013 nicm

Fix previous not to leak fd on failure, whoops.


# 1.121 05-Oct-2013 nicm

Use open(".")/fchdir() to save and restore current directory rather than
getcwd()/chdir().


Revision tags: OPENBSD_5_4_BASE
# 1.120 24-Apr-2013 nicm

Rename global configuration define.


# 1.119 11-Apr-2013 nicm

Call setlocale(LC_TIME) at startup.


# 1.118 27-Mar-2013 nicm

Add TMUX_TMPDIR variable to put the socket directory outside
TMPDIR. From Ben Boeckel.


# 1.117 27-Mar-2013 nicm

Remove tmux's (already minimal) 88 colour support. Such terminals are
few and unnecessary.


# 1.116 25-Mar-2013 nicm

Rename session idx to session id throughout and add $ prefix to targets
to use it, extended from a diff from George Nachman.


# 1.115 24-Mar-2013 nicm

Add a command queue to standardize and simplify commands that call other
commands and allow a command to block execution of subsequent
commands. This allows run-shell and if-shell to be synchronous which has
been much requested.

Each client has a default command queue and commands are consumed one at
a time from it. A command may suspend execution from the queue by
returning CMD_RETURN_WAIT and then resume it by calling cmd_continue() -
for example run-shell does this from the callback that is fired after
the job is freed.

When the command queue becomes empty, command clients are automatically
exited (unless attaching). A callback is also fired - this is used for
nested commands in, for example, if-shell which can block execution of
the client's cmdq until a new cmdq becomes empty.

Also merge all the old error/info/print functions together and lose the
old curclient/cmdclient distinction - a cmdq is bound to one client (or
none if in the configuration file), this is a command client if
c->session is NULL otherwise an attached client.


Revision tags: OPENBSD_5_3_BASE
# 1.114 27-Nov-2012 nicm

Correctly aggregate together errors from nested config files (with
source-file). Fix by Thomas Adam, reported by Sam Livingstone-Gray


# 1.113 26-Nov-2012 nicm

Call realpath earlier on the socket directory path rather than on the
socket file path because the latter may not exist yet and in that case
realpath is allowed to fail. From Romain Francoise.


Revision tags: OPENBSD_5_2_BASE
# 1.112 10-Jul-2012 nicm

xfree is not particularly helpful, remove it. From Thomas Adam.


# 1.111 18-Jun-2012 nicm

Add a skeleton mode to tmux (called "control mode") that let's tmux
commands be sent and output received on stdout. This can be used to
integrate with other terminal emulators and should allow some other
things to be made simpler later. More to come so doesn't do much yet and
deliberately not documented.


# 1.110 30-May-2012 nicm

Do not use stderr for log file and don't call log_close when not needed.


# 1.109 25-May-2012 nicm

Simplify logging and just fprintf(stderr, ...) for early errors.


Revision tags: OPENBSD_5_1_BASE
# 1.108 21-Jan-2012 nicm

Drop the ability to have a list of keys in the prefix in favour of two
separate options, prefix and prefix2. This simplifies the code and gets
rid the data options type which was only used for this one option.

Also add a -2 flag to send-prefix to send the secondary prefix key,
fixing a cause of minor irritation.

People who want three prefix keys are out of luck :-).


# 1.107 23-Oct-2011 nicm

Try to resolve relative paths for loadb and saveb (first using client
working directory if any then default-path or session wd).


# 1.106 23-Oct-2011 nicm

Ignore LC_ALL and LC_CTYPE if they are empty as well as unset.


# 1.105 25-Sep-2011 nicm

Reject $SHELL if it is not a full path.


Revision tags: OPENBSD_5_0_BASE
# 1.104 04-Mar-2011 nicm

Two fixes by Micah Cowan: make mouse work properly beyond >127 on signed
char architectures and properly parse $TMUX by stopping the socket path
at the first comma.


Revision tags: OPENBSD_4_9_BASE
# 1.103 23-Jan-2011 nicm

Set $TMUX without the session when background jobs are run.


# 1.102 12-Jan-2011 nicm

Use TMPDIR if set, from Han Boetes.


# 1.101 08-Jan-2011 nicm

Move all calls to fcntl(...O_NONBLOCK) into a function and clear the
flag on the stdio file descriptors before closing them (fixes things
like "tmux ls && cat").


# 1.100 03-Jan-2011 nicm

Support for UTF-8 mouse input (\033[1005h). This was added in xterm 262
and supports larger terminals than the older way.

If the new mouse-utf8 option is on, UTF-8 mouse input is enabled for all
UTF-8 terminals. The option defaults to on if LANG etc are set in the
same manner as the utf8 option.

With help and based on code from hsim at gmx.li.


# 1.99 01-Jan-2011 nicm

Move the user-visible parts of all options (names, types, limit, default
values) together into one set of tables in options-table.c. Also clean
up and simplify cmd-set-options.c and move a common print function into
option-table.c.


# 1.98 30-Dec-2010 nicm

Change from a per-session stack of buffers to one global stack which is
much more convenient and also simplifies lot of code. This renders
copy-buffer useless and makes buffer-limit now a server option.

By Tiago Cunha.


# 1.97 19-Dec-2010 nicm

Add other-pane-height and other-pane-width options, allowing the width
or height of the smaller panes in the main-horizontal and main-vertical
layouts to be set. Mostly from David Goodlad.


# 1.96 08-Dec-2010 nicm

In the built-in layouts, distribute the panes more evenly. Set the
default value of main-pane-width to 80, rather than 81. By Micah Cowan.


# 1.95 06-Dec-2010 nicm

Add an option to alert (monitor) for silence (lack of activity) in a
window. From Thomas Adam.


# 1.94 29-Nov-2010 nicm

If VISUAL or EDITOR contains "vi", configure mode-keys and status-keys
to vi.

Based on a diff from martynas@, previously requested by a couple of
other people.


# 1.93 11-Nov-2010 nicm

Add XAUTHORITY to update-environment, requested by Andreas Kloeckner.


# 1.92 18-Oct-2010 nicm

Merge the before and after attach client code into one in client.c
(instead of two in tmux.c and client.c).


# 1.91 16-Oct-2010 nicm

Make stdio blocking again before calling shell command with -c.


# 1.90 16-Oct-2010 nicm

Trying to set FD_CLOEXEC on every fd is a lost cause, just use
closefrom() before exec.


# 1.89 14-Oct-2010 nicm

Use an explicit event rather than event_once for the main event so it
can be removed when the client becomes ready.


# 1.88 26-Sep-2010 nicm

Two new options:

- server option "exit-unattached" makes the server exit when no clients
are attached, even if sessions are present;

- session option "destroy-unattached" destroys a session once no clients
are attached to it.

These are useful for preventing tmux remaining in the background where
it is undesirable and when using tmux as a login shell to keep a limit
on new sessions.


# 1.87 19-Aug-2010 nicm

Do not call event_del() for signals after fork(), just use sigaction()
directly instead - calling libevent functions after fork() w/o
event_reinit() is a bad idea, even if in this case it was harmless.


Revision tags: OPENBSD_4_8_BASE
# 1.86 04-Aug-2010 deraadt

switch back to kqueue for now, since (a) kqueue has been fixed to deal
with strange devices and (b) since there appears to be a bull in the
poll code in libevent as well...
requested by nicm who is away


# 1.85 24-Jul-2010 nicm

kqueue(2) is currently broken when used with /dev/null and a few other
devices.

An upcoming fix for some problems with the client stdout/stderr handling
relies on it working, so make tmux force libevent to use poll(2) via
EVENT_NOKQUEUE, until we have fixed kqueue.


# 1.84 11-Jul-2010 nicm

Return the command client return code with MSG_EXIT now that MSG_ERROR and
MSG_PRINT are unused.

New clients should be compatible with old tmux servers but vice versa may print
an error.


# 1.83 28-Jun-2010 nicm

Send all three of stdin, stdout, stderr from the client to the server, so that
commands can directly make use of them. This means that load-buffer and
save-buffer can have "-" as the file to read from stdin or write to stdout.

This is a protocol version bump so the tmux server will need to be restarted
after upgrade (or an older client used).


# 1.82 27-Jun-2010 nicm

Store the current working directory in the session, change the default-path
option to default to empty and make that mean that the stored session CWD is
used.


# 1.81 27-Jun-2010 nicm

New option, detach-on-destroy, to set what happens to a client when the session
it is attached to is destroyed. If on (the default), it is detached; if off, it
is switched to the most recently active session.


# 1.80 26-Jun-2010 nicm

Setting the cmdlist pointer in the bind-key to NULL to prevent it being freed
after the command is executing is bogus because it may still be needed if the
same command is going to be executed again (for example if you "bind-key a
bind-key b ..."). Making a copy is hard, so instead add a reference count to
the cmd_list.

While here, also print bind-key -n and the rest of the flags properly.

Fixes problem reported by mcbride@.


# 1.79 14-May-2010 nicm

Colour+attribute options for status line alerts, from Alex Alexander.


# 1.78 04-May-2010 nicm

Put this back in with the initialisation in the right order.


# 1.77 04-May-2010 nicm

Revert last change, it appears to be broken somehow.


# 1.76 03-May-2010 nicm

Make signal handler setup/teardown two common functions instead of six,
and reset SIGCHLD after fork to fix problems with some shells. From
Romain Francois.


# 1.75 28-Apr-2010 nicm

Make the active pane border have a green foreground instead of
background by default.


# 1.74 18-Apr-2010 nicm

Catch SIGCHLD to avoid a zombie, from patrick keshishian.


Revision tags: OPENBSD_4_7_BASE
# 1.73 22-Feb-2010 nicm

Option to set the characters considered word separators in copy mode, from
Micah Cowan.


# 1.72 08-Feb-2010 nicm

Add an option to disable the smcup/rmcup alternate screen behaviour inside
tmux. From clemens fischer.


# 1.71 06-Feb-2010 nicm

Change nested check to compare server socket path rather than just assuming
that if $TMUX is set it is nested. From Micah Cowan.


# 1.70 06-Feb-2010 nicm

Clean up $TMUX parsing, from Micah Cowan, tweaked by me.


# 1.69 06-Feb-2010 nicm

Instead of bailing out on the first configuration file error, carry on,
collecting all the errors, then start with the active window in more mode
displaying them.


# 1.68 04-Feb-2010 nicm

Read the path from $TMUX if it is present and -L and -S are not given. Based on
a diff from Micah Cowan.


# 1.67 04-Feb-2010 nicm

Option to display the active pane in a different colour with the display-panes
command. From Paul Hoffman, thanks.


# 1.66 03-Jan-2010 nicm

Options to set the colour of the pane borders, with different colours for the
active pane.


# 1.65 14-Dec-2009 nicm

New server option, escape-time, to set the timeout used to detect if escapes
are alone or part of a function key or meta sequence.


# 1.64 11-Dec-2009 nicm

Use quiet variable, and add missing sentinel to options array.


# 1.63 10-Dec-2009 nicm

Add "server options" which are server-wide and not bound to a session or
window. Set and displayed with "set -s" and "show -s".

Currently the only option is "quiet" (like command-line -q, allowing it to be
set from .tmux.conf), but others will come along.


# 1.62 03-Dec-2009 nicm

Massive spaces->tabs and trailing whitespace cleanup, hopefully for the last
time now I've configured emacs to make them displayed in really annoying
colours...


# 1.61 26-Nov-2009 nicm

Remove a couple of unused arguments where possible, and add /* ARGSUSED */ to
the rest to reduce lint output.


# 1.60 19-Nov-2009 nicm

Two new options, window-status-format and window-status-current-format, which
allow the format of each window in the status line window list to be controlled
using similar # sequences as status-left/right.

This diff also moves part of the way towards UTF-8 support in window names but
it isn't quite there yet.


# 1.59 19-Nov-2009 nicm

Revert to xterm-keys off by default. It was on as an experiment to see if the
option could be removed, but it affects vi, so we have to keep the option, and
a conservative default is better.


# 1.58 18-Nov-2009 nicm

Add a per-client log of status line messages displayed while that client
exists. A new message-limit session option sets the maximum number of entries
and a command, show-messages, shows the log (bound to ~ by default).

This (and prompt history) might be better as a single global log but until
there are global options it is easier for them to be per client.


# 1.57 10-Nov-2009 nicm

There is no real standard for modifier plus function keys. Previously, tmux
output some from rxvt but in other ways did the same as xterm or other
terminals, but this is a bit inconsistent.

xterm's method is fairly sensible and we already support it (xterm-keys), so
enable it by default instead.


# 1.56 04-Nov-2009 nicm

A couple of minor cosmetic changes.


# 1.55 04-Nov-2009 nicm

Initial changes to move tmux to libevent.

This moves the client-side loops are pretty much fully over to event-based only
(tmux.c and client.c) but server-side (server.c and friends) treats libevent as
a sort of clever poll, waking up after every event to run various things.

Moving the server stuff over to bufferevents and timers and so on will come
later.


# 1.54 04-Nov-2009 nicm

Change declaration and use of malloc_options to be more standard, from Tim van
der Molen.


# 1.53 26-Oct-2009 deraadt

tabs are better; ok nicm


# 1.52 25-Oct-2009 nicm

Remove the -d flag to tmux and just use op/AX to detect default colours.

Irritatingly, although op can be used to tell if a terminal supports default
colours, it can't be used to set them because in some terminfo descriptions it
resets attributes as a side-effect (acts as sgr0) and in others it doesn't, so
it is not possible to determine reliably what the terminal state will be
afterwards. So if AX is missing and op is present, tmux just sends sgr0.

Anyone using -d for a terminal who finds they actually needed it can replace it
using terminal-overrides, but please let me know as it is probably an omission
from terminfo.


# 1.51 22-Oct-2009 nicm

Merge prepare_cmd into main as it is short and only called once.


# 1.50 21-Oct-2009 nicm

Client tidying: get rid of client_ctx struct in favour of two variables in
client.c, and move the functions in client-fn.c into other files.


# 1.49 10-Oct-2009 nicm

New option, mouse-select-pane. If on, the mouse may be used to select the
current pane.

Suggested by sthen@ and also by someone else ages ago who I have forgotten.


# 1.48 10-Oct-2009 nicm

Support for individual session idle time locking. May be enabled by turning off
the lock-server option (it is on by default). When this is off, each session
locks when it has been idle for the lock-after-time setting. When on, the
entire server locks when ALL sessions have been idle for their individual
lock-after-time settings.

This replaces one global-only option (lock-after-time) with another
(lock-server), but the default behaviour is usually preferable so there don't
seem to be many alternatives.

Diff/idea largely from Thomas Adam, tweaked by me.


# 1.47 09-Oct-2009 nicm

Add a simple synchronize-panes window option: when set, all input to any pane
that is part of the window is also sent to all other panes in the same
window. Suggested by several, most recently Tomasz Pajor.


# 1.46 23-Sep-2009 nicm

Support -c like sh(1) to execute a command, useful when tmux is a login
shell. Suggested by halex@.

This includes another protocol version increase (the last for now) so again
restart the tmux server before upgrading.


# 1.45 23-Sep-2009 nicm

Remove the internal tmux locking and instead detach each client and run the
command specified by a new option "lock-command" (by default "lock -np") in
each client.

This means each terminal has to be unlocked individually but simplifies the
code and allows the system password to be used to unlock.

Note that the set-password command is gone, so it will need to be removed from
configuration files, and the -U command line flag has been removed.

This is the third protocol version change so again it is best to stop the tmux
server before upgrading.


# 1.44 22-Sep-2009 nicm

Permit multiple prefix keys to be defined, separated by commas, for example:

set -g prefix ^a,^b

Any key in the list acts as the prefix. The send-prefix command always sends
the first key in the list.


# 1.43 18-Sep-2009 nicm

New option, set-titles-string, to allow the window title to be specified (as
for status-left/right) if set-titles is on. Also only update the title when the
status line is being redrawn.


# 1.42 04-Sep-2009 nicm

Tidy main and make it a bit easier to read.


# 1.41 02-Sep-2009 nicm

Accept -l to make it easier for people who use tmux as a login shell to use
$SHELL. Originally from martynas@, tweaked by me.


# 1.40 02-Sep-2009 nicm

When incorrect passwords are entered, behave similarly to login(1) and backoff
for a bit. Based on a diff from martynas@.


# 1.39 01-Sep-2009 nicm

When using tmux as a login shell, there is currently no way to specify a shell
to be used as a login shell inside tmux, so add a default-shell session option.
This sets the shell invoked as a login shell when the default-command option is
empty.

The default option value is whichever of $SHELL, getpwuid(getuid())'s pw_shell
or /bin/sh is valid first.

Based on a diff from martynas@, changed by me to be a session option rather
than a window option.


# 1.38 01-Sep-2009 nicm

Use "Password:" with no space for password prompts and don't display a *s for
the password, like pretty much everything else. From martynas@ with minor
tweaks by me.


# 1.37 01-Sep-2009 nicm

Sort cases same as getopt argument, from martynas.


# 1.36 31-Aug-2009 nicm

Add a new display-panes command, with two options (display-panes-colour and
display-panes-time), which displays a visual indication of the number of each
pane.


# 1.35 23-Aug-2009 nicm

Add some other obvious variables to update-environment (WINDOWID SSH_ASKPASS
SSH_AUTH_SOCK SSH_AGENT_PID SSH_CONNECTION) so they are updated in the session
environment on new/attach.


# 1.34 13-Aug-2009 nicm

Disable mode-mouse (mouse in copy/choice mode) by default as it isn't very
useful at the moment and causes confusion.


# 1.33 13-Aug-2009 nicm

Add a base-index session option to specify the first index checked when looking
for an index for a new window.


# 1.32 12-Aug-2009 nicm

When started as the shell, __progname contains a leading -, so hardcode "tmux"
for socket path and log files, and strip it when working out the shell.


# 1.31 11-Aug-2009 nicm

Switch tmux to use imsg. This is the last major change to make the
client-server protocol more resilient and make the protocol versioning work
properly. In future, the only things requiring a protocol version bump will be
changes in the message structs, and (when both client and server have this
change) mixing different versions should nicely report an error message.

As a side effect this also makes the code tidier, fixes a problem with the way
errors reported during server startup were handled, and supports fd passing
(which will be used in future).

Looked over by eric@, thanks.

Please note that mixing a client with this change with an older server or vice
versa may cause tmux to crash or hang - tmux should be completely exited before
upgrading.


# 1.30 10-Aug-2009 nicm

No arguments are the same as new-session and this requires the environment to
be sent, so set that flag too when argc == 0.


# 1.29 08-Aug-2009 nicm

Infrastructure and commands to manage the environment for processes started
within tmux.

There is a global environment, copied from the external environment when the
server is started and each sesssion has an (initially empty) session
environment which overrides it.

New commands set-environment and show-environment manipulate or display the
environments.

A new session option, update-environment, is a space-separated list of
variables which are updated from the external environment into the session
environment every time a new session is created - the default is DISPLAY.


# 1.28 08-Aug-2009 nicm

Options to set the colours and attributes for status-left/-right. From Thomas
Adam, thanks.


# 1.27 05-Aug-2009 nicm

If colours are not supported by the terminal, try to emulate a coloured
background by setting or clearing the reverse attribute.

This makes a few applications which don't use the reverse attribute themselves
a little happier, and allows the status, message and mode options to have
default attributes and fg/bg options that work as expected when set as reverse.


# 1.26 04-Aug-2009 nicm

Check for "UTF8" as well as "UTF-8" in LANG etc as it seems this may also
appear.


# 1.25 03-Aug-2009 nicm

Add a terminal-overrides session option allowing individual terminfo(5) entries
to be overridden. The 88col/256col checks are now moved into the default
setting and out of the code.

Also remove a couple of old workarounds for xterm and rxvt which are no longer
necessary (tmux can emulate them if missing).


# 1.24 30-Jul-2009 nicm

Add a mode-mouse option to prevent tmux taking over the mouse in choice or copy
modes.


# 1.23 29-Jul-2009 nicm

Rename struct hdrtype to msgtype which is a better name and can be used even
when struct hdr disappears.


# 1.22 29-Jul-2009 nicm

Taking account of the "s, 22 not 24 is the maximum length of #T in status-right
to prevent the date being cut off.


# 1.21 26-Jul-2009 nicm

Make all messages sent between the client and server fixed size.

This is the first of two changes to make the protocol more resilient and less
sensitive to other changes in the code, particularly with commands. The client
now packs argv into a buffer and sends it to the server for parsing, rather
than doing it itself and sending the parsed command data.

As a side-effect this also removes a lot of now-unused command marshalling
code.

Mixing a server without this change and a client with or vice versa will cause
tmux to hang or crash, please ensure that tmux is entirely killed before
upgrading.


# 1.20 22-Jul-2009 nicm

Pass a set of flags into client_init rather than just a start_server
variable. Only one flag now but more to come later.


# 1.19 20-Jul-2009 nicm

Display the number of failed password attempts (if any) when the server is
locked. From Tom Doherty.


# 1.18 20-Jul-2009 nicm

Add a status-justify option to allow the window list in the status line to be
positioned at the left, centre, or right.


# 1.17 20-Jul-2009 nicm

New options, window-status-current-{fg,bg,attr}, to set the fg, bg and
attributes with which the current window is shown in the status line. From
Johan Friis, thanks.


# 1.16 18-Jul-2009 nicm

Add three new session options: visual-activity, visual-bell, visual-content. If
these are enabled (and the monitor-activity, bell-actio and monitor-content
options are configurated appropriately), when activity, a bell, or content is
detected, a message is shown.

Also tidy up the bell/activity/content code in server.c slightly and fix a
couple of errors.


# 1.15 17-Jul-2009 nicm

If -u is specified or UTF-8 is otherwise detected when the server is started,
enable the utf8 and status-utf8 optons. While here, note in the man page that
the server is started with the first session and exits when none remain.


# 1.14 10-Jul-2009 nicm

Add a default-terminal option to set the starting value of $TERM in new
windows.

This is "screen" by default and must be either that or something closely
related. This does makes it easier to customise it if necessary.


# 1.13 08-Jul-2009 nicm

Just appending -l to $SHELL to create a login shell is wrong: -l is not POSIX,
and some people may use shells which do not support it. Instead, make an empty
default-command option mean a login shell, and fork it with a - in argv[0]
which is the method used by login(1).

Also fix the automatic-rename code to handle this correctly and to strip a
leading - if present.


# 1.12 07-Jul-2009 nicm

Rename the global options variables to be shorter and to make session options
clear. No functional change, getting this out of the way to make later options
changes easier.


Revision tags: OPENBSD_4_6_BASE
# 1.11 25-Jun-2009 nicm

If getcwd() fails, use the user's home directory, or /, instead of failing with
an error.


# 1.10 25-Jun-2009 nicm

Remove error about using -L and -S together which was never displayed as
logging wasn't yet enabled, was unnecessary, and contradicted the man page
which says using -S will cause -L to be ignored.


# 1.9 23-Jun-2009 nicm

LC_ALL overrides LC_CTYPE and LANG. Comment was correct but the code
wrong. Pointed out by Hannah Schroeter, thanks.


# 1.8 05-Jun-2009 nicm

Check the first of LC_CTYPE, LC_ALL and LANG, rather than just the last, when
trying to decide about UTF-8, and use strcasestr. Reported by Geert Hendrickx.


# 1.7 04-Jun-2009 nicm

Zero the password given to -U in the client as well.


# 1.6 03-Jun-2009 nicm

Do not set the window title by default (make set-titles option default to off),
wiping over the title is rude and annoying. Agreed by several.


# 1.5 03-Jun-2009 nicm

New session option, status-utf8, to control the interpretation of top-bit-set
characters in status-left and status-right (if on, they are treated as UTF-8;
otherwise passed through).


# 1.4 02-Jun-2009 sobrado

remove unused flag; while here, make usage's output fit on 80-column displays.


# 1.3 02-Jun-2009 pyr

spawn login shells by default, adapt manpage bits as well.
ok nicm@


# 1.2 02-Jun-2009 ray

Don't leak memory if multiple -f flags are given.

OK nicm@


# 1.1 01-Jun-2009 nicm

Import tmux, a terminal multiplexor allowing (among other things) a single
terminal to be switched between several different windows and programs
displayed on one terminal be detached from one terminal and moved to another.

ok deraadt pirofti


# 1.211 17-Apr-2023 nicm

It seems silly to use progname for version, just always say tmux.


Revision tags: OPENBSD_7_3_BASE
# 1.210 10-Nov-2022 jmc

- sort options; from josiah frentsos
ok nicm

- add -N to SYNOPSIS

- sort usage()


Revision tags: OPENBSD_7_0_BASE OPENBSD_7_1_BASE OPENBSD_7_2_BASE
# 1.209 23-Aug-2021 nicm

Fix a few memory leaks.


# 1.208 06-Jul-2021 nicm

Improve error reporting when the tmux /tmp directory cannot be created
or used, GitHub issue 2765 from Uwe Kleine-Koenig.


# 1.207 10-Jun-2021 nicm

Do not expand the file given with -f so it can contain :s.


Revision tags: OPENBSD_6_9_BASE
# 1.206 22-Feb-2021 nicm

expand_paths needs the global environment to be set up, do that first.


# 1.205 22-Feb-2021 nicm

Move config file path expansion much earlier, keep the list of paths
around rather than freeing later, and add a config_files format variable
containing it. Suggested by kn@ a while back.


# 1.204 17-Jan-2021 nicm

Add -N flag to never start server even if command would normally do so,
GitHub issue 2523.


Revision tags: OPENBSD_6_8_BASE
# 1.203 22-Sep-2020 nicm

Fix warnings on some platforms with %llx and add a new message to handle
64-bit client flags.


# 1.202 02-Jun-2020 nicm

Use CLOCK_MONOTONIC for timer measurement and add a timestamp to control
mode %output blocks.


# 1.201 16-May-2020 nicm

Add a -D flag to ask tmux not to daemonize, useful both for running a
debugger (lldb does not have follow-fork-mode) and for running with a
managed supervisor init system. GitHub issue 2190.


# 1.200 16-May-2020 nicm

Add 'e' key in buffer mode to open the buffer in an editor.


# 1.199 16-May-2020 nicm

Build list of paths and weed out duplicates before loading configs, and
add TMUX_SOCK like TMUX_PATH for the socket directory.


Revision tags: OPENBSD_6_7_BASE
# 1.198 20-Apr-2020 nicm

Tidy up the terminal detection and feature code and add named sets of
terminal features, each of which are defined in one place and map to a
builtin set of terminfo(5) capabilities. Features can be specified based
on TERM with a new terminal-features option or with the -T flag when
running tmux. tmux will also detect a few common terminals from the DA
and DSR responses.

This is intended to make it easier to configure tmux's use of
terminfo(5) even in the presence of outdated ncurses(3) or terminfo(5)
databases or for features which do not yet have a terminfo(5) entry.
Instead of having to grok terminfo(5) capability names and what they
should be set to in the terminal-overrides option, the user can
hopefully just give tmux a feature name and let it do the right thing.

The terminal-overrides option remains both for backwards compatibility
and to allow tweaks of individual capabilities.

tmux already did much of this already, this makes it tidier and simpler
to configure.


# 1.197 16-Apr-2020 nicm

Show signal name when process exits rather than number.


# 1.196 09-Apr-2020 nicm

More style nits.


# 1.195 31-Mar-2020 nicm

Add a way to mark environment variables as "hidden" so they can be used
by tmux but are not passed into the environment of new panes.


# 1.194 17-Mar-2020 nicm

Ignore default-shell (and use /bin/sh) if it invalid not just if it is
tmux itself, also refuse to set the option to something invalid in the
first place. GitHub issue 2120.


# 1.193 12-Mar-2020 nicm

When the server socket is given by the user with -S, create it with
umask 177 instead of 117 because it may not be in a safe directory like
the default directory in /tmp. The user can chmod it more open after it
is created if they want.


# 1.192 28-Jan-2020 nicm

-V also needs to go in usage.


# 1.191 28-Jan-2020 nicm

Reduce a difference with portable tmux by adding the -V flag and
#{version} format; on OpenBSD these just report the OpenBSD version.


# 1.190 14-Oct-2019 nicm

Memory leaks, from Igor Wong in GitHub issue 1934.


Revision tags: OPENBSD_6_6_BASE
# 1.189 20-Jun-2019 nicm

Add a per-pane option set. Pane options inherit from window options (so
there should be no change to existing behaviour) and are set and shown
with set-option -p and show-options -p.

Change remain-on-exit and window-style/window-active-style to be pane
options (some others will be changed later).

This makes select-pane -P and -g unnecessary so no longer document them
(they still work) and no longer document set-window-option and
show-window-options in favour of set-option -w and show-options -w.


# 1.188 26-Apr-2019 nicm

Merge hooks into options and make each one an array option. This allows
multiple commands to be easily bound to one hook. set-hook and
show-hooks remain but they are now variants of set-option and
show-options. show-options now has a -H flag to show hooks (by default
they are not shown).


Revision tags: OPENBSD_6_5_BASE
# 1.187 22-Nov-2018 nicm

Do not use PWD unless it actually matches the real working directory.


Revision tags: OPENBSD_6_3_BASE OPENBSD_6_4_BASE
# 1.186 12-Jan-2018 nicm

Improve error message if creating socket parent directory fails, from
Thomas Adam for GitHub issue 1215.


# 1.185 01-Jan-2018 nicm

Prefer PWD for current directory if present in client, from Wei Zhao in
GitHub issue 1183.


Revision tags: OPENBSD_6_2_BASE
# 1.184 12-Jul-2017 nicm

Make shell_command a global like other stuff rather than making it an
exception and using callback argument.


# 1.183 03-Jul-2017 nicm

Try C.UTF-8 which is also a commonly useful locale on some platforms,
from Romain Francoise.


# 1.182 22-Apr-2017 nicm

Do not need getopt.h.


# 1.181 20-Apr-2017 nicm

Use fdforkpty() instead of our own unwrapped versions.


# 1.180 19-Apr-2017 nicm

Style nits and a missing cast.


# 1.179 16-Apr-2017 nicm

Memory leak, from David CARLIER.


Revision tags: OPENBSD_6_1_BASE
# 1.178 21-Mar-2017 nicm

Use uid_t for UID not u_int.


# 1.177 16-Feb-2017 nicm

Style nits.


# 1.176 23-Jan-2017 nicm

Open /dev/ptm before pledge() and save it to be used for PTMGET later
(this means inlining forkpty()).

ok deraadt


# 1.175 15-Jan-2017 nicm

Major tidy up and rework of options tree and set-option/show-options
commands this pushes more of the code into options.c and ties it more
closely to the options table rather than having an unnecessary
split. Also add support for array options (will be used later). Only
(intentional) user visible change is that show-options output is now
passed through vis(3) with VIS_DQ so quotes are escaped.


# 1.174 12-Jan-2017 nicm

Simplify appending to string options.


# 1.173 09-Dec-2016 nicm

Spacing nits.


# 1.172 11-Oct-2016 nicm

Add static in window-*.c and move some internal functions out of tmux.h.


# 1.171 10-Oct-2016 nicm

Loads more static, except for cmd-*.c and window-*.c.


Revision tags: OPENBSD_6_0_BASE
# 1.170 27-May-2016 nicm

Use getprogname() instead of __progname to make portability easier.


# 1.169 04-May-2016 nicm

Fix up a couple of long lines.


# 1.168 05-Mar-2016 nicm

If setlocale("en_US.UTF-8") succeeds, then don't do the check for UTF-8
locale since if it isn't UTF-8 the system is broken anyway. If it fails,
try "" and check for UTF-8 with nl_langinfo(CODESET) rather than
wcwidth(). Based on a diff from schwarze@, nl_langinfo also suggested by
stsp@.


# 1.167 05-Mar-2016 nicm

Although we always have en_US.UTF-8 on OpenBSD, some platforms do not,
so fall back to setlocale(LC_CTYPE, ""). tmux requires a UTF-8 locale,
so check with wcwidth() on a UTF-8 character after setlocale().


# 1.166 01-Mar-2016 nicm

Remove unused variables, from Michal Mazurek.


# 1.165 01-Mar-2016 nicm

Use system wcwidth() instead of carrying around UTF-8 width tables.


Revision tags: OPENBSD_5_9_BASE
# 1.164 19-Jan-2016 nicm

I no longer use my SourceForge address so replace it.


# 1.163 08-Dec-2015 nicm

Add hooks infrastructure, basic commands (set-hook, show-hooks) and a
couple of not very useful client hooks. This will eventually let
commands be run at various points and on notifications. Joint work with
Thomas Adam.


# 1.162 24-Nov-2015 nicm

Make environ_set va_args and use it to tidy up some calls. Also add a
missing word in manpage (from jmc).


# 1.161 24-Nov-2015 nicm

Shell command from -c doesn't have to be global, pass it as an argument.


# 1.160 24-Nov-2015 nicm

Tidy the code that works out the socket path, and just use the full path
in the global socket_path rather than copying it.


# 1.159 24-Nov-2015 nicm

Remove malloc_options DEBUG bit.


# 1.158 24-Nov-2015 nicm

Remove the -I part of show-messages which isn't really that useful; the
server start time can now be accessed with a new start_time format (use:
tmux display -p '#{t:start_time}')


# 1.157 24-Nov-2015 nicm

Make the log stuff a bit tidier with some helper functions.


# 1.156 22-Nov-2015 nicm

Add getpw to pledge, makes tmux work in YP environments, discovered by
matthieu, ok deraadt


# 1.155 20-Nov-2015 nicm

Instead of separate tables for different types of options, give each
option a scope type (server, session, window) in one table.


# 1.154 15-Nov-2015 nicm

Accidentally turned off pledge, turn it back on.


# 1.153 14-Nov-2015 nicm

Push stdout and stderr to clients more aggressively, and add an event to
continue if the send fails.


# 1.152 12-Nov-2015 nicm

tmux is UTF-8, so if $TMUX is set (tmux running in tmux), the client is
UTF-8. Also try to make the existing checks more readable.


# 1.151 12-Nov-2015 nicm

Nuke the utf8 and status-utf8 options and make tmux only a UTF-8
terminal. We still support non-UTF-8 terminals outside tmux, but inside
it is always UTF-8 (as when the utf8 and status-utf8 options were on).


# 1.150 11-Nov-2015 nicm

Drop mouse-utf8 option and always turn on UTF-8 mouse if the client says
it supports UTF-8.


# 1.149 28-Oct-2015 nicm

Like options, move the environ struct into environ.c.


# 1.148 27-Oct-2015 nicm

Move struct options into options.c.


# 1.147 27-Oct-2015 nicm

Break the common process set up, event loop and imsg dispatch code
between server and client out into a separate internal API. This will
make it easier to add another process.


# 1.146 25-Oct-2015 deraadt

Let's see if anyone screams about not being able to specify $TMPDIR
for their tmux sockets.

(Over the years, I have seen $TMPDIR set up worse than /tmp many times,
and don't know how this practice infected other parts of the system.
Nothing uses tmpdir(3), nor a huge-temporary-file program like sort.)
ok nicm


# 1.145 23-Oct-2015 nicm

tmux can call pledge() in main with large set and then reduce it
slightly in the server to "stdio rpath wpath cpath fattr unix recvfd
proc exec tty ps".


# 1.144 14-Sep-2015 nicm

Move tzset() from log_open to main.


# 1.143 03-Sep-2015 nicm

A couple of style nits.


# 1.142 01-Sep-2015 nicm

Work out config file when needed not at startup.


# 1.141 30-Aug-2015 nicm

Path from $TMUX does not need to be global anymore.


# 1.140 30-Aug-2015 nicm

Login shell can be a client flag, and move the exec code into client.c.


# 1.139 30-Aug-2015 nicm

Event base does not need to be global.


# 1.138 30-Aug-2015 nicm

Some style nits and dead assignments.


Revision tags: OPENBSD_5_8_BASE
# 1.137 20-Jul-2015 nicm

Add an option (history-file) for a file to save/restore command prompt
history, from Olof-Joachim Frahm.


# 1.136 04-Jun-2015 jmc

tweak SYNOPSIS and usage();


Revision tags: OPENBSD_5_7_BASE
# 1.135 19-Jan-2015 nicm

Make a tmux-%u directory under TMUX_TMPDIR, like TMPDIR.


# 1.134 19-Jan-2015 nicm

Only care about other permissions, allow group to be set.


# 1.133 19-Jan-2015 nicm

Remove unnecessary duplicate S_ISDIR check, from Dmitri Paduchikh.


# 1.132 20-Oct-2014 nicm

Tidy up some includes.


Revision tags: OPENBSD_5_6_BASE
# 1.131 17-Apr-2014 nicm

Remove the "info" message mechanism, this was only used for about five
mostly useless and annoying messages. Change those commands to silence
on success like all the others. Still accept the -q command line flag
and "quiet" server option for now.


# 1.130 31-Mar-2014 nicm

Remove log_debug2 as well and simplify log.c.


Revision tags: OPENBSD_5_5_BASE
# 1.129 16-Feb-2014 nicm

Leftovers from removing 88 colour support, from Theo Buehler.


# 1.128 15-Jan-2014 nicm

Do not attempt to read .tmux.conf if we can't figure out a home
directory, from Tiago Cunha.


# 1.127 09-Jan-2014 nicm

Three small changes from Tiago Cunha:

- Check for truncation when copying path.
- Don't need to use a temporary buffer in screen_set_title.
- Include strerror in output when connecting to server fails.


# 1.126 10-Oct-2013 nicm

We accidentally haven't been using $TMUX to work out the session for a
while and in fact it is less useful that using the client ttyname. So
don't bother and don't pass it from the client. If we need it in future
it is in c->environ.


# 1.125 10-Oct-2013 nicm

Alter how tmux handles the working directory to internally use file
descriptors rather than strings.

- Each session still has a current working directory.

- New sessions still get their working directory from the client that
created them or its attached session if any.

- New windows are created by default in the session working directory.

- The -c flag to new, neww, splitw allows the working directory to be
overridden.

- The -c flag to attach let's the session working directory be changed.

- The default-path option has been removed.

To get the equivalent to default-path '.', do:

bind c neww -c $PWD

To get the equivalent of default-path '~', do:

bind c neww -c ~

This also changes the client identify protocol to be a set of messages rather
than one as well as some other changes that should make it easier to make
backwards-compatible protocol changes in future.


# 1.124 10-Oct-2013 nicm

Merge IDENTIFY_* flags with CLIENT_* flags.


# 1.123 10-Oct-2013 nicm

Don't treat TMUX_TMPDIR as a potential file

The point of setting TMUX_TMPDIR is to then make any labels from -L go
to that directory. In the case of makesocketpath() with no TMUX_TMPDIR
set, would set both the path and the default socket to a file. The
checking of the permissions on the file worked fine in that case, but
when TMUX_TMPDIR is set, won't work on a directory.

This fixes the problem by ensuring the check on the permissions is
performed on directories only.

By Thomas Adam.


# 1.122 05-Oct-2013 nicm

Fix previous not to leak fd on failure, whoops.


# 1.121 05-Oct-2013 nicm

Use open(".")/fchdir() to save and restore current directory rather than
getcwd()/chdir().


Revision tags: OPENBSD_5_4_BASE
# 1.120 24-Apr-2013 nicm

Rename global configuration define.


# 1.119 11-Apr-2013 nicm

Call setlocale(LC_TIME) at startup.


# 1.118 27-Mar-2013 nicm

Add TMUX_TMPDIR variable to put the socket directory outside
TMPDIR. From Ben Boeckel.


# 1.117 27-Mar-2013 nicm

Remove tmux's (already minimal) 88 colour support. Such terminals are
few and unnecessary.


# 1.116 25-Mar-2013 nicm

Rename session idx to session id throughout and add $ prefix to targets
to use it, extended from a diff from George Nachman.


# 1.115 24-Mar-2013 nicm

Add a command queue to standardize and simplify commands that call other
commands and allow a command to block execution of subsequent
commands. This allows run-shell and if-shell to be synchronous which has
been much requested.

Each client has a default command queue and commands are consumed one at
a time from it. A command may suspend execution from the queue by
returning CMD_RETURN_WAIT and then resume it by calling cmd_continue() -
for example run-shell does this from the callback that is fired after
the job is freed.

When the command queue becomes empty, command clients are automatically
exited (unless attaching). A callback is also fired - this is used for
nested commands in, for example, if-shell which can block execution of
the client's cmdq until a new cmdq becomes empty.

Also merge all the old error/info/print functions together and lose the
old curclient/cmdclient distinction - a cmdq is bound to one client (or
none if in the configuration file), this is a command client if
c->session is NULL otherwise an attached client.


Revision tags: OPENBSD_5_3_BASE
# 1.114 27-Nov-2012 nicm

Correctly aggregate together errors from nested config files (with
source-file). Fix by Thomas Adam, reported by Sam Livingstone-Gray


# 1.113 26-Nov-2012 nicm

Call realpath earlier on the socket directory path rather than on the
socket file path because the latter may not exist yet and in that case
realpath is allowed to fail. From Romain Francoise.


Revision tags: OPENBSD_5_2_BASE
# 1.112 10-Jul-2012 nicm

xfree is not particularly helpful, remove it. From Thomas Adam.


# 1.111 18-Jun-2012 nicm

Add a skeleton mode to tmux (called "control mode") that let's tmux
commands be sent and output received on stdout. This can be used to
integrate with other terminal emulators and should allow some other
things to be made simpler later. More to come so doesn't do much yet and
deliberately not documented.


# 1.110 30-May-2012 nicm

Do not use stderr for log file and don't call log_close when not needed.


# 1.109 25-May-2012 nicm

Simplify logging and just fprintf(stderr, ...) for early errors.


Revision tags: OPENBSD_5_1_BASE
# 1.108 21-Jan-2012 nicm

Drop the ability to have a list of keys in the prefix in favour of two
separate options, prefix and prefix2. This simplifies the code and gets
rid the data options type which was only used for this one option.

Also add a -2 flag to send-prefix to send the secondary prefix key,
fixing a cause of minor irritation.

People who want three prefix keys are out of luck :-).


# 1.107 23-Oct-2011 nicm

Try to resolve relative paths for loadb and saveb (first using client
working directory if any then default-path or session wd).


# 1.106 23-Oct-2011 nicm

Ignore LC_ALL and LC_CTYPE if they are empty as well as unset.


# 1.105 25-Sep-2011 nicm

Reject $SHELL if it is not a full path.


Revision tags: OPENBSD_5_0_BASE
# 1.104 04-Mar-2011 nicm

Two fixes by Micah Cowan: make mouse work properly beyond >127 on signed
char architectures and properly parse $TMUX by stopping the socket path
at the first comma.


Revision tags: OPENBSD_4_9_BASE
# 1.103 23-Jan-2011 nicm

Set $TMUX without the session when background jobs are run.


# 1.102 12-Jan-2011 nicm

Use TMPDIR if set, from Han Boetes.


# 1.101 08-Jan-2011 nicm

Move all calls to fcntl(...O_NONBLOCK) into a function and clear the
flag on the stdio file descriptors before closing them (fixes things
like "tmux ls && cat").


# 1.100 03-Jan-2011 nicm

Support for UTF-8 mouse input (\033[1005h). This was added in xterm 262
and supports larger terminals than the older way.

If the new mouse-utf8 option is on, UTF-8 mouse input is enabled for all
UTF-8 terminals. The option defaults to on if LANG etc are set in the
same manner as the utf8 option.

With help and based on code from hsim at gmx.li.


# 1.99 01-Jan-2011 nicm

Move the user-visible parts of all options (names, types, limit, default
values) together into one set of tables in options-table.c. Also clean
up and simplify cmd-set-options.c and move a common print function into
option-table.c.


# 1.98 30-Dec-2010 nicm

Change from a per-session stack of buffers to one global stack which is
much more convenient and also simplifies lot of code. This renders
copy-buffer useless and makes buffer-limit now a server option.

By Tiago Cunha.


# 1.97 19-Dec-2010 nicm

Add other-pane-height and other-pane-width options, allowing the width
or height of the smaller panes in the main-horizontal and main-vertical
layouts to be set. Mostly from David Goodlad.


# 1.96 08-Dec-2010 nicm

In the built-in layouts, distribute the panes more evenly. Set the
default value of main-pane-width to 80, rather than 81. By Micah Cowan.


# 1.95 06-Dec-2010 nicm

Add an option to alert (monitor) for silence (lack of activity) in a
window. From Thomas Adam.


# 1.94 29-Nov-2010 nicm

If VISUAL or EDITOR contains "vi", configure mode-keys and status-keys
to vi.

Based on a diff from martynas@, previously requested by a couple of
other people.


# 1.93 11-Nov-2010 nicm

Add XAUTHORITY to update-environment, requested by Andreas Kloeckner.


# 1.92 18-Oct-2010 nicm

Merge the before and after attach client code into one in client.c
(instead of two in tmux.c and client.c).


# 1.91 16-Oct-2010 nicm

Make stdio blocking again before calling shell command with -c.


# 1.90 16-Oct-2010 nicm

Trying to set FD_CLOEXEC on every fd is a lost cause, just use
closefrom() before exec.


# 1.89 14-Oct-2010 nicm

Use an explicit event rather than event_once for the main event so it
can be removed when the client becomes ready.


# 1.88 26-Sep-2010 nicm

Two new options:

- server option "exit-unattached" makes the server exit when no clients
are attached, even if sessions are present;

- session option "destroy-unattached" destroys a session once no clients
are attached to it.

These are useful for preventing tmux remaining in the background where
it is undesirable and when using tmux as a login shell to keep a limit
on new sessions.


# 1.87 19-Aug-2010 nicm

Do not call event_del() for signals after fork(), just use sigaction()
directly instead - calling libevent functions after fork() w/o
event_reinit() is a bad idea, even if in this case it was harmless.


Revision tags: OPENBSD_4_8_BASE
# 1.86 04-Aug-2010 deraadt

switch back to kqueue for now, since (a) kqueue has been fixed to deal
with strange devices and (b) since there appears to be a bull in the
poll code in libevent as well...
requested by nicm who is away


# 1.85 24-Jul-2010 nicm

kqueue(2) is currently broken when used with /dev/null and a few other
devices.

An upcoming fix for some problems with the client stdout/stderr handling
relies on it working, so make tmux force libevent to use poll(2) via
EVENT_NOKQUEUE, until we have fixed kqueue.


# 1.84 11-Jul-2010 nicm

Return the command client return code with MSG_EXIT now that MSG_ERROR and
MSG_PRINT are unused.

New clients should be compatible with old tmux servers but vice versa may print
an error.


# 1.83 28-Jun-2010 nicm

Send all three of stdin, stdout, stderr from the client to the server, so that
commands can directly make use of them. This means that load-buffer and
save-buffer can have "-" as the file to read from stdin or write to stdout.

This is a protocol version bump so the tmux server will need to be restarted
after upgrade (or an older client used).


# 1.82 27-Jun-2010 nicm

Store the current working directory in the session, change the default-path
option to default to empty and make that mean that the stored session CWD is
used.


# 1.81 27-Jun-2010 nicm

New option, detach-on-destroy, to set what happens to a client when the session
it is attached to is destroyed. If on (the default), it is detached; if off, it
is switched to the most recently active session.


# 1.80 26-Jun-2010 nicm

Setting the cmdlist pointer in the bind-key to NULL to prevent it being freed
after the command is executing is bogus because it may still be needed if the
same command is going to be executed again (for example if you "bind-key a
bind-key b ..."). Making a copy is hard, so instead add a reference count to
the cmd_list.

While here, also print bind-key -n and the rest of the flags properly.

Fixes problem reported by mcbride@.


# 1.79 14-May-2010 nicm

Colour+attribute options for status line alerts, from Alex Alexander.


# 1.78 04-May-2010 nicm

Put this back in with the initialisation in the right order.


# 1.77 04-May-2010 nicm

Revert last change, it appears to be broken somehow.


# 1.76 03-May-2010 nicm

Make signal handler setup/teardown two common functions instead of six,
and reset SIGCHLD after fork to fix problems with some shells. From
Romain Francois.


# 1.75 28-Apr-2010 nicm

Make the active pane border have a green foreground instead of
background by default.


# 1.74 18-Apr-2010 nicm

Catch SIGCHLD to avoid a zombie, from patrick keshishian.


Revision tags: OPENBSD_4_7_BASE
# 1.73 22-Feb-2010 nicm

Option to set the characters considered word separators in copy mode, from
Micah Cowan.


# 1.72 08-Feb-2010 nicm

Add an option to disable the smcup/rmcup alternate screen behaviour inside
tmux. From clemens fischer.


# 1.71 06-Feb-2010 nicm

Change nested check to compare server socket path rather than just assuming
that if $TMUX is set it is nested. From Micah Cowan.


# 1.70 06-Feb-2010 nicm

Clean up $TMUX parsing, from Micah Cowan, tweaked by me.


# 1.69 06-Feb-2010 nicm

Instead of bailing out on the first configuration file error, carry on,
collecting all the errors, then start with the active window in more mode
displaying them.


# 1.68 04-Feb-2010 nicm

Read the path from $TMUX if it is present and -L and -S are not given. Based on
a diff from Micah Cowan.


# 1.67 04-Feb-2010 nicm

Option to display the active pane in a different colour with the display-panes
command. From Paul Hoffman, thanks.


# 1.66 03-Jan-2010 nicm

Options to set the colour of the pane borders, with different colours for the
active pane.


# 1.65 14-Dec-2009 nicm

New server option, escape-time, to set the timeout used to detect if escapes
are alone or part of a function key or meta sequence.


# 1.64 11-Dec-2009 nicm

Use quiet variable, and add missing sentinel to options array.


# 1.63 10-Dec-2009 nicm

Add "server options" which are server-wide and not bound to a session or
window. Set and displayed with "set -s" and "show -s".

Currently the only option is "quiet" (like command-line -q, allowing it to be
set from .tmux.conf), but others will come along.


# 1.62 03-Dec-2009 nicm

Massive spaces->tabs and trailing whitespace cleanup, hopefully for the last
time now I've configured emacs to make them displayed in really annoying
colours...


# 1.61 26-Nov-2009 nicm

Remove a couple of unused arguments where possible, and add /* ARGSUSED */ to
the rest to reduce lint output.


# 1.60 19-Nov-2009 nicm

Two new options, window-status-format and window-status-current-format, which
allow the format of each window in the status line window list to be controlled
using similar # sequences as status-left/right.

This diff also moves part of the way towards UTF-8 support in window names but
it isn't quite there yet.


# 1.59 19-Nov-2009 nicm

Revert to xterm-keys off by default. It was on as an experiment to see if the
option could be removed, but it affects vi, so we have to keep the option, and
a conservative default is better.


# 1.58 18-Nov-2009 nicm

Add a per-client log of status line messages displayed while that client
exists. A new message-limit session option sets the maximum number of entries
and a command, show-messages, shows the log (bound to ~ by default).

This (and prompt history) might be better as a single global log but until
there are global options it is easier for them to be per client.


# 1.57 10-Nov-2009 nicm

There is no real standard for modifier plus function keys. Previously, tmux
output some from rxvt but in other ways did the same as xterm or other
terminals, but this is a bit inconsistent.

xterm's method is fairly sensible and we already support it (xterm-keys), so
enable it by default instead.


# 1.56 04-Nov-2009 nicm

A couple of minor cosmetic changes.


# 1.55 04-Nov-2009 nicm

Initial changes to move tmux to libevent.

This moves the client-side loops are pretty much fully over to event-based only
(tmux.c and client.c) but server-side (server.c and friends) treats libevent as
a sort of clever poll, waking up after every event to run various things.

Moving the server stuff over to bufferevents and timers and so on will come
later.


# 1.54 04-Nov-2009 nicm

Change declaration and use of malloc_options to be more standard, from Tim van
der Molen.


# 1.53 26-Oct-2009 deraadt

tabs are better; ok nicm


# 1.52 25-Oct-2009 nicm

Remove the -d flag to tmux and just use op/AX to detect default colours.

Irritatingly, although op can be used to tell if a terminal supports default
colours, it can't be used to set them because in some terminfo descriptions it
resets attributes as a side-effect (acts as sgr0) and in others it doesn't, so
it is not possible to determine reliably what the terminal state will be
afterwards. So if AX is missing and op is present, tmux just sends sgr0.

Anyone using -d for a terminal who finds they actually needed it can replace it
using terminal-overrides, but please let me know as it is probably an omission
from terminfo.


# 1.51 22-Oct-2009 nicm

Merge prepare_cmd into main as it is short and only called once.


# 1.50 21-Oct-2009 nicm

Client tidying: get rid of client_ctx struct in favour of two variables in
client.c, and move the functions in client-fn.c into other files.


# 1.49 10-Oct-2009 nicm

New option, mouse-select-pane. If on, the mouse may be used to select the
current pane.

Suggested by sthen@ and also by someone else ages ago who I have forgotten.


# 1.48 10-Oct-2009 nicm

Support for individual session idle time locking. May be enabled by turning off
the lock-server option (it is on by default). When this is off, each session
locks when it has been idle for the lock-after-time setting. When on, the
entire server locks when ALL sessions have been idle for their individual
lock-after-time settings.

This replaces one global-only option (lock-after-time) with another
(lock-server), but the default behaviour is usually preferable so there don't
seem to be many alternatives.

Diff/idea largely from Thomas Adam, tweaked by me.


# 1.47 09-Oct-2009 nicm

Add a simple synchronize-panes window option: when set, all input to any pane
that is part of the window is also sent to all other panes in the same
window. Suggested by several, most recently Tomasz Pajor.


# 1.46 23-Sep-2009 nicm

Support -c like sh(1) to execute a command, useful when tmux is a login
shell. Suggested by halex@.

This includes another protocol version increase (the last for now) so again
restart the tmux server before upgrading.


# 1.45 23-Sep-2009 nicm

Remove the internal tmux locking and instead detach each client and run the
command specified by a new option "lock-command" (by default "lock -np") in
each client.

This means each terminal has to be unlocked individually but simplifies the
code and allows the system password to be used to unlock.

Note that the set-password command is gone, so it will need to be removed from
configuration files, and the -U command line flag has been removed.

This is the third protocol version change so again it is best to stop the tmux
server before upgrading.


# 1.44 22-Sep-2009 nicm

Permit multiple prefix keys to be defined, separated by commas, for example:

set -g prefix ^a,^b

Any key in the list acts as the prefix. The send-prefix command always sends
the first key in the list.


# 1.43 18-Sep-2009 nicm

New option, set-titles-string, to allow the window title to be specified (as
for status-left/right) if set-titles is on. Also only update the title when the
status line is being redrawn.


# 1.42 04-Sep-2009 nicm

Tidy main and make it a bit easier to read.


# 1.41 02-Sep-2009 nicm

Accept -l to make it easier for people who use tmux as a login shell to use
$SHELL. Originally from martynas@, tweaked by me.


# 1.40 02-Sep-2009 nicm

When incorrect passwords are entered, behave similarly to login(1) and backoff
for a bit. Based on a diff from martynas@.


# 1.39 01-Sep-2009 nicm

When using tmux as a login shell, there is currently no way to specify a shell
to be used as a login shell inside tmux, so add a default-shell session option.
This sets the shell invoked as a login shell when the default-command option is
empty.

The default option value is whichever of $SHELL, getpwuid(getuid())'s pw_shell
or /bin/sh is valid first.

Based on a diff from martynas@, changed by me to be a session option rather
than a window option.


# 1.38 01-Sep-2009 nicm

Use "Password:" with no space for password prompts and don't display a *s for
the password, like pretty much everything else. From martynas@ with minor
tweaks by me.


# 1.37 01-Sep-2009 nicm

Sort cases same as getopt argument, from martynas.


# 1.36 31-Aug-2009 nicm

Add a new display-panes command, with two options (display-panes-colour and
display-panes-time), which displays a visual indication of the number of each
pane.


# 1.35 23-Aug-2009 nicm

Add some other obvious variables to update-environment (WINDOWID SSH_ASKPASS
SSH_AUTH_SOCK SSH_AGENT_PID SSH_CONNECTION) so they are updated in the session
environment on new/attach.


# 1.34 13-Aug-2009 nicm

Disable mode-mouse (mouse in copy/choice mode) by default as it isn't very
useful at the moment and causes confusion.


# 1.33 13-Aug-2009 nicm

Add a base-index session option to specify the first index checked when looking
for an index for a new window.


# 1.32 12-Aug-2009 nicm

When started as the shell, __progname contains a leading -, so hardcode "tmux"
for socket path and log files, and strip it when working out the shell.


# 1.31 11-Aug-2009 nicm

Switch tmux to use imsg. This is the last major change to make the
client-server protocol more resilient and make the protocol versioning work
properly. In future, the only things requiring a protocol version bump will be
changes in the message structs, and (when both client and server have this
change) mixing different versions should nicely report an error message.

As a side effect this also makes the code tidier, fixes a problem with the way
errors reported during server startup were handled, and supports fd passing
(which will be used in future).

Looked over by eric@, thanks.

Please note that mixing a client with this change with an older server or vice
versa may cause tmux to crash or hang - tmux should be completely exited before
upgrading.


# 1.30 10-Aug-2009 nicm

No arguments are the same as new-session and this requires the environment to
be sent, so set that flag too when argc == 0.


# 1.29 08-Aug-2009 nicm

Infrastructure and commands to manage the environment for processes started
within tmux.

There is a global environment, copied from the external environment when the
server is started and each sesssion has an (initially empty) session
environment which overrides it.

New commands set-environment and show-environment manipulate or display the
environments.

A new session option, update-environment, is a space-separated list of
variables which are updated from the external environment into the session
environment every time a new session is created - the default is DISPLAY.


# 1.28 08-Aug-2009 nicm

Options to set the colours and attributes for status-left/-right. From Thomas
Adam, thanks.


# 1.27 05-Aug-2009 nicm

If colours are not supported by the terminal, try to emulate a coloured
background by setting or clearing the reverse attribute.

This makes a few applications which don't use the reverse attribute themselves
a little happier, and allows the status, message and mode options to have
default attributes and fg/bg options that work as expected when set as reverse.


# 1.26 04-Aug-2009 nicm

Check for "UTF8" as well as "UTF-8" in LANG etc as it seems this may also
appear.


# 1.25 03-Aug-2009 nicm

Add a terminal-overrides session option allowing individual terminfo(5) entries
to be overridden. The 88col/256col checks are now moved into the default
setting and out of the code.

Also remove a couple of old workarounds for xterm and rxvt which are no longer
necessary (tmux can emulate them if missing).


# 1.24 30-Jul-2009 nicm

Add a mode-mouse option to prevent tmux taking over the mouse in choice or copy
modes.


# 1.23 29-Jul-2009 nicm

Rename struct hdrtype to msgtype which is a better name and can be used even
when struct hdr disappears.


# 1.22 29-Jul-2009 nicm

Taking account of the "s, 22 not 24 is the maximum length of #T in status-right
to prevent the date being cut off.


# 1.21 26-Jul-2009 nicm

Make all messages sent between the client and server fixed size.

This is the first of two changes to make the protocol more resilient and less
sensitive to other changes in the code, particularly with commands. The client
now packs argv into a buffer and sends it to the server for parsing, rather
than doing it itself and sending the parsed command data.

As a side-effect this also removes a lot of now-unused command marshalling
code.

Mixing a server without this change and a client with or vice versa will cause
tmux to hang or crash, please ensure that tmux is entirely killed before
upgrading.


# 1.20 22-Jul-2009 nicm

Pass a set of flags into client_init rather than just a start_server
variable. Only one flag now but more to come later.


# 1.19 20-Jul-2009 nicm

Display the number of failed password attempts (if any) when the server is
locked. From Tom Doherty.


# 1.18 20-Jul-2009 nicm

Add a status-justify option to allow the window list in the status line to be
positioned at the left, centre, or right.


# 1.17 20-Jul-2009 nicm

New options, window-status-current-{fg,bg,attr}, to set the fg, bg and
attributes with which the current window is shown in the status line. From
Johan Friis, thanks.


# 1.16 18-Jul-2009 nicm

Add three new session options: visual-activity, visual-bell, visual-content. If
these are enabled (and the monitor-activity, bell-actio and monitor-content
options are configurated appropriately), when activity, a bell, or content is
detected, a message is shown.

Also tidy up the bell/activity/content code in server.c slightly and fix a
couple of errors.


# 1.15 17-Jul-2009 nicm

If -u is specified or UTF-8 is otherwise detected when the server is started,
enable the utf8 and status-utf8 optons. While here, note in the man page that
the server is started with the first session and exits when none remain.


# 1.14 10-Jul-2009 nicm

Add a default-terminal option to set the starting value of $TERM in new
windows.

This is "screen" by default and must be either that or something closely
related. This does makes it easier to customise it if necessary.


# 1.13 08-Jul-2009 nicm

Just appending -l to $SHELL to create a login shell is wrong: -l is not POSIX,
and some people may use shells which do not support it. Instead, make an empty
default-command option mean a login shell, and fork it with a - in argv[0]
which is the method used by login(1).

Also fix the automatic-rename code to handle this correctly and to strip a
leading - if present.


# 1.12 07-Jul-2009 nicm

Rename the global options variables to be shorter and to make session options
clear. No functional change, getting this out of the way to make later options
changes easier.


Revision tags: OPENBSD_4_6_BASE
# 1.11 25-Jun-2009 nicm

If getcwd() fails, use the user's home directory, or /, instead of failing with
an error.


# 1.10 25-Jun-2009 nicm

Remove error about using -L and -S together which was never displayed as
logging wasn't yet enabled, was unnecessary, and contradicted the man page
which says using -S will cause -L to be ignored.


# 1.9 23-Jun-2009 nicm

LC_ALL overrides LC_CTYPE and LANG. Comment was correct but the code
wrong. Pointed out by Hannah Schroeter, thanks.


# 1.8 05-Jun-2009 nicm

Check the first of LC_CTYPE, LC_ALL and LANG, rather than just the last, when
trying to decide about UTF-8, and use strcasestr. Reported by Geert Hendrickx.


# 1.7 04-Jun-2009 nicm

Zero the password given to -U in the client as well.


# 1.6 03-Jun-2009 nicm

Do not set the window title by default (make set-titles option default to off),
wiping over the title is rude and annoying. Agreed by several.


# 1.5 03-Jun-2009 nicm

New session option, status-utf8, to control the interpretation of top-bit-set
characters in status-left and status-right (if on, they are treated as UTF-8;
otherwise passed through).


# 1.4 02-Jun-2009 sobrado

remove unused flag; while here, make usage's output fit on 80-column displays.


# 1.3 02-Jun-2009 pyr

spawn login shells by default, adapt manpage bits as well.
ok nicm@


# 1.2 02-Jun-2009 ray

Don't leak memory if multiple -f flags are given.

OK nicm@


# 1.1 01-Jun-2009 nicm

Import tmux, a terminal multiplexor allowing (among other things) a single
terminal to be switched between several different windows and programs
displayed on one terminal be detached from one terminal and moved to another.

ok deraadt pirofti


# 1.210 10-Nov-2022 jmc

- sort options; from josiah frentsos
ok nicm

- add -N to SYNOPSIS

- sort usage()


Revision tags: OPENBSD_7_0_BASE OPENBSD_7_1_BASE OPENBSD_7_2_BASE
# 1.209 23-Aug-2021 nicm

Fix a few memory leaks.


# 1.208 06-Jul-2021 nicm

Improve error reporting when the tmux /tmp directory cannot be created
or used, GitHub issue 2765 from Uwe Kleine-Koenig.


# 1.207 10-Jun-2021 nicm

Do not expand the file given with -f so it can contain :s.


Revision tags: OPENBSD_6_9_BASE
# 1.206 22-Feb-2021 nicm

expand_paths needs the global environment to be set up, do that first.


# 1.205 22-Feb-2021 nicm

Move config file path expansion much earlier, keep the list of paths
around rather than freeing later, and add a config_files format variable
containing it. Suggested by kn@ a while back.


# 1.204 17-Jan-2021 nicm

Add -N flag to never start server even if command would normally do so,
GitHub issue 2523.


Revision tags: OPENBSD_6_8_BASE
# 1.203 22-Sep-2020 nicm

Fix warnings on some platforms with %llx and add a new message to handle
64-bit client flags.


# 1.202 02-Jun-2020 nicm

Use CLOCK_MONOTONIC for timer measurement and add a timestamp to control
mode %output blocks.


# 1.201 16-May-2020 nicm

Add a -D flag to ask tmux not to daemonize, useful both for running a
debugger (lldb does not have follow-fork-mode) and for running with a
managed supervisor init system. GitHub issue 2190.


# 1.200 16-May-2020 nicm

Add 'e' key in buffer mode to open the buffer in an editor.


# 1.199 16-May-2020 nicm

Build list of paths and weed out duplicates before loading configs, and
add TMUX_SOCK like TMUX_PATH for the socket directory.


Revision tags: OPENBSD_6_7_BASE
# 1.198 20-Apr-2020 nicm

Tidy up the terminal detection and feature code and add named sets of
terminal features, each of which are defined in one place and map to a
builtin set of terminfo(5) capabilities. Features can be specified based
on TERM with a new terminal-features option or with the -T flag when
running tmux. tmux will also detect a few common terminals from the DA
and DSR responses.

This is intended to make it easier to configure tmux's use of
terminfo(5) even in the presence of outdated ncurses(3) or terminfo(5)
databases or for features which do not yet have a terminfo(5) entry.
Instead of having to grok terminfo(5) capability names and what they
should be set to in the terminal-overrides option, the user can
hopefully just give tmux a feature name and let it do the right thing.

The terminal-overrides option remains both for backwards compatibility
and to allow tweaks of individual capabilities.

tmux already did much of this already, this makes it tidier and simpler
to configure.


# 1.197 16-Apr-2020 nicm

Show signal name when process exits rather than number.


# 1.196 09-Apr-2020 nicm

More style nits.


# 1.195 31-Mar-2020 nicm

Add a way to mark environment variables as "hidden" so they can be used
by tmux but are not passed into the environment of new panes.


# 1.194 17-Mar-2020 nicm

Ignore default-shell (and use /bin/sh) if it invalid not just if it is
tmux itself, also refuse to set the option to something invalid in the
first place. GitHub issue 2120.


# 1.193 12-Mar-2020 nicm

When the server socket is given by the user with -S, create it with
umask 177 instead of 117 because it may not be in a safe directory like
the default directory in /tmp. The user can chmod it more open after it
is created if they want.


# 1.192 28-Jan-2020 nicm

-V also needs to go in usage.


# 1.191 28-Jan-2020 nicm

Reduce a difference with portable tmux by adding the -V flag and
#{version} format; on OpenBSD these just report the OpenBSD version.


# 1.190 14-Oct-2019 nicm

Memory leaks, from Igor Wong in GitHub issue 1934.


Revision tags: OPENBSD_6_6_BASE
# 1.189 20-Jun-2019 nicm

Add a per-pane option set. Pane options inherit from window options (so
there should be no change to existing behaviour) and are set and shown
with set-option -p and show-options -p.

Change remain-on-exit and window-style/window-active-style to be pane
options (some others will be changed later).

This makes select-pane -P and -g unnecessary so no longer document them
(they still work) and no longer document set-window-option and
show-window-options in favour of set-option -w and show-options -w.


# 1.188 26-Apr-2019 nicm

Merge hooks into options and make each one an array option. This allows
multiple commands to be easily bound to one hook. set-hook and
show-hooks remain but they are now variants of set-option and
show-options. show-options now has a -H flag to show hooks (by default
they are not shown).


Revision tags: OPENBSD_6_5_BASE
# 1.187 22-Nov-2018 nicm

Do not use PWD unless it actually matches the real working directory.


Revision tags: OPENBSD_6_3_BASE OPENBSD_6_4_BASE
# 1.186 12-Jan-2018 nicm

Improve error message if creating socket parent directory fails, from
Thomas Adam for GitHub issue 1215.


# 1.185 01-Jan-2018 nicm

Prefer PWD for current directory if present in client, from Wei Zhao in
GitHub issue 1183.


Revision tags: OPENBSD_6_2_BASE
# 1.184 12-Jul-2017 nicm

Make shell_command a global like other stuff rather than making it an
exception and using callback argument.


# 1.183 03-Jul-2017 nicm

Try C.UTF-8 which is also a commonly useful locale on some platforms,
from Romain Francoise.


# 1.182 22-Apr-2017 nicm

Do not need getopt.h.


# 1.181 20-Apr-2017 nicm

Use fdforkpty() instead of our own unwrapped versions.


# 1.180 19-Apr-2017 nicm

Style nits and a missing cast.


# 1.179 16-Apr-2017 nicm

Memory leak, from David CARLIER.


Revision tags: OPENBSD_6_1_BASE
# 1.178 21-Mar-2017 nicm

Use uid_t for UID not u_int.


# 1.177 16-Feb-2017 nicm

Style nits.


# 1.176 23-Jan-2017 nicm

Open /dev/ptm before pledge() and save it to be used for PTMGET later
(this means inlining forkpty()).

ok deraadt


# 1.175 15-Jan-2017 nicm

Major tidy up and rework of options tree and set-option/show-options
commands this pushes more of the code into options.c and ties it more
closely to the options table rather than having an unnecessary
split. Also add support for array options (will be used later). Only
(intentional) user visible change is that show-options output is now
passed through vis(3) with VIS_DQ so quotes are escaped.


# 1.174 12-Jan-2017 nicm

Simplify appending to string options.


# 1.173 09-Dec-2016 nicm

Spacing nits.


# 1.172 11-Oct-2016 nicm

Add static in window-*.c and move some internal functions out of tmux.h.


# 1.171 10-Oct-2016 nicm

Loads more static, except for cmd-*.c and window-*.c.


Revision tags: OPENBSD_6_0_BASE
# 1.170 27-May-2016 nicm

Use getprogname() instead of __progname to make portability easier.


# 1.169 04-May-2016 nicm

Fix up a couple of long lines.


# 1.168 05-Mar-2016 nicm

If setlocale("en_US.UTF-8") succeeds, then don't do the check for UTF-8
locale since if it isn't UTF-8 the system is broken anyway. If it fails,
try "" and check for UTF-8 with nl_langinfo(CODESET) rather than
wcwidth(). Based on a diff from schwarze@, nl_langinfo also suggested by
stsp@.


# 1.167 05-Mar-2016 nicm

Although we always have en_US.UTF-8 on OpenBSD, some platforms do not,
so fall back to setlocale(LC_CTYPE, ""). tmux requires a UTF-8 locale,
so check with wcwidth() on a UTF-8 character after setlocale().


# 1.166 01-Mar-2016 nicm

Remove unused variables, from Michal Mazurek.


# 1.165 01-Mar-2016 nicm

Use system wcwidth() instead of carrying around UTF-8 width tables.


Revision tags: OPENBSD_5_9_BASE
# 1.164 19-Jan-2016 nicm

I no longer use my SourceForge address so replace it.


# 1.163 08-Dec-2015 nicm

Add hooks infrastructure, basic commands (set-hook, show-hooks) and a
couple of not very useful client hooks. This will eventually let
commands be run at various points and on notifications. Joint work with
Thomas Adam.


# 1.162 24-Nov-2015 nicm

Make environ_set va_args and use it to tidy up some calls. Also add a
missing word in manpage (from jmc).


# 1.161 24-Nov-2015 nicm

Shell command from -c doesn't have to be global, pass it as an argument.


# 1.160 24-Nov-2015 nicm

Tidy the code that works out the socket path, and just use the full path
in the global socket_path rather than copying it.


# 1.159 24-Nov-2015 nicm

Remove malloc_options DEBUG bit.


# 1.158 24-Nov-2015 nicm

Remove the -I part of show-messages which isn't really that useful; the
server start time can now be accessed with a new start_time format (use:
tmux display -p '#{t:start_time}')


# 1.157 24-Nov-2015 nicm

Make the log stuff a bit tidier with some helper functions.


# 1.156 22-Nov-2015 nicm

Add getpw to pledge, makes tmux work in YP environments, discovered by
matthieu, ok deraadt


# 1.155 20-Nov-2015 nicm

Instead of separate tables for different types of options, give each
option a scope type (server, session, window) in one table.


# 1.154 15-Nov-2015 nicm

Accidentally turned off pledge, turn it back on.


# 1.153 14-Nov-2015 nicm

Push stdout and stderr to clients more aggressively, and add an event to
continue if the send fails.


# 1.152 12-Nov-2015 nicm

tmux is UTF-8, so if $TMUX is set (tmux running in tmux), the client is
UTF-8. Also try to make the existing checks more readable.


# 1.151 12-Nov-2015 nicm

Nuke the utf8 and status-utf8 options and make tmux only a UTF-8
terminal. We still support non-UTF-8 terminals outside tmux, but inside
it is always UTF-8 (as when the utf8 and status-utf8 options were on).


# 1.150 11-Nov-2015 nicm

Drop mouse-utf8 option and always turn on UTF-8 mouse if the client says
it supports UTF-8.


# 1.149 28-Oct-2015 nicm

Like options, move the environ struct into environ.c.


# 1.148 27-Oct-2015 nicm

Move struct options into options.c.


# 1.147 27-Oct-2015 nicm

Break the common process set up, event loop and imsg dispatch code
between server and client out into a separate internal API. This will
make it easier to add another process.


# 1.146 25-Oct-2015 deraadt

Let's see if anyone screams about not being able to specify $TMPDIR
for their tmux sockets.

(Over the years, I have seen $TMPDIR set up worse than /tmp many times,
and don't know how this practice infected other parts of the system.
Nothing uses tmpdir(3), nor a huge-temporary-file program like sort.)
ok nicm


# 1.145 23-Oct-2015 nicm

tmux can call pledge() in main with large set and then reduce it
slightly in the server to "stdio rpath wpath cpath fattr unix recvfd
proc exec tty ps".


# 1.144 14-Sep-2015 nicm

Move tzset() from log_open to main.


# 1.143 03-Sep-2015 nicm

A couple of style nits.


# 1.142 01-Sep-2015 nicm

Work out config file when needed not at startup.


# 1.141 30-Aug-2015 nicm

Path from $TMUX does not need to be global anymore.


# 1.140 30-Aug-2015 nicm

Login shell can be a client flag, and move the exec code into client.c.


# 1.139 30-Aug-2015 nicm

Event base does not need to be global.


# 1.138 30-Aug-2015 nicm

Some style nits and dead assignments.


Revision tags: OPENBSD_5_8_BASE
# 1.137 20-Jul-2015 nicm

Add an option (history-file) for a file to save/restore command prompt
history, from Olof-Joachim Frahm.


# 1.136 04-Jun-2015 jmc

tweak SYNOPSIS and usage();


Revision tags: OPENBSD_5_7_BASE
# 1.135 19-Jan-2015 nicm

Make a tmux-%u directory under TMUX_TMPDIR, like TMPDIR.


# 1.134 19-Jan-2015 nicm

Only care about other permissions, allow group to be set.


# 1.133 19-Jan-2015 nicm

Remove unnecessary duplicate S_ISDIR check, from Dmitri Paduchikh.


# 1.132 20-Oct-2014 nicm

Tidy up some includes.


Revision tags: OPENBSD_5_6_BASE
# 1.131 17-Apr-2014 nicm

Remove the "info" message mechanism, this was only used for about five
mostly useless and annoying messages. Change those commands to silence
on success like all the others. Still accept the -q command line flag
and "quiet" server option for now.


# 1.130 31-Mar-2014 nicm

Remove log_debug2 as well and simplify log.c.


Revision tags: OPENBSD_5_5_BASE
# 1.129 16-Feb-2014 nicm

Leftovers from removing 88 colour support, from Theo Buehler.


# 1.128 15-Jan-2014 nicm

Do not attempt to read .tmux.conf if we can't figure out a home
directory, from Tiago Cunha.


# 1.127 09-Jan-2014 nicm

Three small changes from Tiago Cunha:

- Check for truncation when copying path.
- Don't need to use a temporary buffer in screen_set_title.
- Include strerror in output when connecting to server fails.


# 1.126 10-Oct-2013 nicm

We accidentally haven't been using $TMUX to work out the session for a
while and in fact it is less useful that using the client ttyname. So
don't bother and don't pass it from the client. If we need it in future
it is in c->environ.


# 1.125 10-Oct-2013 nicm

Alter how tmux handles the working directory to internally use file
descriptors rather than strings.

- Each session still has a current working directory.

- New sessions still get their working directory from the client that
created them or its attached session if any.

- New windows are created by default in the session working directory.

- The -c flag to new, neww, splitw allows the working directory to be
overridden.

- The -c flag to attach let's the session working directory be changed.

- The default-path option has been removed.

To get the equivalent to default-path '.', do:

bind c neww -c $PWD

To get the equivalent of default-path '~', do:

bind c neww -c ~

This also changes the client identify protocol to be a set of messages rather
than one as well as some other changes that should make it easier to make
backwards-compatible protocol changes in future.


# 1.124 10-Oct-2013 nicm

Merge IDENTIFY_* flags with CLIENT_* flags.


# 1.123 10-Oct-2013 nicm

Don't treat TMUX_TMPDIR as a potential file

The point of setting TMUX_TMPDIR is to then make any labels from -L go
to that directory. In the case of makesocketpath() with no TMUX_TMPDIR
set, would set both the path and the default socket to a file. The
checking of the permissions on the file worked fine in that case, but
when TMUX_TMPDIR is set, won't work on a directory.

This fixes the problem by ensuring the check on the permissions is
performed on directories only.

By Thomas Adam.


# 1.122 05-Oct-2013 nicm

Fix previous not to leak fd on failure, whoops.


# 1.121 05-Oct-2013 nicm

Use open(".")/fchdir() to save and restore current directory rather than
getcwd()/chdir().


Revision tags: OPENBSD_5_4_BASE
# 1.120 24-Apr-2013 nicm

Rename global configuration define.


# 1.119 11-Apr-2013 nicm

Call setlocale(LC_TIME) at startup.


# 1.118 27-Mar-2013 nicm

Add TMUX_TMPDIR variable to put the socket directory outside
TMPDIR. From Ben Boeckel.


# 1.117 27-Mar-2013 nicm

Remove tmux's (already minimal) 88 colour support. Such terminals are
few and unnecessary.


# 1.116 25-Mar-2013 nicm

Rename session idx to session id throughout and add $ prefix to targets
to use it, extended from a diff from George Nachman.


# 1.115 24-Mar-2013 nicm

Add a command queue to standardize and simplify commands that call other
commands and allow a command to block execution of subsequent
commands. This allows run-shell and if-shell to be synchronous which has
been much requested.

Each client has a default command queue and commands are consumed one at
a time from it. A command may suspend execution from the queue by
returning CMD_RETURN_WAIT and then resume it by calling cmd_continue() -
for example run-shell does this from the callback that is fired after
the job is freed.

When the command queue becomes empty, command clients are automatically
exited (unless attaching). A callback is also fired - this is used for
nested commands in, for example, if-shell which can block execution of
the client's cmdq until a new cmdq becomes empty.

Also merge all the old error/info/print functions together and lose the
old curclient/cmdclient distinction - a cmdq is bound to one client (or
none if in the configuration file), this is a command client if
c->session is NULL otherwise an attached client.


Revision tags: OPENBSD_5_3_BASE
# 1.114 27-Nov-2012 nicm

Correctly aggregate together errors from nested config files (with
source-file). Fix by Thomas Adam, reported by Sam Livingstone-Gray


# 1.113 26-Nov-2012 nicm

Call realpath earlier on the socket directory path rather than on the
socket file path because the latter may not exist yet and in that case
realpath is allowed to fail. From Romain Francoise.


Revision tags: OPENBSD_5_2_BASE
# 1.112 10-Jul-2012 nicm

xfree is not particularly helpful, remove it. From Thomas Adam.


# 1.111 18-Jun-2012 nicm

Add a skeleton mode to tmux (called "control mode") that let's tmux
commands be sent and output received on stdout. This can be used to
integrate with other terminal emulators and should allow some other
things to be made simpler later. More to come so doesn't do much yet and
deliberately not documented.


# 1.110 30-May-2012 nicm

Do not use stderr for log file and don't call log_close when not needed.


# 1.109 25-May-2012 nicm

Simplify logging and just fprintf(stderr, ...) for early errors.


Revision tags: OPENBSD_5_1_BASE
# 1.108 21-Jan-2012 nicm

Drop the ability to have a list of keys in the prefix in favour of two
separate options, prefix and prefix2. This simplifies the code and gets
rid the data options type which was only used for this one option.

Also add a -2 flag to send-prefix to send the secondary prefix key,
fixing a cause of minor irritation.

People who want three prefix keys are out of luck :-).


# 1.107 23-Oct-2011 nicm

Try to resolve relative paths for loadb and saveb (first using client
working directory if any then default-path or session wd).


# 1.106 23-Oct-2011 nicm

Ignore LC_ALL and LC_CTYPE if they are empty as well as unset.


# 1.105 25-Sep-2011 nicm

Reject $SHELL if it is not a full path.


Revision tags: OPENBSD_5_0_BASE
# 1.104 04-Mar-2011 nicm

Two fixes by Micah Cowan: make mouse work properly beyond >127 on signed
char architectures and properly parse $TMUX by stopping the socket path
at the first comma.


Revision tags: OPENBSD_4_9_BASE
# 1.103 23-Jan-2011 nicm

Set $TMUX without the session when background jobs are run.


# 1.102 12-Jan-2011 nicm

Use TMPDIR if set, from Han Boetes.


# 1.101 08-Jan-2011 nicm

Move all calls to fcntl(...O_NONBLOCK) into a function and clear the
flag on the stdio file descriptors before closing them (fixes things
like "tmux ls && cat").


# 1.100 03-Jan-2011 nicm

Support for UTF-8 mouse input (\033[1005h). This was added in xterm 262
and supports larger terminals than the older way.

If the new mouse-utf8 option is on, UTF-8 mouse input is enabled for all
UTF-8 terminals. The option defaults to on if LANG etc are set in the
same manner as the utf8 option.

With help and based on code from hsim at gmx.li.


# 1.99 01-Jan-2011 nicm

Move the user-visible parts of all options (names, types, limit, default
values) together into one set of tables in options-table.c. Also clean
up and simplify cmd-set-options.c and move a common print function into
option-table.c.


# 1.98 30-Dec-2010 nicm

Change from a per-session stack of buffers to one global stack which is
much more convenient and also simplifies lot of code. This renders
copy-buffer useless and makes buffer-limit now a server option.

By Tiago Cunha.


# 1.97 19-Dec-2010 nicm

Add other-pane-height and other-pane-width options, allowing the width
or height of the smaller panes in the main-horizontal and main-vertical
layouts to be set. Mostly from David Goodlad.


# 1.96 08-Dec-2010 nicm

In the built-in layouts, distribute the panes more evenly. Set the
default value of main-pane-width to 80, rather than 81. By Micah Cowan.


# 1.95 06-Dec-2010 nicm

Add an option to alert (monitor) for silence (lack of activity) in a
window. From Thomas Adam.


# 1.94 29-Nov-2010 nicm

If VISUAL or EDITOR contains "vi", configure mode-keys and status-keys
to vi.

Based on a diff from martynas@, previously requested by a couple of
other people.


# 1.93 11-Nov-2010 nicm

Add XAUTHORITY to update-environment, requested by Andreas Kloeckner.


# 1.92 18-Oct-2010 nicm

Merge the before and after attach client code into one in client.c
(instead of two in tmux.c and client.c).


# 1.91 16-Oct-2010 nicm

Make stdio blocking again before calling shell command with -c.


# 1.90 16-Oct-2010 nicm

Trying to set FD_CLOEXEC on every fd is a lost cause, just use
closefrom() before exec.


# 1.89 14-Oct-2010 nicm

Use an explicit event rather than event_once for the main event so it
can be removed when the client becomes ready.


# 1.88 26-Sep-2010 nicm

Two new options:

- server option "exit-unattached" makes the server exit when no clients
are attached, even if sessions are present;

- session option "destroy-unattached" destroys a session once no clients
are attached to it.

These are useful for preventing tmux remaining in the background where
it is undesirable and when using tmux as a login shell to keep a limit
on new sessions.


# 1.87 19-Aug-2010 nicm

Do not call event_del() for signals after fork(), just use sigaction()
directly instead - calling libevent functions after fork() w/o
event_reinit() is a bad idea, even if in this case it was harmless.


Revision tags: OPENBSD_4_8_BASE
# 1.86 04-Aug-2010 deraadt

switch back to kqueue for now, since (a) kqueue has been fixed to deal
with strange devices and (b) since there appears to be a bull in the
poll code in libevent as well...
requested by nicm who is away


# 1.85 24-Jul-2010 nicm

kqueue(2) is currently broken when used with /dev/null and a few other
devices.

An upcoming fix for some problems with the client stdout/stderr handling
relies on it working, so make tmux force libevent to use poll(2) via
EVENT_NOKQUEUE, until we have fixed kqueue.


# 1.84 11-Jul-2010 nicm

Return the command client return code with MSG_EXIT now that MSG_ERROR and
MSG_PRINT are unused.

New clients should be compatible with old tmux servers but vice versa may print
an error.


# 1.83 28-Jun-2010 nicm

Send all three of stdin, stdout, stderr from the client to the server, so that
commands can directly make use of them. This means that load-buffer and
save-buffer can have "-" as the file to read from stdin or write to stdout.

This is a protocol version bump so the tmux server will need to be restarted
after upgrade (or an older client used).


# 1.82 27-Jun-2010 nicm

Store the current working directory in the session, change the default-path
option to default to empty and make that mean that the stored session CWD is
used.


# 1.81 27-Jun-2010 nicm

New option, detach-on-destroy, to set what happens to a client when the session
it is attached to is destroyed. If on (the default), it is detached; if off, it
is switched to the most recently active session.


# 1.80 26-Jun-2010 nicm

Setting the cmdlist pointer in the bind-key to NULL to prevent it being freed
after the command is executing is bogus because it may still be needed if the
same command is going to be executed again (for example if you "bind-key a
bind-key b ..."). Making a copy is hard, so instead add a reference count to
the cmd_list.

While here, also print bind-key -n and the rest of the flags properly.

Fixes problem reported by mcbride@.


# 1.79 14-May-2010 nicm

Colour+attribute options for status line alerts, from Alex Alexander.


# 1.78 04-May-2010 nicm

Put this back in with the initialisation in the right order.


# 1.77 04-May-2010 nicm

Revert last change, it appears to be broken somehow.


# 1.76 03-May-2010 nicm

Make signal handler setup/teardown two common functions instead of six,
and reset SIGCHLD after fork to fix problems with some shells. From
Romain Francois.


# 1.75 28-Apr-2010 nicm

Make the active pane border have a green foreground instead of
background by default.


# 1.74 18-Apr-2010 nicm

Catch SIGCHLD to avoid a zombie, from patrick keshishian.


Revision tags: OPENBSD_4_7_BASE
# 1.73 22-Feb-2010 nicm

Option to set the characters considered word separators in copy mode, from
Micah Cowan.


# 1.72 08-Feb-2010 nicm

Add an option to disable the smcup/rmcup alternate screen behaviour inside
tmux. From clemens fischer.


# 1.71 06-Feb-2010 nicm

Change nested check to compare server socket path rather than just assuming
that if $TMUX is set it is nested. From Micah Cowan.


# 1.70 06-Feb-2010 nicm

Clean up $TMUX parsing, from Micah Cowan, tweaked by me.


# 1.69 06-Feb-2010 nicm

Instead of bailing out on the first configuration file error, carry on,
collecting all the errors, then start with the active window in more mode
displaying them.


# 1.68 04-Feb-2010 nicm

Read the path from $TMUX if it is present and -L and -S are not given. Based on
a diff from Micah Cowan.


# 1.67 04-Feb-2010 nicm

Option to display the active pane in a different colour with the display-panes
command. From Paul Hoffman, thanks.


# 1.66 03-Jan-2010 nicm

Options to set the colour of the pane borders, with different colours for the
active pane.


# 1.65 14-Dec-2009 nicm

New server option, escape-time, to set the timeout used to detect if escapes
are alone or part of a function key or meta sequence.


# 1.64 11-Dec-2009 nicm

Use quiet variable, and add missing sentinel to options array.


# 1.63 10-Dec-2009 nicm

Add "server options" which are server-wide and not bound to a session or
window. Set and displayed with "set -s" and "show -s".

Currently the only option is "quiet" (like command-line -q, allowing it to be
set from .tmux.conf), but others will come along.


# 1.62 03-Dec-2009 nicm

Massive spaces->tabs and trailing whitespace cleanup, hopefully for the last
time now I've configured emacs to make them displayed in really annoying
colours...


# 1.61 26-Nov-2009 nicm

Remove a couple of unused arguments where possible, and add /* ARGSUSED */ to
the rest to reduce lint output.


# 1.60 19-Nov-2009 nicm

Two new options, window-status-format and window-status-current-format, which
allow the format of each window in the status line window list to be controlled
using similar # sequences as status-left/right.

This diff also moves part of the way towards UTF-8 support in window names but
it isn't quite there yet.


# 1.59 19-Nov-2009 nicm

Revert to xterm-keys off by default. It was on as an experiment to see if the
option could be removed, but it affects vi, so we have to keep the option, and
a conservative default is better.


# 1.58 18-Nov-2009 nicm

Add a per-client log of status line messages displayed while that client
exists. A new message-limit session option sets the maximum number of entries
and a command, show-messages, shows the log (bound to ~ by default).

This (and prompt history) might be better as a single global log but until
there are global options it is easier for them to be per client.


# 1.57 10-Nov-2009 nicm

There is no real standard for modifier plus function keys. Previously, tmux
output some from rxvt but in other ways did the same as xterm or other
terminals, but this is a bit inconsistent.

xterm's method is fairly sensible and we already support it (xterm-keys), so
enable it by default instead.


# 1.56 04-Nov-2009 nicm

A couple of minor cosmetic changes.


# 1.55 04-Nov-2009 nicm

Initial changes to move tmux to libevent.

This moves the client-side loops are pretty much fully over to event-based only
(tmux.c and client.c) but server-side (server.c and friends) treats libevent as
a sort of clever poll, waking up after every event to run various things.

Moving the server stuff over to bufferevents and timers and so on will come
later.


# 1.54 04-Nov-2009 nicm

Change declaration and use of malloc_options to be more standard, from Tim van
der Molen.


# 1.53 26-Oct-2009 deraadt

tabs are better; ok nicm


# 1.52 25-Oct-2009 nicm

Remove the -d flag to tmux and just use op/AX to detect default colours.

Irritatingly, although op can be used to tell if a terminal supports default
colours, it can't be used to set them because in some terminfo descriptions it
resets attributes as a side-effect (acts as sgr0) and in others it doesn't, so
it is not possible to determine reliably what the terminal state will be
afterwards. So if AX is missing and op is present, tmux just sends sgr0.

Anyone using -d for a terminal who finds they actually needed it can replace it
using terminal-overrides, but please let me know as it is probably an omission
from terminfo.


# 1.51 22-Oct-2009 nicm

Merge prepare_cmd into main as it is short and only called once.


# 1.50 21-Oct-2009 nicm

Client tidying: get rid of client_ctx struct in favour of two variables in
client.c, and move the functions in client-fn.c into other files.


# 1.49 10-Oct-2009 nicm

New option, mouse-select-pane. If on, the mouse may be used to select the
current pane.

Suggested by sthen@ and also by someone else ages ago who I have forgotten.


# 1.48 10-Oct-2009 nicm

Support for individual session idle time locking. May be enabled by turning off
the lock-server option (it is on by default). When this is off, each session
locks when it has been idle for the lock-after-time setting. When on, the
entire server locks when ALL sessions have been idle for their individual
lock-after-time settings.

This replaces one global-only option (lock-after-time) with another
(lock-server), but the default behaviour is usually preferable so there don't
seem to be many alternatives.

Diff/idea largely from Thomas Adam, tweaked by me.


# 1.47 09-Oct-2009 nicm

Add a simple synchronize-panes window option: when set, all input to any pane
that is part of the window is also sent to all other panes in the same
window. Suggested by several, most recently Tomasz Pajor.


# 1.46 23-Sep-2009 nicm

Support -c like sh(1) to execute a command, useful when tmux is a login
shell. Suggested by halex@.

This includes another protocol version increase (the last for now) so again
restart the tmux server before upgrading.


# 1.45 23-Sep-2009 nicm

Remove the internal tmux locking and instead detach each client and run the
command specified by a new option "lock-command" (by default "lock -np") in
each client.

This means each terminal has to be unlocked individually but simplifies the
code and allows the system password to be used to unlock.

Note that the set-password command is gone, so it will need to be removed from
configuration files, and the -U command line flag has been removed.

This is the third protocol version change so again it is best to stop the tmux
server before upgrading.


# 1.44 22-Sep-2009 nicm

Permit multiple prefix keys to be defined, separated by commas, for example:

set -g prefix ^a,^b

Any key in the list acts as the prefix. The send-prefix command always sends
the first key in the list.


# 1.43 18-Sep-2009 nicm

New option, set-titles-string, to allow the window title to be specified (as
for status-left/right) if set-titles is on. Also only update the title when the
status line is being redrawn.


# 1.42 04-Sep-2009 nicm

Tidy main and make it a bit easier to read.


# 1.41 02-Sep-2009 nicm

Accept -l to make it easier for people who use tmux as a login shell to use
$SHELL. Originally from martynas@, tweaked by me.


# 1.40 02-Sep-2009 nicm

When incorrect passwords are entered, behave similarly to login(1) and backoff
for a bit. Based on a diff from martynas@.


# 1.39 01-Sep-2009 nicm

When using tmux as a login shell, there is currently no way to specify a shell
to be used as a login shell inside tmux, so add a default-shell session option.
This sets the shell invoked as a login shell when the default-command option is
empty.

The default option value is whichever of $SHELL, getpwuid(getuid())'s pw_shell
or /bin/sh is valid first.

Based on a diff from martynas@, changed by me to be a session option rather
than a window option.


# 1.38 01-Sep-2009 nicm

Use "Password:" with no space for password prompts and don't display a *s for
the password, like pretty much everything else. From martynas@ with minor
tweaks by me.


# 1.37 01-Sep-2009 nicm

Sort cases same as getopt argument, from martynas.


# 1.36 31-Aug-2009 nicm

Add a new display-panes command, with two options (display-panes-colour and
display-panes-time), which displays a visual indication of the number of each
pane.


# 1.35 23-Aug-2009 nicm

Add some other obvious variables to update-environment (WINDOWID SSH_ASKPASS
SSH_AUTH_SOCK SSH_AGENT_PID SSH_CONNECTION) so they are updated in the session
environment on new/attach.


# 1.34 13-Aug-2009 nicm

Disable mode-mouse (mouse in copy/choice mode) by default as it isn't very
useful at the moment and causes confusion.


# 1.33 13-Aug-2009 nicm

Add a base-index session option to specify the first index checked when looking
for an index for a new window.


# 1.32 12-Aug-2009 nicm

When started as the shell, __progname contains a leading -, so hardcode "tmux"
for socket path and log files, and strip it when working out the shell.


# 1.31 11-Aug-2009 nicm

Switch tmux to use imsg. This is the last major change to make the
client-server protocol more resilient and make the protocol versioning work
properly. In future, the only things requiring a protocol version bump will be
changes in the message structs, and (when both client and server have this
change) mixing different versions should nicely report an error message.

As a side effect this also makes the code tidier, fixes a problem with the way
errors reported during server startup were handled, and supports fd passing
(which will be used in future).

Looked over by eric@, thanks.

Please note that mixing a client with this change with an older server or vice
versa may cause tmux to crash or hang - tmux should be completely exited before
upgrading.


# 1.30 10-Aug-2009 nicm

No arguments are the same as new-session and this requires the environment to
be sent, so set that flag too when argc == 0.


# 1.29 08-Aug-2009 nicm

Infrastructure and commands to manage the environment for processes started
within tmux.

There is a global environment, copied from the external environment when the
server is started and each sesssion has an (initially empty) session
environment which overrides it.

New commands set-environment and show-environment manipulate or display the
environments.

A new session option, update-environment, is a space-separated list of
variables which are updated from the external environment into the session
environment every time a new session is created - the default is DISPLAY.


# 1.28 08-Aug-2009 nicm

Options to set the colours and attributes for status-left/-right. From Thomas
Adam, thanks.


# 1.27 05-Aug-2009 nicm

If colours are not supported by the terminal, try to emulate a coloured
background by setting or clearing the reverse attribute.

This makes a few applications which don't use the reverse attribute themselves
a little happier, and allows the status, message and mode options to have
default attributes and fg/bg options that work as expected when set as reverse.


# 1.26 04-Aug-2009 nicm

Check for "UTF8" as well as "UTF-8" in LANG etc as it seems this may also
appear.


# 1.25 03-Aug-2009 nicm

Add a terminal-overrides session option allowing individual terminfo(5) entries
to be overridden. The 88col/256col checks are now moved into the default
setting and out of the code.

Also remove a couple of old workarounds for xterm and rxvt which are no longer
necessary (tmux can emulate them if missing).


# 1.24 30-Jul-2009 nicm

Add a mode-mouse option to prevent tmux taking over the mouse in choice or copy
modes.


# 1.23 29-Jul-2009 nicm

Rename struct hdrtype to msgtype which is a better name and can be used even
when struct hdr disappears.


# 1.22 29-Jul-2009 nicm

Taking account of the "s, 22 not 24 is the maximum length of #T in status-right
to prevent the date being cut off.


# 1.21 26-Jul-2009 nicm

Make all messages sent between the client and server fixed size.

This is the first of two changes to make the protocol more resilient and less
sensitive to other changes in the code, particularly with commands. The client
now packs argv into a buffer and sends it to the server for parsing, rather
than doing it itself and sending the parsed command data.

As a side-effect this also removes a lot of now-unused command marshalling
code.

Mixing a server without this change and a client with or vice versa will cause
tmux to hang or crash, please ensure that tmux is entirely killed before
upgrading.


# 1.20 22-Jul-2009 nicm

Pass a set of flags into client_init rather than just a start_server
variable. Only one flag now but more to come later.


# 1.19 20-Jul-2009 nicm

Display the number of failed password attempts (if any) when the server is
locked. From Tom Doherty.


# 1.18 20-Jul-2009 nicm

Add a status-justify option to allow the window list in the status line to be
positioned at the left, centre, or right.


# 1.17 20-Jul-2009 nicm

New options, window-status-current-{fg,bg,attr}, to set the fg, bg and
attributes with which the current window is shown in the status line. From
Johan Friis, thanks.


# 1.16 18-Jul-2009 nicm

Add three new session options: visual-activity, visual-bell, visual-content. If
these are enabled (and the monitor-activity, bell-actio and monitor-content
options are configurated appropriately), when activity, a bell, or content is
detected, a message is shown.

Also tidy up the bell/activity/content code in server.c slightly and fix a
couple of errors.


# 1.15 17-Jul-2009 nicm

If -u is specified or UTF-8 is otherwise detected when the server is started,
enable the utf8 and status-utf8 optons. While here, note in the man page that
the server is started with the first session and exits when none remain.


# 1.14 10-Jul-2009 nicm

Add a default-terminal option to set the starting value of $TERM in new
windows.

This is "screen" by default and must be either that or something closely
related. This does makes it easier to customise it if necessary.


# 1.13 08-Jul-2009 nicm

Just appending -l to $SHELL to create a login shell is wrong: -l is not POSIX,
and some people may use shells which do not support it. Instead, make an empty
default-command option mean a login shell, and fork it with a - in argv[0]
which is the method used by login(1).

Also fix the automatic-rename code to handle this correctly and to strip a
leading - if present.


# 1.12 07-Jul-2009 nicm

Rename the global options variables to be shorter and to make session options
clear. No functional change, getting this out of the way to make later options
changes easier.


Revision tags: OPENBSD_4_6_BASE
# 1.11 25-Jun-2009 nicm

If getcwd() fails, use the user's home directory, or /, instead of failing with
an error.


# 1.10 25-Jun-2009 nicm

Remove error about using -L and -S together which was never displayed as
logging wasn't yet enabled, was unnecessary, and contradicted the man page
which says using -S will cause -L to be ignored.


# 1.9 23-Jun-2009 nicm

LC_ALL overrides LC_CTYPE and LANG. Comment was correct but the code
wrong. Pointed out by Hannah Schroeter, thanks.


# 1.8 05-Jun-2009 nicm

Check the first of LC_CTYPE, LC_ALL and LANG, rather than just the last, when
trying to decide about UTF-8, and use strcasestr. Reported by Geert Hendrickx.


# 1.7 04-Jun-2009 nicm

Zero the password given to -U in the client as well.


# 1.6 03-Jun-2009 nicm

Do not set the window title by default (make set-titles option default to off),
wiping over the title is rude and annoying. Agreed by several.


# 1.5 03-Jun-2009 nicm

New session option, status-utf8, to control the interpretation of top-bit-set
characters in status-left and status-right (if on, they are treated as UTF-8;
otherwise passed through).


# 1.4 02-Jun-2009 sobrado

remove unused flag; while here, make usage's output fit on 80-column displays.


# 1.3 02-Jun-2009 pyr

spawn login shells by default, adapt manpage bits as well.
ok nicm@


# 1.2 02-Jun-2009 ray

Don't leak memory if multiple -f flags are given.

OK nicm@


# 1.1 01-Jun-2009 nicm

Import tmux, a terminal multiplexor allowing (among other things) a single
terminal to be switched between several different windows and programs
displayed on one terminal be detached from one terminal and moved to another.

ok deraadt pirofti


# 1.209 23-Aug-2021 nicm

Fix a few memory leaks.


# 1.208 06-Jul-2021 nicm

Improve error reporting when the tmux /tmp directory cannot be created
or used, GitHub issue 2765 from Uwe Kleine-Koenig.


# 1.207 10-Jun-2021 nicm

Do not expand the file given with -f so it can contain :s.


Revision tags: OPENBSD_6_9_BASE
# 1.206 22-Feb-2021 nicm

expand_paths needs the global environment to be set up, do that first.


# 1.205 22-Feb-2021 nicm

Move config file path expansion much earlier, keep the list of paths
around rather than freeing later, and add a config_files format variable
containing it. Suggested by kn@ a while back.


# 1.204 17-Jan-2021 nicm

Add -N flag to never start server even if command would normally do so,
GitHub issue 2523.


Revision tags: OPENBSD_6_8_BASE
# 1.203 22-Sep-2020 nicm

Fix warnings on some platforms with %llx and add a new message to handle
64-bit client flags.


# 1.202 02-Jun-2020 nicm

Use CLOCK_MONOTONIC for timer measurement and add a timestamp to control
mode %output blocks.


# 1.201 16-May-2020 nicm

Add a -D flag to ask tmux not to daemonize, useful both for running a
debugger (lldb does not have follow-fork-mode) and for running with a
managed supervisor init system. GitHub issue 2190.


# 1.200 16-May-2020 nicm

Add 'e' key in buffer mode to open the buffer in an editor.


# 1.199 16-May-2020 nicm

Build list of paths and weed out duplicates before loading configs, and
add TMUX_SOCK like TMUX_PATH for the socket directory.


Revision tags: OPENBSD_6_7_BASE
# 1.198 20-Apr-2020 nicm

Tidy up the terminal detection and feature code and add named sets of
terminal features, each of which are defined in one place and map to a
builtin set of terminfo(5) capabilities. Features can be specified based
on TERM with a new terminal-features option or with the -T flag when
running tmux. tmux will also detect a few common terminals from the DA
and DSR responses.

This is intended to make it easier to configure tmux's use of
terminfo(5) even in the presence of outdated ncurses(3) or terminfo(5)
databases or for features which do not yet have a terminfo(5) entry.
Instead of having to grok terminfo(5) capability names and what they
should be set to in the terminal-overrides option, the user can
hopefully just give tmux a feature name and let it do the right thing.

The terminal-overrides option remains both for backwards compatibility
and to allow tweaks of individual capabilities.

tmux already did much of this already, this makes it tidier and simpler
to configure.


# 1.197 16-Apr-2020 nicm

Show signal name when process exits rather than number.


# 1.196 09-Apr-2020 nicm

More style nits.


# 1.195 31-Mar-2020 nicm

Add a way to mark environment variables as "hidden" so they can be used
by tmux but are not passed into the environment of new panes.


# 1.194 17-Mar-2020 nicm

Ignore default-shell (and use /bin/sh) if it invalid not just if it is
tmux itself, also refuse to set the option to something invalid in the
first place. GitHub issue 2120.


# 1.193 12-Mar-2020 nicm

When the server socket is given by the user with -S, create it with
umask 177 instead of 117 because it may not be in a safe directory like
the default directory in /tmp. The user can chmod it more open after it
is created if they want.


# 1.192 28-Jan-2020 nicm

-V also needs to go in usage.


# 1.191 28-Jan-2020 nicm

Reduce a difference with portable tmux by adding the -V flag and
#{version} format; on OpenBSD these just report the OpenBSD version.


# 1.190 14-Oct-2019 nicm

Memory leaks, from Igor Wong in GitHub issue 1934.


Revision tags: OPENBSD_6_6_BASE
# 1.189 20-Jun-2019 nicm

Add a per-pane option set. Pane options inherit from window options (so
there should be no change to existing behaviour) and are set and shown
with set-option -p and show-options -p.

Change remain-on-exit and window-style/window-active-style to be pane
options (some others will be changed later).

This makes select-pane -P and -g unnecessary so no longer document them
(they still work) and no longer document set-window-option and
show-window-options in favour of set-option -w and show-options -w.


# 1.188 26-Apr-2019 nicm

Merge hooks into options and make each one an array option. This allows
multiple commands to be easily bound to one hook. set-hook and
show-hooks remain but they are now variants of set-option and
show-options. show-options now has a -H flag to show hooks (by default
they are not shown).


Revision tags: OPENBSD_6_5_BASE
# 1.187 22-Nov-2018 nicm

Do not use PWD unless it actually matches the real working directory.


Revision tags: OPENBSD_6_3_BASE OPENBSD_6_4_BASE
# 1.186 12-Jan-2018 nicm

Improve error message if creating socket parent directory fails, from
Thomas Adam for GitHub issue 1215.


# 1.185 01-Jan-2018 nicm

Prefer PWD for current directory if present in client, from Wei Zhao in
GitHub issue 1183.


Revision tags: OPENBSD_6_2_BASE
# 1.184 12-Jul-2017 nicm

Make shell_command a global like other stuff rather than making it an
exception and using callback argument.


# 1.183 03-Jul-2017 nicm

Try C.UTF-8 which is also a commonly useful locale on some platforms,
from Romain Francoise.


# 1.182 22-Apr-2017 nicm

Do not need getopt.h.


# 1.181 20-Apr-2017 nicm

Use fdforkpty() instead of our own unwrapped versions.


# 1.180 19-Apr-2017 nicm

Style nits and a missing cast.


# 1.179 16-Apr-2017 nicm

Memory leak, from David CARLIER.


Revision tags: OPENBSD_6_1_BASE
# 1.178 21-Mar-2017 nicm

Use uid_t for UID not u_int.


# 1.177 16-Feb-2017 nicm

Style nits.


# 1.176 23-Jan-2017 nicm

Open /dev/ptm before pledge() and save it to be used for PTMGET later
(this means inlining forkpty()).

ok deraadt


# 1.175 15-Jan-2017 nicm

Major tidy up and rework of options tree and set-option/show-options
commands this pushes more of the code into options.c and ties it more
closely to the options table rather than having an unnecessary
split. Also add support for array options (will be used later). Only
(intentional) user visible change is that show-options output is now
passed through vis(3) with VIS_DQ so quotes are escaped.


# 1.174 12-Jan-2017 nicm

Simplify appending to string options.


# 1.173 09-Dec-2016 nicm

Spacing nits.


# 1.172 11-Oct-2016 nicm

Add static in window-*.c and move some internal functions out of tmux.h.


# 1.171 10-Oct-2016 nicm

Loads more static, except for cmd-*.c and window-*.c.


Revision tags: OPENBSD_6_0_BASE
# 1.170 27-May-2016 nicm

Use getprogname() instead of __progname to make portability easier.


# 1.169 04-May-2016 nicm

Fix up a couple of long lines.


# 1.168 05-Mar-2016 nicm

If setlocale("en_US.UTF-8") succeeds, then don't do the check for UTF-8
locale since if it isn't UTF-8 the system is broken anyway. If it fails,
try "" and check for UTF-8 with nl_langinfo(CODESET) rather than
wcwidth(). Based on a diff from schwarze@, nl_langinfo also suggested by
stsp@.


# 1.167 05-Mar-2016 nicm

Although we always have en_US.UTF-8 on OpenBSD, some platforms do not,
so fall back to setlocale(LC_CTYPE, ""). tmux requires a UTF-8 locale,
so check with wcwidth() on a UTF-8 character after setlocale().


# 1.166 01-Mar-2016 nicm

Remove unused variables, from Michal Mazurek.


# 1.165 01-Mar-2016 nicm

Use system wcwidth() instead of carrying around UTF-8 width tables.


Revision tags: OPENBSD_5_9_BASE
# 1.164 19-Jan-2016 nicm

I no longer use my SourceForge address so replace it.


# 1.163 08-Dec-2015 nicm

Add hooks infrastructure, basic commands (set-hook, show-hooks) and a
couple of not very useful client hooks. This will eventually let
commands be run at various points and on notifications. Joint work with
Thomas Adam.


# 1.162 24-Nov-2015 nicm

Make environ_set va_args and use it to tidy up some calls. Also add a
missing word in manpage (from jmc).


# 1.161 24-Nov-2015 nicm

Shell command from -c doesn't have to be global, pass it as an argument.


# 1.160 24-Nov-2015 nicm

Tidy the code that works out the socket path, and just use the full path
in the global socket_path rather than copying it.


# 1.159 24-Nov-2015 nicm

Remove malloc_options DEBUG bit.


# 1.158 24-Nov-2015 nicm

Remove the -I part of show-messages which isn't really that useful; the
server start time can now be accessed with a new start_time format (use:
tmux display -p '#{t:start_time}')


# 1.157 24-Nov-2015 nicm

Make the log stuff a bit tidier with some helper functions.


# 1.156 22-Nov-2015 nicm

Add getpw to pledge, makes tmux work in YP environments, discovered by
matthieu, ok deraadt


# 1.155 20-Nov-2015 nicm

Instead of separate tables for different types of options, give each
option a scope type (server, session, window) in one table.


# 1.154 15-Nov-2015 nicm

Accidentally turned off pledge, turn it back on.


# 1.153 14-Nov-2015 nicm

Push stdout and stderr to clients more aggressively, and add an event to
continue if the send fails.


# 1.152 12-Nov-2015 nicm

tmux is UTF-8, so if $TMUX is set (tmux running in tmux), the client is
UTF-8. Also try to make the existing checks more readable.


# 1.151 12-Nov-2015 nicm

Nuke the utf8 and status-utf8 options and make tmux only a UTF-8
terminal. We still support non-UTF-8 terminals outside tmux, but inside
it is always UTF-8 (as when the utf8 and status-utf8 options were on).


# 1.150 11-Nov-2015 nicm

Drop mouse-utf8 option and always turn on UTF-8 mouse if the client says
it supports UTF-8.


# 1.149 28-Oct-2015 nicm

Like options, move the environ struct into environ.c.


# 1.148 27-Oct-2015 nicm

Move struct options into options.c.


# 1.147 27-Oct-2015 nicm

Break the common process set up, event loop and imsg dispatch code
between server and client out into a separate internal API. This will
make it easier to add another process.


# 1.146 25-Oct-2015 deraadt

Let's see if anyone screams about not being able to specify $TMPDIR
for their tmux sockets.

(Over the years, I have seen $TMPDIR set up worse than /tmp many times,
and don't know how this practice infected other parts of the system.
Nothing uses tmpdir(3), nor a huge-temporary-file program like sort.)
ok nicm


# 1.145 23-Oct-2015 nicm

tmux can call pledge() in main with large set and then reduce it
slightly in the server to "stdio rpath wpath cpath fattr unix recvfd
proc exec tty ps".


# 1.144 14-Sep-2015 nicm

Move tzset() from log_open to main.


# 1.143 03-Sep-2015 nicm

A couple of style nits.


# 1.142 01-Sep-2015 nicm

Work out config file when needed not at startup.


# 1.141 30-Aug-2015 nicm

Path from $TMUX does not need to be global anymore.


# 1.140 30-Aug-2015 nicm

Login shell can be a client flag, and move the exec code into client.c.


# 1.139 30-Aug-2015 nicm

Event base does not need to be global.


# 1.138 30-Aug-2015 nicm

Some style nits and dead assignments.


Revision tags: OPENBSD_5_8_BASE
# 1.137 20-Jul-2015 nicm

Add an option (history-file) for a file to save/restore command prompt
history, from Olof-Joachim Frahm.


# 1.136 04-Jun-2015 jmc

tweak SYNOPSIS and usage();


Revision tags: OPENBSD_5_7_BASE
# 1.135 19-Jan-2015 nicm

Make a tmux-%u directory under TMUX_TMPDIR, like TMPDIR.


# 1.134 19-Jan-2015 nicm

Only care about other permissions, allow group to be set.


# 1.133 19-Jan-2015 nicm

Remove unnecessary duplicate S_ISDIR check, from Dmitri Paduchikh.


# 1.132 20-Oct-2014 nicm

Tidy up some includes.


Revision tags: OPENBSD_5_6_BASE
# 1.131 17-Apr-2014 nicm

Remove the "info" message mechanism, this was only used for about five
mostly useless and annoying messages. Change those commands to silence
on success like all the others. Still accept the -q command line flag
and "quiet" server option for now.


# 1.130 31-Mar-2014 nicm

Remove log_debug2 as well and simplify log.c.


Revision tags: OPENBSD_5_5_BASE
# 1.129 16-Feb-2014 nicm

Leftovers from removing 88 colour support, from Theo Buehler.


# 1.128 15-Jan-2014 nicm

Do not attempt to read .tmux.conf if we can't figure out a home
directory, from Tiago Cunha.


# 1.127 09-Jan-2014 nicm

Three small changes from Tiago Cunha:

- Check for truncation when copying path.
- Don't need to use a temporary buffer in screen_set_title.
- Include strerror in output when connecting to server fails.


# 1.126 10-Oct-2013 nicm

We accidentally haven't been using $TMUX to work out the session for a
while and in fact it is less useful that using the client ttyname. So
don't bother and don't pass it from the client. If we need it in future
it is in c->environ.


# 1.125 10-Oct-2013 nicm

Alter how tmux handles the working directory to internally use file
descriptors rather than strings.

- Each session still has a current working directory.

- New sessions still get their working directory from the client that
created them or its attached session if any.

- New windows are created by default in the session working directory.

- The -c flag to new, neww, splitw allows the working directory to be
overridden.

- The -c flag to attach let's the session working directory be changed.

- The default-path option has been removed.

To get the equivalent to default-path '.', do:

bind c neww -c $PWD

To get the equivalent of default-path '~', do:

bind c neww -c ~

This also changes the client identify protocol to be a set of messages rather
than one as well as some other changes that should make it easier to make
backwards-compatible protocol changes in future.


# 1.124 10-Oct-2013 nicm

Merge IDENTIFY_* flags with CLIENT_* flags.


# 1.123 10-Oct-2013 nicm

Don't treat TMUX_TMPDIR as a potential file

The point of setting TMUX_TMPDIR is to then make any labels from -L go
to that directory. In the case of makesocketpath() with no TMUX_TMPDIR
set, would set both the path and the default socket to a file. The
checking of the permissions on the file worked fine in that case, but
when TMUX_TMPDIR is set, won't work on a directory.

This fixes the problem by ensuring the check on the permissions is
performed on directories only.

By Thomas Adam.


# 1.122 05-Oct-2013 nicm

Fix previous not to leak fd on failure, whoops.


# 1.121 05-Oct-2013 nicm

Use open(".")/fchdir() to save and restore current directory rather than
getcwd()/chdir().


Revision tags: OPENBSD_5_4_BASE
# 1.120 24-Apr-2013 nicm

Rename global configuration define.


# 1.119 11-Apr-2013 nicm

Call setlocale(LC_TIME) at startup.


# 1.118 27-Mar-2013 nicm

Add TMUX_TMPDIR variable to put the socket directory outside
TMPDIR. From Ben Boeckel.


# 1.117 27-Mar-2013 nicm

Remove tmux's (already minimal) 88 colour support. Such terminals are
few and unnecessary.


# 1.116 25-Mar-2013 nicm

Rename session idx to session id throughout and add $ prefix to targets
to use it, extended from a diff from George Nachman.


# 1.115 24-Mar-2013 nicm

Add a command queue to standardize and simplify commands that call other
commands and allow a command to block execution of subsequent
commands. This allows run-shell and if-shell to be synchronous which has
been much requested.

Each client has a default command queue and commands are consumed one at
a time from it. A command may suspend execution from the queue by
returning CMD_RETURN_WAIT and then resume it by calling cmd_continue() -
for example run-shell does this from the callback that is fired after
the job is freed.

When the command queue becomes empty, command clients are automatically
exited (unless attaching). A callback is also fired - this is used for
nested commands in, for example, if-shell which can block execution of
the client's cmdq until a new cmdq becomes empty.

Also merge all the old error/info/print functions together and lose the
old curclient/cmdclient distinction - a cmdq is bound to one client (or
none if in the configuration file), this is a command client if
c->session is NULL otherwise an attached client.


Revision tags: OPENBSD_5_3_BASE
# 1.114 27-Nov-2012 nicm

Correctly aggregate together errors from nested config files (with
source-file). Fix by Thomas Adam, reported by Sam Livingstone-Gray


# 1.113 26-Nov-2012 nicm

Call realpath earlier on the socket directory path rather than on the
socket file path because the latter may not exist yet and in that case
realpath is allowed to fail. From Romain Francoise.


Revision tags: OPENBSD_5_2_BASE
# 1.112 10-Jul-2012 nicm

xfree is not particularly helpful, remove it. From Thomas Adam.


# 1.111 18-Jun-2012 nicm

Add a skeleton mode to tmux (called "control mode") that let's tmux
commands be sent and output received on stdout. This can be used to
integrate with other terminal emulators and should allow some other
things to be made simpler later. More to come so doesn't do much yet and
deliberately not documented.


# 1.110 30-May-2012 nicm

Do not use stderr for log file and don't call log_close when not needed.


# 1.109 25-May-2012 nicm

Simplify logging and just fprintf(stderr, ...) for early errors.


Revision tags: OPENBSD_5_1_BASE
# 1.108 21-Jan-2012 nicm

Drop the ability to have a list of keys in the prefix in favour of two
separate options, prefix and prefix2. This simplifies the code and gets
rid the data options type which was only used for this one option.

Also add a -2 flag to send-prefix to send the secondary prefix key,
fixing a cause of minor irritation.

People who want three prefix keys are out of luck :-).


# 1.107 23-Oct-2011 nicm

Try to resolve relative paths for loadb and saveb (first using client
working directory if any then default-path or session wd).


# 1.106 23-Oct-2011 nicm

Ignore LC_ALL and LC_CTYPE if they are empty as well as unset.


# 1.105 25-Sep-2011 nicm

Reject $SHELL if it is not a full path.


Revision tags: OPENBSD_5_0_BASE
# 1.104 04-Mar-2011 nicm

Two fixes by Micah Cowan: make mouse work properly beyond >127 on signed
char architectures and properly parse $TMUX by stopping the socket path
at the first comma.


Revision tags: OPENBSD_4_9_BASE
# 1.103 23-Jan-2011 nicm

Set $TMUX without the session when background jobs are run.


# 1.102 12-Jan-2011 nicm

Use TMPDIR if set, from Han Boetes.


# 1.101 08-Jan-2011 nicm

Move all calls to fcntl(...O_NONBLOCK) into a function and clear the
flag on the stdio file descriptors before closing them (fixes things
like "tmux ls && cat").


# 1.100 03-Jan-2011 nicm

Support for UTF-8 mouse input (\033[1005h). This was added in xterm 262
and supports larger terminals than the older way.

If the new mouse-utf8 option is on, UTF-8 mouse input is enabled for all
UTF-8 terminals. The option defaults to on if LANG etc are set in the
same manner as the utf8 option.

With help and based on code from hsim at gmx.li.


# 1.99 01-Jan-2011 nicm

Move the user-visible parts of all options (names, types, limit, default
values) together into one set of tables in options-table.c. Also clean
up and simplify cmd-set-options.c and move a common print function into
option-table.c.


# 1.98 30-Dec-2010 nicm

Change from a per-session stack of buffers to one global stack which is
much more convenient and also simplifies lot of code. This renders
copy-buffer useless and makes buffer-limit now a server option.

By Tiago Cunha.


# 1.97 19-Dec-2010 nicm

Add other-pane-height and other-pane-width options, allowing the width
or height of the smaller panes in the main-horizontal and main-vertical
layouts to be set. Mostly from David Goodlad.


# 1.96 08-Dec-2010 nicm

In the built-in layouts, distribute the panes more evenly. Set the
default value of main-pane-width to 80, rather than 81. By Micah Cowan.


# 1.95 06-Dec-2010 nicm

Add an option to alert (monitor) for silence (lack of activity) in a
window. From Thomas Adam.


# 1.94 29-Nov-2010 nicm

If VISUAL or EDITOR contains "vi", configure mode-keys and status-keys
to vi.

Based on a diff from martynas@, previously requested by a couple of
other people.


# 1.93 11-Nov-2010 nicm

Add XAUTHORITY to update-environment, requested by Andreas Kloeckner.


# 1.92 18-Oct-2010 nicm

Merge the before and after attach client code into one in client.c
(instead of two in tmux.c and client.c).


# 1.91 16-Oct-2010 nicm

Make stdio blocking again before calling shell command with -c.


# 1.90 16-Oct-2010 nicm

Trying to set FD_CLOEXEC on every fd is a lost cause, just use
closefrom() before exec.


# 1.89 14-Oct-2010 nicm

Use an explicit event rather than event_once for the main event so it
can be removed when the client becomes ready.


# 1.88 26-Sep-2010 nicm

Two new options:

- server option "exit-unattached" makes the server exit when no clients
are attached, even if sessions are present;

- session option "destroy-unattached" destroys a session once no clients
are attached to it.

These are useful for preventing tmux remaining in the background where
it is undesirable and when using tmux as a login shell to keep a limit
on new sessions.


# 1.87 19-Aug-2010 nicm

Do not call event_del() for signals after fork(), just use sigaction()
directly instead - calling libevent functions after fork() w/o
event_reinit() is a bad idea, even if in this case it was harmless.


Revision tags: OPENBSD_4_8_BASE
# 1.86 04-Aug-2010 deraadt

switch back to kqueue for now, since (a) kqueue has been fixed to deal
with strange devices and (b) since there appears to be a bull in the
poll code in libevent as well...
requested by nicm who is away


# 1.85 24-Jul-2010 nicm

kqueue(2) is currently broken when used with /dev/null and a few other
devices.

An upcoming fix for some problems with the client stdout/stderr handling
relies on it working, so make tmux force libevent to use poll(2) via
EVENT_NOKQUEUE, until we have fixed kqueue.


# 1.84 11-Jul-2010 nicm

Return the command client return code with MSG_EXIT now that MSG_ERROR and
MSG_PRINT are unused.

New clients should be compatible with old tmux servers but vice versa may print
an error.


# 1.83 28-Jun-2010 nicm

Send all three of stdin, stdout, stderr from the client to the server, so that
commands can directly make use of them. This means that load-buffer and
save-buffer can have "-" as the file to read from stdin or write to stdout.

This is a protocol version bump so the tmux server will need to be restarted
after upgrade (or an older client used).


# 1.82 27-Jun-2010 nicm

Store the current working directory in the session, change the default-path
option to default to empty and make that mean that the stored session CWD is
used.


# 1.81 27-Jun-2010 nicm

New option, detach-on-destroy, to set what happens to a client when the session
it is attached to is destroyed. If on (the default), it is detached; if off, it
is switched to the most recently active session.


# 1.80 26-Jun-2010 nicm

Setting the cmdlist pointer in the bind-key to NULL to prevent it being freed
after the command is executing is bogus because it may still be needed if the
same command is going to be executed again (for example if you "bind-key a
bind-key b ..."). Making a copy is hard, so instead add a reference count to
the cmd_list.

While here, also print bind-key -n and the rest of the flags properly.

Fixes problem reported by mcbride@.


# 1.79 14-May-2010 nicm

Colour+attribute options for status line alerts, from Alex Alexander.


# 1.78 04-May-2010 nicm

Put this back in with the initialisation in the right order.


# 1.77 04-May-2010 nicm

Revert last change, it appears to be broken somehow.


# 1.76 03-May-2010 nicm

Make signal handler setup/teardown two common functions instead of six,
and reset SIGCHLD after fork to fix problems with some shells. From
Romain Francois.


# 1.75 28-Apr-2010 nicm

Make the active pane border have a green foreground instead of
background by default.


# 1.74 18-Apr-2010 nicm

Catch SIGCHLD to avoid a zombie, from patrick keshishian.


Revision tags: OPENBSD_4_7_BASE
# 1.73 22-Feb-2010 nicm

Option to set the characters considered word separators in copy mode, from
Micah Cowan.


# 1.72 08-Feb-2010 nicm

Add an option to disable the smcup/rmcup alternate screen behaviour inside
tmux. From clemens fischer.


# 1.71 06-Feb-2010 nicm

Change nested check to compare server socket path rather than just assuming
that if $TMUX is set it is nested. From Micah Cowan.


# 1.70 06-Feb-2010 nicm

Clean up $TMUX parsing, from Micah Cowan, tweaked by me.


# 1.69 06-Feb-2010 nicm

Instead of bailing out on the first configuration file error, carry on,
collecting all the errors, then start with the active window in more mode
displaying them.


# 1.68 04-Feb-2010 nicm

Read the path from $TMUX if it is present and -L and -S are not given. Based on
a diff from Micah Cowan.


# 1.67 04-Feb-2010 nicm

Option to display the active pane in a different colour with the display-panes
command. From Paul Hoffman, thanks.


# 1.66 03-Jan-2010 nicm

Options to set the colour of the pane borders, with different colours for the
active pane.


# 1.65 14-Dec-2009 nicm

New server option, escape-time, to set the timeout used to detect if escapes
are alone or part of a function key or meta sequence.


# 1.64 11-Dec-2009 nicm

Use quiet variable, and add missing sentinel to options array.


# 1.63 10-Dec-2009 nicm

Add "server options" which are server-wide and not bound to a session or
window. Set and displayed with "set -s" and "show -s".

Currently the only option is "quiet" (like command-line -q, allowing it to be
set from .tmux.conf), but others will come along.


# 1.62 03-Dec-2009 nicm

Massive spaces->tabs and trailing whitespace cleanup, hopefully for the last
time now I've configured emacs to make them displayed in really annoying
colours...


# 1.61 26-Nov-2009 nicm

Remove a couple of unused arguments where possible, and add /* ARGSUSED */ to
the rest to reduce lint output.


# 1.60 19-Nov-2009 nicm

Two new options, window-status-format and window-status-current-format, which
allow the format of each window in the status line window list to be controlled
using similar # sequences as status-left/right.

This diff also moves part of the way towards UTF-8 support in window names but
it isn't quite there yet.


# 1.59 19-Nov-2009 nicm

Revert to xterm-keys off by default. It was on as an experiment to see if the
option could be removed, but it affects vi, so we have to keep the option, and
a conservative default is better.


# 1.58 18-Nov-2009 nicm

Add a per-client log of status line messages displayed while that client
exists. A new message-limit session option sets the maximum number of entries
and a command, show-messages, shows the log (bound to ~ by default).

This (and prompt history) might be better as a single global log but until
there are global options it is easier for them to be per client.


# 1.57 10-Nov-2009 nicm

There is no real standard for modifier plus function keys. Previously, tmux
output some from rxvt but in other ways did the same as xterm or other
terminals, but this is a bit inconsistent.

xterm's method is fairly sensible and we already support it (xterm-keys), so
enable it by default instead.


# 1.56 04-Nov-2009 nicm

A couple of minor cosmetic changes.


# 1.55 04-Nov-2009 nicm

Initial changes to move tmux to libevent.

This moves the client-side loops are pretty much fully over to event-based only
(tmux.c and client.c) but server-side (server.c and friends) treats libevent as
a sort of clever poll, waking up after every event to run various things.

Moving the server stuff over to bufferevents and timers and so on will come
later.


# 1.54 04-Nov-2009 nicm

Change declaration and use of malloc_options to be more standard, from Tim van
der Molen.


# 1.53 26-Oct-2009 deraadt

tabs are better; ok nicm


# 1.52 25-Oct-2009 nicm

Remove the -d flag to tmux and just use op/AX to detect default colours.

Irritatingly, although op can be used to tell if a terminal supports default
colours, it can't be used to set them because in some terminfo descriptions it
resets attributes as a side-effect (acts as sgr0) and in others it doesn't, so
it is not possible to determine reliably what the terminal state will be
afterwards. So if AX is missing and op is present, tmux just sends sgr0.

Anyone using -d for a terminal who finds they actually needed it can replace it
using terminal-overrides, but please let me know as it is probably an omission
from terminfo.


# 1.51 22-Oct-2009 nicm

Merge prepare_cmd into main as it is short and only called once.


# 1.50 21-Oct-2009 nicm

Client tidying: get rid of client_ctx struct in favour of two variables in
client.c, and move the functions in client-fn.c into other files.


# 1.49 10-Oct-2009 nicm

New option, mouse-select-pane. If on, the mouse may be used to select the
current pane.

Suggested by sthen@ and also by someone else ages ago who I have forgotten.


# 1.48 10-Oct-2009 nicm

Support for individual session idle time locking. May be enabled by turning off
the lock-server option (it is on by default). When this is off, each session
locks when it has been idle for the lock-after-time setting. When on, the
entire server locks when ALL sessions have been idle for their individual
lock-after-time settings.

This replaces one global-only option (lock-after-time) with another
(lock-server), but the default behaviour is usually preferable so there don't
seem to be many alternatives.

Diff/idea largely from Thomas Adam, tweaked by me.


# 1.47 09-Oct-2009 nicm

Add a simple synchronize-panes window option: when set, all input to any pane
that is part of the window is also sent to all other panes in the same
window. Suggested by several, most recently Tomasz Pajor.


# 1.46 23-Sep-2009 nicm

Support -c like sh(1) to execute a command, useful when tmux is a login
shell. Suggested by halex@.

This includes another protocol version increase (the last for now) so again
restart the tmux server before upgrading.


# 1.45 23-Sep-2009 nicm

Remove the internal tmux locking and instead detach each client and run the
command specified by a new option "lock-command" (by default "lock -np") in
each client.

This means each terminal has to be unlocked individually but simplifies the
code and allows the system password to be used to unlock.

Note that the set-password command is gone, so it will need to be removed from
configuration files, and the -U command line flag has been removed.

This is the third protocol version change so again it is best to stop the tmux
server before upgrading.


# 1.44 22-Sep-2009 nicm

Permit multiple prefix keys to be defined, separated by commas, for example:

set -g prefix ^a,^b

Any key in the list acts as the prefix. The send-prefix command always sends
the first key in the list.


# 1.43 18-Sep-2009 nicm

New option, set-titles-string, to allow the window title to be specified (as
for status-left/right) if set-titles is on. Also only update the title when the
status line is being redrawn.


# 1.42 04-Sep-2009 nicm

Tidy main and make it a bit easier to read.


# 1.41 02-Sep-2009 nicm

Accept -l to make it easier for people who use tmux as a login shell to use
$SHELL. Originally from martynas@, tweaked by me.


# 1.40 02-Sep-2009 nicm

When incorrect passwords are entered, behave similarly to login(1) and backoff
for a bit. Based on a diff from martynas@.


# 1.39 01-Sep-2009 nicm

When using tmux as a login shell, there is currently no way to specify a shell
to be used as a login shell inside tmux, so add a default-shell session option.
This sets the shell invoked as a login shell when the default-command option is
empty.

The default option value is whichever of $SHELL, getpwuid(getuid())'s pw_shell
or /bin/sh is valid first.

Based on a diff from martynas@, changed by me to be a session option rather
than a window option.


# 1.38 01-Sep-2009 nicm

Use "Password:" with no space for password prompts and don't display a *s for
the password, like pretty much everything else. From martynas@ with minor
tweaks by me.


# 1.37 01-Sep-2009 nicm

Sort cases same as getopt argument, from martynas.


# 1.36 31-Aug-2009 nicm

Add a new display-panes command, with two options (display-panes-colour and
display-panes-time), which displays a visual indication of the number of each
pane.


# 1.35 23-Aug-2009 nicm

Add some other obvious variables to update-environment (WINDOWID SSH_ASKPASS
SSH_AUTH_SOCK SSH_AGENT_PID SSH_CONNECTION) so they are updated in the session
environment on new/attach.


# 1.34 13-Aug-2009 nicm

Disable mode-mouse (mouse in copy/choice mode) by default as it isn't very
useful at the moment and causes confusion.


# 1.33 13-Aug-2009 nicm

Add a base-index session option to specify the first index checked when looking
for an index for a new window.


# 1.32 12-Aug-2009 nicm

When started as the shell, __progname contains a leading -, so hardcode "tmux"
for socket path and log files, and strip it when working out the shell.


# 1.31 11-Aug-2009 nicm

Switch tmux to use imsg. This is the last major change to make the
client-server protocol more resilient and make the protocol versioning work
properly. In future, the only things requiring a protocol version bump will be
changes in the message structs, and (when both client and server have this
change) mixing different versions should nicely report an error message.

As a side effect this also makes the code tidier, fixes a problem with the way
errors reported during server startup were handled, and supports fd passing
(which will be used in future).

Looked over by eric@, thanks.

Please note that mixing a client with this change with an older server or vice
versa may cause tmux to crash or hang - tmux should be completely exited before
upgrading.


# 1.30 10-Aug-2009 nicm

No arguments are the same as new-session and this requires the environment to
be sent, so set that flag too when argc == 0.


# 1.29 08-Aug-2009 nicm

Infrastructure and commands to manage the environment for processes started
within tmux.

There is a global environment, copied from the external environment when the
server is started and each sesssion has an (initially empty) session
environment which overrides it.

New commands set-environment and show-environment manipulate or display the
environments.

A new session option, update-environment, is a space-separated list of
variables which are updated from the external environment into the session
environment every time a new session is created - the default is DISPLAY.


# 1.28 08-Aug-2009 nicm

Options to set the colours and attributes for status-left/-right. From Thomas
Adam, thanks.


# 1.27 05-Aug-2009 nicm

If colours are not supported by the terminal, try to emulate a coloured
background by setting or clearing the reverse attribute.

This makes a few applications which don't use the reverse attribute themselves
a little happier, and allows the status, message and mode options to have
default attributes and fg/bg options that work as expected when set as reverse.


# 1.26 04-Aug-2009 nicm

Check for "UTF8" as well as "UTF-8" in LANG etc as it seems this may also
appear.


# 1.25 03-Aug-2009 nicm

Add a terminal-overrides session option allowing individual terminfo(5) entries
to be overridden. The 88col/256col checks are now moved into the default
setting and out of the code.

Also remove a couple of old workarounds for xterm and rxvt which are no longer
necessary (tmux can emulate them if missing).


# 1.24 30-Jul-2009 nicm

Add a mode-mouse option to prevent tmux taking over the mouse in choice or copy
modes.


# 1.23 29-Jul-2009 nicm

Rename struct hdrtype to msgtype which is a better name and can be used even
when struct hdr disappears.


# 1.22 29-Jul-2009 nicm

Taking account of the "s, 22 not 24 is the maximum length of #T in status-right
to prevent the date being cut off.


# 1.21 26-Jul-2009 nicm

Make all messages sent between the client and server fixed size.

This is the first of two changes to make the protocol more resilient and less
sensitive to other changes in the code, particularly with commands. The client
now packs argv into a buffer and sends it to the server for parsing, rather
than doing it itself and sending the parsed command data.

As a side-effect this also removes a lot of now-unused command marshalling
code.

Mixing a server without this change and a client with or vice versa will cause
tmux to hang or crash, please ensure that tmux is entirely killed before
upgrading.


# 1.20 22-Jul-2009 nicm

Pass a set of flags into client_init rather than just a start_server
variable. Only one flag now but more to come later.


# 1.19 20-Jul-2009 nicm

Display the number of failed password attempts (if any) when the server is
locked. From Tom Doherty.


# 1.18 20-Jul-2009 nicm

Add a status-justify option to allow the window list in the status line to be
positioned at the left, centre, or right.


# 1.17 20-Jul-2009 nicm

New options, window-status-current-{fg,bg,attr}, to set the fg, bg and
attributes with which the current window is shown in the status line. From
Johan Friis, thanks.


# 1.16 18-Jul-2009 nicm

Add three new session options: visual-activity, visual-bell, visual-content. If
these are enabled (and the monitor-activity, bell-actio and monitor-content
options are configurated appropriately), when activity, a bell, or content is
detected, a message is shown.

Also tidy up the bell/activity/content code in server.c slightly and fix a
couple of errors.


# 1.15 17-Jul-2009 nicm

If -u is specified or UTF-8 is otherwise detected when the server is started,
enable the utf8 and status-utf8 optons. While here, note in the man page that
the server is started with the first session and exits when none remain.


# 1.14 10-Jul-2009 nicm

Add a default-terminal option to set the starting value of $TERM in new
windows.

This is "screen" by default and must be either that or something closely
related. This does makes it easier to customise it if necessary.


# 1.13 08-Jul-2009 nicm

Just appending -l to $SHELL to create a login shell is wrong: -l is not POSIX,
and some people may use shells which do not support it. Instead, make an empty
default-command option mean a login shell, and fork it with a - in argv[0]
which is the method used by login(1).

Also fix the automatic-rename code to handle this correctly and to strip a
leading - if present.


# 1.12 07-Jul-2009 nicm

Rename the global options variables to be shorter and to make session options
clear. No functional change, getting this out of the way to make later options
changes easier.


Revision tags: OPENBSD_4_6_BASE
# 1.11 25-Jun-2009 nicm

If getcwd() fails, use the user's home directory, or /, instead of failing with
an error.


# 1.10 25-Jun-2009 nicm

Remove error about using -L and -S together which was never displayed as
logging wasn't yet enabled, was unnecessary, and contradicted the man page
which says using -S will cause -L to be ignored.


# 1.9 23-Jun-2009 nicm

LC_ALL overrides LC_CTYPE and LANG. Comment was correct but the code
wrong. Pointed out by Hannah Schroeter, thanks.


# 1.8 05-Jun-2009 nicm

Check the first of LC_CTYPE, LC_ALL and LANG, rather than just the last, when
trying to decide about UTF-8, and use strcasestr. Reported by Geert Hendrickx.


# 1.7 04-Jun-2009 nicm

Zero the password given to -U in the client as well.


# 1.6 03-Jun-2009 nicm

Do not set the window title by default (make set-titles option default to off),
wiping over the title is rude and annoying. Agreed by several.


# 1.5 03-Jun-2009 nicm

New session option, status-utf8, to control the interpretation of top-bit-set
characters in status-left and status-right (if on, they are treated as UTF-8;
otherwise passed through).


# 1.4 02-Jun-2009 sobrado

remove unused flag; while here, make usage's output fit on 80-column displays.


# 1.3 02-Jun-2009 pyr

spawn login shells by default, adapt manpage bits as well.
ok nicm@


# 1.2 02-Jun-2009 ray

Don't leak memory if multiple -f flags are given.

OK nicm@


# 1.1 01-Jun-2009 nicm

Import tmux, a terminal multiplexor allowing (among other things) a single
terminal to be switched between several different windows and programs
displayed on one terminal be detached from one terminal and moved to another.

ok deraadt pirofti


# 1.208 06-Jul-2021 nicm

Improve error reporting when the tmux /tmp directory cannot be created
or used, GitHub issue 2765 from Uwe Kleine-Koenig.


# 1.207 10-Jun-2021 nicm

Do not expand the file given with -f so it can contain :s.


Revision tags: OPENBSD_6_9_BASE
# 1.206 22-Feb-2021 nicm

expand_paths needs the global environment to be set up, do that first.


# 1.205 22-Feb-2021 nicm

Move config file path expansion much earlier, keep the list of paths
around rather than freeing later, and add a config_files format variable
containing it. Suggested by kn@ a while back.


# 1.204 17-Jan-2021 nicm

Add -N flag to never start server even if command would normally do so,
GitHub issue 2523.


Revision tags: OPENBSD_6_8_BASE
# 1.203 22-Sep-2020 nicm

Fix warnings on some platforms with %llx and add a new message to handle
64-bit client flags.


# 1.202 02-Jun-2020 nicm

Use CLOCK_MONOTONIC for timer measurement and add a timestamp to control
mode %output blocks.


# 1.201 16-May-2020 nicm

Add a -D flag to ask tmux not to daemonize, useful both for running a
debugger (lldb does not have follow-fork-mode) and for running with a
managed supervisor init system. GitHub issue 2190.


# 1.200 16-May-2020 nicm

Add 'e' key in buffer mode to open the buffer in an editor.


# 1.199 16-May-2020 nicm

Build list of paths and weed out duplicates before loading configs, and
add TMUX_SOCK like TMUX_PATH for the socket directory.


Revision tags: OPENBSD_6_7_BASE
# 1.198 20-Apr-2020 nicm

Tidy up the terminal detection and feature code and add named sets of
terminal features, each of which are defined in one place and map to a
builtin set of terminfo(5) capabilities. Features can be specified based
on TERM with a new terminal-features option or with the -T flag when
running tmux. tmux will also detect a few common terminals from the DA
and DSR responses.

This is intended to make it easier to configure tmux's use of
terminfo(5) even in the presence of outdated ncurses(3) or terminfo(5)
databases or for features which do not yet have a terminfo(5) entry.
Instead of having to grok terminfo(5) capability names and what they
should be set to in the terminal-overrides option, the user can
hopefully just give tmux a feature name and let it do the right thing.

The terminal-overrides option remains both for backwards compatibility
and to allow tweaks of individual capabilities.

tmux already did much of this already, this makes it tidier and simpler
to configure.


# 1.197 16-Apr-2020 nicm

Show signal name when process exits rather than number.


# 1.196 09-Apr-2020 nicm

More style nits.


# 1.195 31-Mar-2020 nicm

Add a way to mark environment variables as "hidden" so they can be used
by tmux but are not passed into the environment of new panes.


# 1.194 17-Mar-2020 nicm

Ignore default-shell (and use /bin/sh) if it invalid not just if it is
tmux itself, also refuse to set the option to something invalid in the
first place. GitHub issue 2120.


# 1.193 12-Mar-2020 nicm

When the server socket is given by the user with -S, create it with
umask 177 instead of 117 because it may not be in a safe directory like
the default directory in /tmp. The user can chmod it more open after it
is created if they want.


# 1.192 28-Jan-2020 nicm

-V also needs to go in usage.


# 1.191 28-Jan-2020 nicm

Reduce a difference with portable tmux by adding the -V flag and
#{version} format; on OpenBSD these just report the OpenBSD version.


# 1.190 14-Oct-2019 nicm

Memory leaks, from Igor Wong in GitHub issue 1934.


Revision tags: OPENBSD_6_6_BASE
# 1.189 20-Jun-2019 nicm

Add a per-pane option set. Pane options inherit from window options (so
there should be no change to existing behaviour) and are set and shown
with set-option -p and show-options -p.

Change remain-on-exit and window-style/window-active-style to be pane
options (some others will be changed later).

This makes select-pane -P and -g unnecessary so no longer document them
(they still work) and no longer document set-window-option and
show-window-options in favour of set-option -w and show-options -w.


# 1.188 26-Apr-2019 nicm

Merge hooks into options and make each one an array option. This allows
multiple commands to be easily bound to one hook. set-hook and
show-hooks remain but they are now variants of set-option and
show-options. show-options now has a -H flag to show hooks (by default
they are not shown).


Revision tags: OPENBSD_6_5_BASE
# 1.187 22-Nov-2018 nicm

Do not use PWD unless it actually matches the real working directory.


Revision tags: OPENBSD_6_3_BASE OPENBSD_6_4_BASE
# 1.186 12-Jan-2018 nicm

Improve error message if creating socket parent directory fails, from
Thomas Adam for GitHub issue 1215.


# 1.185 01-Jan-2018 nicm

Prefer PWD for current directory if present in client, from Wei Zhao in
GitHub issue 1183.


Revision tags: OPENBSD_6_2_BASE
# 1.184 12-Jul-2017 nicm

Make shell_command a global like other stuff rather than making it an
exception and using callback argument.


# 1.183 03-Jul-2017 nicm

Try C.UTF-8 which is also a commonly useful locale on some platforms,
from Romain Francoise.


# 1.182 22-Apr-2017 nicm

Do not need getopt.h.


# 1.181 20-Apr-2017 nicm

Use fdforkpty() instead of our own unwrapped versions.


# 1.180 19-Apr-2017 nicm

Style nits and a missing cast.


# 1.179 16-Apr-2017 nicm

Memory leak, from David CARLIER.


Revision tags: OPENBSD_6_1_BASE
# 1.178 21-Mar-2017 nicm

Use uid_t for UID not u_int.


# 1.177 16-Feb-2017 nicm

Style nits.


# 1.176 23-Jan-2017 nicm

Open /dev/ptm before pledge() and save it to be used for PTMGET later
(this means inlining forkpty()).

ok deraadt


# 1.175 15-Jan-2017 nicm

Major tidy up and rework of options tree and set-option/show-options
commands this pushes more of the code into options.c and ties it more
closely to the options table rather than having an unnecessary
split. Also add support for array options (will be used later). Only
(intentional) user visible change is that show-options output is now
passed through vis(3) with VIS_DQ so quotes are escaped.


# 1.174 12-Jan-2017 nicm

Simplify appending to string options.


# 1.173 09-Dec-2016 nicm

Spacing nits.


# 1.172 11-Oct-2016 nicm

Add static in window-*.c and move some internal functions out of tmux.h.


# 1.171 10-Oct-2016 nicm

Loads more static, except for cmd-*.c and window-*.c.


Revision tags: OPENBSD_6_0_BASE
# 1.170 27-May-2016 nicm

Use getprogname() instead of __progname to make portability easier.


# 1.169 04-May-2016 nicm

Fix up a couple of long lines.


# 1.168 05-Mar-2016 nicm

If setlocale("en_US.UTF-8") succeeds, then don't do the check for UTF-8
locale since if it isn't UTF-8 the system is broken anyway. If it fails,
try "" and check for UTF-8 with nl_langinfo(CODESET) rather than
wcwidth(). Based on a diff from schwarze@, nl_langinfo also suggested by
stsp@.


# 1.167 05-Mar-2016 nicm

Although we always have en_US.UTF-8 on OpenBSD, some platforms do not,
so fall back to setlocale(LC_CTYPE, ""). tmux requires a UTF-8 locale,
so check with wcwidth() on a UTF-8 character after setlocale().


# 1.166 01-Mar-2016 nicm

Remove unused variables, from Michal Mazurek.


# 1.165 01-Mar-2016 nicm

Use system wcwidth() instead of carrying around UTF-8 width tables.


Revision tags: OPENBSD_5_9_BASE
# 1.164 19-Jan-2016 nicm

I no longer use my SourceForge address so replace it.


# 1.163 08-Dec-2015 nicm

Add hooks infrastructure, basic commands (set-hook, show-hooks) and a
couple of not very useful client hooks. This will eventually let
commands be run at various points and on notifications. Joint work with
Thomas Adam.


# 1.162 24-Nov-2015 nicm

Make environ_set va_args and use it to tidy up some calls. Also add a
missing word in manpage (from jmc).


# 1.161 24-Nov-2015 nicm

Shell command from -c doesn't have to be global, pass it as an argument.


# 1.160 24-Nov-2015 nicm

Tidy the code that works out the socket path, and just use the full path
in the global socket_path rather than copying it.


# 1.159 24-Nov-2015 nicm

Remove malloc_options DEBUG bit.


# 1.158 24-Nov-2015 nicm

Remove the -I part of show-messages which isn't really that useful; the
server start time can now be accessed with a new start_time format (use:
tmux display -p '#{t:start_time}')


# 1.157 24-Nov-2015 nicm

Make the log stuff a bit tidier with some helper functions.


# 1.156 22-Nov-2015 nicm

Add getpw to pledge, makes tmux work in YP environments, discovered by
matthieu, ok deraadt


# 1.155 20-Nov-2015 nicm

Instead of separate tables for different types of options, give each
option a scope type (server, session, window) in one table.


# 1.154 15-Nov-2015 nicm

Accidentally turned off pledge, turn it back on.


# 1.153 14-Nov-2015 nicm

Push stdout and stderr to clients more aggressively, and add an event to
continue if the send fails.


# 1.152 12-Nov-2015 nicm

tmux is UTF-8, so if $TMUX is set (tmux running in tmux), the client is
UTF-8. Also try to make the existing checks more readable.


# 1.151 12-Nov-2015 nicm

Nuke the utf8 and status-utf8 options and make tmux only a UTF-8
terminal. We still support non-UTF-8 terminals outside tmux, but inside
it is always UTF-8 (as when the utf8 and status-utf8 options were on).


# 1.150 11-Nov-2015 nicm

Drop mouse-utf8 option and always turn on UTF-8 mouse if the client says
it supports UTF-8.


# 1.149 28-Oct-2015 nicm

Like options, move the environ struct into environ.c.


# 1.148 27-Oct-2015 nicm

Move struct options into options.c.


# 1.147 27-Oct-2015 nicm

Break the common process set up, event loop and imsg dispatch code
between server and client out into a separate internal API. This will
make it easier to add another process.


# 1.146 25-Oct-2015 deraadt

Let's see if anyone screams about not being able to specify $TMPDIR
for their tmux sockets.

(Over the years, I have seen $TMPDIR set up worse than /tmp many times,
and don't know how this practice infected other parts of the system.
Nothing uses tmpdir(3), nor a huge-temporary-file program like sort.)
ok nicm


# 1.145 23-Oct-2015 nicm

tmux can call pledge() in main with large set and then reduce it
slightly in the server to "stdio rpath wpath cpath fattr unix recvfd
proc exec tty ps".


# 1.144 14-Sep-2015 nicm

Move tzset() from log_open to main.


# 1.143 03-Sep-2015 nicm

A couple of style nits.


# 1.142 01-Sep-2015 nicm

Work out config file when needed not at startup.


# 1.141 30-Aug-2015 nicm

Path from $TMUX does not need to be global anymore.


# 1.140 30-Aug-2015 nicm

Login shell can be a client flag, and move the exec code into client.c.


# 1.139 30-Aug-2015 nicm

Event base does not need to be global.


# 1.138 30-Aug-2015 nicm

Some style nits and dead assignments.


Revision tags: OPENBSD_5_8_BASE
# 1.137 20-Jul-2015 nicm

Add an option (history-file) for a file to save/restore command prompt
history, from Olof-Joachim Frahm.


# 1.136 04-Jun-2015 jmc

tweak SYNOPSIS and usage();


Revision tags: OPENBSD_5_7_BASE
# 1.135 19-Jan-2015 nicm

Make a tmux-%u directory under TMUX_TMPDIR, like TMPDIR.


# 1.134 19-Jan-2015 nicm

Only care about other permissions, allow group to be set.


# 1.133 19-Jan-2015 nicm

Remove unnecessary duplicate S_ISDIR check, from Dmitri Paduchikh.


# 1.132 20-Oct-2014 nicm

Tidy up some includes.


Revision tags: OPENBSD_5_6_BASE
# 1.131 17-Apr-2014 nicm

Remove the "info" message mechanism, this was only used for about five
mostly useless and annoying messages. Change those commands to silence
on success like all the others. Still accept the -q command line flag
and "quiet" server option for now.


# 1.130 31-Mar-2014 nicm

Remove log_debug2 as well and simplify log.c.


Revision tags: OPENBSD_5_5_BASE
# 1.129 16-Feb-2014 nicm

Leftovers from removing 88 colour support, from Theo Buehler.


# 1.128 15-Jan-2014 nicm

Do not attempt to read .tmux.conf if we can't figure out a home
directory, from Tiago Cunha.


# 1.127 09-Jan-2014 nicm

Three small changes from Tiago Cunha:

- Check for truncation when copying path.
- Don't need to use a temporary buffer in screen_set_title.
- Include strerror in output when connecting to server fails.


# 1.126 10-Oct-2013 nicm

We accidentally haven't been using $TMUX to work out the session for a
while and in fact it is less useful that using the client ttyname. So
don't bother and don't pass it from the client. If we need it in future
it is in c->environ.


# 1.125 10-Oct-2013 nicm

Alter how tmux handles the working directory to internally use file
descriptors rather than strings.

- Each session still has a current working directory.

- New sessions still get their working directory from the client that
created them or its attached session if any.

- New windows are created by default in the session working directory.

- The -c flag to new, neww, splitw allows the working directory to be
overridden.

- The -c flag to attach let's the session working directory be changed.

- The default-path option has been removed.

To get the equivalent to default-path '.', do:

bind c neww -c $PWD

To get the equivalent of default-path '~', do:

bind c neww -c ~

This also changes the client identify protocol to be a set of messages rather
than one as well as some other changes that should make it easier to make
backwards-compatible protocol changes in future.


# 1.124 10-Oct-2013 nicm

Merge IDENTIFY_* flags with CLIENT_* flags.


# 1.123 10-Oct-2013 nicm

Don't treat TMUX_TMPDIR as a potential file

The point of setting TMUX_TMPDIR is to then make any labels from -L go
to that directory. In the case of makesocketpath() with no TMUX_TMPDIR
set, would set both the path and the default socket to a file. The
checking of the permissions on the file worked fine in that case, but
when TMUX_TMPDIR is set, won't work on a directory.

This fixes the problem by ensuring the check on the permissions is
performed on directories only.

By Thomas Adam.


# 1.122 05-Oct-2013 nicm

Fix previous not to leak fd on failure, whoops.


# 1.121 05-Oct-2013 nicm

Use open(".")/fchdir() to save and restore current directory rather than
getcwd()/chdir().


Revision tags: OPENBSD_5_4_BASE
# 1.120 24-Apr-2013 nicm

Rename global configuration define.


# 1.119 11-Apr-2013 nicm

Call setlocale(LC_TIME) at startup.


# 1.118 27-Mar-2013 nicm

Add TMUX_TMPDIR variable to put the socket directory outside
TMPDIR. From Ben Boeckel.


# 1.117 27-Mar-2013 nicm

Remove tmux's (already minimal) 88 colour support. Such terminals are
few and unnecessary.


# 1.116 25-Mar-2013 nicm

Rename session idx to session id throughout and add $ prefix to targets
to use it, extended from a diff from George Nachman.


# 1.115 24-Mar-2013 nicm

Add a command queue to standardize and simplify commands that call other
commands and allow a command to block execution of subsequent
commands. This allows run-shell and if-shell to be synchronous which has
been much requested.

Each client has a default command queue and commands are consumed one at
a time from it. A command may suspend execution from the queue by
returning CMD_RETURN_WAIT and then resume it by calling cmd_continue() -
for example run-shell does this from the callback that is fired after
the job is freed.

When the command queue becomes empty, command clients are automatically
exited (unless attaching). A callback is also fired - this is used for
nested commands in, for example, if-shell which can block execution of
the client's cmdq until a new cmdq becomes empty.

Also merge all the old error/info/print functions together and lose the
old curclient/cmdclient distinction - a cmdq is bound to one client (or
none if in the configuration file), this is a command client if
c->session is NULL otherwise an attached client.


Revision tags: OPENBSD_5_3_BASE
# 1.114 27-Nov-2012 nicm

Correctly aggregate together errors from nested config files (with
source-file). Fix by Thomas Adam, reported by Sam Livingstone-Gray


# 1.113 26-Nov-2012 nicm

Call realpath earlier on the socket directory path rather than on the
socket file path because the latter may not exist yet and in that case
realpath is allowed to fail. From Romain Francoise.


Revision tags: OPENBSD_5_2_BASE
# 1.112 10-Jul-2012 nicm

xfree is not particularly helpful, remove it. From Thomas Adam.


# 1.111 18-Jun-2012 nicm

Add a skeleton mode to tmux (called "control mode") that let's tmux
commands be sent and output received on stdout. This can be used to
integrate with other terminal emulators and should allow some other
things to be made simpler later. More to come so doesn't do much yet and
deliberately not documented.


# 1.110 30-May-2012 nicm

Do not use stderr for log file and don't call log_close when not needed.


# 1.109 25-May-2012 nicm

Simplify logging and just fprintf(stderr, ...) for early errors.


Revision tags: OPENBSD_5_1_BASE
# 1.108 21-Jan-2012 nicm

Drop the ability to have a list of keys in the prefix in favour of two
separate options, prefix and prefix2. This simplifies the code and gets
rid the data options type which was only used for this one option.

Also add a -2 flag to send-prefix to send the secondary prefix key,
fixing a cause of minor irritation.

People who want three prefix keys are out of luck :-).


# 1.107 23-Oct-2011 nicm

Try to resolve relative paths for loadb and saveb (first using client
working directory if any then default-path or session wd).


# 1.106 23-Oct-2011 nicm

Ignore LC_ALL and LC_CTYPE if they are empty as well as unset.


# 1.105 25-Sep-2011 nicm

Reject $SHELL if it is not a full path.


Revision tags: OPENBSD_5_0_BASE
# 1.104 04-Mar-2011 nicm

Two fixes by Micah Cowan: make mouse work properly beyond >127 on signed
char architectures and properly parse $TMUX by stopping the socket path
at the first comma.


Revision tags: OPENBSD_4_9_BASE
# 1.103 23-Jan-2011 nicm

Set $TMUX without the session when background jobs are run.


# 1.102 12-Jan-2011 nicm

Use TMPDIR if set, from Han Boetes.


# 1.101 08-Jan-2011 nicm

Move all calls to fcntl(...O_NONBLOCK) into a function and clear the
flag on the stdio file descriptors before closing them (fixes things
like "tmux ls && cat").


# 1.100 03-Jan-2011 nicm

Support for UTF-8 mouse input (\033[1005h). This was added in xterm 262
and supports larger terminals than the older way.

If the new mouse-utf8 option is on, UTF-8 mouse input is enabled for all
UTF-8 terminals. The option defaults to on if LANG etc are set in the
same manner as the utf8 option.

With help and based on code from hsim at gmx.li.


# 1.99 01-Jan-2011 nicm

Move the user-visible parts of all options (names, types, limit, default
values) together into one set of tables in options-table.c. Also clean
up and simplify cmd-set-options.c and move a common print function into
option-table.c.


# 1.98 30-Dec-2010 nicm

Change from a per-session stack of buffers to one global stack which is
much more convenient and also simplifies lot of code. This renders
copy-buffer useless and makes buffer-limit now a server option.

By Tiago Cunha.


# 1.97 19-Dec-2010 nicm

Add other-pane-height and other-pane-width options, allowing the width
or height of the smaller panes in the main-horizontal and main-vertical
layouts to be set. Mostly from David Goodlad.


# 1.96 08-Dec-2010 nicm

In the built-in layouts, distribute the panes more evenly. Set the
default value of main-pane-width to 80, rather than 81. By Micah Cowan.


# 1.95 06-Dec-2010 nicm

Add an option to alert (monitor) for silence (lack of activity) in a
window. From Thomas Adam.


# 1.94 29-Nov-2010 nicm

If VISUAL or EDITOR contains "vi", configure mode-keys and status-keys
to vi.

Based on a diff from martynas@, previously requested by a couple of
other people.


# 1.93 11-Nov-2010 nicm

Add XAUTHORITY to update-environment, requested by Andreas Kloeckner.


# 1.92 18-Oct-2010 nicm

Merge the before and after attach client code into one in client.c
(instead of two in tmux.c and client.c).


# 1.91 16-Oct-2010 nicm

Make stdio blocking again before calling shell command with -c.


# 1.90 16-Oct-2010 nicm

Trying to set FD_CLOEXEC on every fd is a lost cause, just use
closefrom() before exec.


# 1.89 14-Oct-2010 nicm

Use an explicit event rather than event_once for the main event so it
can be removed when the client becomes ready.


# 1.88 26-Sep-2010 nicm

Two new options:

- server option "exit-unattached" makes the server exit when no clients
are attached, even if sessions are present;

- session option "destroy-unattached" destroys a session once no clients
are attached to it.

These are useful for preventing tmux remaining in the background where
it is undesirable and when using tmux as a login shell to keep a limit
on new sessions.


# 1.87 19-Aug-2010 nicm

Do not call event_del() for signals after fork(), just use sigaction()
directly instead - calling libevent functions after fork() w/o
event_reinit() is a bad idea, even if in this case it was harmless.


Revision tags: OPENBSD_4_8_BASE
# 1.86 04-Aug-2010 deraadt

switch back to kqueue for now, since (a) kqueue has been fixed to deal
with strange devices and (b) since there appears to be a bull in the
poll code in libevent as well...
requested by nicm who is away


# 1.85 24-Jul-2010 nicm

kqueue(2) is currently broken when used with /dev/null and a few other
devices.

An upcoming fix for some problems with the client stdout/stderr handling
relies on it working, so make tmux force libevent to use poll(2) via
EVENT_NOKQUEUE, until we have fixed kqueue.


# 1.84 11-Jul-2010 nicm

Return the command client return code with MSG_EXIT now that MSG_ERROR and
MSG_PRINT are unused.

New clients should be compatible with old tmux servers but vice versa may print
an error.


# 1.83 28-Jun-2010 nicm

Send all three of stdin, stdout, stderr from the client to the server, so that
commands can directly make use of them. This means that load-buffer and
save-buffer can have "-" as the file to read from stdin or write to stdout.

This is a protocol version bump so the tmux server will need to be restarted
after upgrade (or an older client used).


# 1.82 27-Jun-2010 nicm

Store the current working directory in the session, change the default-path
option to default to empty and make that mean that the stored session CWD is
used.


# 1.81 27-Jun-2010 nicm

New option, detach-on-destroy, to set what happens to a client when the session
it is attached to is destroyed. If on (the default), it is detached; if off, it
is switched to the most recently active session.


# 1.80 26-Jun-2010 nicm

Setting the cmdlist pointer in the bind-key to NULL to prevent it being freed
after the command is executing is bogus because it may still be needed if the
same command is going to be executed again (for example if you "bind-key a
bind-key b ..."). Making a copy is hard, so instead add a reference count to
the cmd_list.

While here, also print bind-key -n and the rest of the flags properly.

Fixes problem reported by mcbride@.


# 1.79 14-May-2010 nicm

Colour+attribute options for status line alerts, from Alex Alexander.


# 1.78 04-May-2010 nicm

Put this back in with the initialisation in the right order.


# 1.77 04-May-2010 nicm

Revert last change, it appears to be broken somehow.


# 1.76 03-May-2010 nicm

Make signal handler setup/teardown two common functions instead of six,
and reset SIGCHLD after fork to fix problems with some shells. From
Romain Francois.


# 1.75 28-Apr-2010 nicm

Make the active pane border have a green foreground instead of
background by default.


# 1.74 18-Apr-2010 nicm

Catch SIGCHLD to avoid a zombie, from patrick keshishian.


Revision tags: OPENBSD_4_7_BASE
# 1.73 22-Feb-2010 nicm

Option to set the characters considered word separators in copy mode, from
Micah Cowan.


# 1.72 08-Feb-2010 nicm

Add an option to disable the smcup/rmcup alternate screen behaviour inside
tmux. From clemens fischer.


# 1.71 06-Feb-2010 nicm

Change nested check to compare server socket path rather than just assuming
that if $TMUX is set it is nested. From Micah Cowan.


# 1.70 06-Feb-2010 nicm

Clean up $TMUX parsing, from Micah Cowan, tweaked by me.


# 1.69 06-Feb-2010 nicm

Instead of bailing out on the first configuration file error, carry on,
collecting all the errors, then start with the active window in more mode
displaying them.


# 1.68 04-Feb-2010 nicm

Read the path from $TMUX if it is present and -L and -S are not given. Based on
a diff from Micah Cowan.


# 1.67 04-Feb-2010 nicm

Option to display the active pane in a different colour with the display-panes
command. From Paul Hoffman, thanks.


# 1.66 03-Jan-2010 nicm

Options to set the colour of the pane borders, with different colours for the
active pane.


# 1.65 14-Dec-2009 nicm

New server option, escape-time, to set the timeout used to detect if escapes
are alone or part of a function key or meta sequence.


# 1.64 11-Dec-2009 nicm

Use quiet variable, and add missing sentinel to options array.


# 1.63 10-Dec-2009 nicm

Add "server options" which are server-wide and not bound to a session or
window. Set and displayed with "set -s" and "show -s".

Currently the only option is "quiet" (like command-line -q, allowing it to be
set from .tmux.conf), but others will come along.


# 1.62 03-Dec-2009 nicm

Massive spaces->tabs and trailing whitespace cleanup, hopefully for the last
time now I've configured emacs to make them displayed in really annoying
colours...


# 1.61 26-Nov-2009 nicm

Remove a couple of unused arguments where possible, and add /* ARGSUSED */ to
the rest to reduce lint output.


# 1.60 19-Nov-2009 nicm

Two new options, window-status-format and window-status-current-format, which
allow the format of each window in the status line window list to be controlled
using similar # sequences as status-left/right.

This diff also moves part of the way towards UTF-8 support in window names but
it isn't quite there yet.


# 1.59 19-Nov-2009 nicm

Revert to xterm-keys off by default. It was on as an experiment to see if the
option could be removed, but it affects vi, so we have to keep the option, and
a conservative default is better.


# 1.58 18-Nov-2009 nicm

Add a per-client log of status line messages displayed while that client
exists. A new message-limit session option sets the maximum number of entries
and a command, show-messages, shows the log (bound to ~ by default).

This (and prompt history) might be better as a single global log but until
there are global options it is easier for them to be per client.


# 1.57 10-Nov-2009 nicm

There is no real standard for modifier plus function keys. Previously, tmux
output some from rxvt but in other ways did the same as xterm or other
terminals, but this is a bit inconsistent.

xterm's method is fairly sensible and we already support it (xterm-keys), so
enable it by default instead.


# 1.56 04-Nov-2009 nicm

A couple of minor cosmetic changes.


# 1.55 04-Nov-2009 nicm

Initial changes to move tmux to libevent.

This moves the client-side loops are pretty much fully over to event-based only
(tmux.c and client.c) but server-side (server.c and friends) treats libevent as
a sort of clever poll, waking up after every event to run various things.

Moving the server stuff over to bufferevents and timers and so on will come
later.


# 1.54 04-Nov-2009 nicm

Change declaration and use of malloc_options to be more standard, from Tim van
der Molen.


# 1.53 26-Oct-2009 deraadt

tabs are better; ok nicm


# 1.52 25-Oct-2009 nicm

Remove the -d flag to tmux and just use op/AX to detect default colours.

Irritatingly, although op can be used to tell if a terminal supports default
colours, it can't be used to set them because in some terminfo descriptions it
resets attributes as a side-effect (acts as sgr0) and in others it doesn't, so
it is not possible to determine reliably what the terminal state will be
afterwards. So if AX is missing and op is present, tmux just sends sgr0.

Anyone using -d for a terminal who finds they actually needed it can replace it
using terminal-overrides, but please let me know as it is probably an omission
from terminfo.


# 1.51 22-Oct-2009 nicm

Merge prepare_cmd into main as it is short and only called once.


# 1.50 21-Oct-2009 nicm

Client tidying: get rid of client_ctx struct in favour of two variables in
client.c, and move the functions in client-fn.c into other files.


# 1.49 10-Oct-2009 nicm

New option, mouse-select-pane. If on, the mouse may be used to select the
current pane.

Suggested by sthen@ and also by someone else ages ago who I have forgotten.


# 1.48 10-Oct-2009 nicm

Support for individual session idle time locking. May be enabled by turning off
the lock-server option (it is on by default). When this is off, each session
locks when it has been idle for the lock-after-time setting. When on, the
entire server locks when ALL sessions have been idle for their individual
lock-after-time settings.

This replaces one global-only option (lock-after-time) with another
(lock-server), but the default behaviour is usually preferable so there don't
seem to be many alternatives.

Diff/idea largely from Thomas Adam, tweaked by me.


# 1.47 09-Oct-2009 nicm

Add a simple synchronize-panes window option: when set, all input to any pane
that is part of the window is also sent to all other panes in the same
window. Suggested by several, most recently Tomasz Pajor.


# 1.46 23-Sep-2009 nicm

Support -c like sh(1) to execute a command, useful when tmux is a login
shell. Suggested by halex@.

This includes another protocol version increase (the last for now) so again
restart the tmux server before upgrading.


# 1.45 23-Sep-2009 nicm

Remove the internal tmux locking and instead detach each client and run the
command specified by a new option "lock-command" (by default "lock -np") in
each client.

This means each terminal has to be unlocked individually but simplifies the
code and allows the system password to be used to unlock.

Note that the set-password command is gone, so it will need to be removed from
configuration files, and the -U command line flag has been removed.

This is the third protocol version change so again it is best to stop the tmux
server before upgrading.


# 1.44 22-Sep-2009 nicm

Permit multiple prefix keys to be defined, separated by commas, for example:

set -g prefix ^a,^b

Any key in the list acts as the prefix. The send-prefix command always sends
the first key in the list.


# 1.43 18-Sep-2009 nicm

New option, set-titles-string, to allow the window title to be specified (as
for status-left/right) if set-titles is on. Also only update the title when the
status line is being redrawn.


# 1.42 04-Sep-2009 nicm

Tidy main and make it a bit easier to read.


# 1.41 02-Sep-2009 nicm

Accept -l to make it easier for people who use tmux as a login shell to use
$SHELL. Originally from martynas@, tweaked by me.


# 1.40 02-Sep-2009 nicm

When incorrect passwords are entered, behave similarly to login(1) and backoff
for a bit. Based on a diff from martynas@.


# 1.39 01-Sep-2009 nicm

When using tmux as a login shell, there is currently no way to specify a shell
to be used as a login shell inside tmux, so add a default-shell session option.
This sets the shell invoked as a login shell when the default-command option is
empty.

The default option value is whichever of $SHELL, getpwuid(getuid())'s pw_shell
or /bin/sh is valid first.

Based on a diff from martynas@, changed by me to be a session option rather
than a window option.


# 1.38 01-Sep-2009 nicm

Use "Password:" with no space for password prompts and don't display a *s for
the password, like pretty much everything else. From martynas@ with minor
tweaks by me.


# 1.37 01-Sep-2009 nicm

Sort cases same as getopt argument, from martynas.


# 1.36 31-Aug-2009 nicm

Add a new display-panes command, with two options (display-panes-colour and
display-panes-time), which displays a visual indication of the number of each
pane.


# 1.35 23-Aug-2009 nicm

Add some other obvious variables to update-environment (WINDOWID SSH_ASKPASS
SSH_AUTH_SOCK SSH_AGENT_PID SSH_CONNECTION) so they are updated in the session
environment on new/attach.


# 1.34 13-Aug-2009 nicm

Disable mode-mouse (mouse in copy/choice mode) by default as it isn't very
useful at the moment and causes confusion.


# 1.33 13-Aug-2009 nicm

Add a base-index session option to specify the first index checked when looking
for an index for a new window.


# 1.32 12-Aug-2009 nicm

When started as the shell, __progname contains a leading -, so hardcode "tmux"
for socket path and log files, and strip it when working out the shell.


# 1.31 11-Aug-2009 nicm

Switch tmux to use imsg. This is the last major change to make the
client-server protocol more resilient and make the protocol versioning work
properly. In future, the only things requiring a protocol version bump will be
changes in the message structs, and (when both client and server have this
change) mixing different versions should nicely report an error message.

As a side effect this also makes the code tidier, fixes a problem with the way
errors reported during server startup were handled, and supports fd passing
(which will be used in future).

Looked over by eric@, thanks.

Please note that mixing a client with this change with an older server or vice
versa may cause tmux to crash or hang - tmux should be completely exited before
upgrading.


# 1.30 10-Aug-2009 nicm

No arguments are the same as new-session and this requires the environment to
be sent, so set that flag too when argc == 0.


# 1.29 08-Aug-2009 nicm

Infrastructure and commands to manage the environment for processes started
within tmux.

There is a global environment, copied from the external environment when the
server is started and each sesssion has an (initially empty) session
environment which overrides it.

New commands set-environment and show-environment manipulate or display the
environments.

A new session option, update-environment, is a space-separated list of
variables which are updated from the external environment into the session
environment every time a new session is created - the default is DISPLAY.


# 1.28 08-Aug-2009 nicm

Options to set the colours and attributes for status-left/-right. From Thomas
Adam, thanks.


# 1.27 05-Aug-2009 nicm

If colours are not supported by the terminal, try to emulate a coloured
background by setting or clearing the reverse attribute.

This makes a few applications which don't use the reverse attribute themselves
a little happier, and allows the status, message and mode options to have
default attributes and fg/bg options that work as expected when set as reverse.


# 1.26 04-Aug-2009 nicm

Check for "UTF8" as well as "UTF-8" in LANG etc as it seems this may also
appear.


# 1.25 03-Aug-2009 nicm

Add a terminal-overrides session option allowing individual terminfo(5) entries
to be overridden. The 88col/256col checks are now moved into the default
setting and out of the code.

Also remove a couple of old workarounds for xterm and rxvt which are no longer
necessary (tmux can emulate them if missing).


# 1.24 30-Jul-2009 nicm

Add a mode-mouse option to prevent tmux taking over the mouse in choice or copy
modes.


# 1.23 29-Jul-2009 nicm

Rename struct hdrtype to msgtype which is a better name and can be used even
when struct hdr disappears.


# 1.22 29-Jul-2009 nicm

Taking account of the "s, 22 not 24 is the maximum length of #T in status-right
to prevent the date being cut off.


# 1.21 26-Jul-2009 nicm

Make all messages sent between the client and server fixed size.

This is the first of two changes to make the protocol more resilient and less
sensitive to other changes in the code, particularly with commands. The client
now packs argv into a buffer and sends it to the server for parsing, rather
than doing it itself and sending the parsed command data.

As a side-effect this also removes a lot of now-unused command marshalling
code.

Mixing a server without this change and a client with or vice versa will cause
tmux to hang or crash, please ensure that tmux is entirely killed before
upgrading.


# 1.20 22-Jul-2009 nicm

Pass a set of flags into client_init rather than just a start_server
variable. Only one flag now but more to come later.


# 1.19 20-Jul-2009 nicm

Display the number of failed password attempts (if any) when the server is
locked. From Tom Doherty.


# 1.18 20-Jul-2009 nicm

Add a status-justify option to allow the window list in the status line to be
positioned at the left, centre, or right.


# 1.17 20-Jul-2009 nicm

New options, window-status-current-{fg,bg,attr}, to set the fg, bg and
attributes with which the current window is shown in the status line. From
Johan Friis, thanks.


# 1.16 18-Jul-2009 nicm

Add three new session options: visual-activity, visual-bell, visual-content. If
these are enabled (and the monitor-activity, bell-actio and monitor-content
options are configurated appropriately), when activity, a bell, or content is
detected, a message is shown.

Also tidy up the bell/activity/content code in server.c slightly and fix a
couple of errors.


# 1.15 17-Jul-2009 nicm

If -u is specified or UTF-8 is otherwise detected when the server is started,
enable the utf8 and status-utf8 optons. While here, note in the man page that
the server is started with the first session and exits when none remain.


# 1.14 10-Jul-2009 nicm

Add a default-terminal option to set the starting value of $TERM in new
windows.

This is "screen" by default and must be either that or something closely
related. This does makes it easier to customise it if necessary.


# 1.13 08-Jul-2009 nicm

Just appending -l to $SHELL to create a login shell is wrong: -l is not POSIX,
and some people may use shells which do not support it. Instead, make an empty
default-command option mean a login shell, and fork it with a - in argv[0]
which is the method used by login(1).

Also fix the automatic-rename code to handle this correctly and to strip a
leading - if present.


# 1.12 07-Jul-2009 nicm

Rename the global options variables to be shorter and to make session options
clear. No functional change, getting this out of the way to make later options
changes easier.


Revision tags: OPENBSD_4_6_BASE
# 1.11 25-Jun-2009 nicm

If getcwd() fails, use the user's home directory, or /, instead of failing with
an error.


# 1.10 25-Jun-2009 nicm

Remove error about using -L and -S together which was never displayed as
logging wasn't yet enabled, was unnecessary, and contradicted the man page
which says using -S will cause -L to be ignored.


# 1.9 23-Jun-2009 nicm

LC_ALL overrides LC_CTYPE and LANG. Comment was correct but the code
wrong. Pointed out by Hannah Schroeter, thanks.


# 1.8 05-Jun-2009 nicm

Check the first of LC_CTYPE, LC_ALL and LANG, rather than just the last, when
trying to decide about UTF-8, and use strcasestr. Reported by Geert Hendrickx.


# 1.7 04-Jun-2009 nicm

Zero the password given to -U in the client as well.


# 1.6 03-Jun-2009 nicm

Do not set the window title by default (make set-titles option default to off),
wiping over the title is rude and annoying. Agreed by several.


# 1.5 03-Jun-2009 nicm

New session option, status-utf8, to control the interpretation of top-bit-set
characters in status-left and status-right (if on, they are treated as UTF-8;
otherwise passed through).


# 1.4 02-Jun-2009 sobrado

remove unused flag; while here, make usage's output fit on 80-column displays.


# 1.3 02-Jun-2009 pyr

spawn login shells by default, adapt manpage bits as well.
ok nicm@


# 1.2 02-Jun-2009 ray

Don't leak memory if multiple -f flags are given.

OK nicm@


# 1.1 01-Jun-2009 nicm

Import tmux, a terminal multiplexor allowing (among other things) a single
terminal to be switched between several different windows and programs
displayed on one terminal be detached from one terminal and moved to another.

ok deraadt pirofti


# 1.207 10-Jun-2021 nicm

Do not expand the file given with -f so it can contain :s.


Revision tags: OPENBSD_6_9_BASE
# 1.206 22-Feb-2021 nicm

expand_paths needs the global environment to be set up, do that first.


# 1.205 22-Feb-2021 nicm

Move config file path expansion much earlier, keep the list of paths
around rather than freeing later, and add a config_files format variable
containing it. Suggested by kn@ a while back.


# 1.204 17-Jan-2021 nicm

Add -N flag to never start server even if command would normally do so,
GitHub issue 2523.


Revision tags: OPENBSD_6_8_BASE
# 1.203 22-Sep-2020 nicm

Fix warnings on some platforms with %llx and add a new message to handle
64-bit client flags.


# 1.202 02-Jun-2020 nicm

Use CLOCK_MONOTONIC for timer measurement and add a timestamp to control
mode %output blocks.


# 1.201 16-May-2020 nicm

Add a -D flag to ask tmux not to daemonize, useful both for running a
debugger (lldb does not have follow-fork-mode) and for running with a
managed supervisor init system. GitHub issue 2190.


# 1.200 16-May-2020 nicm

Add 'e' key in buffer mode to open the buffer in an editor.


# 1.199 16-May-2020 nicm

Build list of paths and weed out duplicates before loading configs, and
add TMUX_SOCK like TMUX_PATH for the socket directory.


Revision tags: OPENBSD_6_7_BASE
# 1.198 20-Apr-2020 nicm

Tidy up the terminal detection and feature code and add named sets of
terminal features, each of which are defined in one place and map to a
builtin set of terminfo(5) capabilities. Features can be specified based
on TERM with a new terminal-features option or with the -T flag when
running tmux. tmux will also detect a few common terminals from the DA
and DSR responses.

This is intended to make it easier to configure tmux's use of
terminfo(5) even in the presence of outdated ncurses(3) or terminfo(5)
databases or for features which do not yet have a terminfo(5) entry.
Instead of having to grok terminfo(5) capability names and what they
should be set to in the terminal-overrides option, the user can
hopefully just give tmux a feature name and let it do the right thing.

The terminal-overrides option remains both for backwards compatibility
and to allow tweaks of individual capabilities.

tmux already did much of this already, this makes it tidier and simpler
to configure.


# 1.197 16-Apr-2020 nicm

Show signal name when process exits rather than number.


# 1.196 09-Apr-2020 nicm

More style nits.


# 1.195 31-Mar-2020 nicm

Add a way to mark environment variables as "hidden" so they can be used
by tmux but are not passed into the environment of new panes.


# 1.194 17-Mar-2020 nicm

Ignore default-shell (and use /bin/sh) if it invalid not just if it is
tmux itself, also refuse to set the option to something invalid in the
first place. GitHub issue 2120.


# 1.193 12-Mar-2020 nicm

When the server socket is given by the user with -S, create it with
umask 177 instead of 117 because it may not be in a safe directory like
the default directory in /tmp. The user can chmod it more open after it
is created if they want.


# 1.192 28-Jan-2020 nicm

-V also needs to go in usage.


# 1.191 28-Jan-2020 nicm

Reduce a difference with portable tmux by adding the -V flag and
#{version} format; on OpenBSD these just report the OpenBSD version.


# 1.190 14-Oct-2019 nicm

Memory leaks, from Igor Wong in GitHub issue 1934.


Revision tags: OPENBSD_6_6_BASE
# 1.189 20-Jun-2019 nicm

Add a per-pane option set. Pane options inherit from window options (so
there should be no change to existing behaviour) and are set and shown
with set-option -p and show-options -p.

Change remain-on-exit and window-style/window-active-style to be pane
options (some others will be changed later).

This makes select-pane -P and -g unnecessary so no longer document them
(they still work) and no longer document set-window-option and
show-window-options in favour of set-option -w and show-options -w.


# 1.188 26-Apr-2019 nicm

Merge hooks into options and make each one an array option. This allows
multiple commands to be easily bound to one hook. set-hook and
show-hooks remain but they are now variants of set-option and
show-options. show-options now has a -H flag to show hooks (by default
they are not shown).


Revision tags: OPENBSD_6_5_BASE
# 1.187 22-Nov-2018 nicm

Do not use PWD unless it actually matches the real working directory.


Revision tags: OPENBSD_6_3_BASE OPENBSD_6_4_BASE
# 1.186 12-Jan-2018 nicm

Improve error message if creating socket parent directory fails, from
Thomas Adam for GitHub issue 1215.


# 1.185 01-Jan-2018 nicm

Prefer PWD for current directory if present in client, from Wei Zhao in
GitHub issue 1183.


Revision tags: OPENBSD_6_2_BASE
# 1.184 12-Jul-2017 nicm

Make shell_command a global like other stuff rather than making it an
exception and using callback argument.


# 1.183 03-Jul-2017 nicm

Try C.UTF-8 which is also a commonly useful locale on some platforms,
from Romain Francoise.


# 1.182 22-Apr-2017 nicm

Do not need getopt.h.


# 1.181 20-Apr-2017 nicm

Use fdforkpty() instead of our own unwrapped versions.


# 1.180 19-Apr-2017 nicm

Style nits and a missing cast.


# 1.179 16-Apr-2017 nicm

Memory leak, from David CARLIER.


Revision tags: OPENBSD_6_1_BASE
# 1.178 21-Mar-2017 nicm

Use uid_t for UID not u_int.


# 1.177 16-Feb-2017 nicm

Style nits.


# 1.176 23-Jan-2017 nicm

Open /dev/ptm before pledge() and save it to be used for PTMGET later
(this means inlining forkpty()).

ok deraadt


# 1.175 15-Jan-2017 nicm

Major tidy up and rework of options tree and set-option/show-options
commands this pushes more of the code into options.c and ties it more
closely to the options table rather than having an unnecessary
split. Also add support for array options (will be used later). Only
(intentional) user visible change is that show-options output is now
passed through vis(3) with VIS_DQ so quotes are escaped.


# 1.174 12-Jan-2017 nicm

Simplify appending to string options.


# 1.173 09-Dec-2016 nicm

Spacing nits.


# 1.172 11-Oct-2016 nicm

Add static in window-*.c and move some internal functions out of tmux.h.


# 1.171 10-Oct-2016 nicm

Loads more static, except for cmd-*.c and window-*.c.


Revision tags: OPENBSD_6_0_BASE
# 1.170 27-May-2016 nicm

Use getprogname() instead of __progname to make portability easier.


# 1.169 04-May-2016 nicm

Fix up a couple of long lines.


# 1.168 05-Mar-2016 nicm

If setlocale("en_US.UTF-8") succeeds, then don't do the check for UTF-8
locale since if it isn't UTF-8 the system is broken anyway. If it fails,
try "" and check for UTF-8 with nl_langinfo(CODESET) rather than
wcwidth(). Based on a diff from schwarze@, nl_langinfo also suggested by
stsp@.


# 1.167 05-Mar-2016 nicm

Although we always have en_US.UTF-8 on OpenBSD, some platforms do not,
so fall back to setlocale(LC_CTYPE, ""). tmux requires a UTF-8 locale,
so check with wcwidth() on a UTF-8 character after setlocale().


# 1.166 01-Mar-2016 nicm

Remove unused variables, from Michal Mazurek.


# 1.165 01-Mar-2016 nicm

Use system wcwidth() instead of carrying around UTF-8 width tables.


Revision tags: OPENBSD_5_9_BASE
# 1.164 19-Jan-2016 nicm

I no longer use my SourceForge address so replace it.


# 1.163 08-Dec-2015 nicm

Add hooks infrastructure, basic commands (set-hook, show-hooks) and a
couple of not very useful client hooks. This will eventually let
commands be run at various points and on notifications. Joint work with
Thomas Adam.


# 1.162 24-Nov-2015 nicm

Make environ_set va_args and use it to tidy up some calls. Also add a
missing word in manpage (from jmc).


# 1.161 24-Nov-2015 nicm

Shell command from -c doesn't have to be global, pass it as an argument.


# 1.160 24-Nov-2015 nicm

Tidy the code that works out the socket path, and just use the full path
in the global socket_path rather than copying it.


# 1.159 24-Nov-2015 nicm

Remove malloc_options DEBUG bit.


# 1.158 24-Nov-2015 nicm

Remove the -I part of show-messages which isn't really that useful; the
server start time can now be accessed with a new start_time format (use:
tmux display -p '#{t:start_time}')


# 1.157 24-Nov-2015 nicm

Make the log stuff a bit tidier with some helper functions.


# 1.156 22-Nov-2015 nicm

Add getpw to pledge, makes tmux work in YP environments, discovered by
matthieu, ok deraadt


# 1.155 20-Nov-2015 nicm

Instead of separate tables for different types of options, give each
option a scope type (server, session, window) in one table.


# 1.154 15-Nov-2015 nicm

Accidentally turned off pledge, turn it back on.


# 1.153 14-Nov-2015 nicm

Push stdout and stderr to clients more aggressively, and add an event to
continue if the send fails.


# 1.152 12-Nov-2015 nicm

tmux is UTF-8, so if $TMUX is set (tmux running in tmux), the client is
UTF-8. Also try to make the existing checks more readable.


# 1.151 12-Nov-2015 nicm

Nuke the utf8 and status-utf8 options and make tmux only a UTF-8
terminal. We still support non-UTF-8 terminals outside tmux, but inside
it is always UTF-8 (as when the utf8 and status-utf8 options were on).


# 1.150 11-Nov-2015 nicm

Drop mouse-utf8 option and always turn on UTF-8 mouse if the client says
it supports UTF-8.


# 1.149 28-Oct-2015 nicm

Like options, move the environ struct into environ.c.


# 1.148 27-Oct-2015 nicm

Move struct options into options.c.


# 1.147 27-Oct-2015 nicm

Break the common process set up, event loop and imsg dispatch code
between server and client out into a separate internal API. This will
make it easier to add another process.


# 1.146 25-Oct-2015 deraadt

Let's see if anyone screams about not being able to specify $TMPDIR
for their tmux sockets.

(Over the years, I have seen $TMPDIR set up worse than /tmp many times,
and don't know how this practice infected other parts of the system.
Nothing uses tmpdir(3), nor a huge-temporary-file program like sort.)
ok nicm


# 1.145 23-Oct-2015 nicm

tmux can call pledge() in main with large set and then reduce it
slightly in the server to "stdio rpath wpath cpath fattr unix recvfd
proc exec tty ps".


# 1.144 14-Sep-2015 nicm

Move tzset() from log_open to main.


# 1.143 03-Sep-2015 nicm

A couple of style nits.


# 1.142 01-Sep-2015 nicm

Work out config file when needed not at startup.


# 1.141 30-Aug-2015 nicm

Path from $TMUX does not need to be global anymore.


# 1.140 30-Aug-2015 nicm

Login shell can be a client flag, and move the exec code into client.c.


# 1.139 30-Aug-2015 nicm

Event base does not need to be global.


# 1.138 30-Aug-2015 nicm

Some style nits and dead assignments.


Revision tags: OPENBSD_5_8_BASE
# 1.137 20-Jul-2015 nicm

Add an option (history-file) for a file to save/restore command prompt
history, from Olof-Joachim Frahm.


# 1.136 04-Jun-2015 jmc

tweak SYNOPSIS and usage();


Revision tags: OPENBSD_5_7_BASE
# 1.135 19-Jan-2015 nicm

Make a tmux-%u directory under TMUX_TMPDIR, like TMPDIR.


# 1.134 19-Jan-2015 nicm

Only care about other permissions, allow group to be set.


# 1.133 19-Jan-2015 nicm

Remove unnecessary duplicate S_ISDIR check, from Dmitri Paduchikh.


# 1.132 20-Oct-2014 nicm

Tidy up some includes.


Revision tags: OPENBSD_5_6_BASE
# 1.131 17-Apr-2014 nicm

Remove the "info" message mechanism, this was only used for about five
mostly useless and annoying messages. Change those commands to silence
on success like all the others. Still accept the -q command line flag
and "quiet" server option for now.


# 1.130 31-Mar-2014 nicm

Remove log_debug2 as well and simplify log.c.


Revision tags: OPENBSD_5_5_BASE
# 1.129 16-Feb-2014 nicm

Leftovers from removing 88 colour support, from Theo Buehler.


# 1.128 15-Jan-2014 nicm

Do not attempt to read .tmux.conf if we can't figure out a home
directory, from Tiago Cunha.


# 1.127 09-Jan-2014 nicm

Three small changes from Tiago Cunha:

- Check for truncation when copying path.
- Don't need to use a temporary buffer in screen_set_title.
- Include strerror in output when connecting to server fails.


# 1.126 10-Oct-2013 nicm

We accidentally haven't been using $TMUX to work out the session for a
while and in fact it is less useful that using the client ttyname. So
don't bother and don't pass it from the client. If we need it in future
it is in c->environ.


# 1.125 10-Oct-2013 nicm

Alter how tmux handles the working directory to internally use file
descriptors rather than strings.

- Each session still has a current working directory.

- New sessions still get their working directory from the client that
created them or its attached session if any.

- New windows are created by default in the session working directory.

- The -c flag to new, neww, splitw allows the working directory to be
overridden.

- The -c flag to attach let's the session working directory be changed.

- The default-path option has been removed.

To get the equivalent to default-path '.', do:

bind c neww -c $PWD

To get the equivalent of default-path '~', do:

bind c neww -c ~

This also changes the client identify protocol to be a set of messages rather
than one as well as some other changes that should make it easier to make
backwards-compatible protocol changes in future.


# 1.124 10-Oct-2013 nicm

Merge IDENTIFY_* flags with CLIENT_* flags.


# 1.123 10-Oct-2013 nicm

Don't treat TMUX_TMPDIR as a potential file

The point of setting TMUX_TMPDIR is to then make any labels from -L go
to that directory. In the case of makesocketpath() with no TMUX_TMPDIR
set, would set both the path and the default socket to a file. The
checking of the permissions on the file worked fine in that case, but
when TMUX_TMPDIR is set, won't work on a directory.

This fixes the problem by ensuring the check on the permissions is
performed on directories only.

By Thomas Adam.


# 1.122 05-Oct-2013 nicm

Fix previous not to leak fd on failure, whoops.


# 1.121 05-Oct-2013 nicm

Use open(".")/fchdir() to save and restore current directory rather than
getcwd()/chdir().


Revision tags: OPENBSD_5_4_BASE
# 1.120 24-Apr-2013 nicm

Rename global configuration define.


# 1.119 11-Apr-2013 nicm

Call setlocale(LC_TIME) at startup.


# 1.118 27-Mar-2013 nicm

Add TMUX_TMPDIR variable to put the socket directory outside
TMPDIR. From Ben Boeckel.


# 1.117 27-Mar-2013 nicm

Remove tmux's (already minimal) 88 colour support. Such terminals are
few and unnecessary.


# 1.116 25-Mar-2013 nicm

Rename session idx to session id throughout and add $ prefix to targets
to use it, extended from a diff from George Nachman.


# 1.115 24-Mar-2013 nicm

Add a command queue to standardize and simplify commands that call other
commands and allow a command to block execution of subsequent
commands. This allows run-shell and if-shell to be synchronous which has
been much requested.

Each client has a default command queue and commands are consumed one at
a time from it. A command may suspend execution from the queue by
returning CMD_RETURN_WAIT and then resume it by calling cmd_continue() -
for example run-shell does this from the callback that is fired after
the job is freed.

When the command queue becomes empty, command clients are automatically
exited (unless attaching). A callback is also fired - this is used for
nested commands in, for example, if-shell which can block execution of
the client's cmdq until a new cmdq becomes empty.

Also merge all the old error/info/print functions together and lose the
old curclient/cmdclient distinction - a cmdq is bound to one client (or
none if in the configuration file), this is a command client if
c->session is NULL otherwise an attached client.


Revision tags: OPENBSD_5_3_BASE
# 1.114 27-Nov-2012 nicm

Correctly aggregate together errors from nested config files (with
source-file). Fix by Thomas Adam, reported by Sam Livingstone-Gray


# 1.113 26-Nov-2012 nicm

Call realpath earlier on the socket directory path rather than on the
socket file path because the latter may not exist yet and in that case
realpath is allowed to fail. From Romain Francoise.


Revision tags: OPENBSD_5_2_BASE
# 1.112 10-Jul-2012 nicm

xfree is not particularly helpful, remove it. From Thomas Adam.


# 1.111 18-Jun-2012 nicm

Add a skeleton mode to tmux (called "control mode") that let's tmux
commands be sent and output received on stdout. This can be used to
integrate with other terminal emulators and should allow some other
things to be made simpler later. More to come so doesn't do much yet and
deliberately not documented.


# 1.110 30-May-2012 nicm

Do not use stderr for log file and don't call log_close when not needed.


# 1.109 25-May-2012 nicm

Simplify logging and just fprintf(stderr, ...) for early errors.


Revision tags: OPENBSD_5_1_BASE
# 1.108 21-Jan-2012 nicm

Drop the ability to have a list of keys in the prefix in favour of two
separate options, prefix and prefix2. This simplifies the code and gets
rid the data options type which was only used for this one option.

Also add a -2 flag to send-prefix to send the secondary prefix key,
fixing a cause of minor irritation.

People who want three prefix keys are out of luck :-).


# 1.107 23-Oct-2011 nicm

Try to resolve relative paths for loadb and saveb (first using client
working directory if any then default-path or session wd).


# 1.106 23-Oct-2011 nicm

Ignore LC_ALL and LC_CTYPE if they are empty as well as unset.


# 1.105 25-Sep-2011 nicm

Reject $SHELL if it is not a full path.


Revision tags: OPENBSD_5_0_BASE
# 1.104 04-Mar-2011 nicm

Two fixes by Micah Cowan: make mouse work properly beyond >127 on signed
char architectures and properly parse $TMUX by stopping the socket path
at the first comma.


Revision tags: OPENBSD_4_9_BASE
# 1.103 23-Jan-2011 nicm

Set $TMUX without the session when background jobs are run.


# 1.102 12-Jan-2011 nicm

Use TMPDIR if set, from Han Boetes.


# 1.101 08-Jan-2011 nicm

Move all calls to fcntl(...O_NONBLOCK) into a function and clear the
flag on the stdio file descriptors before closing them (fixes things
like "tmux ls && cat").


# 1.100 03-Jan-2011 nicm

Support for UTF-8 mouse input (\033[1005h). This was added in xterm 262
and supports larger terminals than the older way.

If the new mouse-utf8 option is on, UTF-8 mouse input is enabled for all
UTF-8 terminals. The option defaults to on if LANG etc are set in the
same manner as the utf8 option.

With help and based on code from hsim at gmx.li.


# 1.99 01-Jan-2011 nicm

Move the user-visible parts of all options (names, types, limit, default
values) together into one set of tables in options-table.c. Also clean
up and simplify cmd-set-options.c and move a common print function into
option-table.c.


# 1.98 30-Dec-2010 nicm

Change from a per-session stack of buffers to one global stack which is
much more convenient and also simplifies lot of code. This renders
copy-buffer useless and makes buffer-limit now a server option.

By Tiago Cunha.


# 1.97 19-Dec-2010 nicm

Add other-pane-height and other-pane-width options, allowing the width
or height of the smaller panes in the main-horizontal and main-vertical
layouts to be set. Mostly from David Goodlad.


# 1.96 08-Dec-2010 nicm

In the built-in layouts, distribute the panes more evenly. Set the
default value of main-pane-width to 80, rather than 81. By Micah Cowan.


# 1.95 06-Dec-2010 nicm

Add an option to alert (monitor) for silence (lack of activity) in a
window. From Thomas Adam.


# 1.94 29-Nov-2010 nicm

If VISUAL or EDITOR contains "vi", configure mode-keys and status-keys
to vi.

Based on a diff from martynas@, previously requested by a couple of
other people.


# 1.93 11-Nov-2010 nicm

Add XAUTHORITY to update-environment, requested by Andreas Kloeckner.


# 1.92 18-Oct-2010 nicm

Merge the before and after attach client code into one in client.c
(instead of two in tmux.c and client.c).


# 1.91 16-Oct-2010 nicm

Make stdio blocking again before calling shell command with -c.


# 1.90 16-Oct-2010 nicm

Trying to set FD_CLOEXEC on every fd is a lost cause, just use
closefrom() before exec.


# 1.89 14-Oct-2010 nicm

Use an explicit event rather than event_once for the main event so it
can be removed when the client becomes ready.


# 1.88 26-Sep-2010 nicm

Two new options:

- server option "exit-unattached" makes the server exit when no clients
are attached, even if sessions are present;

- session option "destroy-unattached" destroys a session once no clients
are attached to it.

These are useful for preventing tmux remaining in the background where
it is undesirable and when using tmux as a login shell to keep a limit
on new sessions.


# 1.87 19-Aug-2010 nicm

Do not call event_del() for signals after fork(), just use sigaction()
directly instead - calling libevent functions after fork() w/o
event_reinit() is a bad idea, even if in this case it was harmless.


Revision tags: OPENBSD_4_8_BASE
# 1.86 04-Aug-2010 deraadt

switch back to kqueue for now, since (a) kqueue has been fixed to deal
with strange devices and (b) since there appears to be a bull in the
poll code in libevent as well...
requested by nicm who is away


# 1.85 24-Jul-2010 nicm

kqueue(2) is currently broken when used with /dev/null and a few other
devices.

An upcoming fix for some problems with the client stdout/stderr handling
relies on it working, so make tmux force libevent to use poll(2) via
EVENT_NOKQUEUE, until we have fixed kqueue.


# 1.84 11-Jul-2010 nicm

Return the command client return code with MSG_EXIT now that MSG_ERROR and
MSG_PRINT are unused.

New clients should be compatible with old tmux servers but vice versa may print
an error.


# 1.83 28-Jun-2010 nicm

Send all three of stdin, stdout, stderr from the client to the server, so that
commands can directly make use of them. This means that load-buffer and
save-buffer can have "-" as the file to read from stdin or write to stdout.

This is a protocol version bump so the tmux server will need to be restarted
after upgrade (or an older client used).


# 1.82 27-Jun-2010 nicm

Store the current working directory in the session, change the default-path
option to default to empty and make that mean that the stored session CWD is
used.


# 1.81 27-Jun-2010 nicm

New option, detach-on-destroy, to set what happens to a client when the session
it is attached to is destroyed. If on (the default), it is detached; if off, it
is switched to the most recently active session.


# 1.80 26-Jun-2010 nicm

Setting the cmdlist pointer in the bind-key to NULL to prevent it being freed
after the command is executing is bogus because it may still be needed if the
same command is going to be executed again (for example if you "bind-key a
bind-key b ..."). Making a copy is hard, so instead add a reference count to
the cmd_list.

While here, also print bind-key -n and the rest of the flags properly.

Fixes problem reported by mcbride@.


# 1.79 14-May-2010 nicm

Colour+attribute options for status line alerts, from Alex Alexander.


# 1.78 04-May-2010 nicm

Put this back in with the initialisation in the right order.


# 1.77 04-May-2010 nicm

Revert last change, it appears to be broken somehow.


# 1.76 03-May-2010 nicm

Make signal handler setup/teardown two common functions instead of six,
and reset SIGCHLD after fork to fix problems with some shells. From
Romain Francois.


# 1.75 28-Apr-2010 nicm

Make the active pane border have a green foreground instead of
background by default.


# 1.74 18-Apr-2010 nicm

Catch SIGCHLD to avoid a zombie, from patrick keshishian.


Revision tags: OPENBSD_4_7_BASE
# 1.73 22-Feb-2010 nicm

Option to set the characters considered word separators in copy mode, from
Micah Cowan.


# 1.72 08-Feb-2010 nicm

Add an option to disable the smcup/rmcup alternate screen behaviour inside
tmux. From clemens fischer.


# 1.71 06-Feb-2010 nicm

Change nested check to compare server socket path rather than just assuming
that if $TMUX is set it is nested. From Micah Cowan.


# 1.70 06-Feb-2010 nicm

Clean up $TMUX parsing, from Micah Cowan, tweaked by me.


# 1.69 06-Feb-2010 nicm

Instead of bailing out on the first configuration file error, carry on,
collecting all the errors, then start with the active window in more mode
displaying them.


# 1.68 04-Feb-2010 nicm

Read the path from $TMUX if it is present and -L and -S are not given. Based on
a diff from Micah Cowan.


# 1.67 04-Feb-2010 nicm

Option to display the active pane in a different colour with the display-panes
command. From Paul Hoffman, thanks.


# 1.66 03-Jan-2010 nicm

Options to set the colour of the pane borders, with different colours for the
active pane.


# 1.65 14-Dec-2009 nicm

New server option, escape-time, to set the timeout used to detect if escapes
are alone or part of a function key or meta sequence.


# 1.64 11-Dec-2009 nicm

Use quiet variable, and add missing sentinel to options array.


# 1.63 10-Dec-2009 nicm

Add "server options" which are server-wide and not bound to a session or
window. Set and displayed with "set -s" and "show -s".

Currently the only option is "quiet" (like command-line -q, allowing it to be
set from .tmux.conf), but others will come along.


# 1.62 03-Dec-2009 nicm

Massive spaces->tabs and trailing whitespace cleanup, hopefully for the last
time now I've configured emacs to make them displayed in really annoying
colours...


# 1.61 26-Nov-2009 nicm

Remove a couple of unused arguments where possible, and add /* ARGSUSED */ to
the rest to reduce lint output.


# 1.60 19-Nov-2009 nicm

Two new options, window-status-format and window-status-current-format, which
allow the format of each window in the status line window list to be controlled
using similar # sequences as status-left/right.

This diff also moves part of the way towards UTF-8 support in window names but
it isn't quite there yet.


# 1.59 19-Nov-2009 nicm

Revert to xterm-keys off by default. It was on as an experiment to see if the
option could be removed, but it affects vi, so we have to keep the option, and
a conservative default is better.


# 1.58 18-Nov-2009 nicm

Add a per-client log of status line messages displayed while that client
exists. A new message-limit session option sets the maximum number of entries
and a command, show-messages, shows the log (bound to ~ by default).

This (and prompt history) might be better as a single global log but until
there are global options it is easier for them to be per client.


# 1.57 10-Nov-2009 nicm

There is no real standard for modifier plus function keys. Previously, tmux
output some from rxvt but in other ways did the same as xterm or other
terminals, but this is a bit inconsistent.

xterm's method is fairly sensible and we already support it (xterm-keys), so
enable it by default instead.


# 1.56 04-Nov-2009 nicm

A couple of minor cosmetic changes.


# 1.55 04-Nov-2009 nicm

Initial changes to move tmux to libevent.

This moves the client-side loops are pretty much fully over to event-based only
(tmux.c and client.c) but server-side (server.c and friends) treats libevent as
a sort of clever poll, waking up after every event to run various things.

Moving the server stuff over to bufferevents and timers and so on will come
later.


# 1.54 04-Nov-2009 nicm

Change declaration and use of malloc_options to be more standard, from Tim van
der Molen.


# 1.53 26-Oct-2009 deraadt

tabs are better; ok nicm


# 1.52 25-Oct-2009 nicm

Remove the -d flag to tmux and just use op/AX to detect default colours.

Irritatingly, although op can be used to tell if a terminal supports default
colours, it can't be used to set them because in some terminfo descriptions it
resets attributes as a side-effect (acts as sgr0) and in others it doesn't, so
it is not possible to determine reliably what the terminal state will be
afterwards. So if AX is missing and op is present, tmux just sends sgr0.

Anyone using -d for a terminal who finds they actually needed it can replace it
using terminal-overrides, but please let me know as it is probably an omission
from terminfo.


# 1.51 22-Oct-2009 nicm

Merge prepare_cmd into main as it is short and only called once.


# 1.50 21-Oct-2009 nicm

Client tidying: get rid of client_ctx struct in favour of two variables in
client.c, and move the functions in client-fn.c into other files.


# 1.49 10-Oct-2009 nicm

New option, mouse-select-pane. If on, the mouse may be used to select the
current pane.

Suggested by sthen@ and also by someone else ages ago who I have forgotten.


# 1.48 10-Oct-2009 nicm

Support for individual session idle time locking. May be enabled by turning off
the lock-server option (it is on by default). When this is off, each session
locks when it has been idle for the lock-after-time setting. When on, the
entire server locks when ALL sessions have been idle for their individual
lock-after-time settings.

This replaces one global-only option (lock-after-time) with another
(lock-server), but the default behaviour is usually preferable so there don't
seem to be many alternatives.

Diff/idea largely from Thomas Adam, tweaked by me.


# 1.47 09-Oct-2009 nicm

Add a simple synchronize-panes window option: when set, all input to any pane
that is part of the window is also sent to all other panes in the same
window. Suggested by several, most recently Tomasz Pajor.


# 1.46 23-Sep-2009 nicm

Support -c like sh(1) to execute a command, useful when tmux is a login
shell. Suggested by halex@.

This includes another protocol version increase (the last for now) so again
restart the tmux server before upgrading.


# 1.45 23-Sep-2009 nicm

Remove the internal tmux locking and instead detach each client and run the
command specified by a new option "lock-command" (by default "lock -np") in
each client.

This means each terminal has to be unlocked individually but simplifies the
code and allows the system password to be used to unlock.

Note that the set-password command is gone, so it will need to be removed from
configuration files, and the -U command line flag has been removed.

This is the third protocol version change so again it is best to stop the tmux
server before upgrading.


# 1.44 22-Sep-2009 nicm

Permit multiple prefix keys to be defined, separated by commas, for example:

set -g prefix ^a,^b

Any key in the list acts as the prefix. The send-prefix command always sends
the first key in the list.


# 1.43 18-Sep-2009 nicm

New option, set-titles-string, to allow the window title to be specified (as
for status-left/right) if set-titles is on. Also only update the title when the
status line is being redrawn.


# 1.42 04-Sep-2009 nicm

Tidy main and make it a bit easier to read.


# 1.41 02-Sep-2009 nicm

Accept -l to make it easier for people who use tmux as a login shell to use
$SHELL. Originally from martynas@, tweaked by me.


# 1.40 02-Sep-2009 nicm

When incorrect passwords are entered, behave similarly to login(1) and backoff
for a bit. Based on a diff from martynas@.


# 1.39 01-Sep-2009 nicm

When using tmux as a login shell, there is currently no way to specify a shell
to be used as a login shell inside tmux, so add a default-shell session option.
This sets the shell invoked as a login shell when the default-command option is
empty.

The default option value is whichever of $SHELL, getpwuid(getuid())'s pw_shell
or /bin/sh is valid first.

Based on a diff from martynas@, changed by me to be a session option rather
than a window option.


# 1.38 01-Sep-2009 nicm

Use "Password:" with no space for password prompts and don't display a *s for
the password, like pretty much everything else. From martynas@ with minor
tweaks by me.


# 1.37 01-Sep-2009 nicm

Sort cases same as getopt argument, from martynas.


# 1.36 31-Aug-2009 nicm

Add a new display-panes command, with two options (display-panes-colour and
display-panes-time), which displays a visual indication of the number of each
pane.


# 1.35 23-Aug-2009 nicm

Add some other obvious variables to update-environment (WINDOWID SSH_ASKPASS
SSH_AUTH_SOCK SSH_AGENT_PID SSH_CONNECTION) so they are updated in the session
environment on new/attach.


# 1.34 13-Aug-2009 nicm

Disable mode-mouse (mouse in copy/choice mode) by default as it isn't very
useful at the moment and causes confusion.


# 1.33 13-Aug-2009 nicm

Add a base-index session option to specify the first index checked when looking
for an index for a new window.


# 1.32 12-Aug-2009 nicm

When started as the shell, __progname contains a leading -, so hardcode "tmux"
for socket path and log files, and strip it when working out the shell.


# 1.31 11-Aug-2009 nicm

Switch tmux to use imsg. This is the last major change to make the
client-server protocol more resilient and make the protocol versioning work
properly. In future, the only things requiring a protocol version bump will be
changes in the message structs, and (when both client and server have this
change) mixing different versions should nicely report an error message.

As a side effect this also makes the code tidier, fixes a problem with the way
errors reported during server startup were handled, and supports fd passing
(which will be used in future).

Looked over by eric@, thanks.

Please note that mixing a client with this change with an older server or vice
versa may cause tmux to crash or hang - tmux should be completely exited before
upgrading.


# 1.30 10-Aug-2009 nicm

No arguments are the same as new-session and this requires the environment to
be sent, so set that flag too when argc == 0.


# 1.29 08-Aug-2009 nicm

Infrastructure and commands to manage the environment for processes started
within tmux.

There is a global environment, copied from the external environment when the
server is started and each sesssion has an (initially empty) session
environment which overrides it.

New commands set-environment and show-environment manipulate or display the
environments.

A new session option, update-environment, is a space-separated list of
variables which are updated from the external environment into the session
environment every time a new session is created - the default is DISPLAY.


# 1.28 08-Aug-2009 nicm

Options to set the colours and attributes for status-left/-right. From Thomas
Adam, thanks.


# 1.27 05-Aug-2009 nicm

If colours are not supported by the terminal, try to emulate a coloured
background by setting or clearing the reverse attribute.

This makes a few applications which don't use the reverse attribute themselves
a little happier, and allows the status, message and mode options to have
default attributes and fg/bg options that work as expected when set as reverse.


# 1.26 04-Aug-2009 nicm

Check for "UTF8" as well as "UTF-8" in LANG etc as it seems this may also
appear.


# 1.25 03-Aug-2009 nicm

Add a terminal-overrides session option allowing individual terminfo(5) entries
to be overridden. The 88col/256col checks are now moved into the default
setting and out of the code.

Also remove a couple of old workarounds for xterm and rxvt which are no longer
necessary (tmux can emulate them if missing).


# 1.24 30-Jul-2009 nicm

Add a mode-mouse option to prevent tmux taking over the mouse in choice or copy
modes.


# 1.23 29-Jul-2009 nicm

Rename struct hdrtype to msgtype which is a better name and can be used even
when struct hdr disappears.


# 1.22 29-Jul-2009 nicm

Taking account of the "s, 22 not 24 is the maximum length of #T in status-right
to prevent the date being cut off.


# 1.21 26-Jul-2009 nicm

Make all messages sent between the client and server fixed size.

This is the first of two changes to make the protocol more resilient and less
sensitive to other changes in the code, particularly with commands. The client
now packs argv into a buffer and sends it to the server for parsing, rather
than doing it itself and sending the parsed command data.

As a side-effect this also removes a lot of now-unused command marshalling
code.

Mixing a server without this change and a client with or vice versa will cause
tmux to hang or crash, please ensure that tmux is entirely killed before
upgrading.


# 1.20 22-Jul-2009 nicm

Pass a set of flags into client_init rather than just a start_server
variable. Only one flag now but more to come later.


# 1.19 20-Jul-2009 nicm

Display the number of failed password attempts (if any) when the server is
locked. From Tom Doherty.


# 1.18 20-Jul-2009 nicm

Add a status-justify option to allow the window list in the status line to be
positioned at the left, centre, or right.


# 1.17 20-Jul-2009 nicm

New options, window-status-current-{fg,bg,attr}, to set the fg, bg and
attributes with which the current window is shown in the status line. From
Johan Friis, thanks.


# 1.16 18-Jul-2009 nicm

Add three new session options: visual-activity, visual-bell, visual-content. If
these are enabled (and the monitor-activity, bell-actio and monitor-content
options are configurated appropriately), when activity, a bell, or content is
detected, a message is shown.

Also tidy up the bell/activity/content code in server.c slightly and fix a
couple of errors.


# 1.15 17-Jul-2009 nicm

If -u is specified or UTF-8 is otherwise detected when the server is started,
enable the utf8 and status-utf8 optons. While here, note in the man page that
the server is started with the first session and exits when none remain.


# 1.14 10-Jul-2009 nicm

Add a default-terminal option to set the starting value of $TERM in new
windows.

This is "screen" by default and must be either that or something closely
related. This does makes it easier to customise it if necessary.


# 1.13 08-Jul-2009 nicm

Just appending -l to $SHELL to create a login shell is wrong: -l is not POSIX,
and some people may use shells which do not support it. Instead, make an empty
default-command option mean a login shell, and fork it with a - in argv[0]
which is the method used by login(1).

Also fix the automatic-rename code to handle this correctly and to strip a
leading - if present.


# 1.12 07-Jul-2009 nicm

Rename the global options variables to be shorter and to make session options
clear. No functional change, getting this out of the way to make later options
changes easier.


Revision tags: OPENBSD_4_6_BASE
# 1.11 25-Jun-2009 nicm

If getcwd() fails, use the user's home directory, or /, instead of failing with
an error.


# 1.10 25-Jun-2009 nicm

Remove error about using -L and -S together which was never displayed as
logging wasn't yet enabled, was unnecessary, and contradicted the man page
which says using -S will cause -L to be ignored.


# 1.9 23-Jun-2009 nicm

LC_ALL overrides LC_CTYPE and LANG. Comment was correct but the code
wrong. Pointed out by Hannah Schroeter, thanks.


# 1.8 05-Jun-2009 nicm

Check the first of LC_CTYPE, LC_ALL and LANG, rather than just the last, when
trying to decide about UTF-8, and use strcasestr. Reported by Geert Hendrickx.


# 1.7 04-Jun-2009 nicm

Zero the password given to -U in the client as well.


# 1.6 03-Jun-2009 nicm

Do not set the window title by default (make set-titles option default to off),
wiping over the title is rude and annoying. Agreed by several.


# 1.5 03-Jun-2009 nicm

New session option, status-utf8, to control the interpretation of top-bit-set
characters in status-left and status-right (if on, they are treated as UTF-8;
otherwise passed through).


# 1.4 02-Jun-2009 sobrado

remove unused flag; while here, make usage's output fit on 80-column displays.


# 1.3 02-Jun-2009 pyr

spawn login shells by default, adapt manpage bits as well.
ok nicm@


# 1.2 02-Jun-2009 ray

Don't leak memory if multiple -f flags are given.

OK nicm@


# 1.1 01-Jun-2009 nicm

Import tmux, a terminal multiplexor allowing (among other things) a single
terminal to be switched between several different windows and programs
displayed on one terminal be detached from one terminal and moved to another.

ok deraadt pirofti


# 1.206 22-Feb-2021 nicm

expand_paths needs the global environment to be set up, do that first.


# 1.205 22-Feb-2021 nicm

Move config file path expansion much earlier, keep the list of paths
around rather than freeing later, and add a config_files format variable
containing it. Suggested by kn@ a while back.


# 1.204 17-Jan-2021 nicm

Add -N flag to never start server even if command would normally do so,
GitHub issue 2523.


Revision tags: OPENBSD_6_8_BASE
# 1.203 22-Sep-2020 nicm

Fix warnings on some platforms with %llx and add a new message to handle
64-bit client flags.


# 1.202 02-Jun-2020 nicm

Use CLOCK_MONOTONIC for timer measurement and add a timestamp to control
mode %output blocks.


# 1.201 16-May-2020 nicm

Add a -D flag to ask tmux not to daemonize, useful both for running a
debugger (lldb does not have follow-fork-mode) and for running with a
managed supervisor init system. GitHub issue 2190.


# 1.200 16-May-2020 nicm

Add 'e' key in buffer mode to open the buffer in an editor.


# 1.199 16-May-2020 nicm

Build list of paths and weed out duplicates before loading configs, and
add TMUX_SOCK like TMUX_PATH for the socket directory.


Revision tags: OPENBSD_6_7_BASE
# 1.198 20-Apr-2020 nicm

Tidy up the terminal detection and feature code and add named sets of
terminal features, each of which are defined in one place and map to a
builtin set of terminfo(5) capabilities. Features can be specified based
on TERM with a new terminal-features option or with the -T flag when
running tmux. tmux will also detect a few common terminals from the DA
and DSR responses.

This is intended to make it easier to configure tmux's use of
terminfo(5) even in the presence of outdated ncurses(3) or terminfo(5)
databases or for features which do not yet have a terminfo(5) entry.
Instead of having to grok terminfo(5) capability names and what they
should be set to in the terminal-overrides option, the user can
hopefully just give tmux a feature name and let it do the right thing.

The terminal-overrides option remains both for backwards compatibility
and to allow tweaks of individual capabilities.

tmux already did much of this already, this makes it tidier and simpler
to configure.


# 1.197 16-Apr-2020 nicm

Show signal name when process exits rather than number.


# 1.196 09-Apr-2020 nicm

More style nits.


# 1.195 31-Mar-2020 nicm

Add a way to mark environment variables as "hidden" so they can be used
by tmux but are not passed into the environment of new panes.


# 1.194 17-Mar-2020 nicm

Ignore default-shell (and use /bin/sh) if it invalid not just if it is
tmux itself, also refuse to set the option to something invalid in the
first place. GitHub issue 2120.


# 1.193 12-Mar-2020 nicm

When the server socket is given by the user with -S, create it with
umask 177 instead of 117 because it may not be in a safe directory like
the default directory in /tmp. The user can chmod it more open after it
is created if they want.


# 1.192 28-Jan-2020 nicm

-V also needs to go in usage.


# 1.191 28-Jan-2020 nicm

Reduce a difference with portable tmux by adding the -V flag and
#{version} format; on OpenBSD these just report the OpenBSD version.


# 1.190 14-Oct-2019 nicm

Memory leaks, from Igor Wong in GitHub issue 1934.


Revision tags: OPENBSD_6_6_BASE
# 1.189 20-Jun-2019 nicm

Add a per-pane option set. Pane options inherit from window options (so
there should be no change to existing behaviour) and are set and shown
with set-option -p and show-options -p.

Change remain-on-exit and window-style/window-active-style to be pane
options (some others will be changed later).

This makes select-pane -P and -g unnecessary so no longer document them
(they still work) and no longer document set-window-option and
show-window-options in favour of set-option -w and show-options -w.


# 1.188 26-Apr-2019 nicm

Merge hooks into options and make each one an array option. This allows
multiple commands to be easily bound to one hook. set-hook and
show-hooks remain but they are now variants of set-option and
show-options. show-options now has a -H flag to show hooks (by default
they are not shown).


Revision tags: OPENBSD_6_5_BASE
# 1.187 22-Nov-2018 nicm

Do not use PWD unless it actually matches the real working directory.


Revision tags: OPENBSD_6_3_BASE OPENBSD_6_4_BASE
# 1.186 12-Jan-2018 nicm

Improve error message if creating socket parent directory fails, from
Thomas Adam for GitHub issue 1215.


# 1.185 01-Jan-2018 nicm

Prefer PWD for current directory if present in client, from Wei Zhao in
GitHub issue 1183.


Revision tags: OPENBSD_6_2_BASE
# 1.184 12-Jul-2017 nicm

Make shell_command a global like other stuff rather than making it an
exception and using callback argument.


# 1.183 03-Jul-2017 nicm

Try C.UTF-8 which is also a commonly useful locale on some platforms,
from Romain Francoise.


# 1.182 22-Apr-2017 nicm

Do not need getopt.h.


# 1.181 20-Apr-2017 nicm

Use fdforkpty() instead of our own unwrapped versions.


# 1.180 19-Apr-2017 nicm

Style nits and a missing cast.


# 1.179 16-Apr-2017 nicm

Memory leak, from David CARLIER.


Revision tags: OPENBSD_6_1_BASE
# 1.178 21-Mar-2017 nicm

Use uid_t for UID not u_int.


# 1.177 16-Feb-2017 nicm

Style nits.


# 1.176 23-Jan-2017 nicm

Open /dev/ptm before pledge() and save it to be used for PTMGET later
(this means inlining forkpty()).

ok deraadt


# 1.175 15-Jan-2017 nicm

Major tidy up and rework of options tree and set-option/show-options
commands this pushes more of the code into options.c and ties it more
closely to the options table rather than having an unnecessary
split. Also add support for array options (will be used later). Only
(intentional) user visible change is that show-options output is now
passed through vis(3) with VIS_DQ so quotes are escaped.


# 1.174 12-Jan-2017 nicm

Simplify appending to string options.


# 1.173 09-Dec-2016 nicm

Spacing nits.


# 1.172 11-Oct-2016 nicm

Add static in window-*.c and move some internal functions out of tmux.h.


# 1.171 10-Oct-2016 nicm

Loads more static, except for cmd-*.c and window-*.c.


Revision tags: OPENBSD_6_0_BASE
# 1.170 27-May-2016 nicm

Use getprogname() instead of __progname to make portability easier.


# 1.169 04-May-2016 nicm

Fix up a couple of long lines.


# 1.168 05-Mar-2016 nicm

If setlocale("en_US.UTF-8") succeeds, then don't do the check for UTF-8
locale since if it isn't UTF-8 the system is broken anyway. If it fails,
try "" and check for UTF-8 with nl_langinfo(CODESET) rather than
wcwidth(). Based on a diff from schwarze@, nl_langinfo also suggested by
stsp@.


# 1.167 05-Mar-2016 nicm

Although we always have en_US.UTF-8 on OpenBSD, some platforms do not,
so fall back to setlocale(LC_CTYPE, ""). tmux requires a UTF-8 locale,
so check with wcwidth() on a UTF-8 character after setlocale().


# 1.166 01-Mar-2016 nicm

Remove unused variables, from Michal Mazurek.


# 1.165 01-Mar-2016 nicm

Use system wcwidth() instead of carrying around UTF-8 width tables.


Revision tags: OPENBSD_5_9_BASE
# 1.164 19-Jan-2016 nicm

I no longer use my SourceForge address so replace it.


# 1.163 08-Dec-2015 nicm

Add hooks infrastructure, basic commands (set-hook, show-hooks) and a
couple of not very useful client hooks. This will eventually let
commands be run at various points and on notifications. Joint work with
Thomas Adam.


# 1.162 24-Nov-2015 nicm

Make environ_set va_args and use it to tidy up some calls. Also add a
missing word in manpage (from jmc).


# 1.161 24-Nov-2015 nicm

Shell command from -c doesn't have to be global, pass it as an argument.


# 1.160 24-Nov-2015 nicm

Tidy the code that works out the socket path, and just use the full path
in the global socket_path rather than copying it.


# 1.159 24-Nov-2015 nicm

Remove malloc_options DEBUG bit.


# 1.158 24-Nov-2015 nicm

Remove the -I part of show-messages which isn't really that useful; the
server start time can now be accessed with a new start_time format (use:
tmux display -p '#{t:start_time}')


# 1.157 24-Nov-2015 nicm

Make the log stuff a bit tidier with some helper functions.


# 1.156 22-Nov-2015 nicm

Add getpw to pledge, makes tmux work in YP environments, discovered by
matthieu, ok deraadt


# 1.155 20-Nov-2015 nicm

Instead of separate tables for different types of options, give each
option a scope type (server, session, window) in one table.


# 1.154 15-Nov-2015 nicm

Accidentally turned off pledge, turn it back on.


# 1.153 14-Nov-2015 nicm

Push stdout and stderr to clients more aggressively, and add an event to
continue if the send fails.


# 1.152 12-Nov-2015 nicm

tmux is UTF-8, so if $TMUX is set (tmux running in tmux), the client is
UTF-8. Also try to make the existing checks more readable.


# 1.151 12-Nov-2015 nicm

Nuke the utf8 and status-utf8 options and make tmux only a UTF-8
terminal. We still support non-UTF-8 terminals outside tmux, but inside
it is always UTF-8 (as when the utf8 and status-utf8 options were on).


# 1.150 11-Nov-2015 nicm

Drop mouse-utf8 option and always turn on UTF-8 mouse if the client says
it supports UTF-8.


# 1.149 28-Oct-2015 nicm

Like options, move the environ struct into environ.c.


# 1.148 27-Oct-2015 nicm

Move struct options into options.c.


# 1.147 27-Oct-2015 nicm

Break the common process set up, event loop and imsg dispatch code
between server and client out into a separate internal API. This will
make it easier to add another process.


# 1.146 25-Oct-2015 deraadt

Let's see if anyone screams about not being able to specify $TMPDIR
for their tmux sockets.

(Over the years, I have seen $TMPDIR set up worse than /tmp many times,
and don't know how this practice infected other parts of the system.
Nothing uses tmpdir(3), nor a huge-temporary-file program like sort.)
ok nicm


# 1.145 23-Oct-2015 nicm

tmux can call pledge() in main with large set and then reduce it
slightly in the server to "stdio rpath wpath cpath fattr unix recvfd
proc exec tty ps".


# 1.144 14-Sep-2015 nicm

Move tzset() from log_open to main.


# 1.143 03-Sep-2015 nicm

A couple of style nits.


# 1.142 01-Sep-2015 nicm

Work out config file when needed not at startup.


# 1.141 30-Aug-2015 nicm

Path from $TMUX does not need to be global anymore.


# 1.140 30-Aug-2015 nicm

Login shell can be a client flag, and move the exec code into client.c.


# 1.139 30-Aug-2015 nicm

Event base does not need to be global.


# 1.138 30-Aug-2015 nicm

Some style nits and dead assignments.


Revision tags: OPENBSD_5_8_BASE
# 1.137 20-Jul-2015 nicm

Add an option (history-file) for a file to save/restore command prompt
history, from Olof-Joachim Frahm.


# 1.136 04-Jun-2015 jmc

tweak SYNOPSIS and usage();


Revision tags: OPENBSD_5_7_BASE
# 1.135 19-Jan-2015 nicm

Make a tmux-%u directory under TMUX_TMPDIR, like TMPDIR.


# 1.134 19-Jan-2015 nicm

Only care about other permissions, allow group to be set.


# 1.133 19-Jan-2015 nicm

Remove unnecessary duplicate S_ISDIR check, from Dmitri Paduchikh.


# 1.132 20-Oct-2014 nicm

Tidy up some includes.


Revision tags: OPENBSD_5_6_BASE
# 1.131 17-Apr-2014 nicm

Remove the "info" message mechanism, this was only used for about five
mostly useless and annoying messages. Change those commands to silence
on success like all the others. Still accept the -q command line flag
and "quiet" server option for now.


# 1.130 31-Mar-2014 nicm

Remove log_debug2 as well and simplify log.c.


Revision tags: OPENBSD_5_5_BASE
# 1.129 16-Feb-2014 nicm

Leftovers from removing 88 colour support, from Theo Buehler.


# 1.128 15-Jan-2014 nicm

Do not attempt to read .tmux.conf if we can't figure out a home
directory, from Tiago Cunha.


# 1.127 09-Jan-2014 nicm

Three small changes from Tiago Cunha:

- Check for truncation when copying path.
- Don't need to use a temporary buffer in screen_set_title.
- Include strerror in output when connecting to server fails.


# 1.126 10-Oct-2013 nicm

We accidentally haven't been using $TMUX to work out the session for a
while and in fact it is less useful that using the client ttyname. So
don't bother and don't pass it from the client. If we need it in future
it is in c->environ.


# 1.125 10-Oct-2013 nicm

Alter how tmux handles the working directory to internally use file
descriptors rather than strings.

- Each session still has a current working directory.

- New sessions still get their working directory from the client that
created them or its attached session if any.

- New windows are created by default in the session working directory.

- The -c flag to new, neww, splitw allows the working directory to be
overridden.

- The -c flag to attach let's the session working directory be changed.

- The default-path option has been removed.

To get the equivalent to default-path '.', do:

bind c neww -c $PWD

To get the equivalent of default-path '~', do:

bind c neww -c ~

This also changes the client identify protocol to be a set of messages rather
than one as well as some other changes that should make it easier to make
backwards-compatible protocol changes in future.


# 1.124 10-Oct-2013 nicm

Merge IDENTIFY_* flags with CLIENT_* flags.


# 1.123 10-Oct-2013 nicm

Don't treat TMUX_TMPDIR as a potential file

The point of setting TMUX_TMPDIR is to then make any labels from -L go
to that directory. In the case of makesocketpath() with no TMUX_TMPDIR
set, would set both the path and the default socket to a file. The
checking of the permissions on the file worked fine in that case, but
when TMUX_TMPDIR is set, won't work on a directory.

This fixes the problem by ensuring the check on the permissions is
performed on directories only.

By Thomas Adam.


# 1.122 05-Oct-2013 nicm

Fix previous not to leak fd on failure, whoops.


# 1.121 05-Oct-2013 nicm

Use open(".")/fchdir() to save and restore current directory rather than
getcwd()/chdir().


Revision tags: OPENBSD_5_4_BASE
# 1.120 24-Apr-2013 nicm

Rename global configuration define.


# 1.119 11-Apr-2013 nicm

Call setlocale(LC_TIME) at startup.


# 1.118 27-Mar-2013 nicm

Add TMUX_TMPDIR variable to put the socket directory outside
TMPDIR. From Ben Boeckel.


# 1.117 27-Mar-2013 nicm

Remove tmux's (already minimal) 88 colour support. Such terminals are
few and unnecessary.


# 1.116 25-Mar-2013 nicm

Rename session idx to session id throughout and add $ prefix to targets
to use it, extended from a diff from George Nachman.


# 1.115 24-Mar-2013 nicm

Add a command queue to standardize and simplify commands that call other
commands and allow a command to block execution of subsequent
commands. This allows run-shell and if-shell to be synchronous which has
been much requested.

Each client has a default command queue and commands are consumed one at
a time from it. A command may suspend execution from the queue by
returning CMD_RETURN_WAIT and then resume it by calling cmd_continue() -
for example run-shell does this from the callback that is fired after
the job is freed.

When the command queue becomes empty, command clients are automatically
exited (unless attaching). A callback is also fired - this is used for
nested commands in, for example, if-shell which can block execution of
the client's cmdq until a new cmdq becomes empty.

Also merge all the old error/info/print functions together and lose the
old curclient/cmdclient distinction - a cmdq is bound to one client (or
none if in the configuration file), this is a command client if
c->session is NULL otherwise an attached client.


Revision tags: OPENBSD_5_3_BASE
# 1.114 27-Nov-2012 nicm

Correctly aggregate together errors from nested config files (with
source-file). Fix by Thomas Adam, reported by Sam Livingstone-Gray


# 1.113 26-Nov-2012 nicm

Call realpath earlier on the socket directory path rather than on the
socket file path because the latter may not exist yet and in that case
realpath is allowed to fail. From Romain Francoise.


Revision tags: OPENBSD_5_2_BASE
# 1.112 10-Jul-2012 nicm

xfree is not particularly helpful, remove it. From Thomas Adam.


# 1.111 18-Jun-2012 nicm

Add a skeleton mode to tmux (called "control mode") that let's tmux
commands be sent and output received on stdout. This can be used to
integrate with other terminal emulators and should allow some other
things to be made simpler later. More to come so doesn't do much yet and
deliberately not documented.


# 1.110 30-May-2012 nicm

Do not use stderr for log file and don't call log_close when not needed.


# 1.109 25-May-2012 nicm

Simplify logging and just fprintf(stderr, ...) for early errors.


Revision tags: OPENBSD_5_1_BASE
# 1.108 21-Jan-2012 nicm

Drop the ability to have a list of keys in the prefix in favour of two
separate options, prefix and prefix2. This simplifies the code and gets
rid the data options type which was only used for this one option.

Also add a -2 flag to send-prefix to send the secondary prefix key,
fixing a cause of minor irritation.

People who want three prefix keys are out of luck :-).


# 1.107 23-Oct-2011 nicm

Try to resolve relative paths for loadb and saveb (first using client
working directory if any then default-path or session wd).


# 1.106 23-Oct-2011 nicm

Ignore LC_ALL and LC_CTYPE if they are empty as well as unset.


# 1.105 25-Sep-2011 nicm

Reject $SHELL if it is not a full path.


Revision tags: OPENBSD_5_0_BASE
# 1.104 04-Mar-2011 nicm

Two fixes by Micah Cowan: make mouse work properly beyond >127 on signed
char architectures and properly parse $TMUX by stopping the socket path
at the first comma.


Revision tags: OPENBSD_4_9_BASE
# 1.103 23-Jan-2011 nicm

Set $TMUX without the session when background jobs are run.


# 1.102 12-Jan-2011 nicm

Use TMPDIR if set, from Han Boetes.


# 1.101 08-Jan-2011 nicm

Move all calls to fcntl(...O_NONBLOCK) into a function and clear the
flag on the stdio file descriptors before closing them (fixes things
like "tmux ls && cat").


# 1.100 03-Jan-2011 nicm

Support for UTF-8 mouse input (\033[1005h). This was added in xterm 262
and supports larger terminals than the older way.

If the new mouse-utf8 option is on, UTF-8 mouse input is enabled for all
UTF-8 terminals. The option defaults to on if LANG etc are set in the
same manner as the utf8 option.

With help and based on code from hsim at gmx.li.


# 1.99 01-Jan-2011 nicm

Move the user-visible parts of all options (names, types, limit, default
values) together into one set of tables in options-table.c. Also clean
up and simplify cmd-set-options.c and move a common print function into
option-table.c.


# 1.98 30-Dec-2010 nicm

Change from a per-session stack of buffers to one global stack which is
much more convenient and also simplifies lot of code. This renders
copy-buffer useless and makes buffer-limit now a server option.

By Tiago Cunha.


# 1.97 19-Dec-2010 nicm

Add other-pane-height and other-pane-width options, allowing the width
or height of the smaller panes in the main-horizontal and main-vertical
layouts to be set. Mostly from David Goodlad.


# 1.96 08-Dec-2010 nicm

In the built-in layouts, distribute the panes more evenly. Set the
default value of main-pane-width to 80, rather than 81. By Micah Cowan.


# 1.95 06-Dec-2010 nicm

Add an option to alert (monitor) for silence (lack of activity) in a
window. From Thomas Adam.


# 1.94 29-Nov-2010 nicm

If VISUAL or EDITOR contains "vi", configure mode-keys and status-keys
to vi.

Based on a diff from martynas@, previously requested by a couple of
other people.


# 1.93 11-Nov-2010 nicm

Add XAUTHORITY to update-environment, requested by Andreas Kloeckner.


# 1.92 18-Oct-2010 nicm

Merge the before and after attach client code into one in client.c
(instead of two in tmux.c and client.c).


# 1.91 16-Oct-2010 nicm

Make stdio blocking again before calling shell command with -c.


# 1.90 16-Oct-2010 nicm

Trying to set FD_CLOEXEC on every fd is a lost cause, just use
closefrom() before exec.


# 1.89 14-Oct-2010 nicm

Use an explicit event rather than event_once for the main event so it
can be removed when the client becomes ready.


# 1.88 26-Sep-2010 nicm

Two new options:

- server option "exit-unattached" makes the server exit when no clients
are attached, even if sessions are present;

- session option "destroy-unattached" destroys a session once no clients
are attached to it.

These are useful for preventing tmux remaining in the background where
it is undesirable and when using tmux as a login shell to keep a limit
on new sessions.


# 1.87 19-Aug-2010 nicm

Do not call event_del() for signals after fork(), just use sigaction()
directly instead - calling libevent functions after fork() w/o
event_reinit() is a bad idea, even if in this case it was harmless.


Revision tags: OPENBSD_4_8_BASE
# 1.86 04-Aug-2010 deraadt

switch back to kqueue for now, since (a) kqueue has been fixed to deal
with strange devices and (b) since there appears to be a bull in the
poll code in libevent as well...
requested by nicm who is away


# 1.85 24-Jul-2010 nicm

kqueue(2) is currently broken when used with /dev/null and a few other
devices.

An upcoming fix for some problems with the client stdout/stderr handling
relies on it working, so make tmux force libevent to use poll(2) via
EVENT_NOKQUEUE, until we have fixed kqueue.


# 1.84 11-Jul-2010 nicm

Return the command client return code with MSG_EXIT now that MSG_ERROR and
MSG_PRINT are unused.

New clients should be compatible with old tmux servers but vice versa may print
an error.


# 1.83 28-Jun-2010 nicm

Send all three of stdin, stdout, stderr from the client to the server, so that
commands can directly make use of them. This means that load-buffer and
save-buffer can have "-" as the file to read from stdin or write to stdout.

This is a protocol version bump so the tmux server will need to be restarted
after upgrade (or an older client used).


# 1.82 27-Jun-2010 nicm

Store the current working directory in the session, change the default-path
option to default to empty and make that mean that the stored session CWD is
used.


# 1.81 27-Jun-2010 nicm

New option, detach-on-destroy, to set what happens to a client when the session
it is attached to is destroyed. If on (the default), it is detached; if off, it
is switched to the most recently active session.


# 1.80 26-Jun-2010 nicm

Setting the cmdlist pointer in the bind-key to NULL to prevent it being freed
after the command is executing is bogus because it may still be needed if the
same command is going to be executed again (for example if you "bind-key a
bind-key b ..."). Making a copy is hard, so instead add a reference count to
the cmd_list.

While here, also print bind-key -n and the rest of the flags properly.

Fixes problem reported by mcbride@.


# 1.79 14-May-2010 nicm

Colour+attribute options for status line alerts, from Alex Alexander.


# 1.78 04-May-2010 nicm

Put this back in with the initialisation in the right order.


# 1.77 04-May-2010 nicm

Revert last change, it appears to be broken somehow.


# 1.76 03-May-2010 nicm

Make signal handler setup/teardown two common functions instead of six,
and reset SIGCHLD after fork to fix problems with some shells. From
Romain Francois.


# 1.75 28-Apr-2010 nicm

Make the active pane border have a green foreground instead of
background by default.


# 1.74 18-Apr-2010 nicm

Catch SIGCHLD to avoid a zombie, from patrick keshishian.


Revision tags: OPENBSD_4_7_BASE
# 1.73 22-Feb-2010 nicm

Option to set the characters considered word separators in copy mode, from
Micah Cowan.


# 1.72 08-Feb-2010 nicm

Add an option to disable the smcup/rmcup alternate screen behaviour inside
tmux. From clemens fischer.


# 1.71 06-Feb-2010 nicm

Change nested check to compare server socket path rather than just assuming
that if $TMUX is set it is nested. From Micah Cowan.


# 1.70 06-Feb-2010 nicm

Clean up $TMUX parsing, from Micah Cowan, tweaked by me.


# 1.69 06-Feb-2010 nicm

Instead of bailing out on the first configuration file error, carry on,
collecting all the errors, then start with the active window in more mode
displaying them.


# 1.68 04-Feb-2010 nicm

Read the path from $TMUX if it is present and -L and -S are not given. Based on
a diff from Micah Cowan.


# 1.67 04-Feb-2010 nicm

Option to display the active pane in a different colour with the display-panes
command. From Paul Hoffman, thanks.


# 1.66 03-Jan-2010 nicm

Options to set the colour of the pane borders, with different colours for the
active pane.


# 1.65 14-Dec-2009 nicm

New server option, escape-time, to set the timeout used to detect if escapes
are alone or part of a function key or meta sequence.


# 1.64 11-Dec-2009 nicm

Use quiet variable, and add missing sentinel to options array.


# 1.63 10-Dec-2009 nicm

Add "server options" which are server-wide and not bound to a session or
window. Set and displayed with "set -s" and "show -s".

Currently the only option is "quiet" (like command-line -q, allowing it to be
set from .tmux.conf), but others will come along.


# 1.62 03-Dec-2009 nicm

Massive spaces->tabs and trailing whitespace cleanup, hopefully for the last
time now I've configured emacs to make them displayed in really annoying
colours...


# 1.61 26-Nov-2009 nicm

Remove a couple of unused arguments where possible, and add /* ARGSUSED */ to
the rest to reduce lint output.


# 1.60 19-Nov-2009 nicm

Two new options, window-status-format and window-status-current-format, which
allow the format of each window in the status line window list to be controlled
using similar # sequences as status-left/right.

This diff also moves part of the way towards UTF-8 support in window names but
it isn't quite there yet.


# 1.59 19-Nov-2009 nicm

Revert to xterm-keys off by default. It was on as an experiment to see if the
option could be removed, but it affects vi, so we have to keep the option, and
a conservative default is better.


# 1.58 18-Nov-2009 nicm

Add a per-client log of status line messages displayed while that client
exists. A new message-limit session option sets the maximum number of entries
and a command, show-messages, shows the log (bound to ~ by default).

This (and prompt history) might be better as a single global log but until
there are global options it is easier for them to be per client.


# 1.57 10-Nov-2009 nicm

There is no real standard for modifier plus function keys. Previously, tmux
output some from rxvt but in other ways did the same as xterm or other
terminals, but this is a bit inconsistent.

xterm's method is fairly sensible and we already support it (xterm-keys), so
enable it by default instead.


# 1.56 04-Nov-2009 nicm

A couple of minor cosmetic changes.


# 1.55 04-Nov-2009 nicm

Initial changes to move tmux to libevent.

This moves the client-side loops are pretty much fully over to event-based only
(tmux.c and client.c) but server-side (server.c and friends) treats libevent as
a sort of clever poll, waking up after every event to run various things.

Moving the server stuff over to bufferevents and timers and so on will come
later.


# 1.54 04-Nov-2009 nicm

Change declaration and use of malloc_options to be more standard, from Tim van
der Molen.


# 1.53 26-Oct-2009 deraadt

tabs are better; ok nicm


# 1.52 25-Oct-2009 nicm

Remove the -d flag to tmux and just use op/AX to detect default colours.

Irritatingly, although op can be used to tell if a terminal supports default
colours, it can't be used to set them because in some terminfo descriptions it
resets attributes as a side-effect (acts as sgr0) and in others it doesn't, so
it is not possible to determine reliably what the terminal state will be
afterwards. So if AX is missing and op is present, tmux just sends sgr0.

Anyone using -d for a terminal who finds they actually needed it can replace it
using terminal-overrides, but please let me know as it is probably an omission
from terminfo.


# 1.51 22-Oct-2009 nicm

Merge prepare_cmd into main as it is short and only called once.


# 1.50 21-Oct-2009 nicm

Client tidying: get rid of client_ctx struct in favour of two variables in
client.c, and move the functions in client-fn.c into other files.


# 1.49 10-Oct-2009 nicm

New option, mouse-select-pane. If on, the mouse may be used to select the
current pane.

Suggested by sthen@ and also by someone else ages ago who I have forgotten.


# 1.48 10-Oct-2009 nicm

Support for individual session idle time locking. May be enabled by turning off
the lock-server option (it is on by default). When this is off, each session
locks when it has been idle for the lock-after-time setting. When on, the
entire server locks when ALL sessions have been idle for their individual
lock-after-time settings.

This replaces one global-only option (lock-after-time) with another
(lock-server), but the default behaviour is usually preferable so there don't
seem to be many alternatives.

Diff/idea largely from Thomas Adam, tweaked by me.


# 1.47 09-Oct-2009 nicm

Add a simple synchronize-panes window option: when set, all input to any pane
that is part of the window is also sent to all other panes in the same
window. Suggested by several, most recently Tomasz Pajor.


# 1.46 23-Sep-2009 nicm

Support -c like sh(1) to execute a command, useful when tmux is a login
shell. Suggested by halex@.

This includes another protocol version increase (the last for now) so again
restart the tmux server before upgrading.


# 1.45 23-Sep-2009 nicm

Remove the internal tmux locking and instead detach each client and run the
command specified by a new option "lock-command" (by default "lock -np") in
each client.

This means each terminal has to be unlocked individually but simplifies the
code and allows the system password to be used to unlock.

Note that the set-password command is gone, so it will need to be removed from
configuration files, and the -U command line flag has been removed.

This is the third protocol version change so again it is best to stop the tmux
server before upgrading.


# 1.44 22-Sep-2009 nicm

Permit multiple prefix keys to be defined, separated by commas, for example:

set -g prefix ^a,^b

Any key in the list acts as the prefix. The send-prefix command always sends
the first key in the list.


# 1.43 18-Sep-2009 nicm

New option, set-titles-string, to allow the window title to be specified (as
for status-left/right) if set-titles is on. Also only update the title when the
status line is being redrawn.


# 1.42 04-Sep-2009 nicm

Tidy main and make it a bit easier to read.


# 1.41 02-Sep-2009 nicm

Accept -l to make it easier for people who use tmux as a login shell to use
$SHELL. Originally from martynas@, tweaked by me.


# 1.40 02-Sep-2009 nicm

When incorrect passwords are entered, behave similarly to login(1) and backoff
for a bit. Based on a diff from martynas@.


# 1.39 01-Sep-2009 nicm

When using tmux as a login shell, there is currently no way to specify a shell
to be used as a login shell inside tmux, so add a default-shell session option.
This sets the shell invoked as a login shell when the default-command option is
empty.

The default option value is whichever of $SHELL, getpwuid(getuid())'s pw_shell
or /bin/sh is valid first.

Based on a diff from martynas@, changed by me to be a session option rather
than a window option.


# 1.38 01-Sep-2009 nicm

Use "Password:" with no space for password prompts and don't display a *s for
the password, like pretty much everything else. From martynas@ with minor
tweaks by me.


# 1.37 01-Sep-2009 nicm

Sort cases same as getopt argument, from martynas.


# 1.36 31-Aug-2009 nicm

Add a new display-panes command, with two options (display-panes-colour and
display-panes-time), which displays a visual indication of the number of each
pane.


# 1.35 23-Aug-2009 nicm

Add some other obvious variables to update-environment (WINDOWID SSH_ASKPASS
SSH_AUTH_SOCK SSH_AGENT_PID SSH_CONNECTION) so they are updated in the session
environment on new/attach.


# 1.34 13-Aug-2009 nicm

Disable mode-mouse (mouse in copy/choice mode) by default as it isn't very
useful at the moment and causes confusion.


# 1.33 13-Aug-2009 nicm

Add a base-index session option to specify the first index checked when looking
for an index for a new window.


# 1.32 12-Aug-2009 nicm

When started as the shell, __progname contains a leading -, so hardcode "tmux"
for socket path and log files, and strip it when working out the shell.


# 1.31 11-Aug-2009 nicm

Switch tmux to use imsg. This is the last major change to make the
client-server protocol more resilient and make the protocol versioning work
properly. In future, the only things requiring a protocol version bump will be
changes in the message structs, and (when both client and server have this
change) mixing different versions should nicely report an error message.

As a side effect this also makes the code tidier, fixes a problem with the way
errors reported during server startup were handled, and supports fd passing
(which will be used in future).

Looked over by eric@, thanks.

Please note that mixing a client with this change with an older server or vice
versa may cause tmux to crash or hang - tmux should be completely exited before
upgrading.


# 1.30 10-Aug-2009 nicm

No arguments are the same as new-session and this requires the environment to
be sent, so set that flag too when argc == 0.


# 1.29 08-Aug-2009 nicm

Infrastructure and commands to manage the environment for processes started
within tmux.

There is a global environment, copied from the external environment when the
server is started and each sesssion has an (initially empty) session
environment which overrides it.

New commands set-environment and show-environment manipulate or display the
environments.

A new session option, update-environment, is a space-separated list of
variables which are updated from the external environment into the session
environment every time a new session is created - the default is DISPLAY.


# 1.28 08-Aug-2009 nicm

Options to set the colours and attributes for status-left/-right. From Thomas
Adam, thanks.


# 1.27 05-Aug-2009 nicm

If colours are not supported by the terminal, try to emulate a coloured
background by setting or clearing the reverse attribute.

This makes a few applications which don't use the reverse attribute themselves
a little happier, and allows the status, message and mode options to have
default attributes and fg/bg options that work as expected when set as reverse.


# 1.26 04-Aug-2009 nicm

Check for "UTF8" as well as "UTF-8" in LANG etc as it seems this may also
appear.


# 1.25 03-Aug-2009 nicm

Add a terminal-overrides session option allowing individual terminfo(5) entries
to be overridden. The 88col/256col checks are now moved into the default
setting and out of the code.

Also remove a couple of old workarounds for xterm and rxvt which are no longer
necessary (tmux can emulate them if missing).


# 1.24 30-Jul-2009 nicm

Add a mode-mouse option to prevent tmux taking over the mouse in choice or copy
modes.


# 1.23 29-Jul-2009 nicm

Rename struct hdrtype to msgtype which is a better name and can be used even
when struct hdr disappears.


# 1.22 29-Jul-2009 nicm

Taking account of the "s, 22 not 24 is the maximum length of #T in status-right
to prevent the date being cut off.


# 1.21 26-Jul-2009 nicm

Make all messages sent between the client and server fixed size.

This is the first of two changes to make the protocol more resilient and less
sensitive to other changes in the code, particularly with commands. The client
now packs argv into a buffer and sends it to the server for parsing, rather
than doing it itself and sending the parsed command data.

As a side-effect this also removes a lot of now-unused command marshalling
code.

Mixing a server without this change and a client with or vice versa will cause
tmux to hang or crash, please ensure that tmux is entirely killed before
upgrading.


# 1.20 22-Jul-2009 nicm

Pass a set of flags into client_init rather than just a start_server
variable. Only one flag now but more to come later.


# 1.19 20-Jul-2009 nicm

Display the number of failed password attempts (if any) when the server is
locked. From Tom Doherty.


# 1.18 20-Jul-2009 nicm

Add a status-justify option to allow the window list in the status line to be
positioned at the left, centre, or right.


# 1.17 20-Jul-2009 nicm

New options, window-status-current-{fg,bg,attr}, to set the fg, bg and
attributes with which the current window is shown in the status line. From
Johan Friis, thanks.


# 1.16 18-Jul-2009 nicm

Add three new session options: visual-activity, visual-bell, visual-content. If
these are enabled (and the monitor-activity, bell-actio and monitor-content
options are configurated appropriately), when activity, a bell, or content is
detected, a message is shown.

Also tidy up the bell/activity/content code in server.c slightly and fix a
couple of errors.


# 1.15 17-Jul-2009 nicm

If -u is specified or UTF-8 is otherwise detected when the server is started,
enable the utf8 and status-utf8 optons. While here, note in the man page that
the server is started with the first session and exits when none remain.


# 1.14 10-Jul-2009 nicm

Add a default-terminal option to set the starting value of $TERM in new
windows.

This is "screen" by default and must be either that or something closely
related. This does makes it easier to customise it if necessary.


# 1.13 08-Jul-2009 nicm

Just appending -l to $SHELL to create a login shell is wrong: -l is not POSIX,
and some people may use shells which do not support it. Instead, make an empty
default-command option mean a login shell, and fork it with a - in argv[0]
which is the method used by login(1).

Also fix the automatic-rename code to handle this correctly and to strip a
leading - if present.


# 1.12 07-Jul-2009 nicm

Rename the global options variables to be shorter and to make session options
clear. No functional change, getting this out of the way to make later options
changes easier.


Revision tags: OPENBSD_4_6_BASE
# 1.11 25-Jun-2009 nicm

If getcwd() fails, use the user's home directory, or /, instead of failing with
an error.


# 1.10 25-Jun-2009 nicm

Remove error about using -L and -S together which was never displayed as
logging wasn't yet enabled, was unnecessary, and contradicted the man page
which says using -S will cause -L to be ignored.


# 1.9 23-Jun-2009 nicm

LC_ALL overrides LC_CTYPE and LANG. Comment was correct but the code
wrong. Pointed out by Hannah Schroeter, thanks.


# 1.8 05-Jun-2009 nicm

Check the first of LC_CTYPE, LC_ALL and LANG, rather than just the last, when
trying to decide about UTF-8, and use strcasestr. Reported by Geert Hendrickx.


# 1.7 04-Jun-2009 nicm

Zero the password given to -U in the client as well.


# 1.6 03-Jun-2009 nicm

Do not set the window title by default (make set-titles option default to off),
wiping over the title is rude and annoying. Agreed by several.


# 1.5 03-Jun-2009 nicm

New session option, status-utf8, to control the interpretation of top-bit-set
characters in status-left and status-right (if on, they are treated as UTF-8;
otherwise passed through).


# 1.4 02-Jun-2009 sobrado

remove unused flag; while here, make usage's output fit on 80-column displays.


# 1.3 02-Jun-2009 pyr

spawn login shells by default, adapt manpage bits as well.
ok nicm@


# 1.2 02-Jun-2009 ray

Don't leak memory if multiple -f flags are given.

OK nicm@


# 1.1 01-Jun-2009 nicm

Import tmux, a terminal multiplexor allowing (among other things) a single
terminal to be switched between several different windows and programs
displayed on one terminal be detached from one terminal and moved to another.

ok deraadt pirofti


# 1.204 17-Jan-2021 nicm

Add -N flag to never start server even if command would normally do so,
GitHub issue 2523.


Revision tags: OPENBSD_6_8_BASE
# 1.203 22-Sep-2020 nicm

Fix warnings on some platforms with %llx and add a new message to handle
64-bit client flags.


# 1.202 02-Jun-2020 nicm

Use CLOCK_MONOTONIC for timer measurement and add a timestamp to control
mode %output blocks.


# 1.201 16-May-2020 nicm

Add a -D flag to ask tmux not to daemonize, useful both for running a
debugger (lldb does not have follow-fork-mode) and for running with a
managed supervisor init system. GitHub issue 2190.


# 1.200 16-May-2020 nicm

Add 'e' key in buffer mode to open the buffer in an editor.


# 1.199 16-May-2020 nicm

Build list of paths and weed out duplicates before loading configs, and
add TMUX_SOCK like TMUX_PATH for the socket directory.


Revision tags: OPENBSD_6_7_BASE
# 1.198 20-Apr-2020 nicm

Tidy up the terminal detection and feature code and add named sets of
terminal features, each of which are defined in one place and map to a
builtin set of terminfo(5) capabilities. Features can be specified based
on TERM with a new terminal-features option or with the -T flag when
running tmux. tmux will also detect a few common terminals from the DA
and DSR responses.

This is intended to make it easier to configure tmux's use of
terminfo(5) even in the presence of outdated ncurses(3) or terminfo(5)
databases or for features which do not yet have a terminfo(5) entry.
Instead of having to grok terminfo(5) capability names and what they
should be set to in the terminal-overrides option, the user can
hopefully just give tmux a feature name and let it do the right thing.

The terminal-overrides option remains both for backwards compatibility
and to allow tweaks of individual capabilities.

tmux already did much of this already, this makes it tidier and simpler
to configure.


# 1.197 16-Apr-2020 nicm

Show signal name when process exits rather than number.


# 1.196 09-Apr-2020 nicm

More style nits.


# 1.195 31-Mar-2020 nicm

Add a way to mark environment variables as "hidden" so they can be used
by tmux but are not passed into the environment of new panes.


# 1.194 17-Mar-2020 nicm

Ignore default-shell (and use /bin/sh) if it invalid not just if it is
tmux itself, also refuse to set the option to something invalid in the
first place. GitHub issue 2120.


# 1.193 12-Mar-2020 nicm

When the server socket is given by the user with -S, create it with
umask 177 instead of 117 because it may not be in a safe directory like
the default directory in /tmp. The user can chmod it more open after it
is created if they want.


# 1.192 28-Jan-2020 nicm

-V also needs to go in usage.


# 1.191 28-Jan-2020 nicm

Reduce a difference with portable tmux by adding the -V flag and
#{version} format; on OpenBSD these just report the OpenBSD version.


# 1.190 14-Oct-2019 nicm

Memory leaks, from Igor Wong in GitHub issue 1934.


Revision tags: OPENBSD_6_6_BASE
# 1.189 20-Jun-2019 nicm

Add a per-pane option set. Pane options inherit from window options (so
there should be no change to existing behaviour) and are set and shown
with set-option -p and show-options -p.

Change remain-on-exit and window-style/window-active-style to be pane
options (some others will be changed later).

This makes select-pane -P and -g unnecessary so no longer document them
(they still work) and no longer document set-window-option and
show-window-options in favour of set-option -w and show-options -w.


# 1.188 26-Apr-2019 nicm

Merge hooks into options and make each one an array option. This allows
multiple commands to be easily bound to one hook. set-hook and
show-hooks remain but they are now variants of set-option and
show-options. show-options now has a -H flag to show hooks (by default
they are not shown).


Revision tags: OPENBSD_6_5_BASE
# 1.187 22-Nov-2018 nicm

Do not use PWD unless it actually matches the real working directory.


Revision tags: OPENBSD_6_3_BASE OPENBSD_6_4_BASE
# 1.186 12-Jan-2018 nicm

Improve error message if creating socket parent directory fails, from
Thomas Adam for GitHub issue 1215.


# 1.185 01-Jan-2018 nicm

Prefer PWD for current directory if present in client, from Wei Zhao in
GitHub issue 1183.


Revision tags: OPENBSD_6_2_BASE
# 1.184 12-Jul-2017 nicm

Make shell_command a global like other stuff rather than making it an
exception and using callback argument.


# 1.183 03-Jul-2017 nicm

Try C.UTF-8 which is also a commonly useful locale on some platforms,
from Romain Francoise.


# 1.182 22-Apr-2017 nicm

Do not need getopt.h.


# 1.181 20-Apr-2017 nicm

Use fdforkpty() instead of our own unwrapped versions.


# 1.180 19-Apr-2017 nicm

Style nits and a missing cast.


# 1.179 16-Apr-2017 nicm

Memory leak, from David CARLIER.


Revision tags: OPENBSD_6_1_BASE
# 1.178 21-Mar-2017 nicm

Use uid_t for UID not u_int.


# 1.177 16-Feb-2017 nicm

Style nits.


# 1.176 23-Jan-2017 nicm

Open /dev/ptm before pledge() and save it to be used for PTMGET later
(this means inlining forkpty()).

ok deraadt


# 1.175 15-Jan-2017 nicm

Major tidy up and rework of options tree and set-option/show-options
commands this pushes more of the code into options.c and ties it more
closely to the options table rather than having an unnecessary
split. Also add support for array options (will be used later). Only
(intentional) user visible change is that show-options output is now
passed through vis(3) with VIS_DQ so quotes are escaped.


# 1.174 12-Jan-2017 nicm

Simplify appending to string options.


# 1.173 09-Dec-2016 nicm

Spacing nits.


# 1.172 11-Oct-2016 nicm

Add static in window-*.c and move some internal functions out of tmux.h.


# 1.171 10-Oct-2016 nicm

Loads more static, except for cmd-*.c and window-*.c.


Revision tags: OPENBSD_6_0_BASE
# 1.170 27-May-2016 nicm

Use getprogname() instead of __progname to make portability easier.


# 1.169 04-May-2016 nicm

Fix up a couple of long lines.


# 1.168 05-Mar-2016 nicm

If setlocale("en_US.UTF-8") succeeds, then don't do the check for UTF-8
locale since if it isn't UTF-8 the system is broken anyway. If it fails,
try "" and check for UTF-8 with nl_langinfo(CODESET) rather than
wcwidth(). Based on a diff from schwarze@, nl_langinfo also suggested by
stsp@.


# 1.167 05-Mar-2016 nicm

Although we always have en_US.UTF-8 on OpenBSD, some platforms do not,
so fall back to setlocale(LC_CTYPE, ""). tmux requires a UTF-8 locale,
so check with wcwidth() on a UTF-8 character after setlocale().


# 1.166 01-Mar-2016 nicm

Remove unused variables, from Michal Mazurek.


# 1.165 01-Mar-2016 nicm

Use system wcwidth() instead of carrying around UTF-8 width tables.


Revision tags: OPENBSD_5_9_BASE
# 1.164 19-Jan-2016 nicm

I no longer use my SourceForge address so replace it.


# 1.163 08-Dec-2015 nicm

Add hooks infrastructure, basic commands (set-hook, show-hooks) and a
couple of not very useful client hooks. This will eventually let
commands be run at various points and on notifications. Joint work with
Thomas Adam.


# 1.162 24-Nov-2015 nicm

Make environ_set va_args and use it to tidy up some calls. Also add a
missing word in manpage (from jmc).


# 1.161 24-Nov-2015 nicm

Shell command from -c doesn't have to be global, pass it as an argument.


# 1.160 24-Nov-2015 nicm

Tidy the code that works out the socket path, and just use the full path
in the global socket_path rather than copying it.


# 1.159 24-Nov-2015 nicm

Remove malloc_options DEBUG bit.


# 1.158 24-Nov-2015 nicm

Remove the -I part of show-messages which isn't really that useful; the
server start time can now be accessed with a new start_time format (use:
tmux display -p '#{t:start_time}')


# 1.157 24-Nov-2015 nicm

Make the log stuff a bit tidier with some helper functions.


# 1.156 22-Nov-2015 nicm

Add getpw to pledge, makes tmux work in YP environments, discovered by
matthieu, ok deraadt


# 1.155 20-Nov-2015 nicm

Instead of separate tables for different types of options, give each
option a scope type (server, session, window) in one table.


# 1.154 15-Nov-2015 nicm

Accidentally turned off pledge, turn it back on.


# 1.153 14-Nov-2015 nicm

Push stdout and stderr to clients more aggressively, and add an event to
continue if the send fails.


# 1.152 12-Nov-2015 nicm

tmux is UTF-8, so if $TMUX is set (tmux running in tmux), the client is
UTF-8. Also try to make the existing checks more readable.


# 1.151 12-Nov-2015 nicm

Nuke the utf8 and status-utf8 options and make tmux only a UTF-8
terminal. We still support non-UTF-8 terminals outside tmux, but inside
it is always UTF-8 (as when the utf8 and status-utf8 options were on).


# 1.150 11-Nov-2015 nicm

Drop mouse-utf8 option and always turn on UTF-8 mouse if the client says
it supports UTF-8.


# 1.149 28-Oct-2015 nicm

Like options, move the environ struct into environ.c.


# 1.148 27-Oct-2015 nicm

Move struct options into options.c.


# 1.147 27-Oct-2015 nicm

Break the common process set up, event loop and imsg dispatch code
between server and client out into a separate internal API. This will
make it easier to add another process.


# 1.146 25-Oct-2015 deraadt

Let's see if anyone screams about not being able to specify $TMPDIR
for their tmux sockets.

(Over the years, I have seen $TMPDIR set up worse than /tmp many times,
and don't know how this practice infected other parts of the system.
Nothing uses tmpdir(3), nor a huge-temporary-file program like sort.)
ok nicm


# 1.145 23-Oct-2015 nicm

tmux can call pledge() in main with large set and then reduce it
slightly in the server to "stdio rpath wpath cpath fattr unix recvfd
proc exec tty ps".


# 1.144 14-Sep-2015 nicm

Move tzset() from log_open to main.


# 1.143 03-Sep-2015 nicm

A couple of style nits.


# 1.142 01-Sep-2015 nicm

Work out config file when needed not at startup.


# 1.141 30-Aug-2015 nicm

Path from $TMUX does not need to be global anymore.


# 1.140 30-Aug-2015 nicm

Login shell can be a client flag, and move the exec code into client.c.


# 1.139 30-Aug-2015 nicm

Event base does not need to be global.


# 1.138 30-Aug-2015 nicm

Some style nits and dead assignments.


Revision tags: OPENBSD_5_8_BASE
# 1.137 20-Jul-2015 nicm

Add an option (history-file) for a file to save/restore command prompt
history, from Olof-Joachim Frahm.


# 1.136 04-Jun-2015 jmc

tweak SYNOPSIS and usage();


Revision tags: OPENBSD_5_7_BASE
# 1.135 19-Jan-2015 nicm

Make a tmux-%u directory under TMUX_TMPDIR, like TMPDIR.


# 1.134 19-Jan-2015 nicm

Only care about other permissions, allow group to be set.


# 1.133 19-Jan-2015 nicm

Remove unnecessary duplicate S_ISDIR check, from Dmitri Paduchikh.


# 1.132 20-Oct-2014 nicm

Tidy up some includes.


Revision tags: OPENBSD_5_6_BASE
# 1.131 17-Apr-2014 nicm

Remove the "info" message mechanism, this was only used for about five
mostly useless and annoying messages. Change those commands to silence
on success like all the others. Still accept the -q command line flag
and "quiet" server option for now.


# 1.130 31-Mar-2014 nicm

Remove log_debug2 as well and simplify log.c.


Revision tags: OPENBSD_5_5_BASE
# 1.129 16-Feb-2014 nicm

Leftovers from removing 88 colour support, from Theo Buehler.


# 1.128 15-Jan-2014 nicm

Do not attempt to read .tmux.conf if we can't figure out a home
directory, from Tiago Cunha.


# 1.127 09-Jan-2014 nicm

Three small changes from Tiago Cunha:

- Check for truncation when copying path.
- Don't need to use a temporary buffer in screen_set_title.
- Include strerror in output when connecting to server fails.


# 1.126 10-Oct-2013 nicm

We accidentally haven't been using $TMUX to work out the session for a
while and in fact it is less useful that using the client ttyname. So
don't bother and don't pass it from the client. If we need it in future
it is in c->environ.


# 1.125 10-Oct-2013 nicm

Alter how tmux handles the working directory to internally use file
descriptors rather than strings.

- Each session still has a current working directory.

- New sessions still get their working directory from the client that
created them or its attached session if any.

- New windows are created by default in the session working directory.

- The -c flag to new, neww, splitw allows the working directory to be
overridden.

- The -c flag to attach let's the session working directory be changed.

- The default-path option has been removed.

To get the equivalent to default-path '.', do:

bind c neww -c $PWD

To get the equivalent of default-path '~', do:

bind c neww -c ~

This also changes the client identify protocol to be a set of messages rather
than one as well as some other changes that should make it easier to make
backwards-compatible protocol changes in future.


# 1.124 10-Oct-2013 nicm

Merge IDENTIFY_* flags with CLIENT_* flags.


# 1.123 10-Oct-2013 nicm

Don't treat TMUX_TMPDIR as a potential file

The point of setting TMUX_TMPDIR is to then make any labels from -L go
to that directory. In the case of makesocketpath() with no TMUX_TMPDIR
set, would set both the path and the default socket to a file. The
checking of the permissions on the file worked fine in that case, but
when TMUX_TMPDIR is set, won't work on a directory.

This fixes the problem by ensuring the check on the permissions is
performed on directories only.

By Thomas Adam.


# 1.122 05-Oct-2013 nicm

Fix previous not to leak fd on failure, whoops.


# 1.121 05-Oct-2013 nicm

Use open(".")/fchdir() to save and restore current directory rather than
getcwd()/chdir().


Revision tags: OPENBSD_5_4_BASE
# 1.120 24-Apr-2013 nicm

Rename global configuration define.


# 1.119 11-Apr-2013 nicm

Call setlocale(LC_TIME) at startup.


# 1.118 27-Mar-2013 nicm

Add TMUX_TMPDIR variable to put the socket directory outside
TMPDIR. From Ben Boeckel.


# 1.117 27-Mar-2013 nicm

Remove tmux's (already minimal) 88 colour support. Such terminals are
few and unnecessary.


# 1.116 25-Mar-2013 nicm

Rename session idx to session id throughout and add $ prefix to targets
to use it, extended from a diff from George Nachman.


# 1.115 24-Mar-2013 nicm

Add a command queue to standardize and simplify commands that call other
commands and allow a command to block execution of subsequent
commands. This allows run-shell and if-shell to be synchronous which has
been much requested.

Each client has a default command queue and commands are consumed one at
a time from it. A command may suspend execution from the queue by
returning CMD_RETURN_WAIT and then resume it by calling cmd_continue() -
for example run-shell does this from the callback that is fired after
the job is freed.

When the command queue becomes empty, command clients are automatically
exited (unless attaching). A callback is also fired - this is used for
nested commands in, for example, if-shell which can block execution of
the client's cmdq until a new cmdq becomes empty.

Also merge all the old error/info/print functions together and lose the
old curclient/cmdclient distinction - a cmdq is bound to one client (or
none if in the configuration file), this is a command client if
c->session is NULL otherwise an attached client.


Revision tags: OPENBSD_5_3_BASE
# 1.114 27-Nov-2012 nicm

Correctly aggregate together errors from nested config files (with
source-file). Fix by Thomas Adam, reported by Sam Livingstone-Gray


# 1.113 26-Nov-2012 nicm

Call realpath earlier on the socket directory path rather than on the
socket file path because the latter may not exist yet and in that case
realpath is allowed to fail. From Romain Francoise.


Revision tags: OPENBSD_5_2_BASE
# 1.112 10-Jul-2012 nicm

xfree is not particularly helpful, remove it. From Thomas Adam.


# 1.111 18-Jun-2012 nicm

Add a skeleton mode to tmux (called "control mode") that let's tmux
commands be sent and output received on stdout. This can be used to
integrate with other terminal emulators and should allow some other
things to be made simpler later. More to come so doesn't do much yet and
deliberately not documented.


# 1.110 30-May-2012 nicm

Do not use stderr for log file and don't call log_close when not needed.


# 1.109 25-May-2012 nicm

Simplify logging and just fprintf(stderr, ...) for early errors.


Revision tags: OPENBSD_5_1_BASE
# 1.108 21-Jan-2012 nicm

Drop the ability to have a list of keys in the prefix in favour of two
separate options, prefix and prefix2. This simplifies the code and gets
rid the data options type which was only used for this one option.

Also add a -2 flag to send-prefix to send the secondary prefix key,
fixing a cause of minor irritation.

People who want three prefix keys are out of luck :-).


# 1.107 23-Oct-2011 nicm

Try to resolve relative paths for loadb and saveb (first using client
working directory if any then default-path or session wd).


# 1.106 23-Oct-2011 nicm

Ignore LC_ALL and LC_CTYPE if they are empty as well as unset.


# 1.105 25-Sep-2011 nicm

Reject $SHELL if it is not a full path.


Revision tags: OPENBSD_5_0_BASE
# 1.104 04-Mar-2011 nicm

Two fixes by Micah Cowan: make mouse work properly beyond >127 on signed
char architectures and properly parse $TMUX by stopping the socket path
at the first comma.


Revision tags: OPENBSD_4_9_BASE
# 1.103 23-Jan-2011 nicm

Set $TMUX without the session when background jobs are run.


# 1.102 12-Jan-2011 nicm

Use TMPDIR if set, from Han Boetes.


# 1.101 08-Jan-2011 nicm

Move all calls to fcntl(...O_NONBLOCK) into a function and clear the
flag on the stdio file descriptors before closing them (fixes things
like "tmux ls && cat").


# 1.100 03-Jan-2011 nicm

Support for UTF-8 mouse input (\033[1005h). This was added in xterm 262
and supports larger terminals than the older way.

If the new mouse-utf8 option is on, UTF-8 mouse input is enabled for all
UTF-8 terminals. The option defaults to on if LANG etc are set in the
same manner as the utf8 option.

With help and based on code from hsim at gmx.li.


# 1.99 01-Jan-2011 nicm

Move the user-visible parts of all options (names, types, limit, default
values) together into one set of tables in options-table.c. Also clean
up and simplify cmd-set-options.c and move a common print function into
option-table.c.


# 1.98 30-Dec-2010 nicm

Change from a per-session stack of buffers to one global stack which is
much more convenient and also simplifies lot of code. This renders
copy-buffer useless and makes buffer-limit now a server option.

By Tiago Cunha.


# 1.97 19-Dec-2010 nicm

Add other-pane-height and other-pane-width options, allowing the width
or height of the smaller panes in the main-horizontal and main-vertical
layouts to be set. Mostly from David Goodlad.


# 1.96 08-Dec-2010 nicm

In the built-in layouts, distribute the panes more evenly. Set the
default value of main-pane-width to 80, rather than 81. By Micah Cowan.


# 1.95 06-Dec-2010 nicm

Add an option to alert (monitor) for silence (lack of activity) in a
window. From Thomas Adam.


# 1.94 29-Nov-2010 nicm

If VISUAL or EDITOR contains "vi", configure mode-keys and status-keys
to vi.

Based on a diff from martynas@, previously requested by a couple of
other people.


# 1.93 11-Nov-2010 nicm

Add XAUTHORITY to update-environment, requested by Andreas Kloeckner.


# 1.92 18-Oct-2010 nicm

Merge the before and after attach client code into one in client.c
(instead of two in tmux.c and client.c).


# 1.91 16-Oct-2010 nicm

Make stdio blocking again before calling shell command with -c.


# 1.90 16-Oct-2010 nicm

Trying to set FD_CLOEXEC on every fd is a lost cause, just use
closefrom() before exec.


# 1.89 14-Oct-2010 nicm

Use an explicit event rather than event_once for the main event so it
can be removed when the client becomes ready.


# 1.88 26-Sep-2010 nicm

Two new options:

- server option "exit-unattached" makes the server exit when no clients
are attached, even if sessions are present;

- session option "destroy-unattached" destroys a session once no clients
are attached to it.

These are useful for preventing tmux remaining in the background where
it is undesirable and when using tmux as a login shell to keep a limit
on new sessions.


# 1.87 19-Aug-2010 nicm

Do not call event_del() for signals after fork(), just use sigaction()
directly instead - calling libevent functions after fork() w/o
event_reinit() is a bad idea, even if in this case it was harmless.


Revision tags: OPENBSD_4_8_BASE
# 1.86 04-Aug-2010 deraadt

switch back to kqueue for now, since (a) kqueue has been fixed to deal
with strange devices and (b) since there appears to be a bull in the
poll code in libevent as well...
requested by nicm who is away


# 1.85 24-Jul-2010 nicm

kqueue(2) is currently broken when used with /dev/null and a few other
devices.

An upcoming fix for some problems with the client stdout/stderr handling
relies on it working, so make tmux force libevent to use poll(2) via
EVENT_NOKQUEUE, until we have fixed kqueue.


# 1.84 11-Jul-2010 nicm

Return the command client return code with MSG_EXIT now that MSG_ERROR and
MSG_PRINT are unused.

New clients should be compatible with old tmux servers but vice versa may print
an error.


# 1.83 28-Jun-2010 nicm

Send all three of stdin, stdout, stderr from the client to the server, so that
commands can directly make use of them. This means that load-buffer and
save-buffer can have "-" as the file to read from stdin or write to stdout.

This is a protocol version bump so the tmux server will need to be restarted
after upgrade (or an older client used).


# 1.82 27-Jun-2010 nicm

Store the current working directory in the session, change the default-path
option to default to empty and make that mean that the stored session CWD is
used.


# 1.81 27-Jun-2010 nicm

New option, detach-on-destroy, to set what happens to a client when the session
it is attached to is destroyed. If on (the default), it is detached; if off, it
is switched to the most recently active session.


# 1.80 26-Jun-2010 nicm

Setting the cmdlist pointer in the bind-key to NULL to prevent it being freed
after the command is executing is bogus because it may still be needed if the
same command is going to be executed again (for example if you "bind-key a
bind-key b ..."). Making a copy is hard, so instead add a reference count to
the cmd_list.

While here, also print bind-key -n and the rest of the flags properly.

Fixes problem reported by mcbride@.


# 1.79 14-May-2010 nicm

Colour+attribute options for status line alerts, from Alex Alexander.


# 1.78 04-May-2010 nicm

Put this back in with the initialisation in the right order.


# 1.77 04-May-2010 nicm

Revert last change, it appears to be broken somehow.


# 1.76 03-May-2010 nicm

Make signal handler setup/teardown two common functions instead of six,
and reset SIGCHLD after fork to fix problems with some shells. From
Romain Francois.


# 1.75 28-Apr-2010 nicm

Make the active pane border have a green foreground instead of
background by default.


# 1.74 18-Apr-2010 nicm

Catch SIGCHLD to avoid a zombie, from patrick keshishian.


Revision tags: OPENBSD_4_7_BASE
# 1.73 22-Feb-2010 nicm

Option to set the characters considered word separators in copy mode, from
Micah Cowan.


# 1.72 08-Feb-2010 nicm

Add an option to disable the smcup/rmcup alternate screen behaviour inside
tmux. From clemens fischer.


# 1.71 06-Feb-2010 nicm

Change nested check to compare server socket path rather than just assuming
that if $TMUX is set it is nested. From Micah Cowan.


# 1.70 06-Feb-2010 nicm

Clean up $TMUX parsing, from Micah Cowan, tweaked by me.


# 1.69 06-Feb-2010 nicm

Instead of bailing out on the first configuration file error, carry on,
collecting all the errors, then start with the active window in more mode
displaying them.


# 1.68 04-Feb-2010 nicm

Read the path from $TMUX if it is present and -L and -S are not given. Based on
a diff from Micah Cowan.


# 1.67 04-Feb-2010 nicm

Option to display the active pane in a different colour with the display-panes
command. From Paul Hoffman, thanks.


# 1.66 03-Jan-2010 nicm

Options to set the colour of the pane borders, with different colours for the
active pane.


# 1.65 14-Dec-2009 nicm

New server option, escape-time, to set the timeout used to detect if escapes
are alone or part of a function key or meta sequence.


# 1.64 11-Dec-2009 nicm

Use quiet variable, and add missing sentinel to options array.


# 1.63 10-Dec-2009 nicm

Add "server options" which are server-wide and not bound to a session or
window. Set and displayed with "set -s" and "show -s".

Currently the only option is "quiet" (like command-line -q, allowing it to be
set from .tmux.conf), but others will come along.


# 1.62 03-Dec-2009 nicm

Massive spaces->tabs and trailing whitespace cleanup, hopefully for the last
time now I've configured emacs to make them displayed in really annoying
colours...


# 1.61 26-Nov-2009 nicm

Remove a couple of unused arguments where possible, and add /* ARGSUSED */ to
the rest to reduce lint output.


# 1.60 19-Nov-2009 nicm

Two new options, window-status-format and window-status-current-format, which
allow the format of each window in the status line window list to be controlled
using similar # sequences as status-left/right.

This diff also moves part of the way towards UTF-8 support in window names but
it isn't quite there yet.


# 1.59 19-Nov-2009 nicm

Revert to xterm-keys off by default. It was on as an experiment to see if the
option could be removed, but it affects vi, so we have to keep the option, and
a conservative default is better.


# 1.58 18-Nov-2009 nicm

Add a per-client log of status line messages displayed while that client
exists. A new message-limit session option sets the maximum number of entries
and a command, show-messages, shows the log (bound to ~ by default).

This (and prompt history) might be better as a single global log but until
there are global options it is easier for them to be per client.


# 1.57 10-Nov-2009 nicm

There is no real standard for modifier plus function keys. Previously, tmux
output some from rxvt but in other ways did the same as xterm or other
terminals, but this is a bit inconsistent.

xterm's method is fairly sensible and we already support it (xterm-keys), so
enable it by default instead.


# 1.56 04-Nov-2009 nicm

A couple of minor cosmetic changes.


# 1.55 04-Nov-2009 nicm

Initial changes to move tmux to libevent.

This moves the client-side loops are pretty much fully over to event-based only
(tmux.c and client.c) but server-side (server.c and friends) treats libevent as
a sort of clever poll, waking up after every event to run various things.

Moving the server stuff over to bufferevents and timers and so on will come
later.


# 1.54 04-Nov-2009 nicm

Change declaration and use of malloc_options to be more standard, from Tim van
der Molen.


# 1.53 26-Oct-2009 deraadt

tabs are better; ok nicm


# 1.52 25-Oct-2009 nicm

Remove the -d flag to tmux and just use op/AX to detect default colours.

Irritatingly, although op can be used to tell if a terminal supports default
colours, it can't be used to set them because in some terminfo descriptions it
resets attributes as a side-effect (acts as sgr0) and in others it doesn't, so
it is not possible to determine reliably what the terminal state will be
afterwards. So if AX is missing and op is present, tmux just sends sgr0.

Anyone using -d for a terminal who finds they actually needed it can replace it
using terminal-overrides, but please let me know as it is probably an omission
from terminfo.


# 1.51 22-Oct-2009 nicm

Merge prepare_cmd into main as it is short and only called once.


# 1.50 21-Oct-2009 nicm

Client tidying: get rid of client_ctx struct in favour of two variables in
client.c, and move the functions in client-fn.c into other files.


# 1.49 10-Oct-2009 nicm

New option, mouse-select-pane. If on, the mouse may be used to select the
current pane.

Suggested by sthen@ and also by someone else ages ago who I have forgotten.


# 1.48 10-Oct-2009 nicm

Support for individual session idle time locking. May be enabled by turning off
the lock-server option (it is on by default). When this is off, each session
locks when it has been idle for the lock-after-time setting. When on, the
entire server locks when ALL sessions have been idle for their individual
lock-after-time settings.

This replaces one global-only option (lock-after-time) with another
(lock-server), but the default behaviour is usually preferable so there don't
seem to be many alternatives.

Diff/idea largely from Thomas Adam, tweaked by me.


# 1.47 09-Oct-2009 nicm

Add a simple synchronize-panes window option: when set, all input to any pane
that is part of the window is also sent to all other panes in the same
window. Suggested by several, most recently Tomasz Pajor.


# 1.46 23-Sep-2009 nicm

Support -c like sh(1) to execute a command, useful when tmux is a login
shell. Suggested by halex@.

This includes another protocol version increase (the last for now) so again
restart the tmux server before upgrading.


# 1.45 23-Sep-2009 nicm

Remove the internal tmux locking and instead detach each client and run the
command specified by a new option "lock-command" (by default "lock -np") in
each client.

This means each terminal has to be unlocked individually but simplifies the
code and allows the system password to be used to unlock.

Note that the set-password command is gone, so it will need to be removed from
configuration files, and the -U command line flag has been removed.

This is the third protocol version change so again it is best to stop the tmux
server before upgrading.


# 1.44 22-Sep-2009 nicm

Permit multiple prefix keys to be defined, separated by commas, for example:

set -g prefix ^a,^b

Any key in the list acts as the prefix. The send-prefix command always sends
the first key in the list.


# 1.43 18-Sep-2009 nicm

New option, set-titles-string, to allow the window title to be specified (as
for status-left/right) if set-titles is on. Also only update the title when the
status line is being redrawn.


# 1.42 04-Sep-2009 nicm

Tidy main and make it a bit easier to read.


# 1.41 02-Sep-2009 nicm

Accept -l to make it easier for people who use tmux as a login shell to use
$SHELL. Originally from martynas@, tweaked by me.


# 1.40 02-Sep-2009 nicm

When incorrect passwords are entered, behave similarly to login(1) and backoff
for a bit. Based on a diff from martynas@.


# 1.39 01-Sep-2009 nicm

When using tmux as a login shell, there is currently no way to specify a shell
to be used as a login shell inside tmux, so add a default-shell session option.
This sets the shell invoked as a login shell when the default-command option is
empty.

The default option value is whichever of $SHELL, getpwuid(getuid())'s pw_shell
or /bin/sh is valid first.

Based on a diff from martynas@, changed by me to be a session option rather
than a window option.


# 1.38 01-Sep-2009 nicm

Use "Password:" with no space for password prompts and don't display a *s for
the password, like pretty much everything else. From martynas@ with minor
tweaks by me.


# 1.37 01-Sep-2009 nicm

Sort cases same as getopt argument, from martynas.


# 1.36 31-Aug-2009 nicm

Add a new display-panes command, with two options (display-panes-colour and
display-panes-time), which displays a visual indication of the number of each
pane.


# 1.35 23-Aug-2009 nicm

Add some other obvious variables to update-environment (WINDOWID SSH_ASKPASS
SSH_AUTH_SOCK SSH_AGENT_PID SSH_CONNECTION) so they are updated in the session
environment on new/attach.


# 1.34 13-Aug-2009 nicm

Disable mode-mouse (mouse in copy/choice mode) by default as it isn't very
useful at the moment and causes confusion.


# 1.33 13-Aug-2009 nicm

Add a base-index session option to specify the first index checked when looking
for an index for a new window.


# 1.32 12-Aug-2009 nicm

When started as the shell, __progname contains a leading -, so hardcode "tmux"
for socket path and log files, and strip it when working out the shell.


# 1.31 11-Aug-2009 nicm

Switch tmux to use imsg. This is the last major change to make the
client-server protocol more resilient and make the protocol versioning work
properly. In future, the only things requiring a protocol version bump will be
changes in the message structs, and (when both client and server have this
change) mixing different versions should nicely report an error message.

As a side effect this also makes the code tidier, fixes a problem with the way
errors reported during server startup were handled, and supports fd passing
(which will be used in future).

Looked over by eric@, thanks.

Please note that mixing a client with this change with an older server or vice
versa may cause tmux to crash or hang - tmux should be completely exited before
upgrading.


# 1.30 10-Aug-2009 nicm

No arguments are the same as new-session and this requires the environment to
be sent, so set that flag too when argc == 0.


# 1.29 08-Aug-2009 nicm

Infrastructure and commands to manage the environment for processes started
within tmux.

There is a global environment, copied from the external environment when the
server is started and each sesssion has an (initially empty) session
environment which overrides it.

New commands set-environment and show-environment manipulate or display the
environments.

A new session option, update-environment, is a space-separated list of
variables which are updated from the external environment into the session
environment every time a new session is created - the default is DISPLAY.


# 1.28 08-Aug-2009 nicm

Options to set the colours and attributes for status-left/-right. From Thomas
Adam, thanks.


# 1.27 05-Aug-2009 nicm

If colours are not supported by the terminal, try to emulate a coloured
background by setting or clearing the reverse attribute.

This makes a few applications which don't use the reverse attribute themselves
a little happier, and allows the status, message and mode options to have
default attributes and fg/bg options that work as expected when set as reverse.


# 1.26 04-Aug-2009 nicm

Check for "UTF8" as well as "UTF-8" in LANG etc as it seems this may also
appear.


# 1.25 03-Aug-2009 nicm

Add a terminal-overrides session option allowing individual terminfo(5) entries
to be overridden. The 88col/256col checks are now moved into the default
setting and out of the code.

Also remove a couple of old workarounds for xterm and rxvt which are no longer
necessary (tmux can emulate them if missing).


# 1.24 30-Jul-2009 nicm

Add a mode-mouse option to prevent tmux taking over the mouse in choice or copy
modes.


# 1.23 29-Jul-2009 nicm

Rename struct hdrtype to msgtype which is a better name and can be used even
when struct hdr disappears.


# 1.22 29-Jul-2009 nicm

Taking account of the "s, 22 not 24 is the maximum length of #T in status-right
to prevent the date being cut off.


# 1.21 26-Jul-2009 nicm

Make all messages sent between the client and server fixed size.

This is the first of two changes to make the protocol more resilient and less
sensitive to other changes in the code, particularly with commands. The client
now packs argv into a buffer and sends it to the server for parsing, rather
than doing it itself and sending the parsed command data.

As a side-effect this also removes a lot of now-unused command marshalling
code.

Mixing a server without this change and a client with or vice versa will cause
tmux to hang or crash, please ensure that tmux is entirely killed before
upgrading.


# 1.20 22-Jul-2009 nicm

Pass a set of flags into client_init rather than just a start_server
variable. Only one flag now but more to come later.


# 1.19 20-Jul-2009 nicm

Display the number of failed password attempts (if any) when the server is
locked. From Tom Doherty.


# 1.18 20-Jul-2009 nicm

Add a status-justify option to allow the window list in the status line to be
positioned at the left, centre, or right.


# 1.17 20-Jul-2009 nicm

New options, window-status-current-{fg,bg,attr}, to set the fg, bg and
attributes with which the current window is shown in the status line. From
Johan Friis, thanks.


# 1.16 18-Jul-2009 nicm

Add three new session options: visual-activity, visual-bell, visual-content. If
these are enabled (and the monitor-activity, bell-actio and monitor-content
options are configurated appropriately), when activity, a bell, or content is
detected, a message is shown.

Also tidy up the bell/activity/content code in server.c slightly and fix a
couple of errors.


# 1.15 17-Jul-2009 nicm

If -u is specified or UTF-8 is otherwise detected when the server is started,
enable the utf8 and status-utf8 optons. While here, note in the man page that
the server is started with the first session and exits when none remain.


# 1.14 10-Jul-2009 nicm

Add a default-terminal option to set the starting value of $TERM in new
windows.

This is "screen" by default and must be either that or something closely
related. This does makes it easier to customise it if necessary.


# 1.13 08-Jul-2009 nicm

Just appending -l to $SHELL to create a login shell is wrong: -l is not POSIX,
and some people may use shells which do not support it. Instead, make an empty
default-command option mean a login shell, and fork it with a - in argv[0]
which is the method used by login(1).

Also fix the automatic-rename code to handle this correctly and to strip a
leading - if present.


# 1.12 07-Jul-2009 nicm

Rename the global options variables to be shorter and to make session options
clear. No functional change, getting this out of the way to make later options
changes easier.


Revision tags: OPENBSD_4_6_BASE
# 1.11 25-Jun-2009 nicm

If getcwd() fails, use the user's home directory, or /, instead of failing with
an error.


# 1.10 25-Jun-2009 nicm

Remove error about using -L and -S together which was never displayed as
logging wasn't yet enabled, was unnecessary, and contradicted the man page
which says using -S will cause -L to be ignored.


# 1.9 23-Jun-2009 nicm

LC_ALL overrides LC_CTYPE and LANG. Comment was correct but the code
wrong. Pointed out by Hannah Schroeter, thanks.


# 1.8 05-Jun-2009 nicm

Check the first of LC_CTYPE, LC_ALL and LANG, rather than just the last, when
trying to decide about UTF-8, and use strcasestr. Reported by Geert Hendrickx.


# 1.7 04-Jun-2009 nicm

Zero the password given to -U in the client as well.


# 1.6 03-Jun-2009 nicm

Do not set the window title by default (make set-titles option default to off),
wiping over the title is rude and annoying. Agreed by several.


# 1.5 03-Jun-2009 nicm

New session option, status-utf8, to control the interpretation of top-bit-set
characters in status-left and status-right (if on, they are treated as UTF-8;
otherwise passed through).


# 1.4 02-Jun-2009 sobrado

remove unused flag; while here, make usage's output fit on 80-column displays.


# 1.3 02-Jun-2009 pyr

spawn login shells by default, adapt manpage bits as well.
ok nicm@


# 1.2 02-Jun-2009 ray

Don't leak memory if multiple -f flags are given.

OK nicm@


# 1.1 01-Jun-2009 nicm

Import tmux, a terminal multiplexor allowing (among other things) a single
terminal to be switched between several different windows and programs
displayed on one terminal be detached from one terminal and moved to another.

ok deraadt pirofti


# 1.203 22-Sep-2020 nicm

Fix warnings on some platforms with %llx and add a new message to handle
64-bit client flags.


# 1.202 02-Jun-2020 nicm

Use CLOCK_MONOTONIC for timer measurement and add a timestamp to control
mode %output blocks.


# 1.201 16-May-2020 nicm

Add a -D flag to ask tmux not to daemonize, useful both for running a
debugger (lldb does not have follow-fork-mode) and for running with a
managed supervisor init system. GitHub issue 2190.


# 1.200 16-May-2020 nicm

Add 'e' key in buffer mode to open the buffer in an editor.


# 1.199 16-May-2020 nicm

Build list of paths and weed out duplicates before loading configs, and
add TMUX_SOCK like TMUX_PATH for the socket directory.


Revision tags: OPENBSD_6_7_BASE
# 1.198 20-Apr-2020 nicm

Tidy up the terminal detection and feature code and add named sets of
terminal features, each of which are defined in one place and map to a
builtin set of terminfo(5) capabilities. Features can be specified based
on TERM with a new terminal-features option or with the -T flag when
running tmux. tmux will also detect a few common terminals from the DA
and DSR responses.

This is intended to make it easier to configure tmux's use of
terminfo(5) even in the presence of outdated ncurses(3) or terminfo(5)
databases or for features which do not yet have a terminfo(5) entry.
Instead of having to grok terminfo(5) capability names and what they
should be set to in the terminal-overrides option, the user can
hopefully just give tmux a feature name and let it do the right thing.

The terminal-overrides option remains both for backwards compatibility
and to allow tweaks of individual capabilities.

tmux already did much of this already, this makes it tidier and simpler
to configure.


# 1.197 16-Apr-2020 nicm

Show signal name when process exits rather than number.


# 1.196 09-Apr-2020 nicm

More style nits.


# 1.195 31-Mar-2020 nicm

Add a way to mark environment variables as "hidden" so they can be used
by tmux but are not passed into the environment of new panes.


# 1.194 17-Mar-2020 nicm

Ignore default-shell (and use /bin/sh) if it invalid not just if it is
tmux itself, also refuse to set the option to something invalid in the
first place. GitHub issue 2120.


# 1.193 12-Mar-2020 nicm

When the server socket is given by the user with -S, create it with
umask 177 instead of 117 because it may not be in a safe directory like
the default directory in /tmp. The user can chmod it more open after it
is created if they want.


# 1.192 28-Jan-2020 nicm

-V also needs to go in usage.


# 1.191 28-Jan-2020 nicm

Reduce a difference with portable tmux by adding the -V flag and
#{version} format; on OpenBSD these just report the OpenBSD version.


# 1.190 14-Oct-2019 nicm

Memory leaks, from Igor Wong in GitHub issue 1934.


Revision tags: OPENBSD_6_6_BASE
# 1.189 20-Jun-2019 nicm

Add a per-pane option set. Pane options inherit from window options (so
there should be no change to existing behaviour) and are set and shown
with set-option -p and show-options -p.

Change remain-on-exit and window-style/window-active-style to be pane
options (some others will be changed later).

This makes select-pane -P and -g unnecessary so no longer document them
(they still work) and no longer document set-window-option and
show-window-options in favour of set-option -w and show-options -w.


# 1.188 26-Apr-2019 nicm

Merge hooks into options and make each one an array option. This allows
multiple commands to be easily bound to one hook. set-hook and
show-hooks remain but they are now variants of set-option and
show-options. show-options now has a -H flag to show hooks (by default
they are not shown).


Revision tags: OPENBSD_6_5_BASE
# 1.187 22-Nov-2018 nicm

Do not use PWD unless it actually matches the real working directory.


Revision tags: OPENBSD_6_3_BASE OPENBSD_6_4_BASE
# 1.186 12-Jan-2018 nicm

Improve error message if creating socket parent directory fails, from
Thomas Adam for GitHub issue 1215.


# 1.185 01-Jan-2018 nicm

Prefer PWD for current directory if present in client, from Wei Zhao in
GitHub issue 1183.


Revision tags: OPENBSD_6_2_BASE
# 1.184 12-Jul-2017 nicm

Make shell_command a global like other stuff rather than making it an
exception and using callback argument.


# 1.183 03-Jul-2017 nicm

Try C.UTF-8 which is also a commonly useful locale on some platforms,
from Romain Francoise.


# 1.182 22-Apr-2017 nicm

Do not need getopt.h.


# 1.181 20-Apr-2017 nicm

Use fdforkpty() instead of our own unwrapped versions.


# 1.180 19-Apr-2017 nicm

Style nits and a missing cast.


# 1.179 16-Apr-2017 nicm

Memory leak, from David CARLIER.


Revision tags: OPENBSD_6_1_BASE
# 1.178 21-Mar-2017 nicm

Use uid_t for UID not u_int.


# 1.177 16-Feb-2017 nicm

Style nits.


# 1.176 23-Jan-2017 nicm

Open /dev/ptm before pledge() and save it to be used for PTMGET later
(this means inlining forkpty()).

ok deraadt


# 1.175 15-Jan-2017 nicm

Major tidy up and rework of options tree and set-option/show-options
commands this pushes more of the code into options.c and ties it more
closely to the options table rather than having an unnecessary
split. Also add support for array options (will be used later). Only
(intentional) user visible change is that show-options output is now
passed through vis(3) with VIS_DQ so quotes are escaped.


# 1.174 12-Jan-2017 nicm

Simplify appending to string options.


# 1.173 09-Dec-2016 nicm

Spacing nits.


# 1.172 11-Oct-2016 nicm

Add static in window-*.c and move some internal functions out of tmux.h.


# 1.171 10-Oct-2016 nicm

Loads more static, except for cmd-*.c and window-*.c.


Revision tags: OPENBSD_6_0_BASE
# 1.170 27-May-2016 nicm

Use getprogname() instead of __progname to make portability easier.


# 1.169 04-May-2016 nicm

Fix up a couple of long lines.


# 1.168 05-Mar-2016 nicm

If setlocale("en_US.UTF-8") succeeds, then don't do the check for UTF-8
locale since if it isn't UTF-8 the system is broken anyway. If it fails,
try "" and check for UTF-8 with nl_langinfo(CODESET) rather than
wcwidth(). Based on a diff from schwarze@, nl_langinfo also suggested by
stsp@.


# 1.167 05-Mar-2016 nicm

Although we always have en_US.UTF-8 on OpenBSD, some platforms do not,
so fall back to setlocale(LC_CTYPE, ""). tmux requires a UTF-8 locale,
so check with wcwidth() on a UTF-8 character after setlocale().


# 1.166 01-Mar-2016 nicm

Remove unused variables, from Michal Mazurek.


# 1.165 01-Mar-2016 nicm

Use system wcwidth() instead of carrying around UTF-8 width tables.


Revision tags: OPENBSD_5_9_BASE
# 1.164 19-Jan-2016 nicm

I no longer use my SourceForge address so replace it.


# 1.163 08-Dec-2015 nicm

Add hooks infrastructure, basic commands (set-hook, show-hooks) and a
couple of not very useful client hooks. This will eventually let
commands be run at various points and on notifications. Joint work with
Thomas Adam.


# 1.162 24-Nov-2015 nicm

Make environ_set va_args and use it to tidy up some calls. Also add a
missing word in manpage (from jmc).


# 1.161 24-Nov-2015 nicm

Shell command from -c doesn't have to be global, pass it as an argument.


# 1.160 24-Nov-2015 nicm

Tidy the code that works out the socket path, and just use the full path
in the global socket_path rather than copying it.


# 1.159 24-Nov-2015 nicm

Remove malloc_options DEBUG bit.


# 1.158 24-Nov-2015 nicm

Remove the -I part of show-messages which isn't really that useful; the
server start time can now be accessed with a new start_time format (use:
tmux display -p '#{t:start_time}')


# 1.157 24-Nov-2015 nicm

Make the log stuff a bit tidier with some helper functions.


# 1.156 22-Nov-2015 nicm

Add getpw to pledge, makes tmux work in YP environments, discovered by
matthieu, ok deraadt


# 1.155 20-Nov-2015 nicm

Instead of separate tables for different types of options, give each
option a scope type (server, session, window) in one table.


# 1.154 15-Nov-2015 nicm

Accidentally turned off pledge, turn it back on.


# 1.153 14-Nov-2015 nicm

Push stdout and stderr to clients more aggressively, and add an event to
continue if the send fails.


# 1.152 12-Nov-2015 nicm

tmux is UTF-8, so if $TMUX is set (tmux running in tmux), the client is
UTF-8. Also try to make the existing checks more readable.


# 1.151 12-Nov-2015 nicm

Nuke the utf8 and status-utf8 options and make tmux only a UTF-8
terminal. We still support non-UTF-8 terminals outside tmux, but inside
it is always UTF-8 (as when the utf8 and status-utf8 options were on).


# 1.150 11-Nov-2015 nicm

Drop mouse-utf8 option and always turn on UTF-8 mouse if the client says
it supports UTF-8.


# 1.149 28-Oct-2015 nicm

Like options, move the environ struct into environ.c.


# 1.148 27-Oct-2015 nicm

Move struct options into options.c.


# 1.147 27-Oct-2015 nicm

Break the common process set up, event loop and imsg dispatch code
between server and client out into a separate internal API. This will
make it easier to add another process.


# 1.146 25-Oct-2015 deraadt

Let's see if anyone screams about not being able to specify $TMPDIR
for their tmux sockets.

(Over the years, I have seen $TMPDIR set up worse than /tmp many times,
and don't know how this practice infected other parts of the system.
Nothing uses tmpdir(3), nor a huge-temporary-file program like sort.)
ok nicm


# 1.145 23-Oct-2015 nicm

tmux can call pledge() in main with large set and then reduce it
slightly in the server to "stdio rpath wpath cpath fattr unix recvfd
proc exec tty ps".


# 1.144 14-Sep-2015 nicm

Move tzset() from log_open to main.


# 1.143 03-Sep-2015 nicm

A couple of style nits.


# 1.142 01-Sep-2015 nicm

Work out config file when needed not at startup.


# 1.141 30-Aug-2015 nicm

Path from $TMUX does not need to be global anymore.


# 1.140 30-Aug-2015 nicm

Login shell can be a client flag, and move the exec code into client.c.


# 1.139 30-Aug-2015 nicm

Event base does not need to be global.


# 1.138 30-Aug-2015 nicm

Some style nits and dead assignments.


Revision tags: OPENBSD_5_8_BASE
# 1.137 20-Jul-2015 nicm

Add an option (history-file) for a file to save/restore command prompt
history, from Olof-Joachim Frahm.


# 1.136 04-Jun-2015 jmc

tweak SYNOPSIS and usage();


Revision tags: OPENBSD_5_7_BASE
# 1.135 19-Jan-2015 nicm

Make a tmux-%u directory under TMUX_TMPDIR, like TMPDIR.


# 1.134 19-Jan-2015 nicm

Only care about other permissions, allow group to be set.


# 1.133 19-Jan-2015 nicm

Remove unnecessary duplicate S_ISDIR check, from Dmitri Paduchikh.


# 1.132 20-Oct-2014 nicm

Tidy up some includes.


Revision tags: OPENBSD_5_6_BASE
# 1.131 17-Apr-2014 nicm

Remove the "info" message mechanism, this was only used for about five
mostly useless and annoying messages. Change those commands to silence
on success like all the others. Still accept the -q command line flag
and "quiet" server option for now.


# 1.130 31-Mar-2014 nicm

Remove log_debug2 as well and simplify log.c.


Revision tags: OPENBSD_5_5_BASE
# 1.129 16-Feb-2014 nicm

Leftovers from removing 88 colour support, from Theo Buehler.


# 1.128 15-Jan-2014 nicm

Do not attempt to read .tmux.conf if we can't figure out a home
directory, from Tiago Cunha.


# 1.127 09-Jan-2014 nicm

Three small changes from Tiago Cunha:

- Check for truncation when copying path.
- Don't need to use a temporary buffer in screen_set_title.
- Include strerror in output when connecting to server fails.


# 1.126 10-Oct-2013 nicm

We accidentally haven't been using $TMUX to work out the session for a
while and in fact it is less useful that using the client ttyname. So
don't bother and don't pass it from the client. If we need it in future
it is in c->environ.


# 1.125 10-Oct-2013 nicm

Alter how tmux handles the working directory to internally use file
descriptors rather than strings.

- Each session still has a current working directory.

- New sessions still get their working directory from the client that
created them or its attached session if any.

- New windows are created by default in the session working directory.

- The -c flag to new, neww, splitw allows the working directory to be
overridden.

- The -c flag to attach let's the session working directory be changed.

- The default-path option has been removed.

To get the equivalent to default-path '.', do:

bind c neww -c $PWD

To get the equivalent of default-path '~', do:

bind c neww -c ~

This also changes the client identify protocol to be a set of messages rather
than one as well as some other changes that should make it easier to make
backwards-compatible protocol changes in future.


# 1.124 10-Oct-2013 nicm

Merge IDENTIFY_* flags with CLIENT_* flags.


# 1.123 10-Oct-2013 nicm

Don't treat TMUX_TMPDIR as a potential file

The point of setting TMUX_TMPDIR is to then make any labels from -L go
to that directory. In the case of makesocketpath() with no TMUX_TMPDIR
set, would set both the path and the default socket to a file. The
checking of the permissions on the file worked fine in that case, but
when TMUX_TMPDIR is set, won't work on a directory.

This fixes the problem by ensuring the check on the permissions is
performed on directories only.

By Thomas Adam.


# 1.122 05-Oct-2013 nicm

Fix previous not to leak fd on failure, whoops.


# 1.121 05-Oct-2013 nicm

Use open(".")/fchdir() to save and restore current directory rather than
getcwd()/chdir().


Revision tags: OPENBSD_5_4_BASE
# 1.120 24-Apr-2013 nicm

Rename global configuration define.


# 1.119 11-Apr-2013 nicm

Call setlocale(LC_TIME) at startup.


# 1.118 27-Mar-2013 nicm

Add TMUX_TMPDIR variable to put the socket directory outside
TMPDIR. From Ben Boeckel.


# 1.117 27-Mar-2013 nicm

Remove tmux's (already minimal) 88 colour support. Such terminals are
few and unnecessary.


# 1.116 25-Mar-2013 nicm

Rename session idx to session id throughout and add $ prefix to targets
to use it, extended from a diff from George Nachman.


# 1.115 24-Mar-2013 nicm

Add a command queue to standardize and simplify commands that call other
commands and allow a command to block execution of subsequent
commands. This allows run-shell and if-shell to be synchronous which has
been much requested.

Each client has a default command queue and commands are consumed one at
a time from it. A command may suspend execution from the queue by
returning CMD_RETURN_WAIT and then resume it by calling cmd_continue() -
for example run-shell does this from the callback that is fired after
the job is freed.

When the command queue becomes empty, command clients are automatically
exited (unless attaching). A callback is also fired - this is used for
nested commands in, for example, if-shell which can block execution of
the client's cmdq until a new cmdq becomes empty.

Also merge all the old error/info/print functions together and lose the
old curclient/cmdclient distinction - a cmdq is bound to one client (or
none if in the configuration file), this is a command client if
c->session is NULL otherwise an attached client.


Revision tags: OPENBSD_5_3_BASE
# 1.114 27-Nov-2012 nicm

Correctly aggregate together errors from nested config files (with
source-file). Fix by Thomas Adam, reported by Sam Livingstone-Gray


# 1.113 26-Nov-2012 nicm

Call realpath earlier on the socket directory path rather than on the
socket file path because the latter may not exist yet and in that case
realpath is allowed to fail. From Romain Francoise.


Revision tags: OPENBSD_5_2_BASE
# 1.112 10-Jul-2012 nicm

xfree is not particularly helpful, remove it. From Thomas Adam.


# 1.111 18-Jun-2012 nicm

Add a skeleton mode to tmux (called "control mode") that let's tmux
commands be sent and output received on stdout. This can be used to
integrate with other terminal emulators and should allow some other
things to be made simpler later. More to come so doesn't do much yet and
deliberately not documented.


# 1.110 30-May-2012 nicm

Do not use stderr for log file and don't call log_close when not needed.


# 1.109 25-May-2012 nicm

Simplify logging and just fprintf(stderr, ...) for early errors.


Revision tags: OPENBSD_5_1_BASE
# 1.108 21-Jan-2012 nicm

Drop the ability to have a list of keys in the prefix in favour of two
separate options, prefix and prefix2. This simplifies the code and gets
rid the data options type which was only used for this one option.

Also add a -2 flag to send-prefix to send the secondary prefix key,
fixing a cause of minor irritation.

People who want three prefix keys are out of luck :-).


# 1.107 23-Oct-2011 nicm

Try to resolve relative paths for loadb and saveb (first using client
working directory if any then default-path or session wd).


# 1.106 23-Oct-2011 nicm

Ignore LC_ALL and LC_CTYPE if they are empty as well as unset.


# 1.105 25-Sep-2011 nicm

Reject $SHELL if it is not a full path.


Revision tags: OPENBSD_5_0_BASE
# 1.104 04-Mar-2011 nicm

Two fixes by Micah Cowan: make mouse work properly beyond >127 on signed
char architectures and properly parse $TMUX by stopping the socket path
at the first comma.


Revision tags: OPENBSD_4_9_BASE
# 1.103 23-Jan-2011 nicm

Set $TMUX without the session when background jobs are run.


# 1.102 12-Jan-2011 nicm

Use TMPDIR if set, from Han Boetes.


# 1.101 08-Jan-2011 nicm

Move all calls to fcntl(...O_NONBLOCK) into a function and clear the
flag on the stdio file descriptors before closing them (fixes things
like "tmux ls && cat").


# 1.100 03-Jan-2011 nicm

Support for UTF-8 mouse input (\033[1005h). This was added in xterm 262
and supports larger terminals than the older way.

If the new mouse-utf8 option is on, UTF-8 mouse input is enabled for all
UTF-8 terminals. The option defaults to on if LANG etc are set in the
same manner as the utf8 option.

With help and based on code from hsim at gmx.li.


# 1.99 01-Jan-2011 nicm

Move the user-visible parts of all options (names, types, limit, default
values) together into one set of tables in options-table.c. Also clean
up and simplify cmd-set-options.c and move a common print function into
option-table.c.


# 1.98 30-Dec-2010 nicm

Change from a per-session stack of buffers to one global stack which is
much more convenient and also simplifies lot of code. This renders
copy-buffer useless and makes buffer-limit now a server option.

By Tiago Cunha.


# 1.97 19-Dec-2010 nicm

Add other-pane-height and other-pane-width options, allowing the width
or height of the smaller panes in the main-horizontal and main-vertical
layouts to be set. Mostly from David Goodlad.


# 1.96 08-Dec-2010 nicm

In the built-in layouts, distribute the panes more evenly. Set the
default value of main-pane-width to 80, rather than 81. By Micah Cowan.


# 1.95 06-Dec-2010 nicm

Add an option to alert (monitor) for silence (lack of activity) in a
window. From Thomas Adam.


# 1.94 29-Nov-2010 nicm

If VISUAL or EDITOR contains "vi", configure mode-keys and status-keys
to vi.

Based on a diff from martynas@, previously requested by a couple of
other people.


# 1.93 11-Nov-2010 nicm

Add XAUTHORITY to update-environment, requested by Andreas Kloeckner.


# 1.92 18-Oct-2010 nicm

Merge the before and after attach client code into one in client.c
(instead of two in tmux.c and client.c).


# 1.91 16-Oct-2010 nicm

Make stdio blocking again before calling shell command with -c.


# 1.90 16-Oct-2010 nicm

Trying to set FD_CLOEXEC on every fd is a lost cause, just use
closefrom() before exec.


# 1.89 14-Oct-2010 nicm

Use an explicit event rather than event_once for the main event so it
can be removed when the client becomes ready.


# 1.88 26-Sep-2010 nicm

Two new options:

- server option "exit-unattached" makes the server exit when no clients
are attached, even if sessions are present;

- session option "destroy-unattached" destroys a session once no clients
are attached to it.

These are useful for preventing tmux remaining in the background where
it is undesirable and when using tmux as a login shell to keep a limit
on new sessions.


# 1.87 19-Aug-2010 nicm

Do not call event_del() for signals after fork(), just use sigaction()
directly instead - calling libevent functions after fork() w/o
event_reinit() is a bad idea, even if in this case it was harmless.


Revision tags: OPENBSD_4_8_BASE
# 1.86 04-Aug-2010 deraadt

switch back to kqueue for now, since (a) kqueue has been fixed to deal
with strange devices and (b) since there appears to be a bull in the
poll code in libevent as well...
requested by nicm who is away


# 1.85 24-Jul-2010 nicm

kqueue(2) is currently broken when used with /dev/null and a few other
devices.

An upcoming fix for some problems with the client stdout/stderr handling
relies on it working, so make tmux force libevent to use poll(2) via
EVENT_NOKQUEUE, until we have fixed kqueue.


# 1.84 11-Jul-2010 nicm

Return the command client return code with MSG_EXIT now that MSG_ERROR and
MSG_PRINT are unused.

New clients should be compatible with old tmux servers but vice versa may print
an error.


# 1.83 28-Jun-2010 nicm

Send all three of stdin, stdout, stderr from the client to the server, so that
commands can directly make use of them. This means that load-buffer and
save-buffer can have "-" as the file to read from stdin or write to stdout.

This is a protocol version bump so the tmux server will need to be restarted
after upgrade (or an older client used).


# 1.82 27-Jun-2010 nicm

Store the current working directory in the session, change the default-path
option to default to empty and make that mean that the stored session CWD is
used.


# 1.81 27-Jun-2010 nicm

New option, detach-on-destroy, to set what happens to a client when the session
it is attached to is destroyed. If on (the default), it is detached; if off, it
is switched to the most recently active session.


# 1.80 26-Jun-2010 nicm

Setting the cmdlist pointer in the bind-key to NULL to prevent it being freed
after the command is executing is bogus because it may still be needed if the
same command is going to be executed again (for example if you "bind-key a
bind-key b ..."). Making a copy is hard, so instead add a reference count to
the cmd_list.

While here, also print bind-key -n and the rest of the flags properly.

Fixes problem reported by mcbride@.


# 1.79 14-May-2010 nicm

Colour+attribute options for status line alerts, from Alex Alexander.


# 1.78 04-May-2010 nicm

Put this back in with the initialisation in the right order.


# 1.77 04-May-2010 nicm

Revert last change, it appears to be broken somehow.


# 1.76 03-May-2010 nicm

Make signal handler setup/teardown two common functions instead of six,
and reset SIGCHLD after fork to fix problems with some shells. From
Romain Francois.


# 1.75 28-Apr-2010 nicm

Make the active pane border have a green foreground instead of
background by default.


# 1.74 18-Apr-2010 nicm

Catch SIGCHLD to avoid a zombie, from patrick keshishian.


Revision tags: OPENBSD_4_7_BASE
# 1.73 22-Feb-2010 nicm

Option to set the characters considered word separators in copy mode, from
Micah Cowan.


# 1.72 08-Feb-2010 nicm

Add an option to disable the smcup/rmcup alternate screen behaviour inside
tmux. From clemens fischer.


# 1.71 06-Feb-2010 nicm

Change nested check to compare server socket path rather than just assuming
that if $TMUX is set it is nested. From Micah Cowan.


# 1.70 06-Feb-2010 nicm

Clean up $TMUX parsing, from Micah Cowan, tweaked by me.


# 1.69 06-Feb-2010 nicm

Instead of bailing out on the first configuration file error, carry on,
collecting all the errors, then start with the active window in more mode
displaying them.


# 1.68 04-Feb-2010 nicm

Read the path from $TMUX if it is present and -L and -S are not given. Based on
a diff from Micah Cowan.


# 1.67 04-Feb-2010 nicm

Option to display the active pane in a different colour with the display-panes
command. From Paul Hoffman, thanks.


# 1.66 03-Jan-2010 nicm

Options to set the colour of the pane borders, with different colours for the
active pane.


# 1.65 14-Dec-2009 nicm

New server option, escape-time, to set the timeout used to detect if escapes
are alone or part of a function key or meta sequence.


# 1.64 11-Dec-2009 nicm

Use quiet variable, and add missing sentinel to options array.


# 1.63 10-Dec-2009 nicm

Add "server options" which are server-wide and not bound to a session or
window. Set and displayed with "set -s" and "show -s".

Currently the only option is "quiet" (like command-line -q, allowing it to be
set from .tmux.conf), but others will come along.


# 1.62 03-Dec-2009 nicm

Massive spaces->tabs and trailing whitespace cleanup, hopefully for the last
time now I've configured emacs to make them displayed in really annoying
colours...


# 1.61 26-Nov-2009 nicm

Remove a couple of unused arguments where possible, and add /* ARGSUSED */ to
the rest to reduce lint output.


# 1.60 19-Nov-2009 nicm

Two new options, window-status-format and window-status-current-format, which
allow the format of each window in the status line window list to be controlled
using similar # sequences as status-left/right.

This diff also moves part of the way towards UTF-8 support in window names but
it isn't quite there yet.


# 1.59 19-Nov-2009 nicm

Revert to xterm-keys off by default. It was on as an experiment to see if the
option could be removed, but it affects vi, so we have to keep the option, and
a conservative default is better.


# 1.58 18-Nov-2009 nicm

Add a per-client log of status line messages displayed while that client
exists. A new message-limit session option sets the maximum number of entries
and a command, show-messages, shows the log (bound to ~ by default).

This (and prompt history) might be better as a single global log but until
there are global options it is easier for them to be per client.


# 1.57 10-Nov-2009 nicm

There is no real standard for modifier plus function keys. Previously, tmux
output some from rxvt but in other ways did the same as xterm or other
terminals, but this is a bit inconsistent.

xterm's method is fairly sensible and we already support it (xterm-keys), so
enable it by default instead.


# 1.56 04-Nov-2009 nicm

A couple of minor cosmetic changes.


# 1.55 04-Nov-2009 nicm

Initial changes to move tmux to libevent.

This moves the client-side loops are pretty much fully over to event-based only
(tmux.c and client.c) but server-side (server.c and friends) treats libevent as
a sort of clever poll, waking up after every event to run various things.

Moving the server stuff over to bufferevents and timers and so on will come
later.


# 1.54 04-Nov-2009 nicm

Change declaration and use of malloc_options to be more standard, from Tim van
der Molen.


# 1.53 26-Oct-2009 deraadt

tabs are better; ok nicm


# 1.52 25-Oct-2009 nicm

Remove the -d flag to tmux and just use op/AX to detect default colours.

Irritatingly, although op can be used to tell if a terminal supports default
colours, it can't be used to set them because in some terminfo descriptions it
resets attributes as a side-effect (acts as sgr0) and in others it doesn't, so
it is not possible to determine reliably what the terminal state will be
afterwards. So if AX is missing and op is present, tmux just sends sgr0.

Anyone using -d for a terminal who finds they actually needed it can replace it
using terminal-overrides, but please let me know as it is probably an omission
from terminfo.


# 1.51 22-Oct-2009 nicm

Merge prepare_cmd into main as it is short and only called once.


# 1.50 21-Oct-2009 nicm

Client tidying: get rid of client_ctx struct in favour of two variables in
client.c, and move the functions in client-fn.c into other files.


# 1.49 10-Oct-2009 nicm

New option, mouse-select-pane. If on, the mouse may be used to select the
current pane.

Suggested by sthen@ and also by someone else ages ago who I have forgotten.


# 1.48 10-Oct-2009 nicm

Support for individual session idle time locking. May be enabled by turning off
the lock-server option (it is on by default). When this is off, each session
locks when it has been idle for the lock-after-time setting. When on, the
entire server locks when ALL sessions have been idle for their individual
lock-after-time settings.

This replaces one global-only option (lock-after-time) with another
(lock-server), but the default behaviour is usually preferable so there don't
seem to be many alternatives.

Diff/idea largely from Thomas Adam, tweaked by me.


# 1.47 09-Oct-2009 nicm

Add a simple synchronize-panes window option: when set, all input to any pane
that is part of the window is also sent to all other panes in the same
window. Suggested by several, most recently Tomasz Pajor.


# 1.46 23-Sep-2009 nicm

Support -c like sh(1) to execute a command, useful when tmux is a login
shell. Suggested by halex@.

This includes another protocol version increase (the last for now) so again
restart the tmux server before upgrading.


# 1.45 23-Sep-2009 nicm

Remove the internal tmux locking and instead detach each client and run the
command specified by a new option "lock-command" (by default "lock -np") in
each client.

This means each terminal has to be unlocked individually but simplifies the
code and allows the system password to be used to unlock.

Note that the set-password command is gone, so it will need to be removed from
configuration files, and the -U command line flag has been removed.

This is the third protocol version change so again it is best to stop the tmux
server before upgrading.


# 1.44 22-Sep-2009 nicm

Permit multiple prefix keys to be defined, separated by commas, for example:

set -g prefix ^a,^b

Any key in the list acts as the prefix. The send-prefix command always sends
the first key in the list.


# 1.43 18-Sep-2009 nicm

New option, set-titles-string, to allow the window title to be specified (as
for status-left/right) if set-titles is on. Also only update the title when the
status line is being redrawn.


# 1.42 04-Sep-2009 nicm

Tidy main and make it a bit easier to read.


# 1.41 02-Sep-2009 nicm

Accept -l to make it easier for people who use tmux as a login shell to use
$SHELL. Originally from martynas@, tweaked by me.


# 1.40 02-Sep-2009 nicm

When incorrect passwords are entered, behave similarly to login(1) and backoff
for a bit. Based on a diff from martynas@.


# 1.39 01-Sep-2009 nicm

When using tmux as a login shell, there is currently no way to specify a shell
to be used as a login shell inside tmux, so add a default-shell session option.
This sets the shell invoked as a login shell when the default-command option is
empty.

The default option value is whichever of $SHELL, getpwuid(getuid())'s pw_shell
or /bin/sh is valid first.

Based on a diff from martynas@, changed by me to be a session option rather
than a window option.


# 1.38 01-Sep-2009 nicm

Use "Password:" with no space for password prompts and don't display a *s for
the password, like pretty much everything else. From martynas@ with minor
tweaks by me.


# 1.37 01-Sep-2009 nicm

Sort cases same as getopt argument, from martynas.


# 1.36 31-Aug-2009 nicm

Add a new display-panes command, with two options (display-panes-colour and
display-panes-time), which displays a visual indication of the number of each
pane.


# 1.35 23-Aug-2009 nicm

Add some other obvious variables to update-environment (WINDOWID SSH_ASKPASS
SSH_AUTH_SOCK SSH_AGENT_PID SSH_CONNECTION) so they are updated in the session
environment on new/attach.


# 1.34 13-Aug-2009 nicm

Disable mode-mouse (mouse in copy/choice mode) by default as it isn't very
useful at the moment and causes confusion.


# 1.33 13-Aug-2009 nicm

Add a base-index session option to specify the first index checked when looking
for an index for a new window.


# 1.32 12-Aug-2009 nicm

When started as the shell, __progname contains a leading -, so hardcode "tmux"
for socket path and log files, and strip it when working out the shell.


# 1.31 11-Aug-2009 nicm

Switch tmux to use imsg. This is the last major change to make the
client-server protocol more resilient and make the protocol versioning work
properly. In future, the only things requiring a protocol version bump will be
changes in the message structs, and (when both client and server have this
change) mixing different versions should nicely report an error message.

As a side effect this also makes the code tidier, fixes a problem with the way
errors reported during server startup were handled, and supports fd passing
(which will be used in future).

Looked over by eric@, thanks.

Please note that mixing a client with this change with an older server or vice
versa may cause tmux to crash or hang - tmux should be completely exited before
upgrading.


# 1.30 10-Aug-2009 nicm

No arguments are the same as new-session and this requires the environment to
be sent, so set that flag too when argc == 0.


# 1.29 08-Aug-2009 nicm

Infrastructure and commands to manage the environment for processes started
within tmux.

There is a global environment, copied from the external environment when the
server is started and each sesssion has an (initially empty) session
environment which overrides it.

New commands set-environment and show-environment manipulate or display the
environments.

A new session option, update-environment, is a space-separated list of
variables which are updated from the external environment into the session
environment every time a new session is created - the default is DISPLAY.


# 1.28 08-Aug-2009 nicm

Options to set the colours and attributes for status-left/-right. From Thomas
Adam, thanks.


# 1.27 05-Aug-2009 nicm

If colours are not supported by the terminal, try to emulate a coloured
background by setting or clearing the reverse attribute.

This makes a few applications which don't use the reverse attribute themselves
a little happier, and allows the status, message and mode options to have
default attributes and fg/bg options that work as expected when set as reverse.


# 1.26 04-Aug-2009 nicm

Check for "UTF8" as well as "UTF-8" in LANG etc as it seems this may also
appear.


# 1.25 03-Aug-2009 nicm

Add a terminal-overrides session option allowing individual terminfo(5) entries
to be overridden. The 88col/256col checks are now moved into the default
setting and out of the code.

Also remove a couple of old workarounds for xterm and rxvt which are no longer
necessary (tmux can emulate them if missing).


# 1.24 30-Jul-2009 nicm

Add a mode-mouse option to prevent tmux taking over the mouse in choice or copy
modes.


# 1.23 29-Jul-2009 nicm

Rename struct hdrtype to msgtype which is a better name and can be used even
when struct hdr disappears.


# 1.22 29-Jul-2009 nicm

Taking account of the "s, 22 not 24 is the maximum length of #T in status-right
to prevent the date being cut off.


# 1.21 26-Jul-2009 nicm

Make all messages sent between the client and server fixed size.

This is the first of two changes to make the protocol more resilient and less
sensitive to other changes in the code, particularly with commands. The client
now packs argv into a buffer and sends it to the server for parsing, rather
than doing it itself and sending the parsed command data.

As a side-effect this also removes a lot of now-unused command marshalling
code.

Mixing a server without this change and a client with or vice versa will cause
tmux to hang or crash, please ensure that tmux is entirely killed before
upgrading.


# 1.20 22-Jul-2009 nicm

Pass a set of flags into client_init rather than just a start_server
variable. Only one flag now but more to come later.


# 1.19 20-Jul-2009 nicm

Display the number of failed password attempts (if any) when the server is
locked. From Tom Doherty.


# 1.18 20-Jul-2009 nicm

Add a status-justify option to allow the window list in the status line to be
positioned at the left, centre, or right.


# 1.17 20-Jul-2009 nicm

New options, window-status-current-{fg,bg,attr}, to set the fg, bg and
attributes with which the current window is shown in the status line. From
Johan Friis, thanks.


# 1.16 18-Jul-2009 nicm

Add three new session options: visual-activity, visual-bell, visual-content. If
these are enabled (and the monitor-activity, bell-actio and monitor-content
options are configurated appropriately), when activity, a bell, or content is
detected, a message is shown.

Also tidy up the bell/activity/content code in server.c slightly and fix a
couple of errors.


# 1.15 17-Jul-2009 nicm

If -u is specified or UTF-8 is otherwise detected when the server is started,
enable the utf8 and status-utf8 optons. While here, note in the man page that
the server is started with the first session and exits when none remain.


# 1.14 10-Jul-2009 nicm

Add a default-terminal option to set the starting value of $TERM in new
windows.

This is "screen" by default and must be either that or something closely
related. This does makes it easier to customise it if necessary.


# 1.13 08-Jul-2009 nicm

Just appending -l to $SHELL to create a login shell is wrong: -l is not POSIX,
and some people may use shells which do not support it. Instead, make an empty
default-command option mean a login shell, and fork it with a - in argv[0]
which is the method used by login(1).

Also fix the automatic-rename code to handle this correctly and to strip a
leading - if present.


# 1.12 07-Jul-2009 nicm

Rename the global options variables to be shorter and to make session options
clear. No functional change, getting this out of the way to make later options
changes easier.


Revision tags: OPENBSD_4_6_BASE
# 1.11 25-Jun-2009 nicm

If getcwd() fails, use the user's home directory, or /, instead of failing with
an error.


# 1.10 25-Jun-2009 nicm

Remove error about using -L and -S together which was never displayed as
logging wasn't yet enabled, was unnecessary, and contradicted the man page
which says using -S will cause -L to be ignored.


# 1.9 23-Jun-2009 nicm

LC_ALL overrides LC_CTYPE and LANG. Comment was correct but the code
wrong. Pointed out by Hannah Schroeter, thanks.


# 1.8 05-Jun-2009 nicm

Check the first of LC_CTYPE, LC_ALL and LANG, rather than just the last, when
trying to decide about UTF-8, and use strcasestr. Reported by Geert Hendrickx.


# 1.7 04-Jun-2009 nicm

Zero the password given to -U in the client as well.


# 1.6 03-Jun-2009 nicm

Do not set the window title by default (make set-titles option default to off),
wiping over the title is rude and annoying. Agreed by several.


# 1.5 03-Jun-2009 nicm

New session option, status-utf8, to control the interpretation of top-bit-set
characters in status-left and status-right (if on, they are treated as UTF-8;
otherwise passed through).


# 1.4 02-Jun-2009 sobrado

remove unused flag; while here, make usage's output fit on 80-column displays.


# 1.3 02-Jun-2009 pyr

spawn login shells by default, adapt manpage bits as well.
ok nicm@


# 1.2 02-Jun-2009 ray

Don't leak memory if multiple -f flags are given.

OK nicm@


# 1.1 01-Jun-2009 nicm

Import tmux, a terminal multiplexor allowing (among other things) a single
terminal to be switched between several different windows and programs
displayed on one terminal be detached from one terminal and moved to another.

ok deraadt pirofti


# 1.202 02-Jun-2020 nicm

Use CLOCK_MONOTONIC for timer measurement and add a timestamp to control
mode %output blocks.


# 1.201 16-May-2020 nicm

Add a -D flag to ask tmux not to daemonize, useful both for running a
debugger (lldb does not have follow-fork-mode) and for running with a
managed supervisor init system. GitHub issue 2190.


# 1.200 16-May-2020 nicm

Add 'e' key in buffer mode to open the buffer in an editor.


# 1.199 16-May-2020 nicm

Build list of paths and weed out duplicates before loading configs, and
add TMUX_SOCK like TMUX_PATH for the socket directory.


Revision tags: OPENBSD_6_7_BASE
# 1.198 20-Apr-2020 nicm

Tidy up the terminal detection and feature code and add named sets of
terminal features, each of which are defined in one place and map to a
builtin set of terminfo(5) capabilities. Features can be specified based
on TERM with a new terminal-features option or with the -T flag when
running tmux. tmux will also detect a few common terminals from the DA
and DSR responses.

This is intended to make it easier to configure tmux's use of
terminfo(5) even in the presence of outdated ncurses(3) or terminfo(5)
databases or for features which do not yet have a terminfo(5) entry.
Instead of having to grok terminfo(5) capability names and what they
should be set to in the terminal-overrides option, the user can
hopefully just give tmux a feature name and let it do the right thing.

The terminal-overrides option remains both for backwards compatibility
and to allow tweaks of individual capabilities.

tmux already did much of this already, this makes it tidier and simpler
to configure.


# 1.197 16-Apr-2020 nicm

Show signal name when process exits rather than number.


# 1.196 09-Apr-2020 nicm

More style nits.


# 1.195 31-Mar-2020 nicm

Add a way to mark environment variables as "hidden" so they can be used
by tmux but are not passed into the environment of new panes.


# 1.194 17-Mar-2020 nicm

Ignore default-shell (and use /bin/sh) if it invalid not just if it is
tmux itself, also refuse to set the option to something invalid in the
first place. GitHub issue 2120.


# 1.193 12-Mar-2020 nicm

When the server socket is given by the user with -S, create it with
umask 177 instead of 117 because it may not be in a safe directory like
the default directory in /tmp. The user can chmod it more open after it
is created if they want.


# 1.192 28-Jan-2020 nicm

-V also needs to go in usage.


# 1.191 28-Jan-2020 nicm

Reduce a difference with portable tmux by adding the -V flag and
#{version} format; on OpenBSD these just report the OpenBSD version.


# 1.190 14-Oct-2019 nicm

Memory leaks, from Igor Wong in GitHub issue 1934.


Revision tags: OPENBSD_6_6_BASE
# 1.189 20-Jun-2019 nicm

Add a per-pane option set. Pane options inherit from window options (so
there should be no change to existing behaviour) and are set and shown
with set-option -p and show-options -p.

Change remain-on-exit and window-style/window-active-style to be pane
options (some others will be changed later).

This makes select-pane -P and -g unnecessary so no longer document them
(they still work) and no longer document set-window-option and
show-window-options in favour of set-option -w and show-options -w.


# 1.188 26-Apr-2019 nicm

Merge hooks into options and make each one an array option. This allows
multiple commands to be easily bound to one hook. set-hook and
show-hooks remain but they are now variants of set-option and
show-options. show-options now has a -H flag to show hooks (by default
they are not shown).


Revision tags: OPENBSD_6_5_BASE
# 1.187 22-Nov-2018 nicm

Do not use PWD unless it actually matches the real working directory.


Revision tags: OPENBSD_6_3_BASE OPENBSD_6_4_BASE
# 1.186 12-Jan-2018 nicm

Improve error message if creating socket parent directory fails, from
Thomas Adam for GitHub issue 1215.


# 1.185 01-Jan-2018 nicm

Prefer PWD for current directory if present in client, from Wei Zhao in
GitHub issue 1183.


Revision tags: OPENBSD_6_2_BASE
# 1.184 12-Jul-2017 nicm

Make shell_command a global like other stuff rather than making it an
exception and using callback argument.


# 1.183 03-Jul-2017 nicm

Try C.UTF-8 which is also a commonly useful locale on some platforms,
from Romain Francoise.


# 1.182 22-Apr-2017 nicm

Do not need getopt.h.


# 1.181 20-Apr-2017 nicm

Use fdforkpty() instead of our own unwrapped versions.


# 1.180 19-Apr-2017 nicm

Style nits and a missing cast.


# 1.179 16-Apr-2017 nicm

Memory leak, from David CARLIER.


Revision tags: OPENBSD_6_1_BASE
# 1.178 21-Mar-2017 nicm

Use uid_t for UID not u_int.


# 1.177 16-Feb-2017 nicm

Style nits.


# 1.176 23-Jan-2017 nicm

Open /dev/ptm before pledge() and save it to be used for PTMGET later
(this means inlining forkpty()).

ok deraadt


# 1.175 15-Jan-2017 nicm

Major tidy up and rework of options tree and set-option/show-options
commands this pushes more of the code into options.c and ties it more
closely to the options table rather than having an unnecessary
split. Also add support for array options (will be used later). Only
(intentional) user visible change is that show-options output is now
passed through vis(3) with VIS_DQ so quotes are escaped.


# 1.174 12-Jan-2017 nicm

Simplify appending to string options.


# 1.173 09-Dec-2016 nicm

Spacing nits.


# 1.172 11-Oct-2016 nicm

Add static in window-*.c and move some internal functions out of tmux.h.


# 1.171 10-Oct-2016 nicm

Loads more static, except for cmd-*.c and window-*.c.


Revision tags: OPENBSD_6_0_BASE
# 1.170 27-May-2016 nicm

Use getprogname() instead of __progname to make portability easier.


# 1.169 04-May-2016 nicm

Fix up a couple of long lines.


# 1.168 05-Mar-2016 nicm

If setlocale("en_US.UTF-8") succeeds, then don't do the check for UTF-8
locale since if it isn't UTF-8 the system is broken anyway. If it fails,
try "" and check for UTF-8 with nl_langinfo(CODESET) rather than
wcwidth(). Based on a diff from schwarze@, nl_langinfo also suggested by
stsp@.


# 1.167 05-Mar-2016 nicm

Although we always have en_US.UTF-8 on OpenBSD, some platforms do not,
so fall back to setlocale(LC_CTYPE, ""). tmux requires a UTF-8 locale,
so check with wcwidth() on a UTF-8 character after setlocale().


# 1.166 01-Mar-2016 nicm

Remove unused variables, from Michal Mazurek.


# 1.165 01-Mar-2016 nicm

Use system wcwidth() instead of carrying around UTF-8 width tables.


Revision tags: OPENBSD_5_9_BASE
# 1.164 19-Jan-2016 nicm

I no longer use my SourceForge address so replace it.


# 1.163 08-Dec-2015 nicm

Add hooks infrastructure, basic commands (set-hook, show-hooks) and a
couple of not very useful client hooks. This will eventually let
commands be run at various points and on notifications. Joint work with
Thomas Adam.


# 1.162 24-Nov-2015 nicm

Make environ_set va_args and use it to tidy up some calls. Also add a
missing word in manpage (from jmc).


# 1.161 24-Nov-2015 nicm

Shell command from -c doesn't have to be global, pass it as an argument.


# 1.160 24-Nov-2015 nicm

Tidy the code that works out the socket path, and just use the full path
in the global socket_path rather than copying it.


# 1.159 24-Nov-2015 nicm

Remove malloc_options DEBUG bit.


# 1.158 24-Nov-2015 nicm

Remove the -I part of show-messages which isn't really that useful; the
server start time can now be accessed with a new start_time format (use:
tmux display -p '#{t:start_time}')


# 1.157 24-Nov-2015 nicm

Make the log stuff a bit tidier with some helper functions.


# 1.156 22-Nov-2015 nicm

Add getpw to pledge, makes tmux work in YP environments, discovered by
matthieu, ok deraadt


# 1.155 20-Nov-2015 nicm

Instead of separate tables for different types of options, give each
option a scope type (server, session, window) in one table.


# 1.154 15-Nov-2015 nicm

Accidentally turned off pledge, turn it back on.


# 1.153 14-Nov-2015 nicm

Push stdout and stderr to clients more aggressively, and add an event to
continue if the send fails.


# 1.152 12-Nov-2015 nicm

tmux is UTF-8, so if $TMUX is set (tmux running in tmux), the client is
UTF-8. Also try to make the existing checks more readable.


# 1.151 12-Nov-2015 nicm

Nuke the utf8 and status-utf8 options and make tmux only a UTF-8
terminal. We still support non-UTF-8 terminals outside tmux, but inside
it is always UTF-8 (as when the utf8 and status-utf8 options were on).


# 1.150 11-Nov-2015 nicm

Drop mouse-utf8 option and always turn on UTF-8 mouse if the client says
it supports UTF-8.


# 1.149 28-Oct-2015 nicm

Like options, move the environ struct into environ.c.


# 1.148 27-Oct-2015 nicm

Move struct options into options.c.


# 1.147 27-Oct-2015 nicm

Break the common process set up, event loop and imsg dispatch code
between server and client out into a separate internal API. This will
make it easier to add another process.


# 1.146 25-Oct-2015 deraadt

Let's see if anyone screams about not being able to specify $TMPDIR
for their tmux sockets.

(Over the years, I have seen $TMPDIR set up worse than /tmp many times,
and don't know how this practice infected other parts of the system.
Nothing uses tmpdir(3), nor a huge-temporary-file program like sort.)
ok nicm


# 1.145 23-Oct-2015 nicm

tmux can call pledge() in main with large set and then reduce it
slightly in the server to "stdio rpath wpath cpath fattr unix recvfd
proc exec tty ps".


# 1.144 14-Sep-2015 nicm

Move tzset() from log_open to main.


# 1.143 03-Sep-2015 nicm

A couple of style nits.


# 1.142 01-Sep-2015 nicm

Work out config file when needed not at startup.


# 1.141 30-Aug-2015 nicm

Path from $TMUX does not need to be global anymore.


# 1.140 30-Aug-2015 nicm

Login shell can be a client flag, and move the exec code into client.c.


# 1.139 30-Aug-2015 nicm

Event base does not need to be global.


# 1.138 30-Aug-2015 nicm

Some style nits and dead assignments.


Revision tags: OPENBSD_5_8_BASE
# 1.137 20-Jul-2015 nicm

Add an option (history-file) for a file to save/restore command prompt
history, from Olof-Joachim Frahm.


# 1.136 04-Jun-2015 jmc

tweak SYNOPSIS and usage();


Revision tags: OPENBSD_5_7_BASE
# 1.135 19-Jan-2015 nicm

Make a tmux-%u directory under TMUX_TMPDIR, like TMPDIR.


# 1.134 19-Jan-2015 nicm

Only care about other permissions, allow group to be set.


# 1.133 19-Jan-2015 nicm

Remove unnecessary duplicate S_ISDIR check, from Dmitri Paduchikh.


# 1.132 20-Oct-2014 nicm

Tidy up some includes.


Revision tags: OPENBSD_5_6_BASE
# 1.131 17-Apr-2014 nicm

Remove the "info" message mechanism, this was only used for about five
mostly useless and annoying messages. Change those commands to silence
on success like all the others. Still accept the -q command line flag
and "quiet" server option for now.


# 1.130 31-Mar-2014 nicm

Remove log_debug2 as well and simplify log.c.


Revision tags: OPENBSD_5_5_BASE
# 1.129 16-Feb-2014 nicm

Leftovers from removing 88 colour support, from Theo Buehler.


# 1.128 15-Jan-2014 nicm

Do not attempt to read .tmux.conf if we can't figure out a home
directory, from Tiago Cunha.


# 1.127 09-Jan-2014 nicm

Three small changes from Tiago Cunha:

- Check for truncation when copying path.
- Don't need to use a temporary buffer in screen_set_title.
- Include strerror in output when connecting to server fails.


# 1.126 10-Oct-2013 nicm

We accidentally haven't been using $TMUX to work out the session for a
while and in fact it is less useful that using the client ttyname. So
don't bother and don't pass it from the client. If we need it in future
it is in c->environ.


# 1.125 10-Oct-2013 nicm

Alter how tmux handles the working directory to internally use file
descriptors rather than strings.

- Each session still has a current working directory.

- New sessions still get their working directory from the client that
created them or its attached session if any.

- New windows are created by default in the session working directory.

- The -c flag to new, neww, splitw allows the working directory to be
overridden.

- The -c flag to attach let's the session working directory be changed.

- The default-path option has been removed.

To get the equivalent to default-path '.', do:

bind c neww -c $PWD

To get the equivalent of default-path '~', do:

bind c neww -c ~

This also changes the client identify protocol to be a set of messages rather
than one as well as some other changes that should make it easier to make
backwards-compatible protocol changes in future.


# 1.124 10-Oct-2013 nicm

Merge IDENTIFY_* flags with CLIENT_* flags.


# 1.123 10-Oct-2013 nicm

Don't treat TMUX_TMPDIR as a potential file

The point of setting TMUX_TMPDIR is to then make any labels from -L go
to that directory. In the case of makesocketpath() with no TMUX_TMPDIR
set, would set both the path and the default socket to a file. The
checking of the permissions on the file worked fine in that case, but
when TMUX_TMPDIR is set, won't work on a directory.

This fixes the problem by ensuring the check on the permissions is
performed on directories only.

By Thomas Adam.


# 1.122 05-Oct-2013 nicm

Fix previous not to leak fd on failure, whoops.


# 1.121 05-Oct-2013 nicm

Use open(".")/fchdir() to save and restore current directory rather than
getcwd()/chdir().


Revision tags: OPENBSD_5_4_BASE
# 1.120 24-Apr-2013 nicm

Rename global configuration define.


# 1.119 11-Apr-2013 nicm

Call setlocale(LC_TIME) at startup.


# 1.118 27-Mar-2013 nicm

Add TMUX_TMPDIR variable to put the socket directory outside
TMPDIR. From Ben Boeckel.


# 1.117 27-Mar-2013 nicm

Remove tmux's (already minimal) 88 colour support. Such terminals are
few and unnecessary.


# 1.116 25-Mar-2013 nicm

Rename session idx to session id throughout and add $ prefix to targets
to use it, extended from a diff from George Nachman.


# 1.115 24-Mar-2013 nicm

Add a command queue to standardize and simplify commands that call other
commands and allow a command to block execution of subsequent
commands. This allows run-shell and if-shell to be synchronous which has
been much requested.

Each client has a default command queue and commands are consumed one at
a time from it. A command may suspend execution from the queue by
returning CMD_RETURN_WAIT and then resume it by calling cmd_continue() -
for example run-shell does this from the callback that is fired after
the job is freed.

When the command queue becomes empty, command clients are automatically
exited (unless attaching). A callback is also fired - this is used for
nested commands in, for example, if-shell which can block execution of
the client's cmdq until a new cmdq becomes empty.

Also merge all the old error/info/print functions together and lose the
old curclient/cmdclient distinction - a cmdq is bound to one client (or
none if in the configuration file), this is a command client if
c->session is NULL otherwise an attached client.


Revision tags: OPENBSD_5_3_BASE
# 1.114 27-Nov-2012 nicm

Correctly aggregate together errors from nested config files (with
source-file). Fix by Thomas Adam, reported by Sam Livingstone-Gray


# 1.113 26-Nov-2012 nicm

Call realpath earlier on the socket directory path rather than on the
socket file path because the latter may not exist yet and in that case
realpath is allowed to fail. From Romain Francoise.


Revision tags: OPENBSD_5_2_BASE
# 1.112 10-Jul-2012 nicm

xfree is not particularly helpful, remove it. From Thomas Adam.


# 1.111 18-Jun-2012 nicm

Add a skeleton mode to tmux (called "control mode") that let's tmux
commands be sent and output received on stdout. This can be used to
integrate with other terminal emulators and should allow some other
things to be made simpler later. More to come so doesn't do much yet and
deliberately not documented.


# 1.110 30-May-2012 nicm

Do not use stderr for log file and don't call log_close when not needed.


# 1.109 25-May-2012 nicm

Simplify logging and just fprintf(stderr, ...) for early errors.


Revision tags: OPENBSD_5_1_BASE
# 1.108 21-Jan-2012 nicm

Drop the ability to have a list of keys in the prefix in favour of two
separate options, prefix and prefix2. This simplifies the code and gets
rid the data options type which was only used for this one option.

Also add a -2 flag to send-prefix to send the secondary prefix key,
fixing a cause of minor irritation.

People who want three prefix keys are out of luck :-).


# 1.107 23-Oct-2011 nicm

Try to resolve relative paths for loadb and saveb (first using client
working directory if any then default-path or session wd).


# 1.106 23-Oct-2011 nicm

Ignore LC_ALL and LC_CTYPE if they are empty as well as unset.


# 1.105 25-Sep-2011 nicm

Reject $SHELL if it is not a full path.


Revision tags: OPENBSD_5_0_BASE
# 1.104 04-Mar-2011 nicm

Two fixes by Micah Cowan: make mouse work properly beyond >127 on signed
char architectures and properly parse $TMUX by stopping the socket path
at the first comma.


Revision tags: OPENBSD_4_9_BASE
# 1.103 23-Jan-2011 nicm

Set $TMUX without the session when background jobs are run.


# 1.102 12-Jan-2011 nicm

Use TMPDIR if set, from Han Boetes.


# 1.101 08-Jan-2011 nicm

Move all calls to fcntl(...O_NONBLOCK) into a function and clear the
flag on the stdio file descriptors before closing them (fixes things
like "tmux ls && cat").


# 1.100 03-Jan-2011 nicm

Support for UTF-8 mouse input (\033[1005h). This was added in xterm 262
and supports larger terminals than the older way.

If the new mouse-utf8 option is on, UTF-8 mouse input is enabled for all
UTF-8 terminals. The option defaults to on if LANG etc are set in the
same manner as the utf8 option.

With help and based on code from hsim at gmx.li.


# 1.99 01-Jan-2011 nicm

Move the user-visible parts of all options (names, types, limit, default
values) together into one set of tables in options-table.c. Also clean
up and simplify cmd-set-options.c and move a common print function into
option-table.c.


# 1.98 30-Dec-2010 nicm

Change from a per-session stack of buffers to one global stack which is
much more convenient and also simplifies lot of code. This renders
copy-buffer useless and makes buffer-limit now a server option.

By Tiago Cunha.


# 1.97 19-Dec-2010 nicm

Add other-pane-height and other-pane-width options, allowing the width
or height of the smaller panes in the main-horizontal and main-vertical
layouts to be set. Mostly from David Goodlad.


# 1.96 08-Dec-2010 nicm

In the built-in layouts, distribute the panes more evenly. Set the
default value of main-pane-width to 80, rather than 81. By Micah Cowan.


# 1.95 06-Dec-2010 nicm

Add an option to alert (monitor) for silence (lack of activity) in a
window. From Thomas Adam.


# 1.94 29-Nov-2010 nicm

If VISUAL or EDITOR contains "vi", configure mode-keys and status-keys
to vi.

Based on a diff from martynas@, previously requested by a couple of
other people.


# 1.93 11-Nov-2010 nicm

Add XAUTHORITY to update-environment, requested by Andreas Kloeckner.


# 1.92 18-Oct-2010 nicm

Merge the before and after attach client code into one in client.c
(instead of two in tmux.c and client.c).


# 1.91 16-Oct-2010 nicm

Make stdio blocking again before calling shell command with -c.


# 1.90 16-Oct-2010 nicm

Trying to set FD_CLOEXEC on every fd is a lost cause, just use
closefrom() before exec.


# 1.89 14-Oct-2010 nicm

Use an explicit event rather than event_once for the main event so it
can be removed when the client becomes ready.


# 1.88 26-Sep-2010 nicm

Two new options:

- server option "exit-unattached" makes the server exit when no clients
are attached, even if sessions are present;

- session option "destroy-unattached" destroys a session once no clients
are attached to it.

These are useful for preventing tmux remaining in the background where
it is undesirable and when using tmux as a login shell to keep a limit
on new sessions.


# 1.87 19-Aug-2010 nicm

Do not call event_del() for signals after fork(), just use sigaction()
directly instead - calling libevent functions after fork() w/o
event_reinit() is a bad idea, even if in this case it was harmless.


Revision tags: OPENBSD_4_8_BASE
# 1.86 04-Aug-2010 deraadt

switch back to kqueue for now, since (a) kqueue has been fixed to deal
with strange devices and (b) since there appears to be a bull in the
poll code in libevent as well...
requested by nicm who is away


# 1.85 24-Jul-2010 nicm

kqueue(2) is currently broken when used with /dev/null and a few other
devices.

An upcoming fix for some problems with the client stdout/stderr handling
relies on it working, so make tmux force libevent to use poll(2) via
EVENT_NOKQUEUE, until we have fixed kqueue.


# 1.84 11-Jul-2010 nicm

Return the command client return code with MSG_EXIT now that MSG_ERROR and
MSG_PRINT are unused.

New clients should be compatible with old tmux servers but vice versa may print
an error.


# 1.83 28-Jun-2010 nicm

Send all three of stdin, stdout, stderr from the client to the server, so that
commands can directly make use of them. This means that load-buffer and
save-buffer can have "-" as the file to read from stdin or write to stdout.

This is a protocol version bump so the tmux server will need to be restarted
after upgrade (or an older client used).


# 1.82 27-Jun-2010 nicm

Store the current working directory in the session, change the default-path
option to default to empty and make that mean that the stored session CWD is
used.


# 1.81 27-Jun-2010 nicm

New option, detach-on-destroy, to set what happens to a client when the session
it is attached to is destroyed. If on (the default), it is detached; if off, it
is switched to the most recently active session.


# 1.80 26-Jun-2010 nicm

Setting the cmdlist pointer in the bind-key to NULL to prevent it being freed
after the command is executing is bogus because it may still be needed if the
same command is going to be executed again (for example if you "bind-key a
bind-key b ..."). Making a copy is hard, so instead add a reference count to
the cmd_list.

While here, also print bind-key -n and the rest of the flags properly.

Fixes problem reported by mcbride@.


# 1.79 14-May-2010 nicm

Colour+attribute options for status line alerts, from Alex Alexander.


# 1.78 04-May-2010 nicm

Put this back in with the initialisation in the right order.


# 1.77 04-May-2010 nicm

Revert last change, it appears to be broken somehow.


# 1.76 03-May-2010 nicm

Make signal handler setup/teardown two common functions instead of six,
and reset SIGCHLD after fork to fix problems with some shells. From
Romain Francois.


# 1.75 28-Apr-2010 nicm

Make the active pane border have a green foreground instead of
background by default.


# 1.74 18-Apr-2010 nicm

Catch SIGCHLD to avoid a zombie, from patrick keshishian.


Revision tags: OPENBSD_4_7_BASE
# 1.73 22-Feb-2010 nicm

Option to set the characters considered word separators in copy mode, from
Micah Cowan.


# 1.72 08-Feb-2010 nicm

Add an option to disable the smcup/rmcup alternate screen behaviour inside
tmux. From clemens fischer.


# 1.71 06-Feb-2010 nicm

Change nested check to compare server socket path rather than just assuming
that if $TMUX is set it is nested. From Micah Cowan.


# 1.70 06-Feb-2010 nicm

Clean up $TMUX parsing, from Micah Cowan, tweaked by me.


# 1.69 06-Feb-2010 nicm

Instead of bailing out on the first configuration file error, carry on,
collecting all the errors, then start with the active window in more mode
displaying them.


# 1.68 04-Feb-2010 nicm

Read the path from $TMUX if it is present and -L and -S are not given. Based on
a diff from Micah Cowan.


# 1.67 04-Feb-2010 nicm

Option to display the active pane in a different colour with the display-panes
command. From Paul Hoffman, thanks.


# 1.66 03-Jan-2010 nicm

Options to set the colour of the pane borders, with different colours for the
active pane.


# 1.65 14-Dec-2009 nicm

New server option, escape-time, to set the timeout used to detect if escapes
are alone or part of a function key or meta sequence.


# 1.64 11-Dec-2009 nicm

Use quiet variable, and add missing sentinel to options array.


# 1.63 10-Dec-2009 nicm

Add "server options" which are server-wide and not bound to a session or
window. Set and displayed with "set -s" and "show -s".

Currently the only option is "quiet" (like command-line -q, allowing it to be
set from .tmux.conf), but others will come along.


# 1.62 03-Dec-2009 nicm

Massive spaces->tabs and trailing whitespace cleanup, hopefully for the last
time now I've configured emacs to make them displayed in really annoying
colours...


# 1.61 26-Nov-2009 nicm

Remove a couple of unused arguments where possible, and add /* ARGSUSED */ to
the rest to reduce lint output.


# 1.60 19-Nov-2009 nicm

Two new options, window-status-format and window-status-current-format, which
allow the format of each window in the status line window list to be controlled
using similar # sequences as status-left/right.

This diff also moves part of the way towards UTF-8 support in window names but
it isn't quite there yet.


# 1.59 19-Nov-2009 nicm

Revert to xterm-keys off by default. It was on as an experiment to see if the
option could be removed, but it affects vi, so we have to keep the option, and
a conservative default is better.


# 1.58 18-Nov-2009 nicm

Add a per-client log of status line messages displayed while that client
exists. A new message-limit session option sets the maximum number of entries
and a command, show-messages, shows the log (bound to ~ by default).

This (and prompt history) might be better as a single global log but until
there are global options it is easier for them to be per client.


# 1.57 10-Nov-2009 nicm

There is no real standard for modifier plus function keys. Previously, tmux
output some from rxvt but in other ways did the same as xterm or other
terminals, but this is a bit inconsistent.

xterm's method is fairly sensible and we already support it (xterm-keys), so
enable it by default instead.


# 1.56 04-Nov-2009 nicm

A couple of minor cosmetic changes.


# 1.55 04-Nov-2009 nicm

Initial changes to move tmux to libevent.

This moves the client-side loops are pretty much fully over to event-based only
(tmux.c and client.c) but server-side (server.c and friends) treats libevent as
a sort of clever poll, waking up after every event to run various things.

Moving the server stuff over to bufferevents and timers and so on will come
later.


# 1.54 04-Nov-2009 nicm

Change declaration and use of malloc_options to be more standard, from Tim van
der Molen.


# 1.53 26-Oct-2009 deraadt

tabs are better; ok nicm


# 1.52 25-Oct-2009 nicm

Remove the -d flag to tmux and just use op/AX to detect default colours.

Irritatingly, although op can be used to tell if a terminal supports default
colours, it can't be used to set them because in some terminfo descriptions it
resets attributes as a side-effect (acts as sgr0) and in others it doesn't, so
it is not possible to determine reliably what the terminal state will be
afterwards. So if AX is missing and op is present, tmux just sends sgr0.

Anyone using -d for a terminal who finds they actually needed it can replace it
using terminal-overrides, but please let me know as it is probably an omission
from terminfo.


# 1.51 22-Oct-2009 nicm

Merge prepare_cmd into main as it is short and only called once.


# 1.50 21-Oct-2009 nicm

Client tidying: get rid of client_ctx struct in favour of two variables in
client.c, and move the functions in client-fn.c into other files.


# 1.49 10-Oct-2009 nicm

New option, mouse-select-pane. If on, the mouse may be used to select the
current pane.

Suggested by sthen@ and also by someone else ages ago who I have forgotten.


# 1.48 10-Oct-2009 nicm

Support for individual session idle time locking. May be enabled by turning off
the lock-server option (it is on by default). When this is off, each session
locks when it has been idle for the lock-after-time setting. When on, the
entire server locks when ALL sessions have been idle for their individual
lock-after-time settings.

This replaces one global-only option (lock-after-time) with another
(lock-server), but the default behaviour is usually preferable so there don't
seem to be many alternatives.

Diff/idea largely from Thomas Adam, tweaked by me.


# 1.47 09-Oct-2009 nicm

Add a simple synchronize-panes window option: when set, all input to any pane
that is part of the window is also sent to all other panes in the same
window. Suggested by several, most recently Tomasz Pajor.


# 1.46 23-Sep-2009 nicm

Support -c like sh(1) to execute a command, useful when tmux is a login
shell. Suggested by halex@.

This includes another protocol version increase (the last for now) so again
restart the tmux server before upgrading.


# 1.45 23-Sep-2009 nicm

Remove the internal tmux locking and instead detach each client and run the
command specified by a new option "lock-command" (by default "lock -np") in
each client.

This means each terminal has to be unlocked individually but simplifies the
code and allows the system password to be used to unlock.

Note that the set-password command is gone, so it will need to be removed from
configuration files, and the -U command line flag has been removed.

This is the third protocol version change so again it is best to stop the tmux
server before upgrading.


# 1.44 22-Sep-2009 nicm

Permit multiple prefix keys to be defined, separated by commas, for example:

set -g prefix ^a,^b

Any key in the list acts as the prefix. The send-prefix command always sends
the first key in the list.


# 1.43 18-Sep-2009 nicm

New option, set-titles-string, to allow the window title to be specified (as
for status-left/right) if set-titles is on. Also only update the title when the
status line is being redrawn.


# 1.42 04-Sep-2009 nicm

Tidy main and make it a bit easier to read.


# 1.41 02-Sep-2009 nicm

Accept -l to make it easier for people who use tmux as a login shell to use
$SHELL. Originally from martynas@, tweaked by me.


# 1.40 02-Sep-2009 nicm

When incorrect passwords are entered, behave similarly to login(1) and backoff
for a bit. Based on a diff from martynas@.


# 1.39 01-Sep-2009 nicm

When using tmux as a login shell, there is currently no way to specify a shell
to be used as a login shell inside tmux, so add a default-shell session option.
This sets the shell invoked as a login shell when the default-command option is
empty.

The default option value is whichever of $SHELL, getpwuid(getuid())'s pw_shell
or /bin/sh is valid first.

Based on a diff from martynas@, changed by me to be a session option rather
than a window option.


# 1.38 01-Sep-2009 nicm

Use "Password:" with no space for password prompts and don't display a *s for
the password, like pretty much everything else. From martynas@ with minor
tweaks by me.


# 1.37 01-Sep-2009 nicm

Sort cases same as getopt argument, from martynas.


# 1.36 31-Aug-2009 nicm

Add a new display-panes command, with two options (display-panes-colour and
display-panes-time), which displays a visual indication of the number of each
pane.


# 1.35 23-Aug-2009 nicm

Add some other obvious variables to update-environment (WINDOWID SSH_ASKPASS
SSH_AUTH_SOCK SSH_AGENT_PID SSH_CONNECTION) so they are updated in the session
environment on new/attach.


# 1.34 13-Aug-2009 nicm

Disable mode-mouse (mouse in copy/choice mode) by default as it isn't very
useful at the moment and causes confusion.


# 1.33 13-Aug-2009 nicm

Add a base-index session option to specify the first index checked when looking
for an index for a new window.


# 1.32 12-Aug-2009 nicm

When started as the shell, __progname contains a leading -, so hardcode "tmux"
for socket path and log files, and strip it when working out the shell.


# 1.31 11-Aug-2009 nicm

Switch tmux to use imsg. This is the last major change to make the
client-server protocol more resilient and make the protocol versioning work
properly. In future, the only things requiring a protocol version bump will be
changes in the message structs, and (when both client and server have this
change) mixing different versions should nicely report an error message.

As a side effect this also makes the code tidier, fixes a problem with the way
errors reported during server startup were handled, and supports fd passing
(which will be used in future).

Looked over by eric@, thanks.

Please note that mixing a client with this change with an older server or vice
versa may cause tmux to crash or hang - tmux should be completely exited before
upgrading.


# 1.30 10-Aug-2009 nicm

No arguments are the same as new-session and this requires the environment to
be sent, so set that flag too when argc == 0.


# 1.29 08-Aug-2009 nicm

Infrastructure and commands to manage the environment for processes started
within tmux.

There is a global environment, copied from the external environment when the
server is started and each sesssion has an (initially empty) session
environment which overrides it.

New commands set-environment and show-environment manipulate or display the
environments.

A new session option, update-environment, is a space-separated list of
variables which are updated from the external environment into the session
environment every time a new session is created - the default is DISPLAY.


# 1.28 08-Aug-2009 nicm

Options to set the colours and attributes for status-left/-right. From Thomas
Adam, thanks.


# 1.27 05-Aug-2009 nicm

If colours are not supported by the terminal, try to emulate a coloured
background by setting or clearing the reverse attribute.

This makes a few applications which don't use the reverse attribute themselves
a little happier, and allows the status, message and mode options to have
default attributes and fg/bg options that work as expected when set as reverse.


# 1.26 04-Aug-2009 nicm

Check for "UTF8" as well as "UTF-8" in LANG etc as it seems this may also
appear.


# 1.25 03-Aug-2009 nicm

Add a terminal-overrides session option allowing individual terminfo(5) entries
to be overridden. The 88col/256col checks are now moved into the default
setting and out of the code.

Also remove a couple of old workarounds for xterm and rxvt which are no longer
necessary (tmux can emulate them if missing).


# 1.24 30-Jul-2009 nicm

Add a mode-mouse option to prevent tmux taking over the mouse in choice or copy
modes.


# 1.23 29-Jul-2009 nicm

Rename struct hdrtype to msgtype which is a better name and can be used even
when struct hdr disappears.


# 1.22 29-Jul-2009 nicm

Taking account of the "s, 22 not 24 is the maximum length of #T in status-right
to prevent the date being cut off.


# 1.21 26-Jul-2009 nicm

Make all messages sent between the client and server fixed size.

This is the first of two changes to make the protocol more resilient and less
sensitive to other changes in the code, particularly with commands. The client
now packs argv into a buffer and sends it to the server for parsing, rather
than doing it itself and sending the parsed command data.

As a side-effect this also removes a lot of now-unused command marshalling
code.

Mixing a server without this change and a client with or vice versa will cause
tmux to hang or crash, please ensure that tmux is entirely killed before
upgrading.


# 1.20 22-Jul-2009 nicm

Pass a set of flags into client_init rather than just a start_server
variable. Only one flag now but more to come later.


# 1.19 20-Jul-2009 nicm

Display the number of failed password attempts (if any) when the server is
locked. From Tom Doherty.


# 1.18 20-Jul-2009 nicm

Add a status-justify option to allow the window list in the status line to be
positioned at the left, centre, or right.


# 1.17 20-Jul-2009 nicm

New options, window-status-current-{fg,bg,attr}, to set the fg, bg and
attributes with which the current window is shown in the status line. From
Johan Friis, thanks.


# 1.16 18-Jul-2009 nicm

Add three new session options: visual-activity, visual-bell, visual-content. If
these are enabled (and the monitor-activity, bell-actio and monitor-content
options are configurated appropriately), when activity, a bell, or content is
detected, a message is shown.

Also tidy up the bell/activity/content code in server.c slightly and fix a
couple of errors.


# 1.15 17-Jul-2009 nicm

If -u is specified or UTF-8 is otherwise detected when the server is started,
enable the utf8 and status-utf8 optons. While here, note in the man page that
the server is started with the first session and exits when none remain.


# 1.14 10-Jul-2009 nicm

Add a default-terminal option to set the starting value of $TERM in new
windows.

This is "screen" by default and must be either that or something closely
related. This does makes it easier to customise it if necessary.


# 1.13 08-Jul-2009 nicm

Just appending -l to $SHELL to create a login shell is wrong: -l is not POSIX,
and some people may use shells which do not support it. Instead, make an empty
default-command option mean a login shell, and fork it with a - in argv[0]
which is the method used by login(1).

Also fix the automatic-rename code to handle this correctly and to strip a
leading - if present.


# 1.12 07-Jul-2009 nicm

Rename the global options variables to be shorter and to make session options
clear. No functional change, getting this out of the way to make later options
changes easier.


Revision tags: OPENBSD_4_6_BASE
# 1.11 25-Jun-2009 nicm

If getcwd() fails, use the user's home directory, or /, instead of failing with
an error.


# 1.10 25-Jun-2009 nicm

Remove error about using -L and -S together which was never displayed as
logging wasn't yet enabled, was unnecessary, and contradicted the man page
which says using -S will cause -L to be ignored.


# 1.9 23-Jun-2009 nicm

LC_ALL overrides LC_CTYPE and LANG. Comment was correct but the code
wrong. Pointed out by Hannah Schroeter, thanks.


# 1.8 05-Jun-2009 nicm

Check the first of LC_CTYPE, LC_ALL and LANG, rather than just the last, when
trying to decide about UTF-8, and use strcasestr. Reported by Geert Hendrickx.


# 1.7 04-Jun-2009 nicm

Zero the password given to -U in the client as well.


# 1.6 03-Jun-2009 nicm

Do not set the window title by default (make set-titles option default to off),
wiping over the title is rude and annoying. Agreed by several.


# 1.5 03-Jun-2009 nicm

New session option, status-utf8, to control the interpretation of top-bit-set
characters in status-left and status-right (if on, they are treated as UTF-8;
otherwise passed through).


# 1.4 02-Jun-2009 sobrado

remove unused flag; while here, make usage's output fit on 80-column displays.


# 1.3 02-Jun-2009 pyr

spawn login shells by default, adapt manpage bits as well.
ok nicm@


# 1.2 02-Jun-2009 ray

Don't leak memory if multiple -f flags are given.

OK nicm@


# 1.1 01-Jun-2009 nicm

Import tmux, a terminal multiplexor allowing (among other things) a single
terminal to be switched between several different windows and programs
displayed on one terminal be detached from one terminal and moved to another.

ok deraadt pirofti


# 1.201 16-May-2020 nicm

Add a -D flag to ask tmux not to daemonize, useful both for running a
debugger (lldb does not have follow-fork-mode) and for running with a
managed supervisor init system. GitHub issue 2190.


# 1.200 16-May-2020 nicm

Add 'e' key in buffer mode to open the buffer in an editor.


# 1.199 16-May-2020 nicm

Build list of paths and weed out duplicates before loading configs, and
add TMUX_SOCK like TMUX_PATH for the socket directory.


Revision tags: OPENBSD_6_7_BASE
# 1.198 20-Apr-2020 nicm

Tidy up the terminal detection and feature code and add named sets of
terminal features, each of which are defined in one place and map to a
builtin set of terminfo(5) capabilities. Features can be specified based
on TERM with a new terminal-features option or with the -T flag when
running tmux. tmux will also detect a few common terminals from the DA
and DSR responses.

This is intended to make it easier to configure tmux's use of
terminfo(5) even in the presence of outdated ncurses(3) or terminfo(5)
databases or for features which do not yet have a terminfo(5) entry.
Instead of having to grok terminfo(5) capability names and what they
should be set to in the terminal-overrides option, the user can
hopefully just give tmux a feature name and let it do the right thing.

The terminal-overrides option remains both for backwards compatibility
and to allow tweaks of individual capabilities.

tmux already did much of this already, this makes it tidier and simpler
to configure.


# 1.197 16-Apr-2020 nicm

Show signal name when process exits rather than number.


# 1.196 09-Apr-2020 nicm

More style nits.


# 1.195 31-Mar-2020 nicm

Add a way to mark environment variables as "hidden" so they can be used
by tmux but are not passed into the environment of new panes.


# 1.194 17-Mar-2020 nicm

Ignore default-shell (and use /bin/sh) if it invalid not just if it is
tmux itself, also refuse to set the option to something invalid in the
first place. GitHub issue 2120.


# 1.193 12-Mar-2020 nicm

When the server socket is given by the user with -S, create it with
umask 177 instead of 117 because it may not be in a safe directory like
the default directory in /tmp. The user can chmod it more open after it
is created if they want.


# 1.192 28-Jan-2020 nicm

-V also needs to go in usage.


# 1.191 28-Jan-2020 nicm

Reduce a difference with portable tmux by adding the -V flag and
#{version} format; on OpenBSD these just report the OpenBSD version.


# 1.190 14-Oct-2019 nicm

Memory leaks, from Igor Wong in GitHub issue 1934.


Revision tags: OPENBSD_6_6_BASE
# 1.189 20-Jun-2019 nicm

Add a per-pane option set. Pane options inherit from window options (so
there should be no change to existing behaviour) and are set and shown
with set-option -p and show-options -p.

Change remain-on-exit and window-style/window-active-style to be pane
options (some others will be changed later).

This makes select-pane -P and -g unnecessary so no longer document them
(they still work) and no longer document set-window-option and
show-window-options in favour of set-option -w and show-options -w.


# 1.188 26-Apr-2019 nicm

Merge hooks into options and make each one an array option. This allows
multiple commands to be easily bound to one hook. set-hook and
show-hooks remain but they are now variants of set-option and
show-options. show-options now has a -H flag to show hooks (by default
they are not shown).


Revision tags: OPENBSD_6_5_BASE
# 1.187 22-Nov-2018 nicm

Do not use PWD unless it actually matches the real working directory.


Revision tags: OPENBSD_6_3_BASE OPENBSD_6_4_BASE
# 1.186 12-Jan-2018 nicm

Improve error message if creating socket parent directory fails, from
Thomas Adam for GitHub issue 1215.


# 1.185 01-Jan-2018 nicm

Prefer PWD for current directory if present in client, from Wei Zhao in
GitHub issue 1183.


Revision tags: OPENBSD_6_2_BASE
# 1.184 12-Jul-2017 nicm

Make shell_command a global like other stuff rather than making it an
exception and using callback argument.


# 1.183 03-Jul-2017 nicm

Try C.UTF-8 which is also a commonly useful locale on some platforms,
from Romain Francoise.


# 1.182 22-Apr-2017 nicm

Do not need getopt.h.


# 1.181 20-Apr-2017 nicm

Use fdforkpty() instead of our own unwrapped versions.


# 1.180 19-Apr-2017 nicm

Style nits and a missing cast.


# 1.179 16-Apr-2017 nicm

Memory leak, from David CARLIER.


Revision tags: OPENBSD_6_1_BASE
# 1.178 21-Mar-2017 nicm

Use uid_t for UID not u_int.


# 1.177 16-Feb-2017 nicm

Style nits.


# 1.176 23-Jan-2017 nicm

Open /dev/ptm before pledge() and save it to be used for PTMGET later
(this means inlining forkpty()).

ok deraadt


# 1.175 15-Jan-2017 nicm

Major tidy up and rework of options tree and set-option/show-options
commands this pushes more of the code into options.c and ties it more
closely to the options table rather than having an unnecessary
split. Also add support for array options (will be used later). Only
(intentional) user visible change is that show-options output is now
passed through vis(3) with VIS_DQ so quotes are escaped.


# 1.174 12-Jan-2017 nicm

Simplify appending to string options.


# 1.173 09-Dec-2016 nicm

Spacing nits.


# 1.172 11-Oct-2016 nicm

Add static in window-*.c and move some internal functions out of tmux.h.


# 1.171 10-Oct-2016 nicm

Loads more static, except for cmd-*.c and window-*.c.


Revision tags: OPENBSD_6_0_BASE
# 1.170 27-May-2016 nicm

Use getprogname() instead of __progname to make portability easier.


# 1.169 04-May-2016 nicm

Fix up a couple of long lines.


# 1.168 05-Mar-2016 nicm

If setlocale("en_US.UTF-8") succeeds, then don't do the check for UTF-8
locale since if it isn't UTF-8 the system is broken anyway. If it fails,
try "" and check for UTF-8 with nl_langinfo(CODESET) rather than
wcwidth(). Based on a diff from schwarze@, nl_langinfo also suggested by
stsp@.


# 1.167 05-Mar-2016 nicm

Although we always have en_US.UTF-8 on OpenBSD, some platforms do not,
so fall back to setlocale(LC_CTYPE, ""). tmux requires a UTF-8 locale,
so check with wcwidth() on a UTF-8 character after setlocale().


# 1.166 01-Mar-2016 nicm

Remove unused variables, from Michal Mazurek.


# 1.165 01-Mar-2016 nicm

Use system wcwidth() instead of carrying around UTF-8 width tables.


Revision tags: OPENBSD_5_9_BASE
# 1.164 19-Jan-2016 nicm

I no longer use my SourceForge address so replace it.


# 1.163 08-Dec-2015 nicm

Add hooks infrastructure, basic commands (set-hook, show-hooks) and a
couple of not very useful client hooks. This will eventually let
commands be run at various points and on notifications. Joint work with
Thomas Adam.


# 1.162 24-Nov-2015 nicm

Make environ_set va_args and use it to tidy up some calls. Also add a
missing word in manpage (from jmc).


# 1.161 24-Nov-2015 nicm

Shell command from -c doesn't have to be global, pass it as an argument.


# 1.160 24-Nov-2015 nicm

Tidy the code that works out the socket path, and just use the full path
in the global socket_path rather than copying it.


# 1.159 24-Nov-2015 nicm

Remove malloc_options DEBUG bit.


# 1.158 24-Nov-2015 nicm

Remove the -I part of show-messages which isn't really that useful; the
server start time can now be accessed with a new start_time format (use:
tmux display -p '#{t:start_time}')


# 1.157 24-Nov-2015 nicm

Make the log stuff a bit tidier with some helper functions.


# 1.156 22-Nov-2015 nicm

Add getpw to pledge, makes tmux work in YP environments, discovered by
matthieu, ok deraadt


# 1.155 20-Nov-2015 nicm

Instead of separate tables for different types of options, give each
option a scope type (server, session, window) in one table.


# 1.154 15-Nov-2015 nicm

Accidentally turned off pledge, turn it back on.


# 1.153 14-Nov-2015 nicm

Push stdout and stderr to clients more aggressively, and add an event to
continue if the send fails.


# 1.152 12-Nov-2015 nicm

tmux is UTF-8, so if $TMUX is set (tmux running in tmux), the client is
UTF-8. Also try to make the existing checks more readable.


# 1.151 12-Nov-2015 nicm

Nuke the utf8 and status-utf8 options and make tmux only a UTF-8
terminal. We still support non-UTF-8 terminals outside tmux, but inside
it is always UTF-8 (as when the utf8 and status-utf8 options were on).


# 1.150 11-Nov-2015 nicm

Drop mouse-utf8 option and always turn on UTF-8 mouse if the client says
it supports UTF-8.


# 1.149 28-Oct-2015 nicm

Like options, move the environ struct into environ.c.


# 1.148 27-Oct-2015 nicm

Move struct options into options.c.


# 1.147 27-Oct-2015 nicm

Break the common process set up, event loop and imsg dispatch code
between server and client out into a separate internal API. This will
make it easier to add another process.


# 1.146 25-Oct-2015 deraadt

Let's see if anyone screams about not being able to specify $TMPDIR
for their tmux sockets.

(Over the years, I have seen $TMPDIR set up worse than /tmp many times,
and don't know how this practice infected other parts of the system.
Nothing uses tmpdir(3), nor a huge-temporary-file program like sort.)
ok nicm


# 1.145 23-Oct-2015 nicm

tmux can call pledge() in main with large set and then reduce it
slightly in the server to "stdio rpath wpath cpath fattr unix recvfd
proc exec tty ps".


# 1.144 14-Sep-2015 nicm

Move tzset() from log_open to main.


# 1.143 03-Sep-2015 nicm

A couple of style nits.


# 1.142 01-Sep-2015 nicm

Work out config file when needed not at startup.


# 1.141 30-Aug-2015 nicm

Path from $TMUX does not need to be global anymore.


# 1.140 30-Aug-2015 nicm

Login shell can be a client flag, and move the exec code into client.c.


# 1.139 30-Aug-2015 nicm

Event base does not need to be global.


# 1.138 30-Aug-2015 nicm

Some style nits and dead assignments.


Revision tags: OPENBSD_5_8_BASE
# 1.137 20-Jul-2015 nicm

Add an option (history-file) for a file to save/restore command prompt
history, from Olof-Joachim Frahm.


# 1.136 04-Jun-2015 jmc

tweak SYNOPSIS and usage();


Revision tags: OPENBSD_5_7_BASE
# 1.135 19-Jan-2015 nicm

Make a tmux-%u directory under TMUX_TMPDIR, like TMPDIR.


# 1.134 19-Jan-2015 nicm

Only care about other permissions, allow group to be set.


# 1.133 19-Jan-2015 nicm

Remove unnecessary duplicate S_ISDIR check, from Dmitri Paduchikh.


# 1.132 20-Oct-2014 nicm

Tidy up some includes.


Revision tags: OPENBSD_5_6_BASE
# 1.131 17-Apr-2014 nicm

Remove the "info" message mechanism, this was only used for about five
mostly useless and annoying messages. Change those commands to silence
on success like all the others. Still accept the -q command line flag
and "quiet" server option for now.


# 1.130 31-Mar-2014 nicm

Remove log_debug2 as well and simplify log.c.


Revision tags: OPENBSD_5_5_BASE
# 1.129 16-Feb-2014 nicm

Leftovers from removing 88 colour support, from Theo Buehler.


# 1.128 15-Jan-2014 nicm

Do not attempt to read .tmux.conf if we can't figure out a home
directory, from Tiago Cunha.


# 1.127 09-Jan-2014 nicm

Three small changes from Tiago Cunha:

- Check for truncation when copying path.
- Don't need to use a temporary buffer in screen_set_title.
- Include strerror in output when connecting to server fails.


# 1.126 10-Oct-2013 nicm

We accidentally haven't been using $TMUX to work out the session for a
while and in fact it is less useful that using the client ttyname. So
don't bother and don't pass it from the client. If we need it in future
it is in c->environ.


# 1.125 10-Oct-2013 nicm

Alter how tmux handles the working directory to internally use file
descriptors rather than strings.

- Each session still has a current working directory.

- New sessions still get their working directory from the client that
created them or its attached session if any.

- New windows are created by default in the session working directory.

- The -c flag to new, neww, splitw allows the working directory to be
overridden.

- The -c flag to attach let's the session working directory be changed.

- The default-path option has been removed.

To get the equivalent to default-path '.', do:

bind c neww -c $PWD

To get the equivalent of default-path '~', do:

bind c neww -c ~

This also changes the client identify protocol to be a set of messages rather
than one as well as some other changes that should make it easier to make
backwards-compatible protocol changes in future.


# 1.124 10-Oct-2013 nicm

Merge IDENTIFY_* flags with CLIENT_* flags.


# 1.123 10-Oct-2013 nicm

Don't treat TMUX_TMPDIR as a potential file

The point of setting TMUX_TMPDIR is to then make any labels from -L go
to that directory. In the case of makesocketpath() with no TMUX_TMPDIR
set, would set both the path and the default socket to a file. The
checking of the permissions on the file worked fine in that case, but
when TMUX_TMPDIR is set, won't work on a directory.

This fixes the problem by ensuring the check on the permissions is
performed on directories only.

By Thomas Adam.


# 1.122 05-Oct-2013 nicm

Fix previous not to leak fd on failure, whoops.


# 1.121 05-Oct-2013 nicm

Use open(".")/fchdir() to save and restore current directory rather than
getcwd()/chdir().


Revision tags: OPENBSD_5_4_BASE
# 1.120 24-Apr-2013 nicm

Rename global configuration define.


# 1.119 11-Apr-2013 nicm

Call setlocale(LC_TIME) at startup.


# 1.118 27-Mar-2013 nicm

Add TMUX_TMPDIR variable to put the socket directory outside
TMPDIR. From Ben Boeckel.


# 1.117 27-Mar-2013 nicm

Remove tmux's (already minimal) 88 colour support. Such terminals are
few and unnecessary.


# 1.116 25-Mar-2013 nicm

Rename session idx to session id throughout and add $ prefix to targets
to use it, extended from a diff from George Nachman.


# 1.115 24-Mar-2013 nicm

Add a command queue to standardize and simplify commands that call other
commands and allow a command to block execution of subsequent
commands. This allows run-shell and if-shell to be synchronous which has
been much requested.

Each client has a default command queue and commands are consumed one at
a time from it. A command may suspend execution from the queue by
returning CMD_RETURN_WAIT and then resume it by calling cmd_continue() -
for example run-shell does this from the callback that is fired after
the job is freed.

When the command queue becomes empty, command clients are automatically
exited (unless attaching). A callback is also fired - this is used for
nested commands in, for example, if-shell which can block execution of
the client's cmdq until a new cmdq becomes empty.

Also merge all the old error/info/print functions together and lose the
old curclient/cmdclient distinction - a cmdq is bound to one client (or
none if in the configuration file), this is a command client if
c->session is NULL otherwise an attached client.


Revision tags: OPENBSD_5_3_BASE
# 1.114 27-Nov-2012 nicm

Correctly aggregate together errors from nested config files (with
source-file). Fix by Thomas Adam, reported by Sam Livingstone-Gray


# 1.113 26-Nov-2012 nicm

Call realpath earlier on the socket directory path rather than on the
socket file path because the latter may not exist yet and in that case
realpath is allowed to fail. From Romain Francoise.


Revision tags: OPENBSD_5_2_BASE
# 1.112 10-Jul-2012 nicm

xfree is not particularly helpful, remove it. From Thomas Adam.


# 1.111 18-Jun-2012 nicm

Add a skeleton mode to tmux (called "control mode") that let's tmux
commands be sent and output received on stdout. This can be used to
integrate with other terminal emulators and should allow some other
things to be made simpler later. More to come so doesn't do much yet and
deliberately not documented.


# 1.110 30-May-2012 nicm

Do not use stderr for log file and don't call log_close when not needed.


# 1.109 25-May-2012 nicm

Simplify logging and just fprintf(stderr, ...) for early errors.


Revision tags: OPENBSD_5_1_BASE
# 1.108 21-Jan-2012 nicm

Drop the ability to have a list of keys in the prefix in favour of two
separate options, prefix and prefix2. This simplifies the code and gets
rid the data options type which was only used for this one option.

Also add a -2 flag to send-prefix to send the secondary prefix key,
fixing a cause of minor irritation.

People who want three prefix keys are out of luck :-).


# 1.107 23-Oct-2011 nicm

Try to resolve relative paths for loadb and saveb (first using client
working directory if any then default-path or session wd).


# 1.106 23-Oct-2011 nicm

Ignore LC_ALL and LC_CTYPE if they are empty as well as unset.


# 1.105 25-Sep-2011 nicm

Reject $SHELL if it is not a full path.


Revision tags: OPENBSD_5_0_BASE
# 1.104 04-Mar-2011 nicm

Two fixes by Micah Cowan: make mouse work properly beyond >127 on signed
char architectures and properly parse $TMUX by stopping the socket path
at the first comma.


Revision tags: OPENBSD_4_9_BASE
# 1.103 23-Jan-2011 nicm

Set $TMUX without the session when background jobs are run.


# 1.102 12-Jan-2011 nicm

Use TMPDIR if set, from Han Boetes.


# 1.101 08-Jan-2011 nicm

Move all calls to fcntl(...O_NONBLOCK) into a function and clear the
flag on the stdio file descriptors before closing them (fixes things
like "tmux ls && cat").


# 1.100 03-Jan-2011 nicm

Support for UTF-8 mouse input (\033[1005h). This was added in xterm 262
and supports larger terminals than the older way.

If the new mouse-utf8 option is on, UTF-8 mouse input is enabled for all
UTF-8 terminals. The option defaults to on if LANG etc are set in the
same manner as the utf8 option.

With help and based on code from hsim at gmx.li.


# 1.99 01-Jan-2011 nicm

Move the user-visible parts of all options (names, types, limit, default
values) together into one set of tables in options-table.c. Also clean
up and simplify cmd-set-options.c and move a common print function into
option-table.c.


# 1.98 30-Dec-2010 nicm

Change from a per-session stack of buffers to one global stack which is
much more convenient and also simplifies lot of code. This renders
copy-buffer useless and makes buffer-limit now a server option.

By Tiago Cunha.


# 1.97 19-Dec-2010 nicm

Add other-pane-height and other-pane-width options, allowing the width
or height of the smaller panes in the main-horizontal and main-vertical
layouts to be set. Mostly from David Goodlad.


# 1.96 08-Dec-2010 nicm

In the built-in layouts, distribute the panes more evenly. Set the
default value of main-pane-width to 80, rather than 81. By Micah Cowan.


# 1.95 06-Dec-2010 nicm

Add an option to alert (monitor) for silence (lack of activity) in a
window. From Thomas Adam.


# 1.94 29-Nov-2010 nicm

If VISUAL or EDITOR contains "vi", configure mode-keys and status-keys
to vi.

Based on a diff from martynas@, previously requested by a couple of
other people.


# 1.93 11-Nov-2010 nicm

Add XAUTHORITY to update-environment, requested by Andreas Kloeckner.


# 1.92 18-Oct-2010 nicm

Merge the before and after attach client code into one in client.c
(instead of two in tmux.c and client.c).


# 1.91 16-Oct-2010 nicm

Make stdio blocking again before calling shell command with -c.


# 1.90 16-Oct-2010 nicm

Trying to set FD_CLOEXEC on every fd is a lost cause, just use
closefrom() before exec.


# 1.89 14-Oct-2010 nicm

Use an explicit event rather than event_once for the main event so it
can be removed when the client becomes ready.


# 1.88 26-Sep-2010 nicm

Two new options:

- server option "exit-unattached" makes the server exit when no clients
are attached, even if sessions are present;

- session option "destroy-unattached" destroys a session once no clients
are attached to it.

These are useful for preventing tmux remaining in the background where
it is undesirable and when using tmux as a login shell to keep a limit
on new sessions.


# 1.87 19-Aug-2010 nicm

Do not call event_del() for signals after fork(), just use sigaction()
directly instead - calling libevent functions after fork() w/o
event_reinit() is a bad idea, even if in this case it was harmless.


Revision tags: OPENBSD_4_8_BASE
# 1.86 04-Aug-2010 deraadt

switch back to kqueue for now, since (a) kqueue has been fixed to deal
with strange devices and (b) since there appears to be a bull in the
poll code in libevent as well...
requested by nicm who is away


# 1.85 24-Jul-2010 nicm

kqueue(2) is currently broken when used with /dev/null and a few other
devices.

An upcoming fix for some problems with the client stdout/stderr handling
relies on it working, so make tmux force libevent to use poll(2) via
EVENT_NOKQUEUE, until we have fixed kqueue.


# 1.84 11-Jul-2010 nicm

Return the command client return code with MSG_EXIT now that MSG_ERROR and
MSG_PRINT are unused.

New clients should be compatible with old tmux servers but vice versa may print
an error.


# 1.83 28-Jun-2010 nicm

Send all three of stdin, stdout, stderr from the client to the server, so that
commands can directly make use of them. This means that load-buffer and
save-buffer can have "-" as the file to read from stdin or write to stdout.

This is a protocol version bump so the tmux server will need to be restarted
after upgrade (or an older client used).


# 1.82 27-Jun-2010 nicm

Store the current working directory in the session, change the default-path
option to default to empty and make that mean that the stored session CWD is
used.


# 1.81 27-Jun-2010 nicm

New option, detach-on-destroy, to set what happens to a client when the session
it is attached to is destroyed. If on (the default), it is detached; if off, it
is switched to the most recently active session.


# 1.80 26-Jun-2010 nicm

Setting the cmdlist pointer in the bind-key to NULL to prevent it being freed
after the command is executing is bogus because it may still be needed if the
same command is going to be executed again (for example if you "bind-key a
bind-key b ..."). Making a copy is hard, so instead add a reference count to
the cmd_list.

While here, also print bind-key -n and the rest of the flags properly.

Fixes problem reported by mcbride@.


# 1.79 14-May-2010 nicm

Colour+attribute options for status line alerts, from Alex Alexander.


# 1.78 04-May-2010 nicm

Put this back in with the initialisation in the right order.


# 1.77 04-May-2010 nicm

Revert last change, it appears to be broken somehow.


# 1.76 03-May-2010 nicm

Make signal handler setup/teardown two common functions instead of six,
and reset SIGCHLD after fork to fix problems with some shells. From
Romain Francois.


# 1.75 28-Apr-2010 nicm

Make the active pane border have a green foreground instead of
background by default.


# 1.74 18-Apr-2010 nicm

Catch SIGCHLD to avoid a zombie, from patrick keshishian.


Revision tags: OPENBSD_4_7_BASE
# 1.73 22-Feb-2010 nicm

Option to set the characters considered word separators in copy mode, from
Micah Cowan.


# 1.72 08-Feb-2010 nicm

Add an option to disable the smcup/rmcup alternate screen behaviour inside
tmux. From clemens fischer.


# 1.71 06-Feb-2010 nicm

Change nested check to compare server socket path rather than just assuming
that if $TMUX is set it is nested. From Micah Cowan.


# 1.70 06-Feb-2010 nicm

Clean up $TMUX parsing, from Micah Cowan, tweaked by me.


# 1.69 06-Feb-2010 nicm

Instead of bailing out on the first configuration file error, carry on,
collecting all the errors, then start with the active window in more mode
displaying them.


# 1.68 04-Feb-2010 nicm

Read the path from $TMUX if it is present and -L and -S are not given. Based on
a diff from Micah Cowan.


# 1.67 04-Feb-2010 nicm

Option to display the active pane in a different colour with the display-panes
command. From Paul Hoffman, thanks.


# 1.66 03-Jan-2010 nicm

Options to set the colour of the pane borders, with different colours for the
active pane.


# 1.65 14-Dec-2009 nicm

New server option, escape-time, to set the timeout used to detect if escapes
are alone or part of a function key or meta sequence.


# 1.64 11-Dec-2009 nicm

Use quiet variable, and add missing sentinel to options array.


# 1.63 10-Dec-2009 nicm

Add "server options" which are server-wide and not bound to a session or
window. Set and displayed with "set -s" and "show -s".

Currently the only option is "quiet" (like command-line -q, allowing it to be
set from .tmux.conf), but others will come along.


# 1.62 03-Dec-2009 nicm

Massive spaces->tabs and trailing whitespace cleanup, hopefully for the last
time now I've configured emacs to make them displayed in really annoying
colours...


# 1.61 26-Nov-2009 nicm

Remove a couple of unused arguments where possible, and add /* ARGSUSED */ to
the rest to reduce lint output.


# 1.60 19-Nov-2009 nicm

Two new options, window-status-format and window-status-current-format, which
allow the format of each window in the status line window list to be controlled
using similar # sequences as status-left/right.

This diff also moves part of the way towards UTF-8 support in window names but
it isn't quite there yet.


# 1.59 19-Nov-2009 nicm

Revert to xterm-keys off by default. It was on as an experiment to see if the
option could be removed, but it affects vi, so we have to keep the option, and
a conservative default is better.


# 1.58 18-Nov-2009 nicm

Add a per-client log of status line messages displayed while that client
exists. A new message-limit session option sets the maximum number of entries
and a command, show-messages, shows the log (bound to ~ by default).

This (and prompt history) might be better as a single global log but until
there are global options it is easier for them to be per client.


# 1.57 10-Nov-2009 nicm

There is no real standard for modifier plus function keys. Previously, tmux
output some from rxvt but in other ways did the same as xterm or other
terminals, but this is a bit inconsistent.

xterm's method is fairly sensible and we already support it (xterm-keys), so
enable it by default instead.


# 1.56 04-Nov-2009 nicm

A couple of minor cosmetic changes.


# 1.55 04-Nov-2009 nicm

Initial changes to move tmux to libevent.

This moves the client-side loops are pretty much fully over to event-based only
(tmux.c and client.c) but server-side (server.c and friends) treats libevent as
a sort of clever poll, waking up after every event to run various things.

Moving the server stuff over to bufferevents and timers and so on will come
later.


# 1.54 04-Nov-2009 nicm

Change declaration and use of malloc_options to be more standard, from Tim van
der Molen.


# 1.53 26-Oct-2009 deraadt

tabs are better; ok nicm


# 1.52 25-Oct-2009 nicm

Remove the -d flag to tmux and just use op/AX to detect default colours.

Irritatingly, although op can be used to tell if a terminal supports default
colours, it can't be used to set them because in some terminfo descriptions it
resets attributes as a side-effect (acts as sgr0) and in others it doesn't, so
it is not possible to determine reliably what the terminal state will be
afterwards. So if AX is missing and op is present, tmux just sends sgr0.

Anyone using -d for a terminal who finds they actually needed it can replace it
using terminal-overrides, but please let me know as it is probably an omission
from terminfo.


# 1.51 22-Oct-2009 nicm

Merge prepare_cmd into main as it is short and only called once.


# 1.50 21-Oct-2009 nicm

Client tidying: get rid of client_ctx struct in favour of two variables in
client.c, and move the functions in client-fn.c into other files.


# 1.49 10-Oct-2009 nicm

New option, mouse-select-pane. If on, the mouse may be used to select the
current pane.

Suggested by sthen@ and also by someone else ages ago who I have forgotten.


# 1.48 10-Oct-2009 nicm

Support for individual session idle time locking. May be enabled by turning off
the lock-server option (it is on by default). When this is off, each session
locks when it has been idle for the lock-after-time setting. When on, the
entire server locks when ALL sessions have been idle for their individual
lock-after-time settings.

This replaces one global-only option (lock-after-time) with another
(lock-server), but the default behaviour is usually preferable so there don't
seem to be many alternatives.

Diff/idea largely from Thomas Adam, tweaked by me.


# 1.47 09-Oct-2009 nicm

Add a simple synchronize-panes window option: when set, all input to any pane
that is part of the window is also sent to all other panes in the same
window. Suggested by several, most recently Tomasz Pajor.


# 1.46 23-Sep-2009 nicm

Support -c like sh(1) to execute a command, useful when tmux is a login
shell. Suggested by halex@.

This includes another protocol version increase (the last for now) so again
restart the tmux server before upgrading.


# 1.45 23-Sep-2009 nicm

Remove the internal tmux locking and instead detach each client and run the
command specified by a new option "lock-command" (by default "lock -np") in
each client.

This means each terminal has to be unlocked individually but simplifies the
code and allows the system password to be used to unlock.

Note that the set-password command is gone, so it will need to be removed from
configuration files, and the -U command line flag has been removed.

This is the third protocol version change so again it is best to stop the tmux
server before upgrading.


# 1.44 22-Sep-2009 nicm

Permit multiple prefix keys to be defined, separated by commas, for example:

set -g prefix ^a,^b

Any key in the list acts as the prefix. The send-prefix command always sends
the first key in the list.


# 1.43 18-Sep-2009 nicm

New option, set-titles-string, to allow the window title to be specified (as
for status-left/right) if set-titles is on. Also only update the title when the
status line is being redrawn.


# 1.42 04-Sep-2009 nicm

Tidy main and make it a bit easier to read.


# 1.41 02-Sep-2009 nicm

Accept -l to make it easier for people who use tmux as a login shell to use
$SHELL. Originally from martynas@, tweaked by me.


# 1.40 02-Sep-2009 nicm

When incorrect passwords are entered, behave similarly to login(1) and backoff
for a bit. Based on a diff from martynas@.


# 1.39 01-Sep-2009 nicm

When using tmux as a login shell, there is currently no way to specify a shell
to be used as a login shell inside tmux, so add a default-shell session option.
This sets the shell invoked as a login shell when the default-command option is
empty.

The default option value is whichever of $SHELL, getpwuid(getuid())'s pw_shell
or /bin/sh is valid first.

Based on a diff from martynas@, changed by me to be a session option rather
than a window option.


# 1.38 01-Sep-2009 nicm

Use "Password:" with no space for password prompts and don't display a *s for
the password, like pretty much everything else. From martynas@ with minor
tweaks by me.


# 1.37 01-Sep-2009 nicm

Sort cases same as getopt argument, from martynas.


# 1.36 31-Aug-2009 nicm

Add a new display-panes command, with two options (display-panes-colour and
display-panes-time), which displays a visual indication of the number of each
pane.


# 1.35 23-Aug-2009 nicm

Add some other obvious variables to update-environment (WINDOWID SSH_ASKPASS
SSH_AUTH_SOCK SSH_AGENT_PID SSH_CONNECTION) so they are updated in the session
environment on new/attach.


# 1.34 13-Aug-2009 nicm

Disable mode-mouse (mouse in copy/choice mode) by default as it isn't very
useful at the moment and causes confusion.


# 1.33 13-Aug-2009 nicm

Add a base-index session option to specify the first index checked when looking
for an index for a new window.


# 1.32 12-Aug-2009 nicm

When started as the shell, __progname contains a leading -, so hardcode "tmux"
for socket path and log files, and strip it when working out the shell.


# 1.31 11-Aug-2009 nicm

Switch tmux to use imsg. This is the last major change to make the
client-server protocol more resilient and make the protocol versioning work
properly. In future, the only things requiring a protocol version bump will be
changes in the message structs, and (when both client and server have this
change) mixing different versions should nicely report an error message.

As a side effect this also makes the code tidier, fixes a problem with the way
errors reported during server startup were handled, and supports fd passing
(which will be used in future).

Looked over by eric@, thanks.

Please note that mixing a client with this change with an older server or vice
versa may cause tmux to crash or hang - tmux should be completely exited before
upgrading.


# 1.30 10-Aug-2009 nicm

No arguments are the same as new-session and this requires the environment to
be sent, so set that flag too when argc == 0.


# 1.29 08-Aug-2009 nicm

Infrastructure and commands to manage the environment for processes started
within tmux.

There is a global environment, copied from the external environment when the
server is started and each sesssion has an (initially empty) session
environment which overrides it.

New commands set-environment and show-environment manipulate or display the
environments.

A new session option, update-environment, is a space-separated list of
variables which are updated from the external environment into the session
environment every time a new session is created - the default is DISPLAY.


# 1.28 08-Aug-2009 nicm

Options to set the colours and attributes for status-left/-right. From Thomas
Adam, thanks.


# 1.27 05-Aug-2009 nicm

If colours are not supported by the terminal, try to emulate a coloured
background by setting or clearing the reverse attribute.

This makes a few applications which don't use the reverse attribute themselves
a little happier, and allows the status, message and mode options to have
default attributes and fg/bg options that work as expected when set as reverse.


# 1.26 04-Aug-2009 nicm

Check for "UTF8" as well as "UTF-8" in LANG etc as it seems this may also
appear.


# 1.25 03-Aug-2009 nicm

Add a terminal-overrides session option allowing individual terminfo(5) entries
to be overridden. The 88col/256col checks are now moved into the default
setting and out of the code.

Also remove a couple of old workarounds for xterm and rxvt which are no longer
necessary (tmux can emulate them if missing).


# 1.24 30-Jul-2009 nicm

Add a mode-mouse option to prevent tmux taking over the mouse in choice or copy
modes.


# 1.23 29-Jul-2009 nicm

Rename struct hdrtype to msgtype which is a better name and can be used even
when struct hdr disappears.


# 1.22 29-Jul-2009 nicm

Taking account of the "s, 22 not 24 is the maximum length of #T in status-right
to prevent the date being cut off.


# 1.21 26-Jul-2009 nicm

Make all messages sent between the client and server fixed size.

This is the first of two changes to make the protocol more resilient and less
sensitive to other changes in the code, particularly with commands. The client
now packs argv into a buffer and sends it to the server for parsing, rather
than doing it itself and sending the parsed command data.

As a side-effect this also removes a lot of now-unused command marshalling
code.

Mixing a server without this change and a client with or vice versa will cause
tmux to hang or crash, please ensure that tmux is entirely killed before
upgrading.


# 1.20 22-Jul-2009 nicm

Pass a set of flags into client_init rather than just a start_server
variable. Only one flag now but more to come later.


# 1.19 20-Jul-2009 nicm

Display the number of failed password attempts (if any) when the server is
locked. From Tom Doherty.


# 1.18 20-Jul-2009 nicm

Add a status-justify option to allow the window list in the status line to be
positioned at the left, centre, or right.


# 1.17 20-Jul-2009 nicm

New options, window-status-current-{fg,bg,attr}, to set the fg, bg and
attributes with which the current window is shown in the status line. From
Johan Friis, thanks.


# 1.16 18-Jul-2009 nicm

Add three new session options: visual-activity, visual-bell, visual-content. If
these are enabled (and the monitor-activity, bell-actio and monitor-content
options are configurated appropriately), when activity, a bell, or content is
detected, a message is shown.

Also tidy up the bell/activity/content code in server.c slightly and fix a
couple of errors.


# 1.15 17-Jul-2009 nicm

If -u is specified or UTF-8 is otherwise detected when the server is started,
enable the utf8 and status-utf8 optons. While here, note in the man page that
the server is started with the first session and exits when none remain.


# 1.14 10-Jul-2009 nicm

Add a default-terminal option to set the starting value of $TERM in new
windows.

This is "screen" by default and must be either that or something closely
related. This does makes it easier to customise it if necessary.


# 1.13 08-Jul-2009 nicm

Just appending -l to $SHELL to create a login shell is wrong: -l is not POSIX,
and some people may use shells which do not support it. Instead, make an empty
default-command option mean a login shell, and fork it with a - in argv[0]
which is the method used by login(1).

Also fix the automatic-rename code to handle this correctly and to strip a
leading - if present.


# 1.12 07-Jul-2009 nicm

Rename the global options variables to be shorter and to make session options
clear. No functional change, getting this out of the way to make later options
changes easier.


Revision tags: OPENBSD_4_6_BASE
# 1.11 25-Jun-2009 nicm

If getcwd() fails, use the user's home directory, or /, instead of failing with
an error.


# 1.10 25-Jun-2009 nicm

Remove error about using -L and -S together which was never displayed as
logging wasn't yet enabled, was unnecessary, and contradicted the man page
which says using -S will cause -L to be ignored.


# 1.9 23-Jun-2009 nicm

LC_ALL overrides LC_CTYPE and LANG. Comment was correct but the code
wrong. Pointed out by Hannah Schroeter, thanks.


# 1.8 05-Jun-2009 nicm

Check the first of LC_CTYPE, LC_ALL and LANG, rather than just the last, when
trying to decide about UTF-8, and use strcasestr. Reported by Geert Hendrickx.


# 1.7 04-Jun-2009 nicm

Zero the password given to -U in the client as well.


# 1.6 03-Jun-2009 nicm

Do not set the window title by default (make set-titles option default to off),
wiping over the title is rude and annoying. Agreed by several.


# 1.5 03-Jun-2009 nicm

New session option, status-utf8, to control the interpretation of top-bit-set
characters in status-left and status-right (if on, they are treated as UTF-8;
otherwise passed through).


# 1.4 02-Jun-2009 sobrado

remove unused flag; while here, make usage's output fit on 80-column displays.


# 1.3 02-Jun-2009 pyr

spawn login shells by default, adapt manpage bits as well.
ok nicm@


# 1.2 02-Jun-2009 ray

Don't leak memory if multiple -f flags are given.

OK nicm@


# 1.1 01-Jun-2009 nicm

Import tmux, a terminal multiplexor allowing (among other things) a single
terminal to be switched between several different windows and programs
displayed on one terminal be detached from one terminal and moved to another.

ok deraadt pirofti


# 1.198 20-Apr-2020 nicm

Tidy up the terminal detection and feature code and add named sets of
terminal features, each of which are defined in one place and map to a
builtin set of terminfo(5) capabilities. Features can be specified based
on TERM with a new terminal-features option or with the -T flag when
running tmux. tmux will also detect a few common terminals from the DA
and DSR responses.

This is intended to make it easier to configure tmux's use of
terminfo(5) even in the presence of outdated ncurses(3) or terminfo(5)
databases or for features which do not yet have a terminfo(5) entry.
Instead of having to grok terminfo(5) capability names and what they
should be set to in the terminal-overrides option, the user can
hopefully just give tmux a feature name and let it do the right thing.

The terminal-overrides option remains both for backwards compatibility
and to allow tweaks of individual capabilities.

tmux already did much of this already, this makes it tidier and simpler
to configure.


# 1.197 16-Apr-2020 nicm

Show signal name when process exits rather than number.


# 1.196 09-Apr-2020 nicm

More style nits.


# 1.195 31-Mar-2020 nicm

Add a way to mark environment variables as "hidden" so they can be used
by tmux but are not passed into the environment of new panes.


# 1.194 17-Mar-2020 nicm

Ignore default-shell (and use /bin/sh) if it invalid not just if it is
tmux itself, also refuse to set the option to something invalid in the
first place. GitHub issue 2120.


# 1.193 12-Mar-2020 nicm

When the server socket is given by the user with -S, create it with
umask 177 instead of 117 because it may not be in a safe directory like
the default directory in /tmp. The user can chmod it more open after it
is created if they want.


# 1.192 28-Jan-2020 nicm

-V also needs to go in usage.


# 1.191 28-Jan-2020 nicm

Reduce a difference with portable tmux by adding the -V flag and
#{version} format; on OpenBSD these just report the OpenBSD version.


# 1.190 14-Oct-2019 nicm

Memory leaks, from Igor Wong in GitHub issue 1934.


Revision tags: OPENBSD_6_6_BASE
# 1.189 20-Jun-2019 nicm

Add a per-pane option set. Pane options inherit from window options (so
there should be no change to existing behaviour) and are set and shown
with set-option -p and show-options -p.

Change remain-on-exit and window-style/window-active-style to be pane
options (some others will be changed later).

This makes select-pane -P and -g unnecessary so no longer document them
(they still work) and no longer document set-window-option and
show-window-options in favour of set-option -w and show-options -w.


# 1.188 26-Apr-2019 nicm

Merge hooks into options and make each one an array option. This allows
multiple commands to be easily bound to one hook. set-hook and
show-hooks remain but they are now variants of set-option and
show-options. show-options now has a -H flag to show hooks (by default
they are not shown).


Revision tags: OPENBSD_6_5_BASE
# 1.187 22-Nov-2018 nicm

Do not use PWD unless it actually matches the real working directory.


Revision tags: OPENBSD_6_3_BASE OPENBSD_6_4_BASE
# 1.186 12-Jan-2018 nicm

Improve error message if creating socket parent directory fails, from
Thomas Adam for GitHub issue 1215.


# 1.185 01-Jan-2018 nicm

Prefer PWD for current directory if present in client, from Wei Zhao in
GitHub issue 1183.


Revision tags: OPENBSD_6_2_BASE
# 1.184 12-Jul-2017 nicm

Make shell_command a global like other stuff rather than making it an
exception and using callback argument.


# 1.183 03-Jul-2017 nicm

Try C.UTF-8 which is also a commonly useful locale on some platforms,
from Romain Francoise.


# 1.182 22-Apr-2017 nicm

Do not need getopt.h.


# 1.181 20-Apr-2017 nicm

Use fdforkpty() instead of our own unwrapped versions.


# 1.180 19-Apr-2017 nicm

Style nits and a missing cast.


# 1.179 16-Apr-2017 nicm

Memory leak, from David CARLIER.


Revision tags: OPENBSD_6_1_BASE
# 1.178 21-Mar-2017 nicm

Use uid_t for UID not u_int.


# 1.177 16-Feb-2017 nicm

Style nits.


# 1.176 23-Jan-2017 nicm

Open /dev/ptm before pledge() and save it to be used for PTMGET later
(this means inlining forkpty()).

ok deraadt


# 1.175 15-Jan-2017 nicm

Major tidy up and rework of options tree and set-option/show-options
commands this pushes more of the code into options.c and ties it more
closely to the options table rather than having an unnecessary
split. Also add support for array options (will be used later). Only
(intentional) user visible change is that show-options output is now
passed through vis(3) with VIS_DQ so quotes are escaped.


# 1.174 12-Jan-2017 nicm

Simplify appending to string options.


# 1.173 09-Dec-2016 nicm

Spacing nits.


# 1.172 11-Oct-2016 nicm

Add static in window-*.c and move some internal functions out of tmux.h.


# 1.171 10-Oct-2016 nicm

Loads more static, except for cmd-*.c and window-*.c.


Revision tags: OPENBSD_6_0_BASE
# 1.170 27-May-2016 nicm

Use getprogname() instead of __progname to make portability easier.


# 1.169 04-May-2016 nicm

Fix up a couple of long lines.


# 1.168 05-Mar-2016 nicm

If setlocale("en_US.UTF-8") succeeds, then don't do the check for UTF-8
locale since if it isn't UTF-8 the system is broken anyway. If it fails,
try "" and check for UTF-8 with nl_langinfo(CODESET) rather than
wcwidth(). Based on a diff from schwarze@, nl_langinfo also suggested by
stsp@.


# 1.167 05-Mar-2016 nicm

Although we always have en_US.UTF-8 on OpenBSD, some platforms do not,
so fall back to setlocale(LC_CTYPE, ""). tmux requires a UTF-8 locale,
so check with wcwidth() on a UTF-8 character after setlocale().


# 1.166 01-Mar-2016 nicm

Remove unused variables, from Michal Mazurek.


# 1.165 01-Mar-2016 nicm

Use system wcwidth() instead of carrying around UTF-8 width tables.


Revision tags: OPENBSD_5_9_BASE
# 1.164 19-Jan-2016 nicm

I no longer use my SourceForge address so replace it.


# 1.163 08-Dec-2015 nicm

Add hooks infrastructure, basic commands (set-hook, show-hooks) and a
couple of not very useful client hooks. This will eventually let
commands be run at various points and on notifications. Joint work with
Thomas Adam.


# 1.162 24-Nov-2015 nicm

Make environ_set va_args and use it to tidy up some calls. Also add a
missing word in manpage (from jmc).


# 1.161 24-Nov-2015 nicm

Shell command from -c doesn't have to be global, pass it as an argument.


# 1.160 24-Nov-2015 nicm

Tidy the code that works out the socket path, and just use the full path
in the global socket_path rather than copying it.


# 1.159 24-Nov-2015 nicm

Remove malloc_options DEBUG bit.


# 1.158 24-Nov-2015 nicm

Remove the -I part of show-messages which isn't really that useful; the
server start time can now be accessed with a new start_time format (use:
tmux display -p '#{t:start_time}')


# 1.157 24-Nov-2015 nicm

Make the log stuff a bit tidier with some helper functions.


# 1.156 22-Nov-2015 nicm

Add getpw to pledge, makes tmux work in YP environments, discovered by
matthieu, ok deraadt


# 1.155 20-Nov-2015 nicm

Instead of separate tables for different types of options, give each
option a scope type (server, session, window) in one table.


# 1.154 15-Nov-2015 nicm

Accidentally turned off pledge, turn it back on.


# 1.153 14-Nov-2015 nicm

Push stdout and stderr to clients more aggressively, and add an event to
continue if the send fails.


# 1.152 12-Nov-2015 nicm

tmux is UTF-8, so if $TMUX is set (tmux running in tmux), the client is
UTF-8. Also try to make the existing checks more readable.


# 1.151 12-Nov-2015 nicm

Nuke the utf8 and status-utf8 options and make tmux only a UTF-8
terminal. We still support non-UTF-8 terminals outside tmux, but inside
it is always UTF-8 (as when the utf8 and status-utf8 options were on).


# 1.150 11-Nov-2015 nicm

Drop mouse-utf8 option and always turn on UTF-8 mouse if the client says
it supports UTF-8.


# 1.149 28-Oct-2015 nicm

Like options, move the environ struct into environ.c.


# 1.148 27-Oct-2015 nicm

Move struct options into options.c.


# 1.147 27-Oct-2015 nicm

Break the common process set up, event loop and imsg dispatch code
between server and client out into a separate internal API. This will
make it easier to add another process.


# 1.146 25-Oct-2015 deraadt

Let's see if anyone screams about not being able to specify $TMPDIR
for their tmux sockets.

(Over the years, I have seen $TMPDIR set up worse than /tmp many times,
and don't know how this practice infected other parts of the system.
Nothing uses tmpdir(3), nor a huge-temporary-file program like sort.)
ok nicm


# 1.145 23-Oct-2015 nicm

tmux can call pledge() in main with large set and then reduce it
slightly in the server to "stdio rpath wpath cpath fattr unix recvfd
proc exec tty ps".


# 1.144 14-Sep-2015 nicm

Move tzset() from log_open to main.


# 1.143 03-Sep-2015 nicm

A couple of style nits.


# 1.142 01-Sep-2015 nicm

Work out config file when needed not at startup.


# 1.141 30-Aug-2015 nicm

Path from $TMUX does not need to be global anymore.


# 1.140 30-Aug-2015 nicm

Login shell can be a client flag, and move the exec code into client.c.


# 1.139 30-Aug-2015 nicm

Event base does not need to be global.


# 1.138 30-Aug-2015 nicm

Some style nits and dead assignments.


Revision tags: OPENBSD_5_8_BASE
# 1.137 20-Jul-2015 nicm

Add an option (history-file) for a file to save/restore command prompt
history, from Olof-Joachim Frahm.


# 1.136 04-Jun-2015 jmc

tweak SYNOPSIS and usage();


Revision tags: OPENBSD_5_7_BASE
# 1.135 19-Jan-2015 nicm

Make a tmux-%u directory under TMUX_TMPDIR, like TMPDIR.


# 1.134 19-Jan-2015 nicm

Only care about other permissions, allow group to be set.


# 1.133 19-Jan-2015 nicm

Remove unnecessary duplicate S_ISDIR check, from Dmitri Paduchikh.


# 1.132 20-Oct-2014 nicm

Tidy up some includes.


Revision tags: OPENBSD_5_6_BASE
# 1.131 17-Apr-2014 nicm

Remove the "info" message mechanism, this was only used for about five
mostly useless and annoying messages. Change those commands to silence
on success like all the others. Still accept the -q command line flag
and "quiet" server option for now.


# 1.130 31-Mar-2014 nicm

Remove log_debug2 as well and simplify log.c.


Revision tags: OPENBSD_5_5_BASE
# 1.129 16-Feb-2014 nicm

Leftovers from removing 88 colour support, from Theo Buehler.


# 1.128 15-Jan-2014 nicm

Do not attempt to read .tmux.conf if we can't figure out a home
directory, from Tiago Cunha.


# 1.127 09-Jan-2014 nicm

Three small changes from Tiago Cunha:

- Check for truncation when copying path.
- Don't need to use a temporary buffer in screen_set_title.
- Include strerror in output when connecting to server fails.


# 1.126 10-Oct-2013 nicm

We accidentally haven't been using $TMUX to work out the session for a
while and in fact it is less useful that using the client ttyname. So
don't bother and don't pass it from the client. If we need it in future
it is in c->environ.


# 1.125 10-Oct-2013 nicm

Alter how tmux handles the working directory to internally use file
descriptors rather than strings.

- Each session still has a current working directory.

- New sessions still get their working directory from the client that
created them or its attached session if any.

- New windows are created by default in the session working directory.

- The -c flag to new, neww, splitw allows the working directory to be
overridden.

- The -c flag to attach let's the session working directory be changed.

- The default-path option has been removed.

To get the equivalent to default-path '.', do:

bind c neww -c $PWD

To get the equivalent of default-path '~', do:

bind c neww -c ~

This also changes the client identify protocol to be a set of messages rather
than one as well as some other changes that should make it easier to make
backwards-compatible protocol changes in future.


# 1.124 10-Oct-2013 nicm

Merge IDENTIFY_* flags with CLIENT_* flags.


# 1.123 10-Oct-2013 nicm

Don't treat TMUX_TMPDIR as a potential file

The point of setting TMUX_TMPDIR is to then make any labels from -L go
to that directory. In the case of makesocketpath() with no TMUX_TMPDIR
set, would set both the path and the default socket to a file. The
checking of the permissions on the file worked fine in that case, but
when TMUX_TMPDIR is set, won't work on a directory.

This fixes the problem by ensuring the check on the permissions is
performed on directories only.

By Thomas Adam.


# 1.122 05-Oct-2013 nicm

Fix previous not to leak fd on failure, whoops.


# 1.121 05-Oct-2013 nicm

Use open(".")/fchdir() to save and restore current directory rather than
getcwd()/chdir().


Revision tags: OPENBSD_5_4_BASE
# 1.120 24-Apr-2013 nicm

Rename global configuration define.


# 1.119 11-Apr-2013 nicm

Call setlocale(LC_TIME) at startup.


# 1.118 27-Mar-2013 nicm

Add TMUX_TMPDIR variable to put the socket directory outside
TMPDIR. From Ben Boeckel.


# 1.117 27-Mar-2013 nicm

Remove tmux's (already minimal) 88 colour support. Such terminals are
few and unnecessary.


# 1.116 25-Mar-2013 nicm

Rename session idx to session id throughout and add $ prefix to targets
to use it, extended from a diff from George Nachman.


# 1.115 24-Mar-2013 nicm

Add a command queue to standardize and simplify commands that call other
commands and allow a command to block execution of subsequent
commands. This allows run-shell and if-shell to be synchronous which has
been much requested.

Each client has a default command queue and commands are consumed one at
a time from it. A command may suspend execution from the queue by
returning CMD_RETURN_WAIT and then resume it by calling cmd_continue() -
for example run-shell does this from the callback that is fired after
the job is freed.

When the command queue becomes empty, command clients are automatically
exited (unless attaching). A callback is also fired - this is used for
nested commands in, for example, if-shell which can block execution of
the client's cmdq until a new cmdq becomes empty.

Also merge all the old error/info/print functions together and lose the
old curclient/cmdclient distinction - a cmdq is bound to one client (or
none if in the configuration file), this is a command client if
c->session is NULL otherwise an attached client.


Revision tags: OPENBSD_5_3_BASE
# 1.114 27-Nov-2012 nicm

Correctly aggregate together errors from nested config files (with
source-file). Fix by Thomas Adam, reported by Sam Livingstone-Gray


# 1.113 26-Nov-2012 nicm

Call realpath earlier on the socket directory path rather than on the
socket file path because the latter may not exist yet and in that case
realpath is allowed to fail. From Romain Francoise.


Revision tags: OPENBSD_5_2_BASE
# 1.112 10-Jul-2012 nicm

xfree is not particularly helpful, remove it. From Thomas Adam.


# 1.111 18-Jun-2012 nicm

Add a skeleton mode to tmux (called "control mode") that let's tmux
commands be sent and output received on stdout. This can be used to
integrate with other terminal emulators and should allow some other
things to be made simpler later. More to come so doesn't do much yet and
deliberately not documented.


# 1.110 30-May-2012 nicm

Do not use stderr for log file and don't call log_close when not needed.


# 1.109 25-May-2012 nicm

Simplify logging and just fprintf(stderr, ...) for early errors.


Revision tags: OPENBSD_5_1_BASE
# 1.108 21-Jan-2012 nicm

Drop the ability to have a list of keys in the prefix in favour of two
separate options, prefix and prefix2. This simplifies the code and gets
rid the data options type which was only used for this one option.

Also add a -2 flag to send-prefix to send the secondary prefix key,
fixing a cause of minor irritation.

People who want three prefix keys are out of luck :-).


# 1.107 23-Oct-2011 nicm

Try to resolve relative paths for loadb and saveb (first using client
working directory if any then default-path or session wd).


# 1.106 23-Oct-2011 nicm

Ignore LC_ALL and LC_CTYPE if they are empty as well as unset.


# 1.105 25-Sep-2011 nicm

Reject $SHELL if it is not a full path.


Revision tags: OPENBSD_5_0_BASE
# 1.104 04-Mar-2011 nicm

Two fixes by Micah Cowan: make mouse work properly beyond >127 on signed
char architectures and properly parse $TMUX by stopping the socket path
at the first comma.


Revision tags: OPENBSD_4_9_BASE
# 1.103 23-Jan-2011 nicm

Set $TMUX without the session when background jobs are run.


# 1.102 12-Jan-2011 nicm

Use TMPDIR if set, from Han Boetes.


# 1.101 08-Jan-2011 nicm

Move all calls to fcntl(...O_NONBLOCK) into a function and clear the
flag on the stdio file descriptors before closing them (fixes things
like "tmux ls && cat").


# 1.100 03-Jan-2011 nicm

Support for UTF-8 mouse input (\033[1005h). This was added in xterm 262
and supports larger terminals than the older way.

If the new mouse-utf8 option is on, UTF-8 mouse input is enabled for all
UTF-8 terminals. The option defaults to on if LANG etc are set in the
same manner as the utf8 option.

With help and based on code from hsim at gmx.li.


# 1.99 01-Jan-2011 nicm

Move the user-visible parts of all options (names, types, limit, default
values) together into one set of tables in options-table.c. Also clean
up and simplify cmd-set-options.c and move a common print function into
option-table.c.


# 1.98 30-Dec-2010 nicm

Change from a per-session stack of buffers to one global stack which is
much more convenient and also simplifies lot of code. This renders
copy-buffer useless and makes buffer-limit now a server option.

By Tiago Cunha.


# 1.97 19-Dec-2010 nicm

Add other-pane-height and other-pane-width options, allowing the width
or height of the smaller panes in the main-horizontal and main-vertical
layouts to be set. Mostly from David Goodlad.


# 1.96 08-Dec-2010 nicm

In the built-in layouts, distribute the panes more evenly. Set the
default value of main-pane-width to 80, rather than 81. By Micah Cowan.


# 1.95 06-Dec-2010 nicm

Add an option to alert (monitor) for silence (lack of activity) in a
window. From Thomas Adam.


# 1.94 29-Nov-2010 nicm

If VISUAL or EDITOR contains "vi", configure mode-keys and status-keys
to vi.

Based on a diff from martynas@, previously requested by a couple of
other people.


# 1.93 11-Nov-2010 nicm

Add XAUTHORITY to update-environment, requested by Andreas Kloeckner.


# 1.92 18-Oct-2010 nicm

Merge the before and after attach client code into one in client.c
(instead of two in tmux.c and client.c).


# 1.91 16-Oct-2010 nicm

Make stdio blocking again before calling shell command with -c.


# 1.90 16-Oct-2010 nicm

Trying to set FD_CLOEXEC on every fd is a lost cause, just use
closefrom() before exec.


# 1.89 14-Oct-2010 nicm

Use an explicit event rather than event_once for the main event so it
can be removed when the client becomes ready.


# 1.88 26-Sep-2010 nicm

Two new options:

- server option "exit-unattached" makes the server exit when no clients
are attached, even if sessions are present;

- session option "destroy-unattached" destroys a session once no clients
are attached to it.

These are useful for preventing tmux remaining in the background where
it is undesirable and when using tmux as a login shell to keep a limit
on new sessions.


# 1.87 19-Aug-2010 nicm

Do not call event_del() for signals after fork(), just use sigaction()
directly instead - calling libevent functions after fork() w/o
event_reinit() is a bad idea, even if in this case it was harmless.


Revision tags: OPENBSD_4_8_BASE
# 1.86 04-Aug-2010 deraadt

switch back to kqueue for now, since (a) kqueue has been fixed to deal
with strange devices and (b) since there appears to be a bull in the
poll code in libevent as well...
requested by nicm who is away


# 1.85 24-Jul-2010 nicm

kqueue(2) is currently broken when used with /dev/null and a few other
devices.

An upcoming fix for some problems with the client stdout/stderr handling
relies on it working, so make tmux force libevent to use poll(2) via
EVENT_NOKQUEUE, until we have fixed kqueue.


# 1.84 11-Jul-2010 nicm

Return the command client return code with MSG_EXIT now that MSG_ERROR and
MSG_PRINT are unused.

New clients should be compatible with old tmux servers but vice versa may print
an error.


# 1.83 28-Jun-2010 nicm

Send all three of stdin, stdout, stderr from the client to the server, so that
commands can directly make use of them. This means that load-buffer and
save-buffer can have "-" as the file to read from stdin or write to stdout.

This is a protocol version bump so the tmux server will need to be restarted
after upgrade (or an older client used).


# 1.82 27-Jun-2010 nicm

Store the current working directory in the session, change the default-path
option to default to empty and make that mean that the stored session CWD is
used.


# 1.81 27-Jun-2010 nicm

New option, detach-on-destroy, to set what happens to a client when the session
it is attached to is destroyed. If on (the default), it is detached; if off, it
is switched to the most recently active session.


# 1.80 26-Jun-2010 nicm

Setting the cmdlist pointer in the bind-key to NULL to prevent it being freed
after the command is executing is bogus because it may still be needed if the
same command is going to be executed again (for example if you "bind-key a
bind-key b ..."). Making a copy is hard, so instead add a reference count to
the cmd_list.

While here, also print bind-key -n and the rest of the flags properly.

Fixes problem reported by mcbride@.


# 1.79 14-May-2010 nicm

Colour+attribute options for status line alerts, from Alex Alexander.


# 1.78 04-May-2010 nicm

Put this back in with the initialisation in the right order.


# 1.77 04-May-2010 nicm

Revert last change, it appears to be broken somehow.


# 1.76 03-May-2010 nicm

Make signal handler setup/teardown two common functions instead of six,
and reset SIGCHLD after fork to fix problems with some shells. From
Romain Francois.


# 1.75 28-Apr-2010 nicm

Make the active pane border have a green foreground instead of
background by default.


# 1.74 18-Apr-2010 nicm

Catch SIGCHLD to avoid a zombie, from patrick keshishian.


Revision tags: OPENBSD_4_7_BASE
# 1.73 22-Feb-2010 nicm

Option to set the characters considered word separators in copy mode, from
Micah Cowan.


# 1.72 08-Feb-2010 nicm

Add an option to disable the smcup/rmcup alternate screen behaviour inside
tmux. From clemens fischer.


# 1.71 06-Feb-2010 nicm

Change nested check to compare server socket path rather than just assuming
that if $TMUX is set it is nested. From Micah Cowan.


# 1.70 06-Feb-2010 nicm

Clean up $TMUX parsing, from Micah Cowan, tweaked by me.


# 1.69 06-Feb-2010 nicm

Instead of bailing out on the first configuration file error, carry on,
collecting all the errors, then start with the active window in more mode
displaying them.


# 1.68 04-Feb-2010 nicm

Read the path from $TMUX if it is present and -L and -S are not given. Based on
a diff from Micah Cowan.


# 1.67 04-Feb-2010 nicm

Option to display the active pane in a different colour with the display-panes
command. From Paul Hoffman, thanks.


# 1.66 03-Jan-2010 nicm

Options to set the colour of the pane borders, with different colours for the
active pane.


# 1.65 14-Dec-2009 nicm

New server option, escape-time, to set the timeout used to detect if escapes
are alone or part of a function key or meta sequence.


# 1.64 11-Dec-2009 nicm

Use quiet variable, and add missing sentinel to options array.


# 1.63 10-Dec-2009 nicm

Add "server options" which are server-wide and not bound to a session or
window. Set and displayed with "set -s" and "show -s".

Currently the only option is "quiet" (like command-line -q, allowing it to be
set from .tmux.conf), but others will come along.


# 1.62 03-Dec-2009 nicm

Massive spaces->tabs and trailing whitespace cleanup, hopefully for the last
time now I've configured emacs to make them displayed in really annoying
colours...


# 1.61 26-Nov-2009 nicm

Remove a couple of unused arguments where possible, and add /* ARGSUSED */ to
the rest to reduce lint output.


# 1.60 19-Nov-2009 nicm

Two new options, window-status-format and window-status-current-format, which
allow the format of each window in the status line window list to be controlled
using similar # sequences as status-left/right.

This diff also moves part of the way towards UTF-8 support in window names but
it isn't quite there yet.


# 1.59 19-Nov-2009 nicm

Revert to xterm-keys off by default. It was on as an experiment to see if the
option could be removed, but it affects vi, so we have to keep the option, and
a conservative default is better.


# 1.58 18-Nov-2009 nicm

Add a per-client log of status line messages displayed while that client
exists. A new message-limit session option sets the maximum number of entries
and a command, show-messages, shows the log (bound to ~ by default).

This (and prompt history) might be better as a single global log but until
there are global options it is easier for them to be per client.


# 1.57 10-Nov-2009 nicm

There is no real standard for modifier plus function keys. Previously, tmux
output some from rxvt but in other ways did the same as xterm or other
terminals, but this is a bit inconsistent.

xterm's method is fairly sensible and we already support it (xterm-keys), so
enable it by default instead.


# 1.56 04-Nov-2009 nicm

A couple of minor cosmetic changes.


# 1.55 04-Nov-2009 nicm

Initial changes to move tmux to libevent.

This moves the client-side loops are pretty much fully over to event-based only
(tmux.c and client.c) but server-side (server.c and friends) treats libevent as
a sort of clever poll, waking up after every event to run various things.

Moving the server stuff over to bufferevents and timers and so on will come
later.


# 1.54 04-Nov-2009 nicm

Change declaration and use of malloc_options to be more standard, from Tim van
der Molen.


# 1.53 26-Oct-2009 deraadt

tabs are better; ok nicm


# 1.52 25-Oct-2009 nicm

Remove the -d flag to tmux and just use op/AX to detect default colours.

Irritatingly, although op can be used to tell if a terminal supports default
colours, it can't be used to set them because in some terminfo descriptions it
resets attributes as a side-effect (acts as sgr0) and in others it doesn't, so
it is not possible to determine reliably what the terminal state will be
afterwards. So if AX is missing and op is present, tmux just sends sgr0.

Anyone using -d for a terminal who finds they actually needed it can replace it
using terminal-overrides, but please let me know as it is probably an omission
from terminfo.


# 1.51 22-Oct-2009 nicm

Merge prepare_cmd into main as it is short and only called once.


# 1.50 21-Oct-2009 nicm

Client tidying: get rid of client_ctx struct in favour of two variables in
client.c, and move the functions in client-fn.c into other files.


# 1.49 10-Oct-2009 nicm

New option, mouse-select-pane. If on, the mouse may be used to select the
current pane.

Suggested by sthen@ and also by someone else ages ago who I have forgotten.


# 1.48 10-Oct-2009 nicm

Support for individual session idle time locking. May be enabled by turning off
the lock-server option (it is on by default). When this is off, each session
locks when it has been idle for the lock-after-time setting. When on, the
entire server locks when ALL sessions have been idle for their individual
lock-after-time settings.

This replaces one global-only option (lock-after-time) with another
(lock-server), but the default behaviour is usually preferable so there don't
seem to be many alternatives.

Diff/idea largely from Thomas Adam, tweaked by me.


# 1.47 09-Oct-2009 nicm

Add a simple synchronize-panes window option: when set, all input to any pane
that is part of the window is also sent to all other panes in the same
window. Suggested by several, most recently Tomasz Pajor.


# 1.46 23-Sep-2009 nicm

Support -c like sh(1) to execute a command, useful when tmux is a login
shell. Suggested by halex@.

This includes another protocol version increase (the last for now) so again
restart the tmux server before upgrading.


# 1.45 23-Sep-2009 nicm

Remove the internal tmux locking and instead detach each client and run the
command specified by a new option "lock-command" (by default "lock -np") in
each client.

This means each terminal has to be unlocked individually but simplifies the
code and allows the system password to be used to unlock.

Note that the set-password command is gone, so it will need to be removed from
configuration files, and the -U command line flag has been removed.

This is the third protocol version change so again it is best to stop the tmux
server before upgrading.


# 1.44 22-Sep-2009 nicm

Permit multiple prefix keys to be defined, separated by commas, for example:

set -g prefix ^a,^b

Any key in the list acts as the prefix. The send-prefix command always sends
the first key in the list.


# 1.43 18-Sep-2009 nicm

New option, set-titles-string, to allow the window title to be specified (as
for status-left/right) if set-titles is on. Also only update the title when the
status line is being redrawn.


# 1.42 04-Sep-2009 nicm

Tidy main and make it a bit easier to read.


# 1.41 02-Sep-2009 nicm

Accept -l to make it easier for people who use tmux as a login shell to use
$SHELL. Originally from martynas@, tweaked by me.


# 1.40 02-Sep-2009 nicm

When incorrect passwords are entered, behave similarly to login(1) and backoff
for a bit. Based on a diff from martynas@.


# 1.39 01-Sep-2009 nicm

When using tmux as a login shell, there is currently no way to specify a shell
to be used as a login shell inside tmux, so add a default-shell session option.
This sets the shell invoked as a login shell when the default-command option is
empty.

The default option value is whichever of $SHELL, getpwuid(getuid())'s pw_shell
or /bin/sh is valid first.

Based on a diff from martynas@, changed by me to be a session option rather
than a window option.


# 1.38 01-Sep-2009 nicm

Use "Password:" with no space for password prompts and don't display a *s for
the password, like pretty much everything else. From martynas@ with minor
tweaks by me.


# 1.37 01-Sep-2009 nicm

Sort cases same as getopt argument, from martynas.


# 1.36 31-Aug-2009 nicm

Add a new display-panes command, with two options (display-panes-colour and
display-panes-time), which displays a visual indication of the number of each
pane.


# 1.35 23-Aug-2009 nicm

Add some other obvious variables to update-environment (WINDOWID SSH_ASKPASS
SSH_AUTH_SOCK SSH_AGENT_PID SSH_CONNECTION) so they are updated in the session
environment on new/attach.


# 1.34 13-Aug-2009 nicm

Disable mode-mouse (mouse in copy/choice mode) by default as it isn't very
useful at the moment and causes confusion.


# 1.33 13-Aug-2009 nicm

Add a base-index session option to specify the first index checked when looking
for an index for a new window.


# 1.32 12-Aug-2009 nicm

When started as the shell, __progname contains a leading -, so hardcode "tmux"
for socket path and log files, and strip it when working out the shell.


# 1.31 11-Aug-2009 nicm

Switch tmux to use imsg. This is the last major change to make the
client-server protocol more resilient and make the protocol versioning work
properly. In future, the only things requiring a protocol version bump will be
changes in the message structs, and (when both client and server have this
change) mixing different versions should nicely report an error message.

As a side effect this also makes the code tidier, fixes a problem with the way
errors reported during server startup were handled, and supports fd passing
(which will be used in future).

Looked over by eric@, thanks.

Please note that mixing a client with this change with an older server or vice
versa may cause tmux to crash or hang - tmux should be completely exited before
upgrading.


# 1.30 10-Aug-2009 nicm

No arguments are the same as new-session and this requires the environment to
be sent, so set that flag too when argc == 0.


# 1.29 08-Aug-2009 nicm

Infrastructure and commands to manage the environment for processes started
within tmux.

There is a global environment, copied from the external environment when the
server is started and each sesssion has an (initially empty) session
environment which overrides it.

New commands set-environment and show-environment manipulate or display the
environments.

A new session option, update-environment, is a space-separated list of
variables which are updated from the external environment into the session
environment every time a new session is created - the default is DISPLAY.


# 1.28 08-Aug-2009 nicm

Options to set the colours and attributes for status-left/-right. From Thomas
Adam, thanks.


# 1.27 05-Aug-2009 nicm

If colours are not supported by the terminal, try to emulate a coloured
background by setting or clearing the reverse attribute.

This makes a few applications which don't use the reverse attribute themselves
a little happier, and allows the status, message and mode options to have
default attributes and fg/bg options that work as expected when set as reverse.


# 1.26 04-Aug-2009 nicm

Check for "UTF8" as well as "UTF-8" in LANG etc as it seems this may also
appear.


# 1.25 03-Aug-2009 nicm

Add a terminal-overrides session option allowing individual terminfo(5) entries
to be overridden. The 88col/256col checks are now moved into the default
setting and out of the code.

Also remove a couple of old workarounds for xterm and rxvt which are no longer
necessary (tmux can emulate them if missing).


# 1.24 30-Jul-2009 nicm

Add a mode-mouse option to prevent tmux taking over the mouse in choice or copy
modes.


# 1.23 29-Jul-2009 nicm

Rename struct hdrtype to msgtype which is a better name and can be used even
when struct hdr disappears.


# 1.22 29-Jul-2009 nicm

Taking account of the "s, 22 not 24 is the maximum length of #T in status-right
to prevent the date being cut off.


# 1.21 26-Jul-2009 nicm

Make all messages sent between the client and server fixed size.

This is the first of two changes to make the protocol more resilient and less
sensitive to other changes in the code, particularly with commands. The client
now packs argv into a buffer and sends it to the server for parsing, rather
than doing it itself and sending the parsed command data.

As a side-effect this also removes a lot of now-unused command marshalling
code.

Mixing a server without this change and a client with or vice versa will cause
tmux to hang or crash, please ensure that tmux is entirely killed before
upgrading.


# 1.20 22-Jul-2009 nicm

Pass a set of flags into client_init rather than just a start_server
variable. Only one flag now but more to come later.


# 1.19 20-Jul-2009 nicm

Display the number of failed password attempts (if any) when the server is
locked. From Tom Doherty.


# 1.18 20-Jul-2009 nicm

Add a status-justify option to allow the window list in the status line to be
positioned at the left, centre, or right.


# 1.17 20-Jul-2009 nicm

New options, window-status-current-{fg,bg,attr}, to set the fg, bg and
attributes with which the current window is shown in the status line. From
Johan Friis, thanks.


# 1.16 18-Jul-2009 nicm

Add three new session options: visual-activity, visual-bell, visual-content. If
these are enabled (and the monitor-activity, bell-actio and monitor-content
options are configurated appropriately), when activity, a bell, or content is
detected, a message is shown.

Also tidy up the bell/activity/content code in server.c slightly and fix a
couple of errors.


# 1.15 17-Jul-2009 nicm

If -u is specified or UTF-8 is otherwise detected when the server is started,
enable the utf8 and status-utf8 optons. While here, note in the man page that
the server is started with the first session and exits when none remain.


# 1.14 10-Jul-2009 nicm

Add a default-terminal option to set the starting value of $TERM in new
windows.

This is "screen" by default and must be either that or something closely
related. This does makes it easier to customise it if necessary.


# 1.13 08-Jul-2009 nicm

Just appending -l to $SHELL to create a login shell is wrong: -l is not POSIX,
and some people may use shells which do not support it. Instead, make an empty
default-command option mean a login shell, and fork it with a - in argv[0]
which is the method used by login(1).

Also fix the automatic-rename code to handle this correctly and to strip a
leading - if present.


# 1.12 07-Jul-2009 nicm

Rename the global options variables to be shorter and to make session options
clear. No functional change, getting this out of the way to make later options
changes easier.


Revision tags: OPENBSD_4_6_BASE
# 1.11 25-Jun-2009 nicm

If getcwd() fails, use the user's home directory, or /, instead of failing with
an error.


# 1.10 25-Jun-2009 nicm

Remove error about using -L and -S together which was never displayed as
logging wasn't yet enabled, was unnecessary, and contradicted the man page
which says using -S will cause -L to be ignored.


# 1.9 23-Jun-2009 nicm

LC_ALL overrides LC_CTYPE and LANG. Comment was correct but the code
wrong. Pointed out by Hannah Schroeter, thanks.


# 1.8 05-Jun-2009 nicm

Check the first of LC_CTYPE, LC_ALL and LANG, rather than just the last, when
trying to decide about UTF-8, and use strcasestr. Reported by Geert Hendrickx.


# 1.7 04-Jun-2009 nicm

Zero the password given to -U in the client as well.


# 1.6 03-Jun-2009 nicm

Do not set the window title by default (make set-titles option default to off),
wiping over the title is rude and annoying. Agreed by several.


# 1.5 03-Jun-2009 nicm

New session option, status-utf8, to control the interpretation of top-bit-set
characters in status-left and status-right (if on, they are treated as UTF-8;
otherwise passed through).


# 1.4 02-Jun-2009 sobrado

remove unused flag; while here, make usage's output fit on 80-column displays.


# 1.3 02-Jun-2009 pyr

spawn login shells by default, adapt manpage bits as well.
ok nicm@


# 1.2 02-Jun-2009 ray

Don't leak memory if multiple -f flags are given.

OK nicm@


# 1.1 01-Jun-2009 nicm

Import tmux, a terminal multiplexor allowing (among other things) a single
terminal to be switched between several different windows and programs
displayed on one terminal be detached from one terminal and moved to another.

ok deraadt pirofti


# 1.197 16-Apr-2020 nicm

Show signal name when process exits rather than number.


# 1.196 09-Apr-2020 nicm

More style nits.


# 1.195 31-Mar-2020 nicm

Add a way to mark environment variables as "hidden" so they can be used
by tmux but are not passed into the environment of new panes.


# 1.194 17-Mar-2020 nicm

Ignore default-shell (and use /bin/sh) if it invalid not just if it is
tmux itself, also refuse to set the option to something invalid in the
first place. GitHub issue 2120.


# 1.193 12-Mar-2020 nicm

When the server socket is given by the user with -S, create it with
umask 177 instead of 117 because it may not be in a safe directory like
the default directory in /tmp. The user can chmod it more open after it
is created if they want.


# 1.192 28-Jan-2020 nicm

-V also needs to go in usage.


# 1.191 28-Jan-2020 nicm

Reduce a difference with portable tmux by adding the -V flag and
#{version} format; on OpenBSD these just report the OpenBSD version.


# 1.190 14-Oct-2019 nicm

Memory leaks, from Igor Wong in GitHub issue 1934.


Revision tags: OPENBSD_6_6_BASE
# 1.189 20-Jun-2019 nicm

Add a per-pane option set. Pane options inherit from window options (so
there should be no change to existing behaviour) and are set and shown
with set-option -p and show-options -p.

Change remain-on-exit and window-style/window-active-style to be pane
options (some others will be changed later).

This makes select-pane -P and -g unnecessary so no longer document them
(they still work) and no longer document set-window-option and
show-window-options in favour of set-option -w and show-options -w.


# 1.188 26-Apr-2019 nicm

Merge hooks into options and make each one an array option. This allows
multiple commands to be easily bound to one hook. set-hook and
show-hooks remain but they are now variants of set-option and
show-options. show-options now has a -H flag to show hooks (by default
they are not shown).


Revision tags: OPENBSD_6_5_BASE
# 1.187 22-Nov-2018 nicm

Do not use PWD unless it actually matches the real working directory.


Revision tags: OPENBSD_6_3_BASE OPENBSD_6_4_BASE
# 1.186 12-Jan-2018 nicm

Improve error message if creating socket parent directory fails, from
Thomas Adam for GitHub issue 1215.


# 1.185 01-Jan-2018 nicm

Prefer PWD for current directory if present in client, from Wei Zhao in
GitHub issue 1183.


Revision tags: OPENBSD_6_2_BASE
# 1.184 12-Jul-2017 nicm

Make shell_command a global like other stuff rather than making it an
exception and using callback argument.


# 1.183 03-Jul-2017 nicm

Try C.UTF-8 which is also a commonly useful locale on some platforms,
from Romain Francoise.


# 1.182 22-Apr-2017 nicm

Do not need getopt.h.


# 1.181 20-Apr-2017 nicm

Use fdforkpty() instead of our own unwrapped versions.


# 1.180 19-Apr-2017 nicm

Style nits and a missing cast.


# 1.179 16-Apr-2017 nicm

Memory leak, from David CARLIER.


Revision tags: OPENBSD_6_1_BASE
# 1.178 21-Mar-2017 nicm

Use uid_t for UID not u_int.


# 1.177 16-Feb-2017 nicm

Style nits.


# 1.176 23-Jan-2017 nicm

Open /dev/ptm before pledge() and save it to be used for PTMGET later
(this means inlining forkpty()).

ok deraadt


# 1.175 15-Jan-2017 nicm

Major tidy up and rework of options tree and set-option/show-options
commands this pushes more of the code into options.c and ties it more
closely to the options table rather than having an unnecessary
split. Also add support for array options (will be used later). Only
(intentional) user visible change is that show-options output is now
passed through vis(3) with VIS_DQ so quotes are escaped.


# 1.174 12-Jan-2017 nicm

Simplify appending to string options.


# 1.173 09-Dec-2016 nicm

Spacing nits.


# 1.172 11-Oct-2016 nicm

Add static in window-*.c and move some internal functions out of tmux.h.


# 1.171 10-Oct-2016 nicm

Loads more static, except for cmd-*.c and window-*.c.


Revision tags: OPENBSD_6_0_BASE
# 1.170 27-May-2016 nicm

Use getprogname() instead of __progname to make portability easier.


# 1.169 04-May-2016 nicm

Fix up a couple of long lines.


# 1.168 05-Mar-2016 nicm

If setlocale("en_US.UTF-8") succeeds, then don't do the check for UTF-8
locale since if it isn't UTF-8 the system is broken anyway. If it fails,
try "" and check for UTF-8 with nl_langinfo(CODESET) rather than
wcwidth(). Based on a diff from schwarze@, nl_langinfo also suggested by
stsp@.


# 1.167 05-Mar-2016 nicm

Although we always have en_US.UTF-8 on OpenBSD, some platforms do not,
so fall back to setlocale(LC_CTYPE, ""). tmux requires a UTF-8 locale,
so check with wcwidth() on a UTF-8 character after setlocale().


# 1.166 01-Mar-2016 nicm

Remove unused variables, from Michal Mazurek.


# 1.165 01-Mar-2016 nicm

Use system wcwidth() instead of carrying around UTF-8 width tables.


Revision tags: OPENBSD_5_9_BASE
# 1.164 19-Jan-2016 nicm

I no longer use my SourceForge address so replace it.


# 1.163 08-Dec-2015 nicm

Add hooks infrastructure, basic commands (set-hook, show-hooks) and a
couple of not very useful client hooks. This will eventually let
commands be run at various points and on notifications. Joint work with
Thomas Adam.


# 1.162 24-Nov-2015 nicm

Make environ_set va_args and use it to tidy up some calls. Also add a
missing word in manpage (from jmc).


# 1.161 24-Nov-2015 nicm

Shell command from -c doesn't have to be global, pass it as an argument.


# 1.160 24-Nov-2015 nicm

Tidy the code that works out the socket path, and just use the full path
in the global socket_path rather than copying it.


# 1.159 24-Nov-2015 nicm

Remove malloc_options DEBUG bit.


# 1.158 24-Nov-2015 nicm

Remove the -I part of show-messages which isn't really that useful; the
server start time can now be accessed with a new start_time format (use:
tmux display -p '#{t:start_time}')


# 1.157 24-Nov-2015 nicm

Make the log stuff a bit tidier with some helper functions.


# 1.156 22-Nov-2015 nicm

Add getpw to pledge, makes tmux work in YP environments, discovered by
matthieu, ok deraadt


# 1.155 20-Nov-2015 nicm

Instead of separate tables for different types of options, give each
option a scope type (server, session, window) in one table.


# 1.154 15-Nov-2015 nicm

Accidentally turned off pledge, turn it back on.


# 1.153 14-Nov-2015 nicm

Push stdout and stderr to clients more aggressively, and add an event to
continue if the send fails.


# 1.152 12-Nov-2015 nicm

tmux is UTF-8, so if $TMUX is set (tmux running in tmux), the client is
UTF-8. Also try to make the existing checks more readable.


# 1.151 12-Nov-2015 nicm

Nuke the utf8 and status-utf8 options and make tmux only a UTF-8
terminal. We still support non-UTF-8 terminals outside tmux, but inside
it is always UTF-8 (as when the utf8 and status-utf8 options were on).


# 1.150 11-Nov-2015 nicm

Drop mouse-utf8 option and always turn on UTF-8 mouse if the client says
it supports UTF-8.


# 1.149 28-Oct-2015 nicm

Like options, move the environ struct into environ.c.


# 1.148 27-Oct-2015 nicm

Move struct options into options.c.


# 1.147 27-Oct-2015 nicm

Break the common process set up, event loop and imsg dispatch code
between server and client out into a separate internal API. This will
make it easier to add another process.


# 1.146 25-Oct-2015 deraadt

Let's see if anyone screams about not being able to specify $TMPDIR
for their tmux sockets.

(Over the years, I have seen $TMPDIR set up worse than /tmp many times,
and don't know how this practice infected other parts of the system.
Nothing uses tmpdir(3), nor a huge-temporary-file program like sort.)
ok nicm


# 1.145 23-Oct-2015 nicm

tmux can call pledge() in main with large set and then reduce it
slightly in the server to "stdio rpath wpath cpath fattr unix recvfd
proc exec tty ps".


# 1.144 14-Sep-2015 nicm

Move tzset() from log_open to main.


# 1.143 03-Sep-2015 nicm

A couple of style nits.


# 1.142 01-Sep-2015 nicm

Work out config file when needed not at startup.


# 1.141 30-Aug-2015 nicm

Path from $TMUX does not need to be global anymore.


# 1.140 30-Aug-2015 nicm

Login shell can be a client flag, and move the exec code into client.c.


# 1.139 30-Aug-2015 nicm

Event base does not need to be global.


# 1.138 30-Aug-2015 nicm

Some style nits and dead assignments.


Revision tags: OPENBSD_5_8_BASE
# 1.137 20-Jul-2015 nicm

Add an option (history-file) for a file to save/restore command prompt
history, from Olof-Joachim Frahm.


# 1.136 04-Jun-2015 jmc

tweak SYNOPSIS and usage();


Revision tags: OPENBSD_5_7_BASE
# 1.135 19-Jan-2015 nicm

Make a tmux-%u directory under TMUX_TMPDIR, like TMPDIR.


# 1.134 19-Jan-2015 nicm

Only care about other permissions, allow group to be set.


# 1.133 19-Jan-2015 nicm

Remove unnecessary duplicate S_ISDIR check, from Dmitri Paduchikh.


# 1.132 20-Oct-2014 nicm

Tidy up some includes.


Revision tags: OPENBSD_5_6_BASE
# 1.131 17-Apr-2014 nicm

Remove the "info" message mechanism, this was only used for about five
mostly useless and annoying messages. Change those commands to silence
on success like all the others. Still accept the -q command line flag
and "quiet" server option for now.


# 1.130 31-Mar-2014 nicm

Remove log_debug2 as well and simplify log.c.


Revision tags: OPENBSD_5_5_BASE
# 1.129 16-Feb-2014 nicm

Leftovers from removing 88 colour support, from Theo Buehler.


# 1.128 15-Jan-2014 nicm

Do not attempt to read .tmux.conf if we can't figure out a home
directory, from Tiago Cunha.


# 1.127 09-Jan-2014 nicm

Three small changes from Tiago Cunha:

- Check for truncation when copying path.
- Don't need to use a temporary buffer in screen_set_title.
- Include strerror in output when connecting to server fails.


# 1.126 10-Oct-2013 nicm

We accidentally haven't been using $TMUX to work out the session for a
while and in fact it is less useful that using the client ttyname. So
don't bother and don't pass it from the client. If we need it in future
it is in c->environ.


# 1.125 10-Oct-2013 nicm

Alter how tmux handles the working directory to internally use file
descriptors rather than strings.

- Each session still has a current working directory.

- New sessions still get their working directory from the client that
created them or its attached session if any.

- New windows are created by default in the session working directory.

- The -c flag to new, neww, splitw allows the working directory to be
overridden.

- The -c flag to attach let's the session working directory be changed.

- The default-path option has been removed.

To get the equivalent to default-path '.', do:

bind c neww -c $PWD

To get the equivalent of default-path '~', do:

bind c neww -c ~

This also changes the client identify protocol to be a set of messages rather
than one as well as some other changes that should make it easier to make
backwards-compatible protocol changes in future.


# 1.124 10-Oct-2013 nicm

Merge IDENTIFY_* flags with CLIENT_* flags.


# 1.123 10-Oct-2013 nicm

Don't treat TMUX_TMPDIR as a potential file

The point of setting TMUX_TMPDIR is to then make any labels from -L go
to that directory. In the case of makesocketpath() with no TMUX_TMPDIR
set, would set both the path and the default socket to a file. The
checking of the permissions on the file worked fine in that case, but
when TMUX_TMPDIR is set, won't work on a directory.

This fixes the problem by ensuring the check on the permissions is
performed on directories only.

By Thomas Adam.


# 1.122 05-Oct-2013 nicm

Fix previous not to leak fd on failure, whoops.


# 1.121 05-Oct-2013 nicm

Use open(".")/fchdir() to save and restore current directory rather than
getcwd()/chdir().


Revision tags: OPENBSD_5_4_BASE
# 1.120 24-Apr-2013 nicm

Rename global configuration define.


# 1.119 11-Apr-2013 nicm

Call setlocale(LC_TIME) at startup.


# 1.118 27-Mar-2013 nicm

Add TMUX_TMPDIR variable to put the socket directory outside
TMPDIR. From Ben Boeckel.


# 1.117 27-Mar-2013 nicm

Remove tmux's (already minimal) 88 colour support. Such terminals are
few and unnecessary.


# 1.116 25-Mar-2013 nicm

Rename session idx to session id throughout and add $ prefix to targets
to use it, extended from a diff from George Nachman.


# 1.115 24-Mar-2013 nicm

Add a command queue to standardize and simplify commands that call other
commands and allow a command to block execution of subsequent
commands. This allows run-shell and if-shell to be synchronous which has
been much requested.

Each client has a default command queue and commands are consumed one at
a time from it. A command may suspend execution from the queue by
returning CMD_RETURN_WAIT and then resume it by calling cmd_continue() -
for example run-shell does this from the callback that is fired after
the job is freed.

When the command queue becomes empty, command clients are automatically
exited (unless attaching). A callback is also fired - this is used for
nested commands in, for example, if-shell which can block execution of
the client's cmdq until a new cmdq becomes empty.

Also merge all the old error/info/print functions together and lose the
old curclient/cmdclient distinction - a cmdq is bound to one client (or
none if in the configuration file), this is a command client if
c->session is NULL otherwise an attached client.


Revision tags: OPENBSD_5_3_BASE
# 1.114 27-Nov-2012 nicm

Correctly aggregate together errors from nested config files (with
source-file). Fix by Thomas Adam, reported by Sam Livingstone-Gray


# 1.113 26-Nov-2012 nicm

Call realpath earlier on the socket directory path rather than on the
socket file path because the latter may not exist yet and in that case
realpath is allowed to fail. From Romain Francoise.


Revision tags: OPENBSD_5_2_BASE
# 1.112 10-Jul-2012 nicm

xfree is not particularly helpful, remove it. From Thomas Adam.


# 1.111 18-Jun-2012 nicm

Add a skeleton mode to tmux (called "control mode") that let's tmux
commands be sent and output received on stdout. This can be used to
integrate with other terminal emulators and should allow some other
things to be made simpler later. More to come so doesn't do much yet and
deliberately not documented.


# 1.110 30-May-2012 nicm

Do not use stderr for log file and don't call log_close when not needed.


# 1.109 25-May-2012 nicm

Simplify logging and just fprintf(stderr, ...) for early errors.


Revision tags: OPENBSD_5_1_BASE
# 1.108 21-Jan-2012 nicm

Drop the ability to have a list of keys in the prefix in favour of two
separate options, prefix and prefix2. This simplifies the code and gets
rid the data options type which was only used for this one option.

Also add a -2 flag to send-prefix to send the secondary prefix key,
fixing a cause of minor irritation.

People who want three prefix keys are out of luck :-).


# 1.107 23-Oct-2011 nicm

Try to resolve relative paths for loadb and saveb (first using client
working directory if any then default-path or session wd).


# 1.106 23-Oct-2011 nicm

Ignore LC_ALL and LC_CTYPE if they are empty as well as unset.


# 1.105 25-Sep-2011 nicm

Reject $SHELL if it is not a full path.


Revision tags: OPENBSD_5_0_BASE
# 1.104 04-Mar-2011 nicm

Two fixes by Micah Cowan: make mouse work properly beyond >127 on signed
char architectures and properly parse $TMUX by stopping the socket path
at the first comma.


Revision tags: OPENBSD_4_9_BASE
# 1.103 23-Jan-2011 nicm

Set $TMUX without the session when background jobs are run.


# 1.102 12-Jan-2011 nicm

Use TMPDIR if set, from Han Boetes.


# 1.101 08-Jan-2011 nicm

Move all calls to fcntl(...O_NONBLOCK) into a function and clear the
flag on the stdio file descriptors before closing them (fixes things
like "tmux ls && cat").


# 1.100 03-Jan-2011 nicm

Support for UTF-8 mouse input (\033[1005h). This was added in xterm 262
and supports larger terminals than the older way.

If the new mouse-utf8 option is on, UTF-8 mouse input is enabled for all
UTF-8 terminals. The option defaults to on if LANG etc are set in the
same manner as the utf8 option.

With help and based on code from hsim at gmx.li.


# 1.99 01-Jan-2011 nicm

Move the user-visible parts of all options (names, types, limit, default
values) together into one set of tables in options-table.c. Also clean
up and simplify cmd-set-options.c and move a common print function into
option-table.c.


# 1.98 30-Dec-2010 nicm

Change from a per-session stack of buffers to one global stack which is
much more convenient and also simplifies lot of code. This renders
copy-buffer useless and makes buffer-limit now a server option.

By Tiago Cunha.


# 1.97 19-Dec-2010 nicm

Add other-pane-height and other-pane-width options, allowing the width
or height of the smaller panes in the main-horizontal and main-vertical
layouts to be set. Mostly from David Goodlad.


# 1.96 08-Dec-2010 nicm

In the built-in layouts, distribute the panes more evenly. Set the
default value of main-pane-width to 80, rather than 81. By Micah Cowan.


# 1.95 06-Dec-2010 nicm

Add an option to alert (monitor) for silence (lack of activity) in a
window. From Thomas Adam.


# 1.94 29-Nov-2010 nicm

If VISUAL or EDITOR contains "vi", configure mode-keys and status-keys
to vi.

Based on a diff from martynas@, previously requested by a couple of
other people.


# 1.93 11-Nov-2010 nicm

Add XAUTHORITY to update-environment, requested by Andreas Kloeckner.


# 1.92 18-Oct-2010 nicm

Merge the before and after attach client code into one in client.c
(instead of two in tmux.c and client.c).


# 1.91 16-Oct-2010 nicm

Make stdio blocking again before calling shell command with -c.


# 1.90 16-Oct-2010 nicm

Trying to set FD_CLOEXEC on every fd is a lost cause, just use
closefrom() before exec.


# 1.89 14-Oct-2010 nicm

Use an explicit event rather than event_once for the main event so it
can be removed when the client becomes ready.


# 1.88 26-Sep-2010 nicm

Two new options:

- server option "exit-unattached" makes the server exit when no clients
are attached, even if sessions are present;

- session option "destroy-unattached" destroys a session once no clients
are attached to it.

These are useful for preventing tmux remaining in the background where
it is undesirable and when using tmux as a login shell to keep a limit
on new sessions.


# 1.87 19-Aug-2010 nicm

Do not call event_del() for signals after fork(), just use sigaction()
directly instead - calling libevent functions after fork() w/o
event_reinit() is a bad idea, even if in this case it was harmless.


Revision tags: OPENBSD_4_8_BASE
# 1.86 04-Aug-2010 deraadt

switch back to kqueue for now, since (a) kqueue has been fixed to deal
with strange devices and (b) since there appears to be a bull in the
poll code in libevent as well...
requested by nicm who is away


# 1.85 24-Jul-2010 nicm

kqueue(2) is currently broken when used with /dev/null and a few other
devices.

An upcoming fix for some problems with the client stdout/stderr handling
relies on it working, so make tmux force libevent to use poll(2) via
EVENT_NOKQUEUE, until we have fixed kqueue.


# 1.84 11-Jul-2010 nicm

Return the command client return code with MSG_EXIT now that MSG_ERROR and
MSG_PRINT are unused.

New clients should be compatible with old tmux servers but vice versa may print
an error.


# 1.83 28-Jun-2010 nicm

Send all three of stdin, stdout, stderr from the client to the server, so that
commands can directly make use of them. This means that load-buffer and
save-buffer can have "-" as the file to read from stdin or write to stdout.

This is a protocol version bump so the tmux server will need to be restarted
after upgrade (or an older client used).


# 1.82 27-Jun-2010 nicm

Store the current working directory in the session, change the default-path
option to default to empty and make that mean that the stored session CWD is
used.


# 1.81 27-Jun-2010 nicm

New option, detach-on-destroy, to set what happens to a client when the session
it is attached to is destroyed. If on (the default), it is detached; if off, it
is switched to the most recently active session.


# 1.80 26-Jun-2010 nicm

Setting the cmdlist pointer in the bind-key to NULL to prevent it being freed
after the command is executing is bogus because it may still be needed if the
same command is going to be executed again (for example if you "bind-key a
bind-key b ..."). Making a copy is hard, so instead add a reference count to
the cmd_list.

While here, also print bind-key -n and the rest of the flags properly.

Fixes problem reported by mcbride@.


# 1.79 14-May-2010 nicm

Colour+attribute options for status line alerts, from Alex Alexander.


# 1.78 04-May-2010 nicm

Put this back in with the initialisation in the right order.


# 1.77 04-May-2010 nicm

Revert last change, it appears to be broken somehow.


# 1.76 03-May-2010 nicm

Make signal handler setup/teardown two common functions instead of six,
and reset SIGCHLD after fork to fix problems with some shells. From
Romain Francois.


# 1.75 28-Apr-2010 nicm

Make the active pane border have a green foreground instead of
background by default.


# 1.74 18-Apr-2010 nicm

Catch SIGCHLD to avoid a zombie, from patrick keshishian.


Revision tags: OPENBSD_4_7_BASE
# 1.73 22-Feb-2010 nicm

Option to set the characters considered word separators in copy mode, from
Micah Cowan.


# 1.72 08-Feb-2010 nicm

Add an option to disable the smcup/rmcup alternate screen behaviour inside
tmux. From clemens fischer.


# 1.71 06-Feb-2010 nicm

Change nested check to compare server socket path rather than just assuming
that if $TMUX is set it is nested. From Micah Cowan.


# 1.70 06-Feb-2010 nicm

Clean up $TMUX parsing, from Micah Cowan, tweaked by me.


# 1.69 06-Feb-2010 nicm

Instead of bailing out on the first configuration file error, carry on,
collecting all the errors, then start with the active window in more mode
displaying them.


# 1.68 04-Feb-2010 nicm

Read the path from $TMUX if it is present and -L and -S are not given. Based on
a diff from Micah Cowan.


# 1.67 04-Feb-2010 nicm

Option to display the active pane in a different colour with the display-panes
command. From Paul Hoffman, thanks.


# 1.66 03-Jan-2010 nicm

Options to set the colour of the pane borders, with different colours for the
active pane.


# 1.65 14-Dec-2009 nicm

New server option, escape-time, to set the timeout used to detect if escapes
are alone or part of a function key or meta sequence.


# 1.64 11-Dec-2009 nicm

Use quiet variable, and add missing sentinel to options array.


# 1.63 10-Dec-2009 nicm

Add "server options" which are server-wide and not bound to a session or
window. Set and displayed with "set -s" and "show -s".

Currently the only option is "quiet" (like command-line -q, allowing it to be
set from .tmux.conf), but others will come along.


# 1.62 03-Dec-2009 nicm

Massive spaces->tabs and trailing whitespace cleanup, hopefully for the last
time now I've configured emacs to make them displayed in really annoying
colours...


# 1.61 26-Nov-2009 nicm

Remove a couple of unused arguments where possible, and add /* ARGSUSED */ to
the rest to reduce lint output.


# 1.60 19-Nov-2009 nicm

Two new options, window-status-format and window-status-current-format, which
allow the format of each window in the status line window list to be controlled
using similar # sequences as status-left/right.

This diff also moves part of the way towards UTF-8 support in window names but
it isn't quite there yet.


# 1.59 19-Nov-2009 nicm

Revert to xterm-keys off by default. It was on as an experiment to see if the
option could be removed, but it affects vi, so we have to keep the option, and
a conservative default is better.


# 1.58 18-Nov-2009 nicm

Add a per-client log of status line messages displayed while that client
exists. A new message-limit session option sets the maximum number of entries
and a command, show-messages, shows the log (bound to ~ by default).

This (and prompt history) might be better as a single global log but until
there are global options it is easier for them to be per client.


# 1.57 10-Nov-2009 nicm

There is no real standard for modifier plus function keys. Previously, tmux
output some from rxvt but in other ways did the same as xterm or other
terminals, but this is a bit inconsistent.

xterm's method is fairly sensible and we already support it (xterm-keys), so
enable it by default instead.


# 1.56 04-Nov-2009 nicm

A couple of minor cosmetic changes.


# 1.55 04-Nov-2009 nicm

Initial changes to move tmux to libevent.

This moves the client-side loops are pretty much fully over to event-based only
(tmux.c and client.c) but server-side (server.c and friends) treats libevent as
a sort of clever poll, waking up after every event to run various things.

Moving the server stuff over to bufferevents and timers and so on will come
later.


# 1.54 04-Nov-2009 nicm

Change declaration and use of malloc_options to be more standard, from Tim van
der Molen.


# 1.53 26-Oct-2009 deraadt

tabs are better; ok nicm


# 1.52 25-Oct-2009 nicm

Remove the -d flag to tmux and just use op/AX to detect default colours.

Irritatingly, although op can be used to tell if a terminal supports default
colours, it can't be used to set them because in some terminfo descriptions it
resets attributes as a side-effect (acts as sgr0) and in others it doesn't, so
it is not possible to determine reliably what the terminal state will be
afterwards. So if AX is missing and op is present, tmux just sends sgr0.

Anyone using -d for a terminal who finds they actually needed it can replace it
using terminal-overrides, but please let me know as it is probably an omission
from terminfo.


# 1.51 22-Oct-2009 nicm

Merge prepare_cmd into main as it is short and only called once.


# 1.50 21-Oct-2009 nicm

Client tidying: get rid of client_ctx struct in favour of two variables in
client.c, and move the functions in client-fn.c into other files.


# 1.49 10-Oct-2009 nicm

New option, mouse-select-pane. If on, the mouse may be used to select the
current pane.

Suggested by sthen@ and also by someone else ages ago who I have forgotten.


# 1.48 10-Oct-2009 nicm

Support for individual session idle time locking. May be enabled by turning off
the lock-server option (it is on by default). When this is off, each session
locks when it has been idle for the lock-after-time setting. When on, the
entire server locks when ALL sessions have been idle for their individual
lock-after-time settings.

This replaces one global-only option (lock-after-time) with another
(lock-server), but the default behaviour is usually preferable so there don't
seem to be many alternatives.

Diff/idea largely from Thomas Adam, tweaked by me.


# 1.47 09-Oct-2009 nicm

Add a simple synchronize-panes window option: when set, all input to any pane
that is part of the window is also sent to all other panes in the same
window. Suggested by several, most recently Tomasz Pajor.


# 1.46 23-Sep-2009 nicm

Support -c like sh(1) to execute a command, useful when tmux is a login
shell. Suggested by halex@.

This includes another protocol version increase (the last for now) so again
restart the tmux server before upgrading.


# 1.45 23-Sep-2009 nicm

Remove the internal tmux locking and instead detach each client and run the
command specified by a new option "lock-command" (by default "lock -np") in
each client.

This means each terminal has to be unlocked individually but simplifies the
code and allows the system password to be used to unlock.

Note that the set-password command is gone, so it will need to be removed from
configuration files, and the -U command line flag has been removed.

This is the third protocol version change so again it is best to stop the tmux
server before upgrading.


# 1.44 22-Sep-2009 nicm

Permit multiple prefix keys to be defined, separated by commas, for example:

set -g prefix ^a,^b

Any key in the list acts as the prefix. The send-prefix command always sends
the first key in the list.


# 1.43 18-Sep-2009 nicm

New option, set-titles-string, to allow the window title to be specified (as
for status-left/right) if set-titles is on. Also only update the title when the
status line is being redrawn.


# 1.42 04-Sep-2009 nicm

Tidy main and make it a bit easier to read.


# 1.41 02-Sep-2009 nicm

Accept -l to make it easier for people who use tmux as a login shell to use
$SHELL. Originally from martynas@, tweaked by me.


# 1.40 02-Sep-2009 nicm

When incorrect passwords are entered, behave similarly to login(1) and backoff
for a bit. Based on a diff from martynas@.


# 1.39 01-Sep-2009 nicm

When using tmux as a login shell, there is currently no way to specify a shell
to be used as a login shell inside tmux, so add a default-shell session option.
This sets the shell invoked as a login shell when the default-command option is
empty.

The default option value is whichever of $SHELL, getpwuid(getuid())'s pw_shell
or /bin/sh is valid first.

Based on a diff from martynas@, changed by me to be a session option rather
than a window option.


# 1.38 01-Sep-2009 nicm

Use "Password:" with no space for password prompts and don't display a *s for
the password, like pretty much everything else. From martynas@ with minor
tweaks by me.


# 1.37 01-Sep-2009 nicm

Sort cases same as getopt argument, from martynas.


# 1.36 31-Aug-2009 nicm

Add a new display-panes command, with two options (display-panes-colour and
display-panes-time), which displays a visual indication of the number of each
pane.


# 1.35 23-Aug-2009 nicm

Add some other obvious variables to update-environment (WINDOWID SSH_ASKPASS
SSH_AUTH_SOCK SSH_AGENT_PID SSH_CONNECTION) so they are updated in the session
environment on new/attach.


# 1.34 13-Aug-2009 nicm

Disable mode-mouse (mouse in copy/choice mode) by default as it isn't very
useful at the moment and causes confusion.


# 1.33 13-Aug-2009 nicm

Add a base-index session option to specify the first index checked when looking
for an index for a new window.


# 1.32 12-Aug-2009 nicm

When started as the shell, __progname contains a leading -, so hardcode "tmux"
for socket path and log files, and strip it when working out the shell.


# 1.31 11-Aug-2009 nicm

Switch tmux to use imsg. This is the last major change to make the
client-server protocol more resilient and make the protocol versioning work
properly. In future, the only things requiring a protocol version bump will be
changes in the message structs, and (when both client and server have this
change) mixing different versions should nicely report an error message.

As a side effect this also makes the code tidier, fixes a problem with the way
errors reported during server startup were handled, and supports fd passing
(which will be used in future).

Looked over by eric@, thanks.

Please note that mixing a client with this change with an older server or vice
versa may cause tmux to crash or hang - tmux should be completely exited before
upgrading.


# 1.30 10-Aug-2009 nicm

No arguments are the same as new-session and this requires the environment to
be sent, so set that flag too when argc == 0.


# 1.29 08-Aug-2009 nicm

Infrastructure and commands to manage the environment for processes started
within tmux.

There is a global environment, copied from the external environment when the
server is started and each sesssion has an (initially empty) session
environment which overrides it.

New commands set-environment and show-environment manipulate or display the
environments.

A new session option, update-environment, is a space-separated list of
variables which are updated from the external environment into the session
environment every time a new session is created - the default is DISPLAY.


# 1.28 08-Aug-2009 nicm

Options to set the colours and attributes for status-left/-right. From Thomas
Adam, thanks.


# 1.27 05-Aug-2009 nicm

If colours are not supported by the terminal, try to emulate a coloured
background by setting or clearing the reverse attribute.

This makes a few applications which don't use the reverse attribute themselves
a little happier, and allows the status, message and mode options to have
default attributes and fg/bg options that work as expected when set as reverse.


# 1.26 04-Aug-2009 nicm

Check for "UTF8" as well as "UTF-8" in LANG etc as it seems this may also
appear.


# 1.25 03-Aug-2009 nicm

Add a terminal-overrides session option allowing individual terminfo(5) entries
to be overridden. The 88col/256col checks are now moved into the default
setting and out of the code.

Also remove a couple of old workarounds for xterm and rxvt which are no longer
necessary (tmux can emulate them if missing).


# 1.24 30-Jul-2009 nicm

Add a mode-mouse option to prevent tmux taking over the mouse in choice or copy
modes.


# 1.23 29-Jul-2009 nicm

Rename struct hdrtype to msgtype which is a better name and can be used even
when struct hdr disappears.


# 1.22 29-Jul-2009 nicm

Taking account of the "s, 22 not 24 is the maximum length of #T in status-right
to prevent the date being cut off.


# 1.21 26-Jul-2009 nicm

Make all messages sent between the client and server fixed size.

This is the first of two changes to make the protocol more resilient and less
sensitive to other changes in the code, particularly with commands. The client
now packs argv into a buffer and sends it to the server for parsing, rather
than doing it itself and sending the parsed command data.

As a side-effect this also removes a lot of now-unused command marshalling
code.

Mixing a server without this change and a client with or vice versa will cause
tmux to hang or crash, please ensure that tmux is entirely killed before
upgrading.


# 1.20 22-Jul-2009 nicm

Pass a set of flags into client_init rather than just a start_server
variable. Only one flag now but more to come later.


# 1.19 20-Jul-2009 nicm

Display the number of failed password attempts (if any) when the server is
locked. From Tom Doherty.


# 1.18 20-Jul-2009 nicm

Add a status-justify option to allow the window list in the status line to be
positioned at the left, centre, or right.


# 1.17 20-Jul-2009 nicm

New options, window-status-current-{fg,bg,attr}, to set the fg, bg and
attributes with which the current window is shown in the status line. From
Johan Friis, thanks.


# 1.16 18-Jul-2009 nicm

Add three new session options: visual-activity, visual-bell, visual-content. If
these are enabled (and the monitor-activity, bell-actio and monitor-content
options are configurated appropriately), when activity, a bell, or content is
detected, a message is shown.

Also tidy up the bell/activity/content code in server.c slightly and fix a
couple of errors.


# 1.15 17-Jul-2009 nicm

If -u is specified or UTF-8 is otherwise detected when the server is started,
enable the utf8 and status-utf8 optons. While here, note in the man page that
the server is started with the first session and exits when none remain.


# 1.14 10-Jul-2009 nicm

Add a default-terminal option to set the starting value of $TERM in new
windows.

This is "screen" by default and must be either that or something closely
related. This does makes it easier to customise it if necessary.


# 1.13 08-Jul-2009 nicm

Just appending -l to $SHELL to create a login shell is wrong: -l is not POSIX,
and some people may use shells which do not support it. Instead, make an empty
default-command option mean a login shell, and fork it with a - in argv[0]
which is the method used by login(1).

Also fix the automatic-rename code to handle this correctly and to strip a
leading - if present.


# 1.12 07-Jul-2009 nicm

Rename the global options variables to be shorter and to make session options
clear. No functional change, getting this out of the way to make later options
changes easier.


Revision tags: OPENBSD_4_6_BASE
# 1.11 25-Jun-2009 nicm

If getcwd() fails, use the user's home directory, or /, instead of failing with
an error.


# 1.10 25-Jun-2009 nicm

Remove error about using -L and -S together which was never displayed as
logging wasn't yet enabled, was unnecessary, and contradicted the man page
which says using -S will cause -L to be ignored.


# 1.9 23-Jun-2009 nicm

LC_ALL overrides LC_CTYPE and LANG. Comment was correct but the code
wrong. Pointed out by Hannah Schroeter, thanks.


# 1.8 05-Jun-2009 nicm

Check the first of LC_CTYPE, LC_ALL and LANG, rather than just the last, when
trying to decide about UTF-8, and use strcasestr. Reported by Geert Hendrickx.


# 1.7 04-Jun-2009 nicm

Zero the password given to -U in the client as well.


# 1.6 03-Jun-2009 nicm

Do not set the window title by default (make set-titles option default to off),
wiping over the title is rude and annoying. Agreed by several.


# 1.5 03-Jun-2009 nicm

New session option, status-utf8, to control the interpretation of top-bit-set
characters in status-left and status-right (if on, they are treated as UTF-8;
otherwise passed through).


# 1.4 02-Jun-2009 sobrado

remove unused flag; while here, make usage's output fit on 80-column displays.


# 1.3 02-Jun-2009 pyr

spawn login shells by default, adapt manpage bits as well.
ok nicm@


# 1.2 02-Jun-2009 ray

Don't leak memory if multiple -f flags are given.

OK nicm@


# 1.1 01-Jun-2009 nicm

Import tmux, a terminal multiplexor allowing (among other things) a single
terminal to be switched between several different windows and programs
displayed on one terminal be detached from one terminal and moved to another.

ok deraadt pirofti


# 1.196 09-Apr-2020 nicm

More style nits.


# 1.195 31-Mar-2020 nicm

Add a way to mark environment variables as "hidden" so they can be used
by tmux but are not passed into the environment of new panes.


# 1.194 17-Mar-2020 nicm

Ignore default-shell (and use /bin/sh) if it invalid not just if it is
tmux itself, also refuse to set the option to something invalid in the
first place. GitHub issue 2120.


# 1.193 12-Mar-2020 nicm

When the server socket is given by the user with -S, create it with
umask 177 instead of 117 because it may not be in a safe directory like
the default directory in /tmp. The user can chmod it more open after it
is created if they want.


# 1.192 28-Jan-2020 nicm

-V also needs to go in usage.


# 1.191 28-Jan-2020 nicm

Reduce a difference with portable tmux by adding the -V flag and
#{version} format; on OpenBSD these just report the OpenBSD version.


# 1.190 14-Oct-2019 nicm

Memory leaks, from Igor Wong in GitHub issue 1934.


Revision tags: OPENBSD_6_6_BASE
# 1.189 20-Jun-2019 nicm

Add a per-pane option set. Pane options inherit from window options (so
there should be no change to existing behaviour) and are set and shown
with set-option -p and show-options -p.

Change remain-on-exit and window-style/window-active-style to be pane
options (some others will be changed later).

This makes select-pane -P and -g unnecessary so no longer document them
(they still work) and no longer document set-window-option and
show-window-options in favour of set-option -w and show-options -w.


# 1.188 26-Apr-2019 nicm

Merge hooks into options and make each one an array option. This allows
multiple commands to be easily bound to one hook. set-hook and
show-hooks remain but they are now variants of set-option and
show-options. show-options now has a -H flag to show hooks (by default
they are not shown).


Revision tags: OPENBSD_6_5_BASE
# 1.187 22-Nov-2018 nicm

Do not use PWD unless it actually matches the real working directory.


Revision tags: OPENBSD_6_3_BASE OPENBSD_6_4_BASE
# 1.186 12-Jan-2018 nicm

Improve error message if creating socket parent directory fails, from
Thomas Adam for GitHub issue 1215.


# 1.185 01-Jan-2018 nicm

Prefer PWD for current directory if present in client, from Wei Zhao in
GitHub issue 1183.


Revision tags: OPENBSD_6_2_BASE
# 1.184 12-Jul-2017 nicm

Make shell_command a global like other stuff rather than making it an
exception and using callback argument.


# 1.183 03-Jul-2017 nicm

Try C.UTF-8 which is also a commonly useful locale on some platforms,
from Romain Francoise.


# 1.182 22-Apr-2017 nicm

Do not need getopt.h.


# 1.181 20-Apr-2017 nicm

Use fdforkpty() instead of our own unwrapped versions.


# 1.180 19-Apr-2017 nicm

Style nits and a missing cast.


# 1.179 16-Apr-2017 nicm

Memory leak, from David CARLIER.


Revision tags: OPENBSD_6_1_BASE
# 1.178 21-Mar-2017 nicm

Use uid_t for UID not u_int.


# 1.177 16-Feb-2017 nicm

Style nits.


# 1.176 23-Jan-2017 nicm

Open /dev/ptm before pledge() and save it to be used for PTMGET later
(this means inlining forkpty()).

ok deraadt


# 1.175 15-Jan-2017 nicm

Major tidy up and rework of options tree and set-option/show-options
commands this pushes more of the code into options.c and ties it more
closely to the options table rather than having an unnecessary
split. Also add support for array options (will be used later). Only
(intentional) user visible change is that show-options output is now
passed through vis(3) with VIS_DQ so quotes are escaped.


# 1.174 12-Jan-2017 nicm

Simplify appending to string options.


# 1.173 09-Dec-2016 nicm

Spacing nits.


# 1.172 11-Oct-2016 nicm

Add static in window-*.c and move some internal functions out of tmux.h.


# 1.171 10-Oct-2016 nicm

Loads more static, except for cmd-*.c and window-*.c.


Revision tags: OPENBSD_6_0_BASE
# 1.170 27-May-2016 nicm

Use getprogname() instead of __progname to make portability easier.


# 1.169 04-May-2016 nicm

Fix up a couple of long lines.


# 1.168 05-Mar-2016 nicm

If setlocale("en_US.UTF-8") succeeds, then don't do the check for UTF-8
locale since if it isn't UTF-8 the system is broken anyway. If it fails,
try "" and check for UTF-8 with nl_langinfo(CODESET) rather than
wcwidth(). Based on a diff from schwarze@, nl_langinfo also suggested by
stsp@.


# 1.167 05-Mar-2016 nicm

Although we always have en_US.UTF-8 on OpenBSD, some platforms do not,
so fall back to setlocale(LC_CTYPE, ""). tmux requires a UTF-8 locale,
so check with wcwidth() on a UTF-8 character after setlocale().


# 1.166 01-Mar-2016 nicm

Remove unused variables, from Michal Mazurek.


# 1.165 01-Mar-2016 nicm

Use system wcwidth() instead of carrying around UTF-8 width tables.


Revision tags: OPENBSD_5_9_BASE
# 1.164 19-Jan-2016 nicm

I no longer use my SourceForge address so replace it.


# 1.163 08-Dec-2015 nicm

Add hooks infrastructure, basic commands (set-hook, show-hooks) and a
couple of not very useful client hooks. This will eventually let
commands be run at various points and on notifications. Joint work with
Thomas Adam.


# 1.162 24-Nov-2015 nicm

Make environ_set va_args and use it to tidy up some calls. Also add a
missing word in manpage (from jmc).


# 1.161 24-Nov-2015 nicm

Shell command from -c doesn't have to be global, pass it as an argument.


# 1.160 24-Nov-2015 nicm

Tidy the code that works out the socket path, and just use the full path
in the global socket_path rather than copying it.


# 1.159 24-Nov-2015 nicm

Remove malloc_options DEBUG bit.


# 1.158 24-Nov-2015 nicm

Remove the -I part of show-messages which isn't really that useful; the
server start time can now be accessed with a new start_time format (use:
tmux display -p '#{t:start_time}')


# 1.157 24-Nov-2015 nicm

Make the log stuff a bit tidier with some helper functions.


# 1.156 22-Nov-2015 nicm

Add getpw to pledge, makes tmux work in YP environments, discovered by
matthieu, ok deraadt


# 1.155 20-Nov-2015 nicm

Instead of separate tables for different types of options, give each
option a scope type (server, session, window) in one table.


# 1.154 15-Nov-2015 nicm

Accidentally turned off pledge, turn it back on.


# 1.153 14-Nov-2015 nicm

Push stdout and stderr to clients more aggressively, and add an event to
continue if the send fails.


# 1.152 12-Nov-2015 nicm

tmux is UTF-8, so if $TMUX is set (tmux running in tmux), the client is
UTF-8. Also try to make the existing checks more readable.


# 1.151 12-Nov-2015 nicm

Nuke the utf8 and status-utf8 options and make tmux only a UTF-8
terminal. We still support non-UTF-8 terminals outside tmux, but inside
it is always UTF-8 (as when the utf8 and status-utf8 options were on).


# 1.150 11-Nov-2015 nicm

Drop mouse-utf8 option and always turn on UTF-8 mouse if the client says
it supports UTF-8.


# 1.149 28-Oct-2015 nicm

Like options, move the environ struct into environ.c.


# 1.148 27-Oct-2015 nicm

Move struct options into options.c.


# 1.147 27-Oct-2015 nicm

Break the common process set up, event loop and imsg dispatch code
between server and client out into a separate internal API. This will
make it easier to add another process.


# 1.146 25-Oct-2015 deraadt

Let's see if anyone screams about not being able to specify $TMPDIR
for their tmux sockets.

(Over the years, I have seen $TMPDIR set up worse than /tmp many times,
and don't know how this practice infected other parts of the system.
Nothing uses tmpdir(3), nor a huge-temporary-file program like sort.)
ok nicm


# 1.145 23-Oct-2015 nicm

tmux can call pledge() in main with large set and then reduce it
slightly in the server to "stdio rpath wpath cpath fattr unix recvfd
proc exec tty ps".


# 1.144 14-Sep-2015 nicm

Move tzset() from log_open to main.


# 1.143 03-Sep-2015 nicm

A couple of style nits.


# 1.142 01-Sep-2015 nicm

Work out config file when needed not at startup.


# 1.141 30-Aug-2015 nicm

Path from $TMUX does not need to be global anymore.


# 1.140 30-Aug-2015 nicm

Login shell can be a client flag, and move the exec code into client.c.


# 1.139 30-Aug-2015 nicm

Event base does not need to be global.


# 1.138 30-Aug-2015 nicm

Some style nits and dead assignments.


Revision tags: OPENBSD_5_8_BASE
# 1.137 20-Jul-2015 nicm

Add an option (history-file) for a file to save/restore command prompt
history, from Olof-Joachim Frahm.


# 1.136 04-Jun-2015 jmc

tweak SYNOPSIS and usage();


Revision tags: OPENBSD_5_7_BASE
# 1.135 19-Jan-2015 nicm

Make a tmux-%u directory under TMUX_TMPDIR, like TMPDIR.


# 1.134 19-Jan-2015 nicm

Only care about other permissions, allow group to be set.


# 1.133 19-Jan-2015 nicm

Remove unnecessary duplicate S_ISDIR check, from Dmitri Paduchikh.


# 1.132 20-Oct-2014 nicm

Tidy up some includes.


Revision tags: OPENBSD_5_6_BASE
# 1.131 17-Apr-2014 nicm

Remove the "info" message mechanism, this was only used for about five
mostly useless and annoying messages. Change those commands to silence
on success like all the others. Still accept the -q command line flag
and "quiet" server option for now.


# 1.130 31-Mar-2014 nicm

Remove log_debug2 as well and simplify log.c.


Revision tags: OPENBSD_5_5_BASE
# 1.129 16-Feb-2014 nicm

Leftovers from removing 88 colour support, from Theo Buehler.


# 1.128 15-Jan-2014 nicm

Do not attempt to read .tmux.conf if we can't figure out a home
directory, from Tiago Cunha.


# 1.127 09-Jan-2014 nicm

Three small changes from Tiago Cunha:

- Check for truncation when copying path.
- Don't need to use a temporary buffer in screen_set_title.
- Include strerror in output when connecting to server fails.


# 1.126 10-Oct-2013 nicm

We accidentally haven't been using $TMUX to work out the session for a
while and in fact it is less useful that using the client ttyname. So
don't bother and don't pass it from the client. If we need it in future
it is in c->environ.


# 1.125 10-Oct-2013 nicm

Alter how tmux handles the working directory to internally use file
descriptors rather than strings.

- Each session still has a current working directory.

- New sessions still get their working directory from the client that
created them or its attached session if any.

- New windows are created by default in the session working directory.

- The -c flag to new, neww, splitw allows the working directory to be
overridden.

- The -c flag to attach let's the session working directory be changed.

- The default-path option has been removed.

To get the equivalent to default-path '.', do:

bind c neww -c $PWD

To get the equivalent of default-path '~', do:

bind c neww -c ~

This also changes the client identify protocol to be a set of messages rather
than one as well as some other changes that should make it easier to make
backwards-compatible protocol changes in future.


# 1.124 10-Oct-2013 nicm

Merge IDENTIFY_* flags with CLIENT_* flags.


# 1.123 10-Oct-2013 nicm

Don't treat TMUX_TMPDIR as a potential file

The point of setting TMUX_TMPDIR is to then make any labels from -L go
to that directory. In the case of makesocketpath() with no TMUX_TMPDIR
set, would set both the path and the default socket to a file. The
checking of the permissions on the file worked fine in that case, but
when TMUX_TMPDIR is set, won't work on a directory.

This fixes the problem by ensuring the check on the permissions is
performed on directories only.

By Thomas Adam.


# 1.122 05-Oct-2013 nicm

Fix previous not to leak fd on failure, whoops.


# 1.121 05-Oct-2013 nicm

Use open(".")/fchdir() to save and restore current directory rather than
getcwd()/chdir().


Revision tags: OPENBSD_5_4_BASE
# 1.120 24-Apr-2013 nicm

Rename global configuration define.


# 1.119 11-Apr-2013 nicm

Call setlocale(LC_TIME) at startup.


# 1.118 27-Mar-2013 nicm

Add TMUX_TMPDIR variable to put the socket directory outside
TMPDIR. From Ben Boeckel.


# 1.117 27-Mar-2013 nicm

Remove tmux's (already minimal) 88 colour support. Such terminals are
few and unnecessary.


# 1.116 25-Mar-2013 nicm

Rename session idx to session id throughout and add $ prefix to targets
to use it, extended from a diff from George Nachman.


# 1.115 24-Mar-2013 nicm

Add a command queue to standardize and simplify commands that call other
commands and allow a command to block execution of subsequent
commands. This allows run-shell and if-shell to be synchronous which has
been much requested.

Each client has a default command queue and commands are consumed one at
a time from it. A command may suspend execution from the queue by
returning CMD_RETURN_WAIT and then resume it by calling cmd_continue() -
for example run-shell does this from the callback that is fired after
the job is freed.

When the command queue becomes empty, command clients are automatically
exited (unless attaching). A callback is also fired - this is used for
nested commands in, for example, if-shell which can block execution of
the client's cmdq until a new cmdq becomes empty.

Also merge all the old error/info/print functions together and lose the
old curclient/cmdclient distinction - a cmdq is bound to one client (or
none if in the configuration file), this is a command client if
c->session is NULL otherwise an attached client.


Revision tags: OPENBSD_5_3_BASE
# 1.114 27-Nov-2012 nicm

Correctly aggregate together errors from nested config files (with
source-file). Fix by Thomas Adam, reported by Sam Livingstone-Gray


# 1.113 26-Nov-2012 nicm

Call realpath earlier on the socket directory path rather than on the
socket file path because the latter may not exist yet and in that case
realpath is allowed to fail. From Romain Francoise.


Revision tags: OPENBSD_5_2_BASE
# 1.112 10-Jul-2012 nicm

xfree is not particularly helpful, remove it. From Thomas Adam.


# 1.111 18-Jun-2012 nicm

Add a skeleton mode to tmux (called "control mode") that let's tmux
commands be sent and output received on stdout. This can be used to
integrate with other terminal emulators and should allow some other
things to be made simpler later. More to come so doesn't do much yet and
deliberately not documented.


# 1.110 30-May-2012 nicm

Do not use stderr for log file and don't call log_close when not needed.


# 1.109 25-May-2012 nicm

Simplify logging and just fprintf(stderr, ...) for early errors.


Revision tags: OPENBSD_5_1_BASE
# 1.108 21-Jan-2012 nicm

Drop the ability to have a list of keys in the prefix in favour of two
separate options, prefix and prefix2. This simplifies the code and gets
rid the data options type which was only used for this one option.

Also add a -2 flag to send-prefix to send the secondary prefix key,
fixing a cause of minor irritation.

People who want three prefix keys are out of luck :-).


# 1.107 23-Oct-2011 nicm

Try to resolve relative paths for loadb and saveb (first using client
working directory if any then default-path or session wd).


# 1.106 23-Oct-2011 nicm

Ignore LC_ALL and LC_CTYPE if they are empty as well as unset.


# 1.105 25-Sep-2011 nicm

Reject $SHELL if it is not a full path.


Revision tags: OPENBSD_5_0_BASE
# 1.104 04-Mar-2011 nicm

Two fixes by Micah Cowan: make mouse work properly beyond >127 on signed
char architectures and properly parse $TMUX by stopping the socket path
at the first comma.


Revision tags: OPENBSD_4_9_BASE
# 1.103 23-Jan-2011 nicm

Set $TMUX without the session when background jobs are run.


# 1.102 12-Jan-2011 nicm

Use TMPDIR if set, from Han Boetes.


# 1.101 08-Jan-2011 nicm

Move all calls to fcntl(...O_NONBLOCK) into a function and clear the
flag on the stdio file descriptors before closing them (fixes things
like "tmux ls && cat").


# 1.100 03-Jan-2011 nicm

Support for UTF-8 mouse input (\033[1005h). This was added in xterm 262
and supports larger terminals than the older way.

If the new mouse-utf8 option is on, UTF-8 mouse input is enabled for all
UTF-8 terminals. The option defaults to on if LANG etc are set in the
same manner as the utf8 option.

With help and based on code from hsim at gmx.li.


# 1.99 01-Jan-2011 nicm

Move the user-visible parts of all options (names, types, limit, default
values) together into one set of tables in options-table.c. Also clean
up and simplify cmd-set-options.c and move a common print function into
option-table.c.


# 1.98 30-Dec-2010 nicm

Change from a per-session stack of buffers to one global stack which is
much more convenient and also simplifies lot of code. This renders
copy-buffer useless and makes buffer-limit now a server option.

By Tiago Cunha.


# 1.97 19-Dec-2010 nicm

Add other-pane-height and other-pane-width options, allowing the width
or height of the smaller panes in the main-horizontal and main-vertical
layouts to be set. Mostly from David Goodlad.


# 1.96 08-Dec-2010 nicm

In the built-in layouts, distribute the panes more evenly. Set the
default value of main-pane-width to 80, rather than 81. By Micah Cowan.


# 1.95 06-Dec-2010 nicm

Add an option to alert (monitor) for silence (lack of activity) in a
window. From Thomas Adam.


# 1.94 29-Nov-2010 nicm

If VISUAL or EDITOR contains "vi", configure mode-keys and status-keys
to vi.

Based on a diff from martynas@, previously requested by a couple of
other people.


# 1.93 11-Nov-2010 nicm

Add XAUTHORITY to update-environment, requested by Andreas Kloeckner.


# 1.92 18-Oct-2010 nicm

Merge the before and after attach client code into one in client.c
(instead of two in tmux.c and client.c).


# 1.91 16-Oct-2010 nicm

Make stdio blocking again before calling shell command with -c.


# 1.90 16-Oct-2010 nicm

Trying to set FD_CLOEXEC on every fd is a lost cause, just use
closefrom() before exec.


# 1.89 14-Oct-2010 nicm

Use an explicit event rather than event_once for the main event so it
can be removed when the client becomes ready.


# 1.88 26-Sep-2010 nicm

Two new options:

- server option "exit-unattached" makes the server exit when no clients
are attached, even if sessions are present;

- session option "destroy-unattached" destroys a session once no clients
are attached to it.

These are useful for preventing tmux remaining in the background where
it is undesirable and when using tmux as a login shell to keep a limit
on new sessions.


# 1.87 19-Aug-2010 nicm

Do not call event_del() for signals after fork(), just use sigaction()
directly instead - calling libevent functions after fork() w/o
event_reinit() is a bad idea, even if in this case it was harmless.


Revision tags: OPENBSD_4_8_BASE
# 1.86 04-Aug-2010 deraadt

switch back to kqueue for now, since (a) kqueue has been fixed to deal
with strange devices and (b) since there appears to be a bull in the
poll code in libevent as well...
requested by nicm who is away


# 1.85 24-Jul-2010 nicm

kqueue(2) is currently broken when used with /dev/null and a few other
devices.

An upcoming fix for some problems with the client stdout/stderr handling
relies on it working, so make tmux force libevent to use poll(2) via
EVENT_NOKQUEUE, until we have fixed kqueue.


# 1.84 11-Jul-2010 nicm

Return the command client return code with MSG_EXIT now that MSG_ERROR and
MSG_PRINT are unused.

New clients should be compatible with old tmux servers but vice versa may print
an error.


# 1.83 28-Jun-2010 nicm

Send all three of stdin, stdout, stderr from the client to the server, so that
commands can directly make use of them. This means that load-buffer and
save-buffer can have "-" as the file to read from stdin or write to stdout.

This is a protocol version bump so the tmux server will need to be restarted
after upgrade (or an older client used).


# 1.82 27-Jun-2010 nicm

Store the current working directory in the session, change the default-path
option to default to empty and make that mean that the stored session CWD is
used.


# 1.81 27-Jun-2010 nicm

New option, detach-on-destroy, to set what happens to a client when the session
it is attached to is destroyed. If on (the default), it is detached; if off, it
is switched to the most recently active session.


# 1.80 26-Jun-2010 nicm

Setting the cmdlist pointer in the bind-key to NULL to prevent it being freed
after the command is executing is bogus because it may still be needed if the
same command is going to be executed again (for example if you "bind-key a
bind-key b ..."). Making a copy is hard, so instead add a reference count to
the cmd_list.

While here, also print bind-key -n and the rest of the flags properly.

Fixes problem reported by mcbride@.


# 1.79 14-May-2010 nicm

Colour+attribute options for status line alerts, from Alex Alexander.


# 1.78 04-May-2010 nicm

Put this back in with the initialisation in the right order.


# 1.77 04-May-2010 nicm

Revert last change, it appears to be broken somehow.


# 1.76 03-May-2010 nicm

Make signal handler setup/teardown two common functions instead of six,
and reset SIGCHLD after fork to fix problems with some shells. From
Romain Francois.


# 1.75 28-Apr-2010 nicm

Make the active pane border have a green foreground instead of
background by default.


# 1.74 18-Apr-2010 nicm

Catch SIGCHLD to avoid a zombie, from patrick keshishian.


Revision tags: OPENBSD_4_7_BASE
# 1.73 22-Feb-2010 nicm

Option to set the characters considered word separators in copy mode, from
Micah Cowan.


# 1.72 08-Feb-2010 nicm

Add an option to disable the smcup/rmcup alternate screen behaviour inside
tmux. From clemens fischer.


# 1.71 06-Feb-2010 nicm

Change nested check to compare server socket path rather than just assuming
that if $TMUX is set it is nested. From Micah Cowan.


# 1.70 06-Feb-2010 nicm

Clean up $TMUX parsing, from Micah Cowan, tweaked by me.


# 1.69 06-Feb-2010 nicm

Instead of bailing out on the first configuration file error, carry on,
collecting all the errors, then start with the active window in more mode
displaying them.


# 1.68 04-Feb-2010 nicm

Read the path from $TMUX if it is present and -L and -S are not given. Based on
a diff from Micah Cowan.


# 1.67 04-Feb-2010 nicm

Option to display the active pane in a different colour with the display-panes
command. From Paul Hoffman, thanks.


# 1.66 03-Jan-2010 nicm

Options to set the colour of the pane borders, with different colours for the
active pane.


# 1.65 14-Dec-2009 nicm

New server option, escape-time, to set the timeout used to detect if escapes
are alone or part of a function key or meta sequence.


# 1.64 11-Dec-2009 nicm

Use quiet variable, and add missing sentinel to options array.


# 1.63 10-Dec-2009 nicm

Add "server options" which are server-wide and not bound to a session or
window. Set and displayed with "set -s" and "show -s".

Currently the only option is "quiet" (like command-line -q, allowing it to be
set from .tmux.conf), but others will come along.


# 1.62 03-Dec-2009 nicm

Massive spaces->tabs and trailing whitespace cleanup, hopefully for the last
time now I've configured emacs to make them displayed in really annoying
colours...


# 1.61 26-Nov-2009 nicm

Remove a couple of unused arguments where possible, and add /* ARGSUSED */ to
the rest to reduce lint output.


# 1.60 19-Nov-2009 nicm

Two new options, window-status-format and window-status-current-format, which
allow the format of each window in the status line window list to be controlled
using similar # sequences as status-left/right.

This diff also moves part of the way towards UTF-8 support in window names but
it isn't quite there yet.


# 1.59 19-Nov-2009 nicm

Revert to xterm-keys off by default. It was on as an experiment to see if the
option could be removed, but it affects vi, so we have to keep the option, and
a conservative default is better.


# 1.58 18-Nov-2009 nicm

Add a per-client log of status line messages displayed while that client
exists. A new message-limit session option sets the maximum number of entries
and a command, show-messages, shows the log (bound to ~ by default).

This (and prompt history) might be better as a single global log but until
there are global options it is easier for them to be per client.


# 1.57 10-Nov-2009 nicm

There is no real standard for modifier plus function keys. Previously, tmux
output some from rxvt but in other ways did the same as xterm or other
terminals, but this is a bit inconsistent.

xterm's method is fairly sensible and we already support it (xterm-keys), so
enable it by default instead.


# 1.56 04-Nov-2009 nicm

A couple of minor cosmetic changes.


# 1.55 04-Nov-2009 nicm

Initial changes to move tmux to libevent.

This moves the client-side loops are pretty much fully over to event-based only
(tmux.c and client.c) but server-side (server.c and friends) treats libevent as
a sort of clever poll, waking up after every event to run various things.

Moving the server stuff over to bufferevents and timers and so on will come
later.


# 1.54 04-Nov-2009 nicm

Change declaration and use of malloc_options to be more standard, from Tim van
der Molen.


# 1.53 26-Oct-2009 deraadt

tabs are better; ok nicm


# 1.52 25-Oct-2009 nicm

Remove the -d flag to tmux and just use op/AX to detect default colours.

Irritatingly, although op can be used to tell if a terminal supports default
colours, it can't be used to set them because in some terminfo descriptions it
resets attributes as a side-effect (acts as sgr0) and in others it doesn't, so
it is not possible to determine reliably what the terminal state will be
afterwards. So if AX is missing and op is present, tmux just sends sgr0.

Anyone using -d for a terminal who finds they actually needed it can replace it
using terminal-overrides, but please let me know as it is probably an omission
from terminfo.


# 1.51 22-Oct-2009 nicm

Merge prepare_cmd into main as it is short and only called once.


# 1.50 21-Oct-2009 nicm

Client tidying: get rid of client_ctx struct in favour of two variables in
client.c, and move the functions in client-fn.c into other files.


# 1.49 10-Oct-2009 nicm

New option, mouse-select-pane. If on, the mouse may be used to select the
current pane.

Suggested by sthen@ and also by someone else ages ago who I have forgotten.


# 1.48 10-Oct-2009 nicm

Support for individual session idle time locking. May be enabled by turning off
the lock-server option (it is on by default). When this is off, each session
locks when it has been idle for the lock-after-time setting. When on, the
entire server locks when ALL sessions have been idle for their individual
lock-after-time settings.

This replaces one global-only option (lock-after-time) with another
(lock-server), but the default behaviour is usually preferable so there don't
seem to be many alternatives.

Diff/idea largely from Thomas Adam, tweaked by me.


# 1.47 09-Oct-2009 nicm

Add a simple synchronize-panes window option: when set, all input to any pane
that is part of the window is also sent to all other panes in the same
window. Suggested by several, most recently Tomasz Pajor.


# 1.46 23-Sep-2009 nicm

Support -c like sh(1) to execute a command, useful when tmux is a login
shell. Suggested by halex@.

This includes another protocol version increase (the last for now) so again
restart the tmux server before upgrading.


# 1.45 23-Sep-2009 nicm

Remove the internal tmux locking and instead detach each client and run the
command specified by a new option "lock-command" (by default "lock -np") in
each client.

This means each terminal has to be unlocked individually but simplifies the
code and allows the system password to be used to unlock.

Note that the set-password command is gone, so it will need to be removed from
configuration files, and the -U command line flag has been removed.

This is the third protocol version change so again it is best to stop the tmux
server before upgrading.


# 1.44 22-Sep-2009 nicm

Permit multiple prefix keys to be defined, separated by commas, for example:

set -g prefix ^a,^b

Any key in the list acts as the prefix. The send-prefix command always sends
the first key in the list.


# 1.43 18-Sep-2009 nicm

New option, set-titles-string, to allow the window title to be specified (as
for status-left/right) if set-titles is on. Also only update the title when the
status line is being redrawn.


# 1.42 04-Sep-2009 nicm

Tidy main and make it a bit easier to read.


# 1.41 02-Sep-2009 nicm

Accept -l to make it easier for people who use tmux as a login shell to use
$SHELL. Originally from martynas@, tweaked by me.


# 1.40 02-Sep-2009 nicm

When incorrect passwords are entered, behave similarly to login(1) and backoff
for a bit. Based on a diff from martynas@.


# 1.39 01-Sep-2009 nicm

When using tmux as a login shell, there is currently no way to specify a shell
to be used as a login shell inside tmux, so add a default-shell session option.
This sets the shell invoked as a login shell when the default-command option is
empty.

The default option value is whichever of $SHELL, getpwuid(getuid())'s pw_shell
or /bin/sh is valid first.

Based on a diff from martynas@, changed by me to be a session option rather
than a window option.


# 1.38 01-Sep-2009 nicm

Use "Password:" with no space for password prompts and don't display a *s for
the password, like pretty much everything else. From martynas@ with minor
tweaks by me.


# 1.37 01-Sep-2009 nicm

Sort cases same as getopt argument, from martynas.


# 1.36 31-Aug-2009 nicm

Add a new display-panes command, with two options (display-panes-colour and
display-panes-time), which displays a visual indication of the number of each
pane.


# 1.35 23-Aug-2009 nicm

Add some other obvious variables to update-environment (WINDOWID SSH_ASKPASS
SSH_AUTH_SOCK SSH_AGENT_PID SSH_CONNECTION) so they are updated in the session
environment on new/attach.


# 1.34 13-Aug-2009 nicm

Disable mode-mouse (mouse in copy/choice mode) by default as it isn't very
useful at the moment and causes confusion.


# 1.33 13-Aug-2009 nicm

Add a base-index session option to specify the first index checked when looking
for an index for a new window.


# 1.32 12-Aug-2009 nicm

When started as the shell, __progname contains a leading -, so hardcode "tmux"
for socket path and log files, and strip it when working out the shell.


# 1.31 11-Aug-2009 nicm

Switch tmux to use imsg. This is the last major change to make the
client-server protocol more resilient and make the protocol versioning work
properly. In future, the only things requiring a protocol version bump will be
changes in the message structs, and (when both client and server have this
change) mixing different versions should nicely report an error message.

As a side effect this also makes the code tidier, fixes a problem with the way
errors reported during server startup were handled, and supports fd passing
(which will be used in future).

Looked over by eric@, thanks.

Please note that mixing a client with this change with an older server or vice
versa may cause tmux to crash or hang - tmux should be completely exited before
upgrading.


# 1.30 10-Aug-2009 nicm

No arguments are the same as new-session and this requires the environment to
be sent, so set that flag too when argc == 0.


# 1.29 08-Aug-2009 nicm

Infrastructure and commands to manage the environment for processes started
within tmux.

There is a global environment, copied from the external environment when the
server is started and each sesssion has an (initially empty) session
environment which overrides it.

New commands set-environment and show-environment manipulate or display the
environments.

A new session option, update-environment, is a space-separated list of
variables which are updated from the external environment into the session
environment every time a new session is created - the default is DISPLAY.


# 1.28 08-Aug-2009 nicm

Options to set the colours and attributes for status-left/-right. From Thomas
Adam, thanks.


# 1.27 05-Aug-2009 nicm

If colours are not supported by the terminal, try to emulate a coloured
background by setting or clearing the reverse attribute.

This makes a few applications which don't use the reverse attribute themselves
a little happier, and allows the status, message and mode options to have
default attributes and fg/bg options that work as expected when set as reverse.


# 1.26 04-Aug-2009 nicm

Check for "UTF8" as well as "UTF-8" in LANG etc as it seems this may also
appear.


# 1.25 03-Aug-2009 nicm

Add a terminal-overrides session option allowing individual terminfo(5) entries
to be overridden. The 88col/256col checks are now moved into the default
setting and out of the code.

Also remove a couple of old workarounds for xterm and rxvt which are no longer
necessary (tmux can emulate them if missing).


# 1.24 30-Jul-2009 nicm

Add a mode-mouse option to prevent tmux taking over the mouse in choice or copy
modes.


# 1.23 29-Jul-2009 nicm

Rename struct hdrtype to msgtype which is a better name and can be used even
when struct hdr disappears.


# 1.22 29-Jul-2009 nicm

Taking account of the "s, 22 not 24 is the maximum length of #T in status-right
to prevent the date being cut off.


# 1.21 26-Jul-2009 nicm

Make all messages sent between the client and server fixed size.

This is the first of two changes to make the protocol more resilient and less
sensitive to other changes in the code, particularly with commands. The client
now packs argv into a buffer and sends it to the server for parsing, rather
than doing it itself and sending the parsed command data.

As a side-effect this also removes a lot of now-unused command marshalling
code.

Mixing a server without this change and a client with or vice versa will cause
tmux to hang or crash, please ensure that tmux is entirely killed before
upgrading.


# 1.20 22-Jul-2009 nicm

Pass a set of flags into client_init rather than just a start_server
variable. Only one flag now but more to come later.


# 1.19 20-Jul-2009 nicm

Display the number of failed password attempts (if any) when the server is
locked. From Tom Doherty.


# 1.18 20-Jul-2009 nicm

Add a status-justify option to allow the window list in the status line to be
positioned at the left, centre, or right.


# 1.17 20-Jul-2009 nicm

New options, window-status-current-{fg,bg,attr}, to set the fg, bg and
attributes with which the current window is shown in the status line. From
Johan Friis, thanks.


# 1.16 18-Jul-2009 nicm

Add three new session options: visual-activity, visual-bell, visual-content. If
these are enabled (and the monitor-activity, bell-actio and monitor-content
options are configurated appropriately), when activity, a bell, or content is
detected, a message is shown.

Also tidy up the bell/activity/content code in server.c slightly and fix a
couple of errors.


# 1.15 17-Jul-2009 nicm

If -u is specified or UTF-8 is otherwise detected when the server is started,
enable the utf8 and status-utf8 optons. While here, note in the man page that
the server is started with the first session and exits when none remain.


# 1.14 10-Jul-2009 nicm

Add a default-terminal option to set the starting value of $TERM in new
windows.

This is "screen" by default and must be either that or something closely
related. This does makes it easier to customise it if necessary.


# 1.13 08-Jul-2009 nicm

Just appending -l to $SHELL to create a login shell is wrong: -l is not POSIX,
and some people may use shells which do not support it. Instead, make an empty
default-command option mean a login shell, and fork it with a - in argv[0]
which is the method used by login(1).

Also fix the automatic-rename code to handle this correctly and to strip a
leading - if present.


# 1.12 07-Jul-2009 nicm

Rename the global options variables to be shorter and to make session options
clear. No functional change, getting this out of the way to make later options
changes easier.


Revision tags: OPENBSD_4_6_BASE
# 1.11 25-Jun-2009 nicm

If getcwd() fails, use the user's home directory, or /, instead of failing with
an error.


# 1.10 25-Jun-2009 nicm

Remove error about using -L and -S together which was never displayed as
logging wasn't yet enabled, was unnecessary, and contradicted the man page
which says using -S will cause -L to be ignored.


# 1.9 23-Jun-2009 nicm

LC_ALL overrides LC_CTYPE and LANG. Comment was correct but the code
wrong. Pointed out by Hannah Schroeter, thanks.


# 1.8 05-Jun-2009 nicm

Check the first of LC_CTYPE, LC_ALL and LANG, rather than just the last, when
trying to decide about UTF-8, and use strcasestr. Reported by Geert Hendrickx.


# 1.7 04-Jun-2009 nicm

Zero the password given to -U in the client as well.


# 1.6 03-Jun-2009 nicm

Do not set the window title by default (make set-titles option default to off),
wiping over the title is rude and annoying. Agreed by several.


# 1.5 03-Jun-2009 nicm

New session option, status-utf8, to control the interpretation of top-bit-set
characters in status-left and status-right (if on, they are treated as UTF-8;
otherwise passed through).


# 1.4 02-Jun-2009 sobrado

remove unused flag; while here, make usage's output fit on 80-column displays.


# 1.3 02-Jun-2009 pyr

spawn login shells by default, adapt manpage bits as well.
ok nicm@


# 1.2 02-Jun-2009 ray

Don't leak memory if multiple -f flags are given.

OK nicm@


# 1.1 01-Jun-2009 nicm

Import tmux, a terminal multiplexor allowing (among other things) a single
terminal to be switched between several different windows and programs
displayed on one terminal be detached from one terminal and moved to another.

ok deraadt pirofti


# 1.195 31-Mar-2020 nicm

Add a way to mark environment variables as "hidden" so they can be used
by tmux but are not passed into the environment of new panes.


# 1.194 17-Mar-2020 nicm

Ignore default-shell (and use /bin/sh) if it invalid not just if it is
tmux itself, also refuse to set the option to something invalid in the
first place. GitHub issue 2120.


# 1.193 12-Mar-2020 nicm

When the server socket is given by the user with -S, create it with
umask 177 instead of 117 because it may not be in a safe directory like
the default directory in /tmp. The user can chmod it more open after it
is created if they want.


# 1.192 28-Jan-2020 nicm

-V also needs to go in usage.


# 1.191 28-Jan-2020 nicm

Reduce a difference with portable tmux by adding the -V flag and
#{version} format; on OpenBSD these just report the OpenBSD version.


# 1.190 14-Oct-2019 nicm

Memory leaks, from Igor Wong in GitHub issue 1934.


Revision tags: OPENBSD_6_6_BASE
# 1.189 20-Jun-2019 nicm

Add a per-pane option set. Pane options inherit from window options (so
there should be no change to existing behaviour) and are set and shown
with set-option -p and show-options -p.

Change remain-on-exit and window-style/window-active-style to be pane
options (some others will be changed later).

This makes select-pane -P and -g unnecessary so no longer document them
(they still work) and no longer document set-window-option and
show-window-options in favour of set-option -w and show-options -w.


# 1.188 26-Apr-2019 nicm

Merge hooks into options and make each one an array option. This allows
multiple commands to be easily bound to one hook. set-hook and
show-hooks remain but they are now variants of set-option and
show-options. show-options now has a -H flag to show hooks (by default
they are not shown).


Revision tags: OPENBSD_6_5_BASE
# 1.187 22-Nov-2018 nicm

Do not use PWD unless it actually matches the real working directory.


Revision tags: OPENBSD_6_3_BASE OPENBSD_6_4_BASE
# 1.186 12-Jan-2018 nicm

Improve error message if creating socket parent directory fails, from
Thomas Adam for GitHub issue 1215.


# 1.185 01-Jan-2018 nicm

Prefer PWD for current directory if present in client, from Wei Zhao in
GitHub issue 1183.


Revision tags: OPENBSD_6_2_BASE
# 1.184 12-Jul-2017 nicm

Make shell_command a global like other stuff rather than making it an
exception and using callback argument.


# 1.183 03-Jul-2017 nicm

Try C.UTF-8 which is also a commonly useful locale on some platforms,
from Romain Francoise.


# 1.182 22-Apr-2017 nicm

Do not need getopt.h.


# 1.181 20-Apr-2017 nicm

Use fdforkpty() instead of our own unwrapped versions.


# 1.180 19-Apr-2017 nicm

Style nits and a missing cast.


# 1.179 16-Apr-2017 nicm

Memory leak, from David CARLIER.


Revision tags: OPENBSD_6_1_BASE
# 1.178 21-Mar-2017 nicm

Use uid_t for UID not u_int.


# 1.177 16-Feb-2017 nicm

Style nits.


# 1.176 23-Jan-2017 nicm

Open /dev/ptm before pledge() and save it to be used for PTMGET later
(this means inlining forkpty()).

ok deraadt


# 1.175 15-Jan-2017 nicm

Major tidy up and rework of options tree and set-option/show-options
commands this pushes more of the code into options.c and ties it more
closely to the options table rather than having an unnecessary
split. Also add support for array options (will be used later). Only
(intentional) user visible change is that show-options output is now
passed through vis(3) with VIS_DQ so quotes are escaped.


# 1.174 12-Jan-2017 nicm

Simplify appending to string options.


# 1.173 09-Dec-2016 nicm

Spacing nits.


# 1.172 11-Oct-2016 nicm

Add static in window-*.c and move some internal functions out of tmux.h.


# 1.171 10-Oct-2016 nicm

Loads more static, except for cmd-*.c and window-*.c.


Revision tags: OPENBSD_6_0_BASE
# 1.170 27-May-2016 nicm

Use getprogname() instead of __progname to make portability easier.


# 1.169 04-May-2016 nicm

Fix up a couple of long lines.


# 1.168 05-Mar-2016 nicm

If setlocale("en_US.UTF-8") succeeds, then don't do the check for UTF-8
locale since if it isn't UTF-8 the system is broken anyway. If it fails,
try "" and check for UTF-8 with nl_langinfo(CODESET) rather than
wcwidth(). Based on a diff from schwarze@, nl_langinfo also suggested by
stsp@.


# 1.167 05-Mar-2016 nicm

Although we always have en_US.UTF-8 on OpenBSD, some platforms do not,
so fall back to setlocale(LC_CTYPE, ""). tmux requires a UTF-8 locale,
so check with wcwidth() on a UTF-8 character after setlocale().


# 1.166 01-Mar-2016 nicm

Remove unused variables, from Michal Mazurek.


# 1.165 01-Mar-2016 nicm

Use system wcwidth() instead of carrying around UTF-8 width tables.


Revision tags: OPENBSD_5_9_BASE
# 1.164 19-Jan-2016 nicm

I no longer use my SourceForge address so replace it.


# 1.163 08-Dec-2015 nicm

Add hooks infrastructure, basic commands (set-hook, show-hooks) and a
couple of not very useful client hooks. This will eventually let
commands be run at various points and on notifications. Joint work with
Thomas Adam.


# 1.162 24-Nov-2015 nicm

Make environ_set va_args and use it to tidy up some calls. Also add a
missing word in manpage (from jmc).


# 1.161 24-Nov-2015 nicm

Shell command from -c doesn't have to be global, pass it as an argument.


# 1.160 24-Nov-2015 nicm

Tidy the code that works out the socket path, and just use the full path
in the global socket_path rather than copying it.


# 1.159 24-Nov-2015 nicm

Remove malloc_options DEBUG bit.


# 1.158 24-Nov-2015 nicm

Remove the -I part of show-messages which isn't really that useful; the
server start time can now be accessed with a new start_time format (use:
tmux display -p '#{t:start_time}')


# 1.157 24-Nov-2015 nicm

Make the log stuff a bit tidier with some helper functions.


# 1.156 22-Nov-2015 nicm

Add getpw to pledge, makes tmux work in YP environments, discovered by
matthieu, ok deraadt


# 1.155 20-Nov-2015 nicm

Instead of separate tables for different types of options, give each
option a scope type (server, session, window) in one table.


# 1.154 15-Nov-2015 nicm

Accidentally turned off pledge, turn it back on.


# 1.153 14-Nov-2015 nicm

Push stdout and stderr to clients more aggressively, and add an event to
continue if the send fails.


# 1.152 12-Nov-2015 nicm

tmux is UTF-8, so if $TMUX is set (tmux running in tmux), the client is
UTF-8. Also try to make the existing checks more readable.


# 1.151 12-Nov-2015 nicm

Nuke the utf8 and status-utf8 options and make tmux only a UTF-8
terminal. We still support non-UTF-8 terminals outside tmux, but inside
it is always UTF-8 (as when the utf8 and status-utf8 options were on).


# 1.150 11-Nov-2015 nicm

Drop mouse-utf8 option and always turn on UTF-8 mouse if the client says
it supports UTF-8.


# 1.149 28-Oct-2015 nicm

Like options, move the environ struct into environ.c.


# 1.148 27-Oct-2015 nicm

Move struct options into options.c.


# 1.147 27-Oct-2015 nicm

Break the common process set up, event loop and imsg dispatch code
between server and client out into a separate internal API. This will
make it easier to add another process.


# 1.146 25-Oct-2015 deraadt

Let's see if anyone screams about not being able to specify $TMPDIR
for their tmux sockets.

(Over the years, I have seen $TMPDIR set up worse than /tmp many times,
and don't know how this practice infected other parts of the system.
Nothing uses tmpdir(3), nor a huge-temporary-file program like sort.)
ok nicm


# 1.145 23-Oct-2015 nicm

tmux can call pledge() in main with large set and then reduce it
slightly in the server to "stdio rpath wpath cpath fattr unix recvfd
proc exec tty ps".


# 1.144 14-Sep-2015 nicm

Move tzset() from log_open to main.


# 1.143 03-Sep-2015 nicm

A couple of style nits.


# 1.142 01-Sep-2015 nicm

Work out config file when needed not at startup.


# 1.141 30-Aug-2015 nicm

Path from $TMUX does not need to be global anymore.


# 1.140 30-Aug-2015 nicm

Login shell can be a client flag, and move the exec code into client.c.


# 1.139 30-Aug-2015 nicm

Event base does not need to be global.


# 1.138 30-Aug-2015 nicm

Some style nits and dead assignments.


Revision tags: OPENBSD_5_8_BASE
# 1.137 20-Jul-2015 nicm

Add an option (history-file) for a file to save/restore command prompt
history, from Olof-Joachim Frahm.


# 1.136 04-Jun-2015 jmc

tweak SYNOPSIS and usage();


Revision tags: OPENBSD_5_7_BASE
# 1.135 19-Jan-2015 nicm

Make a tmux-%u directory under TMUX_TMPDIR, like TMPDIR.


# 1.134 19-Jan-2015 nicm

Only care about other permissions, allow group to be set.


# 1.133 19-Jan-2015 nicm

Remove unnecessary duplicate S_ISDIR check, from Dmitri Paduchikh.


# 1.132 20-Oct-2014 nicm

Tidy up some includes.


Revision tags: OPENBSD_5_6_BASE
# 1.131 17-Apr-2014 nicm

Remove the "info" message mechanism, this was only used for about five
mostly useless and annoying messages. Change those commands to silence
on success like all the others. Still accept the -q command line flag
and "quiet" server option for now.


# 1.130 31-Mar-2014 nicm

Remove log_debug2 as well and simplify log.c.


Revision tags: OPENBSD_5_5_BASE
# 1.129 16-Feb-2014 nicm

Leftovers from removing 88 colour support, from Theo Buehler.


# 1.128 15-Jan-2014 nicm

Do not attempt to read .tmux.conf if we can't figure out a home
directory, from Tiago Cunha.


# 1.127 09-Jan-2014 nicm

Three small changes from Tiago Cunha:

- Check for truncation when copying path.
- Don't need to use a temporary buffer in screen_set_title.
- Include strerror in output when connecting to server fails.


# 1.126 10-Oct-2013 nicm

We accidentally haven't been using $TMUX to work out the session for a
while and in fact it is less useful that using the client ttyname. So
don't bother and don't pass it from the client. If we need it in future
it is in c->environ.


# 1.125 10-Oct-2013 nicm

Alter how tmux handles the working directory to internally use file
descriptors rather than strings.

- Each session still has a current working directory.

- New sessions still get their working directory from the client that
created them or its attached session if any.

- New windows are created by default in the session working directory.

- The -c flag to new, neww, splitw allows the working directory to be
overridden.

- The -c flag to attach let's the session working directory be changed.

- The default-path option has been removed.

To get the equivalent to default-path '.', do:

bind c neww -c $PWD

To get the equivalent of default-path '~', do:

bind c neww -c ~

This also changes the client identify protocol to be a set of messages rather
than one as well as some other changes that should make it easier to make
backwards-compatible protocol changes in future.


# 1.124 10-Oct-2013 nicm

Merge IDENTIFY_* flags with CLIENT_* flags.


# 1.123 10-Oct-2013 nicm

Don't treat TMUX_TMPDIR as a potential file

The point of setting TMUX_TMPDIR is to then make any labels from -L go
to that directory. In the case of makesocketpath() with no TMUX_TMPDIR
set, would set both the path and the default socket to a file. The
checking of the permissions on the file worked fine in that case, but
when TMUX_TMPDIR is set, won't work on a directory.

This fixes the problem by ensuring the check on the permissions is
performed on directories only.

By Thomas Adam.


# 1.122 05-Oct-2013 nicm

Fix previous not to leak fd on failure, whoops.


# 1.121 05-Oct-2013 nicm

Use open(".")/fchdir() to save and restore current directory rather than
getcwd()/chdir().


Revision tags: OPENBSD_5_4_BASE
# 1.120 24-Apr-2013 nicm

Rename global configuration define.


# 1.119 11-Apr-2013 nicm

Call setlocale(LC_TIME) at startup.


# 1.118 27-Mar-2013 nicm

Add TMUX_TMPDIR variable to put the socket directory outside
TMPDIR. From Ben Boeckel.


# 1.117 27-Mar-2013 nicm

Remove tmux's (already minimal) 88 colour support. Such terminals are
few and unnecessary.


# 1.116 25-Mar-2013 nicm

Rename session idx to session id throughout and add $ prefix to targets
to use it, extended from a diff from George Nachman.


# 1.115 24-Mar-2013 nicm

Add a command queue to standardize and simplify commands that call other
commands and allow a command to block execution of subsequent
commands. This allows run-shell and if-shell to be synchronous which has
been much requested.

Each client has a default command queue and commands are consumed one at
a time from it. A command may suspend execution from the queue by
returning CMD_RETURN_WAIT and then resume it by calling cmd_continue() -
for example run-shell does this from the callback that is fired after
the job is freed.

When the command queue becomes empty, command clients are automatically
exited (unless attaching). A callback is also fired - this is used for
nested commands in, for example, if-shell which can block execution of
the client's cmdq until a new cmdq becomes empty.

Also merge all the old error/info/print functions together and lose the
old curclient/cmdclient distinction - a cmdq is bound to one client (or
none if in the configuration file), this is a command client if
c->session is NULL otherwise an attached client.


Revision tags: OPENBSD_5_3_BASE
# 1.114 27-Nov-2012 nicm

Correctly aggregate together errors from nested config files (with
source-file). Fix by Thomas Adam, reported by Sam Livingstone-Gray


# 1.113 26-Nov-2012 nicm

Call realpath earlier on the socket directory path rather than on the
socket file path because the latter may not exist yet and in that case
realpath is allowed to fail. From Romain Francoise.


Revision tags: OPENBSD_5_2_BASE
# 1.112 10-Jul-2012 nicm

xfree is not particularly helpful, remove it. From Thomas Adam.


# 1.111 18-Jun-2012 nicm

Add a skeleton mode to tmux (called "control mode") that let's tmux
commands be sent and output received on stdout. This can be used to
integrate with other terminal emulators and should allow some other
things to be made simpler later. More to come so doesn't do much yet and
deliberately not documented.


# 1.110 30-May-2012 nicm

Do not use stderr for log file and don't call log_close when not needed.


# 1.109 25-May-2012 nicm

Simplify logging and just fprintf(stderr, ...) for early errors.


Revision tags: OPENBSD_5_1_BASE
# 1.108 21-Jan-2012 nicm

Drop the ability to have a list of keys in the prefix in favour of two
separate options, prefix and prefix2. This simplifies the code and gets
rid the data options type which was only used for this one option.

Also add a -2 flag to send-prefix to send the secondary prefix key,
fixing a cause of minor irritation.

People who want three prefix keys are out of luck :-).


# 1.107 23-Oct-2011 nicm

Try to resolve relative paths for loadb and saveb (first using client
working directory if any then default-path or session wd).


# 1.106 23-Oct-2011 nicm

Ignore LC_ALL and LC_CTYPE if they are empty as well as unset.


# 1.105 25-Sep-2011 nicm

Reject $SHELL if it is not a full path.


Revision tags: OPENBSD_5_0_BASE
# 1.104 04-Mar-2011 nicm

Two fixes by Micah Cowan: make mouse work properly beyond >127 on signed
char architectures and properly parse $TMUX by stopping the socket path
at the first comma.


Revision tags: OPENBSD_4_9_BASE
# 1.103 23-Jan-2011 nicm

Set $TMUX without the session when background jobs are run.


# 1.102 12-Jan-2011 nicm

Use TMPDIR if set, from Han Boetes.


# 1.101 08-Jan-2011 nicm

Move all calls to fcntl(...O_NONBLOCK) into a function and clear the
flag on the stdio file descriptors before closing them (fixes things
like "tmux ls && cat").


# 1.100 03-Jan-2011 nicm

Support for UTF-8 mouse input (\033[1005h). This was added in xterm 262
and supports larger terminals than the older way.

If the new mouse-utf8 option is on, UTF-8 mouse input is enabled for all
UTF-8 terminals. The option defaults to on if LANG etc are set in the
same manner as the utf8 option.

With help and based on code from hsim at gmx.li.


# 1.99 01-Jan-2011 nicm

Move the user-visible parts of all options (names, types, limit, default
values) together into one set of tables in options-table.c. Also clean
up and simplify cmd-set-options.c and move a common print function into
option-table.c.


# 1.98 30-Dec-2010 nicm

Change from a per-session stack of buffers to one global stack which is
much more convenient and also simplifies lot of code. This renders
copy-buffer useless and makes buffer-limit now a server option.

By Tiago Cunha.


# 1.97 19-Dec-2010 nicm

Add other-pane-height and other-pane-width options, allowing the width
or height of the smaller panes in the main-horizontal and main-vertical
layouts to be set. Mostly from David Goodlad.


# 1.96 08-Dec-2010 nicm

In the built-in layouts, distribute the panes more evenly. Set the
default value of main-pane-width to 80, rather than 81. By Micah Cowan.


# 1.95 06-Dec-2010 nicm

Add an option to alert (monitor) for silence (lack of activity) in a
window. From Thomas Adam.


# 1.94 29-Nov-2010 nicm

If VISUAL or EDITOR contains "vi", configure mode-keys and status-keys
to vi.

Based on a diff from martynas@, previously requested by a couple of
other people.


# 1.93 11-Nov-2010 nicm

Add XAUTHORITY to update-environment, requested by Andreas Kloeckner.


# 1.92 18-Oct-2010 nicm

Merge the before and after attach client code into one in client.c
(instead of two in tmux.c and client.c).


# 1.91 16-Oct-2010 nicm

Make stdio blocking again before calling shell command with -c.


# 1.90 16-Oct-2010 nicm

Trying to set FD_CLOEXEC on every fd is a lost cause, just use
closefrom() before exec.


# 1.89 14-Oct-2010 nicm

Use an explicit event rather than event_once for the main event so it
can be removed when the client becomes ready.


# 1.88 26-Sep-2010 nicm

Two new options:

- server option "exit-unattached" makes the server exit when no clients
are attached, even if sessions are present;

- session option "destroy-unattached" destroys a session once no clients
are attached to it.

These are useful for preventing tmux remaining in the background where
it is undesirable and when using tmux as a login shell to keep a limit
on new sessions.


# 1.87 19-Aug-2010 nicm

Do not call event_del() for signals after fork(), just use sigaction()
directly instead - calling libevent functions after fork() w/o
event_reinit() is a bad idea, even if in this case it was harmless.


Revision tags: OPENBSD_4_8_BASE
# 1.86 04-Aug-2010 deraadt

switch back to kqueue for now, since (a) kqueue has been fixed to deal
with strange devices and (b) since there appears to be a bull in the
poll code in libevent as well...
requested by nicm who is away


# 1.85 24-Jul-2010 nicm

kqueue(2) is currently broken when used with /dev/null and a few other
devices.

An upcoming fix for some problems with the client stdout/stderr handling
relies on it working, so make tmux force libevent to use poll(2) via
EVENT_NOKQUEUE, until we have fixed kqueue.


# 1.84 11-Jul-2010 nicm

Return the command client return code with MSG_EXIT now that MSG_ERROR and
MSG_PRINT are unused.

New clients should be compatible with old tmux servers but vice versa may print
an error.


# 1.83 28-Jun-2010 nicm

Send all three of stdin, stdout, stderr from the client to the server, so that
commands can directly make use of them. This means that load-buffer and
save-buffer can have "-" as the file to read from stdin or write to stdout.

This is a protocol version bump so the tmux server will need to be restarted
after upgrade (or an older client used).


# 1.82 27-Jun-2010 nicm

Store the current working directory in the session, change the default-path
option to default to empty and make that mean that the stored session CWD is
used.


# 1.81 27-Jun-2010 nicm

New option, detach-on-destroy, to set what happens to a client when the session
it is attached to is destroyed. If on (the default), it is detached; if off, it
is switched to the most recently active session.


# 1.80 26-Jun-2010 nicm

Setting the cmdlist pointer in the bind-key to NULL to prevent it being freed
after the command is executing is bogus because it may still be needed if the
same command is going to be executed again (for example if you "bind-key a
bind-key b ..."). Making a copy is hard, so instead add a reference count to
the cmd_list.

While here, also print bind-key -n and the rest of the flags properly.

Fixes problem reported by mcbride@.


# 1.79 14-May-2010 nicm

Colour+attribute options for status line alerts, from Alex Alexander.


# 1.78 04-May-2010 nicm

Put this back in with the initialisation in the right order.


# 1.77 04-May-2010 nicm

Revert last change, it appears to be broken somehow.


# 1.76 03-May-2010 nicm

Make signal handler setup/teardown two common functions instead of six,
and reset SIGCHLD after fork to fix problems with some shells. From
Romain Francois.


# 1.75 28-Apr-2010 nicm

Make the active pane border have a green foreground instead of
background by default.


# 1.74 18-Apr-2010 nicm

Catch SIGCHLD to avoid a zombie, from patrick keshishian.


Revision tags: OPENBSD_4_7_BASE
# 1.73 22-Feb-2010 nicm

Option to set the characters considered word separators in copy mode, from
Micah Cowan.


# 1.72 08-Feb-2010 nicm

Add an option to disable the smcup/rmcup alternate screen behaviour inside
tmux. From clemens fischer.


# 1.71 06-Feb-2010 nicm

Change nested check to compare server socket path rather than just assuming
that if $TMUX is set it is nested. From Micah Cowan.


# 1.70 06-Feb-2010 nicm

Clean up $TMUX parsing, from Micah Cowan, tweaked by me.


# 1.69 06-Feb-2010 nicm

Instead of bailing out on the first configuration file error, carry on,
collecting all the errors, then start with the active window in more mode
displaying them.


# 1.68 04-Feb-2010 nicm

Read the path from $TMUX if it is present and -L and -S are not given. Based on
a diff from Micah Cowan.


# 1.67 04-Feb-2010 nicm

Option to display the active pane in a different colour with the display-panes
command. From Paul Hoffman, thanks.


# 1.66 03-Jan-2010 nicm

Options to set the colour of the pane borders, with different colours for the
active pane.


# 1.65 14-Dec-2009 nicm

New server option, escape-time, to set the timeout used to detect if escapes
are alone or part of a function key or meta sequence.


# 1.64 11-Dec-2009 nicm

Use quiet variable, and add missing sentinel to options array.


# 1.63 10-Dec-2009 nicm

Add "server options" which are server-wide and not bound to a session or
window. Set and displayed with "set -s" and "show -s".

Currently the only option is "quiet" (like command-line -q, allowing it to be
set from .tmux.conf), but others will come along.


# 1.62 03-Dec-2009 nicm

Massive spaces->tabs and trailing whitespace cleanup, hopefully for the last
time now I've configured emacs to make them displayed in really annoying
colours...


# 1.61 26-Nov-2009 nicm

Remove a couple of unused arguments where possible, and add /* ARGSUSED */ to
the rest to reduce lint output.


# 1.60 19-Nov-2009 nicm

Two new options, window-status-format and window-status-current-format, which
allow the format of each window in the status line window list to be controlled
using similar # sequences as status-left/right.

This diff also moves part of the way towards UTF-8 support in window names but
it isn't quite there yet.


# 1.59 19-Nov-2009 nicm

Revert to xterm-keys off by default. It was on as an experiment to see if the
option could be removed, but it affects vi, so we have to keep the option, and
a conservative default is better.


# 1.58 18-Nov-2009 nicm

Add a per-client log of status line messages displayed while that client
exists. A new message-limit session option sets the maximum number of entries
and a command, show-messages, shows the log (bound to ~ by default).

This (and prompt history) might be better as a single global log but until
there are global options it is easier for them to be per client.


# 1.57 10-Nov-2009 nicm

There is no real standard for modifier plus function keys. Previously, tmux
output some from rxvt but in other ways did the same as xterm or other
terminals, but this is a bit inconsistent.

xterm's method is fairly sensible and we already support it (xterm-keys), so
enable it by default instead.


# 1.56 04-Nov-2009 nicm

A couple of minor cosmetic changes.


# 1.55 04-Nov-2009 nicm

Initial changes to move tmux to libevent.

This moves the client-side loops are pretty much fully over to event-based only
(tmux.c and client.c) but server-side (server.c and friends) treats libevent as
a sort of clever poll, waking up after every event to run various things.

Moving the server stuff over to bufferevents and timers and so on will come
later.


# 1.54 04-Nov-2009 nicm

Change declaration and use of malloc_options to be more standard, from Tim van
der Molen.


# 1.53 26-Oct-2009 deraadt

tabs are better; ok nicm


# 1.52 25-Oct-2009 nicm

Remove the -d flag to tmux and just use op/AX to detect default colours.

Irritatingly, although op can be used to tell if a terminal supports default
colours, it can't be used to set them because in some terminfo descriptions it
resets attributes as a side-effect (acts as sgr0) and in others it doesn't, so
it is not possible to determine reliably what the terminal state will be
afterwards. So if AX is missing and op is present, tmux just sends sgr0.

Anyone using -d for a terminal who finds they actually needed it can replace it
using terminal-overrides, but please let me know as it is probably an omission
from terminfo.


# 1.51 22-Oct-2009 nicm

Merge prepare_cmd into main as it is short and only called once.


# 1.50 21-Oct-2009 nicm

Client tidying: get rid of client_ctx struct in favour of two variables in
client.c, and move the functions in client-fn.c into other files.


# 1.49 10-Oct-2009 nicm

New option, mouse-select-pane. If on, the mouse may be used to select the
current pane.

Suggested by sthen@ and also by someone else ages ago who I have forgotten.


# 1.48 10-Oct-2009 nicm

Support for individual session idle time locking. May be enabled by turning off
the lock-server option (it is on by default). When this is off, each session
locks when it has been idle for the lock-after-time setting. When on, the
entire server locks when ALL sessions have been idle for their individual
lock-after-time settings.

This replaces one global-only option (lock-after-time) with another
(lock-server), but the default behaviour is usually preferable so there don't
seem to be many alternatives.

Diff/idea largely from Thomas Adam, tweaked by me.


# 1.47 09-Oct-2009 nicm

Add a simple synchronize-panes window option: when set, all input to any pane
that is part of the window is also sent to all other panes in the same
window. Suggested by several, most recently Tomasz Pajor.


# 1.46 23-Sep-2009 nicm

Support -c like sh(1) to execute a command, useful when tmux is a login
shell. Suggested by halex@.

This includes another protocol version increase (the last for now) so again
restart the tmux server before upgrading.


# 1.45 23-Sep-2009 nicm

Remove the internal tmux locking and instead detach each client and run the
command specified by a new option "lock-command" (by default "lock -np") in
each client.

This means each terminal has to be unlocked individually but simplifies the
code and allows the system password to be used to unlock.

Note that the set-password command is gone, so it will need to be removed from
configuration files, and the -U command line flag has been removed.

This is the third protocol version change so again it is best to stop the tmux
server before upgrading.


# 1.44 22-Sep-2009 nicm

Permit multiple prefix keys to be defined, separated by commas, for example:

set -g prefix ^a,^b

Any key in the list acts as the prefix. The send-prefix command always sends
the first key in the list.


# 1.43 18-Sep-2009 nicm

New option, set-titles-string, to allow the window title to be specified (as
for status-left/right) if set-titles is on. Also only update the title when the
status line is being redrawn.


# 1.42 04-Sep-2009 nicm

Tidy main and make it a bit easier to read.


# 1.41 02-Sep-2009 nicm

Accept -l to make it easier for people who use tmux as a login shell to use
$SHELL. Originally from martynas@, tweaked by me.


# 1.40 02-Sep-2009 nicm

When incorrect passwords are entered, behave similarly to login(1) and backoff
for a bit. Based on a diff from martynas@.


# 1.39 01-Sep-2009 nicm

When using tmux as a login shell, there is currently no way to specify a shell
to be used as a login shell inside tmux, so add a default-shell session option.
This sets the shell invoked as a login shell when the default-command option is
empty.

The default option value is whichever of $SHELL, getpwuid(getuid())'s pw_shell
or /bin/sh is valid first.

Based on a diff from martynas@, changed by me to be a session option rather
than a window option.


# 1.38 01-Sep-2009 nicm

Use "Password:" with no space for password prompts and don't display a *s for
the password, like pretty much everything else. From martynas@ with minor
tweaks by me.


# 1.37 01-Sep-2009 nicm

Sort cases same as getopt argument, from martynas.


# 1.36 31-Aug-2009 nicm

Add a new display-panes command, with two options (display-panes-colour and
display-panes-time), which displays a visual indication of the number of each
pane.


# 1.35 23-Aug-2009 nicm

Add some other obvious variables to update-environment (WINDOWID SSH_ASKPASS
SSH_AUTH_SOCK SSH_AGENT_PID SSH_CONNECTION) so they are updated in the session
environment on new/attach.


# 1.34 13-Aug-2009 nicm

Disable mode-mouse (mouse in copy/choice mode) by default as it isn't very
useful at the moment and causes confusion.


# 1.33 13-Aug-2009 nicm

Add a base-index session option to specify the first index checked when looking
for an index for a new window.


# 1.32 12-Aug-2009 nicm

When started as the shell, __progname contains a leading -, so hardcode "tmux"
for socket path and log files, and strip it when working out the shell.


# 1.31 11-Aug-2009 nicm

Switch tmux to use imsg. This is the last major change to make the
client-server protocol more resilient and make the protocol versioning work
properly. In future, the only things requiring a protocol version bump will be
changes in the message structs, and (when both client and server have this
change) mixing different versions should nicely report an error message.

As a side effect this also makes the code tidier, fixes a problem with the way
errors reported during server startup were handled, and supports fd passing
(which will be used in future).

Looked over by eric@, thanks.

Please note that mixing a client with this change with an older server or vice
versa may cause tmux to crash or hang - tmux should be completely exited before
upgrading.


# 1.30 10-Aug-2009 nicm

No arguments are the same as new-session and this requires the environment to
be sent, so set that flag too when argc == 0.


# 1.29 08-Aug-2009 nicm

Infrastructure and commands to manage the environment for processes started
within tmux.

There is a global environment, copied from the external environment when the
server is started and each sesssion has an (initially empty) session
environment which overrides it.

New commands set-environment and show-environment manipulate or display the
environments.

A new session option, update-environment, is a space-separated list of
variables which are updated from the external environment into the session
environment every time a new session is created - the default is DISPLAY.


# 1.28 08-Aug-2009 nicm

Options to set the colours and attributes for status-left/-right. From Thomas
Adam, thanks.


# 1.27 05-Aug-2009 nicm

If colours are not supported by the terminal, try to emulate a coloured
background by setting or clearing the reverse attribute.

This makes a few applications which don't use the reverse attribute themselves
a little happier, and allows the status, message and mode options to have
default attributes and fg/bg options that work as expected when set as reverse.


# 1.26 04-Aug-2009 nicm

Check for "UTF8" as well as "UTF-8" in LANG etc as it seems this may also
appear.


# 1.25 03-Aug-2009 nicm

Add a terminal-overrides session option allowing individual terminfo(5) entries
to be overridden. The 88col/256col checks are now moved into the default
setting and out of the code.

Also remove a couple of old workarounds for xterm and rxvt which are no longer
necessary (tmux can emulate them if missing).


# 1.24 30-Jul-2009 nicm

Add a mode-mouse option to prevent tmux taking over the mouse in choice or copy
modes.


# 1.23 29-Jul-2009 nicm

Rename struct hdrtype to msgtype which is a better name and can be used even
when struct hdr disappears.


# 1.22 29-Jul-2009 nicm

Taking account of the "s, 22 not 24 is the maximum length of #T in status-right
to prevent the date being cut off.


# 1.21 26-Jul-2009 nicm

Make all messages sent between the client and server fixed size.

This is the first of two changes to make the protocol more resilient and less
sensitive to other changes in the code, particularly with commands. The client
now packs argv into a buffer and sends it to the server for parsing, rather
than doing it itself and sending the parsed command data.

As a side-effect this also removes a lot of now-unused command marshalling
code.

Mixing a server without this change and a client with or vice versa will cause
tmux to hang or crash, please ensure that tmux is entirely killed before
upgrading.


# 1.20 22-Jul-2009 nicm

Pass a set of flags into client_init rather than just a start_server
variable. Only one flag now but more to come later.


# 1.19 20-Jul-2009 nicm

Display the number of failed password attempts (if any) when the server is
locked. From Tom Doherty.


# 1.18 20-Jul-2009 nicm

Add a status-justify option to allow the window list in the status line to be
positioned at the left, centre, or right.


# 1.17 20-Jul-2009 nicm

New options, window-status-current-{fg,bg,attr}, to set the fg, bg and
attributes with which the current window is shown in the status line. From
Johan Friis, thanks.


# 1.16 18-Jul-2009 nicm

Add three new session options: visual-activity, visual-bell, visual-content. If
these are enabled (and the monitor-activity, bell-actio and monitor-content
options are configurated appropriately), when activity, a bell, or content is
detected, a message is shown.

Also tidy up the bell/activity/content code in server.c slightly and fix a
couple of errors.


# 1.15 17-Jul-2009 nicm

If -u is specified or UTF-8 is otherwise detected when the server is started,
enable the utf8 and status-utf8 optons. While here, note in the man page that
the server is started with the first session and exits when none remain.


# 1.14 10-Jul-2009 nicm

Add a default-terminal option to set the starting value of $TERM in new
windows.

This is "screen" by default and must be either that or something closely
related. This does makes it easier to customise it if necessary.


# 1.13 08-Jul-2009 nicm

Just appending -l to $SHELL to create a login shell is wrong: -l is not POSIX,
and some people may use shells which do not support it. Instead, make an empty
default-command option mean a login shell, and fork it with a - in argv[0]
which is the method used by login(1).

Also fix the automatic-rename code to handle this correctly and to strip a
leading - if present.


# 1.12 07-Jul-2009 nicm

Rename the global options variables to be shorter and to make session options
clear. No functional change, getting this out of the way to make later options
changes easier.


Revision tags: OPENBSD_4_6_BASE
# 1.11 25-Jun-2009 nicm

If getcwd() fails, use the user's home directory, or /, instead of failing with
an error.


# 1.10 25-Jun-2009 nicm

Remove error about using -L and -S together which was never displayed as
logging wasn't yet enabled, was unnecessary, and contradicted the man page
which says using -S will cause -L to be ignored.


# 1.9 23-Jun-2009 nicm

LC_ALL overrides LC_CTYPE and LANG. Comment was correct but the code
wrong. Pointed out by Hannah Schroeter, thanks.


# 1.8 05-Jun-2009 nicm

Check the first of LC_CTYPE, LC_ALL and LANG, rather than just the last, when
trying to decide about UTF-8, and use strcasestr. Reported by Geert Hendrickx.


# 1.7 04-Jun-2009 nicm

Zero the password given to -U in the client as well.


# 1.6 03-Jun-2009 nicm

Do not set the window title by default (make set-titles option default to off),
wiping over the title is rude and annoying. Agreed by several.


# 1.5 03-Jun-2009 nicm

New session option, status-utf8, to control the interpretation of top-bit-set
characters in status-left and status-right (if on, they are treated as UTF-8;
otherwise passed through).


# 1.4 02-Jun-2009 sobrado

remove unused flag; while here, make usage's output fit on 80-column displays.


# 1.3 02-Jun-2009 pyr

spawn login shells by default, adapt manpage bits as well.
ok nicm@


# 1.2 02-Jun-2009 ray

Don't leak memory if multiple -f flags are given.

OK nicm@


# 1.1 01-Jun-2009 nicm

Import tmux, a terminal multiplexor allowing (among other things) a single
terminal to be switched between several different windows and programs
displayed on one terminal be detached from one terminal and moved to another.

ok deraadt pirofti


# 1.194 17-Mar-2020 nicm

Ignore default-shell (and use /bin/sh) if it invalid not just if it is
tmux itself, also refuse to set the option to something invalid in the
first place. GitHub issue 2120.


# 1.193 12-Mar-2020 nicm

When the server socket is given by the user with -S, create it with
umask 177 instead of 117 because it may not be in a safe directory like
the default directory in /tmp. The user can chmod it more open after it
is created if they want.


# 1.192 28-Jan-2020 nicm

-V also needs to go in usage.


# 1.191 28-Jan-2020 nicm

Reduce a difference with portable tmux by adding the -V flag and
#{version} format; on OpenBSD these just report the OpenBSD version.


# 1.190 14-Oct-2019 nicm

Memory leaks, from Igor Wong in GitHub issue 1934.


Revision tags: OPENBSD_6_6_BASE
# 1.189 20-Jun-2019 nicm

Add a per-pane option set. Pane options inherit from window options (so
there should be no change to existing behaviour) and are set and shown
with set-option -p and show-options -p.

Change remain-on-exit and window-style/window-active-style to be pane
options (some others will be changed later).

This makes select-pane -P and -g unnecessary so no longer document them
(they still work) and no longer document set-window-option and
show-window-options in favour of set-option -w and show-options -w.


# 1.188 26-Apr-2019 nicm

Merge hooks into options and make each one an array option. This allows
multiple commands to be easily bound to one hook. set-hook and
show-hooks remain but they are now variants of set-option and
show-options. show-options now has a -H flag to show hooks (by default
they are not shown).


Revision tags: OPENBSD_6_5_BASE
# 1.187 22-Nov-2018 nicm

Do not use PWD unless it actually matches the real working directory.


Revision tags: OPENBSD_6_3_BASE OPENBSD_6_4_BASE
# 1.186 12-Jan-2018 nicm

Improve error message if creating socket parent directory fails, from
Thomas Adam for GitHub issue 1215.


# 1.185 01-Jan-2018 nicm

Prefer PWD for current directory if present in client, from Wei Zhao in
GitHub issue 1183.


Revision tags: OPENBSD_6_2_BASE
# 1.184 12-Jul-2017 nicm

Make shell_command a global like other stuff rather than making it an
exception and using callback argument.


# 1.183 03-Jul-2017 nicm

Try C.UTF-8 which is also a commonly useful locale on some platforms,
from Romain Francoise.


# 1.182 22-Apr-2017 nicm

Do not need getopt.h.


# 1.181 20-Apr-2017 nicm

Use fdforkpty() instead of our own unwrapped versions.


# 1.180 19-Apr-2017 nicm

Style nits and a missing cast.


# 1.179 16-Apr-2017 nicm

Memory leak, from David CARLIER.


Revision tags: OPENBSD_6_1_BASE
# 1.178 21-Mar-2017 nicm

Use uid_t for UID not u_int.


# 1.177 16-Feb-2017 nicm

Style nits.


# 1.176 23-Jan-2017 nicm

Open /dev/ptm before pledge() and save it to be used for PTMGET later
(this means inlining forkpty()).

ok deraadt


# 1.175 15-Jan-2017 nicm

Major tidy up and rework of options tree and set-option/show-options
commands this pushes more of the code into options.c and ties it more
closely to the options table rather than having an unnecessary
split. Also add support for array options (will be used later). Only
(intentional) user visible change is that show-options output is now
passed through vis(3) with VIS_DQ so quotes are escaped.


# 1.174 12-Jan-2017 nicm

Simplify appending to string options.


# 1.173 09-Dec-2016 nicm

Spacing nits.


# 1.172 11-Oct-2016 nicm

Add static in window-*.c and move some internal functions out of tmux.h.


# 1.171 10-Oct-2016 nicm

Loads more static, except for cmd-*.c and window-*.c.


Revision tags: OPENBSD_6_0_BASE
# 1.170 27-May-2016 nicm

Use getprogname() instead of __progname to make portability easier.


# 1.169 04-May-2016 nicm

Fix up a couple of long lines.


# 1.168 05-Mar-2016 nicm

If setlocale("en_US.UTF-8") succeeds, then don't do the check for UTF-8
locale since if it isn't UTF-8 the system is broken anyway. If it fails,
try "" and check for UTF-8 with nl_langinfo(CODESET) rather than
wcwidth(). Based on a diff from schwarze@, nl_langinfo also suggested by
stsp@.


# 1.167 05-Mar-2016 nicm

Although we always have en_US.UTF-8 on OpenBSD, some platforms do not,
so fall back to setlocale(LC_CTYPE, ""). tmux requires a UTF-8 locale,
so check with wcwidth() on a UTF-8 character after setlocale().


# 1.166 01-Mar-2016 nicm

Remove unused variables, from Michal Mazurek.


# 1.165 01-Mar-2016 nicm

Use system wcwidth() instead of carrying around UTF-8 width tables.


Revision tags: OPENBSD_5_9_BASE
# 1.164 19-Jan-2016 nicm

I no longer use my SourceForge address so replace it.


# 1.163 08-Dec-2015 nicm

Add hooks infrastructure, basic commands (set-hook, show-hooks) and a
couple of not very useful client hooks. This will eventually let
commands be run at various points and on notifications. Joint work with
Thomas Adam.


# 1.162 24-Nov-2015 nicm

Make environ_set va_args and use it to tidy up some calls. Also add a
missing word in manpage (from jmc).


# 1.161 24-Nov-2015 nicm

Shell command from -c doesn't have to be global, pass it as an argument.


# 1.160 24-Nov-2015 nicm

Tidy the code that works out the socket path, and just use the full path
in the global socket_path rather than copying it.


# 1.159 24-Nov-2015 nicm

Remove malloc_options DEBUG bit.


# 1.158 24-Nov-2015 nicm

Remove the -I part of show-messages which isn't really that useful; the
server start time can now be accessed with a new start_time format (use:
tmux display -p '#{t:start_time}')


# 1.157 24-Nov-2015 nicm

Make the log stuff a bit tidier with some helper functions.


# 1.156 22-Nov-2015 nicm

Add getpw to pledge, makes tmux work in YP environments, discovered by
matthieu, ok deraadt


# 1.155 20-Nov-2015 nicm

Instead of separate tables for different types of options, give each
option a scope type (server, session, window) in one table.


# 1.154 15-Nov-2015 nicm

Accidentally turned off pledge, turn it back on.


# 1.153 14-Nov-2015 nicm

Push stdout and stderr to clients more aggressively, and add an event to
continue if the send fails.


# 1.152 12-Nov-2015 nicm

tmux is UTF-8, so if $TMUX is set (tmux running in tmux), the client is
UTF-8. Also try to make the existing checks more readable.


# 1.151 12-Nov-2015 nicm

Nuke the utf8 and status-utf8 options and make tmux only a UTF-8
terminal. We still support non-UTF-8 terminals outside tmux, but inside
it is always UTF-8 (as when the utf8 and status-utf8 options were on).


# 1.150 11-Nov-2015 nicm

Drop mouse-utf8 option and always turn on UTF-8 mouse if the client says
it supports UTF-8.


# 1.149 28-Oct-2015 nicm

Like options, move the environ struct into environ.c.


# 1.148 27-Oct-2015 nicm

Move struct options into options.c.


# 1.147 27-Oct-2015 nicm

Break the common process set up, event loop and imsg dispatch code
between server and client out into a separate internal API. This will
make it easier to add another process.


# 1.146 25-Oct-2015 deraadt

Let's see if anyone screams about not being able to specify $TMPDIR
for their tmux sockets.

(Over the years, I have seen $TMPDIR set up worse than /tmp many times,
and don't know how this practice infected other parts of the system.
Nothing uses tmpdir(3), nor a huge-temporary-file program like sort.)
ok nicm


# 1.145 23-Oct-2015 nicm

tmux can call pledge() in main with large set and then reduce it
slightly in the server to "stdio rpath wpath cpath fattr unix recvfd
proc exec tty ps".


# 1.144 14-Sep-2015 nicm

Move tzset() from log_open to main.


# 1.143 03-Sep-2015 nicm

A couple of style nits.


# 1.142 01-Sep-2015 nicm

Work out config file when needed not at startup.


# 1.141 30-Aug-2015 nicm

Path from $TMUX does not need to be global anymore.


# 1.140 30-Aug-2015 nicm

Login shell can be a client flag, and move the exec code into client.c.


# 1.139 30-Aug-2015 nicm

Event base does not need to be global.


# 1.138 30-Aug-2015 nicm

Some style nits and dead assignments.


Revision tags: OPENBSD_5_8_BASE
# 1.137 20-Jul-2015 nicm

Add an option (history-file) for a file to save/restore command prompt
history, from Olof-Joachim Frahm.


# 1.136 04-Jun-2015 jmc

tweak SYNOPSIS and usage();


Revision tags: OPENBSD_5_7_BASE
# 1.135 19-Jan-2015 nicm

Make a tmux-%u directory under TMUX_TMPDIR, like TMPDIR.


# 1.134 19-Jan-2015 nicm

Only care about other permissions, allow group to be set.


# 1.133 19-Jan-2015 nicm

Remove unnecessary duplicate S_ISDIR check, from Dmitri Paduchikh.


# 1.132 20-Oct-2014 nicm

Tidy up some includes.


Revision tags: OPENBSD_5_6_BASE
# 1.131 17-Apr-2014 nicm

Remove the "info" message mechanism, this was only used for about five
mostly useless and annoying messages. Change those commands to silence
on success like all the others. Still accept the -q command line flag
and "quiet" server option for now.


# 1.130 31-Mar-2014 nicm

Remove log_debug2 as well and simplify log.c.


Revision tags: OPENBSD_5_5_BASE
# 1.129 16-Feb-2014 nicm

Leftovers from removing 88 colour support, from Theo Buehler.


# 1.128 15-Jan-2014 nicm

Do not attempt to read .tmux.conf if we can't figure out a home
directory, from Tiago Cunha.


# 1.127 09-Jan-2014 nicm

Three small changes from Tiago Cunha:

- Check for truncation when copying path.
- Don't need to use a temporary buffer in screen_set_title.
- Include strerror in output when connecting to server fails.


# 1.126 10-Oct-2013 nicm

We accidentally haven't been using $TMUX to work out the session for a
while and in fact it is less useful that using the client ttyname. So
don't bother and don't pass it from the client. If we need it in future
it is in c->environ.


# 1.125 10-Oct-2013 nicm

Alter how tmux handles the working directory to internally use file
descriptors rather than strings.

- Each session still has a current working directory.

- New sessions still get their working directory from the client that
created them or its attached session if any.

- New windows are created by default in the session working directory.

- The -c flag to new, neww, splitw allows the working directory to be
overridden.

- The -c flag to attach let's the session working directory be changed.

- The default-path option has been removed.

To get the equivalent to default-path '.', do:

bind c neww -c $PWD

To get the equivalent of default-path '~', do:

bind c neww -c ~

This also changes the client identify protocol to be a set of messages rather
than one as well as some other changes that should make it easier to make
backwards-compatible protocol changes in future.


# 1.124 10-Oct-2013 nicm

Merge IDENTIFY_* flags with CLIENT_* flags.


# 1.123 10-Oct-2013 nicm

Don't treat TMUX_TMPDIR as a potential file

The point of setting TMUX_TMPDIR is to then make any labels from -L go
to that directory. In the case of makesocketpath() with no TMUX_TMPDIR
set, would set both the path and the default socket to a file. The
checking of the permissions on the file worked fine in that case, but
when TMUX_TMPDIR is set, won't work on a directory.

This fixes the problem by ensuring the check on the permissions is
performed on directories only.

By Thomas Adam.


# 1.122 05-Oct-2013 nicm

Fix previous not to leak fd on failure, whoops.


# 1.121 05-Oct-2013 nicm

Use open(".")/fchdir() to save and restore current directory rather than
getcwd()/chdir().


Revision tags: OPENBSD_5_4_BASE
# 1.120 24-Apr-2013 nicm

Rename global configuration define.


# 1.119 11-Apr-2013 nicm

Call setlocale(LC_TIME) at startup.


# 1.118 27-Mar-2013 nicm

Add TMUX_TMPDIR variable to put the socket directory outside
TMPDIR. From Ben Boeckel.


# 1.117 27-Mar-2013 nicm

Remove tmux's (already minimal) 88 colour support. Such terminals are
few and unnecessary.


# 1.116 25-Mar-2013 nicm

Rename session idx to session id throughout and add $ prefix to targets
to use it, extended from a diff from George Nachman.


# 1.115 24-Mar-2013 nicm

Add a command queue to standardize and simplify commands that call other
commands and allow a command to block execution of subsequent
commands. This allows run-shell and if-shell to be synchronous which has
been much requested.

Each client has a default command queue and commands are consumed one at
a time from it. A command may suspend execution from the queue by
returning CMD_RETURN_WAIT and then resume it by calling cmd_continue() -
for example run-shell does this from the callback that is fired after
the job is freed.

When the command queue becomes empty, command clients are automatically
exited (unless attaching). A callback is also fired - this is used for
nested commands in, for example, if-shell which can block execution of
the client's cmdq until a new cmdq becomes empty.

Also merge all the old error/info/print functions together and lose the
old curclient/cmdclient distinction - a cmdq is bound to one client (or
none if in the configuration file), this is a command client if
c->session is NULL otherwise an attached client.


Revision tags: OPENBSD_5_3_BASE
# 1.114 27-Nov-2012 nicm

Correctly aggregate together errors from nested config files (with
source-file). Fix by Thomas Adam, reported by Sam Livingstone-Gray


# 1.113 26-Nov-2012 nicm

Call realpath earlier on the socket directory path rather than on the
socket file path because the latter may not exist yet and in that case
realpath is allowed to fail. From Romain Francoise.


Revision tags: OPENBSD_5_2_BASE
# 1.112 10-Jul-2012 nicm

xfree is not particularly helpful, remove it. From Thomas Adam.


# 1.111 18-Jun-2012 nicm

Add a skeleton mode to tmux (called "control mode") that let's tmux
commands be sent and output received on stdout. This can be used to
integrate with other terminal emulators and should allow some other
things to be made simpler later. More to come so doesn't do much yet and
deliberately not documented.


# 1.110 30-May-2012 nicm

Do not use stderr for log file and don't call log_close when not needed.


# 1.109 25-May-2012 nicm

Simplify logging and just fprintf(stderr, ...) for early errors.


Revision tags: OPENBSD_5_1_BASE
# 1.108 21-Jan-2012 nicm

Drop the ability to have a list of keys in the prefix in favour of two
separate options, prefix and prefix2. This simplifies the code and gets
rid the data options type which was only used for this one option.

Also add a -2 flag to send-prefix to send the secondary prefix key,
fixing a cause of minor irritation.

People who want three prefix keys are out of luck :-).


# 1.107 23-Oct-2011 nicm

Try to resolve relative paths for loadb and saveb (first using client
working directory if any then default-path or session wd).


# 1.106 23-Oct-2011 nicm

Ignore LC_ALL and LC_CTYPE if they are empty as well as unset.


# 1.105 25-Sep-2011 nicm

Reject $SHELL if it is not a full path.


Revision tags: OPENBSD_5_0_BASE
# 1.104 04-Mar-2011 nicm

Two fixes by Micah Cowan: make mouse work properly beyond >127 on signed
char architectures and properly parse $TMUX by stopping the socket path
at the first comma.


Revision tags: OPENBSD_4_9_BASE
# 1.103 23-Jan-2011 nicm

Set $TMUX without the session when background jobs are run.


# 1.102 12-Jan-2011 nicm

Use TMPDIR if set, from Han Boetes.


# 1.101 08-Jan-2011 nicm

Move all calls to fcntl(...O_NONBLOCK) into a function and clear the
flag on the stdio file descriptors before closing them (fixes things
like "tmux ls && cat").


# 1.100 03-Jan-2011 nicm

Support for UTF-8 mouse input (\033[1005h). This was added in xterm 262
and supports larger terminals than the older way.

If the new mouse-utf8 option is on, UTF-8 mouse input is enabled for all
UTF-8 terminals. The option defaults to on if LANG etc are set in the
same manner as the utf8 option.

With help and based on code from hsim at gmx.li.


# 1.99 01-Jan-2011 nicm

Move the user-visible parts of all options (names, types, limit, default
values) together into one set of tables in options-table.c. Also clean
up and simplify cmd-set-options.c and move a common print function into
option-table.c.


# 1.98 30-Dec-2010 nicm

Change from a per-session stack of buffers to one global stack which is
much more convenient and also simplifies lot of code. This renders
copy-buffer useless and makes buffer-limit now a server option.

By Tiago Cunha.


# 1.97 19-Dec-2010 nicm

Add other-pane-height and other-pane-width options, allowing the width
or height of the smaller panes in the main-horizontal and main-vertical
layouts to be set. Mostly from David Goodlad.


# 1.96 08-Dec-2010 nicm

In the built-in layouts, distribute the panes more evenly. Set the
default value of main-pane-width to 80, rather than 81. By Micah Cowan.


# 1.95 06-Dec-2010 nicm

Add an option to alert (monitor) for silence (lack of activity) in a
window. From Thomas Adam.


# 1.94 29-Nov-2010 nicm

If VISUAL or EDITOR contains "vi", configure mode-keys and status-keys
to vi.

Based on a diff from martynas@, previously requested by a couple of
other people.


# 1.93 11-Nov-2010 nicm

Add XAUTHORITY to update-environment, requested by Andreas Kloeckner.


# 1.92 18-Oct-2010 nicm

Merge the before and after attach client code into one in client.c
(instead of two in tmux.c and client.c).


# 1.91 16-Oct-2010 nicm

Make stdio blocking again before calling shell command with -c.


# 1.90 16-Oct-2010 nicm

Trying to set FD_CLOEXEC on every fd is a lost cause, just use
closefrom() before exec.


# 1.89 14-Oct-2010 nicm

Use an explicit event rather than event_once for the main event so it
can be removed when the client becomes ready.


# 1.88 26-Sep-2010 nicm

Two new options:

- server option "exit-unattached" makes the server exit when no clients
are attached, even if sessions are present;

- session option "destroy-unattached" destroys a session once no clients
are attached to it.

These are useful for preventing tmux remaining in the background where
it is undesirable and when using tmux as a login shell to keep a limit
on new sessions.


# 1.87 19-Aug-2010 nicm

Do not call event_del() for signals after fork(), just use sigaction()
directly instead - calling libevent functions after fork() w/o
event_reinit() is a bad idea, even if in this case it was harmless.


Revision tags: OPENBSD_4_8_BASE
# 1.86 04-Aug-2010 deraadt

switch back to kqueue for now, since (a) kqueue has been fixed to deal
with strange devices and (b) since there appears to be a bull in the
poll code in libevent as well...
requested by nicm who is away


# 1.85 24-Jul-2010 nicm

kqueue(2) is currently broken when used with /dev/null and a few other
devices.

An upcoming fix for some problems with the client stdout/stderr handling
relies on it working, so make tmux force libevent to use poll(2) via
EVENT_NOKQUEUE, until we have fixed kqueue.


# 1.84 11-Jul-2010 nicm

Return the command client return code with MSG_EXIT now that MSG_ERROR and
MSG_PRINT are unused.

New clients should be compatible with old tmux servers but vice versa may print
an error.


# 1.83 28-Jun-2010 nicm

Send all three of stdin, stdout, stderr from the client to the server, so that
commands can directly make use of them. This means that load-buffer and
save-buffer can have "-" as the file to read from stdin or write to stdout.

This is a protocol version bump so the tmux server will need to be restarted
after upgrade (or an older client used).


# 1.82 27-Jun-2010 nicm

Store the current working directory in the session, change the default-path
option to default to empty and make that mean that the stored session CWD is
used.


# 1.81 27-Jun-2010 nicm

New option, detach-on-destroy, to set what happens to a client when the session
it is attached to is destroyed. If on (the default), it is detached; if off, it
is switched to the most recently active session.


# 1.80 26-Jun-2010 nicm

Setting the cmdlist pointer in the bind-key to NULL to prevent it being freed
after the command is executing is bogus because it may still be needed if the
same command is going to be executed again (for example if you "bind-key a
bind-key b ..."). Making a copy is hard, so instead add a reference count to
the cmd_list.

While here, also print bind-key -n and the rest of the flags properly.

Fixes problem reported by mcbride@.


# 1.79 14-May-2010 nicm

Colour+attribute options for status line alerts, from Alex Alexander.


# 1.78 04-May-2010 nicm

Put this back in with the initialisation in the right order.


# 1.77 04-May-2010 nicm

Revert last change, it appears to be broken somehow.


# 1.76 03-May-2010 nicm

Make signal handler setup/teardown two common functions instead of six,
and reset SIGCHLD after fork to fix problems with some shells. From
Romain Francois.


# 1.75 28-Apr-2010 nicm

Make the active pane border have a green foreground instead of
background by default.


# 1.74 18-Apr-2010 nicm

Catch SIGCHLD to avoid a zombie, from patrick keshishian.


Revision tags: OPENBSD_4_7_BASE
# 1.73 22-Feb-2010 nicm

Option to set the characters considered word separators in copy mode, from
Micah Cowan.


# 1.72 08-Feb-2010 nicm

Add an option to disable the smcup/rmcup alternate screen behaviour inside
tmux. From clemens fischer.


# 1.71 06-Feb-2010 nicm

Change nested check to compare server socket path rather than just assuming
that if $TMUX is set it is nested. From Micah Cowan.


# 1.70 06-Feb-2010 nicm

Clean up $TMUX parsing, from Micah Cowan, tweaked by me.


# 1.69 06-Feb-2010 nicm

Instead of bailing out on the first configuration file error, carry on,
collecting all the errors, then start with the active window in more mode
displaying them.


# 1.68 04-Feb-2010 nicm

Read the path from $TMUX if it is present and -L and -S are not given. Based on
a diff from Micah Cowan.


# 1.67 04-Feb-2010 nicm

Option to display the active pane in a different colour with the display-panes
command. From Paul Hoffman, thanks.


# 1.66 03-Jan-2010 nicm

Options to set the colour of the pane borders, with different colours for the
active pane.


# 1.65 14-Dec-2009 nicm

New server option, escape-time, to set the timeout used to detect if escapes
are alone or part of a function key or meta sequence.


# 1.64 11-Dec-2009 nicm

Use quiet variable, and add missing sentinel to options array.


# 1.63 10-Dec-2009 nicm

Add "server options" which are server-wide and not bound to a session or
window. Set and displayed with "set -s" and "show -s".

Currently the only option is "quiet" (like command-line -q, allowing it to be
set from .tmux.conf), but others will come along.


# 1.62 03-Dec-2009 nicm

Massive spaces->tabs and trailing whitespace cleanup, hopefully for the last
time now I've configured emacs to make them displayed in really annoying
colours...


# 1.61 26-Nov-2009 nicm

Remove a couple of unused arguments where possible, and add /* ARGSUSED */ to
the rest to reduce lint output.


# 1.60 19-Nov-2009 nicm

Two new options, window-status-format and window-status-current-format, which
allow the format of each window in the status line window list to be controlled
using similar # sequences as status-left/right.

This diff also moves part of the way towards UTF-8 support in window names but
it isn't quite there yet.


# 1.59 19-Nov-2009 nicm

Revert to xterm-keys off by default. It was on as an experiment to see if the
option could be removed, but it affects vi, so we have to keep the option, and
a conservative default is better.


# 1.58 18-Nov-2009 nicm

Add a per-client log of status line messages displayed while that client
exists. A new message-limit session option sets the maximum number of entries
and a command, show-messages, shows the log (bound to ~ by default).

This (and prompt history) might be better as a single global log but until
there are global options it is easier for them to be per client.


# 1.57 10-Nov-2009 nicm

There is no real standard for modifier plus function keys. Previously, tmux
output some from rxvt but in other ways did the same as xterm or other
terminals, but this is a bit inconsistent.

xterm's method is fairly sensible and we already support it (xterm-keys), so
enable it by default instead.


# 1.56 04-Nov-2009 nicm

A couple of minor cosmetic changes.


# 1.55 04-Nov-2009 nicm

Initial changes to move tmux to libevent.

This moves the client-side loops are pretty much fully over to event-based only
(tmux.c and client.c) but server-side (server.c and friends) treats libevent as
a sort of clever poll, waking up after every event to run various things.

Moving the server stuff over to bufferevents and timers and so on will come
later.


# 1.54 04-Nov-2009 nicm

Change declaration and use of malloc_options to be more standard, from Tim van
der Molen.


# 1.53 26-Oct-2009 deraadt

tabs are better; ok nicm


# 1.52 25-Oct-2009 nicm

Remove the -d flag to tmux and just use op/AX to detect default colours.

Irritatingly, although op can be used to tell if a terminal supports default
colours, it can't be used to set them because in some terminfo descriptions it
resets attributes as a side-effect (acts as sgr0) and in others it doesn't, so
it is not possible to determine reliably what the terminal state will be
afterwards. So if AX is missing and op is present, tmux just sends sgr0.

Anyone using -d for a terminal who finds they actually needed it can replace it
using terminal-overrides, but please let me know as it is probably an omission
from terminfo.


# 1.51 22-Oct-2009 nicm

Merge prepare_cmd into main as it is short and only called once.


# 1.50 21-Oct-2009 nicm

Client tidying: get rid of client_ctx struct in favour of two variables in
client.c, and move the functions in client-fn.c into other files.


# 1.49 10-Oct-2009 nicm

New option, mouse-select-pane. If on, the mouse may be used to select the
current pane.

Suggested by sthen@ and also by someone else ages ago who I have forgotten.


# 1.48 10-Oct-2009 nicm

Support for individual session idle time locking. May be enabled by turning off
the lock-server option (it is on by default). When this is off, each session
locks when it has been idle for the lock-after-time setting. When on, the
entire server locks when ALL sessions have been idle for their individual
lock-after-time settings.

This replaces one global-only option (lock-after-time) with another
(lock-server), but the default behaviour is usually preferable so there don't
seem to be many alternatives.

Diff/idea largely from Thomas Adam, tweaked by me.


# 1.47 09-Oct-2009 nicm

Add a simple synchronize-panes window option: when set, all input to any pane
that is part of the window is also sent to all other panes in the same
window. Suggested by several, most recently Tomasz Pajor.


# 1.46 23-Sep-2009 nicm

Support -c like sh(1) to execute a command, useful when tmux is a login
shell. Suggested by halex@.

This includes another protocol version increase (the last for now) so again
restart the tmux server before upgrading.


# 1.45 23-Sep-2009 nicm

Remove the internal tmux locking and instead detach each client and run the
command specified by a new option "lock-command" (by default "lock -np") in
each client.

This means each terminal has to be unlocked individually but simplifies the
code and allows the system password to be used to unlock.

Note that the set-password command is gone, so it will need to be removed from
configuration files, and the -U command line flag has been removed.

This is the third protocol version change so again it is best to stop the tmux
server before upgrading.


# 1.44 22-Sep-2009 nicm

Permit multiple prefix keys to be defined, separated by commas, for example:

set -g prefix ^a,^b

Any key in the list acts as the prefix. The send-prefix command always sends
the first key in the list.


# 1.43 18-Sep-2009 nicm

New option, set-titles-string, to allow the window title to be specified (as
for status-left/right) if set-titles is on. Also only update the title when the
status line is being redrawn.


# 1.42 04-Sep-2009 nicm

Tidy main and make it a bit easier to read.


# 1.41 02-Sep-2009 nicm

Accept -l to make it easier for people who use tmux as a login shell to use
$SHELL. Originally from martynas@, tweaked by me.


# 1.40 02-Sep-2009 nicm

When incorrect passwords are entered, behave similarly to login(1) and backoff
for a bit. Based on a diff from martynas@.


# 1.39 01-Sep-2009 nicm

When using tmux as a login shell, there is currently no way to specify a shell
to be used as a login shell inside tmux, so add a default-shell session option.
This sets the shell invoked as a login shell when the default-command option is
empty.

The default option value is whichever of $SHELL, getpwuid(getuid())'s pw_shell
or /bin/sh is valid first.

Based on a diff from martynas@, changed by me to be a session option rather
than a window option.


# 1.38 01-Sep-2009 nicm

Use "Password:" with no space for password prompts and don't display a *s for
the password, like pretty much everything else. From martynas@ with minor
tweaks by me.


# 1.37 01-Sep-2009 nicm

Sort cases same as getopt argument, from martynas.


# 1.36 31-Aug-2009 nicm

Add a new display-panes command, with two options (display-panes-colour and
display-panes-time), which displays a visual indication of the number of each
pane.


# 1.35 23-Aug-2009 nicm

Add some other obvious variables to update-environment (WINDOWID SSH_ASKPASS
SSH_AUTH_SOCK SSH_AGENT_PID SSH_CONNECTION) so they are updated in the session
environment on new/attach.


# 1.34 13-Aug-2009 nicm

Disable mode-mouse (mouse in copy/choice mode) by default as it isn't very
useful at the moment and causes confusion.


# 1.33 13-Aug-2009 nicm

Add a base-index session option to specify the first index checked when looking
for an index for a new window.


# 1.32 12-Aug-2009 nicm

When started as the shell, __progname contains a leading -, so hardcode "tmux"
for socket path and log files, and strip it when working out the shell.


# 1.31 11-Aug-2009 nicm

Switch tmux to use imsg. This is the last major change to make the
client-server protocol more resilient and make the protocol versioning work
properly. In future, the only things requiring a protocol version bump will be
changes in the message structs, and (when both client and server have this
change) mixing different versions should nicely report an error message.

As a side effect this also makes the code tidier, fixes a problem with the way
errors reported during server startup were handled, and supports fd passing
(which will be used in future).

Looked over by eric@, thanks.

Please note that mixing a client with this change with an older server or vice
versa may cause tmux to crash or hang - tmux should be completely exited before
upgrading.


# 1.30 10-Aug-2009 nicm

No arguments are the same as new-session and this requires the environment to
be sent, so set that flag too when argc == 0.


# 1.29 08-Aug-2009 nicm

Infrastructure and commands to manage the environment for processes started
within tmux.

There is a global environment, copied from the external environment when the
server is started and each sesssion has an (initially empty) session
environment which overrides it.

New commands set-environment and show-environment manipulate or display the
environments.

A new session option, update-environment, is a space-separated list of
variables which are updated from the external environment into the session
environment every time a new session is created - the default is DISPLAY.


# 1.28 08-Aug-2009 nicm

Options to set the colours and attributes for status-left/-right. From Thomas
Adam, thanks.


# 1.27 05-Aug-2009 nicm

If colours are not supported by the terminal, try to emulate a coloured
background by setting or clearing the reverse attribute.

This makes a few applications which don't use the reverse attribute themselves
a little happier, and allows the status, message and mode options to have
default attributes and fg/bg options that work as expected when set as reverse.


# 1.26 04-Aug-2009 nicm

Check for "UTF8" as well as "UTF-8" in LANG etc as it seems this may also
appear.


# 1.25 03-Aug-2009 nicm

Add a terminal-overrides session option allowing individual terminfo(5) entries
to be overridden. The 88col/256col checks are now moved into the default
setting and out of the code.

Also remove a couple of old workarounds for xterm and rxvt which are no longer
necessary (tmux can emulate them if missing).


# 1.24 30-Jul-2009 nicm

Add a mode-mouse option to prevent tmux taking over the mouse in choice or copy
modes.


# 1.23 29-Jul-2009 nicm

Rename struct hdrtype to msgtype which is a better name and can be used even
when struct hdr disappears.


# 1.22 29-Jul-2009 nicm

Taking account of the "s, 22 not 24 is the maximum length of #T in status-right
to prevent the date being cut off.


# 1.21 26-Jul-2009 nicm

Make all messages sent between the client and server fixed size.

This is the first of two changes to make the protocol more resilient and less
sensitive to other changes in the code, particularly with commands. The client
now packs argv into a buffer and sends it to the server for parsing, rather
than doing it itself and sending the parsed command data.

As a side-effect this also removes a lot of now-unused command marshalling
code.

Mixing a server without this change and a client with or vice versa will cause
tmux to hang or crash, please ensure that tmux is entirely killed before
upgrading.


# 1.20 22-Jul-2009 nicm

Pass a set of flags into client_init rather than just a start_server
variable. Only one flag now but more to come later.


# 1.19 20-Jul-2009 nicm

Display the number of failed password attempts (if any) when the server is
locked. From Tom Doherty.


# 1.18 20-Jul-2009 nicm

Add a status-justify option to allow the window list in the status line to be
positioned at the left, centre, or right.


# 1.17 20-Jul-2009 nicm

New options, window-status-current-{fg,bg,attr}, to set the fg, bg and
attributes with which the current window is shown in the status line. From
Johan Friis, thanks.


# 1.16 18-Jul-2009 nicm

Add three new session options: visual-activity, visual-bell, visual-content. If
these are enabled (and the monitor-activity, bell-actio and monitor-content
options are configurated appropriately), when activity, a bell, or content is
detected, a message is shown.

Also tidy up the bell/activity/content code in server.c slightly and fix a
couple of errors.


# 1.15 17-Jul-2009 nicm

If -u is specified or UTF-8 is otherwise detected when the server is started,
enable the utf8 and status-utf8 optons. While here, note in the man page that
the server is started with the first session and exits when none remain.


# 1.14 10-Jul-2009 nicm

Add a default-terminal option to set the starting value of $TERM in new
windows.

This is "screen" by default and must be either that or something closely
related. This does makes it easier to customise it if necessary.


# 1.13 08-Jul-2009 nicm

Just appending -l to $SHELL to create a login shell is wrong: -l is not POSIX,
and some people may use shells which do not support it. Instead, make an empty
default-command option mean a login shell, and fork it with a - in argv[0]
which is the method used by login(1).

Also fix the automatic-rename code to handle this correctly and to strip a
leading - if present.


# 1.12 07-Jul-2009 nicm

Rename the global options variables to be shorter and to make session options
clear. No functional change, getting this out of the way to make later options
changes easier.


Revision tags: OPENBSD_4_6_BASE
# 1.11 25-Jun-2009 nicm

If getcwd() fails, use the user's home directory, or /, instead of failing with
an error.


# 1.10 25-Jun-2009 nicm

Remove error about using -L and -S together which was never displayed as
logging wasn't yet enabled, was unnecessary, and contradicted the man page
which says using -S will cause -L to be ignored.


# 1.9 23-Jun-2009 nicm

LC_ALL overrides LC_CTYPE and LANG. Comment was correct but the code
wrong. Pointed out by Hannah Schroeter, thanks.


# 1.8 05-Jun-2009 nicm

Check the first of LC_CTYPE, LC_ALL and LANG, rather than just the last, when
trying to decide about UTF-8, and use strcasestr. Reported by Geert Hendrickx.


# 1.7 04-Jun-2009 nicm

Zero the password given to -U in the client as well.


# 1.6 03-Jun-2009 nicm

Do not set the window title by default (make set-titles option default to off),
wiping over the title is rude and annoying. Agreed by several.


# 1.5 03-Jun-2009 nicm

New session option, status-utf8, to control the interpretation of top-bit-set
characters in status-left and status-right (if on, they are treated as UTF-8;
otherwise passed through).


# 1.4 02-Jun-2009 sobrado

remove unused flag; while here, make usage's output fit on 80-column displays.


# 1.3 02-Jun-2009 pyr

spawn login shells by default, adapt manpage bits as well.
ok nicm@


# 1.2 02-Jun-2009 ray

Don't leak memory if multiple -f flags are given.

OK nicm@


# 1.1 01-Jun-2009 nicm

Import tmux, a terminal multiplexor allowing (among other things) a single
terminal to be switched between several different windows and programs
displayed on one terminal be detached from one terminal and moved to another.

ok deraadt pirofti


# 1.193 12-Mar-2020 nicm

When the server socket is given by the user with -S, create it with
umask 177 instead of 117 because it may not be in a safe directory like
the default directory in /tmp. The user can chmod it more open after it
is created if they want.


# 1.192 28-Jan-2020 nicm

-V also needs to go in usage.


# 1.191 28-Jan-2020 nicm

Reduce a difference with portable tmux by adding the -V flag and
#{version} format; on OpenBSD these just report the OpenBSD version.


# 1.190 14-Oct-2019 nicm

Memory leaks, from Igor Wong in GitHub issue 1934.


Revision tags: OPENBSD_6_6_BASE
# 1.189 20-Jun-2019 nicm

Add a per-pane option set. Pane options inherit from window options (so
there should be no change to existing behaviour) and are set and shown
with set-option -p and show-options -p.

Change remain-on-exit and window-style/window-active-style to be pane
options (some others will be changed later).

This makes select-pane -P and -g unnecessary so no longer document them
(they still work) and no longer document set-window-option and
show-window-options in favour of set-option -w and show-options -w.


# 1.188 26-Apr-2019 nicm

Merge hooks into options and make each one an array option. This allows
multiple commands to be easily bound to one hook. set-hook and
show-hooks remain but they are now variants of set-option and
show-options. show-options now has a -H flag to show hooks (by default
they are not shown).


Revision tags: OPENBSD_6_5_BASE
# 1.187 22-Nov-2018 nicm

Do not use PWD unless it actually matches the real working directory.


Revision tags: OPENBSD_6_3_BASE OPENBSD_6_4_BASE
# 1.186 12-Jan-2018 nicm

Improve error message if creating socket parent directory fails, from
Thomas Adam for GitHub issue 1215.


# 1.185 01-Jan-2018 nicm

Prefer PWD for current directory if present in client, from Wei Zhao in
GitHub issue 1183.


Revision tags: OPENBSD_6_2_BASE
# 1.184 12-Jul-2017 nicm

Make shell_command a global like other stuff rather than making it an
exception and using callback argument.


# 1.183 03-Jul-2017 nicm

Try C.UTF-8 which is also a commonly useful locale on some platforms,
from Romain Francoise.


# 1.182 22-Apr-2017 nicm

Do not need getopt.h.


# 1.181 20-Apr-2017 nicm

Use fdforkpty() instead of our own unwrapped versions.


# 1.180 19-Apr-2017 nicm

Style nits and a missing cast.


# 1.179 16-Apr-2017 nicm

Memory leak, from David CARLIER.


Revision tags: OPENBSD_6_1_BASE
# 1.178 21-Mar-2017 nicm

Use uid_t for UID not u_int.


# 1.177 16-Feb-2017 nicm

Style nits.


# 1.176 23-Jan-2017 nicm

Open /dev/ptm before pledge() and save it to be used for PTMGET later
(this means inlining forkpty()).

ok deraadt


# 1.175 15-Jan-2017 nicm

Major tidy up and rework of options tree and set-option/show-options
commands this pushes more of the code into options.c and ties it more
closely to the options table rather than having an unnecessary
split. Also add support for array options (will be used later). Only
(intentional) user visible change is that show-options output is now
passed through vis(3) with VIS_DQ so quotes are escaped.


# 1.174 12-Jan-2017 nicm

Simplify appending to string options.


# 1.173 09-Dec-2016 nicm

Spacing nits.


# 1.172 11-Oct-2016 nicm

Add static in window-*.c and move some internal functions out of tmux.h.


# 1.171 10-Oct-2016 nicm

Loads more static, except for cmd-*.c and window-*.c.


Revision tags: OPENBSD_6_0_BASE
# 1.170 27-May-2016 nicm

Use getprogname() instead of __progname to make portability easier.


# 1.169 04-May-2016 nicm

Fix up a couple of long lines.


# 1.168 05-Mar-2016 nicm

If setlocale("en_US.UTF-8") succeeds, then don't do the check for UTF-8
locale since if it isn't UTF-8 the system is broken anyway. If it fails,
try "" and check for UTF-8 with nl_langinfo(CODESET) rather than
wcwidth(). Based on a diff from schwarze@, nl_langinfo also suggested by
stsp@.


# 1.167 05-Mar-2016 nicm

Although we always have en_US.UTF-8 on OpenBSD, some platforms do not,
so fall back to setlocale(LC_CTYPE, ""). tmux requires a UTF-8 locale,
so check with wcwidth() on a UTF-8 character after setlocale().


# 1.166 01-Mar-2016 nicm

Remove unused variables, from Michal Mazurek.


# 1.165 01-Mar-2016 nicm

Use system wcwidth() instead of carrying around UTF-8 width tables.


Revision tags: OPENBSD_5_9_BASE
# 1.164 19-Jan-2016 nicm

I no longer use my SourceForge address so replace it.


# 1.163 08-Dec-2015 nicm

Add hooks infrastructure, basic commands (set-hook, show-hooks) and a
couple of not very useful client hooks. This will eventually let
commands be run at various points and on notifications. Joint work with
Thomas Adam.


# 1.162 24-Nov-2015 nicm

Make environ_set va_args and use it to tidy up some calls. Also add a
missing word in manpage (from jmc).


# 1.161 24-Nov-2015 nicm

Shell command from -c doesn't have to be global, pass it as an argument.


# 1.160 24-Nov-2015 nicm

Tidy the code that works out the socket path, and just use the full path
in the global socket_path rather than copying it.


# 1.159 24-Nov-2015 nicm

Remove malloc_options DEBUG bit.


# 1.158 24-Nov-2015 nicm

Remove the -I part of show-messages which isn't really that useful; the
server start time can now be accessed with a new start_time format (use:
tmux display -p '#{t:start_time}')


# 1.157 24-Nov-2015 nicm

Make the log stuff a bit tidier with some helper functions.


# 1.156 22-Nov-2015 nicm

Add getpw to pledge, makes tmux work in YP environments, discovered by
matthieu, ok deraadt


# 1.155 20-Nov-2015 nicm

Instead of separate tables for different types of options, give each
option a scope type (server, session, window) in one table.


# 1.154 15-Nov-2015 nicm

Accidentally turned off pledge, turn it back on.


# 1.153 14-Nov-2015 nicm

Push stdout and stderr to clients more aggressively, and add an event to
continue if the send fails.


# 1.152 12-Nov-2015 nicm

tmux is UTF-8, so if $TMUX is set (tmux running in tmux), the client is
UTF-8. Also try to make the existing checks more readable.


# 1.151 12-Nov-2015 nicm

Nuke the utf8 and status-utf8 options and make tmux only a UTF-8
terminal. We still support non-UTF-8 terminals outside tmux, but inside
it is always UTF-8 (as when the utf8 and status-utf8 options were on).


# 1.150 11-Nov-2015 nicm

Drop mouse-utf8 option and always turn on UTF-8 mouse if the client says
it supports UTF-8.


# 1.149 28-Oct-2015 nicm

Like options, move the environ struct into environ.c.


# 1.148 27-Oct-2015 nicm

Move struct options into options.c.


# 1.147 27-Oct-2015 nicm

Break the common process set up, event loop and imsg dispatch code
between server and client out into a separate internal API. This will
make it easier to add another process.


# 1.146 25-Oct-2015 deraadt

Let's see if anyone screams about not being able to specify $TMPDIR
for their tmux sockets.

(Over the years, I have seen $TMPDIR set up worse than /tmp many times,
and don't know how this practice infected other parts of the system.
Nothing uses tmpdir(3), nor a huge-temporary-file program like sort.)
ok nicm


# 1.145 23-Oct-2015 nicm

tmux can call pledge() in main with large set and then reduce it
slightly in the server to "stdio rpath wpath cpath fattr unix recvfd
proc exec tty ps".


# 1.144 14-Sep-2015 nicm

Move tzset() from log_open to main.


# 1.143 03-Sep-2015 nicm

A couple of style nits.


# 1.142 01-Sep-2015 nicm

Work out config file when needed not at startup.


# 1.141 30-Aug-2015 nicm

Path from $TMUX does not need to be global anymore.


# 1.140 30-Aug-2015 nicm

Login shell can be a client flag, and move the exec code into client.c.


# 1.139 30-Aug-2015 nicm

Event base does not need to be global.


# 1.138 30-Aug-2015 nicm

Some style nits and dead assignments.


Revision tags: OPENBSD_5_8_BASE
# 1.137 20-Jul-2015 nicm

Add an option (history-file) for a file to save/restore command prompt
history, from Olof-Joachim Frahm.


# 1.136 04-Jun-2015 jmc

tweak SYNOPSIS and usage();


Revision tags: OPENBSD_5_7_BASE
# 1.135 19-Jan-2015 nicm

Make a tmux-%u directory under TMUX_TMPDIR, like TMPDIR.


# 1.134 19-Jan-2015 nicm

Only care about other permissions, allow group to be set.


# 1.133 19-Jan-2015 nicm

Remove unnecessary duplicate S_ISDIR check, from Dmitri Paduchikh.


# 1.132 20-Oct-2014 nicm

Tidy up some includes.


Revision tags: OPENBSD_5_6_BASE
# 1.131 17-Apr-2014 nicm

Remove the "info" message mechanism, this was only used for about five
mostly useless and annoying messages. Change those commands to silence
on success like all the others. Still accept the -q command line flag
and "quiet" server option for now.


# 1.130 31-Mar-2014 nicm

Remove log_debug2 as well and simplify log.c.


Revision tags: OPENBSD_5_5_BASE
# 1.129 16-Feb-2014 nicm

Leftovers from removing 88 colour support, from Theo Buehler.


# 1.128 15-Jan-2014 nicm

Do not attempt to read .tmux.conf if we can't figure out a home
directory, from Tiago Cunha.


# 1.127 09-Jan-2014 nicm

Three small changes from Tiago Cunha:

- Check for truncation when copying path.
- Don't need to use a temporary buffer in screen_set_title.
- Include strerror in output when connecting to server fails.


# 1.126 10-Oct-2013 nicm

We accidentally haven't been using $TMUX to work out the session for a
while and in fact it is less useful that using the client ttyname. So
don't bother and don't pass it from the client. If we need it in future
it is in c->environ.


# 1.125 10-Oct-2013 nicm

Alter how tmux handles the working directory to internally use file
descriptors rather than strings.

- Each session still has a current working directory.

- New sessions still get their working directory from the client that
created them or its attached session if any.

- New windows are created by default in the session working directory.

- The -c flag to new, neww, splitw allows the working directory to be
overridden.

- The -c flag to attach let's the session working directory be changed.

- The default-path option has been removed.

To get the equivalent to default-path '.', do:

bind c neww -c $PWD

To get the equivalent of default-path '~', do:

bind c neww -c ~

This also changes the client identify protocol to be a set of messages rather
than one as well as some other changes that should make it easier to make
backwards-compatible protocol changes in future.


# 1.124 10-Oct-2013 nicm

Merge IDENTIFY_* flags with CLIENT_* flags.


# 1.123 10-Oct-2013 nicm

Don't treat TMUX_TMPDIR as a potential file

The point of setting TMUX_TMPDIR is to then make any labels from -L go
to that directory. In the case of makesocketpath() with no TMUX_TMPDIR
set, would set both the path and the default socket to a file. The
checking of the permissions on the file worked fine in that case, but
when TMUX_TMPDIR is set, won't work on a directory.

This fixes the problem by ensuring the check on the permissions is
performed on directories only.

By Thomas Adam.


# 1.122 05-Oct-2013 nicm

Fix previous not to leak fd on failure, whoops.


# 1.121 05-Oct-2013 nicm

Use open(".")/fchdir() to save and restore current directory rather than
getcwd()/chdir().


Revision tags: OPENBSD_5_4_BASE
# 1.120 24-Apr-2013 nicm

Rename global configuration define.


# 1.119 11-Apr-2013 nicm

Call setlocale(LC_TIME) at startup.


# 1.118 27-Mar-2013 nicm

Add TMUX_TMPDIR variable to put the socket directory outside
TMPDIR. From Ben Boeckel.


# 1.117 27-Mar-2013 nicm

Remove tmux's (already minimal) 88 colour support. Such terminals are
few and unnecessary.


# 1.116 25-Mar-2013 nicm

Rename session idx to session id throughout and add $ prefix to targets
to use it, extended from a diff from George Nachman.


# 1.115 24-Mar-2013 nicm

Add a command queue to standardize and simplify commands that call other
commands and allow a command to block execution of subsequent
commands. This allows run-shell and if-shell to be synchronous which has
been much requested.

Each client has a default command queue and commands are consumed one at
a time from it. A command may suspend execution from the queue by
returning CMD_RETURN_WAIT and then resume it by calling cmd_continue() -
for example run-shell does this from the callback that is fired after
the job is freed.

When the command queue becomes empty, command clients are automatically
exited (unless attaching). A callback is also fired - this is used for
nested commands in, for example, if-shell which can block execution of
the client's cmdq until a new cmdq becomes empty.

Also merge all the old error/info/print functions together and lose the
old curclient/cmdclient distinction - a cmdq is bound to one client (or
none if in the configuration file), this is a command client if
c->session is NULL otherwise an attached client.


Revision tags: OPENBSD_5_3_BASE
# 1.114 27-Nov-2012 nicm

Correctly aggregate together errors from nested config files (with
source-file). Fix by Thomas Adam, reported by Sam Livingstone-Gray


# 1.113 26-Nov-2012 nicm

Call realpath earlier on the socket directory path rather than on the
socket file path because the latter may not exist yet and in that case
realpath is allowed to fail. From Romain Francoise.


Revision tags: OPENBSD_5_2_BASE
# 1.112 10-Jul-2012 nicm

xfree is not particularly helpful, remove it. From Thomas Adam.


# 1.111 18-Jun-2012 nicm

Add a skeleton mode to tmux (called "control mode") that let's tmux
commands be sent and output received on stdout. This can be used to
integrate with other terminal emulators and should allow some other
things to be made simpler later. More to come so doesn't do much yet and
deliberately not documented.


# 1.110 30-May-2012 nicm

Do not use stderr for log file and don't call log_close when not needed.


# 1.109 25-May-2012 nicm

Simplify logging and just fprintf(stderr, ...) for early errors.


Revision tags: OPENBSD_5_1_BASE
# 1.108 21-Jan-2012 nicm

Drop the ability to have a list of keys in the prefix in favour of two
separate options, prefix and prefix2. This simplifies the code and gets
rid the data options type which was only used for this one option.

Also add a -2 flag to send-prefix to send the secondary prefix key,
fixing a cause of minor irritation.

People who want three prefix keys are out of luck :-).


# 1.107 23-Oct-2011 nicm

Try to resolve relative paths for loadb and saveb (first using client
working directory if any then default-path or session wd).


# 1.106 23-Oct-2011 nicm

Ignore LC_ALL and LC_CTYPE if they are empty as well as unset.


# 1.105 25-Sep-2011 nicm

Reject $SHELL if it is not a full path.


Revision tags: OPENBSD_5_0_BASE
# 1.104 04-Mar-2011 nicm

Two fixes by Micah Cowan: make mouse work properly beyond >127 on signed
char architectures and properly parse $TMUX by stopping the socket path
at the first comma.


Revision tags: OPENBSD_4_9_BASE
# 1.103 23-Jan-2011 nicm

Set $TMUX without the session when background jobs are run.


# 1.102 12-Jan-2011 nicm

Use TMPDIR if set, from Han Boetes.


# 1.101 08-Jan-2011 nicm

Move all calls to fcntl(...O_NONBLOCK) into a function and clear the
flag on the stdio file descriptors before closing them (fixes things
like "tmux ls && cat").


# 1.100 03-Jan-2011 nicm

Support for UTF-8 mouse input (\033[1005h). This was added in xterm 262
and supports larger terminals than the older way.

If the new mouse-utf8 option is on, UTF-8 mouse input is enabled for all
UTF-8 terminals. The option defaults to on if LANG etc are set in the
same manner as the utf8 option.

With help and based on code from hsim at gmx.li.


# 1.99 01-Jan-2011 nicm

Move the user-visible parts of all options (names, types, limit, default
values) together into one set of tables in options-table.c. Also clean
up and simplify cmd-set-options.c and move a common print function into
option-table.c.


# 1.98 30-Dec-2010 nicm

Change from a per-session stack of buffers to one global stack which is
much more convenient and also simplifies lot of code. This renders
copy-buffer useless and makes buffer-limit now a server option.

By Tiago Cunha.


# 1.97 19-Dec-2010 nicm

Add other-pane-height and other-pane-width options, allowing the width
or height of the smaller panes in the main-horizontal and main-vertical
layouts to be set. Mostly from David Goodlad.


# 1.96 08-Dec-2010 nicm

In the built-in layouts, distribute the panes more evenly. Set the
default value of main-pane-width to 80, rather than 81. By Micah Cowan.


# 1.95 06-Dec-2010 nicm

Add an option to alert (monitor) for silence (lack of activity) in a
window. From Thomas Adam.


# 1.94 29-Nov-2010 nicm

If VISUAL or EDITOR contains "vi", configure mode-keys and status-keys
to vi.

Based on a diff from martynas@, previously requested by a couple of
other people.


# 1.93 11-Nov-2010 nicm

Add XAUTHORITY to update-environment, requested by Andreas Kloeckner.


# 1.92 18-Oct-2010 nicm

Merge the before and after attach client code into one in client.c
(instead of two in tmux.c and client.c).


# 1.91 16-Oct-2010 nicm

Make stdio blocking again before calling shell command with -c.


# 1.90 16-Oct-2010 nicm

Trying to set FD_CLOEXEC on every fd is a lost cause, just use
closefrom() before exec.


# 1.89 14-Oct-2010 nicm

Use an explicit event rather than event_once for the main event so it
can be removed when the client becomes ready.


# 1.88 26-Sep-2010 nicm

Two new options:

- server option "exit-unattached" makes the server exit when no clients
are attached, even if sessions are present;

- session option "destroy-unattached" destroys a session once no clients
are attached to it.

These are useful for preventing tmux remaining in the background where
it is undesirable and when using tmux as a login shell to keep a limit
on new sessions.


# 1.87 19-Aug-2010 nicm

Do not call event_del() for signals after fork(), just use sigaction()
directly instead - calling libevent functions after fork() w/o
event_reinit() is a bad idea, even if in this case it was harmless.


Revision tags: OPENBSD_4_8_BASE
# 1.86 04-Aug-2010 deraadt

switch back to kqueue for now, since (a) kqueue has been fixed to deal
with strange devices and (b) since there appears to be a bull in the
poll code in libevent as well...
requested by nicm who is away


# 1.85 24-Jul-2010 nicm

kqueue(2) is currently broken when used with /dev/null and a few other
devices.

An upcoming fix for some problems with the client stdout/stderr handling
relies on it working, so make tmux force libevent to use poll(2) via
EVENT_NOKQUEUE, until we have fixed kqueue.


# 1.84 11-Jul-2010 nicm

Return the command client return code with MSG_EXIT now that MSG_ERROR and
MSG_PRINT are unused.

New clients should be compatible with old tmux servers but vice versa may print
an error.


# 1.83 28-Jun-2010 nicm

Send all three of stdin, stdout, stderr from the client to the server, so that
commands can directly make use of them. This means that load-buffer and
save-buffer can have "-" as the file to read from stdin or write to stdout.

This is a protocol version bump so the tmux server will need to be restarted
after upgrade (or an older client used).


# 1.82 27-Jun-2010 nicm

Store the current working directory in the session, change the default-path
option to default to empty and make that mean that the stored session CWD is
used.


# 1.81 27-Jun-2010 nicm

New option, detach-on-destroy, to set what happens to a client when the session
it is attached to is destroyed. If on (the default), it is detached; if off, it
is switched to the most recently active session.


# 1.80 26-Jun-2010 nicm

Setting the cmdlist pointer in the bind-key to NULL to prevent it being freed
after the command is executing is bogus because it may still be needed if the
same command is going to be executed again (for example if you "bind-key a
bind-key b ..."). Making a copy is hard, so instead add a reference count to
the cmd_list.

While here, also print bind-key -n and the rest of the flags properly.

Fixes problem reported by mcbride@.


# 1.79 14-May-2010 nicm

Colour+attribute options for status line alerts, from Alex Alexander.


# 1.78 04-May-2010 nicm

Put this back in with the initialisation in the right order.


# 1.77 04-May-2010 nicm

Revert last change, it appears to be broken somehow.


# 1.76 03-May-2010 nicm

Make signal handler setup/teardown two common functions instead of six,
and reset SIGCHLD after fork to fix problems with some shells. From
Romain Francois.


# 1.75 28-Apr-2010 nicm

Make the active pane border have a green foreground instead of
background by default.


# 1.74 18-Apr-2010 nicm

Catch SIGCHLD to avoid a zombie, from patrick keshishian.


Revision tags: OPENBSD_4_7_BASE
# 1.73 22-Feb-2010 nicm

Option to set the characters considered word separators in copy mode, from
Micah Cowan.


# 1.72 08-Feb-2010 nicm

Add an option to disable the smcup/rmcup alternate screen behaviour inside
tmux. From clemens fischer.


# 1.71 06-Feb-2010 nicm

Change nested check to compare server socket path rather than just assuming
that if $TMUX is set it is nested. From Micah Cowan.


# 1.70 06-Feb-2010 nicm

Clean up $TMUX parsing, from Micah Cowan, tweaked by me.


# 1.69 06-Feb-2010 nicm

Instead of bailing out on the first configuration file error, carry on,
collecting all the errors, then start with the active window in more mode
displaying them.


# 1.68 04-Feb-2010 nicm

Read the path from $TMUX if it is present and -L and -S are not given. Based on
a diff from Micah Cowan.


# 1.67 04-Feb-2010 nicm

Option to display the active pane in a different colour with the display-panes
command. From Paul Hoffman, thanks.


# 1.66 03-Jan-2010 nicm

Options to set the colour of the pane borders, with different colours for the
active pane.


# 1.65 14-Dec-2009 nicm

New server option, escape-time, to set the timeout used to detect if escapes
are alone or part of a function key or meta sequence.


# 1.64 11-Dec-2009 nicm

Use quiet variable, and add missing sentinel to options array.


# 1.63 10-Dec-2009 nicm

Add "server options" which are server-wide and not bound to a session or
window. Set and displayed with "set -s" and "show -s".

Currently the only option is "quiet" (like command-line -q, allowing it to be
set from .tmux.conf), but others will come along.


# 1.62 03-Dec-2009 nicm

Massive spaces->tabs and trailing whitespace cleanup, hopefully for the last
time now I've configured emacs to make them displayed in really annoying
colours...


# 1.61 26-Nov-2009 nicm

Remove a couple of unused arguments where possible, and add /* ARGSUSED */ to
the rest to reduce lint output.


# 1.60 19-Nov-2009 nicm

Two new options, window-status-format and window-status-current-format, which
allow the format of each window in the status line window list to be controlled
using similar # sequences as status-left/right.

This diff also moves part of the way towards UTF-8 support in window names but
it isn't quite there yet.


# 1.59 19-Nov-2009 nicm

Revert to xterm-keys off by default. It was on as an experiment to see if the
option could be removed, but it affects vi, so we have to keep the option, and
a conservative default is better.


# 1.58 18-Nov-2009 nicm

Add a per-client log of status line messages displayed while that client
exists. A new message-limit session option sets the maximum number of entries
and a command, show-messages, shows the log (bound to ~ by default).

This (and prompt history) might be better as a single global log but until
there are global options it is easier for them to be per client.


# 1.57 10-Nov-2009 nicm

There is no real standard for modifier plus function keys. Previously, tmux
output some from rxvt but in other ways did the same as xterm or other
terminals, but this is a bit inconsistent.

xterm's method is fairly sensible and we already support it (xterm-keys), so
enable it by default instead.


# 1.56 04-Nov-2009 nicm

A couple of minor cosmetic changes.


# 1.55 04-Nov-2009 nicm

Initial changes to move tmux to libevent.

This moves the client-side loops are pretty much fully over to event-based only
(tmux.c and client.c) but server-side (server.c and friends) treats libevent as
a sort of clever poll, waking up after every event to run various things.

Moving the server stuff over to bufferevents and timers and so on will come
later.


# 1.54 04-Nov-2009 nicm

Change declaration and use of malloc_options to be more standard, from Tim van
der Molen.


# 1.53 26-Oct-2009 deraadt

tabs are better; ok nicm


# 1.52 25-Oct-2009 nicm

Remove the -d flag to tmux and just use op/AX to detect default colours.

Irritatingly, although op can be used to tell if a terminal supports default
colours, it can't be used to set them because in some terminfo descriptions it
resets attributes as a side-effect (acts as sgr0) and in others it doesn't, so
it is not possible to determine reliably what the terminal state will be
afterwards. So if AX is missing and op is present, tmux just sends sgr0.

Anyone using -d for a terminal who finds they actually needed it can replace it
using terminal-overrides, but please let me know as it is probably an omission
from terminfo.


# 1.51 22-Oct-2009 nicm

Merge prepare_cmd into main as it is short and only called once.


# 1.50 21-Oct-2009 nicm

Client tidying: get rid of client_ctx struct in favour of two variables in
client.c, and move the functions in client-fn.c into other files.


# 1.49 10-Oct-2009 nicm

New option, mouse-select-pane. If on, the mouse may be used to select the
current pane.

Suggested by sthen@ and also by someone else ages ago who I have forgotten.


# 1.48 10-Oct-2009 nicm

Support for individual session idle time locking. May be enabled by turning off
the lock-server option (it is on by default). When this is off, each session
locks when it has been idle for the lock-after-time setting. When on, the
entire server locks when ALL sessions have been idle for their individual
lock-after-time settings.

This replaces one global-only option (lock-after-time) with another
(lock-server), but the default behaviour is usually preferable so there don't
seem to be many alternatives.

Diff/idea largely from Thomas Adam, tweaked by me.


# 1.47 09-Oct-2009 nicm

Add a simple synchronize-panes window option: when set, all input to any pane
that is part of the window is also sent to all other panes in the same
window. Suggested by several, most recently Tomasz Pajor.


# 1.46 23-Sep-2009 nicm

Support -c like sh(1) to execute a command, useful when tmux is a login
shell. Suggested by halex@.

This includes another protocol version increase (the last for now) so again
restart the tmux server before upgrading.


# 1.45 23-Sep-2009 nicm

Remove the internal tmux locking and instead detach each client and run the
command specified by a new option "lock-command" (by default "lock -np") in
each client.

This means each terminal has to be unlocked individually but simplifies the
code and allows the system password to be used to unlock.

Note that the set-password command is gone, so it will need to be removed from
configuration files, and the -U command line flag has been removed.

This is the third protocol version change so again it is best to stop the tmux
server before upgrading.


# 1.44 22-Sep-2009 nicm

Permit multiple prefix keys to be defined, separated by commas, for example:

set -g prefix ^a,^b

Any key in the list acts as the prefix. The send-prefix command always sends
the first key in the list.


# 1.43 18-Sep-2009 nicm

New option, set-titles-string, to allow the window title to be specified (as
for status-left/right) if set-titles is on. Also only update the title when the
status line is being redrawn.


# 1.42 04-Sep-2009 nicm

Tidy main and make it a bit easier to read.


# 1.41 02-Sep-2009 nicm

Accept -l to make it easier for people who use tmux as a login shell to use
$SHELL. Originally from martynas@, tweaked by me.


# 1.40 02-Sep-2009 nicm

When incorrect passwords are entered, behave similarly to login(1) and backoff
for a bit. Based on a diff from martynas@.


# 1.39 01-Sep-2009 nicm

When using tmux as a login shell, there is currently no way to specify a shell
to be used as a login shell inside tmux, so add a default-shell session option.
This sets the shell invoked as a login shell when the default-command option is
empty.

The default option value is whichever of $SHELL, getpwuid(getuid())'s pw_shell
or /bin/sh is valid first.

Based on a diff from martynas@, changed by me to be a session option rather
than a window option.


# 1.38 01-Sep-2009 nicm

Use "Password:" with no space for password prompts and don't display a *s for
the password, like pretty much everything else. From martynas@ with minor
tweaks by me.


# 1.37 01-Sep-2009 nicm

Sort cases same as getopt argument, from martynas.


# 1.36 31-Aug-2009 nicm

Add a new display-panes command, with two options (display-panes-colour and
display-panes-time), which displays a visual indication of the number of each
pane.


# 1.35 23-Aug-2009 nicm

Add some other obvious variables to update-environment (WINDOWID SSH_ASKPASS
SSH_AUTH_SOCK SSH_AGENT_PID SSH_CONNECTION) so they are updated in the session
environment on new/attach.


# 1.34 13-Aug-2009 nicm

Disable mode-mouse (mouse in copy/choice mode) by default as it isn't very
useful at the moment and causes confusion.


# 1.33 13-Aug-2009 nicm

Add a base-index session option to specify the first index checked when looking
for an index for a new window.


# 1.32 12-Aug-2009 nicm

When started as the shell, __progname contains a leading -, so hardcode "tmux"
for socket path and log files, and strip it when working out the shell.


# 1.31 11-Aug-2009 nicm

Switch tmux to use imsg. This is the last major change to make the
client-server protocol more resilient and make the protocol versioning work
properly. In future, the only things requiring a protocol version bump will be
changes in the message structs, and (when both client and server have this
change) mixing different versions should nicely report an error message.

As a side effect this also makes the code tidier, fixes a problem with the way
errors reported during server startup were handled, and supports fd passing
(which will be used in future).

Looked over by eric@, thanks.

Please note that mixing a client with this change with an older server or vice
versa may cause tmux to crash or hang - tmux should be completely exited before
upgrading.


# 1.30 10-Aug-2009 nicm

No arguments are the same as new-session and this requires the environment to
be sent, so set that flag too when argc == 0.


# 1.29 08-Aug-2009 nicm

Infrastructure and commands to manage the environment for processes started
within tmux.

There is a global environment, copied from the external environment when the
server is started and each sesssion has an (initially empty) session
environment which overrides it.

New commands set-environment and show-environment manipulate or display the
environments.

A new session option, update-environment, is a space-separated list of
variables which are updated from the external environment into the session
environment every time a new session is created - the default is DISPLAY.


# 1.28 08-Aug-2009 nicm

Options to set the colours and attributes for status-left/-right. From Thomas
Adam, thanks.


# 1.27 05-Aug-2009 nicm

If colours are not supported by the terminal, try to emulate a coloured
background by setting or clearing the reverse attribute.

This makes a few applications which don't use the reverse attribute themselves
a little happier, and allows the status, message and mode options to have
default attributes and fg/bg options that work as expected when set as reverse.


# 1.26 04-Aug-2009 nicm

Check for "UTF8" as well as "UTF-8" in LANG etc as it seems this may also
appear.


# 1.25 03-Aug-2009 nicm

Add a terminal-overrides session option allowing individual terminfo(5) entries
to be overridden. The 88col/256col checks are now moved into the default
setting and out of the code.

Also remove a couple of old workarounds for xterm and rxvt which are no longer
necessary (tmux can emulate them if missing).


# 1.24 30-Jul-2009 nicm

Add a mode-mouse option to prevent tmux taking over the mouse in choice or copy
modes.


# 1.23 29-Jul-2009 nicm

Rename struct hdrtype to msgtype which is a better name and can be used even
when struct hdr disappears.


# 1.22 29-Jul-2009 nicm

Taking account of the "s, 22 not 24 is the maximum length of #T in status-right
to prevent the date being cut off.


# 1.21 26-Jul-2009 nicm

Make all messages sent between the client and server fixed size.

This is the first of two changes to make the protocol more resilient and less
sensitive to other changes in the code, particularly with commands. The client
now packs argv into a buffer and sends it to the server for parsing, rather
than doing it itself and sending the parsed command data.

As a side-effect this also removes a lot of now-unused command marshalling
code.

Mixing a server without this change and a client with or vice versa will cause
tmux to hang or crash, please ensure that tmux is entirely killed before
upgrading.


# 1.20 22-Jul-2009 nicm

Pass a set of flags into client_init rather than just a start_server
variable. Only one flag now but more to come later.


# 1.19 20-Jul-2009 nicm

Display the number of failed password attempts (if any) when the server is
locked. From Tom Doherty.


# 1.18 20-Jul-2009 nicm

Add a status-justify option to allow the window list in the status line to be
positioned at the left, centre, or right.


# 1.17 20-Jul-2009 nicm

New options, window-status-current-{fg,bg,attr}, to set the fg, bg and
attributes with which the current window is shown in the status line. From
Johan Friis, thanks.


# 1.16 18-Jul-2009 nicm

Add three new session options: visual-activity, visual-bell, visual-content. If
these are enabled (and the monitor-activity, bell-actio and monitor-content
options are configurated appropriately), when activity, a bell, or content is
detected, a message is shown.

Also tidy up the bell/activity/content code in server.c slightly and fix a
couple of errors.


# 1.15 17-Jul-2009 nicm

If -u is specified or UTF-8 is otherwise detected when the server is started,
enable the utf8 and status-utf8 optons. While here, note in the man page that
the server is started with the first session and exits when none remain.


# 1.14 10-Jul-2009 nicm

Add a default-terminal option to set the starting value of $TERM in new
windows.

This is "screen" by default and must be either that or something closely
related. This does makes it easier to customise it if necessary.


# 1.13 08-Jul-2009 nicm

Just appending -l to $SHELL to create a login shell is wrong: -l is not POSIX,
and some people may use shells which do not support it. Instead, make an empty
default-command option mean a login shell, and fork it with a - in argv[0]
which is the method used by login(1).

Also fix the automatic-rename code to handle this correctly and to strip a
leading - if present.


# 1.12 07-Jul-2009 nicm

Rename the global options variables to be shorter and to make session options
clear. No functional change, getting this out of the way to make later options
changes easier.


Revision tags: OPENBSD_4_6_BASE
# 1.11 25-Jun-2009 nicm

If getcwd() fails, use the user's home directory, or /, instead of failing with
an error.


# 1.10 25-Jun-2009 nicm

Remove error about using -L and -S together which was never displayed as
logging wasn't yet enabled, was unnecessary, and contradicted the man page
which says using -S will cause -L to be ignored.


# 1.9 23-Jun-2009 nicm

LC_ALL overrides LC_CTYPE and LANG. Comment was correct but the code
wrong. Pointed out by Hannah Schroeter, thanks.


# 1.8 05-Jun-2009 nicm

Check the first of LC_CTYPE, LC_ALL and LANG, rather than just the last, when
trying to decide about UTF-8, and use strcasestr. Reported by Geert Hendrickx.


# 1.7 04-Jun-2009 nicm

Zero the password given to -U in the client as well.


# 1.6 03-Jun-2009 nicm

Do not set the window title by default (make set-titles option default to off),
wiping over the title is rude and annoying. Agreed by several.


# 1.5 03-Jun-2009 nicm

New session option, status-utf8, to control the interpretation of top-bit-set
characters in status-left and status-right (if on, they are treated as UTF-8;
otherwise passed through).


# 1.4 02-Jun-2009 sobrado

remove unused flag; while here, make usage's output fit on 80-column displays.


# 1.3 02-Jun-2009 pyr

spawn login shells by default, adapt manpage bits as well.
ok nicm@


# 1.2 02-Jun-2009 ray

Don't leak memory if multiple -f flags are given.

OK nicm@


# 1.1 01-Jun-2009 nicm

Import tmux, a terminal multiplexor allowing (among other things) a single
terminal to be switched between several different windows and programs
displayed on one terminal be detached from one terminal and moved to another.

ok deraadt pirofti


# 1.192 28-Jan-2020 nicm

-V also needs to go in usage.


# 1.191 28-Jan-2020 nicm

Reduce a difference with portable tmux by adding the -V flag and
#{version} format; on OpenBSD these just report the OpenBSD version.


# 1.190 14-Oct-2019 nicm

Memory leaks, from Igor Wong in GitHub issue 1934.


Revision tags: OPENBSD_6_6_BASE
# 1.189 20-Jun-2019 nicm

Add a per-pane option set. Pane options inherit from window options (so
there should be no change to existing behaviour) and are set and shown
with set-option -p and show-options -p.

Change remain-on-exit and window-style/window-active-style to be pane
options (some others will be changed later).

This makes select-pane -P and -g unnecessary so no longer document them
(they still work) and no longer document set-window-option and
show-window-options in favour of set-option -w and show-options -w.


# 1.188 26-Apr-2019 nicm

Merge hooks into options and make each one an array option. This allows
multiple commands to be easily bound to one hook. set-hook and
show-hooks remain but they are now variants of set-option and
show-options. show-options now has a -H flag to show hooks (by default
they are not shown).


Revision tags: OPENBSD_6_5_BASE
# 1.187 22-Nov-2018 nicm

Do not use PWD unless it actually matches the real working directory.


Revision tags: OPENBSD_6_3_BASE OPENBSD_6_4_BASE
# 1.186 12-Jan-2018 nicm

Improve error message if creating socket parent directory fails, from
Thomas Adam for GitHub issue 1215.


# 1.185 01-Jan-2018 nicm

Prefer PWD for current directory if present in client, from Wei Zhao in
GitHub issue 1183.


Revision tags: OPENBSD_6_2_BASE
# 1.184 12-Jul-2017 nicm

Make shell_command a global like other stuff rather than making it an
exception and using callback argument.


# 1.183 03-Jul-2017 nicm

Try C.UTF-8 which is also a commonly useful locale on some platforms,
from Romain Francoise.


# 1.182 22-Apr-2017 nicm

Do not need getopt.h.


# 1.181 20-Apr-2017 nicm

Use fdforkpty() instead of our own unwrapped versions.


# 1.180 19-Apr-2017 nicm

Style nits and a missing cast.


# 1.179 16-Apr-2017 nicm

Memory leak, from David CARLIER.


Revision tags: OPENBSD_6_1_BASE
# 1.178 21-Mar-2017 nicm

Use uid_t for UID not u_int.


# 1.177 16-Feb-2017 nicm

Style nits.


# 1.176 23-Jan-2017 nicm

Open /dev/ptm before pledge() and save it to be used for PTMGET later
(this means inlining forkpty()).

ok deraadt


# 1.175 15-Jan-2017 nicm

Major tidy up and rework of options tree and set-option/show-options
commands this pushes more of the code into options.c and ties it more
closely to the options table rather than having an unnecessary
split. Also add support for array options (will be used later). Only
(intentional) user visible change is that show-options output is now
passed through vis(3) with VIS_DQ so quotes are escaped.


# 1.174 12-Jan-2017 nicm

Simplify appending to string options.


# 1.173 09-Dec-2016 nicm

Spacing nits.


# 1.172 11-Oct-2016 nicm

Add static in window-*.c and move some internal functions out of tmux.h.


# 1.171 10-Oct-2016 nicm

Loads more static, except for cmd-*.c and window-*.c.


Revision tags: OPENBSD_6_0_BASE
# 1.170 27-May-2016 nicm

Use getprogname() instead of __progname to make portability easier.


# 1.169 04-May-2016 nicm

Fix up a couple of long lines.


# 1.168 05-Mar-2016 nicm

If setlocale("en_US.UTF-8") succeeds, then don't do the check for UTF-8
locale since if it isn't UTF-8 the system is broken anyway. If it fails,
try "" and check for UTF-8 with nl_langinfo(CODESET) rather than
wcwidth(). Based on a diff from schwarze@, nl_langinfo also suggested by
stsp@.


# 1.167 05-Mar-2016 nicm

Although we always have en_US.UTF-8 on OpenBSD, some platforms do not,
so fall back to setlocale(LC_CTYPE, ""). tmux requires a UTF-8 locale,
so check with wcwidth() on a UTF-8 character after setlocale().


# 1.166 01-Mar-2016 nicm

Remove unused variables, from Michal Mazurek.


# 1.165 01-Mar-2016 nicm

Use system wcwidth() instead of carrying around UTF-8 width tables.


Revision tags: OPENBSD_5_9_BASE
# 1.164 19-Jan-2016 nicm

I no longer use my SourceForge address so replace it.


# 1.163 08-Dec-2015 nicm

Add hooks infrastructure, basic commands (set-hook, show-hooks) and a
couple of not very useful client hooks. This will eventually let
commands be run at various points and on notifications. Joint work with
Thomas Adam.


# 1.162 24-Nov-2015 nicm

Make environ_set va_args and use it to tidy up some calls. Also add a
missing word in manpage (from jmc).


# 1.161 24-Nov-2015 nicm

Shell command from -c doesn't have to be global, pass it as an argument.


# 1.160 24-Nov-2015 nicm

Tidy the code that works out the socket path, and just use the full path
in the global socket_path rather than copying it.


# 1.159 24-Nov-2015 nicm

Remove malloc_options DEBUG bit.


# 1.158 24-Nov-2015 nicm

Remove the -I part of show-messages which isn't really that useful; the
server start time can now be accessed with a new start_time format (use:
tmux display -p '#{t:start_time}')


# 1.157 24-Nov-2015 nicm

Make the log stuff a bit tidier with some helper functions.


# 1.156 22-Nov-2015 nicm

Add getpw to pledge, makes tmux work in YP environments, discovered by
matthieu, ok deraadt


# 1.155 20-Nov-2015 nicm

Instead of separate tables for different types of options, give each
option a scope type (server, session, window) in one table.


# 1.154 15-Nov-2015 nicm

Accidentally turned off pledge, turn it back on.


# 1.153 14-Nov-2015 nicm

Push stdout and stderr to clients more aggressively, and add an event to
continue if the send fails.


# 1.152 12-Nov-2015 nicm

tmux is UTF-8, so if $TMUX is set (tmux running in tmux), the client is
UTF-8. Also try to make the existing checks more readable.


# 1.151 12-Nov-2015 nicm

Nuke the utf8 and status-utf8 options and make tmux only a UTF-8
terminal. We still support non-UTF-8 terminals outside tmux, but inside
it is always UTF-8 (as when the utf8 and status-utf8 options were on).


# 1.150 11-Nov-2015 nicm

Drop mouse-utf8 option and always turn on UTF-8 mouse if the client says
it supports UTF-8.


# 1.149 28-Oct-2015 nicm

Like options, move the environ struct into environ.c.


# 1.148 27-Oct-2015 nicm

Move struct options into options.c.


# 1.147 27-Oct-2015 nicm

Break the common process set up, event loop and imsg dispatch code
between server and client out into a separate internal API. This will
make it easier to add another process.


# 1.146 25-Oct-2015 deraadt

Let's see if anyone screams about not being able to specify $TMPDIR
for their tmux sockets.

(Over the years, I have seen $TMPDIR set up worse than /tmp many times,
and don't know how this practice infected other parts of the system.
Nothing uses tmpdir(3), nor a huge-temporary-file program like sort.)
ok nicm


# 1.145 23-Oct-2015 nicm

tmux can call pledge() in main with large set and then reduce it
slightly in the server to "stdio rpath wpath cpath fattr unix recvfd
proc exec tty ps".


# 1.144 14-Sep-2015 nicm

Move tzset() from log_open to main.


# 1.143 03-Sep-2015 nicm

A couple of style nits.


# 1.142 01-Sep-2015 nicm

Work out config file when needed not at startup.


# 1.141 30-Aug-2015 nicm

Path from $TMUX does not need to be global anymore.


# 1.140 30-Aug-2015 nicm

Login shell can be a client flag, and move the exec code into client.c.


# 1.139 30-Aug-2015 nicm

Event base does not need to be global.


# 1.138 30-Aug-2015 nicm

Some style nits and dead assignments.


Revision tags: OPENBSD_5_8_BASE
# 1.137 20-Jul-2015 nicm

Add an option (history-file) for a file to save/restore command prompt
history, from Olof-Joachim Frahm.


# 1.136 04-Jun-2015 jmc

tweak SYNOPSIS and usage();


Revision tags: OPENBSD_5_7_BASE
# 1.135 19-Jan-2015 nicm

Make a tmux-%u directory under TMUX_TMPDIR, like TMPDIR.


# 1.134 19-Jan-2015 nicm

Only care about other permissions, allow group to be set.


# 1.133 19-Jan-2015 nicm

Remove unnecessary duplicate S_ISDIR check, from Dmitri Paduchikh.


# 1.132 20-Oct-2014 nicm

Tidy up some includes.


Revision tags: OPENBSD_5_6_BASE
# 1.131 17-Apr-2014 nicm

Remove the "info" message mechanism, this was only used for about five
mostly useless and annoying messages. Change those commands to silence
on success like all the others. Still accept the -q command line flag
and "quiet" server option for now.


# 1.130 31-Mar-2014 nicm

Remove log_debug2 as well and simplify log.c.


Revision tags: OPENBSD_5_5_BASE
# 1.129 16-Feb-2014 nicm

Leftovers from removing 88 colour support, from Theo Buehler.


# 1.128 15-Jan-2014 nicm

Do not attempt to read .tmux.conf if we can't figure out a home
directory, from Tiago Cunha.


# 1.127 09-Jan-2014 nicm

Three small changes from Tiago Cunha:

- Check for truncation when copying path.
- Don't need to use a temporary buffer in screen_set_title.
- Include strerror in output when connecting to server fails.


# 1.126 10-Oct-2013 nicm

We accidentally haven't been using $TMUX to work out the session for a
while and in fact it is less useful that using the client ttyname. So
don't bother and don't pass it from the client. If we need it in future
it is in c->environ.


# 1.125 10-Oct-2013 nicm

Alter how tmux handles the working directory to internally use file
descriptors rather than strings.

- Each session still has a current working directory.

- New sessions still get their working directory from the client that
created them or its attached session if any.

- New windows are created by default in the session working directory.

- The -c flag to new, neww, splitw allows the working directory to be
overridden.

- The -c flag to attach let's the session working directory be changed.

- The default-path option has been removed.

To get the equivalent to default-path '.', do:

bind c neww -c $PWD

To get the equivalent of default-path '~', do:

bind c neww -c ~

This also changes the client identify protocol to be a set of messages rather
than one as well as some other changes that should make it easier to make
backwards-compatible protocol changes in future.


# 1.124 10-Oct-2013 nicm

Merge IDENTIFY_* flags with CLIENT_* flags.


# 1.123 10-Oct-2013 nicm

Don't treat TMUX_TMPDIR as a potential file

The point of setting TMUX_TMPDIR is to then make any labels from -L go
to that directory. In the case of makesocketpath() with no TMUX_TMPDIR
set, would set both the path and the default socket to a file. The
checking of the permissions on the file worked fine in that case, but
when TMUX_TMPDIR is set, won't work on a directory.

This fixes the problem by ensuring the check on the permissions is
performed on directories only.

By Thomas Adam.


# 1.122 05-Oct-2013 nicm

Fix previous not to leak fd on failure, whoops.


# 1.121 05-Oct-2013 nicm

Use open(".")/fchdir() to save and restore current directory rather than
getcwd()/chdir().


Revision tags: OPENBSD_5_4_BASE
# 1.120 24-Apr-2013 nicm

Rename global configuration define.


# 1.119 11-Apr-2013 nicm

Call setlocale(LC_TIME) at startup.


# 1.118 27-Mar-2013 nicm

Add TMUX_TMPDIR variable to put the socket directory outside
TMPDIR. From Ben Boeckel.


# 1.117 27-Mar-2013 nicm

Remove tmux's (already minimal) 88 colour support. Such terminals are
few and unnecessary.


# 1.116 25-Mar-2013 nicm

Rename session idx to session id throughout and add $ prefix to targets
to use it, extended from a diff from George Nachman.


# 1.115 24-Mar-2013 nicm

Add a command queue to standardize and simplify commands that call other
commands and allow a command to block execution of subsequent
commands. This allows run-shell and if-shell to be synchronous which has
been much requested.

Each client has a default command queue and commands are consumed one at
a time from it. A command may suspend execution from the queue by
returning CMD_RETURN_WAIT and then resume it by calling cmd_continue() -
for example run-shell does this from the callback that is fired after
the job is freed.

When the command queue becomes empty, command clients are automatically
exited (unless attaching). A callback is also fired - this is used for
nested commands in, for example, if-shell which can block execution of
the client's cmdq until a new cmdq becomes empty.

Also merge all the old error/info/print functions together and lose the
old curclient/cmdclient distinction - a cmdq is bound to one client (or
none if in the configuration file), this is a command client if
c->session is NULL otherwise an attached client.


Revision tags: OPENBSD_5_3_BASE
# 1.114 27-Nov-2012 nicm

Correctly aggregate together errors from nested config files (with
source-file). Fix by Thomas Adam, reported by Sam Livingstone-Gray


# 1.113 26-Nov-2012 nicm

Call realpath earlier on the socket directory path rather than on the
socket file path because the latter may not exist yet and in that case
realpath is allowed to fail. From Romain Francoise.


Revision tags: OPENBSD_5_2_BASE
# 1.112 10-Jul-2012 nicm

xfree is not particularly helpful, remove it. From Thomas Adam.


# 1.111 18-Jun-2012 nicm

Add a skeleton mode to tmux (called "control mode") that let's tmux
commands be sent and output received on stdout. This can be used to
integrate with other terminal emulators and should allow some other
things to be made simpler later. More to come so doesn't do much yet and
deliberately not documented.


# 1.110 30-May-2012 nicm

Do not use stderr for log file and don't call log_close when not needed.


# 1.109 25-May-2012 nicm

Simplify logging and just fprintf(stderr, ...) for early errors.


Revision tags: OPENBSD_5_1_BASE
# 1.108 21-Jan-2012 nicm

Drop the ability to have a list of keys in the prefix in favour of two
separate options, prefix and prefix2. This simplifies the code and gets
rid the data options type which was only used for this one option.

Also add a -2 flag to send-prefix to send the secondary prefix key,
fixing a cause of minor irritation.

People who want three prefix keys are out of luck :-).


# 1.107 23-Oct-2011 nicm

Try to resolve relative paths for loadb and saveb (first using client
working directory if any then default-path or session wd).


# 1.106 23-Oct-2011 nicm

Ignore LC_ALL and LC_CTYPE if they are empty as well as unset.


# 1.105 25-Sep-2011 nicm

Reject $SHELL if it is not a full path.


Revision tags: OPENBSD_5_0_BASE
# 1.104 04-Mar-2011 nicm

Two fixes by Micah Cowan: make mouse work properly beyond >127 on signed
char architectures and properly parse $TMUX by stopping the socket path
at the first comma.


Revision tags: OPENBSD_4_9_BASE
# 1.103 23-Jan-2011 nicm

Set $TMUX without the session when background jobs are run.


# 1.102 12-Jan-2011 nicm

Use TMPDIR if set, from Han Boetes.


# 1.101 08-Jan-2011 nicm

Move all calls to fcntl(...O_NONBLOCK) into a function and clear the
flag on the stdio file descriptors before closing them (fixes things
like "tmux ls && cat").


# 1.100 03-Jan-2011 nicm

Support for UTF-8 mouse input (\033[1005h). This was added in xterm 262
and supports larger terminals than the older way.

If the new mouse-utf8 option is on, UTF-8 mouse input is enabled for all
UTF-8 terminals. The option defaults to on if LANG etc are set in the
same manner as the utf8 option.

With help and based on code from hsim at gmx.li.


# 1.99 01-Jan-2011 nicm

Move the user-visible parts of all options (names, types, limit, default
values) together into one set of tables in options-table.c. Also clean
up and simplify cmd-set-options.c and move a common print function into
option-table.c.


# 1.98 30-Dec-2010 nicm

Change from a per-session stack of buffers to one global stack which is
much more convenient and also simplifies lot of code. This renders
copy-buffer useless and makes buffer-limit now a server option.

By Tiago Cunha.


# 1.97 19-Dec-2010 nicm

Add other-pane-height and other-pane-width options, allowing the width
or height of the smaller panes in the main-horizontal and main-vertical
layouts to be set. Mostly from David Goodlad.


# 1.96 08-Dec-2010 nicm

In the built-in layouts, distribute the panes more evenly. Set the
default value of main-pane-width to 80, rather than 81. By Micah Cowan.


# 1.95 06-Dec-2010 nicm

Add an option to alert (monitor) for silence (lack of activity) in a
window. From Thomas Adam.


# 1.94 29-Nov-2010 nicm

If VISUAL or EDITOR contains "vi", configure mode-keys and status-keys
to vi.

Based on a diff from martynas@, previously requested by a couple of
other people.


# 1.93 11-Nov-2010 nicm

Add XAUTHORITY to update-environment, requested by Andreas Kloeckner.


# 1.92 18-Oct-2010 nicm

Merge the before and after attach client code into one in client.c
(instead of two in tmux.c and client.c).


# 1.91 16-Oct-2010 nicm

Make stdio blocking again before calling shell command with -c.


# 1.90 16-Oct-2010 nicm

Trying to set FD_CLOEXEC on every fd is a lost cause, just use
closefrom() before exec.


# 1.89 14-Oct-2010 nicm

Use an explicit event rather than event_once for the main event so it
can be removed when the client becomes ready.


# 1.88 26-Sep-2010 nicm

Two new options:

- server option "exit-unattached" makes the server exit when no clients
are attached, even if sessions are present;

- session option "destroy-unattached" destroys a session once no clients
are attached to it.

These are useful for preventing tmux remaining in the background where
it is undesirable and when using tmux as a login shell to keep a limit
on new sessions.


# 1.87 19-Aug-2010 nicm

Do not call event_del() for signals after fork(), just use sigaction()
directly instead - calling libevent functions after fork() w/o
event_reinit() is a bad idea, even if in this case it was harmless.


Revision tags: OPENBSD_4_8_BASE
# 1.86 04-Aug-2010 deraadt

switch back to kqueue for now, since (a) kqueue has been fixed to deal
with strange devices and (b) since there appears to be a bull in the
poll code in libevent as well...
requested by nicm who is away


# 1.85 24-Jul-2010 nicm

kqueue(2) is currently broken when used with /dev/null and a few other
devices.

An upcoming fix for some problems with the client stdout/stderr handling
relies on it working, so make tmux force libevent to use poll(2) via
EVENT_NOKQUEUE, until we have fixed kqueue.


# 1.84 11-Jul-2010 nicm

Return the command client return code with MSG_EXIT now that MSG_ERROR and
MSG_PRINT are unused.

New clients should be compatible with old tmux servers but vice versa may print
an error.


# 1.83 28-Jun-2010 nicm

Send all three of stdin, stdout, stderr from the client to the server, so that
commands can directly make use of them. This means that load-buffer and
save-buffer can have "-" as the file to read from stdin or write to stdout.

This is a protocol version bump so the tmux server will need to be restarted
after upgrade (or an older client used).


# 1.82 27-Jun-2010 nicm

Store the current working directory in the session, change the default-path
option to default to empty and make that mean that the stored session CWD is
used.


# 1.81 27-Jun-2010 nicm

New option, detach-on-destroy, to set what happens to a client when the session
it is attached to is destroyed. If on (the default), it is detached; if off, it
is switched to the most recently active session.


# 1.80 26-Jun-2010 nicm

Setting the cmdlist pointer in the bind-key to NULL to prevent it being freed
after the command is executing is bogus because it may still be needed if the
same command is going to be executed again (for example if you "bind-key a
bind-key b ..."). Making a copy is hard, so instead add a reference count to
the cmd_list.

While here, also print bind-key -n and the rest of the flags properly.

Fixes problem reported by mcbride@.


# 1.79 14-May-2010 nicm

Colour+attribute options for status line alerts, from Alex Alexander.


# 1.78 04-May-2010 nicm

Put this back in with the initialisation in the right order.


# 1.77 04-May-2010 nicm

Revert last change, it appears to be broken somehow.


# 1.76 03-May-2010 nicm

Make signal handler setup/teardown two common functions instead of six,
and reset SIGCHLD after fork to fix problems with some shells. From
Romain Francois.


# 1.75 28-Apr-2010 nicm

Make the active pane border have a green foreground instead of
background by default.


# 1.74 18-Apr-2010 nicm

Catch SIGCHLD to avoid a zombie, from patrick keshishian.


Revision tags: OPENBSD_4_7_BASE
# 1.73 22-Feb-2010 nicm

Option to set the characters considered word separators in copy mode, from
Micah Cowan.


# 1.72 08-Feb-2010 nicm

Add an option to disable the smcup/rmcup alternate screen behaviour inside
tmux. From clemens fischer.


# 1.71 06-Feb-2010 nicm

Change nested check to compare server socket path rather than just assuming
that if $TMUX is set it is nested. From Micah Cowan.


# 1.70 06-Feb-2010 nicm

Clean up $TMUX parsing, from Micah Cowan, tweaked by me.


# 1.69 06-Feb-2010 nicm

Instead of bailing out on the first configuration file error, carry on,
collecting all the errors, then start with the active window in more mode
displaying them.


# 1.68 04-Feb-2010 nicm

Read the path from $TMUX if it is present and -L and -S are not given. Based on
a diff from Micah Cowan.


# 1.67 04-Feb-2010 nicm

Option to display the active pane in a different colour with the display-panes
command. From Paul Hoffman, thanks.


# 1.66 03-Jan-2010 nicm

Options to set the colour of the pane borders, with different colours for the
active pane.


# 1.65 14-Dec-2009 nicm

New server option, escape-time, to set the timeout used to detect if escapes
are alone or part of a function key or meta sequence.


# 1.64 11-Dec-2009 nicm

Use quiet variable, and add missing sentinel to options array.


# 1.63 10-Dec-2009 nicm

Add "server options" which are server-wide and not bound to a session or
window. Set and displayed with "set -s" and "show -s".

Currently the only option is "quiet" (like command-line -q, allowing it to be
set from .tmux.conf), but others will come along.


# 1.62 03-Dec-2009 nicm

Massive spaces->tabs and trailing whitespace cleanup, hopefully for the last
time now I've configured emacs to make them displayed in really annoying
colours...


# 1.61 26-Nov-2009 nicm

Remove a couple of unused arguments where possible, and add /* ARGSUSED */ to
the rest to reduce lint output.


# 1.60 19-Nov-2009 nicm

Two new options, window-status-format and window-status-current-format, which
allow the format of each window in the status line window list to be controlled
using similar # sequences as status-left/right.

This diff also moves part of the way towards UTF-8 support in window names but
it isn't quite there yet.


# 1.59 19-Nov-2009 nicm

Revert to xterm-keys off by default. It was on as an experiment to see if the
option could be removed, but it affects vi, so we have to keep the option, and
a conservative default is better.


# 1.58 18-Nov-2009 nicm

Add a per-client log of status line messages displayed while that client
exists. A new message-limit session option sets the maximum number of entries
and a command, show-messages, shows the log (bound to ~ by default).

This (and prompt history) might be better as a single global log but until
there are global options it is easier for them to be per client.


# 1.57 10-Nov-2009 nicm

There is no real standard for modifier plus function keys. Previously, tmux
output some from rxvt but in other ways did the same as xterm or other
terminals, but this is a bit inconsistent.

xterm's method is fairly sensible and we already support it (xterm-keys), so
enable it by default instead.


# 1.56 04-Nov-2009 nicm

A couple of minor cosmetic changes.


# 1.55 04-Nov-2009 nicm

Initial changes to move tmux to libevent.

This moves the client-side loops are pretty much fully over to event-based only
(tmux.c and client.c) but server-side (server.c and friends) treats libevent as
a sort of clever poll, waking up after every event to run various things.

Moving the server stuff over to bufferevents and timers and so on will come
later.


# 1.54 04-Nov-2009 nicm

Change declaration and use of malloc_options to be more standard, from Tim van
der Molen.


# 1.53 26-Oct-2009 deraadt

tabs are better; ok nicm


# 1.52 25-Oct-2009 nicm

Remove the -d flag to tmux and just use op/AX to detect default colours.

Irritatingly, although op can be used to tell if a terminal supports default
colours, it can't be used to set them because in some terminfo descriptions it
resets attributes as a side-effect (acts as sgr0) and in others it doesn't, so
it is not possible to determine reliably what the terminal state will be
afterwards. So if AX is missing and op is present, tmux just sends sgr0.

Anyone using -d for a terminal who finds they actually needed it can replace it
using terminal-overrides, but please let me know as it is probably an omission
from terminfo.


# 1.51 22-Oct-2009 nicm

Merge prepare_cmd into main as it is short and only called once.


# 1.50 21-Oct-2009 nicm

Client tidying: get rid of client_ctx struct in favour of two variables in
client.c, and move the functions in client-fn.c into other files.


# 1.49 10-Oct-2009 nicm

New option, mouse-select-pane. If on, the mouse may be used to select the
current pane.

Suggested by sthen@ and also by someone else ages ago who I have forgotten.


# 1.48 10-Oct-2009 nicm

Support for individual session idle time locking. May be enabled by turning off
the lock-server option (it is on by default). When this is off, each session
locks when it has been idle for the lock-after-time setting. When on, the
entire server locks when ALL sessions have been idle for their individual
lock-after-time settings.

This replaces one global-only option (lock-after-time) with another
(lock-server), but the default behaviour is usually preferable so there don't
seem to be many alternatives.

Diff/idea largely from Thomas Adam, tweaked by me.


# 1.47 09-Oct-2009 nicm

Add a simple synchronize-panes window option: when set, all input to any pane
that is part of the window is also sent to all other panes in the same
window. Suggested by several, most recently Tomasz Pajor.


# 1.46 23-Sep-2009 nicm

Support -c like sh(1) to execute a command, useful when tmux is a login
shell. Suggested by halex@.

This includes another protocol version increase (the last for now) so again
restart the tmux server before upgrading.


# 1.45 23-Sep-2009 nicm

Remove the internal tmux locking and instead detach each client and run the
command specified by a new option "lock-command" (by default "lock -np") in
each client.

This means each terminal has to be unlocked individually but simplifies the
code and allows the system password to be used to unlock.

Note that the set-password command is gone, so it will need to be removed from
configuration files, and the -U command line flag has been removed.

This is the third protocol version change so again it is best to stop the tmux
server before upgrading.


# 1.44 22-Sep-2009 nicm

Permit multiple prefix keys to be defined, separated by commas, for example:

set -g prefix ^a,^b

Any key in the list acts as the prefix. The send-prefix command always sends
the first key in the list.


# 1.43 18-Sep-2009 nicm

New option, set-titles-string, to allow the window title to be specified (as
for status-left/right) if set-titles is on. Also only update the title when the
status line is being redrawn.


# 1.42 04-Sep-2009 nicm

Tidy main and make it a bit easier to read.


# 1.41 02-Sep-2009 nicm

Accept -l to make it easier for people who use tmux as a login shell to use
$SHELL. Originally from martynas@, tweaked by me.


# 1.40 02-Sep-2009 nicm

When incorrect passwords are entered, behave similarly to login(1) and backoff
for a bit. Based on a diff from martynas@.


# 1.39 01-Sep-2009 nicm

When using tmux as a login shell, there is currently no way to specify a shell
to be used as a login shell inside tmux, so add a default-shell session option.
This sets the shell invoked as a login shell when the default-command option is
empty.

The default option value is whichever of $SHELL, getpwuid(getuid())'s pw_shell
or /bin/sh is valid first.

Based on a diff from martynas@, changed by me to be a session option rather
than a window option.


# 1.38 01-Sep-2009 nicm

Use "Password:" with no space for password prompts and don't display a *s for
the password, like pretty much everything else. From martynas@ with minor
tweaks by me.


# 1.37 01-Sep-2009 nicm

Sort cases same as getopt argument, from martynas.


# 1.36 31-Aug-2009 nicm

Add a new display-panes command, with two options (display-panes-colour and
display-panes-time), which displays a visual indication of the number of each
pane.


# 1.35 23-Aug-2009 nicm

Add some other obvious variables to update-environment (WINDOWID SSH_ASKPASS
SSH_AUTH_SOCK SSH_AGENT_PID SSH_CONNECTION) so they are updated in the session
environment on new/attach.


# 1.34 13-Aug-2009 nicm

Disable mode-mouse (mouse in copy/choice mode) by default as it isn't very
useful at the moment and causes confusion.


# 1.33 13-Aug-2009 nicm

Add a base-index session option to specify the first index checked when looking
for an index for a new window.


# 1.32 12-Aug-2009 nicm

When started as the shell, __progname contains a leading -, so hardcode "tmux"
for socket path and log files, and strip it when working out the shell.


# 1.31 11-Aug-2009 nicm

Switch tmux to use imsg. This is the last major change to make the
client-server protocol more resilient and make the protocol versioning work
properly. In future, the only things requiring a protocol version bump will be
changes in the message structs, and (when both client and server have this
change) mixing different versions should nicely report an error message.

As a side effect this also makes the code tidier, fixes a problem with the way
errors reported during server startup were handled, and supports fd passing
(which will be used in future).

Looked over by eric@, thanks.

Please note that mixing a client with this change with an older server or vice
versa may cause tmux to crash or hang - tmux should be completely exited before
upgrading.


# 1.30 10-Aug-2009 nicm

No arguments are the same as new-session and this requires the environment to
be sent, so set that flag too when argc == 0.


# 1.29 08-Aug-2009 nicm

Infrastructure and commands to manage the environment for processes started
within tmux.

There is a global environment, copied from the external environment when the
server is started and each sesssion has an (initially empty) session
environment which overrides it.

New commands set-environment and show-environment manipulate or display the
environments.

A new session option, update-environment, is a space-separated list of
variables which are updated from the external environment into the session
environment every time a new session is created - the default is DISPLAY.


# 1.28 08-Aug-2009 nicm

Options to set the colours and attributes for status-left/-right. From Thomas
Adam, thanks.


# 1.27 05-Aug-2009 nicm

If colours are not supported by the terminal, try to emulate a coloured
background by setting or clearing the reverse attribute.

This makes a few applications which don't use the reverse attribute themselves
a little happier, and allows the status, message and mode options to have
default attributes and fg/bg options that work as expected when set as reverse.


# 1.26 04-Aug-2009 nicm

Check for "UTF8" as well as "UTF-8" in LANG etc as it seems this may also
appear.


# 1.25 03-Aug-2009 nicm

Add a terminal-overrides session option allowing individual terminfo(5) entries
to be overridden. The 88col/256col checks are now moved into the default
setting and out of the code.

Also remove a couple of old workarounds for xterm and rxvt which are no longer
necessary (tmux can emulate them if missing).


# 1.24 30-Jul-2009 nicm

Add a mode-mouse option to prevent tmux taking over the mouse in choice or copy
modes.


# 1.23 29-Jul-2009 nicm

Rename struct hdrtype to msgtype which is a better name and can be used even
when struct hdr disappears.


# 1.22 29-Jul-2009 nicm

Taking account of the "s, 22 not 24 is the maximum length of #T in status-right
to prevent the date being cut off.


# 1.21 26-Jul-2009 nicm

Make all messages sent between the client and server fixed size.

This is the first of two changes to make the protocol more resilient and less
sensitive to other changes in the code, particularly with commands. The client
now packs argv into a buffer and sends it to the server for parsing, rather
than doing it itself and sending the parsed command data.

As a side-effect this also removes a lot of now-unused command marshalling
code.

Mixing a server without this change and a client with or vice versa will cause
tmux to hang or crash, please ensure that tmux is entirely killed before
upgrading.


# 1.20 22-Jul-2009 nicm

Pass a set of flags into client_init rather than just a start_server
variable. Only one flag now but more to come later.


# 1.19 20-Jul-2009 nicm

Display the number of failed password attempts (if any) when the server is
locked. From Tom Doherty.


# 1.18 20-Jul-2009 nicm

Add a status-justify option to allow the window list in the status line to be
positioned at the left, centre, or right.


# 1.17 20-Jul-2009 nicm

New options, window-status-current-{fg,bg,attr}, to set the fg, bg and
attributes with which the current window is shown in the status line. From
Johan Friis, thanks.


# 1.16 18-Jul-2009 nicm

Add three new session options: visual-activity, visual-bell, visual-content. If
these are enabled (and the monitor-activity, bell-actio and monitor-content
options are configurated appropriately), when activity, a bell, or content is
detected, a message is shown.

Also tidy up the bell/activity/content code in server.c slightly and fix a
couple of errors.


# 1.15 17-Jul-2009 nicm

If -u is specified or UTF-8 is otherwise detected when the server is started,
enable the utf8 and status-utf8 optons. While here, note in the man page that
the server is started with the first session and exits when none remain.


# 1.14 10-Jul-2009 nicm

Add a default-terminal option to set the starting value of $TERM in new
windows.

This is "screen" by default and must be either that or something closely
related. This does makes it easier to customise it if necessary.


# 1.13 08-Jul-2009 nicm

Just appending -l to $SHELL to create a login shell is wrong: -l is not POSIX,
and some people may use shells which do not support it. Instead, make an empty
default-command option mean a login shell, and fork it with a - in argv[0]
which is the method used by login(1).

Also fix the automatic-rename code to handle this correctly and to strip a
leading - if present.


# 1.12 07-Jul-2009 nicm

Rename the global options variables to be shorter and to make session options
clear. No functional change, getting this out of the way to make later options
changes easier.


Revision tags: OPENBSD_4_6_BASE
# 1.11 25-Jun-2009 nicm

If getcwd() fails, use the user's home directory, or /, instead of failing with
an error.


# 1.10 25-Jun-2009 nicm

Remove error about using -L and -S together which was never displayed as
logging wasn't yet enabled, was unnecessary, and contradicted the man page
which says using -S will cause -L to be ignored.


# 1.9 23-Jun-2009 nicm

LC_ALL overrides LC_CTYPE and LANG. Comment was correct but the code
wrong. Pointed out by Hannah Schroeter, thanks.


# 1.8 05-Jun-2009 nicm

Check the first of LC_CTYPE, LC_ALL and LANG, rather than just the last, when
trying to decide about UTF-8, and use strcasestr. Reported by Geert Hendrickx.


# 1.7 04-Jun-2009 nicm

Zero the password given to -U in the client as well.


# 1.6 03-Jun-2009 nicm

Do not set the window title by default (make set-titles option default to off),
wiping over the title is rude and annoying. Agreed by several.


# 1.5 03-Jun-2009 nicm

New session option, status-utf8, to control the interpretation of top-bit-set
characters in status-left and status-right (if on, they are treated as UTF-8;
otherwise passed through).


# 1.4 02-Jun-2009 sobrado

remove unused flag; while here, make usage's output fit on 80-column displays.


# 1.3 02-Jun-2009 pyr

spawn login shells by default, adapt manpage bits as well.
ok nicm@


# 1.2 02-Jun-2009 ray

Don't leak memory if multiple -f flags are given.

OK nicm@


# 1.1 01-Jun-2009 nicm

Import tmux, a terminal multiplexor allowing (among other things) a single
terminal to be switched between several different windows and programs
displayed on one terminal be detached from one terminal and moved to another.

ok deraadt pirofti


# 1.190 14-Oct-2019 nicm

Memory leaks, from Igor Wong in GitHub issue 1934.


Revision tags: OPENBSD_6_6_BASE
# 1.189 20-Jun-2019 nicm

Add a per-pane option set. Pane options inherit from window options (so
there should be no change to existing behaviour) and are set and shown
with set-option -p and show-options -p.

Change remain-on-exit and window-style/window-active-style to be pane
options (some others will be changed later).

This makes select-pane -P and -g unnecessary so no longer document them
(they still work) and no longer document set-window-option and
show-window-options in favour of set-option -w and show-options -w.


# 1.188 26-Apr-2019 nicm

Merge hooks into options and make each one an array option. This allows
multiple commands to be easily bound to one hook. set-hook and
show-hooks remain but they are now variants of set-option and
show-options. show-options now has a -H flag to show hooks (by default
they are not shown).


Revision tags: OPENBSD_6_5_BASE
# 1.187 22-Nov-2018 nicm

Do not use PWD unless it actually matches the real working directory.


Revision tags: OPENBSD_6_3_BASE OPENBSD_6_4_BASE
# 1.186 12-Jan-2018 nicm

Improve error message if creating socket parent directory fails, from
Thomas Adam for GitHub issue 1215.


# 1.185 01-Jan-2018 nicm

Prefer PWD for current directory if present in client, from Wei Zhao in
GitHub issue 1183.


Revision tags: OPENBSD_6_2_BASE
# 1.184 12-Jul-2017 nicm

Make shell_command a global like other stuff rather than making it an
exception and using callback argument.


# 1.183 03-Jul-2017 nicm

Try C.UTF-8 which is also a commonly useful locale on some platforms,
from Romain Francoise.


# 1.182 22-Apr-2017 nicm

Do not need getopt.h.


# 1.181 20-Apr-2017 nicm

Use fdforkpty() instead of our own unwrapped versions.


# 1.180 19-Apr-2017 nicm

Style nits and a missing cast.


# 1.179 16-Apr-2017 nicm

Memory leak, from David CARLIER.


Revision tags: OPENBSD_6_1_BASE
# 1.178 21-Mar-2017 nicm

Use uid_t for UID not u_int.


# 1.177 16-Feb-2017 nicm

Style nits.


# 1.176 23-Jan-2017 nicm

Open /dev/ptm before pledge() and save it to be used for PTMGET later
(this means inlining forkpty()).

ok deraadt


# 1.175 15-Jan-2017 nicm

Major tidy up and rework of options tree and set-option/show-options
commands this pushes more of the code into options.c and ties it more
closely to the options table rather than having an unnecessary
split. Also add support for array options (will be used later). Only
(intentional) user visible change is that show-options output is now
passed through vis(3) with VIS_DQ so quotes are escaped.


# 1.174 12-Jan-2017 nicm

Simplify appending to string options.


# 1.173 09-Dec-2016 nicm

Spacing nits.


# 1.172 11-Oct-2016 nicm

Add static in window-*.c and move some internal functions out of tmux.h.


# 1.171 10-Oct-2016 nicm

Loads more static, except for cmd-*.c and window-*.c.


Revision tags: OPENBSD_6_0_BASE
# 1.170 27-May-2016 nicm

Use getprogname() instead of __progname to make portability easier.


# 1.169 04-May-2016 nicm

Fix up a couple of long lines.


# 1.168 05-Mar-2016 nicm

If setlocale("en_US.UTF-8") succeeds, then don't do the check for UTF-8
locale since if it isn't UTF-8 the system is broken anyway. If it fails,
try "" and check for UTF-8 with nl_langinfo(CODESET) rather than
wcwidth(). Based on a diff from schwarze@, nl_langinfo also suggested by
stsp@.


# 1.167 05-Mar-2016 nicm

Although we always have en_US.UTF-8 on OpenBSD, some platforms do not,
so fall back to setlocale(LC_CTYPE, ""). tmux requires a UTF-8 locale,
so check with wcwidth() on a UTF-8 character after setlocale().


# 1.166 01-Mar-2016 nicm

Remove unused variables, from Michal Mazurek.


# 1.165 01-Mar-2016 nicm

Use system wcwidth() instead of carrying around UTF-8 width tables.


Revision tags: OPENBSD_5_9_BASE
# 1.164 19-Jan-2016 nicm

I no longer use my SourceForge address so replace it.


# 1.163 08-Dec-2015 nicm

Add hooks infrastructure, basic commands (set-hook, show-hooks) and a
couple of not very useful client hooks. This will eventually let
commands be run at various points and on notifications. Joint work with
Thomas Adam.


# 1.162 24-Nov-2015 nicm

Make environ_set va_args and use it to tidy up some calls. Also add a
missing word in manpage (from jmc).


# 1.161 24-Nov-2015 nicm

Shell command from -c doesn't have to be global, pass it as an argument.


# 1.160 24-Nov-2015 nicm

Tidy the code that works out the socket path, and just use the full path
in the global socket_path rather than copying it.


# 1.159 24-Nov-2015 nicm

Remove malloc_options DEBUG bit.


# 1.158 24-Nov-2015 nicm

Remove the -I part of show-messages which isn't really that useful; the
server start time can now be accessed with a new start_time format (use:
tmux display -p '#{t:start_time}')


# 1.157 24-Nov-2015 nicm

Make the log stuff a bit tidier with some helper functions.


# 1.156 22-Nov-2015 nicm

Add getpw to pledge, makes tmux work in YP environments, discovered by
matthieu, ok deraadt


# 1.155 20-Nov-2015 nicm

Instead of separate tables for different types of options, give each
option a scope type (server, session, window) in one table.


# 1.154 15-Nov-2015 nicm

Accidentally turned off pledge, turn it back on.


# 1.153 14-Nov-2015 nicm

Push stdout and stderr to clients more aggressively, and add an event to
continue if the send fails.


# 1.152 12-Nov-2015 nicm

tmux is UTF-8, so if $TMUX is set (tmux running in tmux), the client is
UTF-8. Also try to make the existing checks more readable.


# 1.151 12-Nov-2015 nicm

Nuke the utf8 and status-utf8 options and make tmux only a UTF-8
terminal. We still support non-UTF-8 terminals outside tmux, but inside
it is always UTF-8 (as when the utf8 and status-utf8 options were on).


# 1.150 11-Nov-2015 nicm

Drop mouse-utf8 option and always turn on UTF-8 mouse if the client says
it supports UTF-8.


# 1.149 28-Oct-2015 nicm

Like options, move the environ struct into environ.c.


# 1.148 27-Oct-2015 nicm

Move struct options into options.c.


# 1.147 27-Oct-2015 nicm

Break the common process set up, event loop and imsg dispatch code
between server and client out into a separate internal API. This will
make it easier to add another process.


# 1.146 25-Oct-2015 deraadt

Let's see if anyone screams about not being able to specify $TMPDIR
for their tmux sockets.

(Over the years, I have seen $TMPDIR set up worse than /tmp many times,
and don't know how this practice infected other parts of the system.
Nothing uses tmpdir(3), nor a huge-temporary-file program like sort.)
ok nicm


# 1.145 23-Oct-2015 nicm

tmux can call pledge() in main with large set and then reduce it
slightly in the server to "stdio rpath wpath cpath fattr unix recvfd
proc exec tty ps".


# 1.144 14-Sep-2015 nicm

Move tzset() from log_open to main.


# 1.143 03-Sep-2015 nicm

A couple of style nits.


# 1.142 01-Sep-2015 nicm

Work out config file when needed not at startup.


# 1.141 30-Aug-2015 nicm

Path from $TMUX does not need to be global anymore.


# 1.140 30-Aug-2015 nicm

Login shell can be a client flag, and move the exec code into client.c.


# 1.139 30-Aug-2015 nicm

Event base does not need to be global.


# 1.138 30-Aug-2015 nicm

Some style nits and dead assignments.


Revision tags: OPENBSD_5_8_BASE
# 1.137 20-Jul-2015 nicm

Add an option (history-file) for a file to save/restore command prompt
history, from Olof-Joachim Frahm.


# 1.136 04-Jun-2015 jmc

tweak SYNOPSIS and usage();


Revision tags: OPENBSD_5_7_BASE
# 1.135 19-Jan-2015 nicm

Make a tmux-%u directory under TMUX_TMPDIR, like TMPDIR.


# 1.134 19-Jan-2015 nicm

Only care about other permissions, allow group to be set.


# 1.133 19-Jan-2015 nicm

Remove unnecessary duplicate S_ISDIR check, from Dmitri Paduchikh.


# 1.132 20-Oct-2014 nicm

Tidy up some includes.


Revision tags: OPENBSD_5_6_BASE
# 1.131 17-Apr-2014 nicm

Remove the "info" message mechanism, this was only used for about five
mostly useless and annoying messages. Change those commands to silence
on success like all the others. Still accept the -q command line flag
and "quiet" server option for now.


# 1.130 31-Mar-2014 nicm

Remove log_debug2 as well and simplify log.c.


Revision tags: OPENBSD_5_5_BASE
# 1.129 16-Feb-2014 nicm

Leftovers from removing 88 colour support, from Theo Buehler.


# 1.128 15-Jan-2014 nicm

Do not attempt to read .tmux.conf if we can't figure out a home
directory, from Tiago Cunha.


# 1.127 09-Jan-2014 nicm

Three small changes from Tiago Cunha:

- Check for truncation when copying path.
- Don't need to use a temporary buffer in screen_set_title.
- Include strerror in output when connecting to server fails.


# 1.126 10-Oct-2013 nicm

We accidentally haven't been using $TMUX to work out the session for a
while and in fact it is less useful that using the client ttyname. So
don't bother and don't pass it from the client. If we need it in future
it is in c->environ.


# 1.125 10-Oct-2013 nicm

Alter how tmux handles the working directory to internally use file
descriptors rather than strings.

- Each session still has a current working directory.

- New sessions still get their working directory from the client that
created them or its attached session if any.

- New windows are created by default in the session working directory.

- The -c flag to new, neww, splitw allows the working directory to be
overridden.

- The -c flag to attach let's the session working directory be changed.

- The default-path option has been removed.

To get the equivalent to default-path '.', do:

bind c neww -c $PWD

To get the equivalent of default-path '~', do:

bind c neww -c ~

This also changes the client identify protocol to be a set of messages rather
than one as well as some other changes that should make it easier to make
backwards-compatible protocol changes in future.


# 1.124 10-Oct-2013 nicm

Merge IDENTIFY_* flags with CLIENT_* flags.


# 1.123 10-Oct-2013 nicm

Don't treat TMUX_TMPDIR as a potential file

The point of setting TMUX_TMPDIR is to then make any labels from -L go
to that directory. In the case of makesocketpath() with no TMUX_TMPDIR
set, would set both the path and the default socket to a file. The
checking of the permissions on the file worked fine in that case, but
when TMUX_TMPDIR is set, won't work on a directory.

This fixes the problem by ensuring the check on the permissions is
performed on directories only.

By Thomas Adam.


# 1.122 05-Oct-2013 nicm

Fix previous not to leak fd on failure, whoops.


# 1.121 05-Oct-2013 nicm

Use open(".")/fchdir() to save and restore current directory rather than
getcwd()/chdir().


Revision tags: OPENBSD_5_4_BASE
# 1.120 24-Apr-2013 nicm

Rename global configuration define.


# 1.119 11-Apr-2013 nicm

Call setlocale(LC_TIME) at startup.


# 1.118 27-Mar-2013 nicm

Add TMUX_TMPDIR variable to put the socket directory outside
TMPDIR. From Ben Boeckel.


# 1.117 27-Mar-2013 nicm

Remove tmux's (already minimal) 88 colour support. Such terminals are
few and unnecessary.


# 1.116 25-Mar-2013 nicm

Rename session idx to session id throughout and add $ prefix to targets
to use it, extended from a diff from George Nachman.


# 1.115 24-Mar-2013 nicm

Add a command queue to standardize and simplify commands that call other
commands and allow a command to block execution of subsequent
commands. This allows run-shell and if-shell to be synchronous which has
been much requested.

Each client has a default command queue and commands are consumed one at
a time from it. A command may suspend execution from the queue by
returning CMD_RETURN_WAIT and then resume it by calling cmd_continue() -
for example run-shell does this from the callback that is fired after
the job is freed.

When the command queue becomes empty, command clients are automatically
exited (unless attaching). A callback is also fired - this is used for
nested commands in, for example, if-shell which can block execution of
the client's cmdq until a new cmdq becomes empty.

Also merge all the old error/info/print functions together and lose the
old curclient/cmdclient distinction - a cmdq is bound to one client (or
none if in the configuration file), this is a command client if
c->session is NULL otherwise an attached client.


Revision tags: OPENBSD_5_3_BASE
# 1.114 27-Nov-2012 nicm

Correctly aggregate together errors from nested config files (with
source-file). Fix by Thomas Adam, reported by Sam Livingstone-Gray


# 1.113 26-Nov-2012 nicm

Call realpath earlier on the socket directory path rather than on the
socket file path because the latter may not exist yet and in that case
realpath is allowed to fail. From Romain Francoise.


Revision tags: OPENBSD_5_2_BASE
# 1.112 10-Jul-2012 nicm

xfree is not particularly helpful, remove it. From Thomas Adam.


# 1.111 18-Jun-2012 nicm

Add a skeleton mode to tmux (called "control mode") that let's tmux
commands be sent and output received on stdout. This can be used to
integrate with other terminal emulators and should allow some other
things to be made simpler later. More to come so doesn't do much yet and
deliberately not documented.


# 1.110 30-May-2012 nicm

Do not use stderr for log file and don't call log_close when not needed.


# 1.109 25-May-2012 nicm

Simplify logging and just fprintf(stderr, ...) for early errors.


Revision tags: OPENBSD_5_1_BASE
# 1.108 21-Jan-2012 nicm

Drop the ability to have a list of keys in the prefix in favour of two
separate options, prefix and prefix2. This simplifies the code and gets
rid the data options type which was only used for this one option.

Also add a -2 flag to send-prefix to send the secondary prefix key,
fixing a cause of minor irritation.

People who want three prefix keys are out of luck :-).


# 1.107 23-Oct-2011 nicm

Try to resolve relative paths for loadb and saveb (first using client
working directory if any then default-path or session wd).


# 1.106 23-Oct-2011 nicm

Ignore LC_ALL and LC_CTYPE if they are empty as well as unset.


# 1.105 25-Sep-2011 nicm

Reject $SHELL if it is not a full path.


Revision tags: OPENBSD_5_0_BASE
# 1.104 04-Mar-2011 nicm

Two fixes by Micah Cowan: make mouse work properly beyond >127 on signed
char architectures and properly parse $TMUX by stopping the socket path
at the first comma.


Revision tags: OPENBSD_4_9_BASE
# 1.103 23-Jan-2011 nicm

Set $TMUX without the session when background jobs are run.


# 1.102 12-Jan-2011 nicm

Use TMPDIR if set, from Han Boetes.


# 1.101 08-Jan-2011 nicm

Move all calls to fcntl(...O_NONBLOCK) into a function and clear the
flag on the stdio file descriptors before closing them (fixes things
like "tmux ls && cat").


# 1.100 03-Jan-2011 nicm

Support for UTF-8 mouse input (\033[1005h). This was added in xterm 262
and supports larger terminals than the older way.

If the new mouse-utf8 option is on, UTF-8 mouse input is enabled for all
UTF-8 terminals. The option defaults to on if LANG etc are set in the
same manner as the utf8 option.

With help and based on code from hsim at gmx.li.


# 1.99 01-Jan-2011 nicm

Move the user-visible parts of all options (names, types, limit, default
values) together into one set of tables in options-table.c. Also clean
up and simplify cmd-set-options.c and move a common print function into
option-table.c.


# 1.98 30-Dec-2010 nicm

Change from a per-session stack of buffers to one global stack which is
much more convenient and also simplifies lot of code. This renders
copy-buffer useless and makes buffer-limit now a server option.

By Tiago Cunha.


# 1.97 19-Dec-2010 nicm

Add other-pane-height and other-pane-width options, allowing the width
or height of the smaller panes in the main-horizontal and main-vertical
layouts to be set. Mostly from David Goodlad.


# 1.96 08-Dec-2010 nicm

In the built-in layouts, distribute the panes more evenly. Set the
default value of main-pane-width to 80, rather than 81. By Micah Cowan.


# 1.95 06-Dec-2010 nicm

Add an option to alert (monitor) for silence (lack of activity) in a
window. From Thomas Adam.


# 1.94 29-Nov-2010 nicm

If VISUAL or EDITOR contains "vi", configure mode-keys and status-keys
to vi.

Based on a diff from martynas@, previously requested by a couple of
other people.


# 1.93 11-Nov-2010 nicm

Add XAUTHORITY to update-environment, requested by Andreas Kloeckner.


# 1.92 18-Oct-2010 nicm

Merge the before and after attach client code into one in client.c
(instead of two in tmux.c and client.c).


# 1.91 16-Oct-2010 nicm

Make stdio blocking again before calling shell command with -c.


# 1.90 16-Oct-2010 nicm

Trying to set FD_CLOEXEC on every fd is a lost cause, just use
closefrom() before exec.


# 1.89 14-Oct-2010 nicm

Use an explicit event rather than event_once for the main event so it
can be removed when the client becomes ready.


# 1.88 26-Sep-2010 nicm

Two new options:

- server option "exit-unattached" makes the server exit when no clients
are attached, even if sessions are present;

- session option "destroy-unattached" destroys a session once no clients
are attached to it.

These are useful for preventing tmux remaining in the background where
it is undesirable and when using tmux as a login shell to keep a limit
on new sessions.


# 1.87 19-Aug-2010 nicm

Do not call event_del() for signals after fork(), just use sigaction()
directly instead - calling libevent functions after fork() w/o
event_reinit() is a bad idea, even if in this case it was harmless.


Revision tags: OPENBSD_4_8_BASE
# 1.86 04-Aug-2010 deraadt

switch back to kqueue for now, since (a) kqueue has been fixed to deal
with strange devices and (b) since there appears to be a bull in the
poll code in libevent as well...
requested by nicm who is away


# 1.85 24-Jul-2010 nicm

kqueue(2) is currently broken when used with /dev/null and a few other
devices.

An upcoming fix for some problems with the client stdout/stderr handling
relies on it working, so make tmux force libevent to use poll(2) via
EVENT_NOKQUEUE, until we have fixed kqueue.


# 1.84 11-Jul-2010 nicm

Return the command client return code with MSG_EXIT now that MSG_ERROR and
MSG_PRINT are unused.

New clients should be compatible with old tmux servers but vice versa may print
an error.


# 1.83 28-Jun-2010 nicm

Send all three of stdin, stdout, stderr from the client to the server, so that
commands can directly make use of them. This means that load-buffer and
save-buffer can have "-" as the file to read from stdin or write to stdout.

This is a protocol version bump so the tmux server will need to be restarted
after upgrade (or an older client used).


# 1.82 27-Jun-2010 nicm

Store the current working directory in the session, change the default-path
option to default to empty and make that mean that the stored session CWD is
used.


# 1.81 27-Jun-2010 nicm

New option, detach-on-destroy, to set what happens to a client when the session
it is attached to is destroyed. If on (the default), it is detached; if off, it
is switched to the most recently active session.


# 1.80 26-Jun-2010 nicm

Setting the cmdlist pointer in the bind-key to NULL to prevent it being freed
after the command is executing is bogus because it may still be needed if the
same command is going to be executed again (for example if you "bind-key a
bind-key b ..."). Making a copy is hard, so instead add a reference count to
the cmd_list.

While here, also print bind-key -n and the rest of the flags properly.

Fixes problem reported by mcbride@.


# 1.79 14-May-2010 nicm

Colour+attribute options for status line alerts, from Alex Alexander.


# 1.78 04-May-2010 nicm

Put this back in with the initialisation in the right order.


# 1.77 04-May-2010 nicm

Revert last change, it appears to be broken somehow.


# 1.76 03-May-2010 nicm

Make signal handler setup/teardown two common functions instead of six,
and reset SIGCHLD after fork to fix problems with some shells. From
Romain Francois.


# 1.75 28-Apr-2010 nicm

Make the active pane border have a green foreground instead of
background by default.


# 1.74 18-Apr-2010 nicm

Catch SIGCHLD to avoid a zombie, from patrick keshishian.


Revision tags: OPENBSD_4_7_BASE
# 1.73 22-Feb-2010 nicm

Option to set the characters considered word separators in copy mode, from
Micah Cowan.


# 1.72 08-Feb-2010 nicm

Add an option to disable the smcup/rmcup alternate screen behaviour inside
tmux. From clemens fischer.


# 1.71 06-Feb-2010 nicm

Change nested check to compare server socket path rather than just assuming
that if $TMUX is set it is nested. From Micah Cowan.


# 1.70 06-Feb-2010 nicm

Clean up $TMUX parsing, from Micah Cowan, tweaked by me.


# 1.69 06-Feb-2010 nicm

Instead of bailing out on the first configuration file error, carry on,
collecting all the errors, then start with the active window in more mode
displaying them.


# 1.68 04-Feb-2010 nicm

Read the path from $TMUX if it is present and -L and -S are not given. Based on
a diff from Micah Cowan.


# 1.67 04-Feb-2010 nicm

Option to display the active pane in a different colour with the display-panes
command. From Paul Hoffman, thanks.


# 1.66 03-Jan-2010 nicm

Options to set the colour of the pane borders, with different colours for the
active pane.


# 1.65 14-Dec-2009 nicm

New server option, escape-time, to set the timeout used to detect if escapes
are alone or part of a function key or meta sequence.


# 1.64 11-Dec-2009 nicm

Use quiet variable, and add missing sentinel to options array.


# 1.63 10-Dec-2009 nicm

Add "server options" which are server-wide and not bound to a session or
window. Set and displayed with "set -s" and "show -s".

Currently the only option is "quiet" (like command-line -q, allowing it to be
set from .tmux.conf), but others will come along.


# 1.62 03-Dec-2009 nicm

Massive spaces->tabs and trailing whitespace cleanup, hopefully for the last
time now I've configured emacs to make them displayed in really annoying
colours...


# 1.61 26-Nov-2009 nicm

Remove a couple of unused arguments where possible, and add /* ARGSUSED */ to
the rest to reduce lint output.


# 1.60 19-Nov-2009 nicm

Two new options, window-status-format and window-status-current-format, which
allow the format of each window in the status line window list to be controlled
using similar # sequences as status-left/right.

This diff also moves part of the way towards UTF-8 support in window names but
it isn't quite there yet.


# 1.59 19-Nov-2009 nicm

Revert to xterm-keys off by default. It was on as an experiment to see if the
option could be removed, but it affects vi, so we have to keep the option, and
a conservative default is better.


# 1.58 18-Nov-2009 nicm

Add a per-client log of status line messages displayed while that client
exists. A new message-limit session option sets the maximum number of entries
and a command, show-messages, shows the log (bound to ~ by default).

This (and prompt history) might be better as a single global log but until
there are global options it is easier for them to be per client.


# 1.57 10-Nov-2009 nicm

There is no real standard for modifier plus function keys. Previously, tmux
output some from rxvt but in other ways did the same as xterm or other
terminals, but this is a bit inconsistent.

xterm's method is fairly sensible and we already support it (xterm-keys), so
enable it by default instead.


# 1.56 04-Nov-2009 nicm

A couple of minor cosmetic changes.


# 1.55 04-Nov-2009 nicm

Initial changes to move tmux to libevent.

This moves the client-side loops are pretty much fully over to event-based only
(tmux.c and client.c) but server-side (server.c and friends) treats libevent as
a sort of clever poll, waking up after every event to run various things.

Moving the server stuff over to bufferevents and timers and so on will come
later.


# 1.54 04-Nov-2009 nicm

Change declaration and use of malloc_options to be more standard, from Tim van
der Molen.


# 1.53 26-Oct-2009 deraadt

tabs are better; ok nicm


# 1.52 25-Oct-2009 nicm

Remove the -d flag to tmux and just use op/AX to detect default colours.

Irritatingly, although op can be used to tell if a terminal supports default
colours, it can't be used to set them because in some terminfo descriptions it
resets attributes as a side-effect (acts as sgr0) and in others it doesn't, so
it is not possible to determine reliably what the terminal state will be
afterwards. So if AX is missing and op is present, tmux just sends sgr0.

Anyone using -d for a terminal who finds they actually needed it can replace it
using terminal-overrides, but please let me know as it is probably an omission
from terminfo.


# 1.51 22-Oct-2009 nicm

Merge prepare_cmd into main as it is short and only called once.


# 1.50 21-Oct-2009 nicm

Client tidying: get rid of client_ctx struct in favour of two variables in
client.c, and move the functions in client-fn.c into other files.


# 1.49 10-Oct-2009 nicm

New option, mouse-select-pane. If on, the mouse may be used to select the
current pane.

Suggested by sthen@ and also by someone else ages ago who I have forgotten.


# 1.48 10-Oct-2009 nicm

Support for individual session idle time locking. May be enabled by turning off
the lock-server option (it is on by default). When this is off, each session
locks when it has been idle for the lock-after-time setting. When on, the
entire server locks when ALL sessions have been idle for their individual
lock-after-time settings.

This replaces one global-only option (lock-after-time) with another
(lock-server), but the default behaviour is usually preferable so there don't
seem to be many alternatives.

Diff/idea largely from Thomas Adam, tweaked by me.


# 1.47 09-Oct-2009 nicm

Add a simple synchronize-panes window option: when set, all input to any pane
that is part of the window is also sent to all other panes in the same
window. Suggested by several, most recently Tomasz Pajor.


# 1.46 23-Sep-2009 nicm

Support -c like sh(1) to execute a command, useful when tmux is a login
shell. Suggested by halex@.

This includes another protocol version increase (the last for now) so again
restart the tmux server before upgrading.


# 1.45 23-Sep-2009 nicm

Remove the internal tmux locking and instead detach each client and run the
command specified by a new option "lock-command" (by default "lock -np") in
each client.

This means each terminal has to be unlocked individually but simplifies the
code and allows the system password to be used to unlock.

Note that the set-password command is gone, so it will need to be removed from
configuration files, and the -U command line flag has been removed.

This is the third protocol version change so again it is best to stop the tmux
server before upgrading.


# 1.44 22-Sep-2009 nicm

Permit multiple prefix keys to be defined, separated by commas, for example:

set -g prefix ^a,^b

Any key in the list acts as the prefix. The send-prefix command always sends
the first key in the list.


# 1.43 18-Sep-2009 nicm

New option, set-titles-string, to allow the window title to be specified (as
for status-left/right) if set-titles is on. Also only update the title when the
status line is being redrawn.


# 1.42 04-Sep-2009 nicm

Tidy main and make it a bit easier to read.


# 1.41 02-Sep-2009 nicm

Accept -l to make it easier for people who use tmux as a login shell to use
$SHELL. Originally from martynas@, tweaked by me.


# 1.40 02-Sep-2009 nicm

When incorrect passwords are entered, behave similarly to login(1) and backoff
for a bit. Based on a diff from martynas@.


# 1.39 01-Sep-2009 nicm

When using tmux as a login shell, there is currently no way to specify a shell
to be used as a login shell inside tmux, so add a default-shell session option.
This sets the shell invoked as a login shell when the default-command option is
empty.

The default option value is whichever of $SHELL, getpwuid(getuid())'s pw_shell
or /bin/sh is valid first.

Based on a diff from martynas@, changed by me to be a session option rather
than a window option.


# 1.38 01-Sep-2009 nicm

Use "Password:" with no space for password prompts and don't display a *s for
the password, like pretty much everything else. From martynas@ with minor
tweaks by me.


# 1.37 01-Sep-2009 nicm

Sort cases same as getopt argument, from martynas.


# 1.36 31-Aug-2009 nicm

Add a new display-panes command, with two options (display-panes-colour and
display-panes-time), which displays a visual indication of the number of each
pane.


# 1.35 23-Aug-2009 nicm

Add some other obvious variables to update-environment (WINDOWID SSH_ASKPASS
SSH_AUTH_SOCK SSH_AGENT_PID SSH_CONNECTION) so they are updated in the session
environment on new/attach.


# 1.34 13-Aug-2009 nicm

Disable mode-mouse (mouse in copy/choice mode) by default as it isn't very
useful at the moment and causes confusion.


# 1.33 13-Aug-2009 nicm

Add a base-index session option to specify the first index checked when looking
for an index for a new window.


# 1.32 12-Aug-2009 nicm

When started as the shell, __progname contains a leading -, so hardcode "tmux"
for socket path and log files, and strip it when working out the shell.


# 1.31 11-Aug-2009 nicm

Switch tmux to use imsg. This is the last major change to make the
client-server protocol more resilient and make the protocol versioning work
properly. In future, the only things requiring a protocol version bump will be
changes in the message structs, and (when both client and server have this
change) mixing different versions should nicely report an error message.

As a side effect this also makes the code tidier, fixes a problem with the way
errors reported during server startup were handled, and supports fd passing
(which will be used in future).

Looked over by eric@, thanks.

Please note that mixing a client with this change with an older server or vice
versa may cause tmux to crash or hang - tmux should be completely exited before
upgrading.


# 1.30 10-Aug-2009 nicm

No arguments are the same as new-session and this requires the environment to
be sent, so set that flag too when argc == 0.


# 1.29 08-Aug-2009 nicm

Infrastructure and commands to manage the environment for processes started
within tmux.

There is a global environment, copied from the external environment when the
server is started and each sesssion has an (initially empty) session
environment which overrides it.

New commands set-environment and show-environment manipulate or display the
environments.

A new session option, update-environment, is a space-separated list of
variables which are updated from the external environment into the session
environment every time a new session is created - the default is DISPLAY.


# 1.28 08-Aug-2009 nicm

Options to set the colours and attributes for status-left/-right. From Thomas
Adam, thanks.


# 1.27 05-Aug-2009 nicm

If colours are not supported by the terminal, try to emulate a coloured
background by setting or clearing the reverse attribute.

This makes a few applications which don't use the reverse attribute themselves
a little happier, and allows the status, message and mode options to have
default attributes and fg/bg options that work as expected when set as reverse.


# 1.26 04-Aug-2009 nicm

Check for "UTF8" as well as "UTF-8" in LANG etc as it seems this may also
appear.


# 1.25 03-Aug-2009 nicm

Add a terminal-overrides session option allowing individual terminfo(5) entries
to be overridden. The 88col/256col checks are now moved into the default
setting and out of the code.

Also remove a couple of old workarounds for xterm and rxvt which are no longer
necessary (tmux can emulate them if missing).


# 1.24 30-Jul-2009 nicm

Add a mode-mouse option to prevent tmux taking over the mouse in choice or copy
modes.


# 1.23 29-Jul-2009 nicm

Rename struct hdrtype to msgtype which is a better name and can be used even
when struct hdr disappears.


# 1.22 29-Jul-2009 nicm

Taking account of the "s, 22 not 24 is the maximum length of #T in status-right
to prevent the date being cut off.


# 1.21 26-Jul-2009 nicm

Make all messages sent between the client and server fixed size.

This is the first of two changes to make the protocol more resilient and less
sensitive to other changes in the code, particularly with commands. The client
now packs argv into a buffer and sends it to the server for parsing, rather
than doing it itself and sending the parsed command data.

As a side-effect this also removes a lot of now-unused command marshalling
code.

Mixing a server without this change and a client with or vice versa will cause
tmux to hang or crash, please ensure that tmux is entirely killed before
upgrading.


# 1.20 22-Jul-2009 nicm

Pass a set of flags into client_init rather than just a start_server
variable. Only one flag now but more to come later.


# 1.19 20-Jul-2009 nicm

Display the number of failed password attempts (if any) when the server is
locked. From Tom Doherty.


# 1.18 20-Jul-2009 nicm

Add a status-justify option to allow the window list in the status line to be
positioned at the left, centre, or right.


# 1.17 20-Jul-2009 nicm

New options, window-status-current-{fg,bg,attr}, to set the fg, bg and
attributes with which the current window is shown in the status line. From
Johan Friis, thanks.


# 1.16 18-Jul-2009 nicm

Add three new session options: visual-activity, visual-bell, visual-content. If
these are enabled (and the monitor-activity, bell-actio and monitor-content
options are configurated appropriately), when activity, a bell, or content is
detected, a message is shown.

Also tidy up the bell/activity/content code in server.c slightly and fix a
couple of errors.


# 1.15 17-Jul-2009 nicm

If -u is specified or UTF-8 is otherwise detected when the server is started,
enable the utf8 and status-utf8 optons. While here, note in the man page that
the server is started with the first session and exits when none remain.


# 1.14 10-Jul-2009 nicm

Add a default-terminal option to set the starting value of $TERM in new
windows.

This is "screen" by default and must be either that or something closely
related. This does makes it easier to customise it if necessary.


# 1.13 08-Jul-2009 nicm

Just appending -l to $SHELL to create a login shell is wrong: -l is not POSIX,
and some people may use shells which do not support it. Instead, make an empty
default-command option mean a login shell, and fork it with a - in argv[0]
which is the method used by login(1).

Also fix the automatic-rename code to handle this correctly and to strip a
leading - if present.


# 1.12 07-Jul-2009 nicm

Rename the global options variables to be shorter and to make session options
clear. No functional change, getting this out of the way to make later options
changes easier.


Revision tags: OPENBSD_4_6_BASE
# 1.11 25-Jun-2009 nicm

If getcwd() fails, use the user's home directory, or /, instead of failing with
an error.


# 1.10 25-Jun-2009 nicm

Remove error about using -L and -S together which was never displayed as
logging wasn't yet enabled, was unnecessary, and contradicted the man page
which says using -S will cause -L to be ignored.


# 1.9 23-Jun-2009 nicm

LC_ALL overrides LC_CTYPE and LANG. Comment was correct but the code
wrong. Pointed out by Hannah Schroeter, thanks.


# 1.8 05-Jun-2009 nicm

Check the first of LC_CTYPE, LC_ALL and LANG, rather than just the last, when
trying to decide about UTF-8, and use strcasestr. Reported by Geert Hendrickx.


# 1.7 04-Jun-2009 nicm

Zero the password given to -U in the client as well.


# 1.6 03-Jun-2009 nicm

Do not set the window title by default (make set-titles option default to off),
wiping over the title is rude and annoying. Agreed by several.


# 1.5 03-Jun-2009 nicm

New session option, status-utf8, to control the interpretation of top-bit-set
characters in status-left and status-right (if on, they are treated as UTF-8;
otherwise passed through).


# 1.4 02-Jun-2009 sobrado

remove unused flag; while here, make usage's output fit on 80-column displays.


# 1.3 02-Jun-2009 pyr

spawn login shells by default, adapt manpage bits as well.
ok nicm@


# 1.2 02-Jun-2009 ray

Don't leak memory if multiple -f flags are given.

OK nicm@


# 1.1 01-Jun-2009 nicm

Import tmux, a terminal multiplexor allowing (among other things) a single
terminal to be switched between several different windows and programs
displayed on one terminal be detached from one terminal and moved to another.

ok deraadt pirofti


# 1.189 20-Jun-2019 nicm

Add a per-pane option set. Pane options inherit from window options (so
there should be no change to existing behaviour) and are set and shown
with set-option -p and show-options -p.

Change remain-on-exit and window-style/window-active-style to be pane
options (some others will be changed later).

This makes select-pane -P and -g unnecessary so no longer document them
(they still work) and no longer document set-window-option and
show-window-options in favour of set-option -w and show-options -w.


# 1.188 26-Apr-2019 nicm

Merge hooks into options and make each one an array option. This allows
multiple commands to be easily bound to one hook. set-hook and
show-hooks remain but they are now variants of set-option and
show-options. show-options now has a -H flag to show hooks (by default
they are not shown).


Revision tags: OPENBSD_6_5_BASE
# 1.187 22-Nov-2018 nicm

Do not use PWD unless it actually matches the real working directory.


Revision tags: OPENBSD_6_3_BASE OPENBSD_6_4_BASE
# 1.186 12-Jan-2018 nicm

Improve error message if creating socket parent directory fails, from
Thomas Adam for GitHub issue 1215.


# 1.185 01-Jan-2018 nicm

Prefer PWD for current directory if present in client, from Wei Zhao in
GitHub issue 1183.


Revision tags: OPENBSD_6_2_BASE
# 1.184 12-Jul-2017 nicm

Make shell_command a global like other stuff rather than making it an
exception and using callback argument.


# 1.183 03-Jul-2017 nicm

Try C.UTF-8 which is also a commonly useful locale on some platforms,
from Romain Francoise.


# 1.182 22-Apr-2017 nicm

Do not need getopt.h.


# 1.181 20-Apr-2017 nicm

Use fdforkpty() instead of our own unwrapped versions.


# 1.180 19-Apr-2017 nicm

Style nits and a missing cast.


# 1.179 16-Apr-2017 nicm

Memory leak, from David CARLIER.


Revision tags: OPENBSD_6_1_BASE
# 1.178 21-Mar-2017 nicm

Use uid_t for UID not u_int.


# 1.177 16-Feb-2017 nicm

Style nits.


# 1.176 23-Jan-2017 nicm

Open /dev/ptm before pledge() and save it to be used for PTMGET later
(this means inlining forkpty()).

ok deraadt


# 1.175 15-Jan-2017 nicm

Major tidy up and rework of options tree and set-option/show-options
commands this pushes more of the code into options.c and ties it more
closely to the options table rather than having an unnecessary
split. Also add support for array options (will be used later). Only
(intentional) user visible change is that show-options output is now
passed through vis(3) with VIS_DQ so quotes are escaped.


# 1.174 12-Jan-2017 nicm

Simplify appending to string options.


# 1.173 09-Dec-2016 nicm

Spacing nits.


# 1.172 11-Oct-2016 nicm

Add static in window-*.c and move some internal functions out of tmux.h.


# 1.171 10-Oct-2016 nicm

Loads more static, except for cmd-*.c and window-*.c.


Revision tags: OPENBSD_6_0_BASE
# 1.170 27-May-2016 nicm

Use getprogname() instead of __progname to make portability easier.


# 1.169 04-May-2016 nicm

Fix up a couple of long lines.


# 1.168 05-Mar-2016 nicm

If setlocale("en_US.UTF-8") succeeds, then don't do the check for UTF-8
locale since if it isn't UTF-8 the system is broken anyway. If it fails,
try "" and check for UTF-8 with nl_langinfo(CODESET) rather than
wcwidth(). Based on a diff from schwarze@, nl_langinfo also suggested by
stsp@.


# 1.167 05-Mar-2016 nicm

Although we always have en_US.UTF-8 on OpenBSD, some platforms do not,
so fall back to setlocale(LC_CTYPE, ""). tmux requires a UTF-8 locale,
so check with wcwidth() on a UTF-8 character after setlocale().


# 1.166 01-Mar-2016 nicm

Remove unused variables, from Michal Mazurek.


# 1.165 01-Mar-2016 nicm

Use system wcwidth() instead of carrying around UTF-8 width tables.


Revision tags: OPENBSD_5_9_BASE
# 1.164 19-Jan-2016 nicm

I no longer use my SourceForge address so replace it.


# 1.163 08-Dec-2015 nicm

Add hooks infrastructure, basic commands (set-hook, show-hooks) and a
couple of not very useful client hooks. This will eventually let
commands be run at various points and on notifications. Joint work with
Thomas Adam.


# 1.162 24-Nov-2015 nicm

Make environ_set va_args and use it to tidy up some calls. Also add a
missing word in manpage (from jmc).


# 1.161 24-Nov-2015 nicm

Shell command from -c doesn't have to be global, pass it as an argument.


# 1.160 24-Nov-2015 nicm

Tidy the code that works out the socket path, and just use the full path
in the global socket_path rather than copying it.


# 1.159 24-Nov-2015 nicm

Remove malloc_options DEBUG bit.


# 1.158 24-Nov-2015 nicm

Remove the -I part of show-messages which isn't really that useful; the
server start time can now be accessed with a new start_time format (use:
tmux display -p '#{t:start_time}')


# 1.157 24-Nov-2015 nicm

Make the log stuff a bit tidier with some helper functions.


# 1.156 22-Nov-2015 nicm

Add getpw to pledge, makes tmux work in YP environments, discovered by
matthieu, ok deraadt


# 1.155 20-Nov-2015 nicm

Instead of separate tables for different types of options, give each
option a scope type (server, session, window) in one table.


# 1.154 15-Nov-2015 nicm

Accidentally turned off pledge, turn it back on.


# 1.153 14-Nov-2015 nicm

Push stdout and stderr to clients more aggressively, and add an event to
continue if the send fails.


# 1.152 12-Nov-2015 nicm

tmux is UTF-8, so if $TMUX is set (tmux running in tmux), the client is
UTF-8. Also try to make the existing checks more readable.


# 1.151 12-Nov-2015 nicm

Nuke the utf8 and status-utf8 options and make tmux only a UTF-8
terminal. We still support non-UTF-8 terminals outside tmux, but inside
it is always UTF-8 (as when the utf8 and status-utf8 options were on).


# 1.150 11-Nov-2015 nicm

Drop mouse-utf8 option and always turn on UTF-8 mouse if the client says
it supports UTF-8.


# 1.149 28-Oct-2015 nicm

Like options, move the environ struct into environ.c.


# 1.148 27-Oct-2015 nicm

Move struct options into options.c.


# 1.147 27-Oct-2015 nicm

Break the common process set up, event loop and imsg dispatch code
between server and client out into a separate internal API. This will
make it easier to add another process.


# 1.146 25-Oct-2015 deraadt

Let's see if anyone screams about not being able to specify $TMPDIR
for their tmux sockets.

(Over the years, I have seen $TMPDIR set up worse than /tmp many times,
and don't know how this practice infected other parts of the system.
Nothing uses tmpdir(3), nor a huge-temporary-file program like sort.)
ok nicm


# 1.145 23-Oct-2015 nicm

tmux can call pledge() in main with large set and then reduce it
slightly in the server to "stdio rpath wpath cpath fattr unix recvfd
proc exec tty ps".


# 1.144 14-Sep-2015 nicm

Move tzset() from log_open to main.


# 1.143 03-Sep-2015 nicm

A couple of style nits.


# 1.142 01-Sep-2015 nicm

Work out config file when needed not at startup.


# 1.141 30-Aug-2015 nicm

Path from $TMUX does not need to be global anymore.


# 1.140 30-Aug-2015 nicm

Login shell can be a client flag, and move the exec code into client.c.


# 1.139 30-Aug-2015 nicm

Event base does not need to be global.


# 1.138 30-Aug-2015 nicm

Some style nits and dead assignments.


Revision tags: OPENBSD_5_8_BASE
# 1.137 20-Jul-2015 nicm

Add an option (history-file) for a file to save/restore command prompt
history, from Olof-Joachim Frahm.


# 1.136 04-Jun-2015 jmc

tweak SYNOPSIS and usage();


Revision tags: OPENBSD_5_7_BASE
# 1.135 19-Jan-2015 nicm

Make a tmux-%u directory under TMUX_TMPDIR, like TMPDIR.


# 1.134 19-Jan-2015 nicm

Only care about other permissions, allow group to be set.


# 1.133 19-Jan-2015 nicm

Remove unnecessary duplicate S_ISDIR check, from Dmitri Paduchikh.


# 1.132 20-Oct-2014 nicm

Tidy up some includes.


Revision tags: OPENBSD_5_6_BASE
# 1.131 17-Apr-2014 nicm

Remove the "info" message mechanism, this was only used for about five
mostly useless and annoying messages. Change those commands to silence
on success like all the others. Still accept the -q command line flag
and "quiet" server option for now.


# 1.130 31-Mar-2014 nicm

Remove log_debug2 as well and simplify log.c.


Revision tags: OPENBSD_5_5_BASE
# 1.129 16-Feb-2014 nicm

Leftovers from removing 88 colour support, from Theo Buehler.


# 1.128 15-Jan-2014 nicm

Do not attempt to read .tmux.conf if we can't figure out a home
directory, from Tiago Cunha.


# 1.127 09-Jan-2014 nicm

Three small changes from Tiago Cunha:

- Check for truncation when copying path.
- Don't need to use a temporary buffer in screen_set_title.
- Include strerror in output when connecting to server fails.


# 1.126 10-Oct-2013 nicm

We accidentally haven't been using $TMUX to work out the session for a
while and in fact it is less useful that using the client ttyname. So
don't bother and don't pass it from the client. If we need it in future
it is in c->environ.


# 1.125 10-Oct-2013 nicm

Alter how tmux handles the working directory to internally use file
descriptors rather than strings.

- Each session still has a current working directory.

- New sessions still get their working directory from the client that
created them or its attached session if any.

- New windows are created by default in the session working directory.

- The -c flag to new, neww, splitw allows the working directory to be
overridden.

- The -c flag to attach let's the session working directory be changed.

- The default-path option has been removed.

To get the equivalent to default-path '.', do:

bind c neww -c $PWD

To get the equivalent of default-path '~', do:

bind c neww -c ~

This also changes the client identify protocol to be a set of messages rather
than one as well as some other changes that should make it easier to make
backwards-compatible protocol changes in future.


# 1.124 10-Oct-2013 nicm

Merge IDENTIFY_* flags with CLIENT_* flags.


# 1.123 10-Oct-2013 nicm

Don't treat TMUX_TMPDIR as a potential file

The point of setting TMUX_TMPDIR is to then make any labels from -L go
to that directory. In the case of makesocketpath() with no TMUX_TMPDIR
set, would set both the path and the default socket to a file. The
checking of the permissions on the file worked fine in that case, but
when TMUX_TMPDIR is set, won't work on a directory.

This fixes the problem by ensuring the check on the permissions is
performed on directories only.

By Thomas Adam.


# 1.122 05-Oct-2013 nicm

Fix previous not to leak fd on failure, whoops.


# 1.121 05-Oct-2013 nicm

Use open(".")/fchdir() to save and restore current directory rather than
getcwd()/chdir().


Revision tags: OPENBSD_5_4_BASE
# 1.120 24-Apr-2013 nicm

Rename global configuration define.


# 1.119 11-Apr-2013 nicm

Call setlocale(LC_TIME) at startup.


# 1.118 27-Mar-2013 nicm

Add TMUX_TMPDIR variable to put the socket directory outside
TMPDIR. From Ben Boeckel.


# 1.117 27-Mar-2013 nicm

Remove tmux's (already minimal) 88 colour support. Such terminals are
few and unnecessary.


# 1.116 25-Mar-2013 nicm

Rename session idx to session id throughout and add $ prefix to targets
to use it, extended from a diff from George Nachman.


# 1.115 24-Mar-2013 nicm

Add a command queue to standardize and simplify commands that call other
commands and allow a command to block execution of subsequent
commands. This allows run-shell and if-shell to be synchronous which has
been much requested.

Each client has a default command queue and commands are consumed one at
a time from it. A command may suspend execution from the queue by
returning CMD_RETURN_WAIT and then resume it by calling cmd_continue() -
for example run-shell does this from the callback that is fired after
the job is freed.

When the command queue becomes empty, command clients are automatically
exited (unless attaching). A callback is also fired - this is used for
nested commands in, for example, if-shell which can block execution of
the client's cmdq until a new cmdq becomes empty.

Also merge all the old error/info/print functions together and lose the
old curclient/cmdclient distinction - a cmdq is bound to one client (or
none if in the configuration file), this is a command client if
c->session is NULL otherwise an attached client.


Revision tags: OPENBSD_5_3_BASE
# 1.114 27-Nov-2012 nicm

Correctly aggregate together errors from nested config files (with
source-file). Fix by Thomas Adam, reported by Sam Livingstone-Gray


# 1.113 26-Nov-2012 nicm

Call realpath earlier on the socket directory path rather than on the
socket file path because the latter may not exist yet and in that case
realpath is allowed to fail. From Romain Francoise.


Revision tags: OPENBSD_5_2_BASE
# 1.112 10-Jul-2012 nicm

xfree is not particularly helpful, remove it. From Thomas Adam.


# 1.111 18-Jun-2012 nicm

Add a skeleton mode to tmux (called "control mode") that let's tmux
commands be sent and output received on stdout. This can be used to
integrate with other terminal emulators and should allow some other
things to be made simpler later. More to come so doesn't do much yet and
deliberately not documented.


# 1.110 30-May-2012 nicm

Do not use stderr for log file and don't call log_close when not needed.


# 1.109 25-May-2012 nicm

Simplify logging and just fprintf(stderr, ...) for early errors.


Revision tags: OPENBSD_5_1_BASE
# 1.108 21-Jan-2012 nicm

Drop the ability to have a list of keys in the prefix in favour of two
separate options, prefix and prefix2. This simplifies the code and gets
rid the data options type which was only used for this one option.

Also add a -2 flag to send-prefix to send the secondary prefix key,
fixing a cause of minor irritation.

People who want three prefix keys are out of luck :-).


# 1.107 23-Oct-2011 nicm

Try to resolve relative paths for loadb and saveb (first using client
working directory if any then default-path or session wd).


# 1.106 23-Oct-2011 nicm

Ignore LC_ALL and LC_CTYPE if they are empty as well as unset.


# 1.105 25-Sep-2011 nicm

Reject $SHELL if it is not a full path.


Revision tags: OPENBSD_5_0_BASE
# 1.104 04-Mar-2011 nicm

Two fixes by Micah Cowan: make mouse work properly beyond >127 on signed
char architectures and properly parse $TMUX by stopping the socket path
at the first comma.


Revision tags: OPENBSD_4_9_BASE
# 1.103 23-Jan-2011 nicm

Set $TMUX without the session when background jobs are run.


# 1.102 12-Jan-2011 nicm

Use TMPDIR if set, from Han Boetes.


# 1.101 08-Jan-2011 nicm

Move all calls to fcntl(...O_NONBLOCK) into a function and clear the
flag on the stdio file descriptors before closing them (fixes things
like "tmux ls && cat").


# 1.100 03-Jan-2011 nicm

Support for UTF-8 mouse input (\033[1005h). This was added in xterm 262
and supports larger terminals than the older way.

If the new mouse-utf8 option is on, UTF-8 mouse input is enabled for all
UTF-8 terminals. The option defaults to on if LANG etc are set in the
same manner as the utf8 option.

With help and based on code from hsim at gmx.li.


# 1.99 01-Jan-2011 nicm

Move the user-visible parts of all options (names, types, limit, default
values) together into one set of tables in options-table.c. Also clean
up and simplify cmd-set-options.c and move a common print function into
option-table.c.


# 1.98 30-Dec-2010 nicm

Change from a per-session stack of buffers to one global stack which is
much more convenient and also simplifies lot of code. This renders
copy-buffer useless and makes buffer-limit now a server option.

By Tiago Cunha.


# 1.97 19-Dec-2010 nicm

Add other-pane-height and other-pane-width options, allowing the width
or height of the smaller panes in the main-horizontal and main-vertical
layouts to be set. Mostly from David Goodlad.


# 1.96 08-Dec-2010 nicm

In the built-in layouts, distribute the panes more evenly. Set the
default value of main-pane-width to 80, rather than 81. By Micah Cowan.


# 1.95 06-Dec-2010 nicm

Add an option to alert (monitor) for silence (lack of activity) in a
window. From Thomas Adam.


# 1.94 29-Nov-2010 nicm

If VISUAL or EDITOR contains "vi", configure mode-keys and status-keys
to vi.

Based on a diff from martynas@, previously requested by a couple of
other people.


# 1.93 11-Nov-2010 nicm

Add XAUTHORITY to update-environment, requested by Andreas Kloeckner.


# 1.92 18-Oct-2010 nicm

Merge the before and after attach client code into one in client.c
(instead of two in tmux.c and client.c).


# 1.91 16-Oct-2010 nicm

Make stdio blocking again before calling shell command with -c.


# 1.90 16-Oct-2010 nicm

Trying to set FD_CLOEXEC on every fd is a lost cause, just use
closefrom() before exec.


# 1.89 14-Oct-2010 nicm

Use an explicit event rather than event_once for the main event so it
can be removed when the client becomes ready.


# 1.88 26-Sep-2010 nicm

Two new options:

- server option "exit-unattached" makes the server exit when no clients
are attached, even if sessions are present;

- session option "destroy-unattached" destroys a session once no clients
are attached to it.

These are useful for preventing tmux remaining in the background where
it is undesirable and when using tmux as a login shell to keep a limit
on new sessions.


# 1.87 19-Aug-2010 nicm

Do not call event_del() for signals after fork(), just use sigaction()
directly instead - calling libevent functions after fork() w/o
event_reinit() is a bad idea, even if in this case it was harmless.


Revision tags: OPENBSD_4_8_BASE
# 1.86 04-Aug-2010 deraadt

switch back to kqueue for now, since (a) kqueue has been fixed to deal
with strange devices and (b) since there appears to be a bull in the
poll code in libevent as well...
requested by nicm who is away


# 1.85 24-Jul-2010 nicm

kqueue(2) is currently broken when used with /dev/null and a few other
devices.

An upcoming fix for some problems with the client stdout/stderr handling
relies on it working, so make tmux force libevent to use poll(2) via
EVENT_NOKQUEUE, until we have fixed kqueue.


# 1.84 11-Jul-2010 nicm

Return the command client return code with MSG_EXIT now that MSG_ERROR and
MSG_PRINT are unused.

New clients should be compatible with old tmux servers but vice versa may print
an error.


# 1.83 28-Jun-2010 nicm

Send all three of stdin, stdout, stderr from the client to the server, so that
commands can directly make use of them. This means that load-buffer and
save-buffer can have "-" as the file to read from stdin or write to stdout.

This is a protocol version bump so the tmux server will need to be restarted
after upgrade (or an older client used).


# 1.82 27-Jun-2010 nicm

Store the current working directory in the session, change the default-path
option to default to empty and make that mean that the stored session CWD is
used.


# 1.81 27-Jun-2010 nicm

New option, detach-on-destroy, to set what happens to a client when the session
it is attached to is destroyed. If on (the default), it is detached; if off, it
is switched to the most recently active session.


# 1.80 26-Jun-2010 nicm

Setting the cmdlist pointer in the bind-key to NULL to prevent it being freed
after the command is executing is bogus because it may still be needed if the
same command is going to be executed again (for example if you "bind-key a
bind-key b ..."). Making a copy is hard, so instead add a reference count to
the cmd_list.

While here, also print bind-key -n and the rest of the flags properly.

Fixes problem reported by mcbride@.


# 1.79 14-May-2010 nicm

Colour+attribute options for status line alerts, from Alex Alexander.


# 1.78 04-May-2010 nicm

Put this back in with the initialisation in the right order.


# 1.77 04-May-2010 nicm

Revert last change, it appears to be broken somehow.


# 1.76 03-May-2010 nicm

Make signal handler setup/teardown two common functions instead of six,
and reset SIGCHLD after fork to fix problems with some shells. From
Romain Francois.


# 1.75 28-Apr-2010 nicm

Make the active pane border have a green foreground instead of
background by default.


# 1.74 18-Apr-2010 nicm

Catch SIGCHLD to avoid a zombie, from patrick keshishian.


Revision tags: OPENBSD_4_7_BASE
# 1.73 22-Feb-2010 nicm

Option to set the characters considered word separators in copy mode, from
Micah Cowan.


# 1.72 08-Feb-2010 nicm

Add an option to disable the smcup/rmcup alternate screen behaviour inside
tmux. From clemens fischer.


# 1.71 06-Feb-2010 nicm

Change nested check to compare server socket path rather than just assuming
that if $TMUX is set it is nested. From Micah Cowan.


# 1.70 06-Feb-2010 nicm

Clean up $TMUX parsing, from Micah Cowan, tweaked by me.


# 1.69 06-Feb-2010 nicm

Instead of bailing out on the first configuration file error, carry on,
collecting all the errors, then start with the active window in more mode
displaying them.


# 1.68 04-Feb-2010 nicm

Read the path from $TMUX if it is present and -L and -S are not given. Based on
a diff from Micah Cowan.


# 1.67 04-Feb-2010 nicm

Option to display the active pane in a different colour with the display-panes
command. From Paul Hoffman, thanks.


# 1.66 03-Jan-2010 nicm

Options to set the colour of the pane borders, with different colours for the
active pane.


# 1.65 14-Dec-2009 nicm

New server option, escape-time, to set the timeout used to detect if escapes
are alone or part of a function key or meta sequence.


# 1.64 11-Dec-2009 nicm

Use quiet variable, and add missing sentinel to options array.


# 1.63 10-Dec-2009 nicm

Add "server options" which are server-wide and not bound to a session or
window. Set and displayed with "set -s" and "show -s".

Currently the only option is "quiet" (like command-line -q, allowing it to be
set from .tmux.conf), but others will come along.


# 1.62 03-Dec-2009 nicm

Massive spaces->tabs and trailing whitespace cleanup, hopefully for the last
time now I've configured emacs to make them displayed in really annoying
colours...


# 1.61 26-Nov-2009 nicm

Remove a couple of unused arguments where possible, and add /* ARGSUSED */ to
the rest to reduce lint output.


# 1.60 19-Nov-2009 nicm

Two new options, window-status-format and window-status-current-format, which
allow the format of each window in the status line window list to be controlled
using similar # sequences as status-left/right.

This diff also moves part of the way towards UTF-8 support in window names but
it isn't quite there yet.


# 1.59 19-Nov-2009 nicm

Revert to xterm-keys off by default. It was on as an experiment to see if the
option could be removed, but it affects vi, so we have to keep the option, and
a conservative default is better.


# 1.58 18-Nov-2009 nicm

Add a per-client log of status line messages displayed while that client
exists. A new message-limit session option sets the maximum number of entries
and a command, show-messages, shows the log (bound to ~ by default).

This (and prompt history) might be better as a single global log but until
there are global options it is easier for them to be per client.


# 1.57 10-Nov-2009 nicm

There is no real standard for modifier plus function keys. Previously, tmux
output some from rxvt but in other ways did the same as xterm or other
terminals, but this is a bit inconsistent.

xterm's method is fairly sensible and we already support it (xterm-keys), so
enable it by default instead.


# 1.56 04-Nov-2009 nicm

A couple of minor cosmetic changes.


# 1.55 04-Nov-2009 nicm

Initial changes to move tmux to libevent.

This moves the client-side loops are pretty much fully over to event-based only
(tmux.c and client.c) but server-side (server.c and friends) treats libevent as
a sort of clever poll, waking up after every event to run various things.

Moving the server stuff over to bufferevents and timers and so on will come
later.


# 1.54 04-Nov-2009 nicm

Change declaration and use of malloc_options to be more standard, from Tim van
der Molen.


# 1.53 26-Oct-2009 deraadt

tabs are better; ok nicm


# 1.52 25-Oct-2009 nicm

Remove the -d flag to tmux and just use op/AX to detect default colours.

Irritatingly, although op can be used to tell if a terminal supports default
colours, it can't be used to set them because in some terminfo descriptions it
resets attributes as a side-effect (acts as sgr0) and in others it doesn't, so
it is not possible to determine reliably what the terminal state will be
afterwards. So if AX is missing and op is present, tmux just sends sgr0.

Anyone using -d for a terminal who finds they actually needed it can replace it
using terminal-overrides, but please let me know as it is probably an omission
from terminfo.


# 1.51 22-Oct-2009 nicm

Merge prepare_cmd into main as it is short and only called once.


# 1.50 21-Oct-2009 nicm

Client tidying: get rid of client_ctx struct in favour of two variables in
client.c, and move the functions in client-fn.c into other files.


# 1.49 10-Oct-2009 nicm

New option, mouse-select-pane. If on, the mouse may be used to select the
current pane.

Suggested by sthen@ and also by someone else ages ago who I have forgotten.


# 1.48 10-Oct-2009 nicm

Support for individual session idle time locking. May be enabled by turning off
the lock-server option (it is on by default). When this is off, each session
locks when it has been idle for the lock-after-time setting. When on, the
entire server locks when ALL sessions have been idle for their individual
lock-after-time settings.

This replaces one global-only option (lock-after-time) with another
(lock-server), but the default behaviour is usually preferable so there don't
seem to be many alternatives.

Diff/idea largely from Thomas Adam, tweaked by me.


# 1.47 09-Oct-2009 nicm

Add a simple synchronize-panes window option: when set, all input to any pane
that is part of the window is also sent to all other panes in the same
window. Suggested by several, most recently Tomasz Pajor.


# 1.46 23-Sep-2009 nicm

Support -c like sh(1) to execute a command, useful when tmux is a login
shell. Suggested by halex@.

This includes another protocol version increase (the last for now) so again
restart the tmux server before upgrading.


# 1.45 23-Sep-2009 nicm

Remove the internal tmux locking and instead detach each client and run the
command specified by a new option "lock-command" (by default "lock -np") in
each client.

This means each terminal has to be unlocked individually but simplifies the
code and allows the system password to be used to unlock.

Note that the set-password command is gone, so it will need to be removed from
configuration files, and the -U command line flag has been removed.

This is the third protocol version change so again it is best to stop the tmux
server before upgrading.


# 1.44 22-Sep-2009 nicm

Permit multiple prefix keys to be defined, separated by commas, for example:

set -g prefix ^a,^b

Any key in the list acts as the prefix. The send-prefix command always sends
the first key in the list.


# 1.43 18-Sep-2009 nicm

New option, set-titles-string, to allow the window title to be specified (as
for status-left/right) if set-titles is on. Also only update the title when the
status line is being redrawn.


# 1.42 04-Sep-2009 nicm

Tidy main and make it a bit easier to read.


# 1.41 02-Sep-2009 nicm

Accept -l to make it easier for people who use tmux as a login shell to use
$SHELL. Originally from martynas@, tweaked by me.


# 1.40 02-Sep-2009 nicm

When incorrect passwords are entered, behave similarly to login(1) and backoff
for a bit. Based on a diff from martynas@.


# 1.39 01-Sep-2009 nicm

When using tmux as a login shell, there is currently no way to specify a shell
to be used as a login shell inside tmux, so add a default-shell session option.
This sets the shell invoked as a login shell when the default-command option is
empty.

The default option value is whichever of $SHELL, getpwuid(getuid())'s pw_shell
or /bin/sh is valid first.

Based on a diff from martynas@, changed by me to be a session option rather
than a window option.


# 1.38 01-Sep-2009 nicm

Use "Password:" with no space for password prompts and don't display a *s for
the password, like pretty much everything else. From martynas@ with minor
tweaks by me.


# 1.37 01-Sep-2009 nicm

Sort cases same as getopt argument, from martynas.


# 1.36 31-Aug-2009 nicm

Add a new display-panes command, with two options (display-panes-colour and
display-panes-time), which displays a visual indication of the number of each
pane.


# 1.35 23-Aug-2009 nicm

Add some other obvious variables to update-environment (WINDOWID SSH_ASKPASS
SSH_AUTH_SOCK SSH_AGENT_PID SSH_CONNECTION) so they are updated in the session
environment on new/attach.


# 1.34 13-Aug-2009 nicm

Disable mode-mouse (mouse in copy/choice mode) by default as it isn't very
useful at the moment and causes confusion.


# 1.33 13-Aug-2009 nicm

Add a base-index session option to specify the first index checked when looking
for an index for a new window.


# 1.32 12-Aug-2009 nicm

When started as the shell, __progname contains a leading -, so hardcode "tmux"
for socket path and log files, and strip it when working out the shell.


# 1.31 11-Aug-2009 nicm

Switch tmux to use imsg. This is the last major change to make the
client-server protocol more resilient and make the protocol versioning work
properly. In future, the only things requiring a protocol version bump will be
changes in the message structs, and (when both client and server have this
change) mixing different versions should nicely report an error message.

As a side effect this also makes the code tidier, fixes a problem with the way
errors reported during server startup were handled, and supports fd passing
(which will be used in future).

Looked over by eric@, thanks.

Please note that mixing a client with this change with an older server or vice
versa may cause tmux to crash or hang - tmux should be completely exited before
upgrading.


# 1.30 10-Aug-2009 nicm

No arguments are the same as new-session and this requires the environment to
be sent, so set that flag too when argc == 0.


# 1.29 08-Aug-2009 nicm

Infrastructure and commands to manage the environment for processes started
within tmux.

There is a global environment, copied from the external environment when the
server is started and each sesssion has an (initially empty) session
environment which overrides it.

New commands set-environment and show-environment manipulate or display the
environments.

A new session option, update-environment, is a space-separated list of
variables which are updated from the external environment into the session
environment every time a new session is created - the default is DISPLAY.


# 1.28 08-Aug-2009 nicm

Options to set the colours and attributes for status-left/-right. From Thomas
Adam, thanks.


# 1.27 05-Aug-2009 nicm

If colours are not supported by the terminal, try to emulate a coloured
background by setting or clearing the reverse attribute.

This makes a few applications which don't use the reverse attribute themselves
a little happier, and allows the status, message and mode options to have
default attributes and fg/bg options that work as expected when set as reverse.


# 1.26 04-Aug-2009 nicm

Check for "UTF8" as well as "UTF-8" in LANG etc as it seems this may also
appear.


# 1.25 03-Aug-2009 nicm

Add a terminal-overrides session option allowing individual terminfo(5) entries
to be overridden. The 88col/256col checks are now moved into the default
setting and out of the code.

Also remove a couple of old workarounds for xterm and rxvt which are no longer
necessary (tmux can emulate them if missing).


# 1.24 30-Jul-2009 nicm

Add a mode-mouse option to prevent tmux taking over the mouse in choice or copy
modes.


# 1.23 29-Jul-2009 nicm

Rename struct hdrtype to msgtype which is a better name and can be used even
when struct hdr disappears.


# 1.22 29-Jul-2009 nicm

Taking account of the "s, 22 not 24 is the maximum length of #T in status-right
to prevent the date being cut off.


# 1.21 26-Jul-2009 nicm

Make all messages sent between the client and server fixed size.

This is the first of two changes to make the protocol more resilient and less
sensitive to other changes in the code, particularly with commands. The client
now packs argv into a buffer and sends it to the server for parsing, rather
than doing it itself and sending the parsed command data.

As a side-effect this also removes a lot of now-unused command marshalling
code.

Mixing a server without this change and a client with or vice versa will cause
tmux to hang or crash, please ensure that tmux is entirely killed before
upgrading.


# 1.20 22-Jul-2009 nicm

Pass a set of flags into client_init rather than just a start_server
variable. Only one flag now but more to come later.


# 1.19 20-Jul-2009 nicm

Display the number of failed password attempts (if any) when the server is
locked. From Tom Doherty.


# 1.18 20-Jul-2009 nicm

Add a status-justify option to allow the window list in the status line to be
positioned at the left, centre, or right.


# 1.17 20-Jul-2009 nicm

New options, window-status-current-{fg,bg,attr}, to set the fg, bg and
attributes with which the current window is shown in the status line. From
Johan Friis, thanks.


# 1.16 18-Jul-2009 nicm

Add three new session options: visual-activity, visual-bell, visual-content. If
these are enabled (and the monitor-activity, bell-actio and monitor-content
options are configurated appropriately), when activity, a bell, or content is
detected, a message is shown.

Also tidy up the bell/activity/content code in server.c slightly and fix a
couple of errors.


# 1.15 17-Jul-2009 nicm

If -u is specified or UTF-8 is otherwise detected when the server is started,
enable the utf8 and status-utf8 optons. While here, note in the man page that
the server is started with the first session and exits when none remain.


# 1.14 10-Jul-2009 nicm

Add a default-terminal option to set the starting value of $TERM in new
windows.

This is "screen" by default and must be either that or something closely
related. This does makes it easier to customise it if necessary.


# 1.13 08-Jul-2009 nicm

Just appending -l to $SHELL to create a login shell is wrong: -l is not POSIX,
and some people may use shells which do not support it. Instead, make an empty
default-command option mean a login shell, and fork it with a - in argv[0]
which is the method used by login(1).

Also fix the automatic-rename code to handle this correctly and to strip a
leading - if present.


# 1.12 07-Jul-2009 nicm

Rename the global options variables to be shorter and to make session options
clear. No functional change, getting this out of the way to make later options
changes easier.


Revision tags: OPENBSD_4_6_BASE
# 1.11 25-Jun-2009 nicm

If getcwd() fails, use the user's home directory, or /, instead of failing with
an error.


# 1.10 25-Jun-2009 nicm

Remove error about using -L and -S together which was never displayed as
logging wasn't yet enabled, was unnecessary, and contradicted the man page
which says using -S will cause -L to be ignored.


# 1.9 23-Jun-2009 nicm

LC_ALL overrides LC_CTYPE and LANG. Comment was correct but the code
wrong. Pointed out by Hannah Schroeter, thanks.


# 1.8 05-Jun-2009 nicm

Check the first of LC_CTYPE, LC_ALL and LANG, rather than just the last, when
trying to decide about UTF-8, and use strcasestr. Reported by Geert Hendrickx.


# 1.7 04-Jun-2009 nicm

Zero the password given to -U in the client as well.


# 1.6 03-Jun-2009 nicm

Do not set the window title by default (make set-titles option default to off),
wiping over the title is rude and annoying. Agreed by several.


# 1.5 03-Jun-2009 nicm

New session option, status-utf8, to control the interpretation of top-bit-set
characters in status-left and status-right (if on, they are treated as UTF-8;
otherwise passed through).


# 1.4 02-Jun-2009 sobrado

remove unused flag; while here, make usage's output fit on 80-column displays.


# 1.3 02-Jun-2009 pyr

spawn login shells by default, adapt manpage bits as well.
ok nicm@


# 1.2 02-Jun-2009 ray

Don't leak memory if multiple -f flags are given.

OK nicm@


# 1.1 01-Jun-2009 nicm

Import tmux, a terminal multiplexor allowing (among other things) a single
terminal to be switched between several different windows and programs
displayed on one terminal be detached from one terminal and moved to another.

ok deraadt pirofti


# 1.188 26-Apr-2019 nicm

Merge hooks into options and make each one an array option. This allows
multiple commands to be easily bound to one hook. set-hook and
show-hooks remain but they are now variants of set-option and
show-options. show-options now has a -H flag to show hooks (by default
they are not shown).


Revision tags: OPENBSD_6_5_BASE
# 1.187 22-Nov-2018 nicm

Do not use PWD unless it actually matches the real working directory.


Revision tags: OPENBSD_6_3_BASE OPENBSD_6_4_BASE
# 1.186 12-Jan-2018 nicm

Improve error message if creating socket parent directory fails, from
Thomas Adam for GitHub issue 1215.


# 1.185 01-Jan-2018 nicm

Prefer PWD for current directory if present in client, from Wei Zhao in
GitHub issue 1183.


Revision tags: OPENBSD_6_2_BASE
# 1.184 12-Jul-2017 nicm

Make shell_command a global like other stuff rather than making it an
exception and using callback argument.


# 1.183 03-Jul-2017 nicm

Try C.UTF-8 which is also a commonly useful locale on some platforms,
from Romain Francoise.


# 1.182 22-Apr-2017 nicm

Do not need getopt.h.


# 1.181 20-Apr-2017 nicm

Use fdforkpty() instead of our own unwrapped versions.


# 1.180 19-Apr-2017 nicm

Style nits and a missing cast.


# 1.179 16-Apr-2017 nicm

Memory leak, from David CARLIER.


Revision tags: OPENBSD_6_1_BASE
# 1.178 21-Mar-2017 nicm

Use uid_t for UID not u_int.


# 1.177 16-Feb-2017 nicm

Style nits.


# 1.176 23-Jan-2017 nicm

Open /dev/ptm before pledge() and save it to be used for PTMGET later
(this means inlining forkpty()).

ok deraadt


# 1.175 15-Jan-2017 nicm

Major tidy up and rework of options tree and set-option/show-options
commands this pushes more of the code into options.c and ties it more
closely to the options table rather than having an unnecessary
split. Also add support for array options (will be used later). Only
(intentional) user visible change is that show-options output is now
passed through vis(3) with VIS_DQ so quotes are escaped.


# 1.174 12-Jan-2017 nicm

Simplify appending to string options.


# 1.173 09-Dec-2016 nicm

Spacing nits.


# 1.172 11-Oct-2016 nicm

Add static in window-*.c and move some internal functions out of tmux.h.


# 1.171 10-Oct-2016 nicm

Loads more static, except for cmd-*.c and window-*.c.


Revision tags: OPENBSD_6_0_BASE
# 1.170 27-May-2016 nicm

Use getprogname() instead of __progname to make portability easier.


# 1.169 04-May-2016 nicm

Fix up a couple of long lines.


# 1.168 05-Mar-2016 nicm

If setlocale("en_US.UTF-8") succeeds, then don't do the check for UTF-8
locale since if it isn't UTF-8 the system is broken anyway. If it fails,
try "" and check for UTF-8 with nl_langinfo(CODESET) rather than
wcwidth(). Based on a diff from schwarze@, nl_langinfo also suggested by
stsp@.


# 1.167 05-Mar-2016 nicm

Although we always have en_US.UTF-8 on OpenBSD, some platforms do not,
so fall back to setlocale(LC_CTYPE, ""). tmux requires a UTF-8 locale,
so check with wcwidth() on a UTF-8 character after setlocale().


# 1.166 01-Mar-2016 nicm

Remove unused variables, from Michal Mazurek.


# 1.165 01-Mar-2016 nicm

Use system wcwidth() instead of carrying around UTF-8 width tables.


Revision tags: OPENBSD_5_9_BASE
# 1.164 19-Jan-2016 nicm

I no longer use my SourceForge address so replace it.


# 1.163 08-Dec-2015 nicm

Add hooks infrastructure, basic commands (set-hook, show-hooks) and a
couple of not very useful client hooks. This will eventually let
commands be run at various points and on notifications. Joint work with
Thomas Adam.


# 1.162 24-Nov-2015 nicm

Make environ_set va_args and use it to tidy up some calls. Also add a
missing word in manpage (from jmc).


# 1.161 24-Nov-2015 nicm

Shell command from -c doesn't have to be global, pass it as an argument.


# 1.160 24-Nov-2015 nicm

Tidy the code that works out the socket path, and just use the full path
in the global socket_path rather than copying it.


# 1.159 24-Nov-2015 nicm

Remove malloc_options DEBUG bit.


# 1.158 24-Nov-2015 nicm

Remove the -I part of show-messages which isn't really that useful; the
server start time can now be accessed with a new start_time format (use:
tmux display -p '#{t:start_time}')


# 1.157 24-Nov-2015 nicm

Make the log stuff a bit tidier with some helper functions.


# 1.156 22-Nov-2015 nicm

Add getpw to pledge, makes tmux work in YP environments, discovered by
matthieu, ok deraadt


# 1.155 20-Nov-2015 nicm

Instead of separate tables for different types of options, give each
option a scope type (server, session, window) in one table.


# 1.154 15-Nov-2015 nicm

Accidentally turned off pledge, turn it back on.


# 1.153 14-Nov-2015 nicm

Push stdout and stderr to clients more aggressively, and add an event to
continue if the send fails.


# 1.152 12-Nov-2015 nicm

tmux is UTF-8, so if $TMUX is set (tmux running in tmux), the client is
UTF-8. Also try to make the existing checks more readable.


# 1.151 12-Nov-2015 nicm

Nuke the utf8 and status-utf8 options and make tmux only a UTF-8
terminal. We still support non-UTF-8 terminals outside tmux, but inside
it is always UTF-8 (as when the utf8 and status-utf8 options were on).


# 1.150 11-Nov-2015 nicm

Drop mouse-utf8 option and always turn on UTF-8 mouse if the client says
it supports UTF-8.


# 1.149 28-Oct-2015 nicm

Like options, move the environ struct into environ.c.


# 1.148 27-Oct-2015 nicm

Move struct options into options.c.


# 1.147 27-Oct-2015 nicm

Break the common process set up, event loop and imsg dispatch code
between server and client out into a separate internal API. This will
make it easier to add another process.


# 1.146 25-Oct-2015 deraadt

Let's see if anyone screams about not being able to specify $TMPDIR
for their tmux sockets.

(Over the years, I have seen $TMPDIR set up worse than /tmp many times,
and don't know how this practice infected other parts of the system.
Nothing uses tmpdir(3), nor a huge-temporary-file program like sort.)
ok nicm


# 1.145 23-Oct-2015 nicm

tmux can call pledge() in main with large set and then reduce it
slightly in the server to "stdio rpath wpath cpath fattr unix recvfd
proc exec tty ps".


# 1.144 14-Sep-2015 nicm

Move tzset() from log_open to main.


# 1.143 03-Sep-2015 nicm

A couple of style nits.


# 1.142 01-Sep-2015 nicm

Work out config file when needed not at startup.


# 1.141 30-Aug-2015 nicm

Path from $TMUX does not need to be global anymore.


# 1.140 30-Aug-2015 nicm

Login shell can be a client flag, and move the exec code into client.c.


# 1.139 30-Aug-2015 nicm

Event base does not need to be global.


# 1.138 30-Aug-2015 nicm

Some style nits and dead assignments.


Revision tags: OPENBSD_5_8_BASE
# 1.137 20-Jul-2015 nicm

Add an option (history-file) for a file to save/restore command prompt
history, from Olof-Joachim Frahm.


# 1.136 04-Jun-2015 jmc

tweak SYNOPSIS and usage();


Revision tags: OPENBSD_5_7_BASE
# 1.135 19-Jan-2015 nicm

Make a tmux-%u directory under TMUX_TMPDIR, like TMPDIR.


# 1.134 19-Jan-2015 nicm

Only care about other permissions, allow group to be set.


# 1.133 19-Jan-2015 nicm

Remove unnecessary duplicate S_ISDIR check, from Dmitri Paduchikh.


# 1.132 20-Oct-2014 nicm

Tidy up some includes.


Revision tags: OPENBSD_5_6_BASE
# 1.131 17-Apr-2014 nicm

Remove the "info" message mechanism, this was only used for about five
mostly useless and annoying messages. Change those commands to silence
on success like all the others. Still accept the -q command line flag
and "quiet" server option for now.


# 1.130 31-Mar-2014 nicm

Remove log_debug2 as well and simplify log.c.


Revision tags: OPENBSD_5_5_BASE
# 1.129 16-Feb-2014 nicm

Leftovers from removing 88 colour support, from Theo Buehler.


# 1.128 15-Jan-2014 nicm

Do not attempt to read .tmux.conf if we can't figure out a home
directory, from Tiago Cunha.


# 1.127 09-Jan-2014 nicm

Three small changes from Tiago Cunha:

- Check for truncation when copying path.
- Don't need to use a temporary buffer in screen_set_title.
- Include strerror in output when connecting to server fails.


# 1.126 10-Oct-2013 nicm

We accidentally haven't been using $TMUX to work out the session for a
while and in fact it is less useful that using the client ttyname. So
don't bother and don't pass it from the client. If we need it in future
it is in c->environ.


# 1.125 10-Oct-2013 nicm

Alter how tmux handles the working directory to internally use file
descriptors rather than strings.

- Each session still has a current working directory.

- New sessions still get their working directory from the client that
created them or its attached session if any.

- New windows are created by default in the session working directory.

- The -c flag to new, neww, splitw allows the working directory to be
overridden.

- The -c flag to attach let's the session working directory be changed.

- The default-path option has been removed.

To get the equivalent to default-path '.', do:

bind c neww -c $PWD

To get the equivalent of default-path '~', do:

bind c neww -c ~

This also changes the client identify protocol to be a set of messages rather
than one as well as some other changes that should make it easier to make
backwards-compatible protocol changes in future.


# 1.124 10-Oct-2013 nicm

Merge IDENTIFY_* flags with CLIENT_* flags.


# 1.123 10-Oct-2013 nicm

Don't treat TMUX_TMPDIR as a potential file

The point of setting TMUX_TMPDIR is to then make any labels from -L go
to that directory. In the case of makesocketpath() with no TMUX_TMPDIR
set, would set both the path and the default socket to a file. The
checking of the permissions on the file worked fine in that case, but
when TMUX_TMPDIR is set, won't work on a directory.

This fixes the problem by ensuring the check on the permissions is
performed on directories only.

By Thomas Adam.


# 1.122 05-Oct-2013 nicm

Fix previous not to leak fd on failure, whoops.


# 1.121 05-Oct-2013 nicm

Use open(".")/fchdir() to save and restore current directory rather than
getcwd()/chdir().


Revision tags: OPENBSD_5_4_BASE
# 1.120 24-Apr-2013 nicm

Rename global configuration define.


# 1.119 11-Apr-2013 nicm

Call setlocale(LC_TIME) at startup.


# 1.118 27-Mar-2013 nicm

Add TMUX_TMPDIR variable to put the socket directory outside
TMPDIR. From Ben Boeckel.


# 1.117 27-Mar-2013 nicm

Remove tmux's (already minimal) 88 colour support. Such terminals are
few and unnecessary.


# 1.116 25-Mar-2013 nicm

Rename session idx to session id throughout and add $ prefix to targets
to use it, extended from a diff from George Nachman.


# 1.115 24-Mar-2013 nicm

Add a command queue to standardize and simplify commands that call other
commands and allow a command to block execution of subsequent
commands. This allows run-shell and if-shell to be synchronous which has
been much requested.

Each client has a default command queue and commands are consumed one at
a time from it. A command may suspend execution from the queue by
returning CMD_RETURN_WAIT and then resume it by calling cmd_continue() -
for example run-shell does this from the callback that is fired after
the job is freed.

When the command queue becomes empty, command clients are automatically
exited (unless attaching). A callback is also fired - this is used for
nested commands in, for example, if-shell which can block execution of
the client's cmdq until a new cmdq becomes empty.

Also merge all the old error/info/print functions together and lose the
old curclient/cmdclient distinction - a cmdq is bound to one client (or
none if in the configuration file), this is a command client if
c->session is NULL otherwise an attached client.


Revision tags: OPENBSD_5_3_BASE
# 1.114 27-Nov-2012 nicm

Correctly aggregate together errors from nested config files (with
source-file). Fix by Thomas Adam, reported by Sam Livingstone-Gray


# 1.113 26-Nov-2012 nicm

Call realpath earlier on the socket directory path rather than on the
socket file path because the latter may not exist yet and in that case
realpath is allowed to fail. From Romain Francoise.


Revision tags: OPENBSD_5_2_BASE
# 1.112 10-Jul-2012 nicm

xfree is not particularly helpful, remove it. From Thomas Adam.


# 1.111 18-Jun-2012 nicm

Add a skeleton mode to tmux (called "control mode") that let's tmux
commands be sent and output received on stdout. This can be used to
integrate with other terminal emulators and should allow some other
things to be made simpler later. More to come so doesn't do much yet and
deliberately not documented.


# 1.110 30-May-2012 nicm

Do not use stderr for log file and don't call log_close when not needed.


# 1.109 25-May-2012 nicm

Simplify logging and just fprintf(stderr, ...) for early errors.


Revision tags: OPENBSD_5_1_BASE
# 1.108 21-Jan-2012 nicm

Drop the ability to have a list of keys in the prefix in favour of two
separate options, prefix and prefix2. This simplifies the code and gets
rid the data options type which was only used for this one option.

Also add a -2 flag to send-prefix to send the secondary prefix key,
fixing a cause of minor irritation.

People who want three prefix keys are out of luck :-).


# 1.107 23-Oct-2011 nicm

Try to resolve relative paths for loadb and saveb (first using client
working directory if any then default-path or session wd).


# 1.106 23-Oct-2011 nicm

Ignore LC_ALL and LC_CTYPE if they are empty as well as unset.


# 1.105 25-Sep-2011 nicm

Reject $SHELL if it is not a full path.


Revision tags: OPENBSD_5_0_BASE
# 1.104 04-Mar-2011 nicm

Two fixes by Micah Cowan: make mouse work properly beyond >127 on signed
char architectures and properly parse $TMUX by stopping the socket path
at the first comma.


Revision tags: OPENBSD_4_9_BASE
# 1.103 23-Jan-2011 nicm

Set $TMUX without the session when background jobs are run.


# 1.102 12-Jan-2011 nicm

Use TMPDIR if set, from Han Boetes.


# 1.101 08-Jan-2011 nicm

Move all calls to fcntl(...O_NONBLOCK) into a function and clear the
flag on the stdio file descriptors before closing them (fixes things
like "tmux ls && cat").


# 1.100 03-Jan-2011 nicm

Support for UTF-8 mouse input (\033[1005h). This was added in xterm 262
and supports larger terminals than the older way.

If the new mouse-utf8 option is on, UTF-8 mouse input is enabled for all
UTF-8 terminals. The option defaults to on if LANG etc are set in the
same manner as the utf8 option.

With help and based on code from hsim at gmx.li.


# 1.99 01-Jan-2011 nicm

Move the user-visible parts of all options (names, types, limit, default
values) together into one set of tables in options-table.c. Also clean
up and simplify cmd-set-options.c and move a common print function into
option-table.c.


# 1.98 30-Dec-2010 nicm

Change from a per-session stack of buffers to one global stack which is
much more convenient and also simplifies lot of code. This renders
copy-buffer useless and makes buffer-limit now a server option.

By Tiago Cunha.


# 1.97 19-Dec-2010 nicm

Add other-pane-height and other-pane-width options, allowing the width
or height of the smaller panes in the main-horizontal and main-vertical
layouts to be set. Mostly from David Goodlad.


# 1.96 08-Dec-2010 nicm

In the built-in layouts, distribute the panes more evenly. Set the
default value of main-pane-width to 80, rather than 81. By Micah Cowan.


# 1.95 06-Dec-2010 nicm

Add an option to alert (monitor) for silence (lack of activity) in a
window. From Thomas Adam.


# 1.94 29-Nov-2010 nicm

If VISUAL or EDITOR contains "vi", configure mode-keys and status-keys
to vi.

Based on a diff from martynas@, previously requested by a couple of
other people.


# 1.93 11-Nov-2010 nicm

Add XAUTHORITY to update-environment, requested by Andreas Kloeckner.


# 1.92 18-Oct-2010 nicm

Merge the before and after attach client code into one in client.c
(instead of two in tmux.c and client.c).


# 1.91 16-Oct-2010 nicm

Make stdio blocking again before calling shell command with -c.


# 1.90 16-Oct-2010 nicm

Trying to set FD_CLOEXEC on every fd is a lost cause, just use
closefrom() before exec.


# 1.89 14-Oct-2010 nicm

Use an explicit event rather than event_once for the main event so it
can be removed when the client becomes ready.


# 1.88 26-Sep-2010 nicm

Two new options:

- server option "exit-unattached" makes the server exit when no clients
are attached, even if sessions are present;

- session option "destroy-unattached" destroys a session once no clients
are attached to it.

These are useful for preventing tmux remaining in the background where
it is undesirable and when using tmux as a login shell to keep a limit
on new sessions.


# 1.87 19-Aug-2010 nicm

Do not call event_del() for signals after fork(), just use sigaction()
directly instead - calling libevent functions after fork() w/o
event_reinit() is a bad idea, even if in this case it was harmless.


Revision tags: OPENBSD_4_8_BASE
# 1.86 04-Aug-2010 deraadt

switch back to kqueue for now, since (a) kqueue has been fixed to deal
with strange devices and (b) since there appears to be a bull in the
poll code in libevent as well...
requested by nicm who is away


# 1.85 24-Jul-2010 nicm

kqueue(2) is currently broken when used with /dev/null and a few other
devices.

An upcoming fix for some problems with the client stdout/stderr handling
relies on it working, so make tmux force libevent to use poll(2) via
EVENT_NOKQUEUE, until we have fixed kqueue.


# 1.84 11-Jul-2010 nicm

Return the command client return code with MSG_EXIT now that MSG_ERROR and
MSG_PRINT are unused.

New clients should be compatible with old tmux servers but vice versa may print
an error.


# 1.83 28-Jun-2010 nicm

Send all three of stdin, stdout, stderr from the client to the server, so that
commands can directly make use of them. This means that load-buffer and
save-buffer can have "-" as the file to read from stdin or write to stdout.

This is a protocol version bump so the tmux server will need to be restarted
after upgrade (or an older client used).


# 1.82 27-Jun-2010 nicm

Store the current working directory in the session, change the default-path
option to default to empty and make that mean that the stored session CWD is
used.


# 1.81 27-Jun-2010 nicm

New option, detach-on-destroy, to set what happens to a client when the session
it is attached to is destroyed. If on (the default), it is detached; if off, it
is switched to the most recently active session.


# 1.80 26-Jun-2010 nicm

Setting the cmdlist pointer in the bind-key to NULL to prevent it being freed
after the command is executing is bogus because it may still be needed if the
same command is going to be executed again (for example if you "bind-key a
bind-key b ..."). Making a copy is hard, so instead add a reference count to
the cmd_list.

While here, also print bind-key -n and the rest of the flags properly.

Fixes problem reported by mcbride@.


# 1.79 14-May-2010 nicm

Colour+attribute options for status line alerts, from Alex Alexander.


# 1.78 04-May-2010 nicm

Put this back in with the initialisation in the right order.


# 1.77 04-May-2010 nicm

Revert last change, it appears to be broken somehow.


# 1.76 03-May-2010 nicm

Make signal handler setup/teardown two common functions instead of six,
and reset SIGCHLD after fork to fix problems with some shells. From
Romain Francois.


# 1.75 28-Apr-2010 nicm

Make the active pane border have a green foreground instead of
background by default.


# 1.74 18-Apr-2010 nicm

Catch SIGCHLD to avoid a zombie, from patrick keshishian.


Revision tags: OPENBSD_4_7_BASE
# 1.73 22-Feb-2010 nicm

Option to set the characters considered word separators in copy mode, from
Micah Cowan.


# 1.72 08-Feb-2010 nicm

Add an option to disable the smcup/rmcup alternate screen behaviour inside
tmux. From clemens fischer.


# 1.71 06-Feb-2010 nicm

Change nested check to compare server socket path rather than just assuming
that if $TMUX is set it is nested. From Micah Cowan.


# 1.70 06-Feb-2010 nicm

Clean up $TMUX parsing, from Micah Cowan, tweaked by me.


# 1.69 06-Feb-2010 nicm

Instead of bailing out on the first configuration file error, carry on,
collecting all the errors, then start with the active window in more mode
displaying them.


# 1.68 04-Feb-2010 nicm

Read the path from $TMUX if it is present and -L and -S are not given. Based on
a diff from Micah Cowan.


# 1.67 04-Feb-2010 nicm

Option to display the active pane in a different colour with the display-panes
command. From Paul Hoffman, thanks.


# 1.66 03-Jan-2010 nicm

Options to set the colour of the pane borders, with different colours for the
active pane.


# 1.65 14-Dec-2009 nicm

New server option, escape-time, to set the timeout used to detect if escapes
are alone or part of a function key or meta sequence.


# 1.64 11-Dec-2009 nicm

Use quiet variable, and add missing sentinel to options array.


# 1.63 10-Dec-2009 nicm

Add "server options" which are server-wide and not bound to a session or
window. Set and displayed with "set -s" and "show -s".

Currently the only option is "quiet" (like command-line -q, allowing it to be
set from .tmux.conf), but others will come along.


# 1.62 03-Dec-2009 nicm

Massive spaces->tabs and trailing whitespace cleanup, hopefully for the last
time now I've configured emacs to make them displayed in really annoying
colours...


# 1.61 26-Nov-2009 nicm

Remove a couple of unused arguments where possible, and add /* ARGSUSED */ to
the rest to reduce lint output.


# 1.60 19-Nov-2009 nicm

Two new options, window-status-format and window-status-current-format, which
allow the format of each window in the status line window list to be controlled
using similar # sequences as status-left/right.

This diff also moves part of the way towards UTF-8 support in window names but
it isn't quite there yet.


# 1.59 19-Nov-2009 nicm

Revert to xterm-keys off by default. It was on as an experiment to see if the
option could be removed, but it affects vi, so we have to keep the option, and
a conservative default is better.


# 1.58 18-Nov-2009 nicm

Add a per-client log of status line messages displayed while that client
exists. A new message-limit session option sets the maximum number of entries
and a command, show-messages, shows the log (bound to ~ by default).

This (and prompt history) might be better as a single global log but until
there are global options it is easier for them to be per client.


# 1.57 10-Nov-2009 nicm

There is no real standard for modifier plus function keys. Previously, tmux
output some from rxvt but in other ways did the same as xterm or other
terminals, but this is a bit inconsistent.

xterm's method is fairly sensible and we already support it (xterm-keys), so
enable it by default instead.


# 1.56 04-Nov-2009 nicm

A couple of minor cosmetic changes.


# 1.55 04-Nov-2009 nicm

Initial changes to move tmux to libevent.

This moves the client-side loops are pretty much fully over to event-based only
(tmux.c and client.c) but server-side (server.c and friends) treats libevent as
a sort of clever poll, waking up after every event to run various things.

Moving the server stuff over to bufferevents and timers and so on will come
later.


# 1.54 04-Nov-2009 nicm

Change declaration and use of malloc_options to be more standard, from Tim van
der Molen.


# 1.53 26-Oct-2009 deraadt

tabs are better; ok nicm


# 1.52 25-Oct-2009 nicm

Remove the -d flag to tmux and just use op/AX to detect default colours.

Irritatingly, although op can be used to tell if a terminal supports default
colours, it can't be used to set them because in some terminfo descriptions it
resets attributes as a side-effect (acts as sgr0) and in others it doesn't, so
it is not possible to determine reliably what the terminal state will be
afterwards. So if AX is missing and op is present, tmux just sends sgr0.

Anyone using -d for a terminal who finds they actually needed it can replace it
using terminal-overrides, but please let me know as it is probably an omission
from terminfo.


# 1.51 22-Oct-2009 nicm

Merge prepare_cmd into main as it is short and only called once.


# 1.50 21-Oct-2009 nicm

Client tidying: get rid of client_ctx struct in favour of two variables in
client.c, and move the functions in client-fn.c into other files.


# 1.49 10-Oct-2009 nicm

New option, mouse-select-pane. If on, the mouse may be used to select the
current pane.

Suggested by sthen@ and also by someone else ages ago who I have forgotten.


# 1.48 10-Oct-2009 nicm

Support for individual session idle time locking. May be enabled by turning off
the lock-server option (it is on by default). When this is off, each session
locks when it has been idle for the lock-after-time setting. When on, the
entire server locks when ALL sessions have been idle for their individual
lock-after-time settings.

This replaces one global-only option (lock-after-time) with another
(lock-server), but the default behaviour is usually preferable so there don't
seem to be many alternatives.

Diff/idea largely from Thomas Adam, tweaked by me.


# 1.47 09-Oct-2009 nicm

Add a simple synchronize-panes window option: when set, all input to any pane
that is part of the window is also sent to all other panes in the same
window. Suggested by several, most recently Tomasz Pajor.


# 1.46 23-Sep-2009 nicm

Support -c like sh(1) to execute a command, useful when tmux is a login
shell. Suggested by halex@.

This includes another protocol version increase (the last for now) so again
restart the tmux server before upgrading.


# 1.45 23-Sep-2009 nicm

Remove the internal tmux locking and instead detach each client and run the
command specified by a new option "lock-command" (by default "lock -np") in
each client.

This means each terminal has to be unlocked individually but simplifies the
code and allows the system password to be used to unlock.

Note that the set-password command is gone, so it will need to be removed from
configuration files, and the -U command line flag has been removed.

This is the third protocol version change so again it is best to stop the tmux
server before upgrading.


# 1.44 22-Sep-2009 nicm

Permit multiple prefix keys to be defined, separated by commas, for example:

set -g prefix ^a,^b

Any key in the list acts as the prefix. The send-prefix command always sends
the first key in the list.


# 1.43 18-Sep-2009 nicm

New option, set-titles-string, to allow the window title to be specified (as
for status-left/right) if set-titles is on. Also only update the title when the
status line is being redrawn.


# 1.42 04-Sep-2009 nicm

Tidy main and make it a bit easier to read.


# 1.41 02-Sep-2009 nicm

Accept -l to make it easier for people who use tmux as a login shell to use
$SHELL. Originally from martynas@, tweaked by me.


# 1.40 02-Sep-2009 nicm

When incorrect passwords are entered, behave similarly to login(1) and backoff
for a bit. Based on a diff from martynas@.


# 1.39 01-Sep-2009 nicm

When using tmux as a login shell, there is currently no way to specify a shell
to be used as a login shell inside tmux, so add a default-shell session option.
This sets the shell invoked as a login shell when the default-command option is
empty.

The default option value is whichever of $SHELL, getpwuid(getuid())'s pw_shell
or /bin/sh is valid first.

Based on a diff from martynas@, changed by me to be a session option rather
than a window option.


# 1.38 01-Sep-2009 nicm

Use "Password:" with no space for password prompts and don't display a *s for
the password, like pretty much everything else. From martynas@ with minor
tweaks by me.


# 1.37 01-Sep-2009 nicm

Sort cases same as getopt argument, from martynas.


# 1.36 31-Aug-2009 nicm

Add a new display-panes command, with two options (display-panes-colour and
display-panes-time), which displays a visual indication of the number of each
pane.


# 1.35 23-Aug-2009 nicm

Add some other obvious variables to update-environment (WINDOWID SSH_ASKPASS
SSH_AUTH_SOCK SSH_AGENT_PID SSH_CONNECTION) so they are updated in the session
environment on new/attach.


# 1.34 13-Aug-2009 nicm

Disable mode-mouse (mouse in copy/choice mode) by default as it isn't very
useful at the moment and causes confusion.


# 1.33 13-Aug-2009 nicm

Add a base-index session option to specify the first index checked when looking
for an index for a new window.


# 1.32 12-Aug-2009 nicm

When started as the shell, __progname contains a leading -, so hardcode "tmux"
for socket path and log files, and strip it when working out the shell.


# 1.31 11-Aug-2009 nicm

Switch tmux to use imsg. This is the last major change to make the
client-server protocol more resilient and make the protocol versioning work
properly. In future, the only things requiring a protocol version bump will be
changes in the message structs, and (when both client and server have this
change) mixing different versions should nicely report an error message.

As a side effect this also makes the code tidier, fixes a problem with the way
errors reported during server startup were handled, and supports fd passing
(which will be used in future).

Looked over by eric@, thanks.

Please note that mixing a client with this change with an older server or vice
versa may cause tmux to crash or hang - tmux should be completely exited before
upgrading.


# 1.30 10-Aug-2009 nicm

No arguments are the same as new-session and this requires the environment to
be sent, so set that flag too when argc == 0.


# 1.29 08-Aug-2009 nicm

Infrastructure and commands to manage the environment for processes started
within tmux.

There is a global environment, copied from the external environment when the
server is started and each sesssion has an (initially empty) session
environment which overrides it.

New commands set-environment and show-environment manipulate or display the
environments.

A new session option, update-environment, is a space-separated list of
variables which are updated from the external environment into the session
environment every time a new session is created - the default is DISPLAY.


# 1.28 08-Aug-2009 nicm

Options to set the colours and attributes for status-left/-right. From Thomas
Adam, thanks.


# 1.27 05-Aug-2009 nicm

If colours are not supported by the terminal, try to emulate a coloured
background by setting or clearing the reverse attribute.

This makes a few applications which don't use the reverse attribute themselves
a little happier, and allows the status, message and mode options to have
default attributes and fg/bg options that work as expected when set as reverse.


# 1.26 04-Aug-2009 nicm

Check for "UTF8" as well as "UTF-8" in LANG etc as it seems this may also
appear.


# 1.25 03-Aug-2009 nicm

Add a terminal-overrides session option allowing individual terminfo(5) entries
to be overridden. The 88col/256col checks are now moved into the default
setting and out of the code.

Also remove a couple of old workarounds for xterm and rxvt which are no longer
necessary (tmux can emulate them if missing).


# 1.24 30-Jul-2009 nicm

Add a mode-mouse option to prevent tmux taking over the mouse in choice or copy
modes.


# 1.23 29-Jul-2009 nicm

Rename struct hdrtype to msgtype which is a better name and can be used even
when struct hdr disappears.


# 1.22 29-Jul-2009 nicm

Taking account of the "s, 22 not 24 is the maximum length of #T in status-right
to prevent the date being cut off.


# 1.21 26-Jul-2009 nicm

Make all messages sent between the client and server fixed size.

This is the first of two changes to make the protocol more resilient and less
sensitive to other changes in the code, particularly with commands. The client
now packs argv into a buffer and sends it to the server for parsing, rather
than doing it itself and sending the parsed command data.

As a side-effect this also removes a lot of now-unused command marshalling
code.

Mixing a server without this change and a client with or vice versa will cause
tmux to hang or crash, please ensure that tmux is entirely killed before
upgrading.


# 1.20 22-Jul-2009 nicm

Pass a set of flags into client_init rather than just a start_server
variable. Only one flag now but more to come later.


# 1.19 20-Jul-2009 nicm

Display the number of failed password attempts (if any) when the server is
locked. From Tom Doherty.


# 1.18 20-Jul-2009 nicm

Add a status-justify option to allow the window list in the status line to be
positioned at the left, centre, or right.


# 1.17 20-Jul-2009 nicm

New options, window-status-current-{fg,bg,attr}, to set the fg, bg and
attributes with which the current window is shown in the status line. From
Johan Friis, thanks.


# 1.16 18-Jul-2009 nicm

Add three new session options: visual-activity, visual-bell, visual-content. If
these are enabled (and the monitor-activity, bell-actio and monitor-content
options are configurated appropriately), when activity, a bell, or content is
detected, a message is shown.

Also tidy up the bell/activity/content code in server.c slightly and fix a
couple of errors.


# 1.15 17-Jul-2009 nicm

If -u is specified or UTF-8 is otherwise detected when the server is started,
enable the utf8 and status-utf8 optons. While here, note in the man page that
the server is started with the first session and exits when none remain.


# 1.14 10-Jul-2009 nicm

Add a default-terminal option to set the starting value of $TERM in new
windows.

This is "screen" by default and must be either that or something closely
related. This does makes it easier to customise it if necessary.


# 1.13 08-Jul-2009 nicm

Just appending -l to $SHELL to create a login shell is wrong: -l is not POSIX,
and some people may use shells which do not support it. Instead, make an empty
default-command option mean a login shell, and fork it with a - in argv[0]
which is the method used by login(1).

Also fix the automatic-rename code to handle this correctly and to strip a
leading - if present.


# 1.12 07-Jul-2009 nicm

Rename the global options variables to be shorter and to make session options
clear. No functional change, getting this out of the way to make later options
changes easier.


Revision tags: OPENBSD_4_6_BASE
# 1.11 25-Jun-2009 nicm

If getcwd() fails, use the user's home directory, or /, instead of failing with
an error.


# 1.10 25-Jun-2009 nicm

Remove error about using -L and -S together which was never displayed as
logging wasn't yet enabled, was unnecessary, and contradicted the man page
which says using -S will cause -L to be ignored.


# 1.9 23-Jun-2009 nicm

LC_ALL overrides LC_CTYPE and LANG. Comment was correct but the code
wrong. Pointed out by Hannah Schroeter, thanks.


# 1.8 05-Jun-2009 nicm

Check the first of LC_CTYPE, LC_ALL and LANG, rather than just the last, when
trying to decide about UTF-8, and use strcasestr. Reported by Geert Hendrickx.


# 1.7 04-Jun-2009 nicm

Zero the password given to -U in the client as well.


# 1.6 03-Jun-2009 nicm

Do not set the window title by default (make set-titles option default to off),
wiping over the title is rude and annoying. Agreed by several.


# 1.5 03-Jun-2009 nicm

New session option, status-utf8, to control the interpretation of top-bit-set
characters in status-left and status-right (if on, they are treated as UTF-8;
otherwise passed through).


# 1.4 02-Jun-2009 sobrado

remove unused flag; while here, make usage's output fit on 80-column displays.


# 1.3 02-Jun-2009 pyr

spawn login shells by default, adapt manpage bits as well.
ok nicm@


# 1.2 02-Jun-2009 ray

Don't leak memory if multiple -f flags are given.

OK nicm@


# 1.1 01-Jun-2009 nicm

Import tmux, a terminal multiplexor allowing (among other things) a single
terminal to be switched between several different windows and programs
displayed on one terminal be detached from one terminal and moved to another.

ok deraadt pirofti


# 1.187 22-Nov-2018 nicm

Do not use PWD unless it actually matches the real working directory.


Revision tags: OPENBSD_6_3_BASE OPENBSD_6_4_BASE
# 1.186 12-Jan-2018 nicm

Improve error message if creating socket parent directory fails, from
Thomas Adam for GitHub issue 1215.


# 1.185 01-Jan-2018 nicm

Prefer PWD for current directory if present in client, from Wei Zhao in
GitHub issue 1183.


Revision tags: OPENBSD_6_2_BASE
# 1.184 12-Jul-2017 nicm

Make shell_command a global like other stuff rather than making it an
exception and using callback argument.


# 1.183 03-Jul-2017 nicm

Try C.UTF-8 which is also a commonly useful locale on some platforms,
from Romain Francoise.


# 1.182 22-Apr-2017 nicm

Do not need getopt.h.


# 1.181 20-Apr-2017 nicm

Use fdforkpty() instead of our own unwrapped versions.


# 1.180 19-Apr-2017 nicm

Style nits and a missing cast.


# 1.179 16-Apr-2017 nicm

Memory leak, from David CARLIER.


Revision tags: OPENBSD_6_1_BASE
# 1.178 21-Mar-2017 nicm

Use uid_t for UID not u_int.


# 1.177 16-Feb-2017 nicm

Style nits.


# 1.176 23-Jan-2017 nicm

Open /dev/ptm before pledge() and save it to be used for PTMGET later
(this means inlining forkpty()).

ok deraadt


# 1.175 15-Jan-2017 nicm

Major tidy up and rework of options tree and set-option/show-options
commands this pushes more of the code into options.c and ties it more
closely to the options table rather than having an unnecessary
split. Also add support for array options (will be used later). Only
(intentional) user visible change is that show-options output is now
passed through vis(3) with VIS_DQ so quotes are escaped.


# 1.174 12-Jan-2017 nicm

Simplify appending to string options.


# 1.173 09-Dec-2016 nicm

Spacing nits.


# 1.172 11-Oct-2016 nicm

Add static in window-*.c and move some internal functions out of tmux.h.


# 1.171 10-Oct-2016 nicm

Loads more static, except for cmd-*.c and window-*.c.


Revision tags: OPENBSD_6_0_BASE
# 1.170 27-May-2016 nicm

Use getprogname() instead of __progname to make portability easier.


# 1.169 04-May-2016 nicm

Fix up a couple of long lines.


# 1.168 05-Mar-2016 nicm

If setlocale("en_US.UTF-8") succeeds, then don't do the check for UTF-8
locale since if it isn't UTF-8 the system is broken anyway. If it fails,
try "" and check for UTF-8 with nl_langinfo(CODESET) rather than
wcwidth(). Based on a diff from schwarze@, nl_langinfo also suggested by
stsp@.


# 1.167 05-Mar-2016 nicm

Although we always have en_US.UTF-8 on OpenBSD, some platforms do not,
so fall back to setlocale(LC_CTYPE, ""). tmux requires a UTF-8 locale,
so check with wcwidth() on a UTF-8 character after setlocale().


# 1.166 01-Mar-2016 nicm

Remove unused variables, from Michal Mazurek.


# 1.165 01-Mar-2016 nicm

Use system wcwidth() instead of carrying around UTF-8 width tables.


Revision tags: OPENBSD_5_9_BASE
# 1.164 19-Jan-2016 nicm

I no longer use my SourceForge address so replace it.


# 1.163 08-Dec-2015 nicm

Add hooks infrastructure, basic commands (set-hook, show-hooks) and a
couple of not very useful client hooks. This will eventually let
commands be run at various points and on notifications. Joint work with
Thomas Adam.


# 1.162 24-Nov-2015 nicm

Make environ_set va_args and use it to tidy up some calls. Also add a
missing word in manpage (from jmc).


# 1.161 24-Nov-2015 nicm

Shell command from -c doesn't have to be global, pass it as an argument.


# 1.160 24-Nov-2015 nicm

Tidy the code that works out the socket path, and just use the full path
in the global socket_path rather than copying it.


# 1.159 24-Nov-2015 nicm

Remove malloc_options DEBUG bit.


# 1.158 24-Nov-2015 nicm

Remove the -I part of show-messages which isn't really that useful; the
server start time can now be accessed with a new start_time format (use:
tmux display -p '#{t:start_time}')


# 1.157 24-Nov-2015 nicm

Make the log stuff a bit tidier with some helper functions.


# 1.156 22-Nov-2015 nicm

Add getpw to pledge, makes tmux work in YP environments, discovered by
matthieu, ok deraadt


# 1.155 20-Nov-2015 nicm

Instead of separate tables for different types of options, give each
option a scope type (server, session, window) in one table.


# 1.154 15-Nov-2015 nicm

Accidentally turned off pledge, turn it back on.


# 1.153 14-Nov-2015 nicm

Push stdout and stderr to clients more aggressively, and add an event to
continue if the send fails.


# 1.152 12-Nov-2015 nicm

tmux is UTF-8, so if $TMUX is set (tmux running in tmux), the client is
UTF-8. Also try to make the existing checks more readable.


# 1.151 12-Nov-2015 nicm

Nuke the utf8 and status-utf8 options and make tmux only a UTF-8
terminal. We still support non-UTF-8 terminals outside tmux, but inside
it is always UTF-8 (as when the utf8 and status-utf8 options were on).


# 1.150 11-Nov-2015 nicm

Drop mouse-utf8 option and always turn on UTF-8 mouse if the client says
it supports UTF-8.


# 1.149 28-Oct-2015 nicm

Like options, move the environ struct into environ.c.


# 1.148 27-Oct-2015 nicm

Move struct options into options.c.


# 1.147 27-Oct-2015 nicm

Break the common process set up, event loop and imsg dispatch code
between server and client out into a separate internal API. This will
make it easier to add another process.


# 1.146 25-Oct-2015 deraadt

Let's see if anyone screams about not being able to specify $TMPDIR
for their tmux sockets.

(Over the years, I have seen $TMPDIR set up worse than /tmp many times,
and don't know how this practice infected other parts of the system.
Nothing uses tmpdir(3), nor a huge-temporary-file program like sort.)
ok nicm


# 1.145 23-Oct-2015 nicm

tmux can call pledge() in main with large set and then reduce it
slightly in the server to "stdio rpath wpath cpath fattr unix recvfd
proc exec tty ps".


# 1.144 14-Sep-2015 nicm

Move tzset() from log_open to main.


# 1.143 03-Sep-2015 nicm

A couple of style nits.


# 1.142 01-Sep-2015 nicm

Work out config file when needed not at startup.


# 1.141 30-Aug-2015 nicm

Path from $TMUX does not need to be global anymore.


# 1.140 30-Aug-2015 nicm

Login shell can be a client flag, and move the exec code into client.c.


# 1.139 30-Aug-2015 nicm

Event base does not need to be global.


# 1.138 30-Aug-2015 nicm

Some style nits and dead assignments.


Revision tags: OPENBSD_5_8_BASE
# 1.137 20-Jul-2015 nicm

Add an option (history-file) for a file to save/restore command prompt
history, from Olof-Joachim Frahm.


# 1.136 04-Jun-2015 jmc

tweak SYNOPSIS and usage();


Revision tags: OPENBSD_5_7_BASE
# 1.135 19-Jan-2015 nicm

Make a tmux-%u directory under TMUX_TMPDIR, like TMPDIR.


# 1.134 19-Jan-2015 nicm

Only care about other permissions, allow group to be set.


# 1.133 19-Jan-2015 nicm

Remove unnecessary duplicate S_ISDIR check, from Dmitri Paduchikh.


# 1.132 20-Oct-2014 nicm

Tidy up some includes.


Revision tags: OPENBSD_5_6_BASE
# 1.131 17-Apr-2014 nicm

Remove the "info" message mechanism, this was only used for about five
mostly useless and annoying messages. Change those commands to silence
on success like all the others. Still accept the -q command line flag
and "quiet" server option for now.


# 1.130 31-Mar-2014 nicm

Remove log_debug2 as well and simplify log.c.


Revision tags: OPENBSD_5_5_BASE
# 1.129 16-Feb-2014 nicm

Leftovers from removing 88 colour support, from Theo Buehler.


# 1.128 15-Jan-2014 nicm

Do not attempt to read .tmux.conf if we can't figure out a home
directory, from Tiago Cunha.


# 1.127 09-Jan-2014 nicm

Three small changes from Tiago Cunha:

- Check for truncation when copying path.
- Don't need to use a temporary buffer in screen_set_title.
- Include strerror in output when connecting to server fails.


# 1.126 10-Oct-2013 nicm

We accidentally haven't been using $TMUX to work out the session for a
while and in fact it is less useful that using the client ttyname. So
don't bother and don't pass it from the client. If we need it in future
it is in c->environ.


# 1.125 10-Oct-2013 nicm

Alter how tmux handles the working directory to internally use file
descriptors rather than strings.

- Each session still has a current working directory.

- New sessions still get their working directory from the client that
created them or its attached session if any.

- New windows are created by default in the session working directory.

- The -c flag to new, neww, splitw allows the working directory to be
overridden.

- The -c flag to attach let's the session working directory be changed.

- The default-path option has been removed.

To get the equivalent to default-path '.', do:

bind c neww -c $PWD

To get the equivalent of default-path '~', do:

bind c neww -c ~

This also changes the client identify protocol to be a set of messages rather
than one as well as some other changes that should make it easier to make
backwards-compatible protocol changes in future.


# 1.124 10-Oct-2013 nicm

Merge IDENTIFY_* flags with CLIENT_* flags.


# 1.123 10-Oct-2013 nicm

Don't treat TMUX_TMPDIR as a potential file

The point of setting TMUX_TMPDIR is to then make any labels from -L go
to that directory. In the case of makesocketpath() with no TMUX_TMPDIR
set, would set both the path and the default socket to a file. The
checking of the permissions on the file worked fine in that case, but
when TMUX_TMPDIR is set, won't work on a directory.

This fixes the problem by ensuring the check on the permissions is
performed on directories only.

By Thomas Adam.


# 1.122 05-Oct-2013 nicm

Fix previous not to leak fd on failure, whoops.


# 1.121 05-Oct-2013 nicm

Use open(".")/fchdir() to save and restore current directory rather than
getcwd()/chdir().


Revision tags: OPENBSD_5_4_BASE
# 1.120 24-Apr-2013 nicm

Rename global configuration define.


# 1.119 11-Apr-2013 nicm

Call setlocale(LC_TIME) at startup.


# 1.118 27-Mar-2013 nicm

Add TMUX_TMPDIR variable to put the socket directory outside
TMPDIR. From Ben Boeckel.


# 1.117 27-Mar-2013 nicm

Remove tmux's (already minimal) 88 colour support. Such terminals are
few and unnecessary.


# 1.116 25-Mar-2013 nicm

Rename session idx to session id throughout and add $ prefix to targets
to use it, extended from a diff from George Nachman.


# 1.115 24-Mar-2013 nicm

Add a command queue to standardize and simplify commands that call other
commands and allow a command to block execution of subsequent
commands. This allows run-shell and if-shell to be synchronous which has
been much requested.

Each client has a default command queue and commands are consumed one at
a time from it. A command may suspend execution from the queue by
returning CMD_RETURN_WAIT and then resume it by calling cmd_continue() -
for example run-shell does this from the callback that is fired after
the job is freed.

When the command queue becomes empty, command clients are automatically
exited (unless attaching). A callback is also fired - this is used for
nested commands in, for example, if-shell which can block execution of
the client's cmdq until a new cmdq becomes empty.

Also merge all the old error/info/print functions together and lose the
old curclient/cmdclient distinction - a cmdq is bound to one client (or
none if in the configuration file), this is a command client if
c->session is NULL otherwise an attached client.


Revision tags: OPENBSD_5_3_BASE
# 1.114 27-Nov-2012 nicm

Correctly aggregate together errors from nested config files (with
source-file). Fix by Thomas Adam, reported by Sam Livingstone-Gray


# 1.113 26-Nov-2012 nicm

Call realpath earlier on the socket directory path rather than on the
socket file path because the latter may not exist yet and in that case
realpath is allowed to fail. From Romain Francoise.


Revision tags: OPENBSD_5_2_BASE
# 1.112 10-Jul-2012 nicm

xfree is not particularly helpful, remove it. From Thomas Adam.


# 1.111 18-Jun-2012 nicm

Add a skeleton mode to tmux (called "control mode") that let's tmux
commands be sent and output received on stdout. This can be used to
integrate with other terminal emulators and should allow some other
things to be made simpler later. More to come so doesn't do much yet and
deliberately not documented.


# 1.110 30-May-2012 nicm

Do not use stderr for log file and don't call log_close when not needed.


# 1.109 25-May-2012 nicm

Simplify logging and just fprintf(stderr, ...) for early errors.


Revision tags: OPENBSD_5_1_BASE
# 1.108 21-Jan-2012 nicm

Drop the ability to have a list of keys in the prefix in favour of two
separate options, prefix and prefix2. This simplifies the code and gets
rid the data options type which was only used for this one option.

Also add a -2 flag to send-prefix to send the secondary prefix key,
fixing a cause of minor irritation.

People who want three prefix keys are out of luck :-).


# 1.107 23-Oct-2011 nicm

Try to resolve relative paths for loadb and saveb (first using client
working directory if any then default-path or session wd).


# 1.106 23-Oct-2011 nicm

Ignore LC_ALL and LC_CTYPE if they are empty as well as unset.


# 1.105 25-Sep-2011 nicm

Reject $SHELL if it is not a full path.


Revision tags: OPENBSD_5_0_BASE
# 1.104 04-Mar-2011 nicm

Two fixes by Micah Cowan: make mouse work properly beyond >127 on signed
char architectures and properly parse $TMUX by stopping the socket path
at the first comma.


Revision tags: OPENBSD_4_9_BASE
# 1.103 23-Jan-2011 nicm

Set $TMUX without the session when background jobs are run.


# 1.102 12-Jan-2011 nicm

Use TMPDIR if set, from Han Boetes.


# 1.101 08-Jan-2011 nicm

Move all calls to fcntl(...O_NONBLOCK) into a function and clear the
flag on the stdio file descriptors before closing them (fixes things
like "tmux ls && cat").


# 1.100 03-Jan-2011 nicm

Support for UTF-8 mouse input (\033[1005h). This was added in xterm 262
and supports larger terminals than the older way.

If the new mouse-utf8 option is on, UTF-8 mouse input is enabled for all
UTF-8 terminals. The option defaults to on if LANG etc are set in the
same manner as the utf8 option.

With help and based on code from hsim at gmx.li.


# 1.99 01-Jan-2011 nicm

Move the user-visible parts of all options (names, types, limit, default
values) together into one set of tables in options-table.c. Also clean
up and simplify cmd-set-options.c and move a common print function into
option-table.c.


# 1.98 30-Dec-2010 nicm

Change from a per-session stack of buffers to one global stack which is
much more convenient and also simplifies lot of code. This renders
copy-buffer useless and makes buffer-limit now a server option.

By Tiago Cunha.


# 1.97 19-Dec-2010 nicm

Add other-pane-height and other-pane-width options, allowing the width
or height of the smaller panes in the main-horizontal and main-vertical
layouts to be set. Mostly from David Goodlad.


# 1.96 08-Dec-2010 nicm

In the built-in layouts, distribute the panes more evenly. Set the
default value of main-pane-width to 80, rather than 81. By Micah Cowan.


# 1.95 06-Dec-2010 nicm

Add an option to alert (monitor) for silence (lack of activity) in a
window. From Thomas Adam.


# 1.94 29-Nov-2010 nicm

If VISUAL or EDITOR contains "vi", configure mode-keys and status-keys
to vi.

Based on a diff from martynas@, previously requested by a couple of
other people.


# 1.93 11-Nov-2010 nicm

Add XAUTHORITY to update-environment, requested by Andreas Kloeckner.


# 1.92 18-Oct-2010 nicm

Merge the before and after attach client code into one in client.c
(instead of two in tmux.c and client.c).


# 1.91 16-Oct-2010 nicm

Make stdio blocking again before calling shell command with -c.


# 1.90 16-Oct-2010 nicm

Trying to set FD_CLOEXEC on every fd is a lost cause, just use
closefrom() before exec.


# 1.89 14-Oct-2010 nicm

Use an explicit event rather than event_once for the main event so it
can be removed when the client becomes ready.


# 1.88 26-Sep-2010 nicm

Two new options:

- server option "exit-unattached" makes the server exit when no clients
are attached, even if sessions are present;

- session option "destroy-unattached" destroys a session once no clients
are attached to it.

These are useful for preventing tmux remaining in the background where
it is undesirable and when using tmux as a login shell to keep a limit
on new sessions.


# 1.87 19-Aug-2010 nicm

Do not call event_del() for signals after fork(), just use sigaction()
directly instead - calling libevent functions after fork() w/o
event_reinit() is a bad idea, even if in this case it was harmless.


Revision tags: OPENBSD_4_8_BASE
# 1.86 04-Aug-2010 deraadt

switch back to kqueue for now, since (a) kqueue has been fixed to deal
with strange devices and (b) since there appears to be a bull in the
poll code in libevent as well...
requested by nicm who is away


# 1.85 24-Jul-2010 nicm

kqueue(2) is currently broken when used with /dev/null and a few other
devices.

An upcoming fix for some problems with the client stdout/stderr handling
relies on it working, so make tmux force libevent to use poll(2) via
EVENT_NOKQUEUE, until we have fixed kqueue.


# 1.84 11-Jul-2010 nicm

Return the command client return code with MSG_EXIT now that MSG_ERROR and
MSG_PRINT are unused.

New clients should be compatible with old tmux servers but vice versa may print
an error.


# 1.83 28-Jun-2010 nicm

Send all three of stdin, stdout, stderr from the client to the server, so that
commands can directly make use of them. This means that load-buffer and
save-buffer can have "-" as the file to read from stdin or write to stdout.

This is a protocol version bump so the tmux server will need to be restarted
after upgrade (or an older client used).


# 1.82 27-Jun-2010 nicm

Store the current working directory in the session, change the default-path
option to default to empty and make that mean that the stored session CWD is
used.


# 1.81 27-Jun-2010 nicm

New option, detach-on-destroy, to set what happens to a client when the session
it is attached to is destroyed. If on (the default), it is detached; if off, it
is switched to the most recently active session.


# 1.80 26-Jun-2010 nicm

Setting the cmdlist pointer in the bind-key to NULL to prevent it being freed
after the command is executing is bogus because it may still be needed if the
same command is going to be executed again (for example if you "bind-key a
bind-key b ..."). Making a copy is hard, so instead add a reference count to
the cmd_list.

While here, also print bind-key -n and the rest of the flags properly.

Fixes problem reported by mcbride@.


# 1.79 14-May-2010 nicm

Colour+attribute options for status line alerts, from Alex Alexander.


# 1.78 04-May-2010 nicm

Put this back in with the initialisation in the right order.


# 1.77 04-May-2010 nicm

Revert last change, it appears to be broken somehow.


# 1.76 03-May-2010 nicm

Make signal handler setup/teardown two common functions instead of six,
and reset SIGCHLD after fork to fix problems with some shells. From
Romain Francois.


# 1.75 28-Apr-2010 nicm

Make the active pane border have a green foreground instead of
background by default.


# 1.74 18-Apr-2010 nicm

Catch SIGCHLD to avoid a zombie, from patrick keshishian.


Revision tags: OPENBSD_4_7_BASE
# 1.73 22-Feb-2010 nicm

Option to set the characters considered word separators in copy mode, from
Micah Cowan.


# 1.72 08-Feb-2010 nicm

Add an option to disable the smcup/rmcup alternate screen behaviour inside
tmux. From clemens fischer.


# 1.71 06-Feb-2010 nicm

Change nested check to compare server socket path rather than just assuming
that if $TMUX is set it is nested. From Micah Cowan.


# 1.70 06-Feb-2010 nicm

Clean up $TMUX parsing, from Micah Cowan, tweaked by me.


# 1.69 06-Feb-2010 nicm

Instead of bailing out on the first configuration file error, carry on,
collecting all the errors, then start with the active window in more mode
displaying them.


# 1.68 04-Feb-2010 nicm

Read the path from $TMUX if it is present and -L and -S are not given. Based on
a diff from Micah Cowan.


# 1.67 04-Feb-2010 nicm

Option to display the active pane in a different colour with the display-panes
command. From Paul Hoffman, thanks.


# 1.66 03-Jan-2010 nicm

Options to set the colour of the pane borders, with different colours for the
active pane.


# 1.65 14-Dec-2009 nicm

New server option, escape-time, to set the timeout used to detect if escapes
are alone or part of a function key or meta sequence.


# 1.64 11-Dec-2009 nicm

Use quiet variable, and add missing sentinel to options array.


# 1.63 10-Dec-2009 nicm

Add "server options" which are server-wide and not bound to a session or
window. Set and displayed with "set -s" and "show -s".

Currently the only option is "quiet" (like command-line -q, allowing it to be
set from .tmux.conf), but others will come along.


# 1.62 03-Dec-2009 nicm

Massive spaces->tabs and trailing whitespace cleanup, hopefully for the last
time now I've configured emacs to make them displayed in really annoying
colours...


# 1.61 26-Nov-2009 nicm

Remove a couple of unused arguments where possible, and add /* ARGSUSED */ to
the rest to reduce lint output.


# 1.60 19-Nov-2009 nicm

Two new options, window-status-format and window-status-current-format, which
allow the format of each window in the status line window list to be controlled
using similar # sequences as status-left/right.

This diff also moves part of the way towards UTF-8 support in window names but
it isn't quite there yet.


# 1.59 19-Nov-2009 nicm

Revert to xterm-keys off by default. It was on as an experiment to see if the
option could be removed, but it affects vi, so we have to keep the option, and
a conservative default is better.


# 1.58 18-Nov-2009 nicm

Add a per-client log of status line messages displayed while that client
exists. A new message-limit session option sets the maximum number of entries
and a command, show-messages, shows the log (bound to ~ by default).

This (and prompt history) might be better as a single global log but until
there are global options it is easier for them to be per client.


# 1.57 10-Nov-2009 nicm

There is no real standard for modifier plus function keys. Previously, tmux
output some from rxvt but in other ways did the same as xterm or other
terminals, but this is a bit inconsistent.

xterm's method is fairly sensible and we already support it (xterm-keys), so
enable it by default instead.


# 1.56 04-Nov-2009 nicm

A couple of minor cosmetic changes.


# 1.55 04-Nov-2009 nicm

Initial changes to move tmux to libevent.

This moves the client-side loops are pretty much fully over to event-based only
(tmux.c and client.c) but server-side (server.c and friends) treats libevent as
a sort of clever poll, waking up after every event to run various things.

Moving the server stuff over to bufferevents and timers and so on will come
later.


# 1.54 04-Nov-2009 nicm

Change declaration and use of malloc_options to be more standard, from Tim van
der Molen.


# 1.53 26-Oct-2009 deraadt

tabs are better; ok nicm


# 1.52 25-Oct-2009 nicm

Remove the -d flag to tmux and just use op/AX to detect default colours.

Irritatingly, although op can be used to tell if a terminal supports default
colours, it can't be used to set them because in some terminfo descriptions it
resets attributes as a side-effect (acts as sgr0) and in others it doesn't, so
it is not possible to determine reliably what the terminal state will be
afterwards. So if AX is missing and op is present, tmux just sends sgr0.

Anyone using -d for a terminal who finds they actually needed it can replace it
using terminal-overrides, but please let me know as it is probably an omission
from terminfo.


# 1.51 22-Oct-2009 nicm

Merge prepare_cmd into main as it is short and only called once.


# 1.50 21-Oct-2009 nicm

Client tidying: get rid of client_ctx struct in favour of two variables in
client.c, and move the functions in client-fn.c into other files.


# 1.49 10-Oct-2009 nicm

New option, mouse-select-pane. If on, the mouse may be used to select the
current pane.

Suggested by sthen@ and also by someone else ages ago who I have forgotten.


# 1.48 10-Oct-2009 nicm

Support for individual session idle time locking. May be enabled by turning off
the lock-server option (it is on by default). When this is off, each session
locks when it has been idle for the lock-after-time setting. When on, the
entire server locks when ALL sessions have been idle for their individual
lock-after-time settings.

This replaces one global-only option (lock-after-time) with another
(lock-server), but the default behaviour is usually preferable so there don't
seem to be many alternatives.

Diff/idea largely from Thomas Adam, tweaked by me.


# 1.47 09-Oct-2009 nicm

Add a simple synchronize-panes window option: when set, all input to any pane
that is part of the window is also sent to all other panes in the same
window. Suggested by several, most recently Tomasz Pajor.


# 1.46 23-Sep-2009 nicm

Support -c like sh(1) to execute a command, useful when tmux is a login
shell. Suggested by halex@.

This includes another protocol version increase (the last for now) so again
restart the tmux server before upgrading.


# 1.45 23-Sep-2009 nicm

Remove the internal tmux locking and instead detach each client and run the
command specified by a new option "lock-command" (by default "lock -np") in
each client.

This means each terminal has to be unlocked individually but simplifies the
code and allows the system password to be used to unlock.

Note that the set-password command is gone, so it will need to be removed from
configuration files, and the -U command line flag has been removed.

This is the third protocol version change so again it is best to stop the tmux
server before upgrading.


# 1.44 22-Sep-2009 nicm

Permit multiple prefix keys to be defined, separated by commas, for example:

set -g prefix ^a,^b

Any key in the list acts as the prefix. The send-prefix command always sends
the first key in the list.


# 1.43 18-Sep-2009 nicm

New option, set-titles-string, to allow the window title to be specified (as
for status-left/right) if set-titles is on. Also only update the title when the
status line is being redrawn.


# 1.42 04-Sep-2009 nicm

Tidy main and make it a bit easier to read.


# 1.41 02-Sep-2009 nicm

Accept -l to make it easier for people who use tmux as a login shell to use
$SHELL. Originally from martynas@, tweaked by me.


# 1.40 02-Sep-2009 nicm

When incorrect passwords are entered, behave similarly to login(1) and backoff
for a bit. Based on a diff from martynas@.


# 1.39 01-Sep-2009 nicm

When using tmux as a login shell, there is currently no way to specify a shell
to be used as a login shell inside tmux, so add a default-shell session option.
This sets the shell invoked as a login shell when the default-command option is
empty.

The default option value is whichever of $SHELL, getpwuid(getuid())'s pw_shell
or /bin/sh is valid first.

Based on a diff from martynas@, changed by me to be a session option rather
than a window option.


# 1.38 01-Sep-2009 nicm

Use "Password:" with no space for password prompts and don't display a *s for
the password, like pretty much everything else. From martynas@ with minor
tweaks by me.


# 1.37 01-Sep-2009 nicm

Sort cases same as getopt argument, from martynas.


# 1.36 31-Aug-2009 nicm

Add a new display-panes command, with two options (display-panes-colour and
display-panes-time), which displays a visual indication of the number of each
pane.


# 1.35 23-Aug-2009 nicm

Add some other obvious variables to update-environment (WINDOWID SSH_ASKPASS
SSH_AUTH_SOCK SSH_AGENT_PID SSH_CONNECTION) so they are updated in the session
environment on new/attach.


# 1.34 13-Aug-2009 nicm

Disable mode-mouse (mouse in copy/choice mode) by default as it isn't very
useful at the moment and causes confusion.


# 1.33 13-Aug-2009 nicm

Add a base-index session option to specify the first index checked when looking
for an index for a new window.


# 1.32 12-Aug-2009 nicm

When started as the shell, __progname contains a leading -, so hardcode "tmux"
for socket path and log files, and strip it when working out the shell.


# 1.31 11-Aug-2009 nicm

Switch tmux to use imsg. This is the last major change to make the
client-server protocol more resilient and make the protocol versioning work
properly. In future, the only things requiring a protocol version bump will be
changes in the message structs, and (when both client and server have this
change) mixing different versions should nicely report an error message.

As a side effect this also makes the code tidier, fixes a problem with the way
errors reported during server startup were handled, and supports fd passing
(which will be used in future).

Looked over by eric@, thanks.

Please note that mixing a client with this change with an older server or vice
versa may cause tmux to crash or hang - tmux should be completely exited before
upgrading.


# 1.30 10-Aug-2009 nicm

No arguments are the same as new-session and this requires the environment to
be sent, so set that flag too when argc == 0.


# 1.29 08-Aug-2009 nicm

Infrastructure and commands to manage the environment for processes started
within tmux.

There is a global environment, copied from the external environment when the
server is started and each sesssion has an (initially empty) session
environment which overrides it.

New commands set-environment and show-environment manipulate or display the
environments.

A new session option, update-environment, is a space-separated list of
variables which are updated from the external environment into the session
environment every time a new session is created - the default is DISPLAY.


# 1.28 08-Aug-2009 nicm

Options to set the colours and attributes for status-left/-right. From Thomas
Adam, thanks.


# 1.27 05-Aug-2009 nicm

If colours are not supported by the terminal, try to emulate a coloured
background by setting or clearing the reverse attribute.

This makes a few applications which don't use the reverse attribute themselves
a little happier, and allows the status, message and mode options to have
default attributes and fg/bg options that work as expected when set as reverse.


# 1.26 04-Aug-2009 nicm

Check for "UTF8" as well as "UTF-8" in LANG etc as it seems this may also
appear.


# 1.25 03-Aug-2009 nicm

Add a terminal-overrides session option allowing individual terminfo(5) entries
to be overridden. The 88col/256col checks are now moved into the default
setting and out of the code.

Also remove a couple of old workarounds for xterm and rxvt which are no longer
necessary (tmux can emulate them if missing).


# 1.24 30-Jul-2009 nicm

Add a mode-mouse option to prevent tmux taking over the mouse in choice or copy
modes.


# 1.23 29-Jul-2009 nicm

Rename struct hdrtype to msgtype which is a better name and can be used even
when struct hdr disappears.


# 1.22 29-Jul-2009 nicm

Taking account of the "s, 22 not 24 is the maximum length of #T in status-right
to prevent the date being cut off.


# 1.21 26-Jul-2009 nicm

Make all messages sent between the client and server fixed size.

This is the first of two changes to make the protocol more resilient and less
sensitive to other changes in the code, particularly with commands. The client
now packs argv into a buffer and sends it to the server for parsing, rather
than doing it itself and sending the parsed command data.

As a side-effect this also removes a lot of now-unused command marshalling
code.

Mixing a server without this change and a client with or vice versa will cause
tmux to hang or crash, please ensure that tmux is entirely killed before
upgrading.


# 1.20 22-Jul-2009 nicm

Pass a set of flags into client_init rather than just a start_server
variable. Only one flag now but more to come later.


# 1.19 20-Jul-2009 nicm

Display the number of failed password attempts (if any) when the server is
locked. From Tom Doherty.


# 1.18 20-Jul-2009 nicm

Add a status-justify option to allow the window list in the status line to be
positioned at the left, centre, or right.


# 1.17 20-Jul-2009 nicm

New options, window-status-current-{fg,bg,attr}, to set the fg, bg and
attributes with which the current window is shown in the status line. From
Johan Friis, thanks.


# 1.16 18-Jul-2009 nicm

Add three new session options: visual-activity, visual-bell, visual-content. If
these are enabled (and the monitor-activity, bell-actio and monitor-content
options are configurated appropriately), when activity, a bell, or content is
detected, a message is shown.

Also tidy up the bell/activity/content code in server.c slightly and fix a
couple of errors.


# 1.15 17-Jul-2009 nicm

If -u is specified or UTF-8 is otherwise detected when the server is started,
enable the utf8 and status-utf8 optons. While here, note in the man page that
the server is started with the first session and exits when none remain.


# 1.14 10-Jul-2009 nicm

Add a default-terminal option to set the starting value of $TERM in new
windows.

This is "screen" by default and must be either that or something closely
related. This does makes it easier to customise it if necessary.


# 1.13 08-Jul-2009 nicm

Just appending -l to $SHELL to create a login shell is wrong: -l is not POSIX,
and some people may use shells which do not support it. Instead, make an empty
default-command option mean a login shell, and fork it with a - in argv[0]
which is the method used by login(1).

Also fix the automatic-rename code to handle this correctly and to strip a
leading - if present.


# 1.12 07-Jul-2009 nicm

Rename the global options variables to be shorter and to make session options
clear. No functional change, getting this out of the way to make later options
changes easier.


Revision tags: OPENBSD_4_6_BASE
# 1.11 25-Jun-2009 nicm

If getcwd() fails, use the user's home directory, or /, instead of failing with
an error.


# 1.10 25-Jun-2009 nicm

Remove error about using -L and -S together which was never displayed as
logging wasn't yet enabled, was unnecessary, and contradicted the man page
which says using -S will cause -L to be ignored.


# 1.9 23-Jun-2009 nicm

LC_ALL overrides LC_CTYPE and LANG. Comment was correct but the code
wrong. Pointed out by Hannah Schroeter, thanks.


# 1.8 05-Jun-2009 nicm

Check the first of LC_CTYPE, LC_ALL and LANG, rather than just the last, when
trying to decide about UTF-8, and use strcasestr. Reported by Geert Hendrickx.


# 1.7 04-Jun-2009 nicm

Zero the password given to -U in the client as well.


# 1.6 03-Jun-2009 nicm

Do not set the window title by default (make set-titles option default to off),
wiping over the title is rude and annoying. Agreed by several.


# 1.5 03-Jun-2009 nicm

New session option, status-utf8, to control the interpretation of top-bit-set
characters in status-left and status-right (if on, they are treated as UTF-8;
otherwise passed through).


# 1.4 02-Jun-2009 sobrado

remove unused flag; while here, make usage's output fit on 80-column displays.


# 1.3 02-Jun-2009 pyr

spawn login shells by default, adapt manpage bits as well.
ok nicm@


# 1.2 02-Jun-2009 ray

Don't leak memory if multiple -f flags are given.

OK nicm@


# 1.1 01-Jun-2009 nicm

Import tmux, a terminal multiplexor allowing (among other things) a single
terminal to be switched between several different windows and programs
displayed on one terminal be detached from one terminal and moved to another.

ok deraadt pirofti


# 1.186 12-Jan-2018 nicm

Improve error message if creating socket parent directory fails, from
Thomas Adam for GitHub issue 1215.


# 1.185 01-Jan-2018 nicm

Prefer PWD for current directory if present in client, from Wei Zhao in
GitHub issue 1183.


Revision tags: OPENBSD_6_2_BASE
# 1.184 12-Jul-2017 nicm

Make shell_command a global like other stuff rather than making it an
exception and using callback argument.


# 1.183 03-Jul-2017 nicm

Try C.UTF-8 which is also a commonly useful locale on some platforms,
from Romain Francoise.


# 1.182 22-Apr-2017 nicm

Do not need getopt.h.


# 1.181 20-Apr-2017 nicm

Use fdforkpty() instead of our own unwrapped versions.


# 1.180 19-Apr-2017 nicm

Style nits and a missing cast.


# 1.179 16-Apr-2017 nicm

Memory leak, from David CARLIER.


Revision tags: OPENBSD_6_1_BASE
# 1.178 21-Mar-2017 nicm

Use uid_t for UID not u_int.


# 1.177 16-Feb-2017 nicm

Style nits.


# 1.176 23-Jan-2017 nicm

Open /dev/ptm before pledge() and save it to be used for PTMGET later
(this means inlining forkpty()).

ok deraadt


# 1.175 15-Jan-2017 nicm

Major tidy up and rework of options tree and set-option/show-options
commands this pushes more of the code into options.c and ties it more
closely to the options table rather than having an unnecessary
split. Also add support for array options (will be used later). Only
(intentional) user visible change is that show-options output is now
passed through vis(3) with VIS_DQ so quotes are escaped.


# 1.174 12-Jan-2017 nicm

Simplify appending to string options.


# 1.173 09-Dec-2016 nicm

Spacing nits.


# 1.172 11-Oct-2016 nicm

Add static in window-*.c and move some internal functions out of tmux.h.


# 1.171 10-Oct-2016 nicm

Loads more static, except for cmd-*.c and window-*.c.


Revision tags: OPENBSD_6_0_BASE
# 1.170 27-May-2016 nicm

Use getprogname() instead of __progname to make portability easier.


# 1.169 04-May-2016 nicm

Fix up a couple of long lines.


# 1.168 05-Mar-2016 nicm

If setlocale("en_US.UTF-8") succeeds, then don't do the check for UTF-8
locale since if it isn't UTF-8 the system is broken anyway. If it fails,
try "" and check for UTF-8 with nl_langinfo(CODESET) rather than
wcwidth(). Based on a diff from schwarze@, nl_langinfo also suggested by
stsp@.


# 1.167 05-Mar-2016 nicm

Although we always have en_US.UTF-8 on OpenBSD, some platforms do not,
so fall back to setlocale(LC_CTYPE, ""). tmux requires a UTF-8 locale,
so check with wcwidth() on a UTF-8 character after setlocale().


# 1.166 01-Mar-2016 nicm

Remove unused variables, from Michal Mazurek.


# 1.165 01-Mar-2016 nicm

Use system wcwidth() instead of carrying around UTF-8 width tables.


Revision tags: OPENBSD_5_9_BASE
# 1.164 19-Jan-2016 nicm

I no longer use my SourceForge address so replace it.


# 1.163 08-Dec-2015 nicm

Add hooks infrastructure, basic commands (set-hook, show-hooks) and a
couple of not very useful client hooks. This will eventually let
commands be run at various points and on notifications. Joint work with
Thomas Adam.


# 1.162 24-Nov-2015 nicm

Make environ_set va_args and use it to tidy up some calls. Also add a
missing word in manpage (from jmc).


# 1.161 24-Nov-2015 nicm

Shell command from -c doesn't have to be global, pass it as an argument.


# 1.160 24-Nov-2015 nicm

Tidy the code that works out the socket path, and just use the full path
in the global socket_path rather than copying it.


# 1.159 24-Nov-2015 nicm

Remove malloc_options DEBUG bit.


# 1.158 24-Nov-2015 nicm

Remove the -I part of show-messages which isn't really that useful; the
server start time can now be accessed with a new start_time format (use:
tmux display -p '#{t:start_time}')


# 1.157 24-Nov-2015 nicm

Make the log stuff a bit tidier with some helper functions.


# 1.156 22-Nov-2015 nicm

Add getpw to pledge, makes tmux work in YP environments, discovered by
matthieu, ok deraadt


# 1.155 20-Nov-2015 nicm

Instead of separate tables for different types of options, give each
option a scope type (server, session, window) in one table.


# 1.154 15-Nov-2015 nicm

Accidentally turned off pledge, turn it back on.


# 1.153 14-Nov-2015 nicm

Push stdout and stderr to clients more aggressively, and add an event to
continue if the send fails.


# 1.152 12-Nov-2015 nicm

tmux is UTF-8, so if $TMUX is set (tmux running in tmux), the client is
UTF-8. Also try to make the existing checks more readable.


# 1.151 12-Nov-2015 nicm

Nuke the utf8 and status-utf8 options and make tmux only a UTF-8
terminal. We still support non-UTF-8 terminals outside tmux, but inside
it is always UTF-8 (as when the utf8 and status-utf8 options were on).


# 1.150 11-Nov-2015 nicm

Drop mouse-utf8 option and always turn on UTF-8 mouse if the client says
it supports UTF-8.


# 1.149 28-Oct-2015 nicm

Like options, move the environ struct into environ.c.


# 1.148 27-Oct-2015 nicm

Move struct options into options.c.


# 1.147 27-Oct-2015 nicm

Break the common process set up, event loop and imsg dispatch code
between server and client out into a separate internal API. This will
make it easier to add another process.


# 1.146 25-Oct-2015 deraadt

Let's see if anyone screams about not being able to specify $TMPDIR
for their tmux sockets.

(Over the years, I have seen $TMPDIR set up worse than /tmp many times,
and don't know how this practice infected other parts of the system.
Nothing uses tmpdir(3), nor a huge-temporary-file program like sort.)
ok nicm


# 1.145 23-Oct-2015 nicm

tmux can call pledge() in main with large set and then reduce it
slightly in the server to "stdio rpath wpath cpath fattr unix recvfd
proc exec tty ps".


# 1.144 14-Sep-2015 nicm

Move tzset() from log_open to main.


# 1.143 03-Sep-2015 nicm

A couple of style nits.


# 1.142 01-Sep-2015 nicm

Work out config file when needed not at startup.


# 1.141 30-Aug-2015 nicm

Path from $TMUX does not need to be global anymore.


# 1.140 30-Aug-2015 nicm

Login shell can be a client flag, and move the exec code into client.c.


# 1.139 30-Aug-2015 nicm

Event base does not need to be global.


# 1.138 30-Aug-2015 nicm

Some style nits and dead assignments.


Revision tags: OPENBSD_5_8_BASE
# 1.137 20-Jul-2015 nicm

Add an option (history-file) for a file to save/restore command prompt
history, from Olof-Joachim Frahm.


# 1.136 04-Jun-2015 jmc

tweak SYNOPSIS and usage();


Revision tags: OPENBSD_5_7_BASE
# 1.135 19-Jan-2015 nicm

Make a tmux-%u directory under TMUX_TMPDIR, like TMPDIR.


# 1.134 19-Jan-2015 nicm

Only care about other permissions, allow group to be set.


# 1.133 19-Jan-2015 nicm

Remove unnecessary duplicate S_ISDIR check, from Dmitri Paduchikh.


# 1.132 20-Oct-2014 nicm

Tidy up some includes.


Revision tags: OPENBSD_5_6_BASE
# 1.131 17-Apr-2014 nicm

Remove the "info" message mechanism, this was only used for about five
mostly useless and annoying messages. Change those commands to silence
on success like all the others. Still accept the -q command line flag
and "quiet" server option for now.


# 1.130 31-Mar-2014 nicm

Remove log_debug2 as well and simplify log.c.


Revision tags: OPENBSD_5_5_BASE
# 1.129 16-Feb-2014 nicm

Leftovers from removing 88 colour support, from Theo Buehler.


# 1.128 15-Jan-2014 nicm

Do not attempt to read .tmux.conf if we can't figure out a home
directory, from Tiago Cunha.


# 1.127 09-Jan-2014 nicm

Three small changes from Tiago Cunha:

- Check for truncation when copying path.
- Don't need to use a temporary buffer in screen_set_title.
- Include strerror in output when connecting to server fails.


# 1.126 10-Oct-2013 nicm

We accidentally haven't been using $TMUX to work out the session for a
while and in fact it is less useful that using the client ttyname. So
don't bother and don't pass it from the client. If we need it in future
it is in c->environ.


# 1.125 10-Oct-2013 nicm

Alter how tmux handles the working directory to internally use file
descriptors rather than strings.

- Each session still has a current working directory.

- New sessions still get their working directory from the client that
created them or its attached session if any.

- New windows are created by default in the session working directory.

- The -c flag to new, neww, splitw allows the working directory to be
overridden.

- The -c flag to attach let's the session working directory be changed.

- The default-path option has been removed.

To get the equivalent to default-path '.', do:

bind c neww -c $PWD

To get the equivalent of default-path '~', do:

bind c neww -c ~

This also changes the client identify protocol to be a set of messages rather
than one as well as some other changes that should make it easier to make
backwards-compatible protocol changes in future.


# 1.124 10-Oct-2013 nicm

Merge IDENTIFY_* flags with CLIENT_* flags.


# 1.123 10-Oct-2013 nicm

Don't treat TMUX_TMPDIR as a potential file

The point of setting TMUX_TMPDIR is to then make any labels from -L go
to that directory. In the case of makesocketpath() with no TMUX_TMPDIR
set, would set both the path and the default socket to a file. The
checking of the permissions on the file worked fine in that case, but
when TMUX_TMPDIR is set, won't work on a directory.

This fixes the problem by ensuring the check on the permissions is
performed on directories only.

By Thomas Adam.


# 1.122 05-Oct-2013 nicm

Fix previous not to leak fd on failure, whoops.


# 1.121 05-Oct-2013 nicm

Use open(".")/fchdir() to save and restore current directory rather than
getcwd()/chdir().


Revision tags: OPENBSD_5_4_BASE
# 1.120 24-Apr-2013 nicm

Rename global configuration define.


# 1.119 11-Apr-2013 nicm

Call setlocale(LC_TIME) at startup.


# 1.118 27-Mar-2013 nicm

Add TMUX_TMPDIR variable to put the socket directory outside
TMPDIR. From Ben Boeckel.


# 1.117 27-Mar-2013 nicm

Remove tmux's (already minimal) 88 colour support. Such terminals are
few and unnecessary.


# 1.116 25-Mar-2013 nicm

Rename session idx to session id throughout and add $ prefix to targets
to use it, extended from a diff from George Nachman.


# 1.115 24-Mar-2013 nicm

Add a command queue to standardize and simplify commands that call other
commands and allow a command to block execution of subsequent
commands. This allows run-shell and if-shell to be synchronous which has
been much requested.

Each client has a default command queue and commands are consumed one at
a time from it. A command may suspend execution from the queue by
returning CMD_RETURN_WAIT and then resume it by calling cmd_continue() -
for example run-shell does this from the callback that is fired after
the job is freed.

When the command queue becomes empty, command clients are automatically
exited (unless attaching). A callback is also fired - this is used for
nested commands in, for example, if-shell which can block execution of
the client's cmdq until a new cmdq becomes empty.

Also merge all the old error/info/print functions together and lose the
old curclient/cmdclient distinction - a cmdq is bound to one client (or
none if in the configuration file), this is a command client if
c->session is NULL otherwise an attached client.


Revision tags: OPENBSD_5_3_BASE
# 1.114 27-Nov-2012 nicm

Correctly aggregate together errors from nested config files (with
source-file). Fix by Thomas Adam, reported by Sam Livingstone-Gray


# 1.113 26-Nov-2012 nicm

Call realpath earlier on the socket directory path rather than on the
socket file path because the latter may not exist yet and in that case
realpath is allowed to fail. From Romain Francoise.


Revision tags: OPENBSD_5_2_BASE
# 1.112 10-Jul-2012 nicm

xfree is not particularly helpful, remove it. From Thomas Adam.


# 1.111 18-Jun-2012 nicm

Add a skeleton mode to tmux (called "control mode") that let's tmux
commands be sent and output received on stdout. This can be used to
integrate with other terminal emulators and should allow some other
things to be made simpler later. More to come so doesn't do much yet and
deliberately not documented.


# 1.110 30-May-2012 nicm

Do not use stderr for log file and don't call log_close when not needed.


# 1.109 25-May-2012 nicm

Simplify logging and just fprintf(stderr, ...) for early errors.


Revision tags: OPENBSD_5_1_BASE
# 1.108 21-Jan-2012 nicm

Drop the ability to have a list of keys in the prefix in favour of two
separate options, prefix and prefix2. This simplifies the code and gets
rid the data options type which was only used for this one option.

Also add a -2 flag to send-prefix to send the secondary prefix key,
fixing a cause of minor irritation.

People who want three prefix keys are out of luck :-).


# 1.107 23-Oct-2011 nicm

Try to resolve relative paths for loadb and saveb (first using client
working directory if any then default-path or session wd).


# 1.106 23-Oct-2011 nicm

Ignore LC_ALL and LC_CTYPE if they are empty as well as unset.


# 1.105 25-Sep-2011 nicm

Reject $SHELL if it is not a full path.


Revision tags: OPENBSD_5_0_BASE
# 1.104 04-Mar-2011 nicm

Two fixes by Micah Cowan: make mouse work properly beyond >127 on signed
char architectures and properly parse $TMUX by stopping the socket path
at the first comma.


Revision tags: OPENBSD_4_9_BASE
# 1.103 23-Jan-2011 nicm

Set $TMUX without the session when background jobs are run.


# 1.102 12-Jan-2011 nicm

Use TMPDIR if set, from Han Boetes.


# 1.101 08-Jan-2011 nicm

Move all calls to fcntl(...O_NONBLOCK) into a function and clear the
flag on the stdio file descriptors before closing them (fixes things
like "tmux ls && cat").


# 1.100 03-Jan-2011 nicm

Support for UTF-8 mouse input (\033[1005h). This was added in xterm 262
and supports larger terminals than the older way.

If the new mouse-utf8 option is on, UTF-8 mouse input is enabled for all
UTF-8 terminals. The option defaults to on if LANG etc are set in the
same manner as the utf8 option.

With help and based on code from hsim at gmx.li.


# 1.99 01-Jan-2011 nicm

Move the user-visible parts of all options (names, types, limit, default
values) together into one set of tables in options-table.c. Also clean
up and simplify cmd-set-options.c and move a common print function into
option-table.c.


# 1.98 30-Dec-2010 nicm

Change from a per-session stack of buffers to one global stack which is
much more convenient and also simplifies lot of code. This renders
copy-buffer useless and makes buffer-limit now a server option.

By Tiago Cunha.


# 1.97 19-Dec-2010 nicm

Add other-pane-height and other-pane-width options, allowing the width
or height of the smaller panes in the main-horizontal and main-vertical
layouts to be set. Mostly from David Goodlad.


# 1.96 08-Dec-2010 nicm

In the built-in layouts, distribute the panes more evenly. Set the
default value of main-pane-width to 80, rather than 81. By Micah Cowan.


# 1.95 06-Dec-2010 nicm

Add an option to alert (monitor) for silence (lack of activity) in a
window. From Thomas Adam.


# 1.94 29-Nov-2010 nicm

If VISUAL or EDITOR contains "vi", configure mode-keys and status-keys
to vi.

Based on a diff from martynas@, previously requested by a couple of
other people.


# 1.93 11-Nov-2010 nicm

Add XAUTHORITY to update-environment, requested by Andreas Kloeckner.


# 1.92 18-Oct-2010 nicm

Merge the before and after attach client code into one in client.c
(instead of two in tmux.c and client.c).


# 1.91 16-Oct-2010 nicm

Make stdio blocking again before calling shell command with -c.


# 1.90 16-Oct-2010 nicm

Trying to set FD_CLOEXEC on every fd is a lost cause, just use
closefrom() before exec.


# 1.89 14-Oct-2010 nicm

Use an explicit event rather than event_once for the main event so it
can be removed when the client becomes ready.


# 1.88 26-Sep-2010 nicm

Two new options:

- server option "exit-unattached" makes the server exit when no clients
are attached, even if sessions are present;

- session option "destroy-unattached" destroys a session once no clients
are attached to it.

These are useful for preventing tmux remaining in the background where
it is undesirable and when using tmux as a login shell to keep a limit
on new sessions.


# 1.87 19-Aug-2010 nicm

Do not call event_del() for signals after fork(), just use sigaction()
directly instead - calling libevent functions after fork() w/o
event_reinit() is a bad idea, even if in this case it was harmless.


Revision tags: OPENBSD_4_8_BASE
# 1.86 04-Aug-2010 deraadt

switch back to kqueue for now, since (a) kqueue has been fixed to deal
with strange devices and (b) since there appears to be a bull in the
poll code in libevent as well...
requested by nicm who is away


# 1.85 24-Jul-2010 nicm

kqueue(2) is currently broken when used with /dev/null and a few other
devices.

An upcoming fix for some problems with the client stdout/stderr handling
relies on it working, so make tmux force libevent to use poll(2) via
EVENT_NOKQUEUE, until we have fixed kqueue.


# 1.84 11-Jul-2010 nicm

Return the command client return code with MSG_EXIT now that MSG_ERROR and
MSG_PRINT are unused.

New clients should be compatible with old tmux servers but vice versa may print
an error.


# 1.83 28-Jun-2010 nicm

Send all three of stdin, stdout, stderr from the client to the server, so that
commands can directly make use of them. This means that load-buffer and
save-buffer can have "-" as the file to read from stdin or write to stdout.

This is a protocol version bump so the tmux server will need to be restarted
after upgrade (or an older client used).


# 1.82 27-Jun-2010 nicm

Store the current working directory in the session, change the default-path
option to default to empty and make that mean that the stored session CWD is
used.


# 1.81 27-Jun-2010 nicm

New option, detach-on-destroy, to set what happens to a client when the session
it is attached to is destroyed. If on (the default), it is detached; if off, it
is switched to the most recently active session.


# 1.80 26-Jun-2010 nicm

Setting the cmdlist pointer in the bind-key to NULL to prevent it being freed
after the command is executing is bogus because it may still be needed if the
same command is going to be executed again (for example if you "bind-key a
bind-key b ..."). Making a copy is hard, so instead add a reference count to
the cmd_list.

While here, also print bind-key -n and the rest of the flags properly.

Fixes problem reported by mcbride@.


# 1.79 14-May-2010 nicm

Colour+attribute options for status line alerts, from Alex Alexander.


# 1.78 04-May-2010 nicm

Put this back in with the initialisation in the right order.


# 1.77 04-May-2010 nicm

Revert last change, it appears to be broken somehow.


# 1.76 03-May-2010 nicm

Make signal handler setup/teardown two common functions instead of six,
and reset SIGCHLD after fork to fix problems with some shells. From
Romain Francois.


# 1.75 28-Apr-2010 nicm

Make the active pane border have a green foreground instead of
background by default.


# 1.74 18-Apr-2010 nicm

Catch SIGCHLD to avoid a zombie, from patrick keshishian.


Revision tags: OPENBSD_4_7_BASE
# 1.73 22-Feb-2010 nicm

Option to set the characters considered word separators in copy mode, from
Micah Cowan.


# 1.72 08-Feb-2010 nicm

Add an option to disable the smcup/rmcup alternate screen behaviour inside
tmux. From clemens fischer.


# 1.71 06-Feb-2010 nicm

Change nested check to compare server socket path rather than just assuming
that if $TMUX is set it is nested. From Micah Cowan.


# 1.70 06-Feb-2010 nicm

Clean up $TMUX parsing, from Micah Cowan, tweaked by me.


# 1.69 06-Feb-2010 nicm

Instead of bailing out on the first configuration file error, carry on,
collecting all the errors, then start with the active window in more mode
displaying them.


# 1.68 04-Feb-2010 nicm

Read the path from $TMUX if it is present and -L and -S are not given. Based on
a diff from Micah Cowan.


# 1.67 04-Feb-2010 nicm

Option to display the active pane in a different colour with the display-panes
command. From Paul Hoffman, thanks.


# 1.66 03-Jan-2010 nicm

Options to set the colour of the pane borders, with different colours for the
active pane.


# 1.65 14-Dec-2009 nicm

New server option, escape-time, to set the timeout used to detect if escapes
are alone or part of a function key or meta sequence.


# 1.64 11-Dec-2009 nicm

Use quiet variable, and add missing sentinel to options array.


# 1.63 10-Dec-2009 nicm

Add "server options" which are server-wide and not bound to a session or
window. Set and displayed with "set -s" and "show -s".

Currently the only option is "quiet" (like command-line -q, allowing it to be
set from .tmux.conf), but others will come along.


# 1.62 03-Dec-2009 nicm

Massive spaces->tabs and trailing whitespace cleanup, hopefully for the last
time now I've configured emacs to make them displayed in really annoying
colours...


# 1.61 26-Nov-2009 nicm

Remove a couple of unused arguments where possible, and add /* ARGSUSED */ to
the rest to reduce lint output.


# 1.60 19-Nov-2009 nicm

Two new options, window-status-format and window-status-current-format, which
allow the format of each window in the status line window list to be controlled
using similar # sequences as status-left/right.

This diff also moves part of the way towards UTF-8 support in window names but
it isn't quite there yet.


# 1.59 19-Nov-2009 nicm

Revert to xterm-keys off by default. It was on as an experiment to see if the
option could be removed, but it affects vi, so we have to keep the option, and
a conservative default is better.


# 1.58 18-Nov-2009 nicm

Add a per-client log of status line messages displayed while that client
exists. A new message-limit session option sets the maximum number of entries
and a command, show-messages, shows the log (bound to ~ by default).

This (and prompt history) might be better as a single global log but until
there are global options it is easier for them to be per client.


# 1.57 10-Nov-2009 nicm

There is no real standard for modifier plus function keys. Previously, tmux
output some from rxvt but in other ways did the same as xterm or other
terminals, but this is a bit inconsistent.

xterm's method is fairly sensible and we already support it (xterm-keys), so
enable it by default instead.


# 1.56 04-Nov-2009 nicm

A couple of minor cosmetic changes.


# 1.55 04-Nov-2009 nicm

Initial changes to move tmux to libevent.

This moves the client-side loops are pretty much fully over to event-based only
(tmux.c and client.c) but server-side (server.c and friends) treats libevent as
a sort of clever poll, waking up after every event to run various things.

Moving the server stuff over to bufferevents and timers and so on will come
later.


# 1.54 04-Nov-2009 nicm

Change declaration and use of malloc_options to be more standard, from Tim van
der Molen.


# 1.53 26-Oct-2009 deraadt

tabs are better; ok nicm


# 1.52 25-Oct-2009 nicm

Remove the -d flag to tmux and just use op/AX to detect default colours.

Irritatingly, although op can be used to tell if a terminal supports default
colours, it can't be used to set them because in some terminfo descriptions it
resets attributes as a side-effect (acts as sgr0) and in others it doesn't, so
it is not possible to determine reliably what the terminal state will be
afterwards. So if AX is missing and op is present, tmux just sends sgr0.

Anyone using -d for a terminal who finds they actually needed it can replace it
using terminal-overrides, but please let me know as it is probably an omission
from terminfo.


# 1.51 22-Oct-2009 nicm

Merge prepare_cmd into main as it is short and only called once.


# 1.50 21-Oct-2009 nicm

Client tidying: get rid of client_ctx struct in favour of two variables in
client.c, and move the functions in client-fn.c into other files.


# 1.49 10-Oct-2009 nicm

New option, mouse-select-pane. If on, the mouse may be used to select the
current pane.

Suggested by sthen@ and also by someone else ages ago who I have forgotten.


# 1.48 10-Oct-2009 nicm

Support for individual session idle time locking. May be enabled by turning off
the lock-server option (it is on by default). When this is off, each session
locks when it has been idle for the lock-after-time setting. When on, the
entire server locks when ALL sessions have been idle for their individual
lock-after-time settings.

This replaces one global-only option (lock-after-time) with another
(lock-server), but the default behaviour is usually preferable so there don't
seem to be many alternatives.

Diff/idea largely from Thomas Adam, tweaked by me.


# 1.47 09-Oct-2009 nicm

Add a simple synchronize-panes window option: when set, all input to any pane
that is part of the window is also sent to all other panes in the same
window. Suggested by several, most recently Tomasz Pajor.


# 1.46 23-Sep-2009 nicm

Support -c like sh(1) to execute a command, useful when tmux is a login
shell. Suggested by halex@.

This includes another protocol version increase (the last for now) so again
restart the tmux server before upgrading.


# 1.45 23-Sep-2009 nicm

Remove the internal tmux locking and instead detach each client and run the
command specified by a new option "lock-command" (by default "lock -np") in
each client.

This means each terminal has to be unlocked individually but simplifies the
code and allows the system password to be used to unlock.

Note that the set-password command is gone, so it will need to be removed from
configuration files, and the -U command line flag has been removed.

This is the third protocol version change so again it is best to stop the tmux
server before upgrading.


# 1.44 22-Sep-2009 nicm

Permit multiple prefix keys to be defined, separated by commas, for example:

set -g prefix ^a,^b

Any key in the list acts as the prefix. The send-prefix command always sends
the first key in the list.


# 1.43 18-Sep-2009 nicm

New option, set-titles-string, to allow the window title to be specified (as
for status-left/right) if set-titles is on. Also only update the title when the
status line is being redrawn.


# 1.42 04-Sep-2009 nicm

Tidy main and make it a bit easier to read.


# 1.41 02-Sep-2009 nicm

Accept -l to make it easier for people who use tmux as a login shell to use
$SHELL. Originally from martynas@, tweaked by me.


# 1.40 02-Sep-2009 nicm

When incorrect passwords are entered, behave similarly to login(1) and backoff
for a bit. Based on a diff from martynas@.


# 1.39 01-Sep-2009 nicm

When using tmux as a login shell, there is currently no way to specify a shell
to be used as a login shell inside tmux, so add a default-shell session option.
This sets the shell invoked as a login shell when the default-command option is
empty.

The default option value is whichever of $SHELL, getpwuid(getuid())'s pw_shell
or /bin/sh is valid first.

Based on a diff from martynas@, changed by me to be a session option rather
than a window option.


# 1.38 01-Sep-2009 nicm

Use "Password:" with no space for password prompts and don't display a *s for
the password, like pretty much everything else. From martynas@ with minor
tweaks by me.


# 1.37 01-Sep-2009 nicm

Sort cases same as getopt argument, from martynas.


# 1.36 31-Aug-2009 nicm

Add a new display-panes command, with two options (display-panes-colour and
display-panes-time), which displays a visual indication of the number of each
pane.


# 1.35 23-Aug-2009 nicm

Add some other obvious variables to update-environment (WINDOWID SSH_ASKPASS
SSH_AUTH_SOCK SSH_AGENT_PID SSH_CONNECTION) so they are updated in the session
environment on new/attach.


# 1.34 13-Aug-2009 nicm

Disable mode-mouse (mouse in copy/choice mode) by default as it isn't very
useful at the moment and causes confusion.


# 1.33 13-Aug-2009 nicm

Add a base-index session option to specify the first index checked when looking
for an index for a new window.


# 1.32 12-Aug-2009 nicm

When started as the shell, __progname contains a leading -, so hardcode "tmux"
for socket path and log files, and strip it when working out the shell.


# 1.31 11-Aug-2009 nicm

Switch tmux to use imsg. This is the last major change to make the
client-server protocol more resilient and make the protocol versioning work
properly. In future, the only things requiring a protocol version bump will be
changes in the message structs, and (when both client and server have this
change) mixing different versions should nicely report an error message.

As a side effect this also makes the code tidier, fixes a problem with the way
errors reported during server startup were handled, and supports fd passing
(which will be used in future).

Looked over by eric@, thanks.

Please note that mixing a client with this change with an older server or vice
versa may cause tmux to crash or hang - tmux should be completely exited before
upgrading.


# 1.30 10-Aug-2009 nicm

No arguments are the same as new-session and this requires the environment to
be sent, so set that flag too when argc == 0.


# 1.29 08-Aug-2009 nicm

Infrastructure and commands to manage the environment for processes started
within tmux.

There is a global environment, copied from the external environment when the
server is started and each sesssion has an (initially empty) session
environment which overrides it.

New commands set-environment and show-environment manipulate or display the
environments.

A new session option, update-environment, is a space-separated list of
variables which are updated from the external environment into the session
environment every time a new session is created - the default is DISPLAY.


# 1.28 08-Aug-2009 nicm

Options to set the colours and attributes for status-left/-right. From Thomas
Adam, thanks.


# 1.27 05-Aug-2009 nicm

If colours are not supported by the terminal, try to emulate a coloured
background by setting or clearing the reverse attribute.

This makes a few applications which don't use the reverse attribute themselves
a little happier, and allows the status, message and mode options to have
default attributes and fg/bg options that work as expected when set as reverse.


# 1.26 04-Aug-2009 nicm

Check for "UTF8" as well as "UTF-8" in LANG etc as it seems this may also
appear.


# 1.25 03-Aug-2009 nicm

Add a terminal-overrides session option allowing individual terminfo(5) entries
to be overridden. The 88col/256col checks are now moved into the default
setting and out of the code.

Also remove a couple of old workarounds for xterm and rxvt which are no longer
necessary (tmux can emulate them if missing).


# 1.24 30-Jul-2009 nicm

Add a mode-mouse option to prevent tmux taking over the mouse in choice or copy
modes.


# 1.23 29-Jul-2009 nicm

Rename struct hdrtype to msgtype which is a better name and can be used even
when struct hdr disappears.


# 1.22 29-Jul-2009 nicm

Taking account of the "s, 22 not 24 is the maximum length of #T in status-right
to prevent the date being cut off.


# 1.21 26-Jul-2009 nicm

Make all messages sent between the client and server fixed size.

This is the first of two changes to make the protocol more resilient and less
sensitive to other changes in the code, particularly with commands. The client
now packs argv into a buffer and sends it to the server for parsing, rather
than doing it itself and sending the parsed command data.

As a side-effect this also removes a lot of now-unused command marshalling
code.

Mixing a server without this change and a client with or vice versa will cause
tmux to hang or crash, please ensure that tmux is entirely killed before
upgrading.


# 1.20 22-Jul-2009 nicm

Pass a set of flags into client_init rather than just a start_server
variable. Only one flag now but more to come later.


# 1.19 20-Jul-2009 nicm

Display the number of failed password attempts (if any) when the server is
locked. From Tom Doherty.


# 1.18 20-Jul-2009 nicm

Add a status-justify option to allow the window list in the status line to be
positioned at the left, centre, or right.


# 1.17 20-Jul-2009 nicm

New options, window-status-current-{fg,bg,attr}, to set the fg, bg and
attributes with which the current window is shown in the status line. From
Johan Friis, thanks.


# 1.16 18-Jul-2009 nicm

Add three new session options: visual-activity, visual-bell, visual-content. If
these are enabled (and the monitor-activity, bell-actio and monitor-content
options are configurated appropriately), when activity, a bell, or content is
detected, a message is shown.

Also tidy up the bell/activity/content code in server.c slightly and fix a
couple of errors.


# 1.15 17-Jul-2009 nicm

If -u is specified or UTF-8 is otherwise detected when the server is started,
enable the utf8 and status-utf8 optons. While here, note in the man page that
the server is started with the first session and exits when none remain.


# 1.14 10-Jul-2009 nicm

Add a default-terminal option to set the starting value of $TERM in new
windows.

This is "screen" by default and must be either that or something closely
related. This does makes it easier to customise it if necessary.


# 1.13 08-Jul-2009 nicm

Just appending -l to $SHELL to create a login shell is wrong: -l is not POSIX,
and some people may use shells which do not support it. Instead, make an empty
default-command option mean a login shell, and fork it with a - in argv[0]
which is the method used by login(1).

Also fix the automatic-rename code to handle this correctly and to strip a
leading - if present.


# 1.12 07-Jul-2009 nicm

Rename the global options variables to be shorter and to make session options
clear. No functional change, getting this out of the way to make later options
changes easier.


Revision tags: OPENBSD_4_6_BASE
# 1.11 25-Jun-2009 nicm

If getcwd() fails, use the user's home directory, or /, instead of failing with
an error.


# 1.10 25-Jun-2009 nicm

Remove error about using -L and -S together which was never displayed as
logging wasn't yet enabled, was unnecessary, and contradicted the man page
which says using -S will cause -L to be ignored.


# 1.9 23-Jun-2009 nicm

LC_ALL overrides LC_CTYPE and LANG. Comment was correct but the code
wrong. Pointed out by Hannah Schroeter, thanks.


# 1.8 05-Jun-2009 nicm

Check the first of LC_CTYPE, LC_ALL and LANG, rather than just the last, when
trying to decide about UTF-8, and use strcasestr. Reported by Geert Hendrickx.


# 1.7 04-Jun-2009 nicm

Zero the password given to -U in the client as well.


# 1.6 03-Jun-2009 nicm

Do not set the window title by default (make set-titles option default to off),
wiping over the title is rude and annoying. Agreed by several.


# 1.5 03-Jun-2009 nicm

New session option, status-utf8, to control the interpretation of top-bit-set
characters in status-left and status-right (if on, they are treated as UTF-8;
otherwise passed through).


# 1.4 02-Jun-2009 sobrado

remove unused flag; while here, make usage's output fit on 80-column displays.


# 1.3 02-Jun-2009 pyr

spawn login shells by default, adapt manpage bits as well.
ok nicm@


# 1.2 02-Jun-2009 ray

Don't leak memory if multiple -f flags are given.

OK nicm@


# 1.1 01-Jun-2009 nicm

Import tmux, a terminal multiplexor allowing (among other things) a single
terminal to be switched between several different windows and programs
displayed on one terminal be detached from one terminal and moved to another.

ok deraadt pirofti