History log of /openbsd-current/usr.bin/tmux/cmd-split-window.c
Revision (<<< Hide revision tags) (Show revision tags >>>) Date Author Comments
Revision tags: OPENBSD_7_5_BASE
# 1.114 06-Mar-2024 nicm

Check for the right flag to fix split-window -p, from Bryan Childs.


Revision tags: OPENBSD_7_2_BASE OPENBSD_7_3_BASE OPENBSD_7_4_BASE
# 1.113 07-Jun-2022 nicm

Expand arguments to some commands where it makes sense, GitHub issue
3204 from Anindya Mukherjee.


Revision tags: OPENBSD_7_1_BASE
# 1.112 08-Mar-2022 nicm

With -f use percentages of window size not pane size, GitHub issue 2866.


# 1.111 07-Oct-2021 nicm

Handle splitw -I correctly when used from an attached client, GitHub
issue 2917.


Revision tags: OPENBSD_7_0_BASE
# 1.110 27-Aug-2021 nicm

Replace %% in command lists (by copying them) for template arguments ,
this means they can be used with {} as well. Also make argument
processing from an existing vector preserve commands. GitHub issue 2858.


# 1.109 21-Aug-2021 nicm

Rename a member to match what it will be in future.


# 1.108 21-Aug-2021 nicm

Add args parsing callback for some future work, currently unused.


# 1.107 20-Aug-2021 nicm

Hide struct args behind a couple of accessor functions.


# 1.106 20-Aug-2021 nicm

Expose args_value struct (will be needed soon) and add some missing frees.


Revision tags: OPENBSD_6_9_BASE
# 1.105 11-Mar-2021 nicm

Add split-window -Z to start the pane zoomed, GitHub issue 2591.


Revision tags: OPENBSD_6_8_BASE
# 1.104 16-May-2020 nicm

Add a client flag 'active-pane' which stores the active pane in the
client and allows it to be changed independently from the real active
pane stored in the window. This is can be used with session groups which
allow an independent current window (although it would be nice to have a
flag for this too and remove session groups). The client active pane is
only really useful interactively, many things (hooks, window-style,
zooming) still use the window active pane.


Revision tags: OPENBSD_6_7_BASE
# 1.103 13-Apr-2020 nicm

Make client -c and -t handling common in cmd-queue.c and try to be
clearer about whether the client is the target client (must have a
session) or not.


# 1.102 13-Apr-2020 nicm

Move cmdq_state into cmd-queue.c.


# 1.101 13-Apr-2020 nicm

Rename cmdq_shared to cmdq_state which will better reflect what it is
(going to be) used for.


# 1.100 13-Apr-2020 nicm

Also move cmdq_item and cmdq_list into cmd-queue.c (this is to make its
use more clearly defined and preparation for some future work).


# 1.99 13-Apr-2020 nicm

Make struct cmd local to cmd.c and move it out of tmux.h.


# 1.98 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.97 16-Mar-2020 nicm

Do not attempt to close a NULL pane when failing to create a new one.


# 1.96 15-Oct-2019 nicm

Add support for percentage sizes for resize-pane ("-x 10%"). Also change
split-window and join-pane -l to accept similar percentages and
deprecate -p. From Anindya Mukherjee.


Revision tags: OPENBSD_6_6_BASE
# 1.95 03-May-2019 nicm

Allow panes to be empty (no command), output can be piped to them with
split-window or display-message -I.


# 1.94 28-Apr-2019 nicm

Support multiple occurances of the same argument. Use this for a new
flag -e to new-window, split-window, respawn-window, respawn-pane to
pass environment variables into the newly created process. From Steffen
Christgau in GitHub issue 1697.


# 1.93 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).


# 1.92 17-Apr-2019 nicm

Break new window and pane creation common code from various commands and
window.c into a separate file spawn.c.


Revision tags: OPENBSD_6_5_BASE
# 1.91 18-Oct-2018 nicm

Support for windows larger than visible on the attached client. This has
been a limitation for a long time.

There are two new options, window-size and default-size, and a new
command, resize-window. The force-width and force-height options and the
session_width and session_height formats have been removed.

The new window-size option tells tmux how to work out the size of
windows: largest means it picks the size of the largest session,
smallest the smallest session (similar to the old behaviour) and manual
means that it does not automatically resize windows. The default is
currently largest but this may change. aggressive-resize modifies the
choice of session for largest and smallest as it did before.

If a window is in a session attached to a client that is too small, only
part of the window is shown. tmux attempts to keep the cursor visible,
so the part of the window displayed is changed as the cursor moves (with
a small delay, to try and avoid excess redrawing when applications
redraw status lines or similar that are not currently visible). The
offset of the visible portion of the window is shown in status-right.

Drawing windows which are larger than the client is not as efficient as
those which fit, particularly when the cursor moves, so it is
recommended to avoid using this on slow machines or networks (set
window-size to smallest or manual).

The resize-window command can be used to resize a window manually. If it
is used, the window-size option is automatically set to manual for the
window (undo this with "setw -u window-size"). resize-window works in a
similar way to resize-pane (-U -D -L -R -x -y flags) but also has -a and
-A flags. -a sets the window to the size of the smallest client (what it
would be if window-size was smallest) and -A the largest.

For the same behaviour as force-width or force-height, use resize-window
-x or -y, and "setw -u window-size" to revert to automatic sizing..

If the global window-size option is set to manual, the default-size
option is used for new windows. If -x or -y is used with new-session,
that sets the default-size option for the new session.

The maximum size of a window is 10000x10000. But expect applications to
complain and much higher memory use if making a window excessively
big. The minimum size is the size required for the current layout
including borders.

The refresh-client command can be used to pan around a window, -U -D -L
-R moves up, down, left or right and -c returns to automatic cursor
tracking. The position is reset when the current window is changed.


Revision tags: OPENBSD_6_4_BASE
# 1.90 24-May-2018 nicm

Make server_client_get_cwd used (almost) everywhere we need to work out
the cwd, and do not fall back to "." as it is pretty useless. GitHub
issue 1331.


Revision tags: OPENBSD_6_3_BASE
# 1.89 16-Mar-2018 nicm

Insert full size panes at the right position, from KOIE Hidetaka in
GitHub issue 1284.


# 1.88 01-Mar-2018 nicm

Expand formats in window and session names.


Revision tags: OPENBSD_6_2_BASE
# 1.87 30-Aug-2017 nicm

Pass flags into cmd_find_from_* to fix prefer-unattached, reported by
Thomas Sattler.


# 1.86 21-Jul-2017 nicm

Add -c for respawn-pane and respawn-window, from J Raynor.


# 1.85 30-May-2017 nicm

Rewrite of choose mode, both to simplify and tidy the code and to add
some modern features.

Now the common code is in mode-tree.c, which provides an API used by the
three modes now separated into window-{buffer,client,tree}.c. Buffer
mode shows buffers, client mode clients and tree mode a tree of
sessions, windows and panes.

Each mode has a common set of key bindings plus a few that are specific
to the mode. Other changes are:

- each mode has a preview pane: for buffers this is the buffer content
(very useful), for others it is a preview of the pane;

- items may be sorted in different ways ('O' key);

- multiple items may be tagged and an operation applied to all of them
(for example, to delete multiple buffers at once);

- in tree mode a command may be run on the selected item (session,
window, pane) or on tagged items (key ':');

- displayed items may be filtered in tree mode by using a format (this
is used to implement find-window) (key 'f');

- the custom format (-F) for the display is no longer available;

- shortcut keys change from 0-9, a-z, A-Z which was always a bit weird
with keys used for other uses to 0-9, M-a to M-z.

Now that the code is simpler, other improvements will come later.

Primary key bindings for each mode are documented under the commands in
the man page (choose-buffer, choose-client, choose-tree).

Parts written by Thomas Adam.


# 1.84 25-Apr-2017 nicm

Do not update TERM into config file parsing has finished.


# 1.83 22-Apr-2017 nicm

Get rid of the extra layer of flags and cmd_prepare() and just store the
CMD_FIND_* flags in the cmd_entry and call it for the command. Commands
with special requirements call it themselves and update the target for
hooks to use.


# 1.82 22-Apr-2017 nicm

Mouse bindings and hooks set up an initial current state when running a
command. This is used for the session, window and pane for all commands
in the command sequence if there is no -t or -s.

However, using it for all commands in the command sequence means that if
the active pane or current session is changed, subsequent commands still
use the previous state. So make commands which explicitly change the
current state (such as neww and selectp) update it themselves for later
commands. Commands which may invalidate the state (like killp) are
already OK because an invalid state will be ignored.

Also fill in the current state for all key bindings rather than just the
mouse, so that any omissions are easier to spot.


# 1.81 21-Apr-2017 nicm

Add cmd_find_from_winlink_pane and use it in a couple of places, and
make functions that can't fail void.


Revision tags: OPENBSD_6_1_BASE
# 1.80 09-Mar-2017 nicm

Move server_fill_environ into environ.c and move some other common code
into it.


# 1.79 08-Mar-2017 nicm

Add a helper function for the most common format_create/defaults/expand
pattern.


# 1.78 27-Feb-2017 nicm

If splitw -b is used, insert the new pane before the current one in the
pane list. This means the numbering is in order (for example for
display-panes) and fixes a problem with redrawing the active pane
borders.


# 1.77 03-Feb-2017 nicm

Add a window or pane id "tag" to each format tree and use it to separate
jobs, this means that if the same job is used for different windows or
panes (for example in pane-border-format), it will be run separately for
each pane.


# 1.76 16-Oct-2016 nicm

Use the notify name string instead of going via an enum and change
existing hooks to use notifys instead.


# 1.75 16-Oct-2016 nicm

Mass rename struct cmd_q to struct cmdq_item and related.


# 1.74 16-Oct-2016 nicm

Rewrite command queue handling. Each client still has a command queue,
but there is also now a global command queue. Instead of command queues
being dispatched on demand from wherever the command happens to be
added, they are now all dispatched from the top level server
loop. Command queues may now also include callbacks as well as commands,
and items may be inserted after the current command as well as at the end.

This all makes command queues significantly more predictable and easier
to use, and avoids the complex multiple nested command queues used by
source-file, if-shell and friends.

A mass rename of struct cmdq to a better name (cmdq_item probably) is
coming.


# 1.73 13-Oct-2016 nicm

Trying to do hooks generically is way too complicated and unreliable and
confusing, particularly trying to automatically figure out what target
hooks should be using. So simplify it:

- drop before hooks entirely, they don't seem to be very useful;

- commands with special requirements now fire their own after hook (for
example, if they change session or window, or if they have -t and -s
and need to choose which one the hook uses as current target);

- commands with no special requirements can have the CMD_AFTERHOOK flag
added and they will use the -t state.

At the moment new-session, new-window, split-window fire their own hook,
and display-message uses the flag. The remaining commands still need to
be looked at.


# 1.72 13-Oct-2016 nicm

Some improvements and bug fixes for hooks:

- Prepare the state again before the "after" hooks are run, because the
command may have killed or moved windows.

- Use the hooks list from the newly prepared target, not the old hooks
list (only matters for new-session really).

- Correctly detect an invalid current state and ignore it in
cmd_find_target ("killw; swapw").

- Change neww, new, killp, killw, splitw, swapp, swapw to update the
current state (used if no explicit target is given) to something more
useful after they have finished. For example, neww changes it to the
newly created window.

Hooks are still relatively new and primitive so there are likely to be
more changes to come.

Parts based on bug reports from Uwe Werler and Iblis Lin.


# 1.71 10-Oct-2016 nicm

Add static in cmd-* and fix a few other nits.


# 1.70 04-Sep-2016 nicm

Add support for performing a full width split (with splitw -f), rather
than splitting the current cell. From Stephen Kent.


Revision tags: OPENBSD_6_0_BASE
# 1.69 06-Jun-2016 nicm

Insert new panes after the pane being split in the list rather than
always after the active pane. This is more sensible when doing it with
commands rather than keys.


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

I no longer use my SourceForge address so replace it.


# 1.67 14-Dec-2015 nicm

Instead of combined flags for -c, -s, -t, split into different sets
using an enum and simplify the parsing code.


# 1.66 13-Dec-2015 nicm

Use member names in cmd_entry definitions so I stop getting confused
about the order.


# 1.65 13-Dec-2015 nicm

Instead of every command resolving the target (-t or -s) itself, prepare
the state (client, session, winlink, pane) for it it before entering the
command. Each command provides some flags that tell the prepare step
what it is expecting.

This is a requirement for having hooks on commands (for example, if you
hook "select-window -t1:2", the hook command should to operate on window
1:2 not whatever it thinks is the current window), and should allow some
other target improvements.

The old cmd_find_* functions remain for the moment but that layer will
be dropped later.

Joint work with Thomas Adam.


# 1.64 11-Dec-2015 nicm

Add cmdq as an argument to format_create and add a format for the
command name (will also be used for more later).


# 1.63 08-Dec-2015 nicm

Remove format_create_flags and just pass flags to format_create.


# 1.62 31-Oct-2015 nicm

Fall back silently to ~ or / rather than checking -c with access(), this
was the old behaviour.


# 1.61 31-Oct-2015 nicm

Because pledge(2) does not allow us to pass directory file descriptors
around, we can't use file descriptors for the working directory because
we will be unable to pass it to a privileged process to tell it where to
read or write files or spawn children. So move tmux back to using
strings for the current working directory. We try to check it exists
with access() when it is set but ultimately fall back to ~ if it fails
at time of use (or / if that fails too).


# 1.60 28-Oct-2015 nicm

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


# 1.59 27-Oct-2015 nicm

Move struct options into options.c.


# 1.58 23-Oct-2015 nicm

Remove some unnecessary checks before free().


Revision tags: OPENBSD_5_8_BASE
# 1.57 26-Apr-2015 nicm

Remove panes from layout if spawning them fails, reported by Anthony J
Bentley.


Revision tags: OPENBSD_5_7_BASE
# 1.56 05-Feb-2015 nicm

Remove a couple of now-unused variables.


# 1.55 05-Feb-2015 nicm

Wrap all the individual format_* calls in a single format_defaults
functions.


# 1.54 12-Nov-2014 nicm

Add -b to splitw like joinw, from Felix Rosencrantz.


# 1.53 20-Oct-2014 nicm

Move template defines back into .c files.


# 1.52 20-Oct-2014 nicm

Instead of setting up the default keys by building the key struct
directly with a helper function in the cmd_entry, include a table of
bind-key commands and pass them through the command parser and a
temporary cmd_q.

As well as being smaller, this will allow default bindings to be command
sequences which will probably be needed soon.


# 1.51 01-Sep-2014 nicm

Various minor style and spacing nits.


Revision tags: OPENBSD_5_6_BASE
# 1.50 13-May-2014 nicm

If multiple arguments are given to new-session, new-window,
split-window, respawn-window or respawn-pane, pass them directly to
execvp() to help avoid quoting problems. One argument still goes to "sh
-c" like before. Requested by many over the years. Patch from J Raynor.


# 1.49 17-Apr-2014 nicm

Set PATH explicitly, either from client or session
environment. Previously it came from the session environment. From J
Raynor.


Revision tags: OPENBSD_5_5_BASE
# 1.48 22-Nov-2013 nicm

Handle empty current directory more gracefully.


# 1.47 10-Oct-2013 nicm

Don't boke when figuring out working directory from configuration file.


# 1.46 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.45 10-Oct-2013 nicm

Support -c for new-session, based on code from J Raynor.


# 1.44 10-Oct-2013 nicm

Restore missing key binding for %, from Chris Johnsen.


# 1.43 10-Oct-2013 nicm

Remove the barely-used and unnecessary command check() function.


Revision tags: OPENBSD_5_4_BASE
# 1.42 25-Mar-2013 nicm

Revert the command-prefix change which breaks sequences of commands.


# 1.41 24-Mar-2013 nicm

Add resize-pane -Z to temporary zoom the active pane to occupy the full
window or unzoom (restored to the normal layout) if it already zoomed,
bound to C-b z by default. The pane is unzoomed on pretty much any
excuse whatsoever.

We considered making this a new layout but the requirements are quite
different from layouts so decided it is better as a special case. Each
current layout cell is saved, a temporary one-cell layout generated and
all except the active pane set to NULL.

Prompted by suggestions and scripts from several. Thanks to Aaron Jensen
and Thiago Padilha for testing an earlier version.


# 1.40 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.


# 1.39 24-Mar-2013 nicm

Fix error reporting for client commands by adding a flag to
cmd_find_client to tell it whether or not to show errors, sometimes it's
needed and sometimes not.


# 1.38 24-Mar-2013 nicm

Add option command-prefix which is automatically prepended to any
command (apart from a naked default-shell). The default is "exec ".


Revision tags: OPENBSD_5_3_BASE
# 1.37 09-Dec-2012 nicm

Use the CMD_*_USAGE defines consistently, from Thomas Adam.


# 1.36 14-Aug-2012 nicm

Use a separate define for each default format template and strip clutter
from the choose-tree defaults.


Revision tags: OPENBSD_5_2_BASE
# 1.35 11-Jul-2012 nicm

Make command exec functions return an enum rather than -1/0/1 values and
add a new value to mean "leave client running but don't attach" to fix
problems with using some commands in a command sequence. Most of the
work by Thomas Adam, problem reported by "jspenguin" on SF bug 3535531.


# 1.34 10-Jul-2012 nicm

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


# 1.33 22-May-2012 nicm

Switch all of the various choose- and list- commands over to the format
infrastructure, from Thomas Adam.


# 1.32 17-Mar-2012 nicm

Add notify hooks for various events, the functions are currently empty
stubs but will be filled in for control mode later. From George Nachman.


# 1.31 04-Mar-2012 nicm

free -> xfree.


# 1.30 04-Mar-2012 nicm

Add -F format to new-window and split-window to use with the -P flag,
from George Nachman.


# 1.29 03-Mar-2012 nicm

Add move-pane command (like join-pane but allows the same window). Also
-b flag to join-pane and move-pane to place the pane to the left or
above. From George Nachman.


Revision tags: OPENBSD_5_1_BASE
# 1.28 31-Jan-2012 nicm

Provide defined ways to set the various default-path possibilities: ~
for home directory, . for server start directory, - for session start
directory and empty for the pane's working directory (the default). All
can also be used as part of a relative path (eg -/foo). Also provide -c
flags to neww and splitw to override default-path setting.

Based on a diff from sthen. ok sthen


# 1.27 20-Jan-2012 nicm

Add some const and fix a warning.


# 1.26 09-Dec-2011 nicm

Change the way the working directory for new processes is discovered. If
default-path isn't empty, it is used. Otherwise:

1) If tmux neww is run from the command line, the working directory of the
client is used.

2) Otherwise sysctl KERN_PROC_CWD is used to retrieve the current
working directory of the process in the active pane.

3) If that fails, the directory where the session was created is used.

Support code by Romain Francois, OpenBSD specific bits by me.

Note this requires a recent userland and kernel with KERN_PROC_CWD.


# 1.25 15-Nov-2011 nicm

Make window_pane_index work the same as window_index, from Ben Boeckel.


# 1.24 30-Aug-2011 nicm

Plug memory leak, from Tiago Cunha.


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE
# 1.23 10-Feb-2011 nicm

Size on split-window is -l not -s. Doh.


# 1.22 04-Jan-2011 nicm

Clean up and simplify tmux command argument parsing.

Originally, tmux commands were parsed in the client process into a
struct with the command data which was then serialised and sent to the
server to be executed. The parsing was later moved into the server (an
argv was sent from the client), but the parse step and intermediate
struct was kept.

This change removes that struct and the separate parse step. Argument
parsing and printing is now common to all commands (in arguments.c) with
each command left with just an optional check function (to validate the
arguments at parse time), the exec function and a function to set up any
key bindings (renamed from the old init function).

This is overall more simple and consistent.

There should be no changes to any commands behaviour or syntax although
as this touches every command please watch for any unexpected changes.


# 1.21 01-Jan-2011 nicm

Add a -P option to new-window and split-window to print the new window
or pane index in target form (useful to pass it into other commands).


Revision tags: OPENBSD_4_8_BASE
# 1.20 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.


Revision tags: OPENBSD_4_7_BASE
# 1.19 07-Jan-2010 nicm

New command, join-pane, to split and move an existing pane into the space (like
splitw then movep, or the reverse of breakp).


# 1.18 07-Jan-2010 nicm

Use the specified pane for size calculations. Doh.


# 1.17 07-Jan-2010 nicm

Change split-window to accept a pane target (it should be split-pane but
renaming the command would be annoying).


# 1.16 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.15 20-Nov-2009 nicm

When -h and -p are given to split-window, calculate the percentage size using
the width instead of the height.


# 1.14 13-Nov-2009 nicm

Get rid of the ugly CMD_CHFLAG macro and use a const string (eg "dDU") in the
command entry structs and a couple of functions to check/set the flags.


# 1.13 21-Sep-2009 nicm

Use KEYC_NONE constant instead of 0 on init.


# 1.12 16-Sep-2009 nicm

Rather than constructing an entire termios struct from ttydefaults.h, just let
forkpty do it and then alter the bits that should be changed after fork. A
little neater and more portable.


# 1.11 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.10 25-Aug-2009 nicm

Print -l and -p when showing command, pointed out by Tiago Cunha.


# 1.9 13-Aug-2009 nicm

When creating a new session from the command-line where there is an external
terminal, copy the termios(4) special characters and use them for new windows
created in the new session. Suggested by Theo.


# 1.8 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.7 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.6 22-Jul-2009 nicm

window_add_pane cannot fail, so remove the unused cause argument and don't
bother to check for a NULL return.


# 1.5 19-Jul-2009 nicm

Improved layout code.

Each window now has a tree of layout cells associated with it. In this tree,
each node is either a horizontal or vertical cell containing a list of other
cells running from left-to-right or top-to-bottom, or a leaf cell which is
associated with a pane.

The major functional changes are:

- panes may now be split arbitrarily both horizontally (splitw -h, C-b %) and
vertically (splitw -v, C-b ");
- panes may be resized both horizontally and vertically (resizep -L/-R/-U/-D,
bound to C-b left/right/up/down and C-b M-left/right/up/down);
- layouts are now applied and then may be modified by resizing or splitting
panes, rather than being fixed and reapplied when the window is resized or
panes are added;
- manual-vertical layout is no longer necessary, and active-only layout is gone
(but may return in future);
- the main-pane layouts now reduce the size of the main pane to fit all panes
if possible.

Thanks to all who tested.


# 1.4 13-Jul-2009 nicm

Having fixed flags for single-character getopt options is a bit hard to
maintain and is only going to get worse as more are used. So instead, add a new
uint64_t member to cmd_entry which is a bitmask of upper and lowercase options
accepted by the command.

This means new single character options can be used without the need to add it
explicitly to the list.


# 1.3 07-Jul-2009 nicm

The fix for default-path (use target session options instead of global options)
is required here as well, doh.


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

lines variable can be -1 (to be ignored), so should be signed. Found by lint.


# 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.113 07-Jun-2022 nicm

Expand arguments to some commands where it makes sense, GitHub issue
3204 from Anindya Mukherjee.


Revision tags: OPENBSD_7_1_BASE
# 1.112 08-Mar-2022 nicm

With -f use percentages of window size not pane size, GitHub issue 2866.


# 1.111 07-Oct-2021 nicm

Handle splitw -I correctly when used from an attached client, GitHub
issue 2917.


Revision tags: OPENBSD_7_0_BASE
# 1.110 27-Aug-2021 nicm

Replace %% in command lists (by copying them) for template arguments ,
this means they can be used with {} as well. Also make argument
processing from an existing vector preserve commands. GitHub issue 2858.


# 1.109 21-Aug-2021 nicm

Rename a member to match what it will be in future.


# 1.108 21-Aug-2021 nicm

Add args parsing callback for some future work, currently unused.


# 1.107 20-Aug-2021 nicm

Hide struct args behind a couple of accessor functions.


# 1.106 20-Aug-2021 nicm

Expose args_value struct (will be needed soon) and add some missing frees.


Revision tags: OPENBSD_6_9_BASE
# 1.105 11-Mar-2021 nicm

Add split-window -Z to start the pane zoomed, GitHub issue 2591.


Revision tags: OPENBSD_6_8_BASE
# 1.104 16-May-2020 nicm

Add a client flag 'active-pane' which stores the active pane in the
client and allows it to be changed independently from the real active
pane stored in the window. This is can be used with session groups which
allow an independent current window (although it would be nice to have a
flag for this too and remove session groups). The client active pane is
only really useful interactively, many things (hooks, window-style,
zooming) still use the window active pane.


Revision tags: OPENBSD_6_7_BASE
# 1.103 13-Apr-2020 nicm

Make client -c and -t handling common in cmd-queue.c and try to be
clearer about whether the client is the target client (must have a
session) or not.


# 1.102 13-Apr-2020 nicm

Move cmdq_state into cmd-queue.c.


# 1.101 13-Apr-2020 nicm

Rename cmdq_shared to cmdq_state which will better reflect what it is
(going to be) used for.


# 1.100 13-Apr-2020 nicm

Also move cmdq_item and cmdq_list into cmd-queue.c (this is to make its
use more clearly defined and preparation for some future work).


# 1.99 13-Apr-2020 nicm

Make struct cmd local to cmd.c and move it out of tmux.h.


# 1.98 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.97 16-Mar-2020 nicm

Do not attempt to close a NULL pane when failing to create a new one.


# 1.96 15-Oct-2019 nicm

Add support for percentage sizes for resize-pane ("-x 10%"). Also change
split-window and join-pane -l to accept similar percentages and
deprecate -p. From Anindya Mukherjee.


Revision tags: OPENBSD_6_6_BASE
# 1.95 03-May-2019 nicm

Allow panes to be empty (no command), output can be piped to them with
split-window or display-message -I.


# 1.94 28-Apr-2019 nicm

Support multiple occurances of the same argument. Use this for a new
flag -e to new-window, split-window, respawn-window, respawn-pane to
pass environment variables into the newly created process. From Steffen
Christgau in GitHub issue 1697.


# 1.93 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).


# 1.92 17-Apr-2019 nicm

Break new window and pane creation common code from various commands and
window.c into a separate file spawn.c.


Revision tags: OPENBSD_6_5_BASE
# 1.91 18-Oct-2018 nicm

Support for windows larger than visible on the attached client. This has
been a limitation for a long time.

There are two new options, window-size and default-size, and a new
command, resize-window. The force-width and force-height options and the
session_width and session_height formats have been removed.

The new window-size option tells tmux how to work out the size of
windows: largest means it picks the size of the largest session,
smallest the smallest session (similar to the old behaviour) and manual
means that it does not automatically resize windows. The default is
currently largest but this may change. aggressive-resize modifies the
choice of session for largest and smallest as it did before.

If a window is in a session attached to a client that is too small, only
part of the window is shown. tmux attempts to keep the cursor visible,
so the part of the window displayed is changed as the cursor moves (with
a small delay, to try and avoid excess redrawing when applications
redraw status lines or similar that are not currently visible). The
offset of the visible portion of the window is shown in status-right.

Drawing windows which are larger than the client is not as efficient as
those which fit, particularly when the cursor moves, so it is
recommended to avoid using this on slow machines or networks (set
window-size to smallest or manual).

The resize-window command can be used to resize a window manually. If it
is used, the window-size option is automatically set to manual for the
window (undo this with "setw -u window-size"). resize-window works in a
similar way to resize-pane (-U -D -L -R -x -y flags) but also has -a and
-A flags. -a sets the window to the size of the smallest client (what it
would be if window-size was smallest) and -A the largest.

For the same behaviour as force-width or force-height, use resize-window
-x or -y, and "setw -u window-size" to revert to automatic sizing..

If the global window-size option is set to manual, the default-size
option is used for new windows. If -x or -y is used with new-session,
that sets the default-size option for the new session.

The maximum size of a window is 10000x10000. But expect applications to
complain and much higher memory use if making a window excessively
big. The minimum size is the size required for the current layout
including borders.

The refresh-client command can be used to pan around a window, -U -D -L
-R moves up, down, left or right and -c returns to automatic cursor
tracking. The position is reset when the current window is changed.


Revision tags: OPENBSD_6_4_BASE
# 1.90 24-May-2018 nicm

Make server_client_get_cwd used (almost) everywhere we need to work out
the cwd, and do not fall back to "." as it is pretty useless. GitHub
issue 1331.


Revision tags: OPENBSD_6_3_BASE
# 1.89 16-Mar-2018 nicm

Insert full size panes at the right position, from KOIE Hidetaka in
GitHub issue 1284.


# 1.88 01-Mar-2018 nicm

Expand formats in window and session names.


Revision tags: OPENBSD_6_2_BASE
# 1.87 30-Aug-2017 nicm

Pass flags into cmd_find_from_* to fix prefer-unattached, reported by
Thomas Sattler.


# 1.86 21-Jul-2017 nicm

Add -c for respawn-pane and respawn-window, from J Raynor.


# 1.85 30-May-2017 nicm

Rewrite of choose mode, both to simplify and tidy the code and to add
some modern features.

Now the common code is in mode-tree.c, which provides an API used by the
three modes now separated into window-{buffer,client,tree}.c. Buffer
mode shows buffers, client mode clients and tree mode a tree of
sessions, windows and panes.

Each mode has a common set of key bindings plus a few that are specific
to the mode. Other changes are:

- each mode has a preview pane: for buffers this is the buffer content
(very useful), for others it is a preview of the pane;

- items may be sorted in different ways ('O' key);

- multiple items may be tagged and an operation applied to all of them
(for example, to delete multiple buffers at once);

- in tree mode a command may be run on the selected item (session,
window, pane) or on tagged items (key ':');

- displayed items may be filtered in tree mode by using a format (this
is used to implement find-window) (key 'f');

- the custom format (-F) for the display is no longer available;

- shortcut keys change from 0-9, a-z, A-Z which was always a bit weird
with keys used for other uses to 0-9, M-a to M-z.

Now that the code is simpler, other improvements will come later.

Primary key bindings for each mode are documented under the commands in
the man page (choose-buffer, choose-client, choose-tree).

Parts written by Thomas Adam.


# 1.84 25-Apr-2017 nicm

Do not update TERM into config file parsing has finished.


# 1.83 22-Apr-2017 nicm

Get rid of the extra layer of flags and cmd_prepare() and just store the
CMD_FIND_* flags in the cmd_entry and call it for the command. Commands
with special requirements call it themselves and update the target for
hooks to use.


# 1.82 22-Apr-2017 nicm

Mouse bindings and hooks set up an initial current state when running a
command. This is used for the session, window and pane for all commands
in the command sequence if there is no -t or -s.

However, using it for all commands in the command sequence means that if
the active pane or current session is changed, subsequent commands still
use the previous state. So make commands which explicitly change the
current state (such as neww and selectp) update it themselves for later
commands. Commands which may invalidate the state (like killp) are
already OK because an invalid state will be ignored.

Also fill in the current state for all key bindings rather than just the
mouse, so that any omissions are easier to spot.


# 1.81 21-Apr-2017 nicm

Add cmd_find_from_winlink_pane and use it in a couple of places, and
make functions that can't fail void.


Revision tags: OPENBSD_6_1_BASE
# 1.80 09-Mar-2017 nicm

Move server_fill_environ into environ.c and move some other common code
into it.


# 1.79 08-Mar-2017 nicm

Add a helper function for the most common format_create/defaults/expand
pattern.


# 1.78 27-Feb-2017 nicm

If splitw -b is used, insert the new pane before the current one in the
pane list. This means the numbering is in order (for example for
display-panes) and fixes a problem with redrawing the active pane
borders.


# 1.77 03-Feb-2017 nicm

Add a window or pane id "tag" to each format tree and use it to separate
jobs, this means that if the same job is used for different windows or
panes (for example in pane-border-format), it will be run separately for
each pane.


# 1.76 16-Oct-2016 nicm

Use the notify name string instead of going via an enum and change
existing hooks to use notifys instead.


# 1.75 16-Oct-2016 nicm

Mass rename struct cmd_q to struct cmdq_item and related.


# 1.74 16-Oct-2016 nicm

Rewrite command queue handling. Each client still has a command queue,
but there is also now a global command queue. Instead of command queues
being dispatched on demand from wherever the command happens to be
added, they are now all dispatched from the top level server
loop. Command queues may now also include callbacks as well as commands,
and items may be inserted after the current command as well as at the end.

This all makes command queues significantly more predictable and easier
to use, and avoids the complex multiple nested command queues used by
source-file, if-shell and friends.

A mass rename of struct cmdq to a better name (cmdq_item probably) is
coming.


# 1.73 13-Oct-2016 nicm

Trying to do hooks generically is way too complicated and unreliable and
confusing, particularly trying to automatically figure out what target
hooks should be using. So simplify it:

- drop before hooks entirely, they don't seem to be very useful;

- commands with special requirements now fire their own after hook (for
example, if they change session or window, or if they have -t and -s
and need to choose which one the hook uses as current target);

- commands with no special requirements can have the CMD_AFTERHOOK flag
added and they will use the -t state.

At the moment new-session, new-window, split-window fire their own hook,
and display-message uses the flag. The remaining commands still need to
be looked at.


# 1.72 13-Oct-2016 nicm

Some improvements and bug fixes for hooks:

- Prepare the state again before the "after" hooks are run, because the
command may have killed or moved windows.

- Use the hooks list from the newly prepared target, not the old hooks
list (only matters for new-session really).

- Correctly detect an invalid current state and ignore it in
cmd_find_target ("killw; swapw").

- Change neww, new, killp, killw, splitw, swapp, swapw to update the
current state (used if no explicit target is given) to something more
useful after they have finished. For example, neww changes it to the
newly created window.

Hooks are still relatively new and primitive so there are likely to be
more changes to come.

Parts based on bug reports from Uwe Werler and Iblis Lin.


# 1.71 10-Oct-2016 nicm

Add static in cmd-* and fix a few other nits.


# 1.70 04-Sep-2016 nicm

Add support for performing a full width split (with splitw -f), rather
than splitting the current cell. From Stephen Kent.


Revision tags: OPENBSD_6_0_BASE
# 1.69 06-Jun-2016 nicm

Insert new panes after the pane being split in the list rather than
always after the active pane. This is more sensible when doing it with
commands rather than keys.


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

I no longer use my SourceForge address so replace it.


# 1.67 14-Dec-2015 nicm

Instead of combined flags for -c, -s, -t, split into different sets
using an enum and simplify the parsing code.


# 1.66 13-Dec-2015 nicm

Use member names in cmd_entry definitions so I stop getting confused
about the order.


# 1.65 13-Dec-2015 nicm

Instead of every command resolving the target (-t or -s) itself, prepare
the state (client, session, winlink, pane) for it it before entering the
command. Each command provides some flags that tell the prepare step
what it is expecting.

This is a requirement for having hooks on commands (for example, if you
hook "select-window -t1:2", the hook command should to operate on window
1:2 not whatever it thinks is the current window), and should allow some
other target improvements.

The old cmd_find_* functions remain for the moment but that layer will
be dropped later.

Joint work with Thomas Adam.


# 1.64 11-Dec-2015 nicm

Add cmdq as an argument to format_create and add a format for the
command name (will also be used for more later).


# 1.63 08-Dec-2015 nicm

Remove format_create_flags and just pass flags to format_create.


# 1.62 31-Oct-2015 nicm

Fall back silently to ~ or / rather than checking -c with access(), this
was the old behaviour.


# 1.61 31-Oct-2015 nicm

Because pledge(2) does not allow us to pass directory file descriptors
around, we can't use file descriptors for the working directory because
we will be unable to pass it to a privileged process to tell it where to
read or write files or spawn children. So move tmux back to using
strings for the current working directory. We try to check it exists
with access() when it is set but ultimately fall back to ~ if it fails
at time of use (or / if that fails too).


# 1.60 28-Oct-2015 nicm

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


# 1.59 27-Oct-2015 nicm

Move struct options into options.c.


# 1.58 23-Oct-2015 nicm

Remove some unnecessary checks before free().


Revision tags: OPENBSD_5_8_BASE
# 1.57 26-Apr-2015 nicm

Remove panes from layout if spawning them fails, reported by Anthony J
Bentley.


Revision tags: OPENBSD_5_7_BASE
# 1.56 05-Feb-2015 nicm

Remove a couple of now-unused variables.


# 1.55 05-Feb-2015 nicm

Wrap all the individual format_* calls in a single format_defaults
functions.


# 1.54 12-Nov-2014 nicm

Add -b to splitw like joinw, from Felix Rosencrantz.


# 1.53 20-Oct-2014 nicm

Move template defines back into .c files.


# 1.52 20-Oct-2014 nicm

Instead of setting up the default keys by building the key struct
directly with a helper function in the cmd_entry, include a table of
bind-key commands and pass them through the command parser and a
temporary cmd_q.

As well as being smaller, this will allow default bindings to be command
sequences which will probably be needed soon.


# 1.51 01-Sep-2014 nicm

Various minor style and spacing nits.


Revision tags: OPENBSD_5_6_BASE
# 1.50 13-May-2014 nicm

If multiple arguments are given to new-session, new-window,
split-window, respawn-window or respawn-pane, pass them directly to
execvp() to help avoid quoting problems. One argument still goes to "sh
-c" like before. Requested by many over the years. Patch from J Raynor.


# 1.49 17-Apr-2014 nicm

Set PATH explicitly, either from client or session
environment. Previously it came from the session environment. From J
Raynor.


Revision tags: OPENBSD_5_5_BASE
# 1.48 22-Nov-2013 nicm

Handle empty current directory more gracefully.


# 1.47 10-Oct-2013 nicm

Don't boke when figuring out working directory from configuration file.


# 1.46 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.45 10-Oct-2013 nicm

Support -c for new-session, based on code from J Raynor.


# 1.44 10-Oct-2013 nicm

Restore missing key binding for %, from Chris Johnsen.


# 1.43 10-Oct-2013 nicm

Remove the barely-used and unnecessary command check() function.


Revision tags: OPENBSD_5_4_BASE
# 1.42 25-Mar-2013 nicm

Revert the command-prefix change which breaks sequences of commands.


# 1.41 24-Mar-2013 nicm

Add resize-pane -Z to temporary zoom the active pane to occupy the full
window or unzoom (restored to the normal layout) if it already zoomed,
bound to C-b z by default. The pane is unzoomed on pretty much any
excuse whatsoever.

We considered making this a new layout but the requirements are quite
different from layouts so decided it is better as a special case. Each
current layout cell is saved, a temporary one-cell layout generated and
all except the active pane set to NULL.

Prompted by suggestions and scripts from several. Thanks to Aaron Jensen
and Thiago Padilha for testing an earlier version.


# 1.40 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.


# 1.39 24-Mar-2013 nicm

Fix error reporting for client commands by adding a flag to
cmd_find_client to tell it whether or not to show errors, sometimes it's
needed and sometimes not.


# 1.38 24-Mar-2013 nicm

Add option command-prefix which is automatically prepended to any
command (apart from a naked default-shell). The default is "exec ".


Revision tags: OPENBSD_5_3_BASE
# 1.37 09-Dec-2012 nicm

Use the CMD_*_USAGE defines consistently, from Thomas Adam.


# 1.36 14-Aug-2012 nicm

Use a separate define for each default format template and strip clutter
from the choose-tree defaults.


Revision tags: OPENBSD_5_2_BASE
# 1.35 11-Jul-2012 nicm

Make command exec functions return an enum rather than -1/0/1 values and
add a new value to mean "leave client running but don't attach" to fix
problems with using some commands in a command sequence. Most of the
work by Thomas Adam, problem reported by "jspenguin" on SF bug 3535531.


# 1.34 10-Jul-2012 nicm

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


# 1.33 22-May-2012 nicm

Switch all of the various choose- and list- commands over to the format
infrastructure, from Thomas Adam.


# 1.32 17-Mar-2012 nicm

Add notify hooks for various events, the functions are currently empty
stubs but will be filled in for control mode later. From George Nachman.


# 1.31 04-Mar-2012 nicm

free -> xfree.


# 1.30 04-Mar-2012 nicm

Add -F format to new-window and split-window to use with the -P flag,
from George Nachman.


# 1.29 03-Mar-2012 nicm

Add move-pane command (like join-pane but allows the same window). Also
-b flag to join-pane and move-pane to place the pane to the left or
above. From George Nachman.


Revision tags: OPENBSD_5_1_BASE
# 1.28 31-Jan-2012 nicm

Provide defined ways to set the various default-path possibilities: ~
for home directory, . for server start directory, - for session start
directory and empty for the pane's working directory (the default). All
can also be used as part of a relative path (eg -/foo). Also provide -c
flags to neww and splitw to override default-path setting.

Based on a diff from sthen. ok sthen


# 1.27 20-Jan-2012 nicm

Add some const and fix a warning.


# 1.26 09-Dec-2011 nicm

Change the way the working directory for new processes is discovered. If
default-path isn't empty, it is used. Otherwise:

1) If tmux neww is run from the command line, the working directory of the
client is used.

2) Otherwise sysctl KERN_PROC_CWD is used to retrieve the current
working directory of the process in the active pane.

3) If that fails, the directory where the session was created is used.

Support code by Romain Francois, OpenBSD specific bits by me.

Note this requires a recent userland and kernel with KERN_PROC_CWD.


# 1.25 15-Nov-2011 nicm

Make window_pane_index work the same as window_index, from Ben Boeckel.


# 1.24 30-Aug-2011 nicm

Plug memory leak, from Tiago Cunha.


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE
# 1.23 10-Feb-2011 nicm

Size on split-window is -l not -s. Doh.


# 1.22 04-Jan-2011 nicm

Clean up and simplify tmux command argument parsing.

Originally, tmux commands were parsed in the client process into a
struct with the command data which was then serialised and sent to the
server to be executed. The parsing was later moved into the server (an
argv was sent from the client), but the parse step and intermediate
struct was kept.

This change removes that struct and the separate parse step. Argument
parsing and printing is now common to all commands (in arguments.c) with
each command left with just an optional check function (to validate the
arguments at parse time), the exec function and a function to set up any
key bindings (renamed from the old init function).

This is overall more simple and consistent.

There should be no changes to any commands behaviour or syntax although
as this touches every command please watch for any unexpected changes.


# 1.21 01-Jan-2011 nicm

Add a -P option to new-window and split-window to print the new window
or pane index in target form (useful to pass it into other commands).


Revision tags: OPENBSD_4_8_BASE
# 1.20 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.


Revision tags: OPENBSD_4_7_BASE
# 1.19 07-Jan-2010 nicm

New command, join-pane, to split and move an existing pane into the space (like
splitw then movep, or the reverse of breakp).


# 1.18 07-Jan-2010 nicm

Use the specified pane for size calculations. Doh.


# 1.17 07-Jan-2010 nicm

Change split-window to accept a pane target (it should be split-pane but
renaming the command would be annoying).


# 1.16 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.15 20-Nov-2009 nicm

When -h and -p are given to split-window, calculate the percentage size using
the width instead of the height.


# 1.14 13-Nov-2009 nicm

Get rid of the ugly CMD_CHFLAG macro and use a const string (eg "dDU") in the
command entry structs and a couple of functions to check/set the flags.


# 1.13 21-Sep-2009 nicm

Use KEYC_NONE constant instead of 0 on init.


# 1.12 16-Sep-2009 nicm

Rather than constructing an entire termios struct from ttydefaults.h, just let
forkpty do it and then alter the bits that should be changed after fork. A
little neater and more portable.


# 1.11 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.10 25-Aug-2009 nicm

Print -l and -p when showing command, pointed out by Tiago Cunha.


# 1.9 13-Aug-2009 nicm

When creating a new session from the command-line where there is an external
terminal, copy the termios(4) special characters and use them for new windows
created in the new session. Suggested by Theo.


# 1.8 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.7 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.6 22-Jul-2009 nicm

window_add_pane cannot fail, so remove the unused cause argument and don't
bother to check for a NULL return.


# 1.5 19-Jul-2009 nicm

Improved layout code.

Each window now has a tree of layout cells associated with it. In this tree,
each node is either a horizontal or vertical cell containing a list of other
cells running from left-to-right or top-to-bottom, or a leaf cell which is
associated with a pane.

The major functional changes are:

- panes may now be split arbitrarily both horizontally (splitw -h, C-b %) and
vertically (splitw -v, C-b ");
- panes may be resized both horizontally and vertically (resizep -L/-R/-U/-D,
bound to C-b left/right/up/down and C-b M-left/right/up/down);
- layouts are now applied and then may be modified by resizing or splitting
panes, rather than being fixed and reapplied when the window is resized or
panes are added;
- manual-vertical layout is no longer necessary, and active-only layout is gone
(but may return in future);
- the main-pane layouts now reduce the size of the main pane to fit all panes
if possible.

Thanks to all who tested.


# 1.4 13-Jul-2009 nicm

Having fixed flags for single-character getopt options is a bit hard to
maintain and is only going to get worse as more are used. So instead, add a new
uint64_t member to cmd_entry which is a bitmask of upper and lowercase options
accepted by the command.

This means new single character options can be used without the need to add it
explicitly to the list.


# 1.3 07-Jul-2009 nicm

The fix for default-path (use target session options instead of global options)
is required here as well, doh.


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

lines variable can be -1 (to be ignored), so should be signed. Found by lint.


# 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.112 08-Mar-2022 nicm

With -f use percentages of window size not pane size, GitHub issue 2866.


# 1.111 07-Oct-2021 nicm

Handle splitw -I correctly when used from an attached client, GitHub
issue 2917.


Revision tags: OPENBSD_7_0_BASE
# 1.110 27-Aug-2021 nicm

Replace %% in command lists (by copying them) for template arguments ,
this means they can be used with {} as well. Also make argument
processing from an existing vector preserve commands. GitHub issue 2858.


# 1.109 21-Aug-2021 nicm

Rename a member to match what it will be in future.


# 1.108 21-Aug-2021 nicm

Add args parsing callback for some future work, currently unused.


# 1.107 20-Aug-2021 nicm

Hide struct args behind a couple of accessor functions.


# 1.106 20-Aug-2021 nicm

Expose args_value struct (will be needed soon) and add some missing frees.


Revision tags: OPENBSD_6_9_BASE
# 1.105 11-Mar-2021 nicm

Add split-window -Z to start the pane zoomed, GitHub issue 2591.


Revision tags: OPENBSD_6_8_BASE
# 1.104 16-May-2020 nicm

Add a client flag 'active-pane' which stores the active pane in the
client and allows it to be changed independently from the real active
pane stored in the window. This is can be used with session groups which
allow an independent current window (although it would be nice to have a
flag for this too and remove session groups). The client active pane is
only really useful interactively, many things (hooks, window-style,
zooming) still use the window active pane.


Revision tags: OPENBSD_6_7_BASE
# 1.103 13-Apr-2020 nicm

Make client -c and -t handling common in cmd-queue.c and try to be
clearer about whether the client is the target client (must have a
session) or not.


# 1.102 13-Apr-2020 nicm

Move cmdq_state into cmd-queue.c.


# 1.101 13-Apr-2020 nicm

Rename cmdq_shared to cmdq_state which will better reflect what it is
(going to be) used for.


# 1.100 13-Apr-2020 nicm

Also move cmdq_item and cmdq_list into cmd-queue.c (this is to make its
use more clearly defined and preparation for some future work).


# 1.99 13-Apr-2020 nicm

Make struct cmd local to cmd.c and move it out of tmux.h.


# 1.98 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.97 16-Mar-2020 nicm

Do not attempt to close a NULL pane when failing to create a new one.


# 1.96 15-Oct-2019 nicm

Add support for percentage sizes for resize-pane ("-x 10%"). Also change
split-window and join-pane -l to accept similar percentages and
deprecate -p. From Anindya Mukherjee.


Revision tags: OPENBSD_6_6_BASE
# 1.95 03-May-2019 nicm

Allow panes to be empty (no command), output can be piped to them with
split-window or display-message -I.


# 1.94 28-Apr-2019 nicm

Support multiple occurances of the same argument. Use this for a new
flag -e to new-window, split-window, respawn-window, respawn-pane to
pass environment variables into the newly created process. From Steffen
Christgau in GitHub issue 1697.


# 1.93 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).


# 1.92 17-Apr-2019 nicm

Break new window and pane creation common code from various commands and
window.c into a separate file spawn.c.


Revision tags: OPENBSD_6_5_BASE
# 1.91 18-Oct-2018 nicm

Support for windows larger than visible on the attached client. This has
been a limitation for a long time.

There are two new options, window-size and default-size, and a new
command, resize-window. The force-width and force-height options and the
session_width and session_height formats have been removed.

The new window-size option tells tmux how to work out the size of
windows: largest means it picks the size of the largest session,
smallest the smallest session (similar to the old behaviour) and manual
means that it does not automatically resize windows. The default is
currently largest but this may change. aggressive-resize modifies the
choice of session for largest and smallest as it did before.

If a window is in a session attached to a client that is too small, only
part of the window is shown. tmux attempts to keep the cursor visible,
so the part of the window displayed is changed as the cursor moves (with
a small delay, to try and avoid excess redrawing when applications
redraw status lines or similar that are not currently visible). The
offset of the visible portion of the window is shown in status-right.

Drawing windows which are larger than the client is not as efficient as
those which fit, particularly when the cursor moves, so it is
recommended to avoid using this on slow machines or networks (set
window-size to smallest or manual).

The resize-window command can be used to resize a window manually. If it
is used, the window-size option is automatically set to manual for the
window (undo this with "setw -u window-size"). resize-window works in a
similar way to resize-pane (-U -D -L -R -x -y flags) but also has -a and
-A flags. -a sets the window to the size of the smallest client (what it
would be if window-size was smallest) and -A the largest.

For the same behaviour as force-width or force-height, use resize-window
-x or -y, and "setw -u window-size" to revert to automatic sizing..

If the global window-size option is set to manual, the default-size
option is used for new windows. If -x or -y is used with new-session,
that sets the default-size option for the new session.

The maximum size of a window is 10000x10000. But expect applications to
complain and much higher memory use if making a window excessively
big. The minimum size is the size required for the current layout
including borders.

The refresh-client command can be used to pan around a window, -U -D -L
-R moves up, down, left or right and -c returns to automatic cursor
tracking. The position is reset when the current window is changed.


Revision tags: OPENBSD_6_4_BASE
# 1.90 24-May-2018 nicm

Make server_client_get_cwd used (almost) everywhere we need to work out
the cwd, and do not fall back to "." as it is pretty useless. GitHub
issue 1331.


Revision tags: OPENBSD_6_3_BASE
# 1.89 16-Mar-2018 nicm

Insert full size panes at the right position, from KOIE Hidetaka in
GitHub issue 1284.


# 1.88 01-Mar-2018 nicm

Expand formats in window and session names.


Revision tags: OPENBSD_6_2_BASE
# 1.87 30-Aug-2017 nicm

Pass flags into cmd_find_from_* to fix prefer-unattached, reported by
Thomas Sattler.


# 1.86 21-Jul-2017 nicm

Add -c for respawn-pane and respawn-window, from J Raynor.


# 1.85 30-May-2017 nicm

Rewrite of choose mode, both to simplify and tidy the code and to add
some modern features.

Now the common code is in mode-tree.c, which provides an API used by the
three modes now separated into window-{buffer,client,tree}.c. Buffer
mode shows buffers, client mode clients and tree mode a tree of
sessions, windows and panes.

Each mode has a common set of key bindings plus a few that are specific
to the mode. Other changes are:

- each mode has a preview pane: for buffers this is the buffer content
(very useful), for others it is a preview of the pane;

- items may be sorted in different ways ('O' key);

- multiple items may be tagged and an operation applied to all of them
(for example, to delete multiple buffers at once);

- in tree mode a command may be run on the selected item (session,
window, pane) or on tagged items (key ':');

- displayed items may be filtered in tree mode by using a format (this
is used to implement find-window) (key 'f');

- the custom format (-F) for the display is no longer available;

- shortcut keys change from 0-9, a-z, A-Z which was always a bit weird
with keys used for other uses to 0-9, M-a to M-z.

Now that the code is simpler, other improvements will come later.

Primary key bindings for each mode are documented under the commands in
the man page (choose-buffer, choose-client, choose-tree).

Parts written by Thomas Adam.


# 1.84 25-Apr-2017 nicm

Do not update TERM into config file parsing has finished.


# 1.83 22-Apr-2017 nicm

Get rid of the extra layer of flags and cmd_prepare() and just store the
CMD_FIND_* flags in the cmd_entry and call it for the command. Commands
with special requirements call it themselves and update the target for
hooks to use.


# 1.82 22-Apr-2017 nicm

Mouse bindings and hooks set up an initial current state when running a
command. This is used for the session, window and pane for all commands
in the command sequence if there is no -t or -s.

However, using it for all commands in the command sequence means that if
the active pane or current session is changed, subsequent commands still
use the previous state. So make commands which explicitly change the
current state (such as neww and selectp) update it themselves for later
commands. Commands which may invalidate the state (like killp) are
already OK because an invalid state will be ignored.

Also fill in the current state for all key bindings rather than just the
mouse, so that any omissions are easier to spot.


# 1.81 21-Apr-2017 nicm

Add cmd_find_from_winlink_pane and use it in a couple of places, and
make functions that can't fail void.


Revision tags: OPENBSD_6_1_BASE
# 1.80 09-Mar-2017 nicm

Move server_fill_environ into environ.c and move some other common code
into it.


# 1.79 08-Mar-2017 nicm

Add a helper function for the most common format_create/defaults/expand
pattern.


# 1.78 27-Feb-2017 nicm

If splitw -b is used, insert the new pane before the current one in the
pane list. This means the numbering is in order (for example for
display-panes) and fixes a problem with redrawing the active pane
borders.


# 1.77 03-Feb-2017 nicm

Add a window or pane id "tag" to each format tree and use it to separate
jobs, this means that if the same job is used for different windows or
panes (for example in pane-border-format), it will be run separately for
each pane.


# 1.76 16-Oct-2016 nicm

Use the notify name string instead of going via an enum and change
existing hooks to use notifys instead.


# 1.75 16-Oct-2016 nicm

Mass rename struct cmd_q to struct cmdq_item and related.


# 1.74 16-Oct-2016 nicm

Rewrite command queue handling. Each client still has a command queue,
but there is also now a global command queue. Instead of command queues
being dispatched on demand from wherever the command happens to be
added, they are now all dispatched from the top level server
loop. Command queues may now also include callbacks as well as commands,
and items may be inserted after the current command as well as at the end.

This all makes command queues significantly more predictable and easier
to use, and avoids the complex multiple nested command queues used by
source-file, if-shell and friends.

A mass rename of struct cmdq to a better name (cmdq_item probably) is
coming.


# 1.73 13-Oct-2016 nicm

Trying to do hooks generically is way too complicated and unreliable and
confusing, particularly trying to automatically figure out what target
hooks should be using. So simplify it:

- drop before hooks entirely, they don't seem to be very useful;

- commands with special requirements now fire their own after hook (for
example, if they change session or window, or if they have -t and -s
and need to choose which one the hook uses as current target);

- commands with no special requirements can have the CMD_AFTERHOOK flag
added and they will use the -t state.

At the moment new-session, new-window, split-window fire their own hook,
and display-message uses the flag. The remaining commands still need to
be looked at.


# 1.72 13-Oct-2016 nicm

Some improvements and bug fixes for hooks:

- Prepare the state again before the "after" hooks are run, because the
command may have killed or moved windows.

- Use the hooks list from the newly prepared target, not the old hooks
list (only matters for new-session really).

- Correctly detect an invalid current state and ignore it in
cmd_find_target ("killw; swapw").

- Change neww, new, killp, killw, splitw, swapp, swapw to update the
current state (used if no explicit target is given) to something more
useful after they have finished. For example, neww changes it to the
newly created window.

Hooks are still relatively new and primitive so there are likely to be
more changes to come.

Parts based on bug reports from Uwe Werler and Iblis Lin.


# 1.71 10-Oct-2016 nicm

Add static in cmd-* and fix a few other nits.


# 1.70 04-Sep-2016 nicm

Add support for performing a full width split (with splitw -f), rather
than splitting the current cell. From Stephen Kent.


Revision tags: OPENBSD_6_0_BASE
# 1.69 06-Jun-2016 nicm

Insert new panes after the pane being split in the list rather than
always after the active pane. This is more sensible when doing it with
commands rather than keys.


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

I no longer use my SourceForge address so replace it.


# 1.67 14-Dec-2015 nicm

Instead of combined flags for -c, -s, -t, split into different sets
using an enum and simplify the parsing code.


# 1.66 13-Dec-2015 nicm

Use member names in cmd_entry definitions so I stop getting confused
about the order.


# 1.65 13-Dec-2015 nicm

Instead of every command resolving the target (-t or -s) itself, prepare
the state (client, session, winlink, pane) for it it before entering the
command. Each command provides some flags that tell the prepare step
what it is expecting.

This is a requirement for having hooks on commands (for example, if you
hook "select-window -t1:2", the hook command should to operate on window
1:2 not whatever it thinks is the current window), and should allow some
other target improvements.

The old cmd_find_* functions remain for the moment but that layer will
be dropped later.

Joint work with Thomas Adam.


# 1.64 11-Dec-2015 nicm

Add cmdq as an argument to format_create and add a format for the
command name (will also be used for more later).


# 1.63 08-Dec-2015 nicm

Remove format_create_flags and just pass flags to format_create.


# 1.62 31-Oct-2015 nicm

Fall back silently to ~ or / rather than checking -c with access(), this
was the old behaviour.


# 1.61 31-Oct-2015 nicm

Because pledge(2) does not allow us to pass directory file descriptors
around, we can't use file descriptors for the working directory because
we will be unable to pass it to a privileged process to tell it where to
read or write files or spawn children. So move tmux back to using
strings for the current working directory. We try to check it exists
with access() when it is set but ultimately fall back to ~ if it fails
at time of use (or / if that fails too).


# 1.60 28-Oct-2015 nicm

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


# 1.59 27-Oct-2015 nicm

Move struct options into options.c.


# 1.58 23-Oct-2015 nicm

Remove some unnecessary checks before free().


Revision tags: OPENBSD_5_8_BASE
# 1.57 26-Apr-2015 nicm

Remove panes from layout if spawning them fails, reported by Anthony J
Bentley.


Revision tags: OPENBSD_5_7_BASE
# 1.56 05-Feb-2015 nicm

Remove a couple of now-unused variables.


# 1.55 05-Feb-2015 nicm

Wrap all the individual format_* calls in a single format_defaults
functions.


# 1.54 12-Nov-2014 nicm

Add -b to splitw like joinw, from Felix Rosencrantz.


# 1.53 20-Oct-2014 nicm

Move template defines back into .c files.


# 1.52 20-Oct-2014 nicm

Instead of setting up the default keys by building the key struct
directly with a helper function in the cmd_entry, include a table of
bind-key commands and pass them through the command parser and a
temporary cmd_q.

As well as being smaller, this will allow default bindings to be command
sequences which will probably be needed soon.


# 1.51 01-Sep-2014 nicm

Various minor style and spacing nits.


Revision tags: OPENBSD_5_6_BASE
# 1.50 13-May-2014 nicm

If multiple arguments are given to new-session, new-window,
split-window, respawn-window or respawn-pane, pass them directly to
execvp() to help avoid quoting problems. One argument still goes to "sh
-c" like before. Requested by many over the years. Patch from J Raynor.


# 1.49 17-Apr-2014 nicm

Set PATH explicitly, either from client or session
environment. Previously it came from the session environment. From J
Raynor.


Revision tags: OPENBSD_5_5_BASE
# 1.48 22-Nov-2013 nicm

Handle empty current directory more gracefully.


# 1.47 10-Oct-2013 nicm

Don't boke when figuring out working directory from configuration file.


# 1.46 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.45 10-Oct-2013 nicm

Support -c for new-session, based on code from J Raynor.


# 1.44 10-Oct-2013 nicm

Restore missing key binding for %, from Chris Johnsen.


# 1.43 10-Oct-2013 nicm

Remove the barely-used and unnecessary command check() function.


Revision tags: OPENBSD_5_4_BASE
# 1.42 25-Mar-2013 nicm

Revert the command-prefix change which breaks sequences of commands.


# 1.41 24-Mar-2013 nicm

Add resize-pane -Z to temporary zoom the active pane to occupy the full
window or unzoom (restored to the normal layout) if it already zoomed,
bound to C-b z by default. The pane is unzoomed on pretty much any
excuse whatsoever.

We considered making this a new layout but the requirements are quite
different from layouts so decided it is better as a special case. Each
current layout cell is saved, a temporary one-cell layout generated and
all except the active pane set to NULL.

Prompted by suggestions and scripts from several. Thanks to Aaron Jensen
and Thiago Padilha for testing an earlier version.


# 1.40 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.


# 1.39 24-Mar-2013 nicm

Fix error reporting for client commands by adding a flag to
cmd_find_client to tell it whether or not to show errors, sometimes it's
needed and sometimes not.


# 1.38 24-Mar-2013 nicm

Add option command-prefix which is automatically prepended to any
command (apart from a naked default-shell). The default is "exec ".


Revision tags: OPENBSD_5_3_BASE
# 1.37 09-Dec-2012 nicm

Use the CMD_*_USAGE defines consistently, from Thomas Adam.


# 1.36 14-Aug-2012 nicm

Use a separate define for each default format template and strip clutter
from the choose-tree defaults.


Revision tags: OPENBSD_5_2_BASE
# 1.35 11-Jul-2012 nicm

Make command exec functions return an enum rather than -1/0/1 values and
add a new value to mean "leave client running but don't attach" to fix
problems with using some commands in a command sequence. Most of the
work by Thomas Adam, problem reported by "jspenguin" on SF bug 3535531.


# 1.34 10-Jul-2012 nicm

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


# 1.33 22-May-2012 nicm

Switch all of the various choose- and list- commands over to the format
infrastructure, from Thomas Adam.


# 1.32 17-Mar-2012 nicm

Add notify hooks for various events, the functions are currently empty
stubs but will be filled in for control mode later. From George Nachman.


# 1.31 04-Mar-2012 nicm

free -> xfree.


# 1.30 04-Mar-2012 nicm

Add -F format to new-window and split-window to use with the -P flag,
from George Nachman.


# 1.29 03-Mar-2012 nicm

Add move-pane command (like join-pane but allows the same window). Also
-b flag to join-pane and move-pane to place the pane to the left or
above. From George Nachman.


Revision tags: OPENBSD_5_1_BASE
# 1.28 31-Jan-2012 nicm

Provide defined ways to set the various default-path possibilities: ~
for home directory, . for server start directory, - for session start
directory and empty for the pane's working directory (the default). All
can also be used as part of a relative path (eg -/foo). Also provide -c
flags to neww and splitw to override default-path setting.

Based on a diff from sthen. ok sthen


# 1.27 20-Jan-2012 nicm

Add some const and fix a warning.


# 1.26 09-Dec-2011 nicm

Change the way the working directory for new processes is discovered. If
default-path isn't empty, it is used. Otherwise:

1) If tmux neww is run from the command line, the working directory of the
client is used.

2) Otherwise sysctl KERN_PROC_CWD is used to retrieve the current
working directory of the process in the active pane.

3) If that fails, the directory where the session was created is used.

Support code by Romain Francois, OpenBSD specific bits by me.

Note this requires a recent userland and kernel with KERN_PROC_CWD.


# 1.25 15-Nov-2011 nicm

Make window_pane_index work the same as window_index, from Ben Boeckel.


# 1.24 30-Aug-2011 nicm

Plug memory leak, from Tiago Cunha.


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE
# 1.23 10-Feb-2011 nicm

Size on split-window is -l not -s. Doh.


# 1.22 04-Jan-2011 nicm

Clean up and simplify tmux command argument parsing.

Originally, tmux commands were parsed in the client process into a
struct with the command data which was then serialised and sent to the
server to be executed. The parsing was later moved into the server (an
argv was sent from the client), but the parse step and intermediate
struct was kept.

This change removes that struct and the separate parse step. Argument
parsing and printing is now common to all commands (in arguments.c) with
each command left with just an optional check function (to validate the
arguments at parse time), the exec function and a function to set up any
key bindings (renamed from the old init function).

This is overall more simple and consistent.

There should be no changes to any commands behaviour or syntax although
as this touches every command please watch for any unexpected changes.


# 1.21 01-Jan-2011 nicm

Add a -P option to new-window and split-window to print the new window
or pane index in target form (useful to pass it into other commands).


Revision tags: OPENBSD_4_8_BASE
# 1.20 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.


Revision tags: OPENBSD_4_7_BASE
# 1.19 07-Jan-2010 nicm

New command, join-pane, to split and move an existing pane into the space (like
splitw then movep, or the reverse of breakp).


# 1.18 07-Jan-2010 nicm

Use the specified pane for size calculations. Doh.


# 1.17 07-Jan-2010 nicm

Change split-window to accept a pane target (it should be split-pane but
renaming the command would be annoying).


# 1.16 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.15 20-Nov-2009 nicm

When -h and -p are given to split-window, calculate the percentage size using
the width instead of the height.


# 1.14 13-Nov-2009 nicm

Get rid of the ugly CMD_CHFLAG macro and use a const string (eg "dDU") in the
command entry structs and a couple of functions to check/set the flags.


# 1.13 21-Sep-2009 nicm

Use KEYC_NONE constant instead of 0 on init.


# 1.12 16-Sep-2009 nicm

Rather than constructing an entire termios struct from ttydefaults.h, just let
forkpty do it and then alter the bits that should be changed after fork. A
little neater and more portable.


# 1.11 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.10 25-Aug-2009 nicm

Print -l and -p when showing command, pointed out by Tiago Cunha.


# 1.9 13-Aug-2009 nicm

When creating a new session from the command-line where there is an external
terminal, copy the termios(4) special characters and use them for new windows
created in the new session. Suggested by Theo.


# 1.8 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.7 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.6 22-Jul-2009 nicm

window_add_pane cannot fail, so remove the unused cause argument and don't
bother to check for a NULL return.


# 1.5 19-Jul-2009 nicm

Improved layout code.

Each window now has a tree of layout cells associated with it. In this tree,
each node is either a horizontal or vertical cell containing a list of other
cells running from left-to-right or top-to-bottom, or a leaf cell which is
associated with a pane.

The major functional changes are:

- panes may now be split arbitrarily both horizontally (splitw -h, C-b %) and
vertically (splitw -v, C-b ");
- panes may be resized both horizontally and vertically (resizep -L/-R/-U/-D,
bound to C-b left/right/up/down and C-b M-left/right/up/down);
- layouts are now applied and then may be modified by resizing or splitting
panes, rather than being fixed and reapplied when the window is resized or
panes are added;
- manual-vertical layout is no longer necessary, and active-only layout is gone
(but may return in future);
- the main-pane layouts now reduce the size of the main pane to fit all panes
if possible.

Thanks to all who tested.


# 1.4 13-Jul-2009 nicm

Having fixed flags for single-character getopt options is a bit hard to
maintain and is only going to get worse as more are used. So instead, add a new
uint64_t member to cmd_entry which is a bitmask of upper and lowercase options
accepted by the command.

This means new single character options can be used without the need to add it
explicitly to the list.


# 1.3 07-Jul-2009 nicm

The fix for default-path (use target session options instead of global options)
is required here as well, doh.


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

lines variable can be -1 (to be ignored), so should be signed. Found by lint.


# 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.111 07-Oct-2021 nicm

Handle splitw -I correctly when used from an attached client, GitHub
issue 2917.


Revision tags: OPENBSD_7_0_BASE
# 1.110 27-Aug-2021 nicm

Replace %% in command lists (by copying them) for template arguments ,
this means they can be used with {} as well. Also make argument
processing from an existing vector preserve commands. GitHub issue 2858.


# 1.109 21-Aug-2021 nicm

Rename a member to match what it will be in future.


# 1.108 21-Aug-2021 nicm

Add args parsing callback for some future work, currently unused.


# 1.107 20-Aug-2021 nicm

Hide struct args behind a couple of accessor functions.


# 1.106 20-Aug-2021 nicm

Expose args_value struct (will be needed soon) and add some missing frees.


Revision tags: OPENBSD_6_9_BASE
# 1.105 11-Mar-2021 nicm

Add split-window -Z to start the pane zoomed, GitHub issue 2591.


Revision tags: OPENBSD_6_8_BASE
# 1.104 16-May-2020 nicm

Add a client flag 'active-pane' which stores the active pane in the
client and allows it to be changed independently from the real active
pane stored in the window. This is can be used with session groups which
allow an independent current window (although it would be nice to have a
flag for this too and remove session groups). The client active pane is
only really useful interactively, many things (hooks, window-style,
zooming) still use the window active pane.


Revision tags: OPENBSD_6_7_BASE
# 1.103 13-Apr-2020 nicm

Make client -c and -t handling common in cmd-queue.c and try to be
clearer about whether the client is the target client (must have a
session) or not.


# 1.102 13-Apr-2020 nicm

Move cmdq_state into cmd-queue.c.


# 1.101 13-Apr-2020 nicm

Rename cmdq_shared to cmdq_state which will better reflect what it is
(going to be) used for.


# 1.100 13-Apr-2020 nicm

Also move cmdq_item and cmdq_list into cmd-queue.c (this is to make its
use more clearly defined and preparation for some future work).


# 1.99 13-Apr-2020 nicm

Make struct cmd local to cmd.c and move it out of tmux.h.


# 1.98 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.97 16-Mar-2020 nicm

Do not attempt to close a NULL pane when failing to create a new one.


# 1.96 15-Oct-2019 nicm

Add support for percentage sizes for resize-pane ("-x 10%"). Also change
split-window and join-pane -l to accept similar percentages and
deprecate -p. From Anindya Mukherjee.


Revision tags: OPENBSD_6_6_BASE
# 1.95 03-May-2019 nicm

Allow panes to be empty (no command), output can be piped to them with
split-window or display-message -I.


# 1.94 28-Apr-2019 nicm

Support multiple occurances of the same argument. Use this for a new
flag -e to new-window, split-window, respawn-window, respawn-pane to
pass environment variables into the newly created process. From Steffen
Christgau in GitHub issue 1697.


# 1.93 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).


# 1.92 17-Apr-2019 nicm

Break new window and pane creation common code from various commands and
window.c into a separate file spawn.c.


Revision tags: OPENBSD_6_5_BASE
# 1.91 18-Oct-2018 nicm

Support for windows larger than visible on the attached client. This has
been a limitation for a long time.

There are two new options, window-size and default-size, and a new
command, resize-window. The force-width and force-height options and the
session_width and session_height formats have been removed.

The new window-size option tells tmux how to work out the size of
windows: largest means it picks the size of the largest session,
smallest the smallest session (similar to the old behaviour) and manual
means that it does not automatically resize windows. The default is
currently largest but this may change. aggressive-resize modifies the
choice of session for largest and smallest as it did before.

If a window is in a session attached to a client that is too small, only
part of the window is shown. tmux attempts to keep the cursor visible,
so the part of the window displayed is changed as the cursor moves (with
a small delay, to try and avoid excess redrawing when applications
redraw status lines or similar that are not currently visible). The
offset of the visible portion of the window is shown in status-right.

Drawing windows which are larger than the client is not as efficient as
those which fit, particularly when the cursor moves, so it is
recommended to avoid using this on slow machines or networks (set
window-size to smallest or manual).

The resize-window command can be used to resize a window manually. If it
is used, the window-size option is automatically set to manual for the
window (undo this with "setw -u window-size"). resize-window works in a
similar way to resize-pane (-U -D -L -R -x -y flags) but also has -a and
-A flags. -a sets the window to the size of the smallest client (what it
would be if window-size was smallest) and -A the largest.

For the same behaviour as force-width or force-height, use resize-window
-x or -y, and "setw -u window-size" to revert to automatic sizing..

If the global window-size option is set to manual, the default-size
option is used for new windows. If -x or -y is used with new-session,
that sets the default-size option for the new session.

The maximum size of a window is 10000x10000. But expect applications to
complain and much higher memory use if making a window excessively
big. The minimum size is the size required for the current layout
including borders.

The refresh-client command can be used to pan around a window, -U -D -L
-R moves up, down, left or right and -c returns to automatic cursor
tracking. The position is reset when the current window is changed.


Revision tags: OPENBSD_6_4_BASE
# 1.90 24-May-2018 nicm

Make server_client_get_cwd used (almost) everywhere we need to work out
the cwd, and do not fall back to "." as it is pretty useless. GitHub
issue 1331.


Revision tags: OPENBSD_6_3_BASE
# 1.89 16-Mar-2018 nicm

Insert full size panes at the right position, from KOIE Hidetaka in
GitHub issue 1284.


# 1.88 01-Mar-2018 nicm

Expand formats in window and session names.


Revision tags: OPENBSD_6_2_BASE
# 1.87 30-Aug-2017 nicm

Pass flags into cmd_find_from_* to fix prefer-unattached, reported by
Thomas Sattler.


# 1.86 21-Jul-2017 nicm

Add -c for respawn-pane and respawn-window, from J Raynor.


# 1.85 30-May-2017 nicm

Rewrite of choose mode, both to simplify and tidy the code and to add
some modern features.

Now the common code is in mode-tree.c, which provides an API used by the
three modes now separated into window-{buffer,client,tree}.c. Buffer
mode shows buffers, client mode clients and tree mode a tree of
sessions, windows and panes.

Each mode has a common set of key bindings plus a few that are specific
to the mode. Other changes are:

- each mode has a preview pane: for buffers this is the buffer content
(very useful), for others it is a preview of the pane;

- items may be sorted in different ways ('O' key);

- multiple items may be tagged and an operation applied to all of them
(for example, to delete multiple buffers at once);

- in tree mode a command may be run on the selected item (session,
window, pane) or on tagged items (key ':');

- displayed items may be filtered in tree mode by using a format (this
is used to implement find-window) (key 'f');

- the custom format (-F) for the display is no longer available;

- shortcut keys change from 0-9, a-z, A-Z which was always a bit weird
with keys used for other uses to 0-9, M-a to M-z.

Now that the code is simpler, other improvements will come later.

Primary key bindings for each mode are documented under the commands in
the man page (choose-buffer, choose-client, choose-tree).

Parts written by Thomas Adam.


# 1.84 25-Apr-2017 nicm

Do not update TERM into config file parsing has finished.


# 1.83 22-Apr-2017 nicm

Get rid of the extra layer of flags and cmd_prepare() and just store the
CMD_FIND_* flags in the cmd_entry and call it for the command. Commands
with special requirements call it themselves and update the target for
hooks to use.


# 1.82 22-Apr-2017 nicm

Mouse bindings and hooks set up an initial current state when running a
command. This is used for the session, window and pane for all commands
in the command sequence if there is no -t or -s.

However, using it for all commands in the command sequence means that if
the active pane or current session is changed, subsequent commands still
use the previous state. So make commands which explicitly change the
current state (such as neww and selectp) update it themselves for later
commands. Commands which may invalidate the state (like killp) are
already OK because an invalid state will be ignored.

Also fill in the current state for all key bindings rather than just the
mouse, so that any omissions are easier to spot.


# 1.81 21-Apr-2017 nicm

Add cmd_find_from_winlink_pane and use it in a couple of places, and
make functions that can't fail void.


Revision tags: OPENBSD_6_1_BASE
# 1.80 09-Mar-2017 nicm

Move server_fill_environ into environ.c and move some other common code
into it.


# 1.79 08-Mar-2017 nicm

Add a helper function for the most common format_create/defaults/expand
pattern.


# 1.78 27-Feb-2017 nicm

If splitw -b is used, insert the new pane before the current one in the
pane list. This means the numbering is in order (for example for
display-panes) and fixes a problem with redrawing the active pane
borders.


# 1.77 03-Feb-2017 nicm

Add a window or pane id "tag" to each format tree and use it to separate
jobs, this means that if the same job is used for different windows or
panes (for example in pane-border-format), it will be run separately for
each pane.


# 1.76 16-Oct-2016 nicm

Use the notify name string instead of going via an enum and change
existing hooks to use notifys instead.


# 1.75 16-Oct-2016 nicm

Mass rename struct cmd_q to struct cmdq_item and related.


# 1.74 16-Oct-2016 nicm

Rewrite command queue handling. Each client still has a command queue,
but there is also now a global command queue. Instead of command queues
being dispatched on demand from wherever the command happens to be
added, they are now all dispatched from the top level server
loop. Command queues may now also include callbacks as well as commands,
and items may be inserted after the current command as well as at the end.

This all makes command queues significantly more predictable and easier
to use, and avoids the complex multiple nested command queues used by
source-file, if-shell and friends.

A mass rename of struct cmdq to a better name (cmdq_item probably) is
coming.


# 1.73 13-Oct-2016 nicm

Trying to do hooks generically is way too complicated and unreliable and
confusing, particularly trying to automatically figure out what target
hooks should be using. So simplify it:

- drop before hooks entirely, they don't seem to be very useful;

- commands with special requirements now fire their own after hook (for
example, if they change session or window, or if they have -t and -s
and need to choose which one the hook uses as current target);

- commands with no special requirements can have the CMD_AFTERHOOK flag
added and they will use the -t state.

At the moment new-session, new-window, split-window fire their own hook,
and display-message uses the flag. The remaining commands still need to
be looked at.


# 1.72 13-Oct-2016 nicm

Some improvements and bug fixes for hooks:

- Prepare the state again before the "after" hooks are run, because the
command may have killed or moved windows.

- Use the hooks list from the newly prepared target, not the old hooks
list (only matters for new-session really).

- Correctly detect an invalid current state and ignore it in
cmd_find_target ("killw; swapw").

- Change neww, new, killp, killw, splitw, swapp, swapw to update the
current state (used if no explicit target is given) to something more
useful after they have finished. For example, neww changes it to the
newly created window.

Hooks are still relatively new and primitive so there are likely to be
more changes to come.

Parts based on bug reports from Uwe Werler and Iblis Lin.


# 1.71 10-Oct-2016 nicm

Add static in cmd-* and fix a few other nits.


# 1.70 04-Sep-2016 nicm

Add support for performing a full width split (with splitw -f), rather
than splitting the current cell. From Stephen Kent.


Revision tags: OPENBSD_6_0_BASE
# 1.69 06-Jun-2016 nicm

Insert new panes after the pane being split in the list rather than
always after the active pane. This is more sensible when doing it with
commands rather than keys.


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

I no longer use my SourceForge address so replace it.


# 1.67 14-Dec-2015 nicm

Instead of combined flags for -c, -s, -t, split into different sets
using an enum and simplify the parsing code.


# 1.66 13-Dec-2015 nicm

Use member names in cmd_entry definitions so I stop getting confused
about the order.


# 1.65 13-Dec-2015 nicm

Instead of every command resolving the target (-t or -s) itself, prepare
the state (client, session, winlink, pane) for it it before entering the
command. Each command provides some flags that tell the prepare step
what it is expecting.

This is a requirement for having hooks on commands (for example, if you
hook "select-window -t1:2", the hook command should to operate on window
1:2 not whatever it thinks is the current window), and should allow some
other target improvements.

The old cmd_find_* functions remain for the moment but that layer will
be dropped later.

Joint work with Thomas Adam.


# 1.64 11-Dec-2015 nicm

Add cmdq as an argument to format_create and add a format for the
command name (will also be used for more later).


# 1.63 08-Dec-2015 nicm

Remove format_create_flags and just pass flags to format_create.


# 1.62 31-Oct-2015 nicm

Fall back silently to ~ or / rather than checking -c with access(), this
was the old behaviour.


# 1.61 31-Oct-2015 nicm

Because pledge(2) does not allow us to pass directory file descriptors
around, we can't use file descriptors for the working directory because
we will be unable to pass it to a privileged process to tell it where to
read or write files or spawn children. So move tmux back to using
strings for the current working directory. We try to check it exists
with access() when it is set but ultimately fall back to ~ if it fails
at time of use (or / if that fails too).


# 1.60 28-Oct-2015 nicm

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


# 1.59 27-Oct-2015 nicm

Move struct options into options.c.


# 1.58 23-Oct-2015 nicm

Remove some unnecessary checks before free().


Revision tags: OPENBSD_5_8_BASE
# 1.57 26-Apr-2015 nicm

Remove panes from layout if spawning them fails, reported by Anthony J
Bentley.


Revision tags: OPENBSD_5_7_BASE
# 1.56 05-Feb-2015 nicm

Remove a couple of now-unused variables.


# 1.55 05-Feb-2015 nicm

Wrap all the individual format_* calls in a single format_defaults
functions.


# 1.54 12-Nov-2014 nicm

Add -b to splitw like joinw, from Felix Rosencrantz.


# 1.53 20-Oct-2014 nicm

Move template defines back into .c files.


# 1.52 20-Oct-2014 nicm

Instead of setting up the default keys by building the key struct
directly with a helper function in the cmd_entry, include a table of
bind-key commands and pass them through the command parser and a
temporary cmd_q.

As well as being smaller, this will allow default bindings to be command
sequences which will probably be needed soon.


# 1.51 01-Sep-2014 nicm

Various minor style and spacing nits.


Revision tags: OPENBSD_5_6_BASE
# 1.50 13-May-2014 nicm

If multiple arguments are given to new-session, new-window,
split-window, respawn-window or respawn-pane, pass them directly to
execvp() to help avoid quoting problems. One argument still goes to "sh
-c" like before. Requested by many over the years. Patch from J Raynor.


# 1.49 17-Apr-2014 nicm

Set PATH explicitly, either from client or session
environment. Previously it came from the session environment. From J
Raynor.


Revision tags: OPENBSD_5_5_BASE
# 1.48 22-Nov-2013 nicm

Handle empty current directory more gracefully.


# 1.47 10-Oct-2013 nicm

Don't boke when figuring out working directory from configuration file.


# 1.46 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.45 10-Oct-2013 nicm

Support -c for new-session, based on code from J Raynor.


# 1.44 10-Oct-2013 nicm

Restore missing key binding for %, from Chris Johnsen.


# 1.43 10-Oct-2013 nicm

Remove the barely-used and unnecessary command check() function.


Revision tags: OPENBSD_5_4_BASE
# 1.42 25-Mar-2013 nicm

Revert the command-prefix change which breaks sequences of commands.


# 1.41 24-Mar-2013 nicm

Add resize-pane -Z to temporary zoom the active pane to occupy the full
window or unzoom (restored to the normal layout) if it already zoomed,
bound to C-b z by default. The pane is unzoomed on pretty much any
excuse whatsoever.

We considered making this a new layout but the requirements are quite
different from layouts so decided it is better as a special case. Each
current layout cell is saved, a temporary one-cell layout generated and
all except the active pane set to NULL.

Prompted by suggestions and scripts from several. Thanks to Aaron Jensen
and Thiago Padilha for testing an earlier version.


# 1.40 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.


# 1.39 24-Mar-2013 nicm

Fix error reporting for client commands by adding a flag to
cmd_find_client to tell it whether or not to show errors, sometimes it's
needed and sometimes not.


# 1.38 24-Mar-2013 nicm

Add option command-prefix which is automatically prepended to any
command (apart from a naked default-shell). The default is "exec ".


Revision tags: OPENBSD_5_3_BASE
# 1.37 09-Dec-2012 nicm

Use the CMD_*_USAGE defines consistently, from Thomas Adam.


# 1.36 14-Aug-2012 nicm

Use a separate define for each default format template and strip clutter
from the choose-tree defaults.


Revision tags: OPENBSD_5_2_BASE
# 1.35 11-Jul-2012 nicm

Make command exec functions return an enum rather than -1/0/1 values and
add a new value to mean "leave client running but don't attach" to fix
problems with using some commands in a command sequence. Most of the
work by Thomas Adam, problem reported by "jspenguin" on SF bug 3535531.


# 1.34 10-Jul-2012 nicm

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


# 1.33 22-May-2012 nicm

Switch all of the various choose- and list- commands over to the format
infrastructure, from Thomas Adam.


# 1.32 17-Mar-2012 nicm

Add notify hooks for various events, the functions are currently empty
stubs but will be filled in for control mode later. From George Nachman.


# 1.31 04-Mar-2012 nicm

free -> xfree.


# 1.30 04-Mar-2012 nicm

Add -F format to new-window and split-window to use with the -P flag,
from George Nachman.


# 1.29 03-Mar-2012 nicm

Add move-pane command (like join-pane but allows the same window). Also
-b flag to join-pane and move-pane to place the pane to the left or
above. From George Nachman.


Revision tags: OPENBSD_5_1_BASE
# 1.28 31-Jan-2012 nicm

Provide defined ways to set the various default-path possibilities: ~
for home directory, . for server start directory, - for session start
directory and empty for the pane's working directory (the default). All
can also be used as part of a relative path (eg -/foo). Also provide -c
flags to neww and splitw to override default-path setting.

Based on a diff from sthen. ok sthen


# 1.27 20-Jan-2012 nicm

Add some const and fix a warning.


# 1.26 09-Dec-2011 nicm

Change the way the working directory for new processes is discovered. If
default-path isn't empty, it is used. Otherwise:

1) If tmux neww is run from the command line, the working directory of the
client is used.

2) Otherwise sysctl KERN_PROC_CWD is used to retrieve the current
working directory of the process in the active pane.

3) If that fails, the directory where the session was created is used.

Support code by Romain Francois, OpenBSD specific bits by me.

Note this requires a recent userland and kernel with KERN_PROC_CWD.


# 1.25 15-Nov-2011 nicm

Make window_pane_index work the same as window_index, from Ben Boeckel.


# 1.24 30-Aug-2011 nicm

Plug memory leak, from Tiago Cunha.


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE
# 1.23 10-Feb-2011 nicm

Size on split-window is -l not -s. Doh.


# 1.22 04-Jan-2011 nicm

Clean up and simplify tmux command argument parsing.

Originally, tmux commands were parsed in the client process into a
struct with the command data which was then serialised and sent to the
server to be executed. The parsing was later moved into the server (an
argv was sent from the client), but the parse step and intermediate
struct was kept.

This change removes that struct and the separate parse step. Argument
parsing and printing is now common to all commands (in arguments.c) with
each command left with just an optional check function (to validate the
arguments at parse time), the exec function and a function to set up any
key bindings (renamed from the old init function).

This is overall more simple and consistent.

There should be no changes to any commands behaviour or syntax although
as this touches every command please watch for any unexpected changes.


# 1.21 01-Jan-2011 nicm

Add a -P option to new-window and split-window to print the new window
or pane index in target form (useful to pass it into other commands).


Revision tags: OPENBSD_4_8_BASE
# 1.20 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.


Revision tags: OPENBSD_4_7_BASE
# 1.19 07-Jan-2010 nicm

New command, join-pane, to split and move an existing pane into the space (like
splitw then movep, or the reverse of breakp).


# 1.18 07-Jan-2010 nicm

Use the specified pane for size calculations. Doh.


# 1.17 07-Jan-2010 nicm

Change split-window to accept a pane target (it should be split-pane but
renaming the command would be annoying).


# 1.16 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.15 20-Nov-2009 nicm

When -h and -p are given to split-window, calculate the percentage size using
the width instead of the height.


# 1.14 13-Nov-2009 nicm

Get rid of the ugly CMD_CHFLAG macro and use a const string (eg "dDU") in the
command entry structs and a couple of functions to check/set the flags.


# 1.13 21-Sep-2009 nicm

Use KEYC_NONE constant instead of 0 on init.


# 1.12 16-Sep-2009 nicm

Rather than constructing an entire termios struct from ttydefaults.h, just let
forkpty do it and then alter the bits that should be changed after fork. A
little neater and more portable.


# 1.11 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.10 25-Aug-2009 nicm

Print -l and -p when showing command, pointed out by Tiago Cunha.


# 1.9 13-Aug-2009 nicm

When creating a new session from the command-line where there is an external
terminal, copy the termios(4) special characters and use them for new windows
created in the new session. Suggested by Theo.


# 1.8 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.7 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.6 22-Jul-2009 nicm

window_add_pane cannot fail, so remove the unused cause argument and don't
bother to check for a NULL return.


# 1.5 19-Jul-2009 nicm

Improved layout code.

Each window now has a tree of layout cells associated with it. In this tree,
each node is either a horizontal or vertical cell containing a list of other
cells running from left-to-right or top-to-bottom, or a leaf cell which is
associated with a pane.

The major functional changes are:

- panes may now be split arbitrarily both horizontally (splitw -h, C-b %) and
vertically (splitw -v, C-b ");
- panes may be resized both horizontally and vertically (resizep -L/-R/-U/-D,
bound to C-b left/right/up/down and C-b M-left/right/up/down);
- layouts are now applied and then may be modified by resizing or splitting
panes, rather than being fixed and reapplied when the window is resized or
panes are added;
- manual-vertical layout is no longer necessary, and active-only layout is gone
(but may return in future);
- the main-pane layouts now reduce the size of the main pane to fit all panes
if possible.

Thanks to all who tested.


# 1.4 13-Jul-2009 nicm

Having fixed flags for single-character getopt options is a bit hard to
maintain and is only going to get worse as more are used. So instead, add a new
uint64_t member to cmd_entry which is a bitmask of upper and lowercase options
accepted by the command.

This means new single character options can be used without the need to add it
explicitly to the list.


# 1.3 07-Jul-2009 nicm

The fix for default-path (use target session options instead of global options)
is required here as well, doh.


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

lines variable can be -1 (to be ignored), so should be signed. Found by lint.


# 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.110 27-Aug-2021 nicm

Replace %% in command lists (by copying them) for template arguments ,
this means they can be used with {} as well. Also make argument
processing from an existing vector preserve commands. GitHub issue 2858.


# 1.109 21-Aug-2021 nicm

Rename a member to match what it will be in future.


# 1.108 21-Aug-2021 nicm

Add args parsing callback for some future work, currently unused.


# 1.107 20-Aug-2021 nicm

Hide struct args behind a couple of accessor functions.


# 1.106 20-Aug-2021 nicm

Expose args_value struct (will be needed soon) and add some missing frees.


Revision tags: OPENBSD_6_9_BASE
# 1.105 11-Mar-2021 nicm

Add split-window -Z to start the pane zoomed, GitHub issue 2591.


Revision tags: OPENBSD_6_8_BASE
# 1.104 16-May-2020 nicm

Add a client flag 'active-pane' which stores the active pane in the
client and allows it to be changed independently from the real active
pane stored in the window. This is can be used with session groups which
allow an independent current window (although it would be nice to have a
flag for this too and remove session groups). The client active pane is
only really useful interactively, many things (hooks, window-style,
zooming) still use the window active pane.


Revision tags: OPENBSD_6_7_BASE
# 1.103 13-Apr-2020 nicm

Make client -c and -t handling common in cmd-queue.c and try to be
clearer about whether the client is the target client (must have a
session) or not.


# 1.102 13-Apr-2020 nicm

Move cmdq_state into cmd-queue.c.


# 1.101 13-Apr-2020 nicm

Rename cmdq_shared to cmdq_state which will better reflect what it is
(going to be) used for.


# 1.100 13-Apr-2020 nicm

Also move cmdq_item and cmdq_list into cmd-queue.c (this is to make its
use more clearly defined and preparation for some future work).


# 1.99 13-Apr-2020 nicm

Make struct cmd local to cmd.c and move it out of tmux.h.


# 1.98 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.97 16-Mar-2020 nicm

Do not attempt to close a NULL pane when failing to create a new one.


# 1.96 15-Oct-2019 nicm

Add support for percentage sizes for resize-pane ("-x 10%"). Also change
split-window and join-pane -l to accept similar percentages and
deprecate -p. From Anindya Mukherjee.


Revision tags: OPENBSD_6_6_BASE
# 1.95 03-May-2019 nicm

Allow panes to be empty (no command), output can be piped to them with
split-window or display-message -I.


# 1.94 28-Apr-2019 nicm

Support multiple occurances of the same argument. Use this for a new
flag -e to new-window, split-window, respawn-window, respawn-pane to
pass environment variables into the newly created process. From Steffen
Christgau in GitHub issue 1697.


# 1.93 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).


# 1.92 17-Apr-2019 nicm

Break new window and pane creation common code from various commands and
window.c into a separate file spawn.c.


Revision tags: OPENBSD_6_5_BASE
# 1.91 18-Oct-2018 nicm

Support for windows larger than visible on the attached client. This has
been a limitation for a long time.

There are two new options, window-size and default-size, and a new
command, resize-window. The force-width and force-height options and the
session_width and session_height formats have been removed.

The new window-size option tells tmux how to work out the size of
windows: largest means it picks the size of the largest session,
smallest the smallest session (similar to the old behaviour) and manual
means that it does not automatically resize windows. The default is
currently largest but this may change. aggressive-resize modifies the
choice of session for largest and smallest as it did before.

If a window is in a session attached to a client that is too small, only
part of the window is shown. tmux attempts to keep the cursor visible,
so the part of the window displayed is changed as the cursor moves (with
a small delay, to try and avoid excess redrawing when applications
redraw status lines or similar that are not currently visible). The
offset of the visible portion of the window is shown in status-right.

Drawing windows which are larger than the client is not as efficient as
those which fit, particularly when the cursor moves, so it is
recommended to avoid using this on slow machines or networks (set
window-size to smallest or manual).

The resize-window command can be used to resize a window manually. If it
is used, the window-size option is automatically set to manual for the
window (undo this with "setw -u window-size"). resize-window works in a
similar way to resize-pane (-U -D -L -R -x -y flags) but also has -a and
-A flags. -a sets the window to the size of the smallest client (what it
would be if window-size was smallest) and -A the largest.

For the same behaviour as force-width or force-height, use resize-window
-x or -y, and "setw -u window-size" to revert to automatic sizing..

If the global window-size option is set to manual, the default-size
option is used for new windows. If -x or -y is used with new-session,
that sets the default-size option for the new session.

The maximum size of a window is 10000x10000. But expect applications to
complain and much higher memory use if making a window excessively
big. The minimum size is the size required for the current layout
including borders.

The refresh-client command can be used to pan around a window, -U -D -L
-R moves up, down, left or right and -c returns to automatic cursor
tracking. The position is reset when the current window is changed.


Revision tags: OPENBSD_6_4_BASE
# 1.90 24-May-2018 nicm

Make server_client_get_cwd used (almost) everywhere we need to work out
the cwd, and do not fall back to "." as it is pretty useless. GitHub
issue 1331.


Revision tags: OPENBSD_6_3_BASE
# 1.89 16-Mar-2018 nicm

Insert full size panes at the right position, from KOIE Hidetaka in
GitHub issue 1284.


# 1.88 01-Mar-2018 nicm

Expand formats in window and session names.


Revision tags: OPENBSD_6_2_BASE
# 1.87 30-Aug-2017 nicm

Pass flags into cmd_find_from_* to fix prefer-unattached, reported by
Thomas Sattler.


# 1.86 21-Jul-2017 nicm

Add -c for respawn-pane and respawn-window, from J Raynor.


# 1.85 30-May-2017 nicm

Rewrite of choose mode, both to simplify and tidy the code and to add
some modern features.

Now the common code is in mode-tree.c, which provides an API used by the
three modes now separated into window-{buffer,client,tree}.c. Buffer
mode shows buffers, client mode clients and tree mode a tree of
sessions, windows and panes.

Each mode has a common set of key bindings plus a few that are specific
to the mode. Other changes are:

- each mode has a preview pane: for buffers this is the buffer content
(very useful), for others it is a preview of the pane;

- items may be sorted in different ways ('O' key);

- multiple items may be tagged and an operation applied to all of them
(for example, to delete multiple buffers at once);

- in tree mode a command may be run on the selected item (session,
window, pane) or on tagged items (key ':');

- displayed items may be filtered in tree mode by using a format (this
is used to implement find-window) (key 'f');

- the custom format (-F) for the display is no longer available;

- shortcut keys change from 0-9, a-z, A-Z which was always a bit weird
with keys used for other uses to 0-9, M-a to M-z.

Now that the code is simpler, other improvements will come later.

Primary key bindings for each mode are documented under the commands in
the man page (choose-buffer, choose-client, choose-tree).

Parts written by Thomas Adam.


# 1.84 25-Apr-2017 nicm

Do not update TERM into config file parsing has finished.


# 1.83 22-Apr-2017 nicm

Get rid of the extra layer of flags and cmd_prepare() and just store the
CMD_FIND_* flags in the cmd_entry and call it for the command. Commands
with special requirements call it themselves and update the target for
hooks to use.


# 1.82 22-Apr-2017 nicm

Mouse bindings and hooks set up an initial current state when running a
command. This is used for the session, window and pane for all commands
in the command sequence if there is no -t or -s.

However, using it for all commands in the command sequence means that if
the active pane or current session is changed, subsequent commands still
use the previous state. So make commands which explicitly change the
current state (such as neww and selectp) update it themselves for later
commands. Commands which may invalidate the state (like killp) are
already OK because an invalid state will be ignored.

Also fill in the current state for all key bindings rather than just the
mouse, so that any omissions are easier to spot.


# 1.81 21-Apr-2017 nicm

Add cmd_find_from_winlink_pane and use it in a couple of places, and
make functions that can't fail void.


Revision tags: OPENBSD_6_1_BASE
# 1.80 09-Mar-2017 nicm

Move server_fill_environ into environ.c and move some other common code
into it.


# 1.79 08-Mar-2017 nicm

Add a helper function for the most common format_create/defaults/expand
pattern.


# 1.78 27-Feb-2017 nicm

If splitw -b is used, insert the new pane before the current one in the
pane list. This means the numbering is in order (for example for
display-panes) and fixes a problem with redrawing the active pane
borders.


# 1.77 03-Feb-2017 nicm

Add a window or pane id "tag" to each format tree and use it to separate
jobs, this means that if the same job is used for different windows or
panes (for example in pane-border-format), it will be run separately for
each pane.


# 1.76 16-Oct-2016 nicm

Use the notify name string instead of going via an enum and change
existing hooks to use notifys instead.


# 1.75 16-Oct-2016 nicm

Mass rename struct cmd_q to struct cmdq_item and related.


# 1.74 16-Oct-2016 nicm

Rewrite command queue handling. Each client still has a command queue,
but there is also now a global command queue. Instead of command queues
being dispatched on demand from wherever the command happens to be
added, they are now all dispatched from the top level server
loop. Command queues may now also include callbacks as well as commands,
and items may be inserted after the current command as well as at the end.

This all makes command queues significantly more predictable and easier
to use, and avoids the complex multiple nested command queues used by
source-file, if-shell and friends.

A mass rename of struct cmdq to a better name (cmdq_item probably) is
coming.


# 1.73 13-Oct-2016 nicm

Trying to do hooks generically is way too complicated and unreliable and
confusing, particularly trying to automatically figure out what target
hooks should be using. So simplify it:

- drop before hooks entirely, they don't seem to be very useful;

- commands with special requirements now fire their own after hook (for
example, if they change session or window, or if they have -t and -s
and need to choose which one the hook uses as current target);

- commands with no special requirements can have the CMD_AFTERHOOK flag
added and they will use the -t state.

At the moment new-session, new-window, split-window fire their own hook,
and display-message uses the flag. The remaining commands still need to
be looked at.


# 1.72 13-Oct-2016 nicm

Some improvements and bug fixes for hooks:

- Prepare the state again before the "after" hooks are run, because the
command may have killed or moved windows.

- Use the hooks list from the newly prepared target, not the old hooks
list (only matters for new-session really).

- Correctly detect an invalid current state and ignore it in
cmd_find_target ("killw; swapw").

- Change neww, new, killp, killw, splitw, swapp, swapw to update the
current state (used if no explicit target is given) to something more
useful after they have finished. For example, neww changes it to the
newly created window.

Hooks are still relatively new and primitive so there are likely to be
more changes to come.

Parts based on bug reports from Uwe Werler and Iblis Lin.


# 1.71 10-Oct-2016 nicm

Add static in cmd-* and fix a few other nits.


# 1.70 04-Sep-2016 nicm

Add support for performing a full width split (with splitw -f), rather
than splitting the current cell. From Stephen Kent.


Revision tags: OPENBSD_6_0_BASE
# 1.69 06-Jun-2016 nicm

Insert new panes after the pane being split in the list rather than
always after the active pane. This is more sensible when doing it with
commands rather than keys.


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

I no longer use my SourceForge address so replace it.


# 1.67 14-Dec-2015 nicm

Instead of combined flags for -c, -s, -t, split into different sets
using an enum and simplify the parsing code.


# 1.66 13-Dec-2015 nicm

Use member names in cmd_entry definitions so I stop getting confused
about the order.


# 1.65 13-Dec-2015 nicm

Instead of every command resolving the target (-t or -s) itself, prepare
the state (client, session, winlink, pane) for it it before entering the
command. Each command provides some flags that tell the prepare step
what it is expecting.

This is a requirement for having hooks on commands (for example, if you
hook "select-window -t1:2", the hook command should to operate on window
1:2 not whatever it thinks is the current window), and should allow some
other target improvements.

The old cmd_find_* functions remain for the moment but that layer will
be dropped later.

Joint work with Thomas Adam.


# 1.64 11-Dec-2015 nicm

Add cmdq as an argument to format_create and add a format for the
command name (will also be used for more later).


# 1.63 08-Dec-2015 nicm

Remove format_create_flags and just pass flags to format_create.


# 1.62 31-Oct-2015 nicm

Fall back silently to ~ or / rather than checking -c with access(), this
was the old behaviour.


# 1.61 31-Oct-2015 nicm

Because pledge(2) does not allow us to pass directory file descriptors
around, we can't use file descriptors for the working directory because
we will be unable to pass it to a privileged process to tell it where to
read or write files or spawn children. So move tmux back to using
strings for the current working directory. We try to check it exists
with access() when it is set but ultimately fall back to ~ if it fails
at time of use (or / if that fails too).


# 1.60 28-Oct-2015 nicm

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


# 1.59 27-Oct-2015 nicm

Move struct options into options.c.


# 1.58 23-Oct-2015 nicm

Remove some unnecessary checks before free().


Revision tags: OPENBSD_5_8_BASE
# 1.57 26-Apr-2015 nicm

Remove panes from layout if spawning them fails, reported by Anthony J
Bentley.


Revision tags: OPENBSD_5_7_BASE
# 1.56 05-Feb-2015 nicm

Remove a couple of now-unused variables.


# 1.55 05-Feb-2015 nicm

Wrap all the individual format_* calls in a single format_defaults
functions.


# 1.54 12-Nov-2014 nicm

Add -b to splitw like joinw, from Felix Rosencrantz.


# 1.53 20-Oct-2014 nicm

Move template defines back into .c files.


# 1.52 20-Oct-2014 nicm

Instead of setting up the default keys by building the key struct
directly with a helper function in the cmd_entry, include a table of
bind-key commands and pass them through the command parser and a
temporary cmd_q.

As well as being smaller, this will allow default bindings to be command
sequences which will probably be needed soon.


# 1.51 01-Sep-2014 nicm

Various minor style and spacing nits.


Revision tags: OPENBSD_5_6_BASE
# 1.50 13-May-2014 nicm

If multiple arguments are given to new-session, new-window,
split-window, respawn-window or respawn-pane, pass them directly to
execvp() to help avoid quoting problems. One argument still goes to "sh
-c" like before. Requested by many over the years. Patch from J Raynor.


# 1.49 17-Apr-2014 nicm

Set PATH explicitly, either from client or session
environment. Previously it came from the session environment. From J
Raynor.


Revision tags: OPENBSD_5_5_BASE
# 1.48 22-Nov-2013 nicm

Handle empty current directory more gracefully.


# 1.47 10-Oct-2013 nicm

Don't boke when figuring out working directory from configuration file.


# 1.46 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.45 10-Oct-2013 nicm

Support -c for new-session, based on code from J Raynor.


# 1.44 10-Oct-2013 nicm

Restore missing key binding for %, from Chris Johnsen.


# 1.43 10-Oct-2013 nicm

Remove the barely-used and unnecessary command check() function.


Revision tags: OPENBSD_5_4_BASE
# 1.42 25-Mar-2013 nicm

Revert the command-prefix change which breaks sequences of commands.


# 1.41 24-Mar-2013 nicm

Add resize-pane -Z to temporary zoom the active pane to occupy the full
window or unzoom (restored to the normal layout) if it already zoomed,
bound to C-b z by default. The pane is unzoomed on pretty much any
excuse whatsoever.

We considered making this a new layout but the requirements are quite
different from layouts so decided it is better as a special case. Each
current layout cell is saved, a temporary one-cell layout generated and
all except the active pane set to NULL.

Prompted by suggestions and scripts from several. Thanks to Aaron Jensen
and Thiago Padilha for testing an earlier version.


# 1.40 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.


# 1.39 24-Mar-2013 nicm

Fix error reporting for client commands by adding a flag to
cmd_find_client to tell it whether or not to show errors, sometimes it's
needed and sometimes not.


# 1.38 24-Mar-2013 nicm

Add option command-prefix which is automatically prepended to any
command (apart from a naked default-shell). The default is "exec ".


Revision tags: OPENBSD_5_3_BASE
# 1.37 09-Dec-2012 nicm

Use the CMD_*_USAGE defines consistently, from Thomas Adam.


# 1.36 14-Aug-2012 nicm

Use a separate define for each default format template and strip clutter
from the choose-tree defaults.


Revision tags: OPENBSD_5_2_BASE
# 1.35 11-Jul-2012 nicm

Make command exec functions return an enum rather than -1/0/1 values and
add a new value to mean "leave client running but don't attach" to fix
problems with using some commands in a command sequence. Most of the
work by Thomas Adam, problem reported by "jspenguin" on SF bug 3535531.


# 1.34 10-Jul-2012 nicm

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


# 1.33 22-May-2012 nicm

Switch all of the various choose- and list- commands over to the format
infrastructure, from Thomas Adam.


# 1.32 17-Mar-2012 nicm

Add notify hooks for various events, the functions are currently empty
stubs but will be filled in for control mode later. From George Nachman.


# 1.31 04-Mar-2012 nicm

free -> xfree.


# 1.30 04-Mar-2012 nicm

Add -F format to new-window and split-window to use with the -P flag,
from George Nachman.


# 1.29 03-Mar-2012 nicm

Add move-pane command (like join-pane but allows the same window). Also
-b flag to join-pane and move-pane to place the pane to the left or
above. From George Nachman.


Revision tags: OPENBSD_5_1_BASE
# 1.28 31-Jan-2012 nicm

Provide defined ways to set the various default-path possibilities: ~
for home directory, . for server start directory, - for session start
directory and empty for the pane's working directory (the default). All
can also be used as part of a relative path (eg -/foo). Also provide -c
flags to neww and splitw to override default-path setting.

Based on a diff from sthen. ok sthen


# 1.27 20-Jan-2012 nicm

Add some const and fix a warning.


# 1.26 09-Dec-2011 nicm

Change the way the working directory for new processes is discovered. If
default-path isn't empty, it is used. Otherwise:

1) If tmux neww is run from the command line, the working directory of the
client is used.

2) Otherwise sysctl KERN_PROC_CWD is used to retrieve the current
working directory of the process in the active pane.

3) If that fails, the directory where the session was created is used.

Support code by Romain Francois, OpenBSD specific bits by me.

Note this requires a recent userland and kernel with KERN_PROC_CWD.


# 1.25 15-Nov-2011 nicm

Make window_pane_index work the same as window_index, from Ben Boeckel.


# 1.24 30-Aug-2011 nicm

Plug memory leak, from Tiago Cunha.


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE
# 1.23 10-Feb-2011 nicm

Size on split-window is -l not -s. Doh.


# 1.22 04-Jan-2011 nicm

Clean up and simplify tmux command argument parsing.

Originally, tmux commands were parsed in the client process into a
struct with the command data which was then serialised and sent to the
server to be executed. The parsing was later moved into the server (an
argv was sent from the client), but the parse step and intermediate
struct was kept.

This change removes that struct and the separate parse step. Argument
parsing and printing is now common to all commands (in arguments.c) with
each command left with just an optional check function (to validate the
arguments at parse time), the exec function and a function to set up any
key bindings (renamed from the old init function).

This is overall more simple and consistent.

There should be no changes to any commands behaviour or syntax although
as this touches every command please watch for any unexpected changes.


# 1.21 01-Jan-2011 nicm

Add a -P option to new-window and split-window to print the new window
or pane index in target form (useful to pass it into other commands).


Revision tags: OPENBSD_4_8_BASE
# 1.20 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.


Revision tags: OPENBSD_4_7_BASE
# 1.19 07-Jan-2010 nicm

New command, join-pane, to split and move an existing pane into the space (like
splitw then movep, or the reverse of breakp).


# 1.18 07-Jan-2010 nicm

Use the specified pane for size calculations. Doh.


# 1.17 07-Jan-2010 nicm

Change split-window to accept a pane target (it should be split-pane but
renaming the command would be annoying).


# 1.16 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.15 20-Nov-2009 nicm

When -h and -p are given to split-window, calculate the percentage size using
the width instead of the height.


# 1.14 13-Nov-2009 nicm

Get rid of the ugly CMD_CHFLAG macro and use a const string (eg "dDU") in the
command entry structs and a couple of functions to check/set the flags.


# 1.13 21-Sep-2009 nicm

Use KEYC_NONE constant instead of 0 on init.


# 1.12 16-Sep-2009 nicm

Rather than constructing an entire termios struct from ttydefaults.h, just let
forkpty do it and then alter the bits that should be changed after fork. A
little neater and more portable.


# 1.11 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.10 25-Aug-2009 nicm

Print -l and -p when showing command, pointed out by Tiago Cunha.


# 1.9 13-Aug-2009 nicm

When creating a new session from the command-line where there is an external
terminal, copy the termios(4) special characters and use them for new windows
created in the new session. Suggested by Theo.


# 1.8 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.7 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.6 22-Jul-2009 nicm

window_add_pane cannot fail, so remove the unused cause argument and don't
bother to check for a NULL return.


# 1.5 19-Jul-2009 nicm

Improved layout code.

Each window now has a tree of layout cells associated with it. In this tree,
each node is either a horizontal or vertical cell containing a list of other
cells running from left-to-right or top-to-bottom, or a leaf cell which is
associated with a pane.

The major functional changes are:

- panes may now be split arbitrarily both horizontally (splitw -h, C-b %) and
vertically (splitw -v, C-b ");
- panes may be resized both horizontally and vertically (resizep -L/-R/-U/-D,
bound to C-b left/right/up/down and C-b M-left/right/up/down);
- layouts are now applied and then may be modified by resizing or splitting
panes, rather than being fixed and reapplied when the window is resized or
panes are added;
- manual-vertical layout is no longer necessary, and active-only layout is gone
(but may return in future);
- the main-pane layouts now reduce the size of the main pane to fit all panes
if possible.

Thanks to all who tested.


# 1.4 13-Jul-2009 nicm

Having fixed flags for single-character getopt options is a bit hard to
maintain and is only going to get worse as more are used. So instead, add a new
uint64_t member to cmd_entry which is a bitmask of upper and lowercase options
accepted by the command.

This means new single character options can be used without the need to add it
explicitly to the list.


# 1.3 07-Jul-2009 nicm

The fix for default-path (use target session options instead of global options)
is required here as well, doh.


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

lines variable can be -1 (to be ignored), so should be signed. Found by lint.


# 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.109 21-Aug-2021 nicm

Rename a member to match what it will be in future.


# 1.108 21-Aug-2021 nicm

Add args parsing callback for some future work, currently unused.


# 1.107 20-Aug-2021 nicm

Hide struct args behind a couple of accessor functions.


# 1.106 20-Aug-2021 nicm

Expose args_value struct (will be needed soon) and add some missing frees.


Revision tags: OPENBSD_6_9_BASE
# 1.105 11-Mar-2021 nicm

Add split-window -Z to start the pane zoomed, GitHub issue 2591.


Revision tags: OPENBSD_6_8_BASE
# 1.104 16-May-2020 nicm

Add a client flag 'active-pane' which stores the active pane in the
client and allows it to be changed independently from the real active
pane stored in the window. This is can be used with session groups which
allow an independent current window (although it would be nice to have a
flag for this too and remove session groups). The client active pane is
only really useful interactively, many things (hooks, window-style,
zooming) still use the window active pane.


Revision tags: OPENBSD_6_7_BASE
# 1.103 13-Apr-2020 nicm

Make client -c and -t handling common in cmd-queue.c and try to be
clearer about whether the client is the target client (must have a
session) or not.


# 1.102 13-Apr-2020 nicm

Move cmdq_state into cmd-queue.c.


# 1.101 13-Apr-2020 nicm

Rename cmdq_shared to cmdq_state which will better reflect what it is
(going to be) used for.


# 1.100 13-Apr-2020 nicm

Also move cmdq_item and cmdq_list into cmd-queue.c (this is to make its
use more clearly defined and preparation for some future work).


# 1.99 13-Apr-2020 nicm

Make struct cmd local to cmd.c and move it out of tmux.h.


# 1.98 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.97 16-Mar-2020 nicm

Do not attempt to close a NULL pane when failing to create a new one.


# 1.96 15-Oct-2019 nicm

Add support for percentage sizes for resize-pane ("-x 10%"). Also change
split-window and join-pane -l to accept similar percentages and
deprecate -p. From Anindya Mukherjee.


Revision tags: OPENBSD_6_6_BASE
# 1.95 03-May-2019 nicm

Allow panes to be empty (no command), output can be piped to them with
split-window or display-message -I.


# 1.94 28-Apr-2019 nicm

Support multiple occurances of the same argument. Use this for a new
flag -e to new-window, split-window, respawn-window, respawn-pane to
pass environment variables into the newly created process. From Steffen
Christgau in GitHub issue 1697.


# 1.93 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).


# 1.92 17-Apr-2019 nicm

Break new window and pane creation common code from various commands and
window.c into a separate file spawn.c.


Revision tags: OPENBSD_6_5_BASE
# 1.91 18-Oct-2018 nicm

Support for windows larger than visible on the attached client. This has
been a limitation for a long time.

There are two new options, window-size and default-size, and a new
command, resize-window. The force-width and force-height options and the
session_width and session_height formats have been removed.

The new window-size option tells tmux how to work out the size of
windows: largest means it picks the size of the largest session,
smallest the smallest session (similar to the old behaviour) and manual
means that it does not automatically resize windows. The default is
currently largest but this may change. aggressive-resize modifies the
choice of session for largest and smallest as it did before.

If a window is in a session attached to a client that is too small, only
part of the window is shown. tmux attempts to keep the cursor visible,
so the part of the window displayed is changed as the cursor moves (with
a small delay, to try and avoid excess redrawing when applications
redraw status lines or similar that are not currently visible). The
offset of the visible portion of the window is shown in status-right.

Drawing windows which are larger than the client is not as efficient as
those which fit, particularly when the cursor moves, so it is
recommended to avoid using this on slow machines or networks (set
window-size to smallest or manual).

The resize-window command can be used to resize a window manually. If it
is used, the window-size option is automatically set to manual for the
window (undo this with "setw -u window-size"). resize-window works in a
similar way to resize-pane (-U -D -L -R -x -y flags) but also has -a and
-A flags. -a sets the window to the size of the smallest client (what it
would be if window-size was smallest) and -A the largest.

For the same behaviour as force-width or force-height, use resize-window
-x or -y, and "setw -u window-size" to revert to automatic sizing..

If the global window-size option is set to manual, the default-size
option is used for new windows. If -x or -y is used with new-session,
that sets the default-size option for the new session.

The maximum size of a window is 10000x10000. But expect applications to
complain and much higher memory use if making a window excessively
big. The minimum size is the size required for the current layout
including borders.

The refresh-client command can be used to pan around a window, -U -D -L
-R moves up, down, left or right and -c returns to automatic cursor
tracking. The position is reset when the current window is changed.


Revision tags: OPENBSD_6_4_BASE
# 1.90 24-May-2018 nicm

Make server_client_get_cwd used (almost) everywhere we need to work out
the cwd, and do not fall back to "." as it is pretty useless. GitHub
issue 1331.


Revision tags: OPENBSD_6_3_BASE
# 1.89 16-Mar-2018 nicm

Insert full size panes at the right position, from KOIE Hidetaka in
GitHub issue 1284.


# 1.88 01-Mar-2018 nicm

Expand formats in window and session names.


Revision tags: OPENBSD_6_2_BASE
# 1.87 30-Aug-2017 nicm

Pass flags into cmd_find_from_* to fix prefer-unattached, reported by
Thomas Sattler.


# 1.86 21-Jul-2017 nicm

Add -c for respawn-pane and respawn-window, from J Raynor.


# 1.85 30-May-2017 nicm

Rewrite of choose mode, both to simplify and tidy the code and to add
some modern features.

Now the common code is in mode-tree.c, which provides an API used by the
three modes now separated into window-{buffer,client,tree}.c. Buffer
mode shows buffers, client mode clients and tree mode a tree of
sessions, windows and panes.

Each mode has a common set of key bindings plus a few that are specific
to the mode. Other changes are:

- each mode has a preview pane: for buffers this is the buffer content
(very useful), for others it is a preview of the pane;

- items may be sorted in different ways ('O' key);

- multiple items may be tagged and an operation applied to all of them
(for example, to delete multiple buffers at once);

- in tree mode a command may be run on the selected item (session,
window, pane) or on tagged items (key ':');

- displayed items may be filtered in tree mode by using a format (this
is used to implement find-window) (key 'f');

- the custom format (-F) for the display is no longer available;

- shortcut keys change from 0-9, a-z, A-Z which was always a bit weird
with keys used for other uses to 0-9, M-a to M-z.

Now that the code is simpler, other improvements will come later.

Primary key bindings for each mode are documented under the commands in
the man page (choose-buffer, choose-client, choose-tree).

Parts written by Thomas Adam.


# 1.84 25-Apr-2017 nicm

Do not update TERM into config file parsing has finished.


# 1.83 22-Apr-2017 nicm

Get rid of the extra layer of flags and cmd_prepare() and just store the
CMD_FIND_* flags in the cmd_entry and call it for the command. Commands
with special requirements call it themselves and update the target for
hooks to use.


# 1.82 22-Apr-2017 nicm

Mouse bindings and hooks set up an initial current state when running a
command. This is used for the session, window and pane for all commands
in the command sequence if there is no -t or -s.

However, using it for all commands in the command sequence means that if
the active pane or current session is changed, subsequent commands still
use the previous state. So make commands which explicitly change the
current state (such as neww and selectp) update it themselves for later
commands. Commands which may invalidate the state (like killp) are
already OK because an invalid state will be ignored.

Also fill in the current state for all key bindings rather than just the
mouse, so that any omissions are easier to spot.


# 1.81 21-Apr-2017 nicm

Add cmd_find_from_winlink_pane and use it in a couple of places, and
make functions that can't fail void.


Revision tags: OPENBSD_6_1_BASE
# 1.80 09-Mar-2017 nicm

Move server_fill_environ into environ.c and move some other common code
into it.


# 1.79 08-Mar-2017 nicm

Add a helper function for the most common format_create/defaults/expand
pattern.


# 1.78 27-Feb-2017 nicm

If splitw -b is used, insert the new pane before the current one in the
pane list. This means the numbering is in order (for example for
display-panes) and fixes a problem with redrawing the active pane
borders.


# 1.77 03-Feb-2017 nicm

Add a window or pane id "tag" to each format tree and use it to separate
jobs, this means that if the same job is used for different windows or
panes (for example in pane-border-format), it will be run separately for
each pane.


# 1.76 16-Oct-2016 nicm

Use the notify name string instead of going via an enum and change
existing hooks to use notifys instead.


# 1.75 16-Oct-2016 nicm

Mass rename struct cmd_q to struct cmdq_item and related.


# 1.74 16-Oct-2016 nicm

Rewrite command queue handling. Each client still has a command queue,
but there is also now a global command queue. Instead of command queues
being dispatched on demand from wherever the command happens to be
added, they are now all dispatched from the top level server
loop. Command queues may now also include callbacks as well as commands,
and items may be inserted after the current command as well as at the end.

This all makes command queues significantly more predictable and easier
to use, and avoids the complex multiple nested command queues used by
source-file, if-shell and friends.

A mass rename of struct cmdq to a better name (cmdq_item probably) is
coming.


# 1.73 13-Oct-2016 nicm

Trying to do hooks generically is way too complicated and unreliable and
confusing, particularly trying to automatically figure out what target
hooks should be using. So simplify it:

- drop before hooks entirely, they don't seem to be very useful;

- commands with special requirements now fire their own after hook (for
example, if they change session or window, or if they have -t and -s
and need to choose which one the hook uses as current target);

- commands with no special requirements can have the CMD_AFTERHOOK flag
added and they will use the -t state.

At the moment new-session, new-window, split-window fire their own hook,
and display-message uses the flag. The remaining commands still need to
be looked at.


# 1.72 13-Oct-2016 nicm

Some improvements and bug fixes for hooks:

- Prepare the state again before the "after" hooks are run, because the
command may have killed or moved windows.

- Use the hooks list from the newly prepared target, not the old hooks
list (only matters for new-session really).

- Correctly detect an invalid current state and ignore it in
cmd_find_target ("killw; swapw").

- Change neww, new, killp, killw, splitw, swapp, swapw to update the
current state (used if no explicit target is given) to something more
useful after they have finished. For example, neww changes it to the
newly created window.

Hooks are still relatively new and primitive so there are likely to be
more changes to come.

Parts based on bug reports from Uwe Werler and Iblis Lin.


# 1.71 10-Oct-2016 nicm

Add static in cmd-* and fix a few other nits.


# 1.70 04-Sep-2016 nicm

Add support for performing a full width split (with splitw -f), rather
than splitting the current cell. From Stephen Kent.


Revision tags: OPENBSD_6_0_BASE
# 1.69 06-Jun-2016 nicm

Insert new panes after the pane being split in the list rather than
always after the active pane. This is more sensible when doing it with
commands rather than keys.


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

I no longer use my SourceForge address so replace it.


# 1.67 14-Dec-2015 nicm

Instead of combined flags for -c, -s, -t, split into different sets
using an enum and simplify the parsing code.


# 1.66 13-Dec-2015 nicm

Use member names in cmd_entry definitions so I stop getting confused
about the order.


# 1.65 13-Dec-2015 nicm

Instead of every command resolving the target (-t or -s) itself, prepare
the state (client, session, winlink, pane) for it it before entering the
command. Each command provides some flags that tell the prepare step
what it is expecting.

This is a requirement for having hooks on commands (for example, if you
hook "select-window -t1:2", the hook command should to operate on window
1:2 not whatever it thinks is the current window), and should allow some
other target improvements.

The old cmd_find_* functions remain for the moment but that layer will
be dropped later.

Joint work with Thomas Adam.


# 1.64 11-Dec-2015 nicm

Add cmdq as an argument to format_create and add a format for the
command name (will also be used for more later).


# 1.63 08-Dec-2015 nicm

Remove format_create_flags and just pass flags to format_create.


# 1.62 31-Oct-2015 nicm

Fall back silently to ~ or / rather than checking -c with access(), this
was the old behaviour.


# 1.61 31-Oct-2015 nicm

Because pledge(2) does not allow us to pass directory file descriptors
around, we can't use file descriptors for the working directory because
we will be unable to pass it to a privileged process to tell it where to
read or write files or spawn children. So move tmux back to using
strings for the current working directory. We try to check it exists
with access() when it is set but ultimately fall back to ~ if it fails
at time of use (or / if that fails too).


# 1.60 28-Oct-2015 nicm

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


# 1.59 27-Oct-2015 nicm

Move struct options into options.c.


# 1.58 23-Oct-2015 nicm

Remove some unnecessary checks before free().


Revision tags: OPENBSD_5_8_BASE
# 1.57 26-Apr-2015 nicm

Remove panes from layout if spawning them fails, reported by Anthony J
Bentley.


Revision tags: OPENBSD_5_7_BASE
# 1.56 05-Feb-2015 nicm

Remove a couple of now-unused variables.


# 1.55 05-Feb-2015 nicm

Wrap all the individual format_* calls in a single format_defaults
functions.


# 1.54 12-Nov-2014 nicm

Add -b to splitw like joinw, from Felix Rosencrantz.


# 1.53 20-Oct-2014 nicm

Move template defines back into .c files.


# 1.52 20-Oct-2014 nicm

Instead of setting up the default keys by building the key struct
directly with a helper function in the cmd_entry, include a table of
bind-key commands and pass them through the command parser and a
temporary cmd_q.

As well as being smaller, this will allow default bindings to be command
sequences which will probably be needed soon.


# 1.51 01-Sep-2014 nicm

Various minor style and spacing nits.


Revision tags: OPENBSD_5_6_BASE
# 1.50 13-May-2014 nicm

If multiple arguments are given to new-session, new-window,
split-window, respawn-window or respawn-pane, pass them directly to
execvp() to help avoid quoting problems. One argument still goes to "sh
-c" like before. Requested by many over the years. Patch from J Raynor.


# 1.49 17-Apr-2014 nicm

Set PATH explicitly, either from client or session
environment. Previously it came from the session environment. From J
Raynor.


Revision tags: OPENBSD_5_5_BASE
# 1.48 22-Nov-2013 nicm

Handle empty current directory more gracefully.


# 1.47 10-Oct-2013 nicm

Don't boke when figuring out working directory from configuration file.


# 1.46 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.45 10-Oct-2013 nicm

Support -c for new-session, based on code from J Raynor.


# 1.44 10-Oct-2013 nicm

Restore missing key binding for %, from Chris Johnsen.


# 1.43 10-Oct-2013 nicm

Remove the barely-used and unnecessary command check() function.


Revision tags: OPENBSD_5_4_BASE
# 1.42 25-Mar-2013 nicm

Revert the command-prefix change which breaks sequences of commands.


# 1.41 24-Mar-2013 nicm

Add resize-pane -Z to temporary zoom the active pane to occupy the full
window or unzoom (restored to the normal layout) if it already zoomed,
bound to C-b z by default. The pane is unzoomed on pretty much any
excuse whatsoever.

We considered making this a new layout but the requirements are quite
different from layouts so decided it is better as a special case. Each
current layout cell is saved, a temporary one-cell layout generated and
all except the active pane set to NULL.

Prompted by suggestions and scripts from several. Thanks to Aaron Jensen
and Thiago Padilha for testing an earlier version.


# 1.40 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.


# 1.39 24-Mar-2013 nicm

Fix error reporting for client commands by adding a flag to
cmd_find_client to tell it whether or not to show errors, sometimes it's
needed and sometimes not.


# 1.38 24-Mar-2013 nicm

Add option command-prefix which is automatically prepended to any
command (apart from a naked default-shell). The default is "exec ".


Revision tags: OPENBSD_5_3_BASE
# 1.37 09-Dec-2012 nicm

Use the CMD_*_USAGE defines consistently, from Thomas Adam.


# 1.36 14-Aug-2012 nicm

Use a separate define for each default format template and strip clutter
from the choose-tree defaults.


Revision tags: OPENBSD_5_2_BASE
# 1.35 11-Jul-2012 nicm

Make command exec functions return an enum rather than -1/0/1 values and
add a new value to mean "leave client running but don't attach" to fix
problems with using some commands in a command sequence. Most of the
work by Thomas Adam, problem reported by "jspenguin" on SF bug 3535531.


# 1.34 10-Jul-2012 nicm

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


# 1.33 22-May-2012 nicm

Switch all of the various choose- and list- commands over to the format
infrastructure, from Thomas Adam.


# 1.32 17-Mar-2012 nicm

Add notify hooks for various events, the functions are currently empty
stubs but will be filled in for control mode later. From George Nachman.


# 1.31 04-Mar-2012 nicm

free -> xfree.


# 1.30 04-Mar-2012 nicm

Add -F format to new-window and split-window to use with the -P flag,
from George Nachman.


# 1.29 03-Mar-2012 nicm

Add move-pane command (like join-pane but allows the same window). Also
-b flag to join-pane and move-pane to place the pane to the left or
above. From George Nachman.


Revision tags: OPENBSD_5_1_BASE
# 1.28 31-Jan-2012 nicm

Provide defined ways to set the various default-path possibilities: ~
for home directory, . for server start directory, - for session start
directory and empty for the pane's working directory (the default). All
can also be used as part of a relative path (eg -/foo). Also provide -c
flags to neww and splitw to override default-path setting.

Based on a diff from sthen. ok sthen


# 1.27 20-Jan-2012 nicm

Add some const and fix a warning.


# 1.26 09-Dec-2011 nicm

Change the way the working directory for new processes is discovered. If
default-path isn't empty, it is used. Otherwise:

1) If tmux neww is run from the command line, the working directory of the
client is used.

2) Otherwise sysctl KERN_PROC_CWD is used to retrieve the current
working directory of the process in the active pane.

3) If that fails, the directory where the session was created is used.

Support code by Romain Francois, OpenBSD specific bits by me.

Note this requires a recent userland and kernel with KERN_PROC_CWD.


# 1.25 15-Nov-2011 nicm

Make window_pane_index work the same as window_index, from Ben Boeckel.


# 1.24 30-Aug-2011 nicm

Plug memory leak, from Tiago Cunha.


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE
# 1.23 10-Feb-2011 nicm

Size on split-window is -l not -s. Doh.


# 1.22 04-Jan-2011 nicm

Clean up and simplify tmux command argument parsing.

Originally, tmux commands were parsed in the client process into a
struct with the command data which was then serialised and sent to the
server to be executed. The parsing was later moved into the server (an
argv was sent from the client), but the parse step and intermediate
struct was kept.

This change removes that struct and the separate parse step. Argument
parsing and printing is now common to all commands (in arguments.c) with
each command left with just an optional check function (to validate the
arguments at parse time), the exec function and a function to set up any
key bindings (renamed from the old init function).

This is overall more simple and consistent.

There should be no changes to any commands behaviour or syntax although
as this touches every command please watch for any unexpected changes.


# 1.21 01-Jan-2011 nicm

Add a -P option to new-window and split-window to print the new window
or pane index in target form (useful to pass it into other commands).


Revision tags: OPENBSD_4_8_BASE
# 1.20 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.


Revision tags: OPENBSD_4_7_BASE
# 1.19 07-Jan-2010 nicm

New command, join-pane, to split and move an existing pane into the space (like
splitw then movep, or the reverse of breakp).


# 1.18 07-Jan-2010 nicm

Use the specified pane for size calculations. Doh.


# 1.17 07-Jan-2010 nicm

Change split-window to accept a pane target (it should be split-pane but
renaming the command would be annoying).


# 1.16 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.15 20-Nov-2009 nicm

When -h and -p are given to split-window, calculate the percentage size using
the width instead of the height.


# 1.14 13-Nov-2009 nicm

Get rid of the ugly CMD_CHFLAG macro and use a const string (eg "dDU") in the
command entry structs and a couple of functions to check/set the flags.


# 1.13 21-Sep-2009 nicm

Use KEYC_NONE constant instead of 0 on init.


# 1.12 16-Sep-2009 nicm

Rather than constructing an entire termios struct from ttydefaults.h, just let
forkpty do it and then alter the bits that should be changed after fork. A
little neater and more portable.


# 1.11 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.10 25-Aug-2009 nicm

Print -l and -p when showing command, pointed out by Tiago Cunha.


# 1.9 13-Aug-2009 nicm

When creating a new session from the command-line where there is an external
terminal, copy the termios(4) special characters and use them for new windows
created in the new session. Suggested by Theo.


# 1.8 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.7 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.6 22-Jul-2009 nicm

window_add_pane cannot fail, so remove the unused cause argument and don't
bother to check for a NULL return.


# 1.5 19-Jul-2009 nicm

Improved layout code.

Each window now has a tree of layout cells associated with it. In this tree,
each node is either a horizontal or vertical cell containing a list of other
cells running from left-to-right or top-to-bottom, or a leaf cell which is
associated with a pane.

The major functional changes are:

- panes may now be split arbitrarily both horizontally (splitw -h, C-b %) and
vertically (splitw -v, C-b ");
- panes may be resized both horizontally and vertically (resizep -L/-R/-U/-D,
bound to C-b left/right/up/down and C-b M-left/right/up/down);
- layouts are now applied and then may be modified by resizing or splitting
panes, rather than being fixed and reapplied when the window is resized or
panes are added;
- manual-vertical layout is no longer necessary, and active-only layout is gone
(but may return in future);
- the main-pane layouts now reduce the size of the main pane to fit all panes
if possible.

Thanks to all who tested.


# 1.4 13-Jul-2009 nicm

Having fixed flags for single-character getopt options is a bit hard to
maintain and is only going to get worse as more are used. So instead, add a new
uint64_t member to cmd_entry which is a bitmask of upper and lowercase options
accepted by the command.

This means new single character options can be used without the need to add it
explicitly to the list.


# 1.3 07-Jul-2009 nicm

The fix for default-path (use target session options instead of global options)
is required here as well, doh.


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

lines variable can be -1 (to be ignored), so should be signed. Found by lint.


# 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.105 11-Mar-2021 nicm

Add split-window -Z to start the pane zoomed, GitHub issue 2591.


Revision tags: OPENBSD_6_8_BASE
# 1.104 16-May-2020 nicm

Add a client flag 'active-pane' which stores the active pane in the
client and allows it to be changed independently from the real active
pane stored in the window. This is can be used with session groups which
allow an independent current window (although it would be nice to have a
flag for this too and remove session groups). The client active pane is
only really useful interactively, many things (hooks, window-style,
zooming) still use the window active pane.


Revision tags: OPENBSD_6_7_BASE
# 1.103 13-Apr-2020 nicm

Make client -c and -t handling common in cmd-queue.c and try to be
clearer about whether the client is the target client (must have a
session) or not.


# 1.102 13-Apr-2020 nicm

Move cmdq_state into cmd-queue.c.


# 1.101 13-Apr-2020 nicm

Rename cmdq_shared to cmdq_state which will better reflect what it is
(going to be) used for.


# 1.100 13-Apr-2020 nicm

Also move cmdq_item and cmdq_list into cmd-queue.c (this is to make its
use more clearly defined and preparation for some future work).


# 1.99 13-Apr-2020 nicm

Make struct cmd local to cmd.c and move it out of tmux.h.


# 1.98 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.97 16-Mar-2020 nicm

Do not attempt to close a NULL pane when failing to create a new one.


# 1.96 15-Oct-2019 nicm

Add support for percentage sizes for resize-pane ("-x 10%"). Also change
split-window and join-pane -l to accept similar percentages and
deprecate -p. From Anindya Mukherjee.


Revision tags: OPENBSD_6_6_BASE
# 1.95 03-May-2019 nicm

Allow panes to be empty (no command), output can be piped to them with
split-window or display-message -I.


# 1.94 28-Apr-2019 nicm

Support multiple occurances of the same argument. Use this for a new
flag -e to new-window, split-window, respawn-window, respawn-pane to
pass environment variables into the newly created process. From Steffen
Christgau in GitHub issue 1697.


# 1.93 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).


# 1.92 17-Apr-2019 nicm

Break new window and pane creation common code from various commands and
window.c into a separate file spawn.c.


Revision tags: OPENBSD_6_5_BASE
# 1.91 18-Oct-2018 nicm

Support for windows larger than visible on the attached client. This has
been a limitation for a long time.

There are two new options, window-size and default-size, and a new
command, resize-window. The force-width and force-height options and the
session_width and session_height formats have been removed.

The new window-size option tells tmux how to work out the size of
windows: largest means it picks the size of the largest session,
smallest the smallest session (similar to the old behaviour) and manual
means that it does not automatically resize windows. The default is
currently largest but this may change. aggressive-resize modifies the
choice of session for largest and smallest as it did before.

If a window is in a session attached to a client that is too small, only
part of the window is shown. tmux attempts to keep the cursor visible,
so the part of the window displayed is changed as the cursor moves (with
a small delay, to try and avoid excess redrawing when applications
redraw status lines or similar that are not currently visible). The
offset of the visible portion of the window is shown in status-right.

Drawing windows which are larger than the client is not as efficient as
those which fit, particularly when the cursor moves, so it is
recommended to avoid using this on slow machines or networks (set
window-size to smallest or manual).

The resize-window command can be used to resize a window manually. If it
is used, the window-size option is automatically set to manual for the
window (undo this with "setw -u window-size"). resize-window works in a
similar way to resize-pane (-U -D -L -R -x -y flags) but also has -a and
-A flags. -a sets the window to the size of the smallest client (what it
would be if window-size was smallest) and -A the largest.

For the same behaviour as force-width or force-height, use resize-window
-x or -y, and "setw -u window-size" to revert to automatic sizing..

If the global window-size option is set to manual, the default-size
option is used for new windows. If -x or -y is used with new-session,
that sets the default-size option for the new session.

The maximum size of a window is 10000x10000. But expect applications to
complain and much higher memory use if making a window excessively
big. The minimum size is the size required for the current layout
including borders.

The refresh-client command can be used to pan around a window, -U -D -L
-R moves up, down, left or right and -c returns to automatic cursor
tracking. The position is reset when the current window is changed.


Revision tags: OPENBSD_6_4_BASE
# 1.90 24-May-2018 nicm

Make server_client_get_cwd used (almost) everywhere we need to work out
the cwd, and do not fall back to "." as it is pretty useless. GitHub
issue 1331.


Revision tags: OPENBSD_6_3_BASE
# 1.89 16-Mar-2018 nicm

Insert full size panes at the right position, from KOIE Hidetaka in
GitHub issue 1284.


# 1.88 01-Mar-2018 nicm

Expand formats in window and session names.


Revision tags: OPENBSD_6_2_BASE
# 1.87 30-Aug-2017 nicm

Pass flags into cmd_find_from_* to fix prefer-unattached, reported by
Thomas Sattler.


# 1.86 21-Jul-2017 nicm

Add -c for respawn-pane and respawn-window, from J Raynor.


# 1.85 30-May-2017 nicm

Rewrite of choose mode, both to simplify and tidy the code and to add
some modern features.

Now the common code is in mode-tree.c, which provides an API used by the
three modes now separated into window-{buffer,client,tree}.c. Buffer
mode shows buffers, client mode clients and tree mode a tree of
sessions, windows and panes.

Each mode has a common set of key bindings plus a few that are specific
to the mode. Other changes are:

- each mode has a preview pane: for buffers this is the buffer content
(very useful), for others it is a preview of the pane;

- items may be sorted in different ways ('O' key);

- multiple items may be tagged and an operation applied to all of them
(for example, to delete multiple buffers at once);

- in tree mode a command may be run on the selected item (session,
window, pane) or on tagged items (key ':');

- displayed items may be filtered in tree mode by using a format (this
is used to implement find-window) (key 'f');

- the custom format (-F) for the display is no longer available;

- shortcut keys change from 0-9, a-z, A-Z which was always a bit weird
with keys used for other uses to 0-9, M-a to M-z.

Now that the code is simpler, other improvements will come later.

Primary key bindings for each mode are documented under the commands in
the man page (choose-buffer, choose-client, choose-tree).

Parts written by Thomas Adam.


# 1.84 25-Apr-2017 nicm

Do not update TERM into config file parsing has finished.


# 1.83 22-Apr-2017 nicm

Get rid of the extra layer of flags and cmd_prepare() and just store the
CMD_FIND_* flags in the cmd_entry and call it for the command. Commands
with special requirements call it themselves and update the target for
hooks to use.


# 1.82 22-Apr-2017 nicm

Mouse bindings and hooks set up an initial current state when running a
command. This is used for the session, window and pane for all commands
in the command sequence if there is no -t or -s.

However, using it for all commands in the command sequence means that if
the active pane or current session is changed, subsequent commands still
use the previous state. So make commands which explicitly change the
current state (such as neww and selectp) update it themselves for later
commands. Commands which may invalidate the state (like killp) are
already OK because an invalid state will be ignored.

Also fill in the current state for all key bindings rather than just the
mouse, so that any omissions are easier to spot.


# 1.81 21-Apr-2017 nicm

Add cmd_find_from_winlink_pane and use it in a couple of places, and
make functions that can't fail void.


Revision tags: OPENBSD_6_1_BASE
# 1.80 09-Mar-2017 nicm

Move server_fill_environ into environ.c and move some other common code
into it.


# 1.79 08-Mar-2017 nicm

Add a helper function for the most common format_create/defaults/expand
pattern.


# 1.78 27-Feb-2017 nicm

If splitw -b is used, insert the new pane before the current one in the
pane list. This means the numbering is in order (for example for
display-panes) and fixes a problem with redrawing the active pane
borders.


# 1.77 03-Feb-2017 nicm

Add a window or pane id "tag" to each format tree and use it to separate
jobs, this means that if the same job is used for different windows or
panes (for example in pane-border-format), it will be run separately for
each pane.


# 1.76 16-Oct-2016 nicm

Use the notify name string instead of going via an enum and change
existing hooks to use notifys instead.


# 1.75 16-Oct-2016 nicm

Mass rename struct cmd_q to struct cmdq_item and related.


# 1.74 16-Oct-2016 nicm

Rewrite command queue handling. Each client still has a command queue,
but there is also now a global command queue. Instead of command queues
being dispatched on demand from wherever the command happens to be
added, they are now all dispatched from the top level server
loop. Command queues may now also include callbacks as well as commands,
and items may be inserted after the current command as well as at the end.

This all makes command queues significantly more predictable and easier
to use, and avoids the complex multiple nested command queues used by
source-file, if-shell and friends.

A mass rename of struct cmdq to a better name (cmdq_item probably) is
coming.


# 1.73 13-Oct-2016 nicm

Trying to do hooks generically is way too complicated and unreliable and
confusing, particularly trying to automatically figure out what target
hooks should be using. So simplify it:

- drop before hooks entirely, they don't seem to be very useful;

- commands with special requirements now fire their own after hook (for
example, if they change session or window, or if they have -t and -s
and need to choose which one the hook uses as current target);

- commands with no special requirements can have the CMD_AFTERHOOK flag
added and they will use the -t state.

At the moment new-session, new-window, split-window fire their own hook,
and display-message uses the flag. The remaining commands still need to
be looked at.


# 1.72 13-Oct-2016 nicm

Some improvements and bug fixes for hooks:

- Prepare the state again before the "after" hooks are run, because the
command may have killed or moved windows.

- Use the hooks list from the newly prepared target, not the old hooks
list (only matters for new-session really).

- Correctly detect an invalid current state and ignore it in
cmd_find_target ("killw; swapw").

- Change neww, new, killp, killw, splitw, swapp, swapw to update the
current state (used if no explicit target is given) to something more
useful after they have finished. For example, neww changes it to the
newly created window.

Hooks are still relatively new and primitive so there are likely to be
more changes to come.

Parts based on bug reports from Uwe Werler and Iblis Lin.


# 1.71 10-Oct-2016 nicm

Add static in cmd-* and fix a few other nits.


# 1.70 04-Sep-2016 nicm

Add support for performing a full width split (with splitw -f), rather
than splitting the current cell. From Stephen Kent.


Revision tags: OPENBSD_6_0_BASE
# 1.69 06-Jun-2016 nicm

Insert new panes after the pane being split in the list rather than
always after the active pane. This is more sensible when doing it with
commands rather than keys.


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

I no longer use my SourceForge address so replace it.


# 1.67 14-Dec-2015 nicm

Instead of combined flags for -c, -s, -t, split into different sets
using an enum and simplify the parsing code.


# 1.66 13-Dec-2015 nicm

Use member names in cmd_entry definitions so I stop getting confused
about the order.


# 1.65 13-Dec-2015 nicm

Instead of every command resolving the target (-t or -s) itself, prepare
the state (client, session, winlink, pane) for it it before entering the
command. Each command provides some flags that tell the prepare step
what it is expecting.

This is a requirement for having hooks on commands (for example, if you
hook "select-window -t1:2", the hook command should to operate on window
1:2 not whatever it thinks is the current window), and should allow some
other target improvements.

The old cmd_find_* functions remain for the moment but that layer will
be dropped later.

Joint work with Thomas Adam.


# 1.64 11-Dec-2015 nicm

Add cmdq as an argument to format_create and add a format for the
command name (will also be used for more later).


# 1.63 08-Dec-2015 nicm

Remove format_create_flags and just pass flags to format_create.


# 1.62 31-Oct-2015 nicm

Fall back silently to ~ or / rather than checking -c with access(), this
was the old behaviour.


# 1.61 31-Oct-2015 nicm

Because pledge(2) does not allow us to pass directory file descriptors
around, we can't use file descriptors for the working directory because
we will be unable to pass it to a privileged process to tell it where to
read or write files or spawn children. So move tmux back to using
strings for the current working directory. We try to check it exists
with access() when it is set but ultimately fall back to ~ if it fails
at time of use (or / if that fails too).


# 1.60 28-Oct-2015 nicm

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


# 1.59 27-Oct-2015 nicm

Move struct options into options.c.


# 1.58 23-Oct-2015 nicm

Remove some unnecessary checks before free().


Revision tags: OPENBSD_5_8_BASE
# 1.57 26-Apr-2015 nicm

Remove panes from layout if spawning them fails, reported by Anthony J
Bentley.


Revision tags: OPENBSD_5_7_BASE
# 1.56 05-Feb-2015 nicm

Remove a couple of now-unused variables.


# 1.55 05-Feb-2015 nicm

Wrap all the individual format_* calls in a single format_defaults
functions.


# 1.54 12-Nov-2014 nicm

Add -b to splitw like joinw, from Felix Rosencrantz.


# 1.53 20-Oct-2014 nicm

Move template defines back into .c files.


# 1.52 20-Oct-2014 nicm

Instead of setting up the default keys by building the key struct
directly with a helper function in the cmd_entry, include a table of
bind-key commands and pass them through the command parser and a
temporary cmd_q.

As well as being smaller, this will allow default bindings to be command
sequences which will probably be needed soon.


# 1.51 01-Sep-2014 nicm

Various minor style and spacing nits.


Revision tags: OPENBSD_5_6_BASE
# 1.50 13-May-2014 nicm

If multiple arguments are given to new-session, new-window,
split-window, respawn-window or respawn-pane, pass them directly to
execvp() to help avoid quoting problems. One argument still goes to "sh
-c" like before. Requested by many over the years. Patch from J Raynor.


# 1.49 17-Apr-2014 nicm

Set PATH explicitly, either from client or session
environment. Previously it came from the session environment. From J
Raynor.


Revision tags: OPENBSD_5_5_BASE
# 1.48 22-Nov-2013 nicm

Handle empty current directory more gracefully.


# 1.47 10-Oct-2013 nicm

Don't boke when figuring out working directory from configuration file.


# 1.46 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.45 10-Oct-2013 nicm

Support -c for new-session, based on code from J Raynor.


# 1.44 10-Oct-2013 nicm

Restore missing key binding for %, from Chris Johnsen.


# 1.43 10-Oct-2013 nicm

Remove the barely-used and unnecessary command check() function.


Revision tags: OPENBSD_5_4_BASE
# 1.42 25-Mar-2013 nicm

Revert the command-prefix change which breaks sequences of commands.


# 1.41 24-Mar-2013 nicm

Add resize-pane -Z to temporary zoom the active pane to occupy the full
window or unzoom (restored to the normal layout) if it already zoomed,
bound to C-b z by default. The pane is unzoomed on pretty much any
excuse whatsoever.

We considered making this a new layout but the requirements are quite
different from layouts so decided it is better as a special case. Each
current layout cell is saved, a temporary one-cell layout generated and
all except the active pane set to NULL.

Prompted by suggestions and scripts from several. Thanks to Aaron Jensen
and Thiago Padilha for testing an earlier version.


# 1.40 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.


# 1.39 24-Mar-2013 nicm

Fix error reporting for client commands by adding a flag to
cmd_find_client to tell it whether or not to show errors, sometimes it's
needed and sometimes not.


# 1.38 24-Mar-2013 nicm

Add option command-prefix which is automatically prepended to any
command (apart from a naked default-shell). The default is "exec ".


Revision tags: OPENBSD_5_3_BASE
# 1.37 09-Dec-2012 nicm

Use the CMD_*_USAGE defines consistently, from Thomas Adam.


# 1.36 14-Aug-2012 nicm

Use a separate define for each default format template and strip clutter
from the choose-tree defaults.


Revision tags: OPENBSD_5_2_BASE
# 1.35 11-Jul-2012 nicm

Make command exec functions return an enum rather than -1/0/1 values and
add a new value to mean "leave client running but don't attach" to fix
problems with using some commands in a command sequence. Most of the
work by Thomas Adam, problem reported by "jspenguin" on SF bug 3535531.


# 1.34 10-Jul-2012 nicm

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


# 1.33 22-May-2012 nicm

Switch all of the various choose- and list- commands over to the format
infrastructure, from Thomas Adam.


# 1.32 17-Mar-2012 nicm

Add notify hooks for various events, the functions are currently empty
stubs but will be filled in for control mode later. From George Nachman.


# 1.31 04-Mar-2012 nicm

free -> xfree.


# 1.30 04-Mar-2012 nicm

Add -F format to new-window and split-window to use with the -P flag,
from George Nachman.


# 1.29 03-Mar-2012 nicm

Add move-pane command (like join-pane but allows the same window). Also
-b flag to join-pane and move-pane to place the pane to the left or
above. From George Nachman.


Revision tags: OPENBSD_5_1_BASE
# 1.28 31-Jan-2012 nicm

Provide defined ways to set the various default-path possibilities: ~
for home directory, . for server start directory, - for session start
directory and empty for the pane's working directory (the default). All
can also be used as part of a relative path (eg -/foo). Also provide -c
flags to neww and splitw to override default-path setting.

Based on a diff from sthen. ok sthen


# 1.27 20-Jan-2012 nicm

Add some const and fix a warning.


# 1.26 09-Dec-2011 nicm

Change the way the working directory for new processes is discovered. If
default-path isn't empty, it is used. Otherwise:

1) If tmux neww is run from the command line, the working directory of the
client is used.

2) Otherwise sysctl KERN_PROC_CWD is used to retrieve the current
working directory of the process in the active pane.

3) If that fails, the directory where the session was created is used.

Support code by Romain Francois, OpenBSD specific bits by me.

Note this requires a recent userland and kernel with KERN_PROC_CWD.


# 1.25 15-Nov-2011 nicm

Make window_pane_index work the same as window_index, from Ben Boeckel.


# 1.24 30-Aug-2011 nicm

Plug memory leak, from Tiago Cunha.


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE
# 1.23 10-Feb-2011 nicm

Size on split-window is -l not -s. Doh.


# 1.22 04-Jan-2011 nicm

Clean up and simplify tmux command argument parsing.

Originally, tmux commands were parsed in the client process into a
struct with the command data which was then serialised and sent to the
server to be executed. The parsing was later moved into the server (an
argv was sent from the client), but the parse step and intermediate
struct was kept.

This change removes that struct and the separate parse step. Argument
parsing and printing is now common to all commands (in arguments.c) with
each command left with just an optional check function (to validate the
arguments at parse time), the exec function and a function to set up any
key bindings (renamed from the old init function).

This is overall more simple and consistent.

There should be no changes to any commands behaviour or syntax although
as this touches every command please watch for any unexpected changes.


# 1.21 01-Jan-2011 nicm

Add a -P option to new-window and split-window to print the new window
or pane index in target form (useful to pass it into other commands).


Revision tags: OPENBSD_4_8_BASE
# 1.20 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.


Revision tags: OPENBSD_4_7_BASE
# 1.19 07-Jan-2010 nicm

New command, join-pane, to split and move an existing pane into the space (like
splitw then movep, or the reverse of breakp).


# 1.18 07-Jan-2010 nicm

Use the specified pane for size calculations. Doh.


# 1.17 07-Jan-2010 nicm

Change split-window to accept a pane target (it should be split-pane but
renaming the command would be annoying).


# 1.16 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.15 20-Nov-2009 nicm

When -h and -p are given to split-window, calculate the percentage size using
the width instead of the height.


# 1.14 13-Nov-2009 nicm

Get rid of the ugly CMD_CHFLAG macro and use a const string (eg "dDU") in the
command entry structs and a couple of functions to check/set the flags.


# 1.13 21-Sep-2009 nicm

Use KEYC_NONE constant instead of 0 on init.


# 1.12 16-Sep-2009 nicm

Rather than constructing an entire termios struct from ttydefaults.h, just let
forkpty do it and then alter the bits that should be changed after fork. A
little neater and more portable.


# 1.11 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.10 25-Aug-2009 nicm

Print -l and -p when showing command, pointed out by Tiago Cunha.


# 1.9 13-Aug-2009 nicm

When creating a new session from the command-line where there is an external
terminal, copy the termios(4) special characters and use them for new windows
created in the new session. Suggested by Theo.


# 1.8 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.7 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.6 22-Jul-2009 nicm

window_add_pane cannot fail, so remove the unused cause argument and don't
bother to check for a NULL return.


# 1.5 19-Jul-2009 nicm

Improved layout code.

Each window now has a tree of layout cells associated with it. In this tree,
each node is either a horizontal or vertical cell containing a list of other
cells running from left-to-right or top-to-bottom, or a leaf cell which is
associated with a pane.

The major functional changes are:

- panes may now be split arbitrarily both horizontally (splitw -h, C-b %) and
vertically (splitw -v, C-b ");
- panes may be resized both horizontally and vertically (resizep -L/-R/-U/-D,
bound to C-b left/right/up/down and C-b M-left/right/up/down);
- layouts are now applied and then may be modified by resizing or splitting
panes, rather than being fixed and reapplied when the window is resized or
panes are added;
- manual-vertical layout is no longer necessary, and active-only layout is gone
(but may return in future);
- the main-pane layouts now reduce the size of the main pane to fit all panes
if possible.

Thanks to all who tested.


# 1.4 13-Jul-2009 nicm

Having fixed flags for single-character getopt options is a bit hard to
maintain and is only going to get worse as more are used. So instead, add a new
uint64_t member to cmd_entry which is a bitmask of upper and lowercase options
accepted by the command.

This means new single character options can be used without the need to add it
explicitly to the list.


# 1.3 07-Jul-2009 nicm

The fix for default-path (use target session options instead of global options)
is required here as well, doh.


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

lines variable can be -1 (to be ignored), so should be signed. Found by lint.


# 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.104 16-May-2020 nicm

Add a client flag 'active-pane' which stores the active pane in the
client and allows it to be changed independently from the real active
pane stored in the window. This is can be used with session groups which
allow an independent current window (although it would be nice to have a
flag for this too and remove session groups). The client active pane is
only really useful interactively, many things (hooks, window-style,
zooming) still use the window active pane.


Revision tags: OPENBSD_6_7_BASE
# 1.103 13-Apr-2020 nicm

Make client -c and -t handling common in cmd-queue.c and try to be
clearer about whether the client is the target client (must have a
session) or not.


# 1.102 13-Apr-2020 nicm

Move cmdq_state into cmd-queue.c.


# 1.101 13-Apr-2020 nicm

Rename cmdq_shared to cmdq_state which will better reflect what it is
(going to be) used for.


# 1.100 13-Apr-2020 nicm

Also move cmdq_item and cmdq_list into cmd-queue.c (this is to make its
use more clearly defined and preparation for some future work).


# 1.99 13-Apr-2020 nicm

Make struct cmd local to cmd.c and move it out of tmux.h.


# 1.98 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.97 16-Mar-2020 nicm

Do not attempt to close a NULL pane when failing to create a new one.


# 1.96 15-Oct-2019 nicm

Add support for percentage sizes for resize-pane ("-x 10%"). Also change
split-window and join-pane -l to accept similar percentages and
deprecate -p. From Anindya Mukherjee.


Revision tags: OPENBSD_6_6_BASE
# 1.95 03-May-2019 nicm

Allow panes to be empty (no command), output can be piped to them with
split-window or display-message -I.


# 1.94 28-Apr-2019 nicm

Support multiple occurances of the same argument. Use this for a new
flag -e to new-window, split-window, respawn-window, respawn-pane to
pass environment variables into the newly created process. From Steffen
Christgau in GitHub issue 1697.


# 1.93 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).


# 1.92 17-Apr-2019 nicm

Break new window and pane creation common code from various commands and
window.c into a separate file spawn.c.


Revision tags: OPENBSD_6_5_BASE
# 1.91 18-Oct-2018 nicm

Support for windows larger than visible on the attached client. This has
been a limitation for a long time.

There are two new options, window-size and default-size, and a new
command, resize-window. The force-width and force-height options and the
session_width and session_height formats have been removed.

The new window-size option tells tmux how to work out the size of
windows: largest means it picks the size of the largest session,
smallest the smallest session (similar to the old behaviour) and manual
means that it does not automatically resize windows. The default is
currently largest but this may change. aggressive-resize modifies the
choice of session for largest and smallest as it did before.

If a window is in a session attached to a client that is too small, only
part of the window is shown. tmux attempts to keep the cursor visible,
so the part of the window displayed is changed as the cursor moves (with
a small delay, to try and avoid excess redrawing when applications
redraw status lines or similar that are not currently visible). The
offset of the visible portion of the window is shown in status-right.

Drawing windows which are larger than the client is not as efficient as
those which fit, particularly when the cursor moves, so it is
recommended to avoid using this on slow machines or networks (set
window-size to smallest or manual).

The resize-window command can be used to resize a window manually. If it
is used, the window-size option is automatically set to manual for the
window (undo this with "setw -u window-size"). resize-window works in a
similar way to resize-pane (-U -D -L -R -x -y flags) but also has -a and
-A flags. -a sets the window to the size of the smallest client (what it
would be if window-size was smallest) and -A the largest.

For the same behaviour as force-width or force-height, use resize-window
-x or -y, and "setw -u window-size" to revert to automatic sizing..

If the global window-size option is set to manual, the default-size
option is used for new windows. If -x or -y is used with new-session,
that sets the default-size option for the new session.

The maximum size of a window is 10000x10000. But expect applications to
complain and much higher memory use if making a window excessively
big. The minimum size is the size required for the current layout
including borders.

The refresh-client command can be used to pan around a window, -U -D -L
-R moves up, down, left or right and -c returns to automatic cursor
tracking. The position is reset when the current window is changed.


Revision tags: OPENBSD_6_4_BASE
# 1.90 24-May-2018 nicm

Make server_client_get_cwd used (almost) everywhere we need to work out
the cwd, and do not fall back to "." as it is pretty useless. GitHub
issue 1331.


Revision tags: OPENBSD_6_3_BASE
# 1.89 16-Mar-2018 nicm

Insert full size panes at the right position, from KOIE Hidetaka in
GitHub issue 1284.


# 1.88 01-Mar-2018 nicm

Expand formats in window and session names.


Revision tags: OPENBSD_6_2_BASE
# 1.87 30-Aug-2017 nicm

Pass flags into cmd_find_from_* to fix prefer-unattached, reported by
Thomas Sattler.


# 1.86 21-Jul-2017 nicm

Add -c for respawn-pane and respawn-window, from J Raynor.


# 1.85 30-May-2017 nicm

Rewrite of choose mode, both to simplify and tidy the code and to add
some modern features.

Now the common code is in mode-tree.c, which provides an API used by the
three modes now separated into window-{buffer,client,tree}.c. Buffer
mode shows buffers, client mode clients and tree mode a tree of
sessions, windows and panes.

Each mode has a common set of key bindings plus a few that are specific
to the mode. Other changes are:

- each mode has a preview pane: for buffers this is the buffer content
(very useful), for others it is a preview of the pane;

- items may be sorted in different ways ('O' key);

- multiple items may be tagged and an operation applied to all of them
(for example, to delete multiple buffers at once);

- in tree mode a command may be run on the selected item (session,
window, pane) or on tagged items (key ':');

- displayed items may be filtered in tree mode by using a format (this
is used to implement find-window) (key 'f');

- the custom format (-F) for the display is no longer available;

- shortcut keys change from 0-9, a-z, A-Z which was always a bit weird
with keys used for other uses to 0-9, M-a to M-z.

Now that the code is simpler, other improvements will come later.

Primary key bindings for each mode are documented under the commands in
the man page (choose-buffer, choose-client, choose-tree).

Parts written by Thomas Adam.


# 1.84 25-Apr-2017 nicm

Do not update TERM into config file parsing has finished.


# 1.83 22-Apr-2017 nicm

Get rid of the extra layer of flags and cmd_prepare() and just store the
CMD_FIND_* flags in the cmd_entry and call it for the command. Commands
with special requirements call it themselves and update the target for
hooks to use.


# 1.82 22-Apr-2017 nicm

Mouse bindings and hooks set up an initial current state when running a
command. This is used for the session, window and pane for all commands
in the command sequence if there is no -t or -s.

However, using it for all commands in the command sequence means that if
the active pane or current session is changed, subsequent commands still
use the previous state. So make commands which explicitly change the
current state (such as neww and selectp) update it themselves for later
commands. Commands which may invalidate the state (like killp) are
already OK because an invalid state will be ignored.

Also fill in the current state for all key bindings rather than just the
mouse, so that any omissions are easier to spot.


# 1.81 21-Apr-2017 nicm

Add cmd_find_from_winlink_pane and use it in a couple of places, and
make functions that can't fail void.


Revision tags: OPENBSD_6_1_BASE
# 1.80 09-Mar-2017 nicm

Move server_fill_environ into environ.c and move some other common code
into it.


# 1.79 08-Mar-2017 nicm

Add a helper function for the most common format_create/defaults/expand
pattern.


# 1.78 27-Feb-2017 nicm

If splitw -b is used, insert the new pane before the current one in the
pane list. This means the numbering is in order (for example for
display-panes) and fixes a problem with redrawing the active pane
borders.


# 1.77 03-Feb-2017 nicm

Add a window or pane id "tag" to each format tree and use it to separate
jobs, this means that if the same job is used for different windows or
panes (for example in pane-border-format), it will be run separately for
each pane.


# 1.76 16-Oct-2016 nicm

Use the notify name string instead of going via an enum and change
existing hooks to use notifys instead.


# 1.75 16-Oct-2016 nicm

Mass rename struct cmd_q to struct cmdq_item and related.


# 1.74 16-Oct-2016 nicm

Rewrite command queue handling. Each client still has a command queue,
but there is also now a global command queue. Instead of command queues
being dispatched on demand from wherever the command happens to be
added, they are now all dispatched from the top level server
loop. Command queues may now also include callbacks as well as commands,
and items may be inserted after the current command as well as at the end.

This all makes command queues significantly more predictable and easier
to use, and avoids the complex multiple nested command queues used by
source-file, if-shell and friends.

A mass rename of struct cmdq to a better name (cmdq_item probably) is
coming.


# 1.73 13-Oct-2016 nicm

Trying to do hooks generically is way too complicated and unreliable and
confusing, particularly trying to automatically figure out what target
hooks should be using. So simplify it:

- drop before hooks entirely, they don't seem to be very useful;

- commands with special requirements now fire their own after hook (for
example, if they change session or window, or if they have -t and -s
and need to choose which one the hook uses as current target);

- commands with no special requirements can have the CMD_AFTERHOOK flag
added and they will use the -t state.

At the moment new-session, new-window, split-window fire their own hook,
and display-message uses the flag. The remaining commands still need to
be looked at.


# 1.72 13-Oct-2016 nicm

Some improvements and bug fixes for hooks:

- Prepare the state again before the "after" hooks are run, because the
command may have killed or moved windows.

- Use the hooks list from the newly prepared target, not the old hooks
list (only matters for new-session really).

- Correctly detect an invalid current state and ignore it in
cmd_find_target ("killw; swapw").

- Change neww, new, killp, killw, splitw, swapp, swapw to update the
current state (used if no explicit target is given) to something more
useful after they have finished. For example, neww changes it to the
newly created window.

Hooks are still relatively new and primitive so there are likely to be
more changes to come.

Parts based on bug reports from Uwe Werler and Iblis Lin.


# 1.71 10-Oct-2016 nicm

Add static in cmd-* and fix a few other nits.


# 1.70 04-Sep-2016 nicm

Add support for performing a full width split (with splitw -f), rather
than splitting the current cell. From Stephen Kent.


Revision tags: OPENBSD_6_0_BASE
# 1.69 06-Jun-2016 nicm

Insert new panes after the pane being split in the list rather than
always after the active pane. This is more sensible when doing it with
commands rather than keys.


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

I no longer use my SourceForge address so replace it.


# 1.67 14-Dec-2015 nicm

Instead of combined flags for -c, -s, -t, split into different sets
using an enum and simplify the parsing code.


# 1.66 13-Dec-2015 nicm

Use member names in cmd_entry definitions so I stop getting confused
about the order.


# 1.65 13-Dec-2015 nicm

Instead of every command resolving the target (-t or -s) itself, prepare
the state (client, session, winlink, pane) for it it before entering the
command. Each command provides some flags that tell the prepare step
what it is expecting.

This is a requirement for having hooks on commands (for example, if you
hook "select-window -t1:2", the hook command should to operate on window
1:2 not whatever it thinks is the current window), and should allow some
other target improvements.

The old cmd_find_* functions remain for the moment but that layer will
be dropped later.

Joint work with Thomas Adam.


# 1.64 11-Dec-2015 nicm

Add cmdq as an argument to format_create and add a format for the
command name (will also be used for more later).


# 1.63 08-Dec-2015 nicm

Remove format_create_flags and just pass flags to format_create.


# 1.62 31-Oct-2015 nicm

Fall back silently to ~ or / rather than checking -c with access(), this
was the old behaviour.


# 1.61 31-Oct-2015 nicm

Because pledge(2) does not allow us to pass directory file descriptors
around, we can't use file descriptors for the working directory because
we will be unable to pass it to a privileged process to tell it where to
read or write files or spawn children. So move tmux back to using
strings for the current working directory. We try to check it exists
with access() when it is set but ultimately fall back to ~ if it fails
at time of use (or / if that fails too).


# 1.60 28-Oct-2015 nicm

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


# 1.59 27-Oct-2015 nicm

Move struct options into options.c.


# 1.58 23-Oct-2015 nicm

Remove some unnecessary checks before free().


Revision tags: OPENBSD_5_8_BASE
# 1.57 26-Apr-2015 nicm

Remove panes from layout if spawning them fails, reported by Anthony J
Bentley.


Revision tags: OPENBSD_5_7_BASE
# 1.56 05-Feb-2015 nicm

Remove a couple of now-unused variables.


# 1.55 05-Feb-2015 nicm

Wrap all the individual format_* calls in a single format_defaults
functions.


# 1.54 12-Nov-2014 nicm

Add -b to splitw like joinw, from Felix Rosencrantz.


# 1.53 20-Oct-2014 nicm

Move template defines back into .c files.


# 1.52 20-Oct-2014 nicm

Instead of setting up the default keys by building the key struct
directly with a helper function in the cmd_entry, include a table of
bind-key commands and pass them through the command parser and a
temporary cmd_q.

As well as being smaller, this will allow default bindings to be command
sequences which will probably be needed soon.


# 1.51 01-Sep-2014 nicm

Various minor style and spacing nits.


Revision tags: OPENBSD_5_6_BASE
# 1.50 13-May-2014 nicm

If multiple arguments are given to new-session, new-window,
split-window, respawn-window or respawn-pane, pass them directly to
execvp() to help avoid quoting problems. One argument still goes to "sh
-c" like before. Requested by many over the years. Patch from J Raynor.


# 1.49 17-Apr-2014 nicm

Set PATH explicitly, either from client or session
environment. Previously it came from the session environment. From J
Raynor.


Revision tags: OPENBSD_5_5_BASE
# 1.48 22-Nov-2013 nicm

Handle empty current directory more gracefully.


# 1.47 10-Oct-2013 nicm

Don't boke when figuring out working directory from configuration file.


# 1.46 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.45 10-Oct-2013 nicm

Support -c for new-session, based on code from J Raynor.


# 1.44 10-Oct-2013 nicm

Restore missing key binding for %, from Chris Johnsen.


# 1.43 10-Oct-2013 nicm

Remove the barely-used and unnecessary command check() function.


Revision tags: OPENBSD_5_4_BASE
# 1.42 25-Mar-2013 nicm

Revert the command-prefix change which breaks sequences of commands.


# 1.41 24-Mar-2013 nicm

Add resize-pane -Z to temporary zoom the active pane to occupy the full
window or unzoom (restored to the normal layout) if it already zoomed,
bound to C-b z by default. The pane is unzoomed on pretty much any
excuse whatsoever.

We considered making this a new layout but the requirements are quite
different from layouts so decided it is better as a special case. Each
current layout cell is saved, a temporary one-cell layout generated and
all except the active pane set to NULL.

Prompted by suggestions and scripts from several. Thanks to Aaron Jensen
and Thiago Padilha for testing an earlier version.


# 1.40 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.


# 1.39 24-Mar-2013 nicm

Fix error reporting for client commands by adding a flag to
cmd_find_client to tell it whether or not to show errors, sometimes it's
needed and sometimes not.


# 1.38 24-Mar-2013 nicm

Add option command-prefix which is automatically prepended to any
command (apart from a naked default-shell). The default is "exec ".


Revision tags: OPENBSD_5_3_BASE
# 1.37 09-Dec-2012 nicm

Use the CMD_*_USAGE defines consistently, from Thomas Adam.


# 1.36 14-Aug-2012 nicm

Use a separate define for each default format template and strip clutter
from the choose-tree defaults.


Revision tags: OPENBSD_5_2_BASE
# 1.35 11-Jul-2012 nicm

Make command exec functions return an enum rather than -1/0/1 values and
add a new value to mean "leave client running but don't attach" to fix
problems with using some commands in a command sequence. Most of the
work by Thomas Adam, problem reported by "jspenguin" on SF bug 3535531.


# 1.34 10-Jul-2012 nicm

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


# 1.33 22-May-2012 nicm

Switch all of the various choose- and list- commands over to the format
infrastructure, from Thomas Adam.


# 1.32 17-Mar-2012 nicm

Add notify hooks for various events, the functions are currently empty
stubs but will be filled in for control mode later. From George Nachman.


# 1.31 04-Mar-2012 nicm

free -> xfree.


# 1.30 04-Mar-2012 nicm

Add -F format to new-window and split-window to use with the -P flag,
from George Nachman.


# 1.29 03-Mar-2012 nicm

Add move-pane command (like join-pane but allows the same window). Also
-b flag to join-pane and move-pane to place the pane to the left or
above. From George Nachman.


Revision tags: OPENBSD_5_1_BASE
# 1.28 31-Jan-2012 nicm

Provide defined ways to set the various default-path possibilities: ~
for home directory, . for server start directory, - for session start
directory and empty for the pane's working directory (the default). All
can also be used as part of a relative path (eg -/foo). Also provide -c
flags to neww and splitw to override default-path setting.

Based on a diff from sthen. ok sthen


# 1.27 20-Jan-2012 nicm

Add some const and fix a warning.


# 1.26 09-Dec-2011 nicm

Change the way the working directory for new processes is discovered. If
default-path isn't empty, it is used. Otherwise:

1) If tmux neww is run from the command line, the working directory of the
client is used.

2) Otherwise sysctl KERN_PROC_CWD is used to retrieve the current
working directory of the process in the active pane.

3) If that fails, the directory where the session was created is used.

Support code by Romain Francois, OpenBSD specific bits by me.

Note this requires a recent userland and kernel with KERN_PROC_CWD.


# 1.25 15-Nov-2011 nicm

Make window_pane_index work the same as window_index, from Ben Boeckel.


# 1.24 30-Aug-2011 nicm

Plug memory leak, from Tiago Cunha.


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE
# 1.23 10-Feb-2011 nicm

Size on split-window is -l not -s. Doh.


# 1.22 04-Jan-2011 nicm

Clean up and simplify tmux command argument parsing.

Originally, tmux commands were parsed in the client process into a
struct with the command data which was then serialised and sent to the
server to be executed. The parsing was later moved into the server (an
argv was sent from the client), but the parse step and intermediate
struct was kept.

This change removes that struct and the separate parse step. Argument
parsing and printing is now common to all commands (in arguments.c) with
each command left with just an optional check function (to validate the
arguments at parse time), the exec function and a function to set up any
key bindings (renamed from the old init function).

This is overall more simple and consistent.

There should be no changes to any commands behaviour or syntax although
as this touches every command please watch for any unexpected changes.


# 1.21 01-Jan-2011 nicm

Add a -P option to new-window and split-window to print the new window
or pane index in target form (useful to pass it into other commands).


Revision tags: OPENBSD_4_8_BASE
# 1.20 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.


Revision tags: OPENBSD_4_7_BASE
# 1.19 07-Jan-2010 nicm

New command, join-pane, to split and move an existing pane into the space (like
splitw then movep, or the reverse of breakp).


# 1.18 07-Jan-2010 nicm

Use the specified pane for size calculations. Doh.


# 1.17 07-Jan-2010 nicm

Change split-window to accept a pane target (it should be split-pane but
renaming the command would be annoying).


# 1.16 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.15 20-Nov-2009 nicm

When -h and -p are given to split-window, calculate the percentage size using
the width instead of the height.


# 1.14 13-Nov-2009 nicm

Get rid of the ugly CMD_CHFLAG macro and use a const string (eg "dDU") in the
command entry structs and a couple of functions to check/set the flags.


# 1.13 21-Sep-2009 nicm

Use KEYC_NONE constant instead of 0 on init.


# 1.12 16-Sep-2009 nicm

Rather than constructing an entire termios struct from ttydefaults.h, just let
forkpty do it and then alter the bits that should be changed after fork. A
little neater and more portable.


# 1.11 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.10 25-Aug-2009 nicm

Print -l and -p when showing command, pointed out by Tiago Cunha.


# 1.9 13-Aug-2009 nicm

When creating a new session from the command-line where there is an external
terminal, copy the termios(4) special characters and use them for new windows
created in the new session. Suggested by Theo.


# 1.8 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.7 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.6 22-Jul-2009 nicm

window_add_pane cannot fail, so remove the unused cause argument and don't
bother to check for a NULL return.


# 1.5 19-Jul-2009 nicm

Improved layout code.

Each window now has a tree of layout cells associated with it. In this tree,
each node is either a horizontal or vertical cell containing a list of other
cells running from left-to-right or top-to-bottom, or a leaf cell which is
associated with a pane.

The major functional changes are:

- panes may now be split arbitrarily both horizontally (splitw -h, C-b %) and
vertically (splitw -v, C-b ");
- panes may be resized both horizontally and vertically (resizep -L/-R/-U/-D,
bound to C-b left/right/up/down and C-b M-left/right/up/down);
- layouts are now applied and then may be modified by resizing or splitting
panes, rather than being fixed and reapplied when the window is resized or
panes are added;
- manual-vertical layout is no longer necessary, and active-only layout is gone
(but may return in future);
- the main-pane layouts now reduce the size of the main pane to fit all panes
if possible.

Thanks to all who tested.


# 1.4 13-Jul-2009 nicm

Having fixed flags for single-character getopt options is a bit hard to
maintain and is only going to get worse as more are used. So instead, add a new
uint64_t member to cmd_entry which is a bitmask of upper and lowercase options
accepted by the command.

This means new single character options can be used without the need to add it
explicitly to the list.


# 1.3 07-Jul-2009 nicm

The fix for default-path (use target session options instead of global options)
is required here as well, doh.


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

lines variable can be -1 (to be ignored), so should be signed. Found by lint.


# 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.103 13-Apr-2020 nicm

Make client -c and -t handling common in cmd-queue.c and try to be
clearer about whether the client is the target client (must have a
session) or not.


# 1.102 13-Apr-2020 nicm

Move cmdq_state into cmd-queue.c.


# 1.101 13-Apr-2020 nicm

Rename cmdq_shared to cmdq_state which will better reflect what it is
(going to be) used for.


# 1.100 13-Apr-2020 nicm

Also move cmdq_item and cmdq_list into cmd-queue.c (this is to make its
use more clearly defined and preparation for some future work).


# 1.99 13-Apr-2020 nicm

Make struct cmd local to cmd.c and move it out of tmux.h.


# 1.98 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.97 16-Mar-2020 nicm

Do not attempt to close a NULL pane when failing to create a new one.


# 1.96 15-Oct-2019 nicm

Add support for percentage sizes for resize-pane ("-x 10%"). Also change
split-window and join-pane -l to accept similar percentages and
deprecate -p. From Anindya Mukherjee.


Revision tags: OPENBSD_6_6_BASE
# 1.95 03-May-2019 nicm

Allow panes to be empty (no command), output can be piped to them with
split-window or display-message -I.


# 1.94 28-Apr-2019 nicm

Support multiple occurances of the same argument. Use this for a new
flag -e to new-window, split-window, respawn-window, respawn-pane to
pass environment variables into the newly created process. From Steffen
Christgau in GitHub issue 1697.


# 1.93 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).


# 1.92 17-Apr-2019 nicm

Break new window and pane creation common code from various commands and
window.c into a separate file spawn.c.


Revision tags: OPENBSD_6_5_BASE
# 1.91 18-Oct-2018 nicm

Support for windows larger than visible on the attached client. This has
been a limitation for a long time.

There are two new options, window-size and default-size, and a new
command, resize-window. The force-width and force-height options and the
session_width and session_height formats have been removed.

The new window-size option tells tmux how to work out the size of
windows: largest means it picks the size of the largest session,
smallest the smallest session (similar to the old behaviour) and manual
means that it does not automatically resize windows. The default is
currently largest but this may change. aggressive-resize modifies the
choice of session for largest and smallest as it did before.

If a window is in a session attached to a client that is too small, only
part of the window is shown. tmux attempts to keep the cursor visible,
so the part of the window displayed is changed as the cursor moves (with
a small delay, to try and avoid excess redrawing when applications
redraw status lines or similar that are not currently visible). The
offset of the visible portion of the window is shown in status-right.

Drawing windows which are larger than the client is not as efficient as
those which fit, particularly when the cursor moves, so it is
recommended to avoid using this on slow machines or networks (set
window-size to smallest or manual).

The resize-window command can be used to resize a window manually. If it
is used, the window-size option is automatically set to manual for the
window (undo this with "setw -u window-size"). resize-window works in a
similar way to resize-pane (-U -D -L -R -x -y flags) but also has -a and
-A flags. -a sets the window to the size of the smallest client (what it
would be if window-size was smallest) and -A the largest.

For the same behaviour as force-width or force-height, use resize-window
-x or -y, and "setw -u window-size" to revert to automatic sizing..

If the global window-size option is set to manual, the default-size
option is used for new windows. If -x or -y is used with new-session,
that sets the default-size option for the new session.

The maximum size of a window is 10000x10000. But expect applications to
complain and much higher memory use if making a window excessively
big. The minimum size is the size required for the current layout
including borders.

The refresh-client command can be used to pan around a window, -U -D -L
-R moves up, down, left or right and -c returns to automatic cursor
tracking. The position is reset when the current window is changed.


Revision tags: OPENBSD_6_4_BASE
# 1.90 24-May-2018 nicm

Make server_client_get_cwd used (almost) everywhere we need to work out
the cwd, and do not fall back to "." as it is pretty useless. GitHub
issue 1331.


Revision tags: OPENBSD_6_3_BASE
# 1.89 16-Mar-2018 nicm

Insert full size panes at the right position, from KOIE Hidetaka in
GitHub issue 1284.


# 1.88 01-Mar-2018 nicm

Expand formats in window and session names.


Revision tags: OPENBSD_6_2_BASE
# 1.87 30-Aug-2017 nicm

Pass flags into cmd_find_from_* to fix prefer-unattached, reported by
Thomas Sattler.


# 1.86 21-Jul-2017 nicm

Add -c for respawn-pane and respawn-window, from J Raynor.


# 1.85 30-May-2017 nicm

Rewrite of choose mode, both to simplify and tidy the code and to add
some modern features.

Now the common code is in mode-tree.c, which provides an API used by the
three modes now separated into window-{buffer,client,tree}.c. Buffer
mode shows buffers, client mode clients and tree mode a tree of
sessions, windows and panes.

Each mode has a common set of key bindings plus a few that are specific
to the mode. Other changes are:

- each mode has a preview pane: for buffers this is the buffer content
(very useful), for others it is a preview of the pane;

- items may be sorted in different ways ('O' key);

- multiple items may be tagged and an operation applied to all of them
(for example, to delete multiple buffers at once);

- in tree mode a command may be run on the selected item (session,
window, pane) or on tagged items (key ':');

- displayed items may be filtered in tree mode by using a format (this
is used to implement find-window) (key 'f');

- the custom format (-F) for the display is no longer available;

- shortcut keys change from 0-9, a-z, A-Z which was always a bit weird
with keys used for other uses to 0-9, M-a to M-z.

Now that the code is simpler, other improvements will come later.

Primary key bindings for each mode are documented under the commands in
the man page (choose-buffer, choose-client, choose-tree).

Parts written by Thomas Adam.


# 1.84 25-Apr-2017 nicm

Do not update TERM into config file parsing has finished.


# 1.83 22-Apr-2017 nicm

Get rid of the extra layer of flags and cmd_prepare() and just store the
CMD_FIND_* flags in the cmd_entry and call it for the command. Commands
with special requirements call it themselves and update the target for
hooks to use.


# 1.82 22-Apr-2017 nicm

Mouse bindings and hooks set up an initial current state when running a
command. This is used for the session, window and pane for all commands
in the command sequence if there is no -t or -s.

However, using it for all commands in the command sequence means that if
the active pane or current session is changed, subsequent commands still
use the previous state. So make commands which explicitly change the
current state (such as neww and selectp) update it themselves for later
commands. Commands which may invalidate the state (like killp) are
already OK because an invalid state will be ignored.

Also fill in the current state for all key bindings rather than just the
mouse, so that any omissions are easier to spot.


# 1.81 21-Apr-2017 nicm

Add cmd_find_from_winlink_pane and use it in a couple of places, and
make functions that can't fail void.


Revision tags: OPENBSD_6_1_BASE
# 1.80 09-Mar-2017 nicm

Move server_fill_environ into environ.c and move some other common code
into it.


# 1.79 08-Mar-2017 nicm

Add a helper function for the most common format_create/defaults/expand
pattern.


# 1.78 27-Feb-2017 nicm

If splitw -b is used, insert the new pane before the current one in the
pane list. This means the numbering is in order (for example for
display-panes) and fixes a problem with redrawing the active pane
borders.


# 1.77 03-Feb-2017 nicm

Add a window or pane id "tag" to each format tree and use it to separate
jobs, this means that if the same job is used for different windows or
panes (for example in pane-border-format), it will be run separately for
each pane.


# 1.76 16-Oct-2016 nicm

Use the notify name string instead of going via an enum and change
existing hooks to use notifys instead.


# 1.75 16-Oct-2016 nicm

Mass rename struct cmd_q to struct cmdq_item and related.


# 1.74 16-Oct-2016 nicm

Rewrite command queue handling. Each client still has a command queue,
but there is also now a global command queue. Instead of command queues
being dispatched on demand from wherever the command happens to be
added, they are now all dispatched from the top level server
loop. Command queues may now also include callbacks as well as commands,
and items may be inserted after the current command as well as at the end.

This all makes command queues significantly more predictable and easier
to use, and avoids the complex multiple nested command queues used by
source-file, if-shell and friends.

A mass rename of struct cmdq to a better name (cmdq_item probably) is
coming.


# 1.73 13-Oct-2016 nicm

Trying to do hooks generically is way too complicated and unreliable and
confusing, particularly trying to automatically figure out what target
hooks should be using. So simplify it:

- drop before hooks entirely, they don't seem to be very useful;

- commands with special requirements now fire their own after hook (for
example, if they change session or window, or if they have -t and -s
and need to choose which one the hook uses as current target);

- commands with no special requirements can have the CMD_AFTERHOOK flag
added and they will use the -t state.

At the moment new-session, new-window, split-window fire their own hook,
and display-message uses the flag. The remaining commands still need to
be looked at.


# 1.72 13-Oct-2016 nicm

Some improvements and bug fixes for hooks:

- Prepare the state again before the "after" hooks are run, because the
command may have killed or moved windows.

- Use the hooks list from the newly prepared target, not the old hooks
list (only matters for new-session really).

- Correctly detect an invalid current state and ignore it in
cmd_find_target ("killw; swapw").

- Change neww, new, killp, killw, splitw, swapp, swapw to update the
current state (used if no explicit target is given) to something more
useful after they have finished. For example, neww changes it to the
newly created window.

Hooks are still relatively new and primitive so there are likely to be
more changes to come.

Parts based on bug reports from Uwe Werler and Iblis Lin.


# 1.71 10-Oct-2016 nicm

Add static in cmd-* and fix a few other nits.


# 1.70 04-Sep-2016 nicm

Add support for performing a full width split (with splitw -f), rather
than splitting the current cell. From Stephen Kent.


Revision tags: OPENBSD_6_0_BASE
# 1.69 06-Jun-2016 nicm

Insert new panes after the pane being split in the list rather than
always after the active pane. This is more sensible when doing it with
commands rather than keys.


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

I no longer use my SourceForge address so replace it.


# 1.67 14-Dec-2015 nicm

Instead of combined flags for -c, -s, -t, split into different sets
using an enum and simplify the parsing code.


# 1.66 13-Dec-2015 nicm

Use member names in cmd_entry definitions so I stop getting confused
about the order.


# 1.65 13-Dec-2015 nicm

Instead of every command resolving the target (-t or -s) itself, prepare
the state (client, session, winlink, pane) for it it before entering the
command. Each command provides some flags that tell the prepare step
what it is expecting.

This is a requirement for having hooks on commands (for example, if you
hook "select-window -t1:2", the hook command should to operate on window
1:2 not whatever it thinks is the current window), and should allow some
other target improvements.

The old cmd_find_* functions remain for the moment but that layer will
be dropped later.

Joint work with Thomas Adam.


# 1.64 11-Dec-2015 nicm

Add cmdq as an argument to format_create and add a format for the
command name (will also be used for more later).


# 1.63 08-Dec-2015 nicm

Remove format_create_flags and just pass flags to format_create.


# 1.62 31-Oct-2015 nicm

Fall back silently to ~ or / rather than checking -c with access(), this
was the old behaviour.


# 1.61 31-Oct-2015 nicm

Because pledge(2) does not allow us to pass directory file descriptors
around, we can't use file descriptors for the working directory because
we will be unable to pass it to a privileged process to tell it where to
read or write files or spawn children. So move tmux back to using
strings for the current working directory. We try to check it exists
with access() when it is set but ultimately fall back to ~ if it fails
at time of use (or / if that fails too).


# 1.60 28-Oct-2015 nicm

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


# 1.59 27-Oct-2015 nicm

Move struct options into options.c.


# 1.58 23-Oct-2015 nicm

Remove some unnecessary checks before free().


Revision tags: OPENBSD_5_8_BASE
# 1.57 26-Apr-2015 nicm

Remove panes from layout if spawning them fails, reported by Anthony J
Bentley.


Revision tags: OPENBSD_5_7_BASE
# 1.56 05-Feb-2015 nicm

Remove a couple of now-unused variables.


# 1.55 05-Feb-2015 nicm

Wrap all the individual format_* calls in a single format_defaults
functions.


# 1.54 12-Nov-2014 nicm

Add -b to splitw like joinw, from Felix Rosencrantz.


# 1.53 20-Oct-2014 nicm

Move template defines back into .c files.


# 1.52 20-Oct-2014 nicm

Instead of setting up the default keys by building the key struct
directly with a helper function in the cmd_entry, include a table of
bind-key commands and pass them through the command parser and a
temporary cmd_q.

As well as being smaller, this will allow default bindings to be command
sequences which will probably be needed soon.


# 1.51 01-Sep-2014 nicm

Various minor style and spacing nits.


Revision tags: OPENBSD_5_6_BASE
# 1.50 13-May-2014 nicm

If multiple arguments are given to new-session, new-window,
split-window, respawn-window or respawn-pane, pass them directly to
execvp() to help avoid quoting problems. One argument still goes to "sh
-c" like before. Requested by many over the years. Patch from J Raynor.


# 1.49 17-Apr-2014 nicm

Set PATH explicitly, either from client or session
environment. Previously it came from the session environment. From J
Raynor.


Revision tags: OPENBSD_5_5_BASE
# 1.48 22-Nov-2013 nicm

Handle empty current directory more gracefully.


# 1.47 10-Oct-2013 nicm

Don't boke when figuring out working directory from configuration file.


# 1.46 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.45 10-Oct-2013 nicm

Support -c for new-session, based on code from J Raynor.


# 1.44 10-Oct-2013 nicm

Restore missing key binding for %, from Chris Johnsen.


# 1.43 10-Oct-2013 nicm

Remove the barely-used and unnecessary command check() function.


Revision tags: OPENBSD_5_4_BASE
# 1.42 25-Mar-2013 nicm

Revert the command-prefix change which breaks sequences of commands.


# 1.41 24-Mar-2013 nicm

Add resize-pane -Z to temporary zoom the active pane to occupy the full
window or unzoom (restored to the normal layout) if it already zoomed,
bound to C-b z by default. The pane is unzoomed on pretty much any
excuse whatsoever.

We considered making this a new layout but the requirements are quite
different from layouts so decided it is better as a special case. Each
current layout cell is saved, a temporary one-cell layout generated and
all except the active pane set to NULL.

Prompted by suggestions and scripts from several. Thanks to Aaron Jensen
and Thiago Padilha for testing an earlier version.


# 1.40 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.


# 1.39 24-Mar-2013 nicm

Fix error reporting for client commands by adding a flag to
cmd_find_client to tell it whether or not to show errors, sometimes it's
needed and sometimes not.


# 1.38 24-Mar-2013 nicm

Add option command-prefix which is automatically prepended to any
command (apart from a naked default-shell). The default is "exec ".


Revision tags: OPENBSD_5_3_BASE
# 1.37 09-Dec-2012 nicm

Use the CMD_*_USAGE defines consistently, from Thomas Adam.


# 1.36 14-Aug-2012 nicm

Use a separate define for each default format template and strip clutter
from the choose-tree defaults.


Revision tags: OPENBSD_5_2_BASE
# 1.35 11-Jul-2012 nicm

Make command exec functions return an enum rather than -1/0/1 values and
add a new value to mean "leave client running but don't attach" to fix
problems with using some commands in a command sequence. Most of the
work by Thomas Adam, problem reported by "jspenguin" on SF bug 3535531.


# 1.34 10-Jul-2012 nicm

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


# 1.33 22-May-2012 nicm

Switch all of the various choose- and list- commands over to the format
infrastructure, from Thomas Adam.


# 1.32 17-Mar-2012 nicm

Add notify hooks for various events, the functions are currently empty
stubs but will be filled in for control mode later. From George Nachman.


# 1.31 04-Mar-2012 nicm

free -> xfree.


# 1.30 04-Mar-2012 nicm

Add -F format to new-window and split-window to use with the -P flag,
from George Nachman.


# 1.29 03-Mar-2012 nicm

Add move-pane command (like join-pane but allows the same window). Also
-b flag to join-pane and move-pane to place the pane to the left or
above. From George Nachman.


Revision tags: OPENBSD_5_1_BASE
# 1.28 31-Jan-2012 nicm

Provide defined ways to set the various default-path possibilities: ~
for home directory, . for server start directory, - for session start
directory and empty for the pane's working directory (the default). All
can also be used as part of a relative path (eg -/foo). Also provide -c
flags to neww and splitw to override default-path setting.

Based on a diff from sthen. ok sthen


# 1.27 20-Jan-2012 nicm

Add some const and fix a warning.


# 1.26 09-Dec-2011 nicm

Change the way the working directory for new processes is discovered. If
default-path isn't empty, it is used. Otherwise:

1) If tmux neww is run from the command line, the working directory of the
client is used.

2) Otherwise sysctl KERN_PROC_CWD is used to retrieve the current
working directory of the process in the active pane.

3) If that fails, the directory where the session was created is used.

Support code by Romain Francois, OpenBSD specific bits by me.

Note this requires a recent userland and kernel with KERN_PROC_CWD.


# 1.25 15-Nov-2011 nicm

Make window_pane_index work the same as window_index, from Ben Boeckel.


# 1.24 30-Aug-2011 nicm

Plug memory leak, from Tiago Cunha.


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE
# 1.23 10-Feb-2011 nicm

Size on split-window is -l not -s. Doh.


# 1.22 04-Jan-2011 nicm

Clean up and simplify tmux command argument parsing.

Originally, tmux commands were parsed in the client process into a
struct with the command data which was then serialised and sent to the
server to be executed. The parsing was later moved into the server (an
argv was sent from the client), but the parse step and intermediate
struct was kept.

This change removes that struct and the separate parse step. Argument
parsing and printing is now common to all commands (in arguments.c) with
each command left with just an optional check function (to validate the
arguments at parse time), the exec function and a function to set up any
key bindings (renamed from the old init function).

This is overall more simple and consistent.

There should be no changes to any commands behaviour or syntax although
as this touches every command please watch for any unexpected changes.


# 1.21 01-Jan-2011 nicm

Add a -P option to new-window and split-window to print the new window
or pane index in target form (useful to pass it into other commands).


Revision tags: OPENBSD_4_8_BASE
# 1.20 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.


Revision tags: OPENBSD_4_7_BASE
# 1.19 07-Jan-2010 nicm

New command, join-pane, to split and move an existing pane into the space (like
splitw then movep, or the reverse of breakp).


# 1.18 07-Jan-2010 nicm

Use the specified pane for size calculations. Doh.


# 1.17 07-Jan-2010 nicm

Change split-window to accept a pane target (it should be split-pane but
renaming the command would be annoying).


# 1.16 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.15 20-Nov-2009 nicm

When -h and -p are given to split-window, calculate the percentage size using
the width instead of the height.


# 1.14 13-Nov-2009 nicm

Get rid of the ugly CMD_CHFLAG macro and use a const string (eg "dDU") in the
command entry structs and a couple of functions to check/set the flags.


# 1.13 21-Sep-2009 nicm

Use KEYC_NONE constant instead of 0 on init.


# 1.12 16-Sep-2009 nicm

Rather than constructing an entire termios struct from ttydefaults.h, just let
forkpty do it and then alter the bits that should be changed after fork. A
little neater and more portable.


# 1.11 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.10 25-Aug-2009 nicm

Print -l and -p when showing command, pointed out by Tiago Cunha.


# 1.9 13-Aug-2009 nicm

When creating a new session from the command-line where there is an external
terminal, copy the termios(4) special characters and use them for new windows
created in the new session. Suggested by Theo.


# 1.8 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.7 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.6 22-Jul-2009 nicm

window_add_pane cannot fail, so remove the unused cause argument and don't
bother to check for a NULL return.


# 1.5 19-Jul-2009 nicm

Improved layout code.

Each window now has a tree of layout cells associated with it. In this tree,
each node is either a horizontal or vertical cell containing a list of other
cells running from left-to-right or top-to-bottom, or a leaf cell which is
associated with a pane.

The major functional changes are:

- panes may now be split arbitrarily both horizontally (splitw -h, C-b %) and
vertically (splitw -v, C-b ");
- panes may be resized both horizontally and vertically (resizep -L/-R/-U/-D,
bound to C-b left/right/up/down and C-b M-left/right/up/down);
- layouts are now applied and then may be modified by resizing or splitting
panes, rather than being fixed and reapplied when the window is resized or
panes are added;
- manual-vertical layout is no longer necessary, and active-only layout is gone
(but may return in future);
- the main-pane layouts now reduce the size of the main pane to fit all panes
if possible.

Thanks to all who tested.


# 1.4 13-Jul-2009 nicm

Having fixed flags for single-character getopt options is a bit hard to
maintain and is only going to get worse as more are used. So instead, add a new
uint64_t member to cmd_entry which is a bitmask of upper and lowercase options
accepted by the command.

This means new single character options can be used without the need to add it
explicitly to the list.


# 1.3 07-Jul-2009 nicm

The fix for default-path (use target session options instead of global options)
is required here as well, doh.


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

lines variable can be -1 (to be ignored), so should be signed. Found by lint.


# 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.100 13-Apr-2020 nicm

Also move cmdq_item and cmdq_list into cmd-queue.c (this is to make its
use more clearly defined and preparation for some future work).


# 1.99 13-Apr-2020 nicm

Make struct cmd local to cmd.c and move it out of tmux.h.


# 1.98 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.97 16-Mar-2020 nicm

Do not attempt to close a NULL pane when failing to create a new one.


# 1.96 15-Oct-2019 nicm

Add support for percentage sizes for resize-pane ("-x 10%"). Also change
split-window and join-pane -l to accept similar percentages and
deprecate -p. From Anindya Mukherjee.


Revision tags: OPENBSD_6_6_BASE
# 1.95 03-May-2019 nicm

Allow panes to be empty (no command), output can be piped to them with
split-window or display-message -I.


# 1.94 28-Apr-2019 nicm

Support multiple occurances of the same argument. Use this for a new
flag -e to new-window, split-window, respawn-window, respawn-pane to
pass environment variables into the newly created process. From Steffen
Christgau in GitHub issue 1697.


# 1.93 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).


# 1.92 17-Apr-2019 nicm

Break new window and pane creation common code from various commands and
window.c into a separate file spawn.c.


Revision tags: OPENBSD_6_5_BASE
# 1.91 18-Oct-2018 nicm

Support for windows larger than visible on the attached client. This has
been a limitation for a long time.

There are two new options, window-size and default-size, and a new
command, resize-window. The force-width and force-height options and the
session_width and session_height formats have been removed.

The new window-size option tells tmux how to work out the size of
windows: largest means it picks the size of the largest session,
smallest the smallest session (similar to the old behaviour) and manual
means that it does not automatically resize windows. The default is
currently largest but this may change. aggressive-resize modifies the
choice of session for largest and smallest as it did before.

If a window is in a session attached to a client that is too small, only
part of the window is shown. tmux attempts to keep the cursor visible,
so the part of the window displayed is changed as the cursor moves (with
a small delay, to try and avoid excess redrawing when applications
redraw status lines or similar that are not currently visible). The
offset of the visible portion of the window is shown in status-right.

Drawing windows which are larger than the client is not as efficient as
those which fit, particularly when the cursor moves, so it is
recommended to avoid using this on slow machines or networks (set
window-size to smallest or manual).

The resize-window command can be used to resize a window manually. If it
is used, the window-size option is automatically set to manual for the
window (undo this with "setw -u window-size"). resize-window works in a
similar way to resize-pane (-U -D -L -R -x -y flags) but also has -a and
-A flags. -a sets the window to the size of the smallest client (what it
would be if window-size was smallest) and -A the largest.

For the same behaviour as force-width or force-height, use resize-window
-x or -y, and "setw -u window-size" to revert to automatic sizing..

If the global window-size option is set to manual, the default-size
option is used for new windows. If -x or -y is used with new-session,
that sets the default-size option for the new session.

The maximum size of a window is 10000x10000. But expect applications to
complain and much higher memory use if making a window excessively
big. The minimum size is the size required for the current layout
including borders.

The refresh-client command can be used to pan around a window, -U -D -L
-R moves up, down, left or right and -c returns to automatic cursor
tracking. The position is reset when the current window is changed.


Revision tags: OPENBSD_6_4_BASE
# 1.90 24-May-2018 nicm

Make server_client_get_cwd used (almost) everywhere we need to work out
the cwd, and do not fall back to "." as it is pretty useless. GitHub
issue 1331.


Revision tags: OPENBSD_6_3_BASE
# 1.89 16-Mar-2018 nicm

Insert full size panes at the right position, from KOIE Hidetaka in
GitHub issue 1284.


# 1.88 01-Mar-2018 nicm

Expand formats in window and session names.


Revision tags: OPENBSD_6_2_BASE
# 1.87 30-Aug-2017 nicm

Pass flags into cmd_find_from_* to fix prefer-unattached, reported by
Thomas Sattler.


# 1.86 21-Jul-2017 nicm

Add -c for respawn-pane and respawn-window, from J Raynor.


# 1.85 30-May-2017 nicm

Rewrite of choose mode, both to simplify and tidy the code and to add
some modern features.

Now the common code is in mode-tree.c, which provides an API used by the
three modes now separated into window-{buffer,client,tree}.c. Buffer
mode shows buffers, client mode clients and tree mode a tree of
sessions, windows and panes.

Each mode has a common set of key bindings plus a few that are specific
to the mode. Other changes are:

- each mode has a preview pane: for buffers this is the buffer content
(very useful), for others it is a preview of the pane;

- items may be sorted in different ways ('O' key);

- multiple items may be tagged and an operation applied to all of them
(for example, to delete multiple buffers at once);

- in tree mode a command may be run on the selected item (session,
window, pane) or on tagged items (key ':');

- displayed items may be filtered in tree mode by using a format (this
is used to implement find-window) (key 'f');

- the custom format (-F) for the display is no longer available;

- shortcut keys change from 0-9, a-z, A-Z which was always a bit weird
with keys used for other uses to 0-9, M-a to M-z.

Now that the code is simpler, other improvements will come later.

Primary key bindings for each mode are documented under the commands in
the man page (choose-buffer, choose-client, choose-tree).

Parts written by Thomas Adam.


# 1.84 25-Apr-2017 nicm

Do not update TERM into config file parsing has finished.


# 1.83 22-Apr-2017 nicm

Get rid of the extra layer of flags and cmd_prepare() and just store the
CMD_FIND_* flags in the cmd_entry and call it for the command. Commands
with special requirements call it themselves and update the target for
hooks to use.


# 1.82 22-Apr-2017 nicm

Mouse bindings and hooks set up an initial current state when running a
command. This is used for the session, window and pane for all commands
in the command sequence if there is no -t or -s.

However, using it for all commands in the command sequence means that if
the active pane or current session is changed, subsequent commands still
use the previous state. So make commands which explicitly change the
current state (such as neww and selectp) update it themselves for later
commands. Commands which may invalidate the state (like killp) are
already OK because an invalid state will be ignored.

Also fill in the current state for all key bindings rather than just the
mouse, so that any omissions are easier to spot.


# 1.81 21-Apr-2017 nicm

Add cmd_find_from_winlink_pane and use it in a couple of places, and
make functions that can't fail void.


Revision tags: OPENBSD_6_1_BASE
# 1.80 09-Mar-2017 nicm

Move server_fill_environ into environ.c and move some other common code
into it.


# 1.79 08-Mar-2017 nicm

Add a helper function for the most common format_create/defaults/expand
pattern.


# 1.78 27-Feb-2017 nicm

If splitw -b is used, insert the new pane before the current one in the
pane list. This means the numbering is in order (for example for
display-panes) and fixes a problem with redrawing the active pane
borders.


# 1.77 03-Feb-2017 nicm

Add a window or pane id "tag" to each format tree and use it to separate
jobs, this means that if the same job is used for different windows or
panes (for example in pane-border-format), it will be run separately for
each pane.


# 1.76 16-Oct-2016 nicm

Use the notify name string instead of going via an enum and change
existing hooks to use notifys instead.


# 1.75 16-Oct-2016 nicm

Mass rename struct cmd_q to struct cmdq_item and related.


# 1.74 16-Oct-2016 nicm

Rewrite command queue handling. Each client still has a command queue,
but there is also now a global command queue. Instead of command queues
being dispatched on demand from wherever the command happens to be
added, they are now all dispatched from the top level server
loop. Command queues may now also include callbacks as well as commands,
and items may be inserted after the current command as well as at the end.

This all makes command queues significantly more predictable and easier
to use, and avoids the complex multiple nested command queues used by
source-file, if-shell and friends.

A mass rename of struct cmdq to a better name (cmdq_item probably) is
coming.


# 1.73 13-Oct-2016 nicm

Trying to do hooks generically is way too complicated and unreliable and
confusing, particularly trying to automatically figure out what target
hooks should be using. So simplify it:

- drop before hooks entirely, they don't seem to be very useful;

- commands with special requirements now fire their own after hook (for
example, if they change session or window, or if they have -t and -s
and need to choose which one the hook uses as current target);

- commands with no special requirements can have the CMD_AFTERHOOK flag
added and they will use the -t state.

At the moment new-session, new-window, split-window fire their own hook,
and display-message uses the flag. The remaining commands still need to
be looked at.


# 1.72 13-Oct-2016 nicm

Some improvements and bug fixes for hooks:

- Prepare the state again before the "after" hooks are run, because the
command may have killed or moved windows.

- Use the hooks list from the newly prepared target, not the old hooks
list (only matters for new-session really).

- Correctly detect an invalid current state and ignore it in
cmd_find_target ("killw; swapw").

- Change neww, new, killp, killw, splitw, swapp, swapw to update the
current state (used if no explicit target is given) to something more
useful after they have finished. For example, neww changes it to the
newly created window.

Hooks are still relatively new and primitive so there are likely to be
more changes to come.

Parts based on bug reports from Uwe Werler and Iblis Lin.


# 1.71 10-Oct-2016 nicm

Add static in cmd-* and fix a few other nits.


# 1.70 04-Sep-2016 nicm

Add support for performing a full width split (with splitw -f), rather
than splitting the current cell. From Stephen Kent.


Revision tags: OPENBSD_6_0_BASE
# 1.69 06-Jun-2016 nicm

Insert new panes after the pane being split in the list rather than
always after the active pane. This is more sensible when doing it with
commands rather than keys.


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

I no longer use my SourceForge address so replace it.


# 1.67 14-Dec-2015 nicm

Instead of combined flags for -c, -s, -t, split into different sets
using an enum and simplify the parsing code.


# 1.66 13-Dec-2015 nicm

Use member names in cmd_entry definitions so I stop getting confused
about the order.


# 1.65 13-Dec-2015 nicm

Instead of every command resolving the target (-t or -s) itself, prepare
the state (client, session, winlink, pane) for it it before entering the
command. Each command provides some flags that tell the prepare step
what it is expecting.

This is a requirement for having hooks on commands (for example, if you
hook "select-window -t1:2", the hook command should to operate on window
1:2 not whatever it thinks is the current window), and should allow some
other target improvements.

The old cmd_find_* functions remain for the moment but that layer will
be dropped later.

Joint work with Thomas Adam.


# 1.64 11-Dec-2015 nicm

Add cmdq as an argument to format_create and add a format for the
command name (will also be used for more later).


# 1.63 08-Dec-2015 nicm

Remove format_create_flags and just pass flags to format_create.


# 1.62 31-Oct-2015 nicm

Fall back silently to ~ or / rather than checking -c with access(), this
was the old behaviour.


# 1.61 31-Oct-2015 nicm

Because pledge(2) does not allow us to pass directory file descriptors
around, we can't use file descriptors for the working directory because
we will be unable to pass it to a privileged process to tell it where to
read or write files or spawn children. So move tmux back to using
strings for the current working directory. We try to check it exists
with access() when it is set but ultimately fall back to ~ if it fails
at time of use (or / if that fails too).


# 1.60 28-Oct-2015 nicm

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


# 1.59 27-Oct-2015 nicm

Move struct options into options.c.


# 1.58 23-Oct-2015 nicm

Remove some unnecessary checks before free().


Revision tags: OPENBSD_5_8_BASE
# 1.57 26-Apr-2015 nicm

Remove panes from layout if spawning them fails, reported by Anthony J
Bentley.


Revision tags: OPENBSD_5_7_BASE
# 1.56 05-Feb-2015 nicm

Remove a couple of now-unused variables.


# 1.55 05-Feb-2015 nicm

Wrap all the individual format_* calls in a single format_defaults
functions.


# 1.54 12-Nov-2014 nicm

Add -b to splitw like joinw, from Felix Rosencrantz.


# 1.53 20-Oct-2014 nicm

Move template defines back into .c files.


# 1.52 20-Oct-2014 nicm

Instead of setting up the default keys by building the key struct
directly with a helper function in the cmd_entry, include a table of
bind-key commands and pass them through the command parser and a
temporary cmd_q.

As well as being smaller, this will allow default bindings to be command
sequences which will probably be needed soon.


# 1.51 01-Sep-2014 nicm

Various minor style and spacing nits.


Revision tags: OPENBSD_5_6_BASE
# 1.50 13-May-2014 nicm

If multiple arguments are given to new-session, new-window,
split-window, respawn-window or respawn-pane, pass them directly to
execvp() to help avoid quoting problems. One argument still goes to "sh
-c" like before. Requested by many over the years. Patch from J Raynor.


# 1.49 17-Apr-2014 nicm

Set PATH explicitly, either from client or session
environment. Previously it came from the session environment. From J
Raynor.


Revision tags: OPENBSD_5_5_BASE
# 1.48 22-Nov-2013 nicm

Handle empty current directory more gracefully.


# 1.47 10-Oct-2013 nicm

Don't boke when figuring out working directory from configuration file.


# 1.46 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.45 10-Oct-2013 nicm

Support -c for new-session, based on code from J Raynor.


# 1.44 10-Oct-2013 nicm

Restore missing key binding for %, from Chris Johnsen.


# 1.43 10-Oct-2013 nicm

Remove the barely-used and unnecessary command check() function.


Revision tags: OPENBSD_5_4_BASE
# 1.42 25-Mar-2013 nicm

Revert the command-prefix change which breaks sequences of commands.


# 1.41 24-Mar-2013 nicm

Add resize-pane -Z to temporary zoom the active pane to occupy the full
window or unzoom (restored to the normal layout) if it already zoomed,
bound to C-b z by default. The pane is unzoomed on pretty much any
excuse whatsoever.

We considered making this a new layout but the requirements are quite
different from layouts so decided it is better as a special case. Each
current layout cell is saved, a temporary one-cell layout generated and
all except the active pane set to NULL.

Prompted by suggestions and scripts from several. Thanks to Aaron Jensen
and Thiago Padilha for testing an earlier version.


# 1.40 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.


# 1.39 24-Mar-2013 nicm

Fix error reporting for client commands by adding a flag to
cmd_find_client to tell it whether or not to show errors, sometimes it's
needed and sometimes not.


# 1.38 24-Mar-2013 nicm

Add option command-prefix which is automatically prepended to any
command (apart from a naked default-shell). The default is "exec ".


Revision tags: OPENBSD_5_3_BASE
# 1.37 09-Dec-2012 nicm

Use the CMD_*_USAGE defines consistently, from Thomas Adam.


# 1.36 14-Aug-2012 nicm

Use a separate define for each default format template and strip clutter
from the choose-tree defaults.


Revision tags: OPENBSD_5_2_BASE
# 1.35 11-Jul-2012 nicm

Make command exec functions return an enum rather than -1/0/1 values and
add a new value to mean "leave client running but don't attach" to fix
problems with using some commands in a command sequence. Most of the
work by Thomas Adam, problem reported by "jspenguin" on SF bug 3535531.


# 1.34 10-Jul-2012 nicm

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


# 1.33 22-May-2012 nicm

Switch all of the various choose- and list- commands over to the format
infrastructure, from Thomas Adam.


# 1.32 17-Mar-2012 nicm

Add notify hooks for various events, the functions are currently empty
stubs but will be filled in for control mode later. From George Nachman.


# 1.31 04-Mar-2012 nicm

free -> xfree.


# 1.30 04-Mar-2012 nicm

Add -F format to new-window and split-window to use with the -P flag,
from George Nachman.


# 1.29 03-Mar-2012 nicm

Add move-pane command (like join-pane but allows the same window). Also
-b flag to join-pane and move-pane to place the pane to the left or
above. From George Nachman.


Revision tags: OPENBSD_5_1_BASE
# 1.28 31-Jan-2012 nicm

Provide defined ways to set the various default-path possibilities: ~
for home directory, . for server start directory, - for session start
directory and empty for the pane's working directory (the default). All
can also be used as part of a relative path (eg -/foo). Also provide -c
flags to neww and splitw to override default-path setting.

Based on a diff from sthen. ok sthen


# 1.27 20-Jan-2012 nicm

Add some const and fix a warning.


# 1.26 09-Dec-2011 nicm

Change the way the working directory for new processes is discovered. If
default-path isn't empty, it is used. Otherwise:

1) If tmux neww is run from the command line, the working directory of the
client is used.

2) Otherwise sysctl KERN_PROC_CWD is used to retrieve the current
working directory of the process in the active pane.

3) If that fails, the directory where the session was created is used.

Support code by Romain Francois, OpenBSD specific bits by me.

Note this requires a recent userland and kernel with KERN_PROC_CWD.


# 1.25 15-Nov-2011 nicm

Make window_pane_index work the same as window_index, from Ben Boeckel.


# 1.24 30-Aug-2011 nicm

Plug memory leak, from Tiago Cunha.


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE
# 1.23 10-Feb-2011 nicm

Size on split-window is -l not -s. Doh.


# 1.22 04-Jan-2011 nicm

Clean up and simplify tmux command argument parsing.

Originally, tmux commands were parsed in the client process into a
struct with the command data which was then serialised and sent to the
server to be executed. The parsing was later moved into the server (an
argv was sent from the client), but the parse step and intermediate
struct was kept.

This change removes that struct and the separate parse step. Argument
parsing and printing is now common to all commands (in arguments.c) with
each command left with just an optional check function (to validate the
arguments at parse time), the exec function and a function to set up any
key bindings (renamed from the old init function).

This is overall more simple and consistent.

There should be no changes to any commands behaviour or syntax although
as this touches every command please watch for any unexpected changes.


# 1.21 01-Jan-2011 nicm

Add a -P option to new-window and split-window to print the new window
or pane index in target form (useful to pass it into other commands).


Revision tags: OPENBSD_4_8_BASE
# 1.20 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.


Revision tags: OPENBSD_4_7_BASE
# 1.19 07-Jan-2010 nicm

New command, join-pane, to split and move an existing pane into the space (like
splitw then movep, or the reverse of breakp).


# 1.18 07-Jan-2010 nicm

Use the specified pane for size calculations. Doh.


# 1.17 07-Jan-2010 nicm

Change split-window to accept a pane target (it should be split-pane but
renaming the command would be annoying).


# 1.16 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.15 20-Nov-2009 nicm

When -h and -p are given to split-window, calculate the percentage size using
the width instead of the height.


# 1.14 13-Nov-2009 nicm

Get rid of the ugly CMD_CHFLAG macro and use a const string (eg "dDU") in the
command entry structs and a couple of functions to check/set the flags.


# 1.13 21-Sep-2009 nicm

Use KEYC_NONE constant instead of 0 on init.


# 1.12 16-Sep-2009 nicm

Rather than constructing an entire termios struct from ttydefaults.h, just let
forkpty do it and then alter the bits that should be changed after fork. A
little neater and more portable.


# 1.11 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.10 25-Aug-2009 nicm

Print -l and -p when showing command, pointed out by Tiago Cunha.


# 1.9 13-Aug-2009 nicm

When creating a new session from the command-line where there is an external
terminal, copy the termios(4) special characters and use them for new windows
created in the new session. Suggested by Theo.


# 1.8 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.7 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.6 22-Jul-2009 nicm

window_add_pane cannot fail, so remove the unused cause argument and don't
bother to check for a NULL return.


# 1.5 19-Jul-2009 nicm

Improved layout code.

Each window now has a tree of layout cells associated with it. In this tree,
each node is either a horizontal or vertical cell containing a list of other
cells running from left-to-right or top-to-bottom, or a leaf cell which is
associated with a pane.

The major functional changes are:

- panes may now be split arbitrarily both horizontally (splitw -h, C-b %) and
vertically (splitw -v, C-b ");
- panes may be resized both horizontally and vertically (resizep -L/-R/-U/-D,
bound to C-b left/right/up/down and C-b M-left/right/up/down);
- layouts are now applied and then may be modified by resizing or splitting
panes, rather than being fixed and reapplied when the window is resized or
panes are added;
- manual-vertical layout is no longer necessary, and active-only layout is gone
(but may return in future);
- the main-pane layouts now reduce the size of the main pane to fit all panes
if possible.

Thanks to all who tested.


# 1.4 13-Jul-2009 nicm

Having fixed flags for single-character getopt options is a bit hard to
maintain and is only going to get worse as more are used. So instead, add a new
uint64_t member to cmd_entry which is a bitmask of upper and lowercase options
accepted by the command.

This means new single character options can be used without the need to add it
explicitly to the list.


# 1.3 07-Jul-2009 nicm

The fix for default-path (use target session options instead of global options)
is required here as well, doh.


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

lines variable can be -1 (to be ignored), so should be signed. Found by lint.


# 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.98 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.97 16-Mar-2020 nicm

Do not attempt to close a NULL pane when failing to create a new one.


# 1.96 15-Oct-2019 nicm

Add support for percentage sizes for resize-pane ("-x 10%"). Also change
split-window and join-pane -l to accept similar percentages and
deprecate -p. From Anindya Mukherjee.


Revision tags: OPENBSD_6_6_BASE
# 1.95 03-May-2019 nicm

Allow panes to be empty (no command), output can be piped to them with
split-window or display-message -I.


# 1.94 28-Apr-2019 nicm

Support multiple occurances of the same argument. Use this for a new
flag -e to new-window, split-window, respawn-window, respawn-pane to
pass environment variables into the newly created process. From Steffen
Christgau in GitHub issue 1697.


# 1.93 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).


# 1.92 17-Apr-2019 nicm

Break new window and pane creation common code from various commands and
window.c into a separate file spawn.c.


Revision tags: OPENBSD_6_5_BASE
# 1.91 18-Oct-2018 nicm

Support for windows larger than visible on the attached client. This has
been a limitation for a long time.

There are two new options, window-size and default-size, and a new
command, resize-window. The force-width and force-height options and the
session_width and session_height formats have been removed.

The new window-size option tells tmux how to work out the size of
windows: largest means it picks the size of the largest session,
smallest the smallest session (similar to the old behaviour) and manual
means that it does not automatically resize windows. The default is
currently largest but this may change. aggressive-resize modifies the
choice of session for largest and smallest as it did before.

If a window is in a session attached to a client that is too small, only
part of the window is shown. tmux attempts to keep the cursor visible,
so the part of the window displayed is changed as the cursor moves (with
a small delay, to try and avoid excess redrawing when applications
redraw status lines or similar that are not currently visible). The
offset of the visible portion of the window is shown in status-right.

Drawing windows which are larger than the client is not as efficient as
those which fit, particularly when the cursor moves, so it is
recommended to avoid using this on slow machines or networks (set
window-size to smallest or manual).

The resize-window command can be used to resize a window manually. If it
is used, the window-size option is automatically set to manual for the
window (undo this with "setw -u window-size"). resize-window works in a
similar way to resize-pane (-U -D -L -R -x -y flags) but also has -a and
-A flags. -a sets the window to the size of the smallest client (what it
would be if window-size was smallest) and -A the largest.

For the same behaviour as force-width or force-height, use resize-window
-x or -y, and "setw -u window-size" to revert to automatic sizing..

If the global window-size option is set to manual, the default-size
option is used for new windows. If -x or -y is used with new-session,
that sets the default-size option for the new session.

The maximum size of a window is 10000x10000. But expect applications to
complain and much higher memory use if making a window excessively
big. The minimum size is the size required for the current layout
including borders.

The refresh-client command can be used to pan around a window, -U -D -L
-R moves up, down, left or right and -c returns to automatic cursor
tracking. The position is reset when the current window is changed.


Revision tags: OPENBSD_6_4_BASE
# 1.90 24-May-2018 nicm

Make server_client_get_cwd used (almost) everywhere we need to work out
the cwd, and do not fall back to "." as it is pretty useless. GitHub
issue 1331.


Revision tags: OPENBSD_6_3_BASE
# 1.89 16-Mar-2018 nicm

Insert full size panes at the right position, from KOIE Hidetaka in
GitHub issue 1284.


# 1.88 01-Mar-2018 nicm

Expand formats in window and session names.


Revision tags: OPENBSD_6_2_BASE
# 1.87 30-Aug-2017 nicm

Pass flags into cmd_find_from_* to fix prefer-unattached, reported by
Thomas Sattler.


# 1.86 21-Jul-2017 nicm

Add -c for respawn-pane and respawn-window, from J Raynor.


# 1.85 30-May-2017 nicm

Rewrite of choose mode, both to simplify and tidy the code and to add
some modern features.

Now the common code is in mode-tree.c, which provides an API used by the
three modes now separated into window-{buffer,client,tree}.c. Buffer
mode shows buffers, client mode clients and tree mode a tree of
sessions, windows and panes.

Each mode has a common set of key bindings plus a few that are specific
to the mode. Other changes are:

- each mode has a preview pane: for buffers this is the buffer content
(very useful), for others it is a preview of the pane;

- items may be sorted in different ways ('O' key);

- multiple items may be tagged and an operation applied to all of them
(for example, to delete multiple buffers at once);

- in tree mode a command may be run on the selected item (session,
window, pane) or on tagged items (key ':');

- displayed items may be filtered in tree mode by using a format (this
is used to implement find-window) (key 'f');

- the custom format (-F) for the display is no longer available;

- shortcut keys change from 0-9, a-z, A-Z which was always a bit weird
with keys used for other uses to 0-9, M-a to M-z.

Now that the code is simpler, other improvements will come later.

Primary key bindings for each mode are documented under the commands in
the man page (choose-buffer, choose-client, choose-tree).

Parts written by Thomas Adam.


# 1.84 25-Apr-2017 nicm

Do not update TERM into config file parsing has finished.


# 1.83 22-Apr-2017 nicm

Get rid of the extra layer of flags and cmd_prepare() and just store the
CMD_FIND_* flags in the cmd_entry and call it for the command. Commands
with special requirements call it themselves and update the target for
hooks to use.


# 1.82 22-Apr-2017 nicm

Mouse bindings and hooks set up an initial current state when running a
command. This is used for the session, window and pane for all commands
in the command sequence if there is no -t or -s.

However, using it for all commands in the command sequence means that if
the active pane or current session is changed, subsequent commands still
use the previous state. So make commands which explicitly change the
current state (such as neww and selectp) update it themselves for later
commands. Commands which may invalidate the state (like killp) are
already OK because an invalid state will be ignored.

Also fill in the current state for all key bindings rather than just the
mouse, so that any omissions are easier to spot.


# 1.81 21-Apr-2017 nicm

Add cmd_find_from_winlink_pane and use it in a couple of places, and
make functions that can't fail void.


Revision tags: OPENBSD_6_1_BASE
# 1.80 09-Mar-2017 nicm

Move server_fill_environ into environ.c and move some other common code
into it.


# 1.79 08-Mar-2017 nicm

Add a helper function for the most common format_create/defaults/expand
pattern.


# 1.78 27-Feb-2017 nicm

If splitw -b is used, insert the new pane before the current one in the
pane list. This means the numbering is in order (for example for
display-panes) and fixes a problem with redrawing the active pane
borders.


# 1.77 03-Feb-2017 nicm

Add a window or pane id "tag" to each format tree and use it to separate
jobs, this means that if the same job is used for different windows or
panes (for example in pane-border-format), it will be run separately for
each pane.


# 1.76 16-Oct-2016 nicm

Use the notify name string instead of going via an enum and change
existing hooks to use notifys instead.


# 1.75 16-Oct-2016 nicm

Mass rename struct cmd_q to struct cmdq_item and related.


# 1.74 16-Oct-2016 nicm

Rewrite command queue handling. Each client still has a command queue,
but there is also now a global command queue. Instead of command queues
being dispatched on demand from wherever the command happens to be
added, they are now all dispatched from the top level server
loop. Command queues may now also include callbacks as well as commands,
and items may be inserted after the current command as well as at the end.

This all makes command queues significantly more predictable and easier
to use, and avoids the complex multiple nested command queues used by
source-file, if-shell and friends.

A mass rename of struct cmdq to a better name (cmdq_item probably) is
coming.


# 1.73 13-Oct-2016 nicm

Trying to do hooks generically is way too complicated and unreliable and
confusing, particularly trying to automatically figure out what target
hooks should be using. So simplify it:

- drop before hooks entirely, they don't seem to be very useful;

- commands with special requirements now fire their own after hook (for
example, if they change session or window, or if they have -t and -s
and need to choose which one the hook uses as current target);

- commands with no special requirements can have the CMD_AFTERHOOK flag
added and they will use the -t state.

At the moment new-session, new-window, split-window fire their own hook,
and display-message uses the flag. The remaining commands still need to
be looked at.


# 1.72 13-Oct-2016 nicm

Some improvements and bug fixes for hooks:

- Prepare the state again before the "after" hooks are run, because the
command may have killed or moved windows.

- Use the hooks list from the newly prepared target, not the old hooks
list (only matters for new-session really).

- Correctly detect an invalid current state and ignore it in
cmd_find_target ("killw; swapw").

- Change neww, new, killp, killw, splitw, swapp, swapw to update the
current state (used if no explicit target is given) to something more
useful after they have finished. For example, neww changes it to the
newly created window.

Hooks are still relatively new and primitive so there are likely to be
more changes to come.

Parts based on bug reports from Uwe Werler and Iblis Lin.


# 1.71 10-Oct-2016 nicm

Add static in cmd-* and fix a few other nits.


# 1.70 04-Sep-2016 nicm

Add support for performing a full width split (with splitw -f), rather
than splitting the current cell. From Stephen Kent.


Revision tags: OPENBSD_6_0_BASE
# 1.69 06-Jun-2016 nicm

Insert new panes after the pane being split in the list rather than
always after the active pane. This is more sensible when doing it with
commands rather than keys.


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

I no longer use my SourceForge address so replace it.


# 1.67 14-Dec-2015 nicm

Instead of combined flags for -c, -s, -t, split into different sets
using an enum and simplify the parsing code.


# 1.66 13-Dec-2015 nicm

Use member names in cmd_entry definitions so I stop getting confused
about the order.


# 1.65 13-Dec-2015 nicm

Instead of every command resolving the target (-t or -s) itself, prepare
the state (client, session, winlink, pane) for it it before entering the
command. Each command provides some flags that tell the prepare step
what it is expecting.

This is a requirement for having hooks on commands (for example, if you
hook "select-window -t1:2", the hook command should to operate on window
1:2 not whatever it thinks is the current window), and should allow some
other target improvements.

The old cmd_find_* functions remain for the moment but that layer will
be dropped later.

Joint work with Thomas Adam.


# 1.64 11-Dec-2015 nicm

Add cmdq as an argument to format_create and add a format for the
command name (will also be used for more later).


# 1.63 08-Dec-2015 nicm

Remove format_create_flags and just pass flags to format_create.


# 1.62 31-Oct-2015 nicm

Fall back silently to ~ or / rather than checking -c with access(), this
was the old behaviour.


# 1.61 31-Oct-2015 nicm

Because pledge(2) does not allow us to pass directory file descriptors
around, we can't use file descriptors for the working directory because
we will be unable to pass it to a privileged process to tell it where to
read or write files or spawn children. So move tmux back to using
strings for the current working directory. We try to check it exists
with access() when it is set but ultimately fall back to ~ if it fails
at time of use (or / if that fails too).


# 1.60 28-Oct-2015 nicm

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


# 1.59 27-Oct-2015 nicm

Move struct options into options.c.


# 1.58 23-Oct-2015 nicm

Remove some unnecessary checks before free().


Revision tags: OPENBSD_5_8_BASE
# 1.57 26-Apr-2015 nicm

Remove panes from layout if spawning them fails, reported by Anthony J
Bentley.


Revision tags: OPENBSD_5_7_BASE
# 1.56 05-Feb-2015 nicm

Remove a couple of now-unused variables.


# 1.55 05-Feb-2015 nicm

Wrap all the individual format_* calls in a single format_defaults
functions.


# 1.54 12-Nov-2014 nicm

Add -b to splitw like joinw, from Felix Rosencrantz.


# 1.53 20-Oct-2014 nicm

Move template defines back into .c files.


# 1.52 20-Oct-2014 nicm

Instead of setting up the default keys by building the key struct
directly with a helper function in the cmd_entry, include a table of
bind-key commands and pass them through the command parser and a
temporary cmd_q.

As well as being smaller, this will allow default bindings to be command
sequences which will probably be needed soon.


# 1.51 01-Sep-2014 nicm

Various minor style and spacing nits.


Revision tags: OPENBSD_5_6_BASE
# 1.50 13-May-2014 nicm

If multiple arguments are given to new-session, new-window,
split-window, respawn-window or respawn-pane, pass them directly to
execvp() to help avoid quoting problems. One argument still goes to "sh
-c" like before. Requested by many over the years. Patch from J Raynor.


# 1.49 17-Apr-2014 nicm

Set PATH explicitly, either from client or session
environment. Previously it came from the session environment. From J
Raynor.


Revision tags: OPENBSD_5_5_BASE
# 1.48 22-Nov-2013 nicm

Handle empty current directory more gracefully.


# 1.47 10-Oct-2013 nicm

Don't boke when figuring out working directory from configuration file.


# 1.46 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.45 10-Oct-2013 nicm

Support -c for new-session, based on code from J Raynor.


# 1.44 10-Oct-2013 nicm

Restore missing key binding for %, from Chris Johnsen.


# 1.43 10-Oct-2013 nicm

Remove the barely-used and unnecessary command check() function.


Revision tags: OPENBSD_5_4_BASE
# 1.42 25-Mar-2013 nicm

Revert the command-prefix change which breaks sequences of commands.


# 1.41 24-Mar-2013 nicm

Add resize-pane -Z to temporary zoom the active pane to occupy the full
window or unzoom (restored to the normal layout) if it already zoomed,
bound to C-b z by default. The pane is unzoomed on pretty much any
excuse whatsoever.

We considered making this a new layout but the requirements are quite
different from layouts so decided it is better as a special case. Each
current layout cell is saved, a temporary one-cell layout generated and
all except the active pane set to NULL.

Prompted by suggestions and scripts from several. Thanks to Aaron Jensen
and Thiago Padilha for testing an earlier version.


# 1.40 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.


# 1.39 24-Mar-2013 nicm

Fix error reporting for client commands by adding a flag to
cmd_find_client to tell it whether or not to show errors, sometimes it's
needed and sometimes not.


# 1.38 24-Mar-2013 nicm

Add option command-prefix which is automatically prepended to any
command (apart from a naked default-shell). The default is "exec ".


Revision tags: OPENBSD_5_3_BASE
# 1.37 09-Dec-2012 nicm

Use the CMD_*_USAGE defines consistently, from Thomas Adam.


# 1.36 14-Aug-2012 nicm

Use a separate define for each default format template and strip clutter
from the choose-tree defaults.


Revision tags: OPENBSD_5_2_BASE
# 1.35 11-Jul-2012 nicm

Make command exec functions return an enum rather than -1/0/1 values and
add a new value to mean "leave client running but don't attach" to fix
problems with using some commands in a command sequence. Most of the
work by Thomas Adam, problem reported by "jspenguin" on SF bug 3535531.


# 1.34 10-Jul-2012 nicm

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


# 1.33 22-May-2012 nicm

Switch all of the various choose- and list- commands over to the format
infrastructure, from Thomas Adam.


# 1.32 17-Mar-2012 nicm

Add notify hooks for various events, the functions are currently empty
stubs but will be filled in for control mode later. From George Nachman.


# 1.31 04-Mar-2012 nicm

free -> xfree.


# 1.30 04-Mar-2012 nicm

Add -F format to new-window and split-window to use with the -P flag,
from George Nachman.


# 1.29 03-Mar-2012 nicm

Add move-pane command (like join-pane but allows the same window). Also
-b flag to join-pane and move-pane to place the pane to the left or
above. From George Nachman.


Revision tags: OPENBSD_5_1_BASE
# 1.28 31-Jan-2012 nicm

Provide defined ways to set the various default-path possibilities: ~
for home directory, . for server start directory, - for session start
directory and empty for the pane's working directory (the default). All
can also be used as part of a relative path (eg -/foo). Also provide -c
flags to neww and splitw to override default-path setting.

Based on a diff from sthen. ok sthen


# 1.27 20-Jan-2012 nicm

Add some const and fix a warning.


# 1.26 09-Dec-2011 nicm

Change the way the working directory for new processes is discovered. If
default-path isn't empty, it is used. Otherwise:

1) If tmux neww is run from the command line, the working directory of the
client is used.

2) Otherwise sysctl KERN_PROC_CWD is used to retrieve the current
working directory of the process in the active pane.

3) If that fails, the directory where the session was created is used.

Support code by Romain Francois, OpenBSD specific bits by me.

Note this requires a recent userland and kernel with KERN_PROC_CWD.


# 1.25 15-Nov-2011 nicm

Make window_pane_index work the same as window_index, from Ben Boeckel.


# 1.24 30-Aug-2011 nicm

Plug memory leak, from Tiago Cunha.


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE
# 1.23 10-Feb-2011 nicm

Size on split-window is -l not -s. Doh.


# 1.22 04-Jan-2011 nicm

Clean up and simplify tmux command argument parsing.

Originally, tmux commands were parsed in the client process into a
struct with the command data which was then serialised and sent to the
server to be executed. The parsing was later moved into the server (an
argv was sent from the client), but the parse step and intermediate
struct was kept.

This change removes that struct and the separate parse step. Argument
parsing and printing is now common to all commands (in arguments.c) with
each command left with just an optional check function (to validate the
arguments at parse time), the exec function and a function to set up any
key bindings (renamed from the old init function).

This is overall more simple and consistent.

There should be no changes to any commands behaviour or syntax although
as this touches every command please watch for any unexpected changes.


# 1.21 01-Jan-2011 nicm

Add a -P option to new-window and split-window to print the new window
or pane index in target form (useful to pass it into other commands).


Revision tags: OPENBSD_4_8_BASE
# 1.20 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.


Revision tags: OPENBSD_4_7_BASE
# 1.19 07-Jan-2010 nicm

New command, join-pane, to split and move an existing pane into the space (like
splitw then movep, or the reverse of breakp).


# 1.18 07-Jan-2010 nicm

Use the specified pane for size calculations. Doh.


# 1.17 07-Jan-2010 nicm

Change split-window to accept a pane target (it should be split-pane but
renaming the command would be annoying).


# 1.16 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.15 20-Nov-2009 nicm

When -h and -p are given to split-window, calculate the percentage size using
the width instead of the height.


# 1.14 13-Nov-2009 nicm

Get rid of the ugly CMD_CHFLAG macro and use a const string (eg "dDU") in the
command entry structs and a couple of functions to check/set the flags.


# 1.13 21-Sep-2009 nicm

Use KEYC_NONE constant instead of 0 on init.


# 1.12 16-Sep-2009 nicm

Rather than constructing an entire termios struct from ttydefaults.h, just let
forkpty do it and then alter the bits that should be changed after fork. A
little neater and more portable.


# 1.11 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.10 25-Aug-2009 nicm

Print -l and -p when showing command, pointed out by Tiago Cunha.


# 1.9 13-Aug-2009 nicm

When creating a new session from the command-line where there is an external
terminal, copy the termios(4) special characters and use them for new windows
created in the new session. Suggested by Theo.


# 1.8 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.7 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.6 22-Jul-2009 nicm

window_add_pane cannot fail, so remove the unused cause argument and don't
bother to check for a NULL return.


# 1.5 19-Jul-2009 nicm

Improved layout code.

Each window now has a tree of layout cells associated with it. In this tree,
each node is either a horizontal or vertical cell containing a list of other
cells running from left-to-right or top-to-bottom, or a leaf cell which is
associated with a pane.

The major functional changes are:

- panes may now be split arbitrarily both horizontally (splitw -h, C-b %) and
vertically (splitw -v, C-b ");
- panes may be resized both horizontally and vertically (resizep -L/-R/-U/-D,
bound to C-b left/right/up/down and C-b M-left/right/up/down);
- layouts are now applied and then may be modified by resizing or splitting
panes, rather than being fixed and reapplied when the window is resized or
panes are added;
- manual-vertical layout is no longer necessary, and active-only layout is gone
(but may return in future);
- the main-pane layouts now reduce the size of the main pane to fit all panes
if possible.

Thanks to all who tested.


# 1.4 13-Jul-2009 nicm

Having fixed flags for single-character getopt options is a bit hard to
maintain and is only going to get worse as more are used. So instead, add a new
uint64_t member to cmd_entry which is a bitmask of upper and lowercase options
accepted by the command.

This means new single character options can be used without the need to add it
explicitly to the list.


# 1.3 07-Jul-2009 nicm

The fix for default-path (use target session options instead of global options)
is required here as well, doh.


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

lines variable can be -1 (to be ignored), so should be signed. Found by lint.


# 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.97 16-Mar-2020 nicm

Do not attempt to close a NULL pane when failing to create a new one.


# 1.96 15-Oct-2019 nicm

Add support for percentage sizes for resize-pane ("-x 10%"). Also change
split-window and join-pane -l to accept similar percentages and
deprecate -p. From Anindya Mukherjee.


Revision tags: OPENBSD_6_6_BASE
# 1.95 03-May-2019 nicm

Allow panes to be empty (no command), output can be piped to them with
split-window or display-message -I.


# 1.94 28-Apr-2019 nicm

Support multiple occurances of the same argument. Use this for a new
flag -e to new-window, split-window, respawn-window, respawn-pane to
pass environment variables into the newly created process. From Steffen
Christgau in GitHub issue 1697.


# 1.93 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).


# 1.92 17-Apr-2019 nicm

Break new window and pane creation common code from various commands and
window.c into a separate file spawn.c.


Revision tags: OPENBSD_6_5_BASE
# 1.91 18-Oct-2018 nicm

Support for windows larger than visible on the attached client. This has
been a limitation for a long time.

There are two new options, window-size and default-size, and a new
command, resize-window. The force-width and force-height options and the
session_width and session_height formats have been removed.

The new window-size option tells tmux how to work out the size of
windows: largest means it picks the size of the largest session,
smallest the smallest session (similar to the old behaviour) and manual
means that it does not automatically resize windows. The default is
currently largest but this may change. aggressive-resize modifies the
choice of session for largest and smallest as it did before.

If a window is in a session attached to a client that is too small, only
part of the window is shown. tmux attempts to keep the cursor visible,
so the part of the window displayed is changed as the cursor moves (with
a small delay, to try and avoid excess redrawing when applications
redraw status lines or similar that are not currently visible). The
offset of the visible portion of the window is shown in status-right.

Drawing windows which are larger than the client is not as efficient as
those which fit, particularly when the cursor moves, so it is
recommended to avoid using this on slow machines or networks (set
window-size to smallest or manual).

The resize-window command can be used to resize a window manually. If it
is used, the window-size option is automatically set to manual for the
window (undo this with "setw -u window-size"). resize-window works in a
similar way to resize-pane (-U -D -L -R -x -y flags) but also has -a and
-A flags. -a sets the window to the size of the smallest client (what it
would be if window-size was smallest) and -A the largest.

For the same behaviour as force-width or force-height, use resize-window
-x or -y, and "setw -u window-size" to revert to automatic sizing..

If the global window-size option is set to manual, the default-size
option is used for new windows. If -x or -y is used with new-session,
that sets the default-size option for the new session.

The maximum size of a window is 10000x10000. But expect applications to
complain and much higher memory use if making a window excessively
big. The minimum size is the size required for the current layout
including borders.

The refresh-client command can be used to pan around a window, -U -D -L
-R moves up, down, left or right and -c returns to automatic cursor
tracking. The position is reset when the current window is changed.


Revision tags: OPENBSD_6_4_BASE
# 1.90 24-May-2018 nicm

Make server_client_get_cwd used (almost) everywhere we need to work out
the cwd, and do not fall back to "." as it is pretty useless. GitHub
issue 1331.


Revision tags: OPENBSD_6_3_BASE
# 1.89 16-Mar-2018 nicm

Insert full size panes at the right position, from KOIE Hidetaka in
GitHub issue 1284.


# 1.88 01-Mar-2018 nicm

Expand formats in window and session names.


Revision tags: OPENBSD_6_2_BASE
# 1.87 30-Aug-2017 nicm

Pass flags into cmd_find_from_* to fix prefer-unattached, reported by
Thomas Sattler.


# 1.86 21-Jul-2017 nicm

Add -c for respawn-pane and respawn-window, from J Raynor.


# 1.85 30-May-2017 nicm

Rewrite of choose mode, both to simplify and tidy the code and to add
some modern features.

Now the common code is in mode-tree.c, which provides an API used by the
three modes now separated into window-{buffer,client,tree}.c. Buffer
mode shows buffers, client mode clients and tree mode a tree of
sessions, windows and panes.

Each mode has a common set of key bindings plus a few that are specific
to the mode. Other changes are:

- each mode has a preview pane: for buffers this is the buffer content
(very useful), for others it is a preview of the pane;

- items may be sorted in different ways ('O' key);

- multiple items may be tagged and an operation applied to all of them
(for example, to delete multiple buffers at once);

- in tree mode a command may be run on the selected item (session,
window, pane) or on tagged items (key ':');

- displayed items may be filtered in tree mode by using a format (this
is used to implement find-window) (key 'f');

- the custom format (-F) for the display is no longer available;

- shortcut keys change from 0-9, a-z, A-Z which was always a bit weird
with keys used for other uses to 0-9, M-a to M-z.

Now that the code is simpler, other improvements will come later.

Primary key bindings for each mode are documented under the commands in
the man page (choose-buffer, choose-client, choose-tree).

Parts written by Thomas Adam.


# 1.84 25-Apr-2017 nicm

Do not update TERM into config file parsing has finished.


# 1.83 22-Apr-2017 nicm

Get rid of the extra layer of flags and cmd_prepare() and just store the
CMD_FIND_* flags in the cmd_entry and call it for the command. Commands
with special requirements call it themselves and update the target for
hooks to use.


# 1.82 22-Apr-2017 nicm

Mouse bindings and hooks set up an initial current state when running a
command. This is used for the session, window and pane for all commands
in the command sequence if there is no -t or -s.

However, using it for all commands in the command sequence means that if
the active pane or current session is changed, subsequent commands still
use the previous state. So make commands which explicitly change the
current state (such as neww and selectp) update it themselves for later
commands. Commands which may invalidate the state (like killp) are
already OK because an invalid state will be ignored.

Also fill in the current state for all key bindings rather than just the
mouse, so that any omissions are easier to spot.


# 1.81 21-Apr-2017 nicm

Add cmd_find_from_winlink_pane and use it in a couple of places, and
make functions that can't fail void.


Revision tags: OPENBSD_6_1_BASE
# 1.80 09-Mar-2017 nicm

Move server_fill_environ into environ.c and move some other common code
into it.


# 1.79 08-Mar-2017 nicm

Add a helper function for the most common format_create/defaults/expand
pattern.


# 1.78 27-Feb-2017 nicm

If splitw -b is used, insert the new pane before the current one in the
pane list. This means the numbering is in order (for example for
display-panes) and fixes a problem with redrawing the active pane
borders.


# 1.77 03-Feb-2017 nicm

Add a window or pane id "tag" to each format tree and use it to separate
jobs, this means that if the same job is used for different windows or
panes (for example in pane-border-format), it will be run separately for
each pane.


# 1.76 16-Oct-2016 nicm

Use the notify name string instead of going via an enum and change
existing hooks to use notifys instead.


# 1.75 16-Oct-2016 nicm

Mass rename struct cmd_q to struct cmdq_item and related.


# 1.74 16-Oct-2016 nicm

Rewrite command queue handling. Each client still has a command queue,
but there is also now a global command queue. Instead of command queues
being dispatched on demand from wherever the command happens to be
added, they are now all dispatched from the top level server
loop. Command queues may now also include callbacks as well as commands,
and items may be inserted after the current command as well as at the end.

This all makes command queues significantly more predictable and easier
to use, and avoids the complex multiple nested command queues used by
source-file, if-shell and friends.

A mass rename of struct cmdq to a better name (cmdq_item probably) is
coming.


# 1.73 13-Oct-2016 nicm

Trying to do hooks generically is way too complicated and unreliable and
confusing, particularly trying to automatically figure out what target
hooks should be using. So simplify it:

- drop before hooks entirely, they don't seem to be very useful;

- commands with special requirements now fire their own after hook (for
example, if they change session or window, or if they have -t and -s
and need to choose which one the hook uses as current target);

- commands with no special requirements can have the CMD_AFTERHOOK flag
added and they will use the -t state.

At the moment new-session, new-window, split-window fire their own hook,
and display-message uses the flag. The remaining commands still need to
be looked at.


# 1.72 13-Oct-2016 nicm

Some improvements and bug fixes for hooks:

- Prepare the state again before the "after" hooks are run, because the
command may have killed or moved windows.

- Use the hooks list from the newly prepared target, not the old hooks
list (only matters for new-session really).

- Correctly detect an invalid current state and ignore it in
cmd_find_target ("killw; swapw").

- Change neww, new, killp, killw, splitw, swapp, swapw to update the
current state (used if no explicit target is given) to something more
useful after they have finished. For example, neww changes it to the
newly created window.

Hooks are still relatively new and primitive so there are likely to be
more changes to come.

Parts based on bug reports from Uwe Werler and Iblis Lin.


# 1.71 10-Oct-2016 nicm

Add static in cmd-* and fix a few other nits.


# 1.70 04-Sep-2016 nicm

Add support for performing a full width split (with splitw -f), rather
than splitting the current cell. From Stephen Kent.


Revision tags: OPENBSD_6_0_BASE
# 1.69 06-Jun-2016 nicm

Insert new panes after the pane being split in the list rather than
always after the active pane. This is more sensible when doing it with
commands rather than keys.


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

I no longer use my SourceForge address so replace it.


# 1.67 14-Dec-2015 nicm

Instead of combined flags for -c, -s, -t, split into different sets
using an enum and simplify the parsing code.


# 1.66 13-Dec-2015 nicm

Use member names in cmd_entry definitions so I stop getting confused
about the order.


# 1.65 13-Dec-2015 nicm

Instead of every command resolving the target (-t or -s) itself, prepare
the state (client, session, winlink, pane) for it it before entering the
command. Each command provides some flags that tell the prepare step
what it is expecting.

This is a requirement for having hooks on commands (for example, if you
hook "select-window -t1:2", the hook command should to operate on window
1:2 not whatever it thinks is the current window), and should allow some
other target improvements.

The old cmd_find_* functions remain for the moment but that layer will
be dropped later.

Joint work with Thomas Adam.


# 1.64 11-Dec-2015 nicm

Add cmdq as an argument to format_create and add a format for the
command name (will also be used for more later).


# 1.63 08-Dec-2015 nicm

Remove format_create_flags and just pass flags to format_create.


# 1.62 31-Oct-2015 nicm

Fall back silently to ~ or / rather than checking -c with access(), this
was the old behaviour.


# 1.61 31-Oct-2015 nicm

Because pledge(2) does not allow us to pass directory file descriptors
around, we can't use file descriptors for the working directory because
we will be unable to pass it to a privileged process to tell it where to
read or write files or spawn children. So move tmux back to using
strings for the current working directory. We try to check it exists
with access() when it is set but ultimately fall back to ~ if it fails
at time of use (or / if that fails too).


# 1.60 28-Oct-2015 nicm

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


# 1.59 27-Oct-2015 nicm

Move struct options into options.c.


# 1.58 23-Oct-2015 nicm

Remove some unnecessary checks before free().


Revision tags: OPENBSD_5_8_BASE
# 1.57 26-Apr-2015 nicm

Remove panes from layout if spawning them fails, reported by Anthony J
Bentley.


Revision tags: OPENBSD_5_7_BASE
# 1.56 05-Feb-2015 nicm

Remove a couple of now-unused variables.


# 1.55 05-Feb-2015 nicm

Wrap all the individual format_* calls in a single format_defaults
functions.


# 1.54 12-Nov-2014 nicm

Add -b to splitw like joinw, from Felix Rosencrantz.


# 1.53 20-Oct-2014 nicm

Move template defines back into .c files.


# 1.52 20-Oct-2014 nicm

Instead of setting up the default keys by building the key struct
directly with a helper function in the cmd_entry, include a table of
bind-key commands and pass them through the command parser and a
temporary cmd_q.

As well as being smaller, this will allow default bindings to be command
sequences which will probably be needed soon.


# 1.51 01-Sep-2014 nicm

Various minor style and spacing nits.


Revision tags: OPENBSD_5_6_BASE
# 1.50 13-May-2014 nicm

If multiple arguments are given to new-session, new-window,
split-window, respawn-window or respawn-pane, pass them directly to
execvp() to help avoid quoting problems. One argument still goes to "sh
-c" like before. Requested by many over the years. Patch from J Raynor.


# 1.49 17-Apr-2014 nicm

Set PATH explicitly, either from client or session
environment. Previously it came from the session environment. From J
Raynor.


Revision tags: OPENBSD_5_5_BASE
# 1.48 22-Nov-2013 nicm

Handle empty current directory more gracefully.


# 1.47 10-Oct-2013 nicm

Don't boke when figuring out working directory from configuration file.


# 1.46 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.45 10-Oct-2013 nicm

Support -c for new-session, based on code from J Raynor.


# 1.44 10-Oct-2013 nicm

Restore missing key binding for %, from Chris Johnsen.


# 1.43 10-Oct-2013 nicm

Remove the barely-used and unnecessary command check() function.


Revision tags: OPENBSD_5_4_BASE
# 1.42 25-Mar-2013 nicm

Revert the command-prefix change which breaks sequences of commands.


# 1.41 24-Mar-2013 nicm

Add resize-pane -Z to temporary zoom the active pane to occupy the full
window or unzoom (restored to the normal layout) if it already zoomed,
bound to C-b z by default. The pane is unzoomed on pretty much any
excuse whatsoever.

We considered making this a new layout but the requirements are quite
different from layouts so decided it is better as a special case. Each
current layout cell is saved, a temporary one-cell layout generated and
all except the active pane set to NULL.

Prompted by suggestions and scripts from several. Thanks to Aaron Jensen
and Thiago Padilha for testing an earlier version.


# 1.40 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.


# 1.39 24-Mar-2013 nicm

Fix error reporting for client commands by adding a flag to
cmd_find_client to tell it whether or not to show errors, sometimes it's
needed and sometimes not.


# 1.38 24-Mar-2013 nicm

Add option command-prefix which is automatically prepended to any
command (apart from a naked default-shell). The default is "exec ".


Revision tags: OPENBSD_5_3_BASE
# 1.37 09-Dec-2012 nicm

Use the CMD_*_USAGE defines consistently, from Thomas Adam.


# 1.36 14-Aug-2012 nicm

Use a separate define for each default format template and strip clutter
from the choose-tree defaults.


Revision tags: OPENBSD_5_2_BASE
# 1.35 11-Jul-2012 nicm

Make command exec functions return an enum rather than -1/0/1 values and
add a new value to mean "leave client running but don't attach" to fix
problems with using some commands in a command sequence. Most of the
work by Thomas Adam, problem reported by "jspenguin" on SF bug 3535531.


# 1.34 10-Jul-2012 nicm

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


# 1.33 22-May-2012 nicm

Switch all of the various choose- and list- commands over to the format
infrastructure, from Thomas Adam.


# 1.32 17-Mar-2012 nicm

Add notify hooks for various events, the functions are currently empty
stubs but will be filled in for control mode later. From George Nachman.


# 1.31 04-Mar-2012 nicm

free -> xfree.


# 1.30 04-Mar-2012 nicm

Add -F format to new-window and split-window to use with the -P flag,
from George Nachman.


# 1.29 03-Mar-2012 nicm

Add move-pane command (like join-pane but allows the same window). Also
-b flag to join-pane and move-pane to place the pane to the left or
above. From George Nachman.


Revision tags: OPENBSD_5_1_BASE
# 1.28 31-Jan-2012 nicm

Provide defined ways to set the various default-path possibilities: ~
for home directory, . for server start directory, - for session start
directory and empty for the pane's working directory (the default). All
can also be used as part of a relative path (eg -/foo). Also provide -c
flags to neww and splitw to override default-path setting.

Based on a diff from sthen. ok sthen


# 1.27 20-Jan-2012 nicm

Add some const and fix a warning.


# 1.26 09-Dec-2011 nicm

Change the way the working directory for new processes is discovered. If
default-path isn't empty, it is used. Otherwise:

1) If tmux neww is run from the command line, the working directory of the
client is used.

2) Otherwise sysctl KERN_PROC_CWD is used to retrieve the current
working directory of the process in the active pane.

3) If that fails, the directory where the session was created is used.

Support code by Romain Francois, OpenBSD specific bits by me.

Note this requires a recent userland and kernel with KERN_PROC_CWD.


# 1.25 15-Nov-2011 nicm

Make window_pane_index work the same as window_index, from Ben Boeckel.


# 1.24 30-Aug-2011 nicm

Plug memory leak, from Tiago Cunha.


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE
# 1.23 10-Feb-2011 nicm

Size on split-window is -l not -s. Doh.


# 1.22 04-Jan-2011 nicm

Clean up and simplify tmux command argument parsing.

Originally, tmux commands were parsed in the client process into a
struct with the command data which was then serialised and sent to the
server to be executed. The parsing was later moved into the server (an
argv was sent from the client), but the parse step and intermediate
struct was kept.

This change removes that struct and the separate parse step. Argument
parsing and printing is now common to all commands (in arguments.c) with
each command left with just an optional check function (to validate the
arguments at parse time), the exec function and a function to set up any
key bindings (renamed from the old init function).

This is overall more simple and consistent.

There should be no changes to any commands behaviour or syntax although
as this touches every command please watch for any unexpected changes.


# 1.21 01-Jan-2011 nicm

Add a -P option to new-window and split-window to print the new window
or pane index in target form (useful to pass it into other commands).


Revision tags: OPENBSD_4_8_BASE
# 1.20 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.


Revision tags: OPENBSD_4_7_BASE
# 1.19 07-Jan-2010 nicm

New command, join-pane, to split and move an existing pane into the space (like
splitw then movep, or the reverse of breakp).


# 1.18 07-Jan-2010 nicm

Use the specified pane for size calculations. Doh.


# 1.17 07-Jan-2010 nicm

Change split-window to accept a pane target (it should be split-pane but
renaming the command would be annoying).


# 1.16 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.15 20-Nov-2009 nicm

When -h and -p are given to split-window, calculate the percentage size using
the width instead of the height.


# 1.14 13-Nov-2009 nicm

Get rid of the ugly CMD_CHFLAG macro and use a const string (eg "dDU") in the
command entry structs and a couple of functions to check/set the flags.


# 1.13 21-Sep-2009 nicm

Use KEYC_NONE constant instead of 0 on init.


# 1.12 16-Sep-2009 nicm

Rather than constructing an entire termios struct from ttydefaults.h, just let
forkpty do it and then alter the bits that should be changed after fork. A
little neater and more portable.


# 1.11 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.10 25-Aug-2009 nicm

Print -l and -p when showing command, pointed out by Tiago Cunha.


# 1.9 13-Aug-2009 nicm

When creating a new session from the command-line where there is an external
terminal, copy the termios(4) special characters and use them for new windows
created in the new session. Suggested by Theo.


# 1.8 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.7 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.6 22-Jul-2009 nicm

window_add_pane cannot fail, so remove the unused cause argument and don't
bother to check for a NULL return.


# 1.5 19-Jul-2009 nicm

Improved layout code.

Each window now has a tree of layout cells associated with it. In this tree,
each node is either a horizontal or vertical cell containing a list of other
cells running from left-to-right or top-to-bottom, or a leaf cell which is
associated with a pane.

The major functional changes are:

- panes may now be split arbitrarily both horizontally (splitw -h, C-b %) and
vertically (splitw -v, C-b ");
- panes may be resized both horizontally and vertically (resizep -L/-R/-U/-D,
bound to C-b left/right/up/down and C-b M-left/right/up/down);
- layouts are now applied and then may be modified by resizing or splitting
panes, rather than being fixed and reapplied when the window is resized or
panes are added;
- manual-vertical layout is no longer necessary, and active-only layout is gone
(but may return in future);
- the main-pane layouts now reduce the size of the main pane to fit all panes
if possible.

Thanks to all who tested.


# 1.4 13-Jul-2009 nicm

Having fixed flags for single-character getopt options is a bit hard to
maintain and is only going to get worse as more are used. So instead, add a new
uint64_t member to cmd_entry which is a bitmask of upper and lowercase options
accepted by the command.

This means new single character options can be used without the need to add it
explicitly to the list.


# 1.3 07-Jul-2009 nicm

The fix for default-path (use target session options instead of global options)
is required here as well, doh.


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

lines variable can be -1 (to be ignored), so should be signed. Found by lint.


# 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.96 15-Oct-2019 nicm

Add support for percentage sizes for resize-pane ("-x 10%"). Also change
split-window and join-pane -l to accept similar percentages and
deprecate -p. From Anindya Mukherjee.


Revision tags: OPENBSD_6_6_BASE
# 1.95 03-May-2019 nicm

Allow panes to be empty (no command), output can be piped to them with
split-window or display-message -I.


# 1.94 28-Apr-2019 nicm

Support multiple occurances of the same argument. Use this for a new
flag -e to new-window, split-window, respawn-window, respawn-pane to
pass environment variables into the newly created process. From Steffen
Christgau in GitHub issue 1697.


# 1.93 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).


# 1.92 17-Apr-2019 nicm

Break new window and pane creation common code from various commands and
window.c into a separate file spawn.c.


Revision tags: OPENBSD_6_5_BASE
# 1.91 18-Oct-2018 nicm

Support for windows larger than visible on the attached client. This has
been a limitation for a long time.

There are two new options, window-size and default-size, and a new
command, resize-window. The force-width and force-height options and the
session_width and session_height formats have been removed.

The new window-size option tells tmux how to work out the size of
windows: largest means it picks the size of the largest session,
smallest the smallest session (similar to the old behaviour) and manual
means that it does not automatically resize windows. The default is
currently largest but this may change. aggressive-resize modifies the
choice of session for largest and smallest as it did before.

If a window is in a session attached to a client that is too small, only
part of the window is shown. tmux attempts to keep the cursor visible,
so the part of the window displayed is changed as the cursor moves (with
a small delay, to try and avoid excess redrawing when applications
redraw status lines or similar that are not currently visible). The
offset of the visible portion of the window is shown in status-right.

Drawing windows which are larger than the client is not as efficient as
those which fit, particularly when the cursor moves, so it is
recommended to avoid using this on slow machines or networks (set
window-size to smallest or manual).

The resize-window command can be used to resize a window manually. If it
is used, the window-size option is automatically set to manual for the
window (undo this with "setw -u window-size"). resize-window works in a
similar way to resize-pane (-U -D -L -R -x -y flags) but also has -a and
-A flags. -a sets the window to the size of the smallest client (what it
would be if window-size was smallest) and -A the largest.

For the same behaviour as force-width or force-height, use resize-window
-x or -y, and "setw -u window-size" to revert to automatic sizing..

If the global window-size option is set to manual, the default-size
option is used for new windows. If -x or -y is used with new-session,
that sets the default-size option for the new session.

The maximum size of a window is 10000x10000. But expect applications to
complain and much higher memory use if making a window excessively
big. The minimum size is the size required for the current layout
including borders.

The refresh-client command can be used to pan around a window, -U -D -L
-R moves up, down, left or right and -c returns to automatic cursor
tracking. The position is reset when the current window is changed.


Revision tags: OPENBSD_6_4_BASE
# 1.90 24-May-2018 nicm

Make server_client_get_cwd used (almost) everywhere we need to work out
the cwd, and do not fall back to "." as it is pretty useless. GitHub
issue 1331.


Revision tags: OPENBSD_6_3_BASE
# 1.89 16-Mar-2018 nicm

Insert full size panes at the right position, from KOIE Hidetaka in
GitHub issue 1284.


# 1.88 01-Mar-2018 nicm

Expand formats in window and session names.


Revision tags: OPENBSD_6_2_BASE
# 1.87 30-Aug-2017 nicm

Pass flags into cmd_find_from_* to fix prefer-unattached, reported by
Thomas Sattler.


# 1.86 21-Jul-2017 nicm

Add -c for respawn-pane and respawn-window, from J Raynor.


# 1.85 30-May-2017 nicm

Rewrite of choose mode, both to simplify and tidy the code and to add
some modern features.

Now the common code is in mode-tree.c, which provides an API used by the
three modes now separated into window-{buffer,client,tree}.c. Buffer
mode shows buffers, client mode clients and tree mode a tree of
sessions, windows and panes.

Each mode has a common set of key bindings plus a few that are specific
to the mode. Other changes are:

- each mode has a preview pane: for buffers this is the buffer content
(very useful), for others it is a preview of the pane;

- items may be sorted in different ways ('O' key);

- multiple items may be tagged and an operation applied to all of them
(for example, to delete multiple buffers at once);

- in tree mode a command may be run on the selected item (session,
window, pane) or on tagged items (key ':');

- displayed items may be filtered in tree mode by using a format (this
is used to implement find-window) (key 'f');

- the custom format (-F) for the display is no longer available;

- shortcut keys change from 0-9, a-z, A-Z which was always a bit weird
with keys used for other uses to 0-9, M-a to M-z.

Now that the code is simpler, other improvements will come later.

Primary key bindings for each mode are documented under the commands in
the man page (choose-buffer, choose-client, choose-tree).

Parts written by Thomas Adam.


# 1.84 25-Apr-2017 nicm

Do not update TERM into config file parsing has finished.


# 1.83 22-Apr-2017 nicm

Get rid of the extra layer of flags and cmd_prepare() and just store the
CMD_FIND_* flags in the cmd_entry and call it for the command. Commands
with special requirements call it themselves and update the target for
hooks to use.


# 1.82 22-Apr-2017 nicm

Mouse bindings and hooks set up an initial current state when running a
command. This is used for the session, window and pane for all commands
in the command sequence if there is no -t or -s.

However, using it for all commands in the command sequence means that if
the active pane or current session is changed, subsequent commands still
use the previous state. So make commands which explicitly change the
current state (such as neww and selectp) update it themselves for later
commands. Commands which may invalidate the state (like killp) are
already OK because an invalid state will be ignored.

Also fill in the current state for all key bindings rather than just the
mouse, so that any omissions are easier to spot.


# 1.81 21-Apr-2017 nicm

Add cmd_find_from_winlink_pane and use it in a couple of places, and
make functions that can't fail void.


Revision tags: OPENBSD_6_1_BASE
# 1.80 09-Mar-2017 nicm

Move server_fill_environ into environ.c and move some other common code
into it.


# 1.79 08-Mar-2017 nicm

Add a helper function for the most common format_create/defaults/expand
pattern.


# 1.78 27-Feb-2017 nicm

If splitw -b is used, insert the new pane before the current one in the
pane list. This means the numbering is in order (for example for
display-panes) and fixes a problem with redrawing the active pane
borders.


# 1.77 03-Feb-2017 nicm

Add a window or pane id "tag" to each format tree and use it to separate
jobs, this means that if the same job is used for different windows or
panes (for example in pane-border-format), it will be run separately for
each pane.


# 1.76 16-Oct-2016 nicm

Use the notify name string instead of going via an enum and change
existing hooks to use notifys instead.


# 1.75 16-Oct-2016 nicm

Mass rename struct cmd_q to struct cmdq_item and related.


# 1.74 16-Oct-2016 nicm

Rewrite command queue handling. Each client still has a command queue,
but there is also now a global command queue. Instead of command queues
being dispatched on demand from wherever the command happens to be
added, they are now all dispatched from the top level server
loop. Command queues may now also include callbacks as well as commands,
and items may be inserted after the current command as well as at the end.

This all makes command queues significantly more predictable and easier
to use, and avoids the complex multiple nested command queues used by
source-file, if-shell and friends.

A mass rename of struct cmdq to a better name (cmdq_item probably) is
coming.


# 1.73 13-Oct-2016 nicm

Trying to do hooks generically is way too complicated and unreliable and
confusing, particularly trying to automatically figure out what target
hooks should be using. So simplify it:

- drop before hooks entirely, they don't seem to be very useful;

- commands with special requirements now fire their own after hook (for
example, if they change session or window, or if they have -t and -s
and need to choose which one the hook uses as current target);

- commands with no special requirements can have the CMD_AFTERHOOK flag
added and they will use the -t state.

At the moment new-session, new-window, split-window fire their own hook,
and display-message uses the flag. The remaining commands still need to
be looked at.


# 1.72 13-Oct-2016 nicm

Some improvements and bug fixes for hooks:

- Prepare the state again before the "after" hooks are run, because the
command may have killed or moved windows.

- Use the hooks list from the newly prepared target, not the old hooks
list (only matters for new-session really).

- Correctly detect an invalid current state and ignore it in
cmd_find_target ("killw; swapw").

- Change neww, new, killp, killw, splitw, swapp, swapw to update the
current state (used if no explicit target is given) to something more
useful after they have finished. For example, neww changes it to the
newly created window.

Hooks are still relatively new and primitive so there are likely to be
more changes to come.

Parts based on bug reports from Uwe Werler and Iblis Lin.


# 1.71 10-Oct-2016 nicm

Add static in cmd-* and fix a few other nits.


# 1.70 04-Sep-2016 nicm

Add support for performing a full width split (with splitw -f), rather
than splitting the current cell. From Stephen Kent.


Revision tags: OPENBSD_6_0_BASE
# 1.69 06-Jun-2016 nicm

Insert new panes after the pane being split in the list rather than
always after the active pane. This is more sensible when doing it with
commands rather than keys.


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

I no longer use my SourceForge address so replace it.


# 1.67 14-Dec-2015 nicm

Instead of combined flags for -c, -s, -t, split into different sets
using an enum and simplify the parsing code.


# 1.66 13-Dec-2015 nicm

Use member names in cmd_entry definitions so I stop getting confused
about the order.


# 1.65 13-Dec-2015 nicm

Instead of every command resolving the target (-t or -s) itself, prepare
the state (client, session, winlink, pane) for it it before entering the
command. Each command provides some flags that tell the prepare step
what it is expecting.

This is a requirement for having hooks on commands (for example, if you
hook "select-window -t1:2", the hook command should to operate on window
1:2 not whatever it thinks is the current window), and should allow some
other target improvements.

The old cmd_find_* functions remain for the moment but that layer will
be dropped later.

Joint work with Thomas Adam.


# 1.64 11-Dec-2015 nicm

Add cmdq as an argument to format_create and add a format for the
command name (will also be used for more later).


# 1.63 08-Dec-2015 nicm

Remove format_create_flags and just pass flags to format_create.


# 1.62 31-Oct-2015 nicm

Fall back silently to ~ or / rather than checking -c with access(), this
was the old behaviour.


# 1.61 31-Oct-2015 nicm

Because pledge(2) does not allow us to pass directory file descriptors
around, we can't use file descriptors for the working directory because
we will be unable to pass it to a privileged process to tell it where to
read or write files or spawn children. So move tmux back to using
strings for the current working directory. We try to check it exists
with access() when it is set but ultimately fall back to ~ if it fails
at time of use (or / if that fails too).


# 1.60 28-Oct-2015 nicm

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


# 1.59 27-Oct-2015 nicm

Move struct options into options.c.


# 1.58 23-Oct-2015 nicm

Remove some unnecessary checks before free().


Revision tags: OPENBSD_5_8_BASE
# 1.57 26-Apr-2015 nicm

Remove panes from layout if spawning them fails, reported by Anthony J
Bentley.


Revision tags: OPENBSD_5_7_BASE
# 1.56 05-Feb-2015 nicm

Remove a couple of now-unused variables.


# 1.55 05-Feb-2015 nicm

Wrap all the individual format_* calls in a single format_defaults
functions.


# 1.54 12-Nov-2014 nicm

Add -b to splitw like joinw, from Felix Rosencrantz.


# 1.53 20-Oct-2014 nicm

Move template defines back into .c files.


# 1.52 20-Oct-2014 nicm

Instead of setting up the default keys by building the key struct
directly with a helper function in the cmd_entry, include a table of
bind-key commands and pass them through the command parser and a
temporary cmd_q.

As well as being smaller, this will allow default bindings to be command
sequences which will probably be needed soon.


# 1.51 01-Sep-2014 nicm

Various minor style and spacing nits.


Revision tags: OPENBSD_5_6_BASE
# 1.50 13-May-2014 nicm

If multiple arguments are given to new-session, new-window,
split-window, respawn-window or respawn-pane, pass them directly to
execvp() to help avoid quoting problems. One argument still goes to "sh
-c" like before. Requested by many over the years. Patch from J Raynor.


# 1.49 17-Apr-2014 nicm

Set PATH explicitly, either from client or session
environment. Previously it came from the session environment. From J
Raynor.


Revision tags: OPENBSD_5_5_BASE
# 1.48 22-Nov-2013 nicm

Handle empty current directory more gracefully.


# 1.47 10-Oct-2013 nicm

Don't boke when figuring out working directory from configuration file.


# 1.46 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.45 10-Oct-2013 nicm

Support -c for new-session, based on code from J Raynor.


# 1.44 10-Oct-2013 nicm

Restore missing key binding for %, from Chris Johnsen.


# 1.43 10-Oct-2013 nicm

Remove the barely-used and unnecessary command check() function.


Revision tags: OPENBSD_5_4_BASE
# 1.42 25-Mar-2013 nicm

Revert the command-prefix change which breaks sequences of commands.


# 1.41 24-Mar-2013 nicm

Add resize-pane -Z to temporary zoom the active pane to occupy the full
window or unzoom (restored to the normal layout) if it already zoomed,
bound to C-b z by default. The pane is unzoomed on pretty much any
excuse whatsoever.

We considered making this a new layout but the requirements are quite
different from layouts so decided it is better as a special case. Each
current layout cell is saved, a temporary one-cell layout generated and
all except the active pane set to NULL.

Prompted by suggestions and scripts from several. Thanks to Aaron Jensen
and Thiago Padilha for testing an earlier version.


# 1.40 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.


# 1.39 24-Mar-2013 nicm

Fix error reporting for client commands by adding a flag to
cmd_find_client to tell it whether or not to show errors, sometimes it's
needed and sometimes not.


# 1.38 24-Mar-2013 nicm

Add option command-prefix which is automatically prepended to any
command (apart from a naked default-shell). The default is "exec ".


Revision tags: OPENBSD_5_3_BASE
# 1.37 09-Dec-2012 nicm

Use the CMD_*_USAGE defines consistently, from Thomas Adam.


# 1.36 14-Aug-2012 nicm

Use a separate define for each default format template and strip clutter
from the choose-tree defaults.


Revision tags: OPENBSD_5_2_BASE
# 1.35 11-Jul-2012 nicm

Make command exec functions return an enum rather than -1/0/1 values and
add a new value to mean "leave client running but don't attach" to fix
problems with using some commands in a command sequence. Most of the
work by Thomas Adam, problem reported by "jspenguin" on SF bug 3535531.


# 1.34 10-Jul-2012 nicm

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


# 1.33 22-May-2012 nicm

Switch all of the various choose- and list- commands over to the format
infrastructure, from Thomas Adam.


# 1.32 17-Mar-2012 nicm

Add notify hooks for various events, the functions are currently empty
stubs but will be filled in for control mode later. From George Nachman.


# 1.31 04-Mar-2012 nicm

free -> xfree.


# 1.30 04-Mar-2012 nicm

Add -F format to new-window and split-window to use with the -P flag,
from George Nachman.


# 1.29 03-Mar-2012 nicm

Add move-pane command (like join-pane but allows the same window). Also
-b flag to join-pane and move-pane to place the pane to the left or
above. From George Nachman.


Revision tags: OPENBSD_5_1_BASE
# 1.28 31-Jan-2012 nicm

Provide defined ways to set the various default-path possibilities: ~
for home directory, . for server start directory, - for session start
directory and empty for the pane's working directory (the default). All
can also be used as part of a relative path (eg -/foo). Also provide -c
flags to neww and splitw to override default-path setting.

Based on a diff from sthen. ok sthen


# 1.27 20-Jan-2012 nicm

Add some const and fix a warning.


# 1.26 09-Dec-2011 nicm

Change the way the working directory for new processes is discovered. If
default-path isn't empty, it is used. Otherwise:

1) If tmux neww is run from the command line, the working directory of the
client is used.

2) Otherwise sysctl KERN_PROC_CWD is used to retrieve the current
working directory of the process in the active pane.

3) If that fails, the directory where the session was created is used.

Support code by Romain Francois, OpenBSD specific bits by me.

Note this requires a recent userland and kernel with KERN_PROC_CWD.


# 1.25 15-Nov-2011 nicm

Make window_pane_index work the same as window_index, from Ben Boeckel.


# 1.24 30-Aug-2011 nicm

Plug memory leak, from Tiago Cunha.


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE
# 1.23 10-Feb-2011 nicm

Size on split-window is -l not -s. Doh.


# 1.22 04-Jan-2011 nicm

Clean up and simplify tmux command argument parsing.

Originally, tmux commands were parsed in the client process into a
struct with the command data which was then serialised and sent to the
server to be executed. The parsing was later moved into the server (an
argv was sent from the client), but the parse step and intermediate
struct was kept.

This change removes that struct and the separate parse step. Argument
parsing and printing is now common to all commands (in arguments.c) with
each command left with just an optional check function (to validate the
arguments at parse time), the exec function and a function to set up any
key bindings (renamed from the old init function).

This is overall more simple and consistent.

There should be no changes to any commands behaviour or syntax although
as this touches every command please watch for any unexpected changes.


# 1.21 01-Jan-2011 nicm

Add a -P option to new-window and split-window to print the new window
or pane index in target form (useful to pass it into other commands).


Revision tags: OPENBSD_4_8_BASE
# 1.20 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.


Revision tags: OPENBSD_4_7_BASE
# 1.19 07-Jan-2010 nicm

New command, join-pane, to split and move an existing pane into the space (like
splitw then movep, or the reverse of breakp).


# 1.18 07-Jan-2010 nicm

Use the specified pane for size calculations. Doh.


# 1.17 07-Jan-2010 nicm

Change split-window to accept a pane target (it should be split-pane but
renaming the command would be annoying).


# 1.16 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.15 20-Nov-2009 nicm

When -h and -p are given to split-window, calculate the percentage size using
the width instead of the height.


# 1.14 13-Nov-2009 nicm

Get rid of the ugly CMD_CHFLAG macro and use a const string (eg "dDU") in the
command entry structs and a couple of functions to check/set the flags.


# 1.13 21-Sep-2009 nicm

Use KEYC_NONE constant instead of 0 on init.


# 1.12 16-Sep-2009 nicm

Rather than constructing an entire termios struct from ttydefaults.h, just let
forkpty do it and then alter the bits that should be changed after fork. A
little neater and more portable.


# 1.11 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.10 25-Aug-2009 nicm

Print -l and -p when showing command, pointed out by Tiago Cunha.


# 1.9 13-Aug-2009 nicm

When creating a new session from the command-line where there is an external
terminal, copy the termios(4) special characters and use them for new windows
created in the new session. Suggested by Theo.


# 1.8 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.7 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.6 22-Jul-2009 nicm

window_add_pane cannot fail, so remove the unused cause argument and don't
bother to check for a NULL return.


# 1.5 19-Jul-2009 nicm

Improved layout code.

Each window now has a tree of layout cells associated with it. In this tree,
each node is either a horizontal or vertical cell containing a list of other
cells running from left-to-right or top-to-bottom, or a leaf cell which is
associated with a pane.

The major functional changes are:

- panes may now be split arbitrarily both horizontally (splitw -h, C-b %) and
vertically (splitw -v, C-b ");
- panes may be resized both horizontally and vertically (resizep -L/-R/-U/-D,
bound to C-b left/right/up/down and C-b M-left/right/up/down);
- layouts are now applied and then may be modified by resizing or splitting
panes, rather than being fixed and reapplied when the window is resized or
panes are added;
- manual-vertical layout is no longer necessary, and active-only layout is gone
(but may return in future);
- the main-pane layouts now reduce the size of the main pane to fit all panes
if possible.

Thanks to all who tested.


# 1.4 13-Jul-2009 nicm

Having fixed flags for single-character getopt options is a bit hard to
maintain and is only going to get worse as more are used. So instead, add a new
uint64_t member to cmd_entry which is a bitmask of upper and lowercase options
accepted by the command.

This means new single character options can be used without the need to add it
explicitly to the list.


# 1.3 07-Jul-2009 nicm

The fix for default-path (use target session options instead of global options)
is required here as well, doh.


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

lines variable can be -1 (to be ignored), so should be signed. Found by lint.


# 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.95 03-May-2019 nicm

Allow panes to be empty (no command), output can be piped to them with
split-window or display-message -I.


# 1.94 28-Apr-2019 nicm

Support multiple occurances of the same argument. Use this for a new
flag -e to new-window, split-window, respawn-window, respawn-pane to
pass environment variables into the newly created process. From Steffen
Christgau in GitHub issue 1697.


# 1.93 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).


# 1.92 17-Apr-2019 nicm

Break new window and pane creation common code from various commands and
window.c into a separate file spawn.c.


Revision tags: OPENBSD_6_5_BASE
# 1.91 18-Oct-2018 nicm

Support for windows larger than visible on the attached client. This has
been a limitation for a long time.

There are two new options, window-size and default-size, and a new
command, resize-window. The force-width and force-height options and the
session_width and session_height formats have been removed.

The new window-size option tells tmux how to work out the size of
windows: largest means it picks the size of the largest session,
smallest the smallest session (similar to the old behaviour) and manual
means that it does not automatically resize windows. The default is
currently largest but this may change. aggressive-resize modifies the
choice of session for largest and smallest as it did before.

If a window is in a session attached to a client that is too small, only
part of the window is shown. tmux attempts to keep the cursor visible,
so the part of the window displayed is changed as the cursor moves (with
a small delay, to try and avoid excess redrawing when applications
redraw status lines or similar that are not currently visible). The
offset of the visible portion of the window is shown in status-right.

Drawing windows which are larger than the client is not as efficient as
those which fit, particularly when the cursor moves, so it is
recommended to avoid using this on slow machines or networks (set
window-size to smallest or manual).

The resize-window command can be used to resize a window manually. If it
is used, the window-size option is automatically set to manual for the
window (undo this with "setw -u window-size"). resize-window works in a
similar way to resize-pane (-U -D -L -R -x -y flags) but also has -a and
-A flags. -a sets the window to the size of the smallest client (what it
would be if window-size was smallest) and -A the largest.

For the same behaviour as force-width or force-height, use resize-window
-x or -y, and "setw -u window-size" to revert to automatic sizing..

If the global window-size option is set to manual, the default-size
option is used for new windows. If -x or -y is used with new-session,
that sets the default-size option for the new session.

The maximum size of a window is 10000x10000. But expect applications to
complain and much higher memory use if making a window excessively
big. The minimum size is the size required for the current layout
including borders.

The refresh-client command can be used to pan around a window, -U -D -L
-R moves up, down, left or right and -c returns to automatic cursor
tracking. The position is reset when the current window is changed.


Revision tags: OPENBSD_6_4_BASE
# 1.90 24-May-2018 nicm

Make server_client_get_cwd used (almost) everywhere we need to work out
the cwd, and do not fall back to "." as it is pretty useless. GitHub
issue 1331.


Revision tags: OPENBSD_6_3_BASE
# 1.89 16-Mar-2018 nicm

Insert full size panes at the right position, from KOIE Hidetaka in
GitHub issue 1284.


# 1.88 01-Mar-2018 nicm

Expand formats in window and session names.


Revision tags: OPENBSD_6_2_BASE
# 1.87 30-Aug-2017 nicm

Pass flags into cmd_find_from_* to fix prefer-unattached, reported by
Thomas Sattler.


# 1.86 21-Jul-2017 nicm

Add -c for respawn-pane and respawn-window, from J Raynor.


# 1.85 30-May-2017 nicm

Rewrite of choose mode, both to simplify and tidy the code and to add
some modern features.

Now the common code is in mode-tree.c, which provides an API used by the
three modes now separated into window-{buffer,client,tree}.c. Buffer
mode shows buffers, client mode clients and tree mode a tree of
sessions, windows and panes.

Each mode has a common set of key bindings plus a few that are specific
to the mode. Other changes are:

- each mode has a preview pane: for buffers this is the buffer content
(very useful), for others it is a preview of the pane;

- items may be sorted in different ways ('O' key);

- multiple items may be tagged and an operation applied to all of them
(for example, to delete multiple buffers at once);

- in tree mode a command may be run on the selected item (session,
window, pane) or on tagged items (key ':');

- displayed items may be filtered in tree mode by using a format (this
is used to implement find-window) (key 'f');

- the custom format (-F) for the display is no longer available;

- shortcut keys change from 0-9, a-z, A-Z which was always a bit weird
with keys used for other uses to 0-9, M-a to M-z.

Now that the code is simpler, other improvements will come later.

Primary key bindings for each mode are documented under the commands in
the man page (choose-buffer, choose-client, choose-tree).

Parts written by Thomas Adam.


# 1.84 25-Apr-2017 nicm

Do not update TERM into config file parsing has finished.


# 1.83 22-Apr-2017 nicm

Get rid of the extra layer of flags and cmd_prepare() and just store the
CMD_FIND_* flags in the cmd_entry and call it for the command. Commands
with special requirements call it themselves and update the target for
hooks to use.


# 1.82 22-Apr-2017 nicm

Mouse bindings and hooks set up an initial current state when running a
command. This is used for the session, window and pane for all commands
in the command sequence if there is no -t or -s.

However, using it for all commands in the command sequence means that if
the active pane or current session is changed, subsequent commands still
use the previous state. So make commands which explicitly change the
current state (such as neww and selectp) update it themselves for later
commands. Commands which may invalidate the state (like killp) are
already OK because an invalid state will be ignored.

Also fill in the current state for all key bindings rather than just the
mouse, so that any omissions are easier to spot.


# 1.81 21-Apr-2017 nicm

Add cmd_find_from_winlink_pane and use it in a couple of places, and
make functions that can't fail void.


Revision tags: OPENBSD_6_1_BASE
# 1.80 09-Mar-2017 nicm

Move server_fill_environ into environ.c and move some other common code
into it.


# 1.79 08-Mar-2017 nicm

Add a helper function for the most common format_create/defaults/expand
pattern.


# 1.78 27-Feb-2017 nicm

If splitw -b is used, insert the new pane before the current one in the
pane list. This means the numbering is in order (for example for
display-panes) and fixes a problem with redrawing the active pane
borders.


# 1.77 03-Feb-2017 nicm

Add a window or pane id "tag" to each format tree and use it to separate
jobs, this means that if the same job is used for different windows or
panes (for example in pane-border-format), it will be run separately for
each pane.


# 1.76 16-Oct-2016 nicm

Use the notify name string instead of going via an enum and change
existing hooks to use notifys instead.


# 1.75 16-Oct-2016 nicm

Mass rename struct cmd_q to struct cmdq_item and related.


# 1.74 16-Oct-2016 nicm

Rewrite command queue handling. Each client still has a command queue,
but there is also now a global command queue. Instead of command queues
being dispatched on demand from wherever the command happens to be
added, they are now all dispatched from the top level server
loop. Command queues may now also include callbacks as well as commands,
and items may be inserted after the current command as well as at the end.

This all makes command queues significantly more predictable and easier
to use, and avoids the complex multiple nested command queues used by
source-file, if-shell and friends.

A mass rename of struct cmdq to a better name (cmdq_item probably) is
coming.


# 1.73 13-Oct-2016 nicm

Trying to do hooks generically is way too complicated and unreliable and
confusing, particularly trying to automatically figure out what target
hooks should be using. So simplify it:

- drop before hooks entirely, they don't seem to be very useful;

- commands with special requirements now fire their own after hook (for
example, if they change session or window, or if they have -t and -s
and need to choose which one the hook uses as current target);

- commands with no special requirements can have the CMD_AFTERHOOK flag
added and they will use the -t state.

At the moment new-session, new-window, split-window fire their own hook,
and display-message uses the flag. The remaining commands still need to
be looked at.


# 1.72 13-Oct-2016 nicm

Some improvements and bug fixes for hooks:

- Prepare the state again before the "after" hooks are run, because the
command may have killed or moved windows.

- Use the hooks list from the newly prepared target, not the old hooks
list (only matters for new-session really).

- Correctly detect an invalid current state and ignore it in
cmd_find_target ("killw; swapw").

- Change neww, new, killp, killw, splitw, swapp, swapw to update the
current state (used if no explicit target is given) to something more
useful after they have finished. For example, neww changes it to the
newly created window.

Hooks are still relatively new and primitive so there are likely to be
more changes to come.

Parts based on bug reports from Uwe Werler and Iblis Lin.


# 1.71 10-Oct-2016 nicm

Add static in cmd-* and fix a few other nits.


# 1.70 04-Sep-2016 nicm

Add support for performing a full width split (with splitw -f), rather
than splitting the current cell. From Stephen Kent.


Revision tags: OPENBSD_6_0_BASE
# 1.69 06-Jun-2016 nicm

Insert new panes after the pane being split in the list rather than
always after the active pane. This is more sensible when doing it with
commands rather than keys.


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

I no longer use my SourceForge address so replace it.


# 1.67 14-Dec-2015 nicm

Instead of combined flags for -c, -s, -t, split into different sets
using an enum and simplify the parsing code.


# 1.66 13-Dec-2015 nicm

Use member names in cmd_entry definitions so I stop getting confused
about the order.


# 1.65 13-Dec-2015 nicm

Instead of every command resolving the target (-t or -s) itself, prepare
the state (client, session, winlink, pane) for it it before entering the
command. Each command provides some flags that tell the prepare step
what it is expecting.

This is a requirement for having hooks on commands (for example, if you
hook "select-window -t1:2", the hook command should to operate on window
1:2 not whatever it thinks is the current window), and should allow some
other target improvements.

The old cmd_find_* functions remain for the moment but that layer will
be dropped later.

Joint work with Thomas Adam.


# 1.64 11-Dec-2015 nicm

Add cmdq as an argument to format_create and add a format for the
command name (will also be used for more later).


# 1.63 08-Dec-2015 nicm

Remove format_create_flags and just pass flags to format_create.


# 1.62 31-Oct-2015 nicm

Fall back silently to ~ or / rather than checking -c with access(), this
was the old behaviour.


# 1.61 31-Oct-2015 nicm

Because pledge(2) does not allow us to pass directory file descriptors
around, we can't use file descriptors for the working directory because
we will be unable to pass it to a privileged process to tell it where to
read or write files or spawn children. So move tmux back to using
strings for the current working directory. We try to check it exists
with access() when it is set but ultimately fall back to ~ if it fails
at time of use (or / if that fails too).


# 1.60 28-Oct-2015 nicm

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


# 1.59 27-Oct-2015 nicm

Move struct options into options.c.


# 1.58 23-Oct-2015 nicm

Remove some unnecessary checks before free().


Revision tags: OPENBSD_5_8_BASE
# 1.57 26-Apr-2015 nicm

Remove panes from layout if spawning them fails, reported by Anthony J
Bentley.


Revision tags: OPENBSD_5_7_BASE
# 1.56 05-Feb-2015 nicm

Remove a couple of now-unused variables.


# 1.55 05-Feb-2015 nicm

Wrap all the individual format_* calls in a single format_defaults
functions.


# 1.54 12-Nov-2014 nicm

Add -b to splitw like joinw, from Felix Rosencrantz.


# 1.53 20-Oct-2014 nicm

Move template defines back into .c files.


# 1.52 20-Oct-2014 nicm

Instead of setting up the default keys by building the key struct
directly with a helper function in the cmd_entry, include a table of
bind-key commands and pass them through the command parser and a
temporary cmd_q.

As well as being smaller, this will allow default bindings to be command
sequences which will probably be needed soon.


# 1.51 01-Sep-2014 nicm

Various minor style and spacing nits.


Revision tags: OPENBSD_5_6_BASE
# 1.50 13-May-2014 nicm

If multiple arguments are given to new-session, new-window,
split-window, respawn-window or respawn-pane, pass them directly to
execvp() to help avoid quoting problems. One argument still goes to "sh
-c" like before. Requested by many over the years. Patch from J Raynor.


# 1.49 17-Apr-2014 nicm

Set PATH explicitly, either from client or session
environment. Previously it came from the session environment. From J
Raynor.


Revision tags: OPENBSD_5_5_BASE
# 1.48 22-Nov-2013 nicm

Handle empty current directory more gracefully.


# 1.47 10-Oct-2013 nicm

Don't boke when figuring out working directory from configuration file.


# 1.46 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.45 10-Oct-2013 nicm

Support -c for new-session, based on code from J Raynor.


# 1.44 10-Oct-2013 nicm

Restore missing key binding for %, from Chris Johnsen.


# 1.43 10-Oct-2013 nicm

Remove the barely-used and unnecessary command check() function.


Revision tags: OPENBSD_5_4_BASE
# 1.42 25-Mar-2013 nicm

Revert the command-prefix change which breaks sequences of commands.


# 1.41 24-Mar-2013 nicm

Add resize-pane -Z to temporary zoom the active pane to occupy the full
window or unzoom (restored to the normal layout) if it already zoomed,
bound to C-b z by default. The pane is unzoomed on pretty much any
excuse whatsoever.

We considered making this a new layout but the requirements are quite
different from layouts so decided it is better as a special case. Each
current layout cell is saved, a temporary one-cell layout generated and
all except the active pane set to NULL.

Prompted by suggestions and scripts from several. Thanks to Aaron Jensen
and Thiago Padilha for testing an earlier version.


# 1.40 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.


# 1.39 24-Mar-2013 nicm

Fix error reporting for client commands by adding a flag to
cmd_find_client to tell it whether or not to show errors, sometimes it's
needed and sometimes not.


# 1.38 24-Mar-2013 nicm

Add option command-prefix which is automatically prepended to any
command (apart from a naked default-shell). The default is "exec ".


Revision tags: OPENBSD_5_3_BASE
# 1.37 09-Dec-2012 nicm

Use the CMD_*_USAGE defines consistently, from Thomas Adam.


# 1.36 14-Aug-2012 nicm

Use a separate define for each default format template and strip clutter
from the choose-tree defaults.


Revision tags: OPENBSD_5_2_BASE
# 1.35 11-Jul-2012 nicm

Make command exec functions return an enum rather than -1/0/1 values and
add a new value to mean "leave client running but don't attach" to fix
problems with using some commands in a command sequence. Most of the
work by Thomas Adam, problem reported by "jspenguin" on SF bug 3535531.


# 1.34 10-Jul-2012 nicm

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


# 1.33 22-May-2012 nicm

Switch all of the various choose- and list- commands over to the format
infrastructure, from Thomas Adam.


# 1.32 17-Mar-2012 nicm

Add notify hooks for various events, the functions are currently empty
stubs but will be filled in for control mode later. From George Nachman.


# 1.31 04-Mar-2012 nicm

free -> xfree.


# 1.30 04-Mar-2012 nicm

Add -F format to new-window and split-window to use with the -P flag,
from George Nachman.


# 1.29 03-Mar-2012 nicm

Add move-pane command (like join-pane but allows the same window). Also
-b flag to join-pane and move-pane to place the pane to the left or
above. From George Nachman.


Revision tags: OPENBSD_5_1_BASE
# 1.28 31-Jan-2012 nicm

Provide defined ways to set the various default-path possibilities: ~
for home directory, . for server start directory, - for session start
directory and empty for the pane's working directory (the default). All
can also be used as part of a relative path (eg -/foo). Also provide -c
flags to neww and splitw to override default-path setting.

Based on a diff from sthen. ok sthen


# 1.27 20-Jan-2012 nicm

Add some const and fix a warning.


# 1.26 09-Dec-2011 nicm

Change the way the working directory for new processes is discovered. If
default-path isn't empty, it is used. Otherwise:

1) If tmux neww is run from the command line, the working directory of the
client is used.

2) Otherwise sysctl KERN_PROC_CWD is used to retrieve the current
working directory of the process in the active pane.

3) If that fails, the directory where the session was created is used.

Support code by Romain Francois, OpenBSD specific bits by me.

Note this requires a recent userland and kernel with KERN_PROC_CWD.


# 1.25 15-Nov-2011 nicm

Make window_pane_index work the same as window_index, from Ben Boeckel.


# 1.24 30-Aug-2011 nicm

Plug memory leak, from Tiago Cunha.


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE
# 1.23 10-Feb-2011 nicm

Size on split-window is -l not -s. Doh.


# 1.22 04-Jan-2011 nicm

Clean up and simplify tmux command argument parsing.

Originally, tmux commands were parsed in the client process into a
struct with the command data which was then serialised and sent to the
server to be executed. The parsing was later moved into the server (an
argv was sent from the client), but the parse step and intermediate
struct was kept.

This change removes that struct and the separate parse step. Argument
parsing and printing is now common to all commands (in arguments.c) with
each command left with just an optional check function (to validate the
arguments at parse time), the exec function and a function to set up any
key bindings (renamed from the old init function).

This is overall more simple and consistent.

There should be no changes to any commands behaviour or syntax although
as this touches every command please watch for any unexpected changes.


# 1.21 01-Jan-2011 nicm

Add a -P option to new-window and split-window to print the new window
or pane index in target form (useful to pass it into other commands).


Revision tags: OPENBSD_4_8_BASE
# 1.20 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.


Revision tags: OPENBSD_4_7_BASE
# 1.19 07-Jan-2010 nicm

New command, join-pane, to split and move an existing pane into the space (like
splitw then movep, or the reverse of breakp).


# 1.18 07-Jan-2010 nicm

Use the specified pane for size calculations. Doh.


# 1.17 07-Jan-2010 nicm

Change split-window to accept a pane target (it should be split-pane but
renaming the command would be annoying).


# 1.16 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.15 20-Nov-2009 nicm

When -h and -p are given to split-window, calculate the percentage size using
the width instead of the height.


# 1.14 13-Nov-2009 nicm

Get rid of the ugly CMD_CHFLAG macro and use a const string (eg "dDU") in the
command entry structs and a couple of functions to check/set the flags.


# 1.13 21-Sep-2009 nicm

Use KEYC_NONE constant instead of 0 on init.


# 1.12 16-Sep-2009 nicm

Rather than constructing an entire termios struct from ttydefaults.h, just let
forkpty do it and then alter the bits that should be changed after fork. A
little neater and more portable.


# 1.11 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.10 25-Aug-2009 nicm

Print -l and -p when showing command, pointed out by Tiago Cunha.


# 1.9 13-Aug-2009 nicm

When creating a new session from the command-line where there is an external
terminal, copy the termios(4) special characters and use them for new windows
created in the new session. Suggested by Theo.


# 1.8 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.7 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.6 22-Jul-2009 nicm

window_add_pane cannot fail, so remove the unused cause argument and don't
bother to check for a NULL return.


# 1.5 19-Jul-2009 nicm

Improved layout code.

Each window now has a tree of layout cells associated with it. In this tree,
each node is either a horizontal or vertical cell containing a list of other
cells running from left-to-right or top-to-bottom, or a leaf cell which is
associated with a pane.

The major functional changes are:

- panes may now be split arbitrarily both horizontally (splitw -h, C-b %) and
vertically (splitw -v, C-b ");
- panes may be resized both horizontally and vertically (resizep -L/-R/-U/-D,
bound to C-b left/right/up/down and C-b M-left/right/up/down);
- layouts are now applied and then may be modified by resizing or splitting
panes, rather than being fixed and reapplied when the window is resized or
panes are added;
- manual-vertical layout is no longer necessary, and active-only layout is gone
(but may return in future);
- the main-pane layouts now reduce the size of the main pane to fit all panes
if possible.

Thanks to all who tested.


# 1.4 13-Jul-2009 nicm

Having fixed flags for single-character getopt options is a bit hard to
maintain and is only going to get worse as more are used. So instead, add a new
uint64_t member to cmd_entry which is a bitmask of upper and lowercase options
accepted by the command.

This means new single character options can be used without the need to add it
explicitly to the list.


# 1.3 07-Jul-2009 nicm

The fix for default-path (use target session options instead of global options)
is required here as well, doh.


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

lines variable can be -1 (to be ignored), so should be signed. Found by lint.


# 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.94 28-Apr-2019 nicm

Support multiple occurances of the same argument. Use this for a new
flag -e to new-window, split-window, respawn-window, respawn-pane to
pass environment variables into the newly created process. From Steffen
Christgau in GitHub issue 1697.


# 1.93 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).


# 1.92 17-Apr-2019 nicm

Break new window and pane creation common code from various commands and
window.c into a separate file spawn.c.


Revision tags: OPENBSD_6_5_BASE
# 1.91 18-Oct-2018 nicm

Support for windows larger than visible on the attached client. This has
been a limitation for a long time.

There are two new options, window-size and default-size, and a new
command, resize-window. The force-width and force-height options and the
session_width and session_height formats have been removed.

The new window-size option tells tmux how to work out the size of
windows: largest means it picks the size of the largest session,
smallest the smallest session (similar to the old behaviour) and manual
means that it does not automatically resize windows. The default is
currently largest but this may change. aggressive-resize modifies the
choice of session for largest and smallest as it did before.

If a window is in a session attached to a client that is too small, only
part of the window is shown. tmux attempts to keep the cursor visible,
so the part of the window displayed is changed as the cursor moves (with
a small delay, to try and avoid excess redrawing when applications
redraw status lines or similar that are not currently visible). The
offset of the visible portion of the window is shown in status-right.

Drawing windows which are larger than the client is not as efficient as
those which fit, particularly when the cursor moves, so it is
recommended to avoid using this on slow machines or networks (set
window-size to smallest or manual).

The resize-window command can be used to resize a window manually. If it
is used, the window-size option is automatically set to manual for the
window (undo this with "setw -u window-size"). resize-window works in a
similar way to resize-pane (-U -D -L -R -x -y flags) but also has -a and
-A flags. -a sets the window to the size of the smallest client (what it
would be if window-size was smallest) and -A the largest.

For the same behaviour as force-width or force-height, use resize-window
-x or -y, and "setw -u window-size" to revert to automatic sizing..

If the global window-size option is set to manual, the default-size
option is used for new windows. If -x or -y is used with new-session,
that sets the default-size option for the new session.

The maximum size of a window is 10000x10000. But expect applications to
complain and much higher memory use if making a window excessively
big. The minimum size is the size required for the current layout
including borders.

The refresh-client command can be used to pan around a window, -U -D -L
-R moves up, down, left or right and -c returns to automatic cursor
tracking. The position is reset when the current window is changed.


Revision tags: OPENBSD_6_4_BASE
# 1.90 24-May-2018 nicm

Make server_client_get_cwd used (almost) everywhere we need to work out
the cwd, and do not fall back to "." as it is pretty useless. GitHub
issue 1331.


Revision tags: OPENBSD_6_3_BASE
# 1.89 16-Mar-2018 nicm

Insert full size panes at the right position, from KOIE Hidetaka in
GitHub issue 1284.


# 1.88 01-Mar-2018 nicm

Expand formats in window and session names.


Revision tags: OPENBSD_6_2_BASE
# 1.87 30-Aug-2017 nicm

Pass flags into cmd_find_from_* to fix prefer-unattached, reported by
Thomas Sattler.


# 1.86 21-Jul-2017 nicm

Add -c for respawn-pane and respawn-window, from J Raynor.


# 1.85 30-May-2017 nicm

Rewrite of choose mode, both to simplify and tidy the code and to add
some modern features.

Now the common code is in mode-tree.c, which provides an API used by the
three modes now separated into window-{buffer,client,tree}.c. Buffer
mode shows buffers, client mode clients and tree mode a tree of
sessions, windows and panes.

Each mode has a common set of key bindings plus a few that are specific
to the mode. Other changes are:

- each mode has a preview pane: for buffers this is the buffer content
(very useful), for others it is a preview of the pane;

- items may be sorted in different ways ('O' key);

- multiple items may be tagged and an operation applied to all of them
(for example, to delete multiple buffers at once);

- in tree mode a command may be run on the selected item (session,
window, pane) or on tagged items (key ':');

- displayed items may be filtered in tree mode by using a format (this
is used to implement find-window) (key 'f');

- the custom format (-F) for the display is no longer available;

- shortcut keys change from 0-9, a-z, A-Z which was always a bit weird
with keys used for other uses to 0-9, M-a to M-z.

Now that the code is simpler, other improvements will come later.

Primary key bindings for each mode are documented under the commands in
the man page (choose-buffer, choose-client, choose-tree).

Parts written by Thomas Adam.


# 1.84 25-Apr-2017 nicm

Do not update TERM into config file parsing has finished.


# 1.83 22-Apr-2017 nicm

Get rid of the extra layer of flags and cmd_prepare() and just store the
CMD_FIND_* flags in the cmd_entry and call it for the command. Commands
with special requirements call it themselves and update the target for
hooks to use.


# 1.82 22-Apr-2017 nicm

Mouse bindings and hooks set up an initial current state when running a
command. This is used for the session, window and pane for all commands
in the command sequence if there is no -t or -s.

However, using it for all commands in the command sequence means that if
the active pane or current session is changed, subsequent commands still
use the previous state. So make commands which explicitly change the
current state (such as neww and selectp) update it themselves for later
commands. Commands which may invalidate the state (like killp) are
already OK because an invalid state will be ignored.

Also fill in the current state for all key bindings rather than just the
mouse, so that any omissions are easier to spot.


# 1.81 21-Apr-2017 nicm

Add cmd_find_from_winlink_pane and use it in a couple of places, and
make functions that can't fail void.


Revision tags: OPENBSD_6_1_BASE
# 1.80 09-Mar-2017 nicm

Move server_fill_environ into environ.c and move some other common code
into it.


# 1.79 08-Mar-2017 nicm

Add a helper function for the most common format_create/defaults/expand
pattern.


# 1.78 27-Feb-2017 nicm

If splitw -b is used, insert the new pane before the current one in the
pane list. This means the numbering is in order (for example for
display-panes) and fixes a problem with redrawing the active pane
borders.


# 1.77 03-Feb-2017 nicm

Add a window or pane id "tag" to each format tree and use it to separate
jobs, this means that if the same job is used for different windows or
panes (for example in pane-border-format), it will be run separately for
each pane.


# 1.76 16-Oct-2016 nicm

Use the notify name string instead of going via an enum and change
existing hooks to use notifys instead.


# 1.75 16-Oct-2016 nicm

Mass rename struct cmd_q to struct cmdq_item and related.


# 1.74 16-Oct-2016 nicm

Rewrite command queue handling. Each client still has a command queue,
but there is also now a global command queue. Instead of command queues
being dispatched on demand from wherever the command happens to be
added, they are now all dispatched from the top level server
loop. Command queues may now also include callbacks as well as commands,
and items may be inserted after the current command as well as at the end.

This all makes command queues significantly more predictable and easier
to use, and avoids the complex multiple nested command queues used by
source-file, if-shell and friends.

A mass rename of struct cmdq to a better name (cmdq_item probably) is
coming.


# 1.73 13-Oct-2016 nicm

Trying to do hooks generically is way too complicated and unreliable and
confusing, particularly trying to automatically figure out what target
hooks should be using. So simplify it:

- drop before hooks entirely, they don't seem to be very useful;

- commands with special requirements now fire their own after hook (for
example, if they change session or window, or if they have -t and -s
and need to choose which one the hook uses as current target);

- commands with no special requirements can have the CMD_AFTERHOOK flag
added and they will use the -t state.

At the moment new-session, new-window, split-window fire their own hook,
and display-message uses the flag. The remaining commands still need to
be looked at.


# 1.72 13-Oct-2016 nicm

Some improvements and bug fixes for hooks:

- Prepare the state again before the "after" hooks are run, because the
command may have killed or moved windows.

- Use the hooks list from the newly prepared target, not the old hooks
list (only matters for new-session really).

- Correctly detect an invalid current state and ignore it in
cmd_find_target ("killw; swapw").

- Change neww, new, killp, killw, splitw, swapp, swapw to update the
current state (used if no explicit target is given) to something more
useful after they have finished. For example, neww changes it to the
newly created window.

Hooks are still relatively new and primitive so there are likely to be
more changes to come.

Parts based on bug reports from Uwe Werler and Iblis Lin.


# 1.71 10-Oct-2016 nicm

Add static in cmd-* and fix a few other nits.


# 1.70 04-Sep-2016 nicm

Add support for performing a full width split (with splitw -f), rather
than splitting the current cell. From Stephen Kent.


Revision tags: OPENBSD_6_0_BASE
# 1.69 06-Jun-2016 nicm

Insert new panes after the pane being split in the list rather than
always after the active pane. This is more sensible when doing it with
commands rather than keys.


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

I no longer use my SourceForge address so replace it.


# 1.67 14-Dec-2015 nicm

Instead of combined flags for -c, -s, -t, split into different sets
using an enum and simplify the parsing code.


# 1.66 13-Dec-2015 nicm

Use member names in cmd_entry definitions so I stop getting confused
about the order.


# 1.65 13-Dec-2015 nicm

Instead of every command resolving the target (-t or -s) itself, prepare
the state (client, session, winlink, pane) for it it before entering the
command. Each command provides some flags that tell the prepare step
what it is expecting.

This is a requirement for having hooks on commands (for example, if you
hook "select-window -t1:2", the hook command should to operate on window
1:2 not whatever it thinks is the current window), and should allow some
other target improvements.

The old cmd_find_* functions remain for the moment but that layer will
be dropped later.

Joint work with Thomas Adam.


# 1.64 11-Dec-2015 nicm

Add cmdq as an argument to format_create and add a format for the
command name (will also be used for more later).


# 1.63 08-Dec-2015 nicm

Remove format_create_flags and just pass flags to format_create.


# 1.62 31-Oct-2015 nicm

Fall back silently to ~ or / rather than checking -c with access(), this
was the old behaviour.


# 1.61 31-Oct-2015 nicm

Because pledge(2) does not allow us to pass directory file descriptors
around, we can't use file descriptors for the working directory because
we will be unable to pass it to a privileged process to tell it where to
read or write files or spawn children. So move tmux back to using
strings for the current working directory. We try to check it exists
with access() when it is set but ultimately fall back to ~ if it fails
at time of use (or / if that fails too).


# 1.60 28-Oct-2015 nicm

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


# 1.59 27-Oct-2015 nicm

Move struct options into options.c.


# 1.58 23-Oct-2015 nicm

Remove some unnecessary checks before free().


Revision tags: OPENBSD_5_8_BASE
# 1.57 26-Apr-2015 nicm

Remove panes from layout if spawning them fails, reported by Anthony J
Bentley.


Revision tags: OPENBSD_5_7_BASE
# 1.56 05-Feb-2015 nicm

Remove a couple of now-unused variables.


# 1.55 05-Feb-2015 nicm

Wrap all the individual format_* calls in a single format_defaults
functions.


# 1.54 12-Nov-2014 nicm

Add -b to splitw like joinw, from Felix Rosencrantz.


# 1.53 20-Oct-2014 nicm

Move template defines back into .c files.


# 1.52 20-Oct-2014 nicm

Instead of setting up the default keys by building the key struct
directly with a helper function in the cmd_entry, include a table of
bind-key commands and pass them through the command parser and a
temporary cmd_q.

As well as being smaller, this will allow default bindings to be command
sequences which will probably be needed soon.


# 1.51 01-Sep-2014 nicm

Various minor style and spacing nits.


Revision tags: OPENBSD_5_6_BASE
# 1.50 13-May-2014 nicm

If multiple arguments are given to new-session, new-window,
split-window, respawn-window or respawn-pane, pass them directly to
execvp() to help avoid quoting problems. One argument still goes to "sh
-c" like before. Requested by many over the years. Patch from J Raynor.


# 1.49 17-Apr-2014 nicm

Set PATH explicitly, either from client or session
environment. Previously it came from the session environment. From J
Raynor.


Revision tags: OPENBSD_5_5_BASE
# 1.48 22-Nov-2013 nicm

Handle empty current directory more gracefully.


# 1.47 10-Oct-2013 nicm

Don't boke when figuring out working directory from configuration file.


# 1.46 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.45 10-Oct-2013 nicm

Support -c for new-session, based on code from J Raynor.


# 1.44 10-Oct-2013 nicm

Restore missing key binding for %, from Chris Johnsen.


# 1.43 10-Oct-2013 nicm

Remove the barely-used and unnecessary command check() function.


Revision tags: OPENBSD_5_4_BASE
# 1.42 25-Mar-2013 nicm

Revert the command-prefix change which breaks sequences of commands.


# 1.41 24-Mar-2013 nicm

Add resize-pane -Z to temporary zoom the active pane to occupy the full
window or unzoom (restored to the normal layout) if it already zoomed,
bound to C-b z by default. The pane is unzoomed on pretty much any
excuse whatsoever.

We considered making this a new layout but the requirements are quite
different from layouts so decided it is better as a special case. Each
current layout cell is saved, a temporary one-cell layout generated and
all except the active pane set to NULL.

Prompted by suggestions and scripts from several. Thanks to Aaron Jensen
and Thiago Padilha for testing an earlier version.


# 1.40 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.


# 1.39 24-Mar-2013 nicm

Fix error reporting for client commands by adding a flag to
cmd_find_client to tell it whether or not to show errors, sometimes it's
needed and sometimes not.


# 1.38 24-Mar-2013 nicm

Add option command-prefix which is automatically prepended to any
command (apart from a naked default-shell). The default is "exec ".


Revision tags: OPENBSD_5_3_BASE
# 1.37 09-Dec-2012 nicm

Use the CMD_*_USAGE defines consistently, from Thomas Adam.


# 1.36 14-Aug-2012 nicm

Use a separate define for each default format template and strip clutter
from the choose-tree defaults.


Revision tags: OPENBSD_5_2_BASE
# 1.35 11-Jul-2012 nicm

Make command exec functions return an enum rather than -1/0/1 values and
add a new value to mean "leave client running but don't attach" to fix
problems with using some commands in a command sequence. Most of the
work by Thomas Adam, problem reported by "jspenguin" on SF bug 3535531.


# 1.34 10-Jul-2012 nicm

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


# 1.33 22-May-2012 nicm

Switch all of the various choose- and list- commands over to the format
infrastructure, from Thomas Adam.


# 1.32 17-Mar-2012 nicm

Add notify hooks for various events, the functions are currently empty
stubs but will be filled in for control mode later. From George Nachman.


# 1.31 04-Mar-2012 nicm

free -> xfree.


# 1.30 04-Mar-2012 nicm

Add -F format to new-window and split-window to use with the -P flag,
from George Nachman.


# 1.29 03-Mar-2012 nicm

Add move-pane command (like join-pane but allows the same window). Also
-b flag to join-pane and move-pane to place the pane to the left or
above. From George Nachman.


Revision tags: OPENBSD_5_1_BASE
# 1.28 31-Jan-2012 nicm

Provide defined ways to set the various default-path possibilities: ~
for home directory, . for server start directory, - for session start
directory and empty for the pane's working directory (the default). All
can also be used as part of a relative path (eg -/foo). Also provide -c
flags to neww and splitw to override default-path setting.

Based on a diff from sthen. ok sthen


# 1.27 20-Jan-2012 nicm

Add some const and fix a warning.


# 1.26 09-Dec-2011 nicm

Change the way the working directory for new processes is discovered. If
default-path isn't empty, it is used. Otherwise:

1) If tmux neww is run from the command line, the working directory of the
client is used.

2) Otherwise sysctl KERN_PROC_CWD is used to retrieve the current
working directory of the process in the active pane.

3) If that fails, the directory where the session was created is used.

Support code by Romain Francois, OpenBSD specific bits by me.

Note this requires a recent userland and kernel with KERN_PROC_CWD.


# 1.25 15-Nov-2011 nicm

Make window_pane_index work the same as window_index, from Ben Boeckel.


# 1.24 30-Aug-2011 nicm

Plug memory leak, from Tiago Cunha.


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE
# 1.23 10-Feb-2011 nicm

Size on split-window is -l not -s. Doh.


# 1.22 04-Jan-2011 nicm

Clean up and simplify tmux command argument parsing.

Originally, tmux commands were parsed in the client process into a
struct with the command data which was then serialised and sent to the
server to be executed. The parsing was later moved into the server (an
argv was sent from the client), but the parse step and intermediate
struct was kept.

This change removes that struct and the separate parse step. Argument
parsing and printing is now common to all commands (in arguments.c) with
each command left with just an optional check function (to validate the
arguments at parse time), the exec function and a function to set up any
key bindings (renamed from the old init function).

This is overall more simple and consistent.

There should be no changes to any commands behaviour or syntax although
as this touches every command please watch for any unexpected changes.


# 1.21 01-Jan-2011 nicm

Add a -P option to new-window and split-window to print the new window
or pane index in target form (useful to pass it into other commands).


Revision tags: OPENBSD_4_8_BASE
# 1.20 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.


Revision tags: OPENBSD_4_7_BASE
# 1.19 07-Jan-2010 nicm

New command, join-pane, to split and move an existing pane into the space (like
splitw then movep, or the reverse of breakp).


# 1.18 07-Jan-2010 nicm

Use the specified pane for size calculations. Doh.


# 1.17 07-Jan-2010 nicm

Change split-window to accept a pane target (it should be split-pane but
renaming the command would be annoying).


# 1.16 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.15 20-Nov-2009 nicm

When -h and -p are given to split-window, calculate the percentage size using
the width instead of the height.


# 1.14 13-Nov-2009 nicm

Get rid of the ugly CMD_CHFLAG macro and use a const string (eg "dDU") in the
command entry structs and a couple of functions to check/set the flags.


# 1.13 21-Sep-2009 nicm

Use KEYC_NONE constant instead of 0 on init.


# 1.12 16-Sep-2009 nicm

Rather than constructing an entire termios struct from ttydefaults.h, just let
forkpty do it and then alter the bits that should be changed after fork. A
little neater and more portable.


# 1.11 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.10 25-Aug-2009 nicm

Print -l and -p when showing command, pointed out by Tiago Cunha.


# 1.9 13-Aug-2009 nicm

When creating a new session from the command-line where there is an external
terminal, copy the termios(4) special characters and use them for new windows
created in the new session. Suggested by Theo.


# 1.8 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.7 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.6 22-Jul-2009 nicm

window_add_pane cannot fail, so remove the unused cause argument and don't
bother to check for a NULL return.


# 1.5 19-Jul-2009 nicm

Improved layout code.

Each window now has a tree of layout cells associated with it. In this tree,
each node is either a horizontal or vertical cell containing a list of other
cells running from left-to-right or top-to-bottom, or a leaf cell which is
associated with a pane.

The major functional changes are:

- panes may now be split arbitrarily both horizontally (splitw -h, C-b %) and
vertically (splitw -v, C-b ");
- panes may be resized both horizontally and vertically (resizep -L/-R/-U/-D,
bound to C-b left/right/up/down and C-b M-left/right/up/down);
- layouts are now applied and then may be modified by resizing or splitting
panes, rather than being fixed and reapplied when the window is resized or
panes are added;
- manual-vertical layout is no longer necessary, and active-only layout is gone
(but may return in future);
- the main-pane layouts now reduce the size of the main pane to fit all panes
if possible.

Thanks to all who tested.


# 1.4 13-Jul-2009 nicm

Having fixed flags for single-character getopt options is a bit hard to
maintain and is only going to get worse as more are used. So instead, add a new
uint64_t member to cmd_entry which is a bitmask of upper and lowercase options
accepted by the command.

This means new single character options can be used without the need to add it
explicitly to the list.


# 1.3 07-Jul-2009 nicm

The fix for default-path (use target session options instead of global options)
is required here as well, doh.


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

lines variable can be -1 (to be ignored), so should be signed. Found by lint.


# 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.91 18-Oct-2018 nicm

Support for windows larger than visible on the attached client. This has
been a limitation for a long time.

There are two new options, window-size and default-size, and a new
command, resize-window. The force-width and force-height options and the
session_width and session_height formats have been removed.

The new window-size option tells tmux how to work out the size of
windows: largest means it picks the size of the largest session,
smallest the smallest session (similar to the old behaviour) and manual
means that it does not automatically resize windows. The default is
currently largest but this may change. aggressive-resize modifies the
choice of session for largest and smallest as it did before.

If a window is in a session attached to a client that is too small, only
part of the window is shown. tmux attempts to keep the cursor visible,
so the part of the window displayed is changed as the cursor moves (with
a small delay, to try and avoid excess redrawing when applications
redraw status lines or similar that are not currently visible). The
offset of the visible portion of the window is shown in status-right.

Drawing windows which are larger than the client is not as efficient as
those which fit, particularly when the cursor moves, so it is
recommended to avoid using this on slow machines or networks (set
window-size to smallest or manual).

The resize-window command can be used to resize a window manually. If it
is used, the window-size option is automatically set to manual for the
window (undo this with "setw -u window-size"). resize-window works in a
similar way to resize-pane (-U -D -L -R -x -y flags) but also has -a and
-A flags. -a sets the window to the size of the smallest client (what it
would be if window-size was smallest) and -A the largest.

For the same behaviour as force-width or force-height, use resize-window
-x or -y, and "setw -u window-size" to revert to automatic sizing..

If the global window-size option is set to manual, the default-size
option is used for new windows. If -x or -y is used with new-session,
that sets the default-size option for the new session.

The maximum size of a window is 10000x10000. But expect applications to
complain and much higher memory use if making a window excessively
big. The minimum size is the size required for the current layout
including borders.

The refresh-client command can be used to pan around a window, -U -D -L
-R moves up, down, left or right and -c returns to automatic cursor
tracking. The position is reset when the current window is changed.


Revision tags: OPENBSD_6_4_BASE
# 1.90 24-May-2018 nicm

Make server_client_get_cwd used (almost) everywhere we need to work out
the cwd, and do not fall back to "." as it is pretty useless. GitHub
issue 1331.


Revision tags: OPENBSD_6_3_BASE
# 1.89 16-Mar-2018 nicm

Insert full size panes at the right position, from KOIE Hidetaka in
GitHub issue 1284.


# 1.88 01-Mar-2018 nicm

Expand formats in window and session names.


Revision tags: OPENBSD_6_2_BASE
# 1.87 30-Aug-2017 nicm

Pass flags into cmd_find_from_* to fix prefer-unattached, reported by
Thomas Sattler.


# 1.86 21-Jul-2017 nicm

Add -c for respawn-pane and respawn-window, from J Raynor.


# 1.85 30-May-2017 nicm

Rewrite of choose mode, both to simplify and tidy the code and to add
some modern features.

Now the common code is in mode-tree.c, which provides an API used by the
three modes now separated into window-{buffer,client,tree}.c. Buffer
mode shows buffers, client mode clients and tree mode a tree of
sessions, windows and panes.

Each mode has a common set of key bindings plus a few that are specific
to the mode. Other changes are:

- each mode has a preview pane: for buffers this is the buffer content
(very useful), for others it is a preview of the pane;

- items may be sorted in different ways ('O' key);

- multiple items may be tagged and an operation applied to all of them
(for example, to delete multiple buffers at once);

- in tree mode a command may be run on the selected item (session,
window, pane) or on tagged items (key ':');

- displayed items may be filtered in tree mode by using a format (this
is used to implement find-window) (key 'f');

- the custom format (-F) for the display is no longer available;

- shortcut keys change from 0-9, a-z, A-Z which was always a bit weird
with keys used for other uses to 0-9, M-a to M-z.

Now that the code is simpler, other improvements will come later.

Primary key bindings for each mode are documented under the commands in
the man page (choose-buffer, choose-client, choose-tree).

Parts written by Thomas Adam.


# 1.84 25-Apr-2017 nicm

Do not update TERM into config file parsing has finished.


# 1.83 22-Apr-2017 nicm

Get rid of the extra layer of flags and cmd_prepare() and just store the
CMD_FIND_* flags in the cmd_entry and call it for the command. Commands
with special requirements call it themselves and update the target for
hooks to use.


# 1.82 22-Apr-2017 nicm

Mouse bindings and hooks set up an initial current state when running a
command. This is used for the session, window and pane for all commands
in the command sequence if there is no -t or -s.

However, using it for all commands in the command sequence means that if
the active pane or current session is changed, subsequent commands still
use the previous state. So make commands which explicitly change the
current state (such as neww and selectp) update it themselves for later
commands. Commands which may invalidate the state (like killp) are
already OK because an invalid state will be ignored.

Also fill in the current state for all key bindings rather than just the
mouse, so that any omissions are easier to spot.


# 1.81 21-Apr-2017 nicm

Add cmd_find_from_winlink_pane and use it in a couple of places, and
make functions that can't fail void.


Revision tags: OPENBSD_6_1_BASE
# 1.80 09-Mar-2017 nicm

Move server_fill_environ into environ.c and move some other common code
into it.


# 1.79 08-Mar-2017 nicm

Add a helper function for the most common format_create/defaults/expand
pattern.


# 1.78 27-Feb-2017 nicm

If splitw -b is used, insert the new pane before the current one in the
pane list. This means the numbering is in order (for example for
display-panes) and fixes a problem with redrawing the active pane
borders.


# 1.77 03-Feb-2017 nicm

Add a window or pane id "tag" to each format tree and use it to separate
jobs, this means that if the same job is used for different windows or
panes (for example in pane-border-format), it will be run separately for
each pane.


# 1.76 16-Oct-2016 nicm

Use the notify name string instead of going via an enum and change
existing hooks to use notifys instead.


# 1.75 16-Oct-2016 nicm

Mass rename struct cmd_q to struct cmdq_item and related.


# 1.74 16-Oct-2016 nicm

Rewrite command queue handling. Each client still has a command queue,
but there is also now a global command queue. Instead of command queues
being dispatched on demand from wherever the command happens to be
added, they are now all dispatched from the top level server
loop. Command queues may now also include callbacks as well as commands,
and items may be inserted after the current command as well as at the end.

This all makes command queues significantly more predictable and easier
to use, and avoids the complex multiple nested command queues used by
source-file, if-shell and friends.

A mass rename of struct cmdq to a better name (cmdq_item probably) is
coming.


# 1.73 13-Oct-2016 nicm

Trying to do hooks generically is way too complicated and unreliable and
confusing, particularly trying to automatically figure out what target
hooks should be using. So simplify it:

- drop before hooks entirely, they don't seem to be very useful;

- commands with special requirements now fire their own after hook (for
example, if they change session or window, or if they have -t and -s
and need to choose which one the hook uses as current target);

- commands with no special requirements can have the CMD_AFTERHOOK flag
added and they will use the -t state.

At the moment new-session, new-window, split-window fire their own hook,
and display-message uses the flag. The remaining commands still need to
be looked at.


# 1.72 13-Oct-2016 nicm

Some improvements and bug fixes for hooks:

- Prepare the state again before the "after" hooks are run, because the
command may have killed or moved windows.

- Use the hooks list from the newly prepared target, not the old hooks
list (only matters for new-session really).

- Correctly detect an invalid current state and ignore it in
cmd_find_target ("killw; swapw").

- Change neww, new, killp, killw, splitw, swapp, swapw to update the
current state (used if no explicit target is given) to something more
useful after they have finished. For example, neww changes it to the
newly created window.

Hooks are still relatively new and primitive so there are likely to be
more changes to come.

Parts based on bug reports from Uwe Werler and Iblis Lin.


# 1.71 10-Oct-2016 nicm

Add static in cmd-* and fix a few other nits.


# 1.70 04-Sep-2016 nicm

Add support for performing a full width split (with splitw -f), rather
than splitting the current cell. From Stephen Kent.


Revision tags: OPENBSD_6_0_BASE
# 1.69 06-Jun-2016 nicm

Insert new panes after the pane being split in the list rather than
always after the active pane. This is more sensible when doing it with
commands rather than keys.


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

I no longer use my SourceForge address so replace it.


# 1.67 14-Dec-2015 nicm

Instead of combined flags for -c, -s, -t, split into different sets
using an enum and simplify the parsing code.


# 1.66 13-Dec-2015 nicm

Use member names in cmd_entry definitions so I stop getting confused
about the order.


# 1.65 13-Dec-2015 nicm

Instead of every command resolving the target (-t or -s) itself, prepare
the state (client, session, winlink, pane) for it it before entering the
command. Each command provides some flags that tell the prepare step
what it is expecting.

This is a requirement for having hooks on commands (for example, if you
hook "select-window -t1:2", the hook command should to operate on window
1:2 not whatever it thinks is the current window), and should allow some
other target improvements.

The old cmd_find_* functions remain for the moment but that layer will
be dropped later.

Joint work with Thomas Adam.


# 1.64 11-Dec-2015 nicm

Add cmdq as an argument to format_create and add a format for the
command name (will also be used for more later).


# 1.63 08-Dec-2015 nicm

Remove format_create_flags and just pass flags to format_create.


# 1.62 31-Oct-2015 nicm

Fall back silently to ~ or / rather than checking -c with access(), this
was the old behaviour.


# 1.61 31-Oct-2015 nicm

Because pledge(2) does not allow us to pass directory file descriptors
around, we can't use file descriptors for the working directory because
we will be unable to pass it to a privileged process to tell it where to
read or write files or spawn children. So move tmux back to using
strings for the current working directory. We try to check it exists
with access() when it is set but ultimately fall back to ~ if it fails
at time of use (or / if that fails too).


# 1.60 28-Oct-2015 nicm

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


# 1.59 27-Oct-2015 nicm

Move struct options into options.c.


# 1.58 23-Oct-2015 nicm

Remove some unnecessary checks before free().


Revision tags: OPENBSD_5_8_BASE
# 1.57 26-Apr-2015 nicm

Remove panes from layout if spawning them fails, reported by Anthony J
Bentley.


Revision tags: OPENBSD_5_7_BASE
# 1.56 05-Feb-2015 nicm

Remove a couple of now-unused variables.


# 1.55 05-Feb-2015 nicm

Wrap all the individual format_* calls in a single format_defaults
functions.


# 1.54 12-Nov-2014 nicm

Add -b to splitw like joinw, from Felix Rosencrantz.


# 1.53 20-Oct-2014 nicm

Move template defines back into .c files.


# 1.52 20-Oct-2014 nicm

Instead of setting up the default keys by building the key struct
directly with a helper function in the cmd_entry, include a table of
bind-key commands and pass them through the command parser and a
temporary cmd_q.

As well as being smaller, this will allow default bindings to be command
sequences which will probably be needed soon.


# 1.51 01-Sep-2014 nicm

Various minor style and spacing nits.


Revision tags: OPENBSD_5_6_BASE
# 1.50 13-May-2014 nicm

If multiple arguments are given to new-session, new-window,
split-window, respawn-window or respawn-pane, pass them directly to
execvp() to help avoid quoting problems. One argument still goes to "sh
-c" like before. Requested by many over the years. Patch from J Raynor.


# 1.49 17-Apr-2014 nicm

Set PATH explicitly, either from client or session
environment. Previously it came from the session environment. From J
Raynor.


Revision tags: OPENBSD_5_5_BASE
# 1.48 22-Nov-2013 nicm

Handle empty current directory more gracefully.


# 1.47 10-Oct-2013 nicm

Don't boke when figuring out working directory from configuration file.


# 1.46 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.45 10-Oct-2013 nicm

Support -c for new-session, based on code from J Raynor.


# 1.44 10-Oct-2013 nicm

Restore missing key binding for %, from Chris Johnsen.


# 1.43 10-Oct-2013 nicm

Remove the barely-used and unnecessary command check() function.


Revision tags: OPENBSD_5_4_BASE
# 1.42 25-Mar-2013 nicm

Revert the command-prefix change which breaks sequences of commands.


# 1.41 24-Mar-2013 nicm

Add resize-pane -Z to temporary zoom the active pane to occupy the full
window or unzoom (restored to the normal layout) if it already zoomed,
bound to C-b z by default. The pane is unzoomed on pretty much any
excuse whatsoever.

We considered making this a new layout but the requirements are quite
different from layouts so decided it is better as a special case. Each
current layout cell is saved, a temporary one-cell layout generated and
all except the active pane set to NULL.

Prompted by suggestions and scripts from several. Thanks to Aaron Jensen
and Thiago Padilha for testing an earlier version.


# 1.40 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.


# 1.39 24-Mar-2013 nicm

Fix error reporting for client commands by adding a flag to
cmd_find_client to tell it whether or not to show errors, sometimes it's
needed and sometimes not.


# 1.38 24-Mar-2013 nicm

Add option command-prefix which is automatically prepended to any
command (apart from a naked default-shell). The default is "exec ".


Revision tags: OPENBSD_5_3_BASE
# 1.37 09-Dec-2012 nicm

Use the CMD_*_USAGE defines consistently, from Thomas Adam.


# 1.36 14-Aug-2012 nicm

Use a separate define for each default format template and strip clutter
from the choose-tree defaults.


Revision tags: OPENBSD_5_2_BASE
# 1.35 11-Jul-2012 nicm

Make command exec functions return an enum rather than -1/0/1 values and
add a new value to mean "leave client running but don't attach" to fix
problems with using some commands in a command sequence. Most of the
work by Thomas Adam, problem reported by "jspenguin" on SF bug 3535531.


# 1.34 10-Jul-2012 nicm

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


# 1.33 22-May-2012 nicm

Switch all of the various choose- and list- commands over to the format
infrastructure, from Thomas Adam.


# 1.32 17-Mar-2012 nicm

Add notify hooks for various events, the functions are currently empty
stubs but will be filled in for control mode later. From George Nachman.


# 1.31 04-Mar-2012 nicm

free -> xfree.


# 1.30 04-Mar-2012 nicm

Add -F format to new-window and split-window to use with the -P flag,
from George Nachman.


# 1.29 03-Mar-2012 nicm

Add move-pane command (like join-pane but allows the same window). Also
-b flag to join-pane and move-pane to place the pane to the left or
above. From George Nachman.


Revision tags: OPENBSD_5_1_BASE
# 1.28 31-Jan-2012 nicm

Provide defined ways to set the various default-path possibilities: ~
for home directory, . for server start directory, - for session start
directory and empty for the pane's working directory (the default). All
can also be used as part of a relative path (eg -/foo). Also provide -c
flags to neww and splitw to override default-path setting.

Based on a diff from sthen. ok sthen


# 1.27 20-Jan-2012 nicm

Add some const and fix a warning.


# 1.26 09-Dec-2011 nicm

Change the way the working directory for new processes is discovered. If
default-path isn't empty, it is used. Otherwise:

1) If tmux neww is run from the command line, the working directory of the
client is used.

2) Otherwise sysctl KERN_PROC_CWD is used to retrieve the current
working directory of the process in the active pane.

3) If that fails, the directory where the session was created is used.

Support code by Romain Francois, OpenBSD specific bits by me.

Note this requires a recent userland and kernel with KERN_PROC_CWD.


# 1.25 15-Nov-2011 nicm

Make window_pane_index work the same as window_index, from Ben Boeckel.


# 1.24 30-Aug-2011 nicm

Plug memory leak, from Tiago Cunha.


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE
# 1.23 10-Feb-2011 nicm

Size on split-window is -l not -s. Doh.


# 1.22 04-Jan-2011 nicm

Clean up and simplify tmux command argument parsing.

Originally, tmux commands were parsed in the client process into a
struct with the command data which was then serialised and sent to the
server to be executed. The parsing was later moved into the server (an
argv was sent from the client), but the parse step and intermediate
struct was kept.

This change removes that struct and the separate parse step. Argument
parsing and printing is now common to all commands (in arguments.c) with
each command left with just an optional check function (to validate the
arguments at parse time), the exec function and a function to set up any
key bindings (renamed from the old init function).

This is overall more simple and consistent.

There should be no changes to any commands behaviour or syntax although
as this touches every command please watch for any unexpected changes.


# 1.21 01-Jan-2011 nicm

Add a -P option to new-window and split-window to print the new window
or pane index in target form (useful to pass it into other commands).


Revision tags: OPENBSD_4_8_BASE
# 1.20 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.


Revision tags: OPENBSD_4_7_BASE
# 1.19 07-Jan-2010 nicm

New command, join-pane, to split and move an existing pane into the space (like
splitw then movep, or the reverse of breakp).


# 1.18 07-Jan-2010 nicm

Use the specified pane for size calculations. Doh.


# 1.17 07-Jan-2010 nicm

Change split-window to accept a pane target (it should be split-pane but
renaming the command would be annoying).


# 1.16 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.15 20-Nov-2009 nicm

When -h and -p are given to split-window, calculate the percentage size using
the width instead of the height.


# 1.14 13-Nov-2009 nicm

Get rid of the ugly CMD_CHFLAG macro and use a const string (eg "dDU") in the
command entry structs and a couple of functions to check/set the flags.


# 1.13 21-Sep-2009 nicm

Use KEYC_NONE constant instead of 0 on init.


# 1.12 16-Sep-2009 nicm

Rather than constructing an entire termios struct from ttydefaults.h, just let
forkpty do it and then alter the bits that should be changed after fork. A
little neater and more portable.


# 1.11 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.10 25-Aug-2009 nicm

Print -l and -p when showing command, pointed out by Tiago Cunha.


# 1.9 13-Aug-2009 nicm

When creating a new session from the command-line where there is an external
terminal, copy the termios(4) special characters and use them for new windows
created in the new session. Suggested by Theo.


# 1.8 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.7 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.6 22-Jul-2009 nicm

window_add_pane cannot fail, so remove the unused cause argument and don't
bother to check for a NULL return.


# 1.5 19-Jul-2009 nicm

Improved layout code.

Each window now has a tree of layout cells associated with it. In this tree,
each node is either a horizontal or vertical cell containing a list of other
cells running from left-to-right or top-to-bottom, or a leaf cell which is
associated with a pane.

The major functional changes are:

- panes may now be split arbitrarily both horizontally (splitw -h, C-b %) and
vertically (splitw -v, C-b ");
- panes may be resized both horizontally and vertically (resizep -L/-R/-U/-D,
bound to C-b left/right/up/down and C-b M-left/right/up/down);
- layouts are now applied and then may be modified by resizing or splitting
panes, rather than being fixed and reapplied when the window is resized or
panes are added;
- manual-vertical layout is no longer necessary, and active-only layout is gone
(but may return in future);
- the main-pane layouts now reduce the size of the main pane to fit all panes
if possible.

Thanks to all who tested.


# 1.4 13-Jul-2009 nicm

Having fixed flags for single-character getopt options is a bit hard to
maintain and is only going to get worse as more are used. So instead, add a new
uint64_t member to cmd_entry which is a bitmask of upper and lowercase options
accepted by the command.

This means new single character options can be used without the need to add it
explicitly to the list.


# 1.3 07-Jul-2009 nicm

The fix for default-path (use target session options instead of global options)
is required here as well, doh.


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

lines variable can be -1 (to be ignored), so should be signed. Found by lint.


# 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.90 24-May-2018 nicm

Make server_client_get_cwd used (almost) everywhere we need to work out
the cwd, and do not fall back to "." as it is pretty useless. GitHub
issue 1331.


Revision tags: OPENBSD_6_3_BASE
# 1.89 16-Mar-2018 nicm

Insert full size panes at the right position, from KOIE Hidetaka in
GitHub issue 1284.


# 1.88 01-Mar-2018 nicm

Expand formats in window and session names.


Revision tags: OPENBSD_6_2_BASE
# 1.87 30-Aug-2017 nicm

Pass flags into cmd_find_from_* to fix prefer-unattached, reported by
Thomas Sattler.


# 1.86 21-Jul-2017 nicm

Add -c for respawn-pane and respawn-window, from J Raynor.


# 1.85 30-May-2017 nicm

Rewrite of choose mode, both to simplify and tidy the code and to add
some modern features.

Now the common code is in mode-tree.c, which provides an API used by the
three modes now separated into window-{buffer,client,tree}.c. Buffer
mode shows buffers, client mode clients and tree mode a tree of
sessions, windows and panes.

Each mode has a common set of key bindings plus a few that are specific
to the mode. Other changes are:

- each mode has a preview pane: for buffers this is the buffer content
(very useful), for others it is a preview of the pane;

- items may be sorted in different ways ('O' key);

- multiple items may be tagged and an operation applied to all of them
(for example, to delete multiple buffers at once);

- in tree mode a command may be run on the selected item (session,
window, pane) or on tagged items (key ':');

- displayed items may be filtered in tree mode by using a format (this
is used to implement find-window) (key 'f');

- the custom format (-F) for the display is no longer available;

- shortcut keys change from 0-9, a-z, A-Z which was always a bit weird
with keys used for other uses to 0-9, M-a to M-z.

Now that the code is simpler, other improvements will come later.

Primary key bindings for each mode are documented under the commands in
the man page (choose-buffer, choose-client, choose-tree).

Parts written by Thomas Adam.


# 1.84 25-Apr-2017 nicm

Do not update TERM into config file parsing has finished.


# 1.83 22-Apr-2017 nicm

Get rid of the extra layer of flags and cmd_prepare() and just store the
CMD_FIND_* flags in the cmd_entry and call it for the command. Commands
with special requirements call it themselves and update the target for
hooks to use.


# 1.82 22-Apr-2017 nicm

Mouse bindings and hooks set up an initial current state when running a
command. This is used for the session, window and pane for all commands
in the command sequence if there is no -t or -s.

However, using it for all commands in the command sequence means that if
the active pane or current session is changed, subsequent commands still
use the previous state. So make commands which explicitly change the
current state (such as neww and selectp) update it themselves for later
commands. Commands which may invalidate the state (like killp) are
already OK because an invalid state will be ignored.

Also fill in the current state for all key bindings rather than just the
mouse, so that any omissions are easier to spot.


# 1.81 21-Apr-2017 nicm

Add cmd_find_from_winlink_pane and use it in a couple of places, and
make functions that can't fail void.


Revision tags: OPENBSD_6_1_BASE
# 1.80 09-Mar-2017 nicm

Move server_fill_environ into environ.c and move some other common code
into it.


# 1.79 08-Mar-2017 nicm

Add a helper function for the most common format_create/defaults/expand
pattern.


# 1.78 27-Feb-2017 nicm

If splitw -b is used, insert the new pane before the current one in the
pane list. This means the numbering is in order (for example for
display-panes) and fixes a problem with redrawing the active pane
borders.


# 1.77 03-Feb-2017 nicm

Add a window or pane id "tag" to each format tree and use it to separate
jobs, this means that if the same job is used for different windows or
panes (for example in pane-border-format), it will be run separately for
each pane.


# 1.76 16-Oct-2016 nicm

Use the notify name string instead of going via an enum and change
existing hooks to use notifys instead.


# 1.75 16-Oct-2016 nicm

Mass rename struct cmd_q to struct cmdq_item and related.


# 1.74 16-Oct-2016 nicm

Rewrite command queue handling. Each client still has a command queue,
but there is also now a global command queue. Instead of command queues
being dispatched on demand from wherever the command happens to be
added, they are now all dispatched from the top level server
loop. Command queues may now also include callbacks as well as commands,
and items may be inserted after the current command as well as at the end.

This all makes command queues significantly more predictable and easier
to use, and avoids the complex multiple nested command queues used by
source-file, if-shell and friends.

A mass rename of struct cmdq to a better name (cmdq_item probably) is
coming.


# 1.73 13-Oct-2016 nicm

Trying to do hooks generically is way too complicated and unreliable and
confusing, particularly trying to automatically figure out what target
hooks should be using. So simplify it:

- drop before hooks entirely, they don't seem to be very useful;

- commands with special requirements now fire their own after hook (for
example, if they change session or window, or if they have -t and -s
and need to choose which one the hook uses as current target);

- commands with no special requirements can have the CMD_AFTERHOOK flag
added and they will use the -t state.

At the moment new-session, new-window, split-window fire their own hook,
and display-message uses the flag. The remaining commands still need to
be looked at.


# 1.72 13-Oct-2016 nicm

Some improvements and bug fixes for hooks:

- Prepare the state again before the "after" hooks are run, because the
command may have killed or moved windows.

- Use the hooks list from the newly prepared target, not the old hooks
list (only matters for new-session really).

- Correctly detect an invalid current state and ignore it in
cmd_find_target ("killw; swapw").

- Change neww, new, killp, killw, splitw, swapp, swapw to update the
current state (used if no explicit target is given) to something more
useful after they have finished. For example, neww changes it to the
newly created window.

Hooks are still relatively new and primitive so there are likely to be
more changes to come.

Parts based on bug reports from Uwe Werler and Iblis Lin.


# 1.71 10-Oct-2016 nicm

Add static in cmd-* and fix a few other nits.


# 1.70 04-Sep-2016 nicm

Add support for performing a full width split (with splitw -f), rather
than splitting the current cell. From Stephen Kent.


Revision tags: OPENBSD_6_0_BASE
# 1.69 06-Jun-2016 nicm

Insert new panes after the pane being split in the list rather than
always after the active pane. This is more sensible when doing it with
commands rather than keys.


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

I no longer use my SourceForge address so replace it.


# 1.67 14-Dec-2015 nicm

Instead of combined flags for -c, -s, -t, split into different sets
using an enum and simplify the parsing code.


# 1.66 13-Dec-2015 nicm

Use member names in cmd_entry definitions so I stop getting confused
about the order.


# 1.65 13-Dec-2015 nicm

Instead of every command resolving the target (-t or -s) itself, prepare
the state (client, session, winlink, pane) for it it before entering the
command. Each command provides some flags that tell the prepare step
what it is expecting.

This is a requirement for having hooks on commands (for example, if you
hook "select-window -t1:2", the hook command should to operate on window
1:2 not whatever it thinks is the current window), and should allow some
other target improvements.

The old cmd_find_* functions remain for the moment but that layer will
be dropped later.

Joint work with Thomas Adam.


# 1.64 11-Dec-2015 nicm

Add cmdq as an argument to format_create and add a format for the
command name (will also be used for more later).


# 1.63 08-Dec-2015 nicm

Remove format_create_flags and just pass flags to format_create.


# 1.62 31-Oct-2015 nicm

Fall back silently to ~ or / rather than checking -c with access(), this
was the old behaviour.


# 1.61 31-Oct-2015 nicm

Because pledge(2) does not allow us to pass directory file descriptors
around, we can't use file descriptors for the working directory because
we will be unable to pass it to a privileged process to tell it where to
read or write files or spawn children. So move tmux back to using
strings for the current working directory. We try to check it exists
with access() when it is set but ultimately fall back to ~ if it fails
at time of use (or / if that fails too).


# 1.60 28-Oct-2015 nicm

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


# 1.59 27-Oct-2015 nicm

Move struct options into options.c.


# 1.58 23-Oct-2015 nicm

Remove some unnecessary checks before free().


Revision tags: OPENBSD_5_8_BASE
# 1.57 26-Apr-2015 nicm

Remove panes from layout if spawning them fails, reported by Anthony J
Bentley.


Revision tags: OPENBSD_5_7_BASE
# 1.56 05-Feb-2015 nicm

Remove a couple of now-unused variables.


# 1.55 05-Feb-2015 nicm

Wrap all the individual format_* calls in a single format_defaults
functions.


# 1.54 12-Nov-2014 nicm

Add -b to splitw like joinw, from Felix Rosencrantz.


# 1.53 20-Oct-2014 nicm

Move template defines back into .c files.


# 1.52 20-Oct-2014 nicm

Instead of setting up the default keys by building the key struct
directly with a helper function in the cmd_entry, include a table of
bind-key commands and pass them through the command parser and a
temporary cmd_q.

As well as being smaller, this will allow default bindings to be command
sequences which will probably be needed soon.


# 1.51 01-Sep-2014 nicm

Various minor style and spacing nits.


Revision tags: OPENBSD_5_6_BASE
# 1.50 13-May-2014 nicm

If multiple arguments are given to new-session, new-window,
split-window, respawn-window or respawn-pane, pass them directly to
execvp() to help avoid quoting problems. One argument still goes to "sh
-c" like before. Requested by many over the years. Patch from J Raynor.


# 1.49 17-Apr-2014 nicm

Set PATH explicitly, either from client or session
environment. Previously it came from the session environment. From J
Raynor.


Revision tags: OPENBSD_5_5_BASE
# 1.48 22-Nov-2013 nicm

Handle empty current directory more gracefully.


# 1.47 10-Oct-2013 nicm

Don't boke when figuring out working directory from configuration file.


# 1.46 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.45 10-Oct-2013 nicm

Support -c for new-session, based on code from J Raynor.


# 1.44 10-Oct-2013 nicm

Restore missing key binding for %, from Chris Johnsen.


# 1.43 10-Oct-2013 nicm

Remove the barely-used and unnecessary command check() function.


Revision tags: OPENBSD_5_4_BASE
# 1.42 25-Mar-2013 nicm

Revert the command-prefix change which breaks sequences of commands.


# 1.41 24-Mar-2013 nicm

Add resize-pane -Z to temporary zoom the active pane to occupy the full
window or unzoom (restored to the normal layout) if it already zoomed,
bound to C-b z by default. The pane is unzoomed on pretty much any
excuse whatsoever.

We considered making this a new layout but the requirements are quite
different from layouts so decided it is better as a special case. Each
current layout cell is saved, a temporary one-cell layout generated and
all except the active pane set to NULL.

Prompted by suggestions and scripts from several. Thanks to Aaron Jensen
and Thiago Padilha for testing an earlier version.


# 1.40 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.


# 1.39 24-Mar-2013 nicm

Fix error reporting for client commands by adding a flag to
cmd_find_client to tell it whether or not to show errors, sometimes it's
needed and sometimes not.


# 1.38 24-Mar-2013 nicm

Add option command-prefix which is automatically prepended to any
command (apart from a naked default-shell). The default is "exec ".


Revision tags: OPENBSD_5_3_BASE
# 1.37 09-Dec-2012 nicm

Use the CMD_*_USAGE defines consistently, from Thomas Adam.


# 1.36 14-Aug-2012 nicm

Use a separate define for each default format template and strip clutter
from the choose-tree defaults.


Revision tags: OPENBSD_5_2_BASE
# 1.35 11-Jul-2012 nicm

Make command exec functions return an enum rather than -1/0/1 values and
add a new value to mean "leave client running but don't attach" to fix
problems with using some commands in a command sequence. Most of the
work by Thomas Adam, problem reported by "jspenguin" on SF bug 3535531.


# 1.34 10-Jul-2012 nicm

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


# 1.33 22-May-2012 nicm

Switch all of the various choose- and list- commands over to the format
infrastructure, from Thomas Adam.


# 1.32 17-Mar-2012 nicm

Add notify hooks for various events, the functions are currently empty
stubs but will be filled in for control mode later. From George Nachman.


# 1.31 04-Mar-2012 nicm

free -> xfree.


# 1.30 04-Mar-2012 nicm

Add -F format to new-window and split-window to use with the -P flag,
from George Nachman.


# 1.29 03-Mar-2012 nicm

Add move-pane command (like join-pane but allows the same window). Also
-b flag to join-pane and move-pane to place the pane to the left or
above. From George Nachman.


Revision tags: OPENBSD_5_1_BASE
# 1.28 31-Jan-2012 nicm

Provide defined ways to set the various default-path possibilities: ~
for home directory, . for server start directory, - for session start
directory and empty for the pane's working directory (the default). All
can also be used as part of a relative path (eg -/foo). Also provide -c
flags to neww and splitw to override default-path setting.

Based on a diff from sthen. ok sthen


# 1.27 20-Jan-2012 nicm

Add some const and fix a warning.


# 1.26 09-Dec-2011 nicm

Change the way the working directory for new processes is discovered. If
default-path isn't empty, it is used. Otherwise:

1) If tmux neww is run from the command line, the working directory of the
client is used.

2) Otherwise sysctl KERN_PROC_CWD is used to retrieve the current
working directory of the process in the active pane.

3) If that fails, the directory where the session was created is used.

Support code by Romain Francois, OpenBSD specific bits by me.

Note this requires a recent userland and kernel with KERN_PROC_CWD.


# 1.25 15-Nov-2011 nicm

Make window_pane_index work the same as window_index, from Ben Boeckel.


# 1.24 30-Aug-2011 nicm

Plug memory leak, from Tiago Cunha.


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE
# 1.23 10-Feb-2011 nicm

Size on split-window is -l not -s. Doh.


# 1.22 04-Jan-2011 nicm

Clean up and simplify tmux command argument parsing.

Originally, tmux commands were parsed in the client process into a
struct with the command data which was then serialised and sent to the
server to be executed. The parsing was later moved into the server (an
argv was sent from the client), but the parse step and intermediate
struct was kept.

This change removes that struct and the separate parse step. Argument
parsing and printing is now common to all commands (in arguments.c) with
each command left with just an optional check function (to validate the
arguments at parse time), the exec function and a function to set up any
key bindings (renamed from the old init function).

This is overall more simple and consistent.

There should be no changes to any commands behaviour or syntax although
as this touches every command please watch for any unexpected changes.


# 1.21 01-Jan-2011 nicm

Add a -P option to new-window and split-window to print the new window
or pane index in target form (useful to pass it into other commands).


Revision tags: OPENBSD_4_8_BASE
# 1.20 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.


Revision tags: OPENBSD_4_7_BASE
# 1.19 07-Jan-2010 nicm

New command, join-pane, to split and move an existing pane into the space (like
splitw then movep, or the reverse of breakp).


# 1.18 07-Jan-2010 nicm

Use the specified pane for size calculations. Doh.


# 1.17 07-Jan-2010 nicm

Change split-window to accept a pane target (it should be split-pane but
renaming the command would be annoying).


# 1.16 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.15 20-Nov-2009 nicm

When -h and -p are given to split-window, calculate the percentage size using
the width instead of the height.


# 1.14 13-Nov-2009 nicm

Get rid of the ugly CMD_CHFLAG macro and use a const string (eg "dDU") in the
command entry structs and a couple of functions to check/set the flags.


# 1.13 21-Sep-2009 nicm

Use KEYC_NONE constant instead of 0 on init.


# 1.12 16-Sep-2009 nicm

Rather than constructing an entire termios struct from ttydefaults.h, just let
forkpty do it and then alter the bits that should be changed after fork. A
little neater and more portable.


# 1.11 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.10 25-Aug-2009 nicm

Print -l and -p when showing command, pointed out by Tiago Cunha.


# 1.9 13-Aug-2009 nicm

When creating a new session from the command-line where there is an external
terminal, copy the termios(4) special characters and use them for new windows
created in the new session. Suggested by Theo.


# 1.8 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.7 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.6 22-Jul-2009 nicm

window_add_pane cannot fail, so remove the unused cause argument and don't
bother to check for a NULL return.


# 1.5 19-Jul-2009 nicm

Improved layout code.

Each window now has a tree of layout cells associated with it. In this tree,
each node is either a horizontal or vertical cell containing a list of other
cells running from left-to-right or top-to-bottom, or a leaf cell which is
associated with a pane.

The major functional changes are:

- panes may now be split arbitrarily both horizontally (splitw -h, C-b %) and
vertically (splitw -v, C-b ");
- panes may be resized both horizontally and vertically (resizep -L/-R/-U/-D,
bound to C-b left/right/up/down and C-b M-left/right/up/down);
- layouts are now applied and then may be modified by resizing or splitting
panes, rather than being fixed and reapplied when the window is resized or
panes are added;
- manual-vertical layout is no longer necessary, and active-only layout is gone
(but may return in future);
- the main-pane layouts now reduce the size of the main pane to fit all panes
if possible.

Thanks to all who tested.


# 1.4 13-Jul-2009 nicm

Having fixed flags for single-character getopt options is a bit hard to
maintain and is only going to get worse as more are used. So instead, add a new
uint64_t member to cmd_entry which is a bitmask of upper and lowercase options
accepted by the command.

This means new single character options can be used without the need to add it
explicitly to the list.


# 1.3 07-Jul-2009 nicm

The fix for default-path (use target session options instead of global options)
is required here as well, doh.


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

lines variable can be -1 (to be ignored), so should be signed. Found by lint.


# 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


Revision tags: OPENBSD_6_3_BASE
# 1.89 16-Mar-2018 nicm

Insert full size panes at the right position, from KOIE Hidetaka in
GitHub issue 1284.


# 1.88 01-Mar-2018 nicm

Expand formats in window and session names.


Revision tags: OPENBSD_6_2_BASE
# 1.87 30-Aug-2017 nicm

Pass flags into cmd_find_from_* to fix prefer-unattached, reported by
Thomas Sattler.


# 1.86 21-Jul-2017 nicm

Add -c for respawn-pane and respawn-window, from J Raynor.


# 1.85 30-May-2017 nicm

Rewrite of choose mode, both to simplify and tidy the code and to add
some modern features.

Now the common code is in mode-tree.c, which provides an API used by the
three modes now separated into window-{buffer,client,tree}.c. Buffer
mode shows buffers, client mode clients and tree mode a tree of
sessions, windows and panes.

Each mode has a common set of key bindings plus a few that are specific
to the mode. Other changes are:

- each mode has a preview pane: for buffers this is the buffer content
(very useful), for others it is a preview of the pane;

- items may be sorted in different ways ('O' key);

- multiple items may be tagged and an operation applied to all of them
(for example, to delete multiple buffers at once);

- in tree mode a command may be run on the selected item (session,
window, pane) or on tagged items (key ':');

- displayed items may be filtered in tree mode by using a format (this
is used to implement find-window) (key 'f');

- the custom format (-F) for the display is no longer available;

- shortcut keys change from 0-9, a-z, A-Z which was always a bit weird
with keys used for other uses to 0-9, M-a to M-z.

Now that the code is simpler, other improvements will come later.

Primary key bindings for each mode are documented under the commands in
the man page (choose-buffer, choose-client, choose-tree).

Parts written by Thomas Adam.


# 1.84 25-Apr-2017 nicm

Do not update TERM into config file parsing has finished.


# 1.83 22-Apr-2017 nicm

Get rid of the extra layer of flags and cmd_prepare() and just store the
CMD_FIND_* flags in the cmd_entry and call it for the command. Commands
with special requirements call it themselves and update the target for
hooks to use.


# 1.82 22-Apr-2017 nicm

Mouse bindings and hooks set up an initial current state when running a
command. This is used for the session, window and pane for all commands
in the command sequence if there is no -t or -s.

However, using it for all commands in the command sequence means that if
the active pane or current session is changed, subsequent commands still
use the previous state. So make commands which explicitly change the
current state (such as neww and selectp) update it themselves for later
commands. Commands which may invalidate the state (like killp) are
already OK because an invalid state will be ignored.

Also fill in the current state for all key bindings rather than just the
mouse, so that any omissions are easier to spot.


# 1.81 21-Apr-2017 nicm

Add cmd_find_from_winlink_pane and use it in a couple of places, and
make functions that can't fail void.


Revision tags: OPENBSD_6_1_BASE
# 1.80 09-Mar-2017 nicm

Move server_fill_environ into environ.c and move some other common code
into it.


# 1.79 08-Mar-2017 nicm

Add a helper function for the most common format_create/defaults/expand
pattern.


# 1.78 27-Feb-2017 nicm

If splitw -b is used, insert the new pane before the current one in the
pane list. This means the numbering is in order (for example for
display-panes) and fixes a problem with redrawing the active pane
borders.


# 1.77 03-Feb-2017 nicm

Add a window or pane id "tag" to each format tree and use it to separate
jobs, this means that if the same job is used for different windows or
panes (for example in pane-border-format), it will be run separately for
each pane.


# 1.76 16-Oct-2016 nicm

Use the notify name string instead of going via an enum and change
existing hooks to use notifys instead.


# 1.75 16-Oct-2016 nicm

Mass rename struct cmd_q to struct cmdq_item and related.


# 1.74 16-Oct-2016 nicm

Rewrite command queue handling. Each client still has a command queue,
but there is also now a global command queue. Instead of command queues
being dispatched on demand from wherever the command happens to be
added, they are now all dispatched from the top level server
loop. Command queues may now also include callbacks as well as commands,
and items may be inserted after the current command as well as at the end.

This all makes command queues significantly more predictable and easier
to use, and avoids the complex multiple nested command queues used by
source-file, if-shell and friends.

A mass rename of struct cmdq to a better name (cmdq_item probably) is
coming.


# 1.73 13-Oct-2016 nicm

Trying to do hooks generically is way too complicated and unreliable and
confusing, particularly trying to automatically figure out what target
hooks should be using. So simplify it:

- drop before hooks entirely, they don't seem to be very useful;

- commands with special requirements now fire their own after hook (for
example, if they change session or window, or if they have -t and -s
and need to choose which one the hook uses as current target);

- commands with no special requirements can have the CMD_AFTERHOOK flag
added and they will use the -t state.

At the moment new-session, new-window, split-window fire their own hook,
and display-message uses the flag. The remaining commands still need to
be looked at.


# 1.72 13-Oct-2016 nicm

Some improvements and bug fixes for hooks:

- Prepare the state again before the "after" hooks are run, because the
command may have killed or moved windows.

- Use the hooks list from the newly prepared target, not the old hooks
list (only matters for new-session really).

- Correctly detect an invalid current state and ignore it in
cmd_find_target ("killw; swapw").

- Change neww, new, killp, killw, splitw, swapp, swapw to update the
current state (used if no explicit target is given) to something more
useful after they have finished. For example, neww changes it to the
newly created window.

Hooks are still relatively new and primitive so there are likely to be
more changes to come.

Parts based on bug reports from Uwe Werler and Iblis Lin.


# 1.71 10-Oct-2016 nicm

Add static in cmd-* and fix a few other nits.


# 1.70 04-Sep-2016 nicm

Add support for performing a full width split (with splitw -f), rather
than splitting the current cell. From Stephen Kent.


Revision tags: OPENBSD_6_0_BASE
# 1.69 06-Jun-2016 nicm

Insert new panes after the pane being split in the list rather than
always after the active pane. This is more sensible when doing it with
commands rather than keys.


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

I no longer use my SourceForge address so replace it.


# 1.67 14-Dec-2015 nicm

Instead of combined flags for -c, -s, -t, split into different sets
using an enum and simplify the parsing code.


# 1.66 13-Dec-2015 nicm

Use member names in cmd_entry definitions so I stop getting confused
about the order.


# 1.65 13-Dec-2015 nicm

Instead of every command resolving the target (-t or -s) itself, prepare
the state (client, session, winlink, pane) for it it before entering the
command. Each command provides some flags that tell the prepare step
what it is expecting.

This is a requirement for having hooks on commands (for example, if you
hook "select-window -t1:2", the hook command should to operate on window
1:2 not whatever it thinks is the current window), and should allow some
other target improvements.

The old cmd_find_* functions remain for the moment but that layer will
be dropped later.

Joint work with Thomas Adam.


# 1.64 11-Dec-2015 nicm

Add cmdq as an argument to format_create and add a format for the
command name (will also be used for more later).


# 1.63 08-Dec-2015 nicm

Remove format_create_flags and just pass flags to format_create.


# 1.62 31-Oct-2015 nicm

Fall back silently to ~ or / rather than checking -c with access(), this
was the old behaviour.


# 1.61 31-Oct-2015 nicm

Because pledge(2) does not allow us to pass directory file descriptors
around, we can't use file descriptors for the working directory because
we will be unable to pass it to a privileged process to tell it where to
read or write files or spawn children. So move tmux back to using
strings for the current working directory. We try to check it exists
with access() when it is set but ultimately fall back to ~ if it fails
at time of use (or / if that fails too).


# 1.60 28-Oct-2015 nicm

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


# 1.59 27-Oct-2015 nicm

Move struct options into options.c.


# 1.58 23-Oct-2015 nicm

Remove some unnecessary checks before free().


Revision tags: OPENBSD_5_8_BASE
# 1.57 26-Apr-2015 nicm

Remove panes from layout if spawning them fails, reported by Anthony J
Bentley.


Revision tags: OPENBSD_5_7_BASE
# 1.56 05-Feb-2015 nicm

Remove a couple of now-unused variables.


# 1.55 05-Feb-2015 nicm

Wrap all the individual format_* calls in a single format_defaults
functions.


# 1.54 12-Nov-2014 nicm

Add -b to splitw like joinw, from Felix Rosencrantz.


# 1.53 20-Oct-2014 nicm

Move template defines back into .c files.


# 1.52 20-Oct-2014 nicm

Instead of setting up the default keys by building the key struct
directly with a helper function in the cmd_entry, include a table of
bind-key commands and pass them through the command parser and a
temporary cmd_q.

As well as being smaller, this will allow default bindings to be command
sequences which will probably be needed soon.


# 1.51 01-Sep-2014 nicm

Various minor style and spacing nits.


Revision tags: OPENBSD_5_6_BASE
# 1.50 13-May-2014 nicm

If multiple arguments are given to new-session, new-window,
split-window, respawn-window or respawn-pane, pass them directly to
execvp() to help avoid quoting problems. One argument still goes to "sh
-c" like before. Requested by many over the years. Patch from J Raynor.


# 1.49 17-Apr-2014 nicm

Set PATH explicitly, either from client or session
environment. Previously it came from the session environment. From J
Raynor.


Revision tags: OPENBSD_5_5_BASE
# 1.48 22-Nov-2013 nicm

Handle empty current directory more gracefully.


# 1.47 10-Oct-2013 nicm

Don't boke when figuring out working directory from configuration file.


# 1.46 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.45 10-Oct-2013 nicm

Support -c for new-session, based on code from J Raynor.


# 1.44 10-Oct-2013 nicm

Restore missing key binding for %, from Chris Johnsen.


# 1.43 10-Oct-2013 nicm

Remove the barely-used and unnecessary command check() function.


Revision tags: OPENBSD_5_4_BASE
# 1.42 25-Mar-2013 nicm

Revert the command-prefix change which breaks sequences of commands.


# 1.41 24-Mar-2013 nicm

Add resize-pane -Z to temporary zoom the active pane to occupy the full
window or unzoom (restored to the normal layout) if it already zoomed,
bound to C-b z by default. The pane is unzoomed on pretty much any
excuse whatsoever.

We considered making this a new layout but the requirements are quite
different from layouts so decided it is better as a special case. Each
current layout cell is saved, a temporary one-cell layout generated and
all except the active pane set to NULL.

Prompted by suggestions and scripts from several. Thanks to Aaron Jensen
and Thiago Padilha for testing an earlier version.


# 1.40 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.


# 1.39 24-Mar-2013 nicm

Fix error reporting for client commands by adding a flag to
cmd_find_client to tell it whether or not to show errors, sometimes it's
needed and sometimes not.


# 1.38 24-Mar-2013 nicm

Add option command-prefix which is automatically prepended to any
command (apart from a naked default-shell). The default is "exec ".


Revision tags: OPENBSD_5_3_BASE
# 1.37 09-Dec-2012 nicm

Use the CMD_*_USAGE defines consistently, from Thomas Adam.


# 1.36 14-Aug-2012 nicm

Use a separate define for each default format template and strip clutter
from the choose-tree defaults.


Revision tags: OPENBSD_5_2_BASE
# 1.35 11-Jul-2012 nicm

Make command exec functions return an enum rather than -1/0/1 values and
add a new value to mean "leave client running but don't attach" to fix
problems with using some commands in a command sequence. Most of the
work by Thomas Adam, problem reported by "jspenguin" on SF bug 3535531.


# 1.34 10-Jul-2012 nicm

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


# 1.33 22-May-2012 nicm

Switch all of the various choose- and list- commands over to the format
infrastructure, from Thomas Adam.


# 1.32 17-Mar-2012 nicm

Add notify hooks for various events, the functions are currently empty
stubs but will be filled in for control mode later. From George Nachman.


# 1.31 04-Mar-2012 nicm

free -> xfree.


# 1.30 04-Mar-2012 nicm

Add -F format to new-window and split-window to use with the -P flag,
from George Nachman.


# 1.29 03-Mar-2012 nicm

Add move-pane command (like join-pane but allows the same window). Also
-b flag to join-pane and move-pane to place the pane to the left or
above. From George Nachman.


Revision tags: OPENBSD_5_1_BASE
# 1.28 31-Jan-2012 nicm

Provide defined ways to set the various default-path possibilities: ~
for home directory, . for server start directory, - for session start
directory and empty for the pane's working directory (the default). All
can also be used as part of a relative path (eg -/foo). Also provide -c
flags to neww and splitw to override default-path setting.

Based on a diff from sthen. ok sthen


# 1.27 20-Jan-2012 nicm

Add some const and fix a warning.


# 1.26 09-Dec-2011 nicm

Change the way the working directory for new processes is discovered. If
default-path isn't empty, it is used. Otherwise:

1) If tmux neww is run from the command line, the working directory of the
client is used.

2) Otherwise sysctl KERN_PROC_CWD is used to retrieve the current
working directory of the process in the active pane.

3) If that fails, the directory where the session was created is used.

Support code by Romain Francois, OpenBSD specific bits by me.

Note this requires a recent userland and kernel with KERN_PROC_CWD.


# 1.25 15-Nov-2011 nicm

Make window_pane_index work the same as window_index, from Ben Boeckel.


# 1.24 30-Aug-2011 nicm

Plug memory leak, from Tiago Cunha.


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE
# 1.23 10-Feb-2011 nicm

Size on split-window is -l not -s. Doh.


# 1.22 04-Jan-2011 nicm

Clean up and simplify tmux command argument parsing.

Originally, tmux commands were parsed in the client process into a
struct with the command data which was then serialised and sent to the
server to be executed. The parsing was later moved into the server (an
argv was sent from the client), but the parse step and intermediate
struct was kept.

This change removes that struct and the separate parse step. Argument
parsing and printing is now common to all commands (in arguments.c) with
each command left with just an optional check function (to validate the
arguments at parse time), the exec function and a function to set up any
key bindings (renamed from the old init function).

This is overall more simple and consistent.

There should be no changes to any commands behaviour or syntax although
as this touches every command please watch for any unexpected changes.


# 1.21 01-Jan-2011 nicm

Add a -P option to new-window and split-window to print the new window
or pane index in target form (useful to pass it into other commands).


Revision tags: OPENBSD_4_8_BASE
# 1.20 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.


Revision tags: OPENBSD_4_7_BASE
# 1.19 07-Jan-2010 nicm

New command, join-pane, to split and move an existing pane into the space (like
splitw then movep, or the reverse of breakp).


# 1.18 07-Jan-2010 nicm

Use the specified pane for size calculations. Doh.


# 1.17 07-Jan-2010 nicm

Change split-window to accept a pane target (it should be split-pane but
renaming the command would be annoying).


# 1.16 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.15 20-Nov-2009 nicm

When -h and -p are given to split-window, calculate the percentage size using
the width instead of the height.


# 1.14 13-Nov-2009 nicm

Get rid of the ugly CMD_CHFLAG macro and use a const string (eg "dDU") in the
command entry structs and a couple of functions to check/set the flags.


# 1.13 21-Sep-2009 nicm

Use KEYC_NONE constant instead of 0 on init.


# 1.12 16-Sep-2009 nicm

Rather than constructing an entire termios struct from ttydefaults.h, just let
forkpty do it and then alter the bits that should be changed after fork. A
little neater and more portable.


# 1.11 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.10 25-Aug-2009 nicm

Print -l and -p when showing command, pointed out by Tiago Cunha.


# 1.9 13-Aug-2009 nicm

When creating a new session from the command-line where there is an external
terminal, copy the termios(4) special characters and use them for new windows
created in the new session. Suggested by Theo.


# 1.8 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.7 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.6 22-Jul-2009 nicm

window_add_pane cannot fail, so remove the unused cause argument and don't
bother to check for a NULL return.


# 1.5 19-Jul-2009 nicm

Improved layout code.

Each window now has a tree of layout cells associated with it. In this tree,
each node is either a horizontal or vertical cell containing a list of other
cells running from left-to-right or top-to-bottom, or a leaf cell which is
associated with a pane.

The major functional changes are:

- panes may now be split arbitrarily both horizontally (splitw -h, C-b %) and
vertically (splitw -v, C-b ");
- panes may be resized both horizontally and vertically (resizep -L/-R/-U/-D,
bound to C-b left/right/up/down and C-b M-left/right/up/down);
- layouts are now applied and then may be modified by resizing or splitting
panes, rather than being fixed and reapplied when the window is resized or
panes are added;
- manual-vertical layout is no longer necessary, and active-only layout is gone
(but may return in future);
- the main-pane layouts now reduce the size of the main pane to fit all panes
if possible.

Thanks to all who tested.


# 1.4 13-Jul-2009 nicm

Having fixed flags for single-character getopt options is a bit hard to
maintain and is only going to get worse as more are used. So instead, add a new
uint64_t member to cmd_entry which is a bitmask of upper and lowercase options
accepted by the command.

This means new single character options can be used without the need to add it
explicitly to the list.


# 1.3 07-Jul-2009 nicm

The fix for default-path (use target session options instead of global options)
is required here as well, doh.


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

lines variable can be -1 (to be ignored), so should be signed. Found by lint.


# 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.88 01-Mar-2018 nicm

Expand formats in window and session names.


Revision tags: OPENBSD_6_2_BASE
# 1.87 30-Aug-2017 nicm

Pass flags into cmd_find_from_* to fix prefer-unattached, reported by
Thomas Sattler.


# 1.86 21-Jul-2017 nicm

Add -c for respawn-pane and respawn-window, from J Raynor.


# 1.85 30-May-2017 nicm

Rewrite of choose mode, both to simplify and tidy the code and to add
some modern features.

Now the common code is in mode-tree.c, which provides an API used by the
three modes now separated into window-{buffer,client,tree}.c. Buffer
mode shows buffers, client mode clients and tree mode a tree of
sessions, windows and panes.

Each mode has a common set of key bindings plus a few that are specific
to the mode. Other changes are:

- each mode has a preview pane: for buffers this is the buffer content
(very useful), for others it is a preview of the pane;

- items may be sorted in different ways ('O' key);

- multiple items may be tagged and an operation applied to all of them
(for example, to delete multiple buffers at once);

- in tree mode a command may be run on the selected item (session,
window, pane) or on tagged items (key ':');

- displayed items may be filtered in tree mode by using a format (this
is used to implement find-window) (key 'f');

- the custom format (-F) for the display is no longer available;

- shortcut keys change from 0-9, a-z, A-Z which was always a bit weird
with keys used for other uses to 0-9, M-a to M-z.

Now that the code is simpler, other improvements will come later.

Primary key bindings for each mode are documented under the commands in
the man page (choose-buffer, choose-client, choose-tree).

Parts written by Thomas Adam.


# 1.84 25-Apr-2017 nicm

Do not update TERM into config file parsing has finished.


# 1.83 22-Apr-2017 nicm

Get rid of the extra layer of flags and cmd_prepare() and just store the
CMD_FIND_* flags in the cmd_entry and call it for the command. Commands
with special requirements call it themselves and update the target for
hooks to use.


# 1.82 22-Apr-2017 nicm

Mouse bindings and hooks set up an initial current state when running a
command. This is used for the session, window and pane for all commands
in the command sequence if there is no -t or -s.

However, using it for all commands in the command sequence means that if
the active pane or current session is changed, subsequent commands still
use the previous state. So make commands which explicitly change the
current state (such as neww and selectp) update it themselves for later
commands. Commands which may invalidate the state (like killp) are
already OK because an invalid state will be ignored.

Also fill in the current state for all key bindings rather than just the
mouse, so that any omissions are easier to spot.


# 1.81 21-Apr-2017 nicm

Add cmd_find_from_winlink_pane and use it in a couple of places, and
make functions that can't fail void.


Revision tags: OPENBSD_6_1_BASE
# 1.80 09-Mar-2017 nicm

Move server_fill_environ into environ.c and move some other common code
into it.


# 1.79 08-Mar-2017 nicm

Add a helper function for the most common format_create/defaults/expand
pattern.


# 1.78 27-Feb-2017 nicm

If splitw -b is used, insert the new pane before the current one in the
pane list. This means the numbering is in order (for example for
display-panes) and fixes a problem with redrawing the active pane
borders.


# 1.77 03-Feb-2017 nicm

Add a window or pane id "tag" to each format tree and use it to separate
jobs, this means that if the same job is used for different windows or
panes (for example in pane-border-format), it will be run separately for
each pane.


# 1.76 16-Oct-2016 nicm

Use the notify name string instead of going via an enum and change
existing hooks to use notifys instead.


# 1.75 16-Oct-2016 nicm

Mass rename struct cmd_q to struct cmdq_item and related.


# 1.74 16-Oct-2016 nicm

Rewrite command queue handling. Each client still has a command queue,
but there is also now a global command queue. Instead of command queues
being dispatched on demand from wherever the command happens to be
added, they are now all dispatched from the top level server
loop. Command queues may now also include callbacks as well as commands,
and items may be inserted after the current command as well as at the end.

This all makes command queues significantly more predictable and easier
to use, and avoids the complex multiple nested command queues used by
source-file, if-shell and friends.

A mass rename of struct cmdq to a better name (cmdq_item probably) is
coming.


# 1.73 13-Oct-2016 nicm

Trying to do hooks generically is way too complicated and unreliable and
confusing, particularly trying to automatically figure out what target
hooks should be using. So simplify it:

- drop before hooks entirely, they don't seem to be very useful;

- commands with special requirements now fire their own after hook (for
example, if they change session or window, or if they have -t and -s
and need to choose which one the hook uses as current target);

- commands with no special requirements can have the CMD_AFTERHOOK flag
added and they will use the -t state.

At the moment new-session, new-window, split-window fire their own hook,
and display-message uses the flag. The remaining commands still need to
be looked at.


# 1.72 13-Oct-2016 nicm

Some improvements and bug fixes for hooks:

- Prepare the state again before the "after" hooks are run, because the
command may have killed or moved windows.

- Use the hooks list from the newly prepared target, not the old hooks
list (only matters for new-session really).

- Correctly detect an invalid current state and ignore it in
cmd_find_target ("killw; swapw").

- Change neww, new, killp, killw, splitw, swapp, swapw to update the
current state (used if no explicit target is given) to something more
useful after they have finished. For example, neww changes it to the
newly created window.

Hooks are still relatively new and primitive so there are likely to be
more changes to come.

Parts based on bug reports from Uwe Werler and Iblis Lin.


# 1.71 10-Oct-2016 nicm

Add static in cmd-* and fix a few other nits.


# 1.70 04-Sep-2016 nicm

Add support for performing a full width split (with splitw -f), rather
than splitting the current cell. From Stephen Kent.


Revision tags: OPENBSD_6_0_BASE
# 1.69 06-Jun-2016 nicm

Insert new panes after the pane being split in the list rather than
always after the active pane. This is more sensible when doing it with
commands rather than keys.


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

I no longer use my SourceForge address so replace it.


# 1.67 14-Dec-2015 nicm

Instead of combined flags for -c, -s, -t, split into different sets
using an enum and simplify the parsing code.


# 1.66 13-Dec-2015 nicm

Use member names in cmd_entry definitions so I stop getting confused
about the order.


# 1.65 13-Dec-2015 nicm

Instead of every command resolving the target (-t or -s) itself, prepare
the state (client, session, winlink, pane) for it it before entering the
command. Each command provides some flags that tell the prepare step
what it is expecting.

This is a requirement for having hooks on commands (for example, if you
hook "select-window -t1:2", the hook command should to operate on window
1:2 not whatever it thinks is the current window), and should allow some
other target improvements.

The old cmd_find_* functions remain for the moment but that layer will
be dropped later.

Joint work with Thomas Adam.


# 1.64 11-Dec-2015 nicm

Add cmdq as an argument to format_create and add a format for the
command name (will also be used for more later).


# 1.63 08-Dec-2015 nicm

Remove format_create_flags and just pass flags to format_create.


# 1.62 31-Oct-2015 nicm

Fall back silently to ~ or / rather than checking -c with access(), this
was the old behaviour.


# 1.61 31-Oct-2015 nicm

Because pledge(2) does not allow us to pass directory file descriptors
around, we can't use file descriptors for the working directory because
we will be unable to pass it to a privileged process to tell it where to
read or write files or spawn children. So move tmux back to using
strings for the current working directory. We try to check it exists
with access() when it is set but ultimately fall back to ~ if it fails
at time of use (or / if that fails too).


# 1.60 28-Oct-2015 nicm

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


# 1.59 27-Oct-2015 nicm

Move struct options into options.c.


# 1.58 23-Oct-2015 nicm

Remove some unnecessary checks before free().


Revision tags: OPENBSD_5_8_BASE
# 1.57 26-Apr-2015 nicm

Remove panes from layout if spawning them fails, reported by Anthony J
Bentley.


Revision tags: OPENBSD_5_7_BASE
# 1.56 05-Feb-2015 nicm

Remove a couple of now-unused variables.


# 1.55 05-Feb-2015 nicm

Wrap all the individual format_* calls in a single format_defaults
functions.


# 1.54 12-Nov-2014 nicm

Add -b to splitw like joinw, from Felix Rosencrantz.


# 1.53 20-Oct-2014 nicm

Move template defines back into .c files.


# 1.52 20-Oct-2014 nicm

Instead of setting up the default keys by building the key struct
directly with a helper function in the cmd_entry, include a table of
bind-key commands and pass them through the command parser and a
temporary cmd_q.

As well as being smaller, this will allow default bindings to be command
sequences which will probably be needed soon.


# 1.51 01-Sep-2014 nicm

Various minor style and spacing nits.


Revision tags: OPENBSD_5_6_BASE
# 1.50 13-May-2014 nicm

If multiple arguments are given to new-session, new-window,
split-window, respawn-window or respawn-pane, pass them directly to
execvp() to help avoid quoting problems. One argument still goes to "sh
-c" like before. Requested by many over the years. Patch from J Raynor.


# 1.49 17-Apr-2014 nicm

Set PATH explicitly, either from client or session
environment. Previously it came from the session environment. From J
Raynor.


Revision tags: OPENBSD_5_5_BASE
# 1.48 22-Nov-2013 nicm

Handle empty current directory more gracefully.


# 1.47 10-Oct-2013 nicm

Don't boke when figuring out working directory from configuration file.


# 1.46 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.45 10-Oct-2013 nicm

Support -c for new-session, based on code from J Raynor.


# 1.44 10-Oct-2013 nicm

Restore missing key binding for %, from Chris Johnsen.


# 1.43 10-Oct-2013 nicm

Remove the barely-used and unnecessary command check() function.


Revision tags: OPENBSD_5_4_BASE
# 1.42 25-Mar-2013 nicm

Revert the command-prefix change which breaks sequences of commands.


# 1.41 24-Mar-2013 nicm

Add resize-pane -Z to temporary zoom the active pane to occupy the full
window or unzoom (restored to the normal layout) if it already zoomed,
bound to C-b z by default. The pane is unzoomed on pretty much any
excuse whatsoever.

We considered making this a new layout but the requirements are quite
different from layouts so decided it is better as a special case. Each
current layout cell is saved, a temporary one-cell layout generated and
all except the active pane set to NULL.

Prompted by suggestions and scripts from several. Thanks to Aaron Jensen
and Thiago Padilha for testing an earlier version.


# 1.40 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.


# 1.39 24-Mar-2013 nicm

Fix error reporting for client commands by adding a flag to
cmd_find_client to tell it whether or not to show errors, sometimes it's
needed and sometimes not.


# 1.38 24-Mar-2013 nicm

Add option command-prefix which is automatically prepended to any
command (apart from a naked default-shell). The default is "exec ".


Revision tags: OPENBSD_5_3_BASE
# 1.37 09-Dec-2012 nicm

Use the CMD_*_USAGE defines consistently, from Thomas Adam.


# 1.36 14-Aug-2012 nicm

Use a separate define for each default format template and strip clutter
from the choose-tree defaults.


Revision tags: OPENBSD_5_2_BASE
# 1.35 11-Jul-2012 nicm

Make command exec functions return an enum rather than -1/0/1 values and
add a new value to mean "leave client running but don't attach" to fix
problems with using some commands in a command sequence. Most of the
work by Thomas Adam, problem reported by "jspenguin" on SF bug 3535531.


# 1.34 10-Jul-2012 nicm

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


# 1.33 22-May-2012 nicm

Switch all of the various choose- and list- commands over to the format
infrastructure, from Thomas Adam.


# 1.32 17-Mar-2012 nicm

Add notify hooks for various events, the functions are currently empty
stubs but will be filled in for control mode later. From George Nachman.


# 1.31 04-Mar-2012 nicm

free -> xfree.


# 1.30 04-Mar-2012 nicm

Add -F format to new-window and split-window to use with the -P flag,
from George Nachman.


# 1.29 03-Mar-2012 nicm

Add move-pane command (like join-pane but allows the same window). Also
-b flag to join-pane and move-pane to place the pane to the left or
above. From George Nachman.


Revision tags: OPENBSD_5_1_BASE
# 1.28 31-Jan-2012 nicm

Provide defined ways to set the various default-path possibilities: ~
for home directory, . for server start directory, - for session start
directory and empty for the pane's working directory (the default). All
can also be used as part of a relative path (eg -/foo). Also provide -c
flags to neww and splitw to override default-path setting.

Based on a diff from sthen. ok sthen


# 1.27 20-Jan-2012 nicm

Add some const and fix a warning.


# 1.26 09-Dec-2011 nicm

Change the way the working directory for new processes is discovered. If
default-path isn't empty, it is used. Otherwise:

1) If tmux neww is run from the command line, the working directory of the
client is used.

2) Otherwise sysctl KERN_PROC_CWD is used to retrieve the current
working directory of the process in the active pane.

3) If that fails, the directory where the session was created is used.

Support code by Romain Francois, OpenBSD specific bits by me.

Note this requires a recent userland and kernel with KERN_PROC_CWD.


# 1.25 15-Nov-2011 nicm

Make window_pane_index work the same as window_index, from Ben Boeckel.


# 1.24 30-Aug-2011 nicm

Plug memory leak, from Tiago Cunha.


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE
# 1.23 10-Feb-2011 nicm

Size on split-window is -l not -s. Doh.


# 1.22 04-Jan-2011 nicm

Clean up and simplify tmux command argument parsing.

Originally, tmux commands were parsed in the client process into a
struct with the command data which was then serialised and sent to the
server to be executed. The parsing was later moved into the server (an
argv was sent from the client), but the parse step and intermediate
struct was kept.

This change removes that struct and the separate parse step. Argument
parsing and printing is now common to all commands (in arguments.c) with
each command left with just an optional check function (to validate the
arguments at parse time), the exec function and a function to set up any
key bindings (renamed from the old init function).

This is overall more simple and consistent.

There should be no changes to any commands behaviour or syntax although
as this touches every command please watch for any unexpected changes.


# 1.21 01-Jan-2011 nicm

Add a -P option to new-window and split-window to print the new window
or pane index in target form (useful to pass it into other commands).


Revision tags: OPENBSD_4_8_BASE
# 1.20 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.


Revision tags: OPENBSD_4_7_BASE
# 1.19 07-Jan-2010 nicm

New command, join-pane, to split and move an existing pane into the space (like
splitw then movep, or the reverse of breakp).


# 1.18 07-Jan-2010 nicm

Use the specified pane for size calculations. Doh.


# 1.17 07-Jan-2010 nicm

Change split-window to accept a pane target (it should be split-pane but
renaming the command would be annoying).


# 1.16 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.15 20-Nov-2009 nicm

When -h and -p are given to split-window, calculate the percentage size using
the width instead of the height.


# 1.14 13-Nov-2009 nicm

Get rid of the ugly CMD_CHFLAG macro and use a const string (eg "dDU") in the
command entry structs and a couple of functions to check/set the flags.


# 1.13 21-Sep-2009 nicm

Use KEYC_NONE constant instead of 0 on init.


# 1.12 16-Sep-2009 nicm

Rather than constructing an entire termios struct from ttydefaults.h, just let
forkpty do it and then alter the bits that should be changed after fork. A
little neater and more portable.


# 1.11 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.10 25-Aug-2009 nicm

Print -l and -p when showing command, pointed out by Tiago Cunha.


# 1.9 13-Aug-2009 nicm

When creating a new session from the command-line where there is an external
terminal, copy the termios(4) special characters and use them for new windows
created in the new session. Suggested by Theo.


# 1.8 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.7 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.6 22-Jul-2009 nicm

window_add_pane cannot fail, so remove the unused cause argument and don't
bother to check for a NULL return.


# 1.5 19-Jul-2009 nicm

Improved layout code.

Each window now has a tree of layout cells associated with it. In this tree,
each node is either a horizontal or vertical cell containing a list of other
cells running from left-to-right or top-to-bottom, or a leaf cell which is
associated with a pane.

The major functional changes are:

- panes may now be split arbitrarily both horizontally (splitw -h, C-b %) and
vertically (splitw -v, C-b ");
- panes may be resized both horizontally and vertically (resizep -L/-R/-U/-D,
bound to C-b left/right/up/down and C-b M-left/right/up/down);
- layouts are now applied and then may be modified by resizing or splitting
panes, rather than being fixed and reapplied when the window is resized or
panes are added;
- manual-vertical layout is no longer necessary, and active-only layout is gone
(but may return in future);
- the main-pane layouts now reduce the size of the main pane to fit all panes
if possible.

Thanks to all who tested.


# 1.4 13-Jul-2009 nicm

Having fixed flags for single-character getopt options is a bit hard to
maintain and is only going to get worse as more are used. So instead, add a new
uint64_t member to cmd_entry which is a bitmask of upper and lowercase options
accepted by the command.

This means new single character options can be used without the need to add it
explicitly to the list.


# 1.3 07-Jul-2009 nicm

The fix for default-path (use target session options instead of global options)
is required here as well, doh.


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

lines variable can be -1 (to be ignored), so should be signed. Found by lint.


# 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


Revision tags: OPENBSD_6_2_BASE
# 1.87 30-Aug-2017 nicm

Pass flags into cmd_find_from_* to fix prefer-unattached, reported by
Thomas Sattler.


# 1.86 21-Jul-2017 nicm

Add -c for respawn-pane and respawn-window, from J Raynor.


# 1.85 30-May-2017 nicm

Rewrite of choose mode, both to simplify and tidy the code and to add
some modern features.

Now the common code is in mode-tree.c, which provides an API used by the
three modes now separated into window-{buffer,client,tree}.c. Buffer
mode shows buffers, client mode clients and tree mode a tree of
sessions, windows and panes.

Each mode has a common set of key bindings plus a few that are specific
to the mode. Other changes are:

- each mode has a preview pane: for buffers this is the buffer content
(very useful), for others it is a preview of the pane;

- items may be sorted in different ways ('O' key);

- multiple items may be tagged and an operation applied to all of them
(for example, to delete multiple buffers at once);

- in tree mode a command may be run on the selected item (session,
window, pane) or on tagged items (key ':');

- displayed items may be filtered in tree mode by using a format (this
is used to implement find-window) (key 'f');

- the custom format (-F) for the display is no longer available;

- shortcut keys change from 0-9, a-z, A-Z which was always a bit weird
with keys used for other uses to 0-9, M-a to M-z.

Now that the code is simpler, other improvements will come later.

Primary key bindings for each mode are documented under the commands in
the man page (choose-buffer, choose-client, choose-tree).

Parts written by Thomas Adam.


# 1.84 25-Apr-2017 nicm

Do not update TERM into config file parsing has finished.


# 1.83 22-Apr-2017 nicm

Get rid of the extra layer of flags and cmd_prepare() and just store the
CMD_FIND_* flags in the cmd_entry and call it for the command. Commands
with special requirements call it themselves and update the target for
hooks to use.


# 1.82 22-Apr-2017 nicm

Mouse bindings and hooks set up an initial current state when running a
command. This is used for the session, window and pane for all commands
in the command sequence if there is no -t or -s.

However, using it for all commands in the command sequence means that if
the active pane or current session is changed, subsequent commands still
use the previous state. So make commands which explicitly change the
current state (such as neww and selectp) update it themselves for later
commands. Commands which may invalidate the state (like killp) are
already OK because an invalid state will be ignored.

Also fill in the current state for all key bindings rather than just the
mouse, so that any omissions are easier to spot.


# 1.81 21-Apr-2017 nicm

Add cmd_find_from_winlink_pane and use it in a couple of places, and
make functions that can't fail void.


Revision tags: OPENBSD_6_1_BASE
# 1.80 09-Mar-2017 nicm

Move server_fill_environ into environ.c and move some other common code
into it.


# 1.79 08-Mar-2017 nicm

Add a helper function for the most common format_create/defaults/expand
pattern.


# 1.78 27-Feb-2017 nicm

If splitw -b is used, insert the new pane before the current one in the
pane list. This means the numbering is in order (for example for
display-panes) and fixes a problem with redrawing the active pane
borders.


# 1.77 03-Feb-2017 nicm

Add a window or pane id "tag" to each format tree and use it to separate
jobs, this means that if the same job is used for different windows or
panes (for example in pane-border-format), it will be run separately for
each pane.


# 1.76 16-Oct-2016 nicm

Use the notify name string instead of going via an enum and change
existing hooks to use notifys instead.


# 1.75 16-Oct-2016 nicm

Mass rename struct cmd_q to struct cmdq_item and related.


# 1.74 16-Oct-2016 nicm

Rewrite command queue handling. Each client still has a command queue,
but there is also now a global command queue. Instead of command queues
being dispatched on demand from wherever the command happens to be
added, they are now all dispatched from the top level server
loop. Command queues may now also include callbacks as well as commands,
and items may be inserted after the current command as well as at the end.

This all makes command queues significantly more predictable and easier
to use, and avoids the complex multiple nested command queues used by
source-file, if-shell and friends.

A mass rename of struct cmdq to a better name (cmdq_item probably) is
coming.


# 1.73 13-Oct-2016 nicm

Trying to do hooks generically is way too complicated and unreliable and
confusing, particularly trying to automatically figure out what target
hooks should be using. So simplify it:

- drop before hooks entirely, they don't seem to be very useful;

- commands with special requirements now fire their own after hook (for
example, if they change session or window, or if they have -t and -s
and need to choose which one the hook uses as current target);

- commands with no special requirements can have the CMD_AFTERHOOK flag
added and they will use the -t state.

At the moment new-session, new-window, split-window fire their own hook,
and display-message uses the flag. The remaining commands still need to
be looked at.


# 1.72 13-Oct-2016 nicm

Some improvements and bug fixes for hooks:

- Prepare the state again before the "after" hooks are run, because the
command may have killed or moved windows.

- Use the hooks list from the newly prepared target, not the old hooks
list (only matters for new-session really).

- Correctly detect an invalid current state and ignore it in
cmd_find_target ("killw; swapw").

- Change neww, new, killp, killw, splitw, swapp, swapw to update the
current state (used if no explicit target is given) to something more
useful after they have finished. For example, neww changes it to the
newly created window.

Hooks are still relatively new and primitive so there are likely to be
more changes to come.

Parts based on bug reports from Uwe Werler and Iblis Lin.


# 1.71 10-Oct-2016 nicm

Add static in cmd-* and fix a few other nits.


# 1.70 04-Sep-2016 nicm

Add support for performing a full width split (with splitw -f), rather
than splitting the current cell. From Stephen Kent.


Revision tags: OPENBSD_6_0_BASE
# 1.69 06-Jun-2016 nicm

Insert new panes after the pane being split in the list rather than
always after the active pane. This is more sensible when doing it with
commands rather than keys.


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

I no longer use my SourceForge address so replace it.


# 1.67 14-Dec-2015 nicm

Instead of combined flags for -c, -s, -t, split into different sets
using an enum and simplify the parsing code.


# 1.66 13-Dec-2015 nicm

Use member names in cmd_entry definitions so I stop getting confused
about the order.


# 1.65 13-Dec-2015 nicm

Instead of every command resolving the target (-t or -s) itself, prepare
the state (client, session, winlink, pane) for it it before entering the
command. Each command provides some flags that tell the prepare step
what it is expecting.

This is a requirement for having hooks on commands (for example, if you
hook "select-window -t1:2", the hook command should to operate on window
1:2 not whatever it thinks is the current window), and should allow some
other target improvements.

The old cmd_find_* functions remain for the moment but that layer will
be dropped later.

Joint work with Thomas Adam.


# 1.64 11-Dec-2015 nicm

Add cmdq as an argument to format_create and add a format for the
command name (will also be used for more later).


# 1.63 08-Dec-2015 nicm

Remove format_create_flags and just pass flags to format_create.


# 1.62 31-Oct-2015 nicm

Fall back silently to ~ or / rather than checking -c with access(), this
was the old behaviour.


# 1.61 31-Oct-2015 nicm

Because pledge(2) does not allow us to pass directory file descriptors
around, we can't use file descriptors for the working directory because
we will be unable to pass it to a privileged process to tell it where to
read or write files or spawn children. So move tmux back to using
strings for the current working directory. We try to check it exists
with access() when it is set but ultimately fall back to ~ if it fails
at time of use (or / if that fails too).


# 1.60 28-Oct-2015 nicm

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


# 1.59 27-Oct-2015 nicm

Move struct options into options.c.


# 1.58 23-Oct-2015 nicm

Remove some unnecessary checks before free().


Revision tags: OPENBSD_5_8_BASE
# 1.57 26-Apr-2015 nicm

Remove panes from layout if spawning them fails, reported by Anthony J
Bentley.


Revision tags: OPENBSD_5_7_BASE
# 1.56 05-Feb-2015 nicm

Remove a couple of now-unused variables.


# 1.55 05-Feb-2015 nicm

Wrap all the individual format_* calls in a single format_defaults
functions.


# 1.54 12-Nov-2014 nicm

Add -b to splitw like joinw, from Felix Rosencrantz.


# 1.53 20-Oct-2014 nicm

Move template defines back into .c files.


# 1.52 20-Oct-2014 nicm

Instead of setting up the default keys by building the key struct
directly with a helper function in the cmd_entry, include a table of
bind-key commands and pass them through the command parser and a
temporary cmd_q.

As well as being smaller, this will allow default bindings to be command
sequences which will probably be needed soon.


# 1.51 01-Sep-2014 nicm

Various minor style and spacing nits.


Revision tags: OPENBSD_5_6_BASE
# 1.50 13-May-2014 nicm

If multiple arguments are given to new-session, new-window,
split-window, respawn-window or respawn-pane, pass them directly to
execvp() to help avoid quoting problems. One argument still goes to "sh
-c" like before. Requested by many over the years. Patch from J Raynor.


# 1.49 17-Apr-2014 nicm

Set PATH explicitly, either from client or session
environment. Previously it came from the session environment. From J
Raynor.


Revision tags: OPENBSD_5_5_BASE
# 1.48 22-Nov-2013 nicm

Handle empty current directory more gracefully.


# 1.47 10-Oct-2013 nicm

Don't boke when figuring out working directory from configuration file.


# 1.46 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.45 10-Oct-2013 nicm

Support -c for new-session, based on code from J Raynor.


# 1.44 10-Oct-2013 nicm

Restore missing key binding for %, from Chris Johnsen.


# 1.43 10-Oct-2013 nicm

Remove the barely-used and unnecessary command check() function.


Revision tags: OPENBSD_5_4_BASE
# 1.42 25-Mar-2013 nicm

Revert the command-prefix change which breaks sequences of commands.


# 1.41 24-Mar-2013 nicm

Add resize-pane -Z to temporary zoom the active pane to occupy the full
window or unzoom (restored to the normal layout) if it already zoomed,
bound to C-b z by default. The pane is unzoomed on pretty much any
excuse whatsoever.

We considered making this a new layout but the requirements are quite
different from layouts so decided it is better as a special case. Each
current layout cell is saved, a temporary one-cell layout generated and
all except the active pane set to NULL.

Prompted by suggestions and scripts from several. Thanks to Aaron Jensen
and Thiago Padilha for testing an earlier version.


# 1.40 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.


# 1.39 24-Mar-2013 nicm

Fix error reporting for client commands by adding a flag to
cmd_find_client to tell it whether or not to show errors, sometimes it's
needed and sometimes not.


# 1.38 24-Mar-2013 nicm

Add option command-prefix which is automatically prepended to any
command (apart from a naked default-shell). The default is "exec ".


Revision tags: OPENBSD_5_3_BASE
# 1.37 09-Dec-2012 nicm

Use the CMD_*_USAGE defines consistently, from Thomas Adam.


# 1.36 14-Aug-2012 nicm

Use a separate define for each default format template and strip clutter
from the choose-tree defaults.


Revision tags: OPENBSD_5_2_BASE
# 1.35 11-Jul-2012 nicm

Make command exec functions return an enum rather than -1/0/1 values and
add a new value to mean "leave client running but don't attach" to fix
problems with using some commands in a command sequence. Most of the
work by Thomas Adam, problem reported by "jspenguin" on SF bug 3535531.


# 1.34 10-Jul-2012 nicm

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


# 1.33 22-May-2012 nicm

Switch all of the various choose- and list- commands over to the format
infrastructure, from Thomas Adam.


# 1.32 17-Mar-2012 nicm

Add notify hooks for various events, the functions are currently empty
stubs but will be filled in for control mode later. From George Nachman.


# 1.31 04-Mar-2012 nicm

free -> xfree.


# 1.30 04-Mar-2012 nicm

Add -F format to new-window and split-window to use with the -P flag,
from George Nachman.


# 1.29 03-Mar-2012 nicm

Add move-pane command (like join-pane but allows the same window). Also
-b flag to join-pane and move-pane to place the pane to the left or
above. From George Nachman.


Revision tags: OPENBSD_5_1_BASE
# 1.28 31-Jan-2012 nicm

Provide defined ways to set the various default-path possibilities: ~
for home directory, . for server start directory, - for session start
directory and empty for the pane's working directory (the default). All
can also be used as part of a relative path (eg -/foo). Also provide -c
flags to neww and splitw to override default-path setting.

Based on a diff from sthen. ok sthen


# 1.27 20-Jan-2012 nicm

Add some const and fix a warning.


# 1.26 09-Dec-2011 nicm

Change the way the working directory for new processes is discovered. If
default-path isn't empty, it is used. Otherwise:

1) If tmux neww is run from the command line, the working directory of the
client is used.

2) Otherwise sysctl KERN_PROC_CWD is used to retrieve the current
working directory of the process in the active pane.

3) If that fails, the directory where the session was created is used.

Support code by Romain Francois, OpenBSD specific bits by me.

Note this requires a recent userland and kernel with KERN_PROC_CWD.


# 1.25 15-Nov-2011 nicm

Make window_pane_index work the same as window_index, from Ben Boeckel.


# 1.24 30-Aug-2011 nicm

Plug memory leak, from Tiago Cunha.


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE
# 1.23 10-Feb-2011 nicm

Size on split-window is -l not -s. Doh.


# 1.22 04-Jan-2011 nicm

Clean up and simplify tmux command argument parsing.

Originally, tmux commands were parsed in the client process into a
struct with the command data which was then serialised and sent to the
server to be executed. The parsing was later moved into the server (an
argv was sent from the client), but the parse step and intermediate
struct was kept.

This change removes that struct and the separate parse step. Argument
parsing and printing is now common to all commands (in arguments.c) with
each command left with just an optional check function (to validate the
arguments at parse time), the exec function and a function to set up any
key bindings (renamed from the old init function).

This is overall more simple and consistent.

There should be no changes to any commands behaviour or syntax although
as this touches every command please watch for any unexpected changes.


# 1.21 01-Jan-2011 nicm

Add a -P option to new-window and split-window to print the new window
or pane index in target form (useful to pass it into other commands).


Revision tags: OPENBSD_4_8_BASE
# 1.20 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.


Revision tags: OPENBSD_4_7_BASE
# 1.19 07-Jan-2010 nicm

New command, join-pane, to split and move an existing pane into the space (like
splitw then movep, or the reverse of breakp).


# 1.18 07-Jan-2010 nicm

Use the specified pane for size calculations. Doh.


# 1.17 07-Jan-2010 nicm

Change split-window to accept a pane target (it should be split-pane but
renaming the command would be annoying).


# 1.16 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.15 20-Nov-2009 nicm

When -h and -p are given to split-window, calculate the percentage size using
the width instead of the height.


# 1.14 13-Nov-2009 nicm

Get rid of the ugly CMD_CHFLAG macro and use a const string (eg "dDU") in the
command entry structs and a couple of functions to check/set the flags.


# 1.13 21-Sep-2009 nicm

Use KEYC_NONE constant instead of 0 on init.


# 1.12 16-Sep-2009 nicm

Rather than constructing an entire termios struct from ttydefaults.h, just let
forkpty do it and then alter the bits that should be changed after fork. A
little neater and more portable.


# 1.11 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.10 25-Aug-2009 nicm

Print -l and -p when showing command, pointed out by Tiago Cunha.


# 1.9 13-Aug-2009 nicm

When creating a new session from the command-line where there is an external
terminal, copy the termios(4) special characters and use them for new windows
created in the new session. Suggested by Theo.


# 1.8 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.7 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.6 22-Jul-2009 nicm

window_add_pane cannot fail, so remove the unused cause argument and don't
bother to check for a NULL return.


# 1.5 19-Jul-2009 nicm

Improved layout code.

Each window now has a tree of layout cells associated with it. In this tree,
each node is either a horizontal or vertical cell containing a list of other
cells running from left-to-right or top-to-bottom, or a leaf cell which is
associated with a pane.

The major functional changes are:

- panes may now be split arbitrarily both horizontally (splitw -h, C-b %) and
vertically (splitw -v, C-b ");
- panes may be resized both horizontally and vertically (resizep -L/-R/-U/-D,
bound to C-b left/right/up/down and C-b M-left/right/up/down);
- layouts are now applied and then may be modified by resizing or splitting
panes, rather than being fixed and reapplied when the window is resized or
panes are added;
- manual-vertical layout is no longer necessary, and active-only layout is gone
(but may return in future);
- the main-pane layouts now reduce the size of the main pane to fit all panes
if possible.

Thanks to all who tested.


# 1.4 13-Jul-2009 nicm

Having fixed flags for single-character getopt options is a bit hard to
maintain and is only going to get worse as more are used. So instead, add a new
uint64_t member to cmd_entry which is a bitmask of upper and lowercase options
accepted by the command.

This means new single character options can be used without the need to add it
explicitly to the list.


# 1.3 07-Jul-2009 nicm

The fix for default-path (use target session options instead of global options)
is required here as well, doh.


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

lines variable can be -1 (to be ignored), so should be signed. Found by lint.


# 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