History log of /openbsd-current/usr.bin/tmux/cmd-source-file.c
Revision (<<< Hide revision tags) (Show revision tags >>>) Date Author Comments
# 1.54 15-Sep-2023 nicm

Add -t to source-file, GitHub issue 3473.


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

Fix a few memory leaks.


# 1.52 22-Aug-2021 nicm

Do not double free expanded path in source-file, also remove some
unnecessary assignments.


# 1.51 21-Aug-2021 nicm

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


# 1.50 20-Aug-2021 nicm

Hide struct args behind a couple of accessor functions.


# 1.49 10-Jun-2021 nicm

Do not use NULL client when source-file finishes, GitHub issue 2707.


Revision tags: OPENBSD_6_8_BASE OPENBSD_6_9_BASE
# 1.48 01-Sep-2020 nicm

Add -F to set-environment and source-file; GitHub issue 2359.


Revision tags: OPENBSD_6_7_BASE
# 1.47 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.46 13-Apr-2020 nicm

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


# 1.45 21-Dec-2019 tim

Restore source-file -q behaviour, broken in r1.42; OK nicm@


# 1.44 19-Dec-2019 nicm

When adding a list with multiple commands to the queue, the next item to
insert after needs to be the last one added, not the first. Reported by
Jason Kim in GitHub issue 2023.


# 1.43 18-Dec-2019 nicm

Do not rely on errno after glob(3) fails.


# 1.42 12-Dec-2019 nicm

Change source-file to use new file code which allows it to read from
stdin.


Revision tags: OPENBSD_6_6_BASE
# 1.41 05-Jun-2019 nicm

Add a -v flag to source-file to show the commands and line numbers.


# 1.40 28-May-2019 nicm

Exit 1 correctly if source-file fails.


# 1.39 28-May-2019 nicm

Allow source-file to take multiple arguments.


# 1.38 23-May-2019 nicm

Replace the split parser code (cfg.c and cmd-string.c) with a single
parser using yacc(1). This is a major change but is clearer and simpler
and allows some edge cases to be made more consistent, as well as
tidying up how aliases are handled. It will also allow some further
improvements later.

Entirely the same parser is now used for parsing the configuration file
and for string commands. This means that constructs previously only
available in .tmux.conf, such as %if, can now be used in string commands
(for example, those given to if-shell - not commands invoked from the
shell, they are still parsed by the shell itself).

The only syntax change I am aware of is that #{} outside quotes or a
comment is now considered a format and not a comment, so #{ is now a
syntax error (notably, if it is at the start of a line).

This also adds two new sections to the man page documenting the syntax
and outlining how parsing and command execution works.

Thanks to everyone who sent me test configs (they still all parse
without errors - but this doesn't mean they still work as intended!).

Thanks to Avi Halachmi for testing and man page improvements, also to
jmc@ for reviewing the man page changes.


# 1.37 20-May-2019 nicm

Fix ordering of source-file with multiple files and add flags to load_cfg.


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.36 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_2_BASE OPENBSD_6_3_BASE
# 1.35 19-Apr-2017 nicm

load_cfg returns < 0 on error, not != 0. Problem reported by Kaushal Modi.


Revision tags: OPENBSD_6_1_BASE
# 1.34 14-Feb-2017 nicm

Make source-file look for files relative to the client working directory
(like load-buffer and save-buffer), from Chris Pickel. Also break the
where-is-this-file code out into its own function for loadb and saveb.


# 1.33 29-Jan-2017 nicm

Add -n to break-pane.


# 1.32 09-Jan-2017 nicm

source-file -q needs to apply to glob(3) too.


# 1.31 09-Jan-2017 nicm

Run the source-file pattern through glob(3).


# 1.30 16-Oct-2016 nicm

Mass rename struct cmd_q to struct cmdq_item and related.


# 1.29 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.28 14-Oct-2016 nicm

source-file and some other commands can recurse back into cmdq_continue,
which could potentially free the currently running command, so we need
to take a reference to it in cmdq_continue_one.

Fixes problem reported by Theo Buehler.


# 1.27 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.26 10-Oct-2016 nicm

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


Revision tags: OPENBSD_6_0_BASE
# 1.25 12-May-2016 tim

- Rework load_cfg() error handling a little.
- Add -q to source-file to suppress errors about nonexistent files.

Input and OK nicm@


# 1.24 29-Apr-2016 nicm

Final parts of command hooks, add before- and after- hooks to each command.


Revision tags: OPENBSD_5_9_BASE
# 1.23 13-Dec-2015 nicm

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


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


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.21 27-Oct-2014 nicm

Move cfg_causes local into cfg.c and remove struct causelist.


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


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.19 10-Oct-2013 nicm

Make cmdq->client_exit a tristate (-1 means "not set") so that if
explicitly set it can be copied from child to parent cmdq by if-shell
and source-file. This fixes using attach or new. From Chris Johnsen.


# 1.18 10-Oct-2013 nicm

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


Revision tags: OPENBSD_5_4_BASE
# 1.17 12-Apr-2013 nicm

Copy the client into the new cmdq in source-file so commands that work
on it (such as new-session) can work. Fixes issue reported by oss-adv at
users dot sf dot net.


# 1.16 25-Mar-2013 nicm

Continue the parent cmdq after sourcing a file.


# 1.15 24-Mar-2013 nicm

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

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

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

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


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

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


Revision tags: OPENBSD_5_2_BASE
# 1.13 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.12 10-Jul-2012 nicm

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


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.11 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.10 29-Dec-2010 nicm

Allow the config file parser and source-file to return "don't exit" to
the client to let attach work from configuration files.


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE
# 1.9 06-Feb-2010 nicm

Use the array.h code for the causes list.


# 1.8 06-Feb-2010 nicm

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


# 1.7 26-Nov-2009 nicm

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


# 1.6 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.5 21-Sep-2009 nicm

Use KEYC_NONE constant instead of 0 on init.


# 1.4 23-Aug-2009 nicm

When using source-file, run the commands in the context of the source-file
command rather than with no context. This makes things like attach work from a
file.


# 1.3 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.2 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.


Revision tags: OPENBSD_4_6_BASE
# 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.53 23-Aug-2021 nicm

Fix a few memory leaks.


# 1.52 22-Aug-2021 nicm

Do not double free expanded path in source-file, also remove some
unnecessary assignments.


# 1.51 21-Aug-2021 nicm

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


# 1.50 20-Aug-2021 nicm

Hide struct args behind a couple of accessor functions.


# 1.49 10-Jun-2021 nicm

Do not use NULL client when source-file finishes, GitHub issue 2707.


Revision tags: OPENBSD_6_8_BASE OPENBSD_6_9_BASE
# 1.48 01-Sep-2020 nicm

Add -F to set-environment and source-file; GitHub issue 2359.


Revision tags: OPENBSD_6_7_BASE
# 1.47 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.46 13-Apr-2020 nicm

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


# 1.45 21-Dec-2019 tim

Restore source-file -q behaviour, broken in r1.42; OK nicm@


# 1.44 19-Dec-2019 nicm

When adding a list with multiple commands to the queue, the next item to
insert after needs to be the last one added, not the first. Reported by
Jason Kim in GitHub issue 2023.


# 1.43 18-Dec-2019 nicm

Do not rely on errno after glob(3) fails.


# 1.42 12-Dec-2019 nicm

Change source-file to use new file code which allows it to read from
stdin.


Revision tags: OPENBSD_6_6_BASE
# 1.41 05-Jun-2019 nicm

Add a -v flag to source-file to show the commands and line numbers.


# 1.40 28-May-2019 nicm

Exit 1 correctly if source-file fails.


# 1.39 28-May-2019 nicm

Allow source-file to take multiple arguments.


# 1.38 23-May-2019 nicm

Replace the split parser code (cfg.c and cmd-string.c) with a single
parser using yacc(1). This is a major change but is clearer and simpler
and allows some edge cases to be made more consistent, as well as
tidying up how aliases are handled. It will also allow some further
improvements later.

Entirely the same parser is now used for parsing the configuration file
and for string commands. This means that constructs previously only
available in .tmux.conf, such as %if, can now be used in string commands
(for example, those given to if-shell - not commands invoked from the
shell, they are still parsed by the shell itself).

The only syntax change I am aware of is that #{} outside quotes or a
comment is now considered a format and not a comment, so #{ is now a
syntax error (notably, if it is at the start of a line).

This also adds two new sections to the man page documenting the syntax
and outlining how parsing and command execution works.

Thanks to everyone who sent me test configs (they still all parse
without errors - but this doesn't mean they still work as intended!).

Thanks to Avi Halachmi for testing and man page improvements, also to
jmc@ for reviewing the man page changes.


# 1.37 20-May-2019 nicm

Fix ordering of source-file with multiple files and add flags to load_cfg.


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.36 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_2_BASE OPENBSD_6_3_BASE
# 1.35 19-Apr-2017 nicm

load_cfg returns < 0 on error, not != 0. Problem reported by Kaushal Modi.


Revision tags: OPENBSD_6_1_BASE
# 1.34 14-Feb-2017 nicm

Make source-file look for files relative to the client working directory
(like load-buffer and save-buffer), from Chris Pickel. Also break the
where-is-this-file code out into its own function for loadb and saveb.


# 1.33 29-Jan-2017 nicm

Add -n to break-pane.


# 1.32 09-Jan-2017 nicm

source-file -q needs to apply to glob(3) too.


# 1.31 09-Jan-2017 nicm

Run the source-file pattern through glob(3).


# 1.30 16-Oct-2016 nicm

Mass rename struct cmd_q to struct cmdq_item and related.


# 1.29 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.28 14-Oct-2016 nicm

source-file and some other commands can recurse back into cmdq_continue,
which could potentially free the currently running command, so we need
to take a reference to it in cmdq_continue_one.

Fixes problem reported by Theo Buehler.


# 1.27 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.26 10-Oct-2016 nicm

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


Revision tags: OPENBSD_6_0_BASE
# 1.25 12-May-2016 tim

- Rework load_cfg() error handling a little.
- Add -q to source-file to suppress errors about nonexistent files.

Input and OK nicm@


# 1.24 29-Apr-2016 nicm

Final parts of command hooks, add before- and after- hooks to each command.


Revision tags: OPENBSD_5_9_BASE
# 1.23 13-Dec-2015 nicm

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


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


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.21 27-Oct-2014 nicm

Move cfg_causes local into cfg.c and remove struct causelist.


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


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.19 10-Oct-2013 nicm

Make cmdq->client_exit a tristate (-1 means "not set") so that if
explicitly set it can be copied from child to parent cmdq by if-shell
and source-file. This fixes using attach or new. From Chris Johnsen.


# 1.18 10-Oct-2013 nicm

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


Revision tags: OPENBSD_5_4_BASE
# 1.17 12-Apr-2013 nicm

Copy the client into the new cmdq in source-file so commands that work
on it (such as new-session) can work. Fixes issue reported by oss-adv at
users dot sf dot net.


# 1.16 25-Mar-2013 nicm

Continue the parent cmdq after sourcing a file.


# 1.15 24-Mar-2013 nicm

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

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

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

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


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

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


Revision tags: OPENBSD_5_2_BASE
# 1.13 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.12 10-Jul-2012 nicm

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


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.11 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.10 29-Dec-2010 nicm

Allow the config file parser and source-file to return "don't exit" to
the client to let attach work from configuration files.


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE
# 1.9 06-Feb-2010 nicm

Use the array.h code for the causes list.


# 1.8 06-Feb-2010 nicm

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


# 1.7 26-Nov-2009 nicm

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


# 1.6 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.5 21-Sep-2009 nicm

Use KEYC_NONE constant instead of 0 on init.


# 1.4 23-Aug-2009 nicm

When using source-file, run the commands in the context of the source-file
command rather than with no context. This makes things like attach work from a
file.


# 1.3 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.2 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.


Revision tags: OPENBSD_4_6_BASE
# 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.53 23-Aug-2021 nicm

Fix a few memory leaks.


# 1.52 22-Aug-2021 nicm

Do not double free expanded path in source-file, also remove some
unnecessary assignments.


# 1.51 21-Aug-2021 nicm

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


# 1.50 20-Aug-2021 nicm

Hide struct args behind a couple of accessor functions.


# 1.49 10-Jun-2021 nicm

Do not use NULL client when source-file finishes, GitHub issue 2707.


Revision tags: OPENBSD_6_8_BASE OPENBSD_6_9_BASE
# 1.48 01-Sep-2020 nicm

Add -F to set-environment and source-file; GitHub issue 2359.


Revision tags: OPENBSD_6_7_BASE
# 1.47 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.46 13-Apr-2020 nicm

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


# 1.45 21-Dec-2019 tim

Restore source-file -q behaviour, broken in r1.42; OK nicm@


# 1.44 19-Dec-2019 nicm

When adding a list with multiple commands to the queue, the next item to
insert after needs to be the last one added, not the first. Reported by
Jason Kim in GitHub issue 2023.


# 1.43 18-Dec-2019 nicm

Do not rely on errno after glob(3) fails.


# 1.42 12-Dec-2019 nicm

Change source-file to use new file code which allows it to read from
stdin.


Revision tags: OPENBSD_6_6_BASE
# 1.41 05-Jun-2019 nicm

Add a -v flag to source-file to show the commands and line numbers.


# 1.40 28-May-2019 nicm

Exit 1 correctly if source-file fails.


# 1.39 28-May-2019 nicm

Allow source-file to take multiple arguments.


# 1.38 23-May-2019 nicm

Replace the split parser code (cfg.c and cmd-string.c) with a single
parser using yacc(1). This is a major change but is clearer and simpler
and allows some edge cases to be made more consistent, as well as
tidying up how aliases are handled. It will also allow some further
improvements later.

Entirely the same parser is now used for parsing the configuration file
and for string commands. This means that constructs previously only
available in .tmux.conf, such as %if, can now be used in string commands
(for example, those given to if-shell - not commands invoked from the
shell, they are still parsed by the shell itself).

The only syntax change I am aware of is that #{} outside quotes or a
comment is now considered a format and not a comment, so #{ is now a
syntax error (notably, if it is at the start of a line).

This also adds two new sections to the man page documenting the syntax
and outlining how parsing and command execution works.

Thanks to everyone who sent me test configs (they still all parse
without errors - but this doesn't mean they still work as intended!).

Thanks to Avi Halachmi for testing and man page improvements, also to
jmc@ for reviewing the man page changes.


# 1.37 20-May-2019 nicm

Fix ordering of source-file with multiple files and add flags to load_cfg.


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.36 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_2_BASE OPENBSD_6_3_BASE
# 1.35 19-Apr-2017 nicm

load_cfg returns < 0 on error, not != 0. Problem reported by Kaushal Modi.


Revision tags: OPENBSD_6_1_BASE
# 1.34 14-Feb-2017 nicm

Make source-file look for files relative to the client working directory
(like load-buffer and save-buffer), from Chris Pickel. Also break the
where-is-this-file code out into its own function for loadb and saveb.


# 1.33 29-Jan-2017 nicm

Add -n to break-pane.


# 1.32 09-Jan-2017 nicm

source-file -q needs to apply to glob(3) too.


# 1.31 09-Jan-2017 nicm

Run the source-file pattern through glob(3).


# 1.30 16-Oct-2016 nicm

Mass rename struct cmd_q to struct cmdq_item and related.


# 1.29 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.28 14-Oct-2016 nicm

source-file and some other commands can recurse back into cmdq_continue,
which could potentially free the currently running command, so we need
to take a reference to it in cmdq_continue_one.

Fixes problem reported by Theo Buehler.


# 1.27 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.26 10-Oct-2016 nicm

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


Revision tags: OPENBSD_6_0_BASE
# 1.25 12-May-2016 tim

- Rework load_cfg() error handling a little.
- Add -q to source-file to suppress errors about nonexistent files.

Input and OK nicm@


# 1.24 29-Apr-2016 nicm

Final parts of command hooks, add before- and after- hooks to each command.


Revision tags: OPENBSD_5_9_BASE
# 1.23 13-Dec-2015 nicm

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


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


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.21 27-Oct-2014 nicm

Move cfg_causes local into cfg.c and remove struct causelist.


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


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.19 10-Oct-2013 nicm

Make cmdq->client_exit a tristate (-1 means "not set") so that if
explicitly set it can be copied from child to parent cmdq by if-shell
and source-file. This fixes using attach or new. From Chris Johnsen.


# 1.18 10-Oct-2013 nicm

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


Revision tags: OPENBSD_5_4_BASE
# 1.17 12-Apr-2013 nicm

Copy the client into the new cmdq in source-file so commands that work
on it (such as new-session) can work. Fixes issue reported by oss-adv at
users dot sf dot net.


# 1.16 25-Mar-2013 nicm

Continue the parent cmdq after sourcing a file.


# 1.15 24-Mar-2013 nicm

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

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

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

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


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

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


Revision tags: OPENBSD_5_2_BASE
# 1.13 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.12 10-Jul-2012 nicm

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


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.11 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.10 29-Dec-2010 nicm

Allow the config file parser and source-file to return "don't exit" to
the client to let attach work from configuration files.


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE
# 1.9 06-Feb-2010 nicm

Use the array.h code for the causes list.


# 1.8 06-Feb-2010 nicm

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


# 1.7 26-Nov-2009 nicm

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


# 1.6 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.5 21-Sep-2009 nicm

Use KEYC_NONE constant instead of 0 on init.


# 1.4 23-Aug-2009 nicm

When using source-file, run the commands in the context of the source-file
command rather than with no context. This makes things like attach work from a
file.


# 1.3 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.2 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.


Revision tags: OPENBSD_4_6_BASE
# 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.51 21-Aug-2021 nicm

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


# 1.50 20-Aug-2021 nicm

Hide struct args behind a couple of accessor functions.


# 1.49 10-Jun-2021 nicm

Do not use NULL client when source-file finishes, GitHub issue 2707.


Revision tags: OPENBSD_6_8_BASE OPENBSD_6_9_BASE
# 1.48 01-Sep-2020 nicm

Add -F to set-environment and source-file; GitHub issue 2359.


Revision tags: OPENBSD_6_7_BASE
# 1.47 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.46 13-Apr-2020 nicm

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


# 1.45 21-Dec-2019 tim

Restore source-file -q behaviour, broken in r1.42; OK nicm@


# 1.44 19-Dec-2019 nicm

When adding a list with multiple commands to the queue, the next item to
insert after needs to be the last one added, not the first. Reported by
Jason Kim in GitHub issue 2023.


# 1.43 18-Dec-2019 nicm

Do not rely on errno after glob(3) fails.


# 1.42 12-Dec-2019 nicm

Change source-file to use new file code which allows it to read from
stdin.


Revision tags: OPENBSD_6_6_BASE
# 1.41 05-Jun-2019 nicm

Add a -v flag to source-file to show the commands and line numbers.


# 1.40 28-May-2019 nicm

Exit 1 correctly if source-file fails.


# 1.39 28-May-2019 nicm

Allow source-file to take multiple arguments.


# 1.38 23-May-2019 nicm

Replace the split parser code (cfg.c and cmd-string.c) with a single
parser using yacc(1). This is a major change but is clearer and simpler
and allows some edge cases to be made more consistent, as well as
tidying up how aliases are handled. It will also allow some further
improvements later.

Entirely the same parser is now used for parsing the configuration file
and for string commands. This means that constructs previously only
available in .tmux.conf, such as %if, can now be used in string commands
(for example, those given to if-shell - not commands invoked from the
shell, they are still parsed by the shell itself).

The only syntax change I am aware of is that #{} outside quotes or a
comment is now considered a format and not a comment, so #{ is now a
syntax error (notably, if it is at the start of a line).

This also adds two new sections to the man page documenting the syntax
and outlining how parsing and command execution works.

Thanks to everyone who sent me test configs (they still all parse
without errors - but this doesn't mean they still work as intended!).

Thanks to Avi Halachmi for testing and man page improvements, also to
jmc@ for reviewing the man page changes.


# 1.37 20-May-2019 nicm

Fix ordering of source-file with multiple files and add flags to load_cfg.


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.36 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_2_BASE OPENBSD_6_3_BASE
# 1.35 19-Apr-2017 nicm

load_cfg returns < 0 on error, not != 0. Problem reported by Kaushal Modi.


Revision tags: OPENBSD_6_1_BASE
# 1.34 14-Feb-2017 nicm

Make source-file look for files relative to the client working directory
(like load-buffer and save-buffer), from Chris Pickel. Also break the
where-is-this-file code out into its own function for loadb and saveb.


# 1.33 29-Jan-2017 nicm

Add -n to break-pane.


# 1.32 09-Jan-2017 nicm

source-file -q needs to apply to glob(3) too.


# 1.31 09-Jan-2017 nicm

Run the source-file pattern through glob(3).


# 1.30 16-Oct-2016 nicm

Mass rename struct cmd_q to struct cmdq_item and related.


# 1.29 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.28 14-Oct-2016 nicm

source-file and some other commands can recurse back into cmdq_continue,
which could potentially free the currently running command, so we need
to take a reference to it in cmdq_continue_one.

Fixes problem reported by Theo Buehler.


# 1.27 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.26 10-Oct-2016 nicm

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


Revision tags: OPENBSD_6_0_BASE
# 1.25 12-May-2016 tim

- Rework load_cfg() error handling a little.
- Add -q to source-file to suppress errors about nonexistent files.

Input and OK nicm@


# 1.24 29-Apr-2016 nicm

Final parts of command hooks, add before- and after- hooks to each command.


Revision tags: OPENBSD_5_9_BASE
# 1.23 13-Dec-2015 nicm

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


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


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.21 27-Oct-2014 nicm

Move cfg_causes local into cfg.c and remove struct causelist.


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


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.19 10-Oct-2013 nicm

Make cmdq->client_exit a tristate (-1 means "not set") so that if
explicitly set it can be copied from child to parent cmdq by if-shell
and source-file. This fixes using attach or new. From Chris Johnsen.


# 1.18 10-Oct-2013 nicm

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


Revision tags: OPENBSD_5_4_BASE
# 1.17 12-Apr-2013 nicm

Copy the client into the new cmdq in source-file so commands that work
on it (such as new-session) can work. Fixes issue reported by oss-adv at
users dot sf dot net.


# 1.16 25-Mar-2013 nicm

Continue the parent cmdq after sourcing a file.


# 1.15 24-Mar-2013 nicm

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

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

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

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


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

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


Revision tags: OPENBSD_5_2_BASE
# 1.13 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.12 10-Jul-2012 nicm

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


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.11 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.10 29-Dec-2010 nicm

Allow the config file parser and source-file to return "don't exit" to
the client to let attach work from configuration files.


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE
# 1.9 06-Feb-2010 nicm

Use the array.h code for the causes list.


# 1.8 06-Feb-2010 nicm

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


# 1.7 26-Nov-2009 nicm

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


# 1.6 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.5 21-Sep-2009 nicm

Use KEYC_NONE constant instead of 0 on init.


# 1.4 23-Aug-2009 nicm

When using source-file, run the commands in the context of the source-file
command rather than with no context. This makes things like attach work from a
file.


# 1.3 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.2 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.


Revision tags: OPENBSD_4_6_BASE
# 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.49 10-Jun-2021 nicm

Do not use NULL client when source-file finishes, GitHub issue 2707.


Revision tags: OPENBSD_6_8_BASE OPENBSD_6_9_BASE
# 1.48 01-Sep-2020 nicm

Add -F to set-environment and source-file; GitHub issue 2359.


Revision tags: OPENBSD_6_7_BASE
# 1.47 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.46 13-Apr-2020 nicm

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


# 1.45 21-Dec-2019 tim

Restore source-file -q behaviour, broken in r1.42; OK nicm@


# 1.44 19-Dec-2019 nicm

When adding a list with multiple commands to the queue, the next item to
insert after needs to be the last one added, not the first. Reported by
Jason Kim in GitHub issue 2023.


# 1.43 18-Dec-2019 nicm

Do not rely on errno after glob(3) fails.


# 1.42 12-Dec-2019 nicm

Change source-file to use new file code which allows it to read from
stdin.


Revision tags: OPENBSD_6_6_BASE
# 1.41 05-Jun-2019 nicm

Add a -v flag to source-file to show the commands and line numbers.


# 1.40 28-May-2019 nicm

Exit 1 correctly if source-file fails.


# 1.39 28-May-2019 nicm

Allow source-file to take multiple arguments.


# 1.38 23-May-2019 nicm

Replace the split parser code (cfg.c and cmd-string.c) with a single
parser using yacc(1). This is a major change but is clearer and simpler
and allows some edge cases to be made more consistent, as well as
tidying up how aliases are handled. It will also allow some further
improvements later.

Entirely the same parser is now used for parsing the configuration file
and for string commands. This means that constructs previously only
available in .tmux.conf, such as %if, can now be used in string commands
(for example, those given to if-shell - not commands invoked from the
shell, they are still parsed by the shell itself).

The only syntax change I am aware of is that #{} outside quotes or a
comment is now considered a format and not a comment, so #{ is now a
syntax error (notably, if it is at the start of a line).

This also adds two new sections to the man page documenting the syntax
and outlining how parsing and command execution works.

Thanks to everyone who sent me test configs (they still all parse
without errors - but this doesn't mean they still work as intended!).

Thanks to Avi Halachmi for testing and man page improvements, also to
jmc@ for reviewing the man page changes.


# 1.37 20-May-2019 nicm

Fix ordering of source-file with multiple files and add flags to load_cfg.


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.36 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_2_BASE OPENBSD_6_3_BASE
# 1.35 19-Apr-2017 nicm

load_cfg returns < 0 on error, not != 0. Problem reported by Kaushal Modi.


Revision tags: OPENBSD_6_1_BASE
# 1.34 14-Feb-2017 nicm

Make source-file look for files relative to the client working directory
(like load-buffer and save-buffer), from Chris Pickel. Also break the
where-is-this-file code out into its own function for loadb and saveb.


# 1.33 29-Jan-2017 nicm

Add -n to break-pane.


# 1.32 09-Jan-2017 nicm

source-file -q needs to apply to glob(3) too.


# 1.31 09-Jan-2017 nicm

Run the source-file pattern through glob(3).


# 1.30 16-Oct-2016 nicm

Mass rename struct cmd_q to struct cmdq_item and related.


# 1.29 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.28 14-Oct-2016 nicm

source-file and some other commands can recurse back into cmdq_continue,
which could potentially free the currently running command, so we need
to take a reference to it in cmdq_continue_one.

Fixes problem reported by Theo Buehler.


# 1.27 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.26 10-Oct-2016 nicm

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


Revision tags: OPENBSD_6_0_BASE
# 1.25 12-May-2016 tim

- Rework load_cfg() error handling a little.
- Add -q to source-file to suppress errors about nonexistent files.

Input and OK nicm@


# 1.24 29-Apr-2016 nicm

Final parts of command hooks, add before- and after- hooks to each command.


Revision tags: OPENBSD_5_9_BASE
# 1.23 13-Dec-2015 nicm

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


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


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.21 27-Oct-2014 nicm

Move cfg_causes local into cfg.c and remove struct causelist.


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


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.19 10-Oct-2013 nicm

Make cmdq->client_exit a tristate (-1 means "not set") so that if
explicitly set it can be copied from child to parent cmdq by if-shell
and source-file. This fixes using attach or new. From Chris Johnsen.


# 1.18 10-Oct-2013 nicm

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


Revision tags: OPENBSD_5_4_BASE
# 1.17 12-Apr-2013 nicm

Copy the client into the new cmdq in source-file so commands that work
on it (such as new-session) can work. Fixes issue reported by oss-adv at
users dot sf dot net.


# 1.16 25-Mar-2013 nicm

Continue the parent cmdq after sourcing a file.


# 1.15 24-Mar-2013 nicm

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

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

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

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


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

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


Revision tags: OPENBSD_5_2_BASE
# 1.13 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.12 10-Jul-2012 nicm

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


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.11 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.10 29-Dec-2010 nicm

Allow the config file parser and source-file to return "don't exit" to
the client to let attach work from configuration files.


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE
# 1.9 06-Feb-2010 nicm

Use the array.h code for the causes list.


# 1.8 06-Feb-2010 nicm

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


# 1.7 26-Nov-2009 nicm

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


# 1.6 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.5 21-Sep-2009 nicm

Use KEYC_NONE constant instead of 0 on init.


# 1.4 23-Aug-2009 nicm

When using source-file, run the commands in the context of the source-file
command rather than with no context. This makes things like attach work from a
file.


# 1.3 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.2 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.


Revision tags: OPENBSD_4_6_BASE
# 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.48 01-Sep-2020 nicm

Add -F to set-environment and source-file; GitHub issue 2359.


Revision tags: OPENBSD_6_7_BASE
# 1.47 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.46 13-Apr-2020 nicm

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


# 1.45 21-Dec-2019 tim

Restore source-file -q behaviour, broken in r1.42; OK nicm@


# 1.44 19-Dec-2019 nicm

When adding a list with multiple commands to the queue, the next item to
insert after needs to be the last one added, not the first. Reported by
Jason Kim in GitHub issue 2023.


# 1.43 18-Dec-2019 nicm

Do not rely on errno after glob(3) fails.


# 1.42 12-Dec-2019 nicm

Change source-file to use new file code which allows it to read from
stdin.


Revision tags: OPENBSD_6_6_BASE
# 1.41 05-Jun-2019 nicm

Add a -v flag to source-file to show the commands and line numbers.


# 1.40 28-May-2019 nicm

Exit 1 correctly if source-file fails.


# 1.39 28-May-2019 nicm

Allow source-file to take multiple arguments.


# 1.38 23-May-2019 nicm

Replace the split parser code (cfg.c and cmd-string.c) with a single
parser using yacc(1). This is a major change but is clearer and simpler
and allows some edge cases to be made more consistent, as well as
tidying up how aliases are handled. It will also allow some further
improvements later.

Entirely the same parser is now used for parsing the configuration file
and for string commands. This means that constructs previously only
available in .tmux.conf, such as %if, can now be used in string commands
(for example, those given to if-shell - not commands invoked from the
shell, they are still parsed by the shell itself).

The only syntax change I am aware of is that #{} outside quotes or a
comment is now considered a format and not a comment, so #{ is now a
syntax error (notably, if it is at the start of a line).

This also adds two new sections to the man page documenting the syntax
and outlining how parsing and command execution works.

Thanks to everyone who sent me test configs (they still all parse
without errors - but this doesn't mean they still work as intended!).

Thanks to Avi Halachmi for testing and man page improvements, also to
jmc@ for reviewing the man page changes.


# 1.37 20-May-2019 nicm

Fix ordering of source-file with multiple files and add flags to load_cfg.


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.36 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_2_BASE OPENBSD_6_3_BASE
# 1.35 19-Apr-2017 nicm

load_cfg returns < 0 on error, not != 0. Problem reported by Kaushal Modi.


Revision tags: OPENBSD_6_1_BASE
# 1.34 14-Feb-2017 nicm

Make source-file look for files relative to the client working directory
(like load-buffer and save-buffer), from Chris Pickel. Also break the
where-is-this-file code out into its own function for loadb and saveb.


# 1.33 29-Jan-2017 nicm

Add -n to break-pane.


# 1.32 09-Jan-2017 nicm

source-file -q needs to apply to glob(3) too.


# 1.31 09-Jan-2017 nicm

Run the source-file pattern through glob(3).


# 1.30 16-Oct-2016 nicm

Mass rename struct cmd_q to struct cmdq_item and related.


# 1.29 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.28 14-Oct-2016 nicm

source-file and some other commands can recurse back into cmdq_continue,
which could potentially free the currently running command, so we need
to take a reference to it in cmdq_continue_one.

Fixes problem reported by Theo Buehler.


# 1.27 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.26 10-Oct-2016 nicm

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


Revision tags: OPENBSD_6_0_BASE
# 1.25 12-May-2016 tim

- Rework load_cfg() error handling a little.
- Add -q to source-file to suppress errors about nonexistent files.

Input and OK nicm@


# 1.24 29-Apr-2016 nicm

Final parts of command hooks, add before- and after- hooks to each command.


Revision tags: OPENBSD_5_9_BASE
# 1.23 13-Dec-2015 nicm

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


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


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.21 27-Oct-2014 nicm

Move cfg_causes local into cfg.c and remove struct causelist.


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


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.19 10-Oct-2013 nicm

Make cmdq->client_exit a tristate (-1 means "not set") so that if
explicitly set it can be copied from child to parent cmdq by if-shell
and source-file. This fixes using attach or new. From Chris Johnsen.


# 1.18 10-Oct-2013 nicm

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


Revision tags: OPENBSD_5_4_BASE
# 1.17 12-Apr-2013 nicm

Copy the client into the new cmdq in source-file so commands that work
on it (such as new-session) can work. Fixes issue reported by oss-adv at
users dot sf dot net.


# 1.16 25-Mar-2013 nicm

Continue the parent cmdq after sourcing a file.


# 1.15 24-Mar-2013 nicm

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

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

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

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


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

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


Revision tags: OPENBSD_5_2_BASE
# 1.13 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.12 10-Jul-2012 nicm

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


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.11 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.10 29-Dec-2010 nicm

Allow the config file parser and source-file to return "don't exit" to
the client to let attach work from configuration files.


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE
# 1.9 06-Feb-2010 nicm

Use the array.h code for the causes list.


# 1.8 06-Feb-2010 nicm

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


# 1.7 26-Nov-2009 nicm

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


# 1.6 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.5 21-Sep-2009 nicm

Use KEYC_NONE constant instead of 0 on init.


# 1.4 23-Aug-2009 nicm

When using source-file, run the commands in the context of the source-file
command rather than with no context. This makes things like attach work from a
file.


# 1.3 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.2 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.


Revision tags: OPENBSD_4_6_BASE
# 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.47 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.46 13-Apr-2020 nicm

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


# 1.45 21-Dec-2019 tim

Restore source-file -q behaviour, broken in r1.42; OK nicm@


# 1.44 19-Dec-2019 nicm

When adding a list with multiple commands to the queue, the next item to
insert after needs to be the last one added, not the first. Reported by
Jason Kim in GitHub issue 2023.


# 1.43 18-Dec-2019 nicm

Do not rely on errno after glob(3) fails.


# 1.42 12-Dec-2019 nicm

Change source-file to use new file code which allows it to read from
stdin.


Revision tags: OPENBSD_6_6_BASE
# 1.41 05-Jun-2019 nicm

Add a -v flag to source-file to show the commands and line numbers.


# 1.40 28-May-2019 nicm

Exit 1 correctly if source-file fails.


# 1.39 28-May-2019 nicm

Allow source-file to take multiple arguments.


# 1.38 23-May-2019 nicm

Replace the split parser code (cfg.c and cmd-string.c) with a single
parser using yacc(1). This is a major change but is clearer and simpler
and allows some edge cases to be made more consistent, as well as
tidying up how aliases are handled. It will also allow some further
improvements later.

Entirely the same parser is now used for parsing the configuration file
and for string commands. This means that constructs previously only
available in .tmux.conf, such as %if, can now be used in string commands
(for example, those given to if-shell - not commands invoked from the
shell, they are still parsed by the shell itself).

The only syntax change I am aware of is that #{} outside quotes or a
comment is now considered a format and not a comment, so #{ is now a
syntax error (notably, if it is at the start of a line).

This also adds two new sections to the man page documenting the syntax
and outlining how parsing and command execution works.

Thanks to everyone who sent me test configs (they still all parse
without errors - but this doesn't mean they still work as intended!).

Thanks to Avi Halachmi for testing and man page improvements, also to
jmc@ for reviewing the man page changes.


# 1.37 20-May-2019 nicm

Fix ordering of source-file with multiple files and add flags to load_cfg.


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.36 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_2_BASE OPENBSD_6_3_BASE
# 1.35 19-Apr-2017 nicm

load_cfg returns < 0 on error, not != 0. Problem reported by Kaushal Modi.


Revision tags: OPENBSD_6_1_BASE
# 1.34 14-Feb-2017 nicm

Make source-file look for files relative to the client working directory
(like load-buffer and save-buffer), from Chris Pickel. Also break the
where-is-this-file code out into its own function for loadb and saveb.


# 1.33 29-Jan-2017 nicm

Add -n to break-pane.


# 1.32 09-Jan-2017 nicm

source-file -q needs to apply to glob(3) too.


# 1.31 09-Jan-2017 nicm

Run the source-file pattern through glob(3).


# 1.30 16-Oct-2016 nicm

Mass rename struct cmd_q to struct cmdq_item and related.


# 1.29 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.28 14-Oct-2016 nicm

source-file and some other commands can recurse back into cmdq_continue,
which could potentially free the currently running command, so we need
to take a reference to it in cmdq_continue_one.

Fixes problem reported by Theo Buehler.


# 1.27 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.26 10-Oct-2016 nicm

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


Revision tags: OPENBSD_6_0_BASE
# 1.25 12-May-2016 tim

- Rework load_cfg() error handling a little.
- Add -q to source-file to suppress errors about nonexistent files.

Input and OK nicm@


# 1.24 29-Apr-2016 nicm

Final parts of command hooks, add before- and after- hooks to each command.


Revision tags: OPENBSD_5_9_BASE
# 1.23 13-Dec-2015 nicm

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


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


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.21 27-Oct-2014 nicm

Move cfg_causes local into cfg.c and remove struct causelist.


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


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.19 10-Oct-2013 nicm

Make cmdq->client_exit a tristate (-1 means "not set") so that if
explicitly set it can be copied from child to parent cmdq by if-shell
and source-file. This fixes using attach or new. From Chris Johnsen.


# 1.18 10-Oct-2013 nicm

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


Revision tags: OPENBSD_5_4_BASE
# 1.17 12-Apr-2013 nicm

Copy the client into the new cmdq in source-file so commands that work
on it (such as new-session) can work. Fixes issue reported by oss-adv at
users dot sf dot net.


# 1.16 25-Mar-2013 nicm

Continue the parent cmdq after sourcing a file.


# 1.15 24-Mar-2013 nicm

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

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

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

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


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

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


Revision tags: OPENBSD_5_2_BASE
# 1.13 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.12 10-Jul-2012 nicm

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


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.11 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.10 29-Dec-2010 nicm

Allow the config file parser and source-file to return "don't exit" to
the client to let attach work from configuration files.


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE
# 1.9 06-Feb-2010 nicm

Use the array.h code for the causes list.


# 1.8 06-Feb-2010 nicm

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


# 1.7 26-Nov-2009 nicm

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


# 1.6 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.5 21-Sep-2009 nicm

Use KEYC_NONE constant instead of 0 on init.


# 1.4 23-Aug-2009 nicm

When using source-file, run the commands in the context of the source-file
command rather than with no context. This makes things like attach work from a
file.


# 1.3 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.2 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.


Revision tags: OPENBSD_4_6_BASE
# 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.45 21-Dec-2019 tim

Restore source-file -q behaviour, broken in r1.42; OK nicm@


# 1.44 19-Dec-2019 nicm

When adding a list with multiple commands to the queue, the next item to
insert after needs to be the last one added, not the first. Reported by
Jason Kim in GitHub issue 2023.


# 1.43 18-Dec-2019 nicm

Do not rely on errno after glob(3) fails.


# 1.42 12-Dec-2019 nicm

Change source-file to use new file code which allows it to read from
stdin.


Revision tags: OPENBSD_6_6_BASE
# 1.41 05-Jun-2019 nicm

Add a -v flag to source-file to show the commands and line numbers.


# 1.40 28-May-2019 nicm

Exit 1 correctly if source-file fails.


# 1.39 28-May-2019 nicm

Allow source-file to take multiple arguments.


# 1.38 23-May-2019 nicm

Replace the split parser code (cfg.c and cmd-string.c) with a single
parser using yacc(1). This is a major change but is clearer and simpler
and allows some edge cases to be made more consistent, as well as
tidying up how aliases are handled. It will also allow some further
improvements later.

Entirely the same parser is now used for parsing the configuration file
and for string commands. This means that constructs previously only
available in .tmux.conf, such as %if, can now be used in string commands
(for example, those given to if-shell - not commands invoked from the
shell, they are still parsed by the shell itself).

The only syntax change I am aware of is that #{} outside quotes or a
comment is now considered a format and not a comment, so #{ is now a
syntax error (notably, if it is at the start of a line).

This also adds two new sections to the man page documenting the syntax
and outlining how parsing and command execution works.

Thanks to everyone who sent me test configs (they still all parse
without errors - but this doesn't mean they still work as intended!).

Thanks to Avi Halachmi for testing and man page improvements, also to
jmc@ for reviewing the man page changes.


# 1.37 20-May-2019 nicm

Fix ordering of source-file with multiple files and add flags to load_cfg.


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.36 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_2_BASE OPENBSD_6_3_BASE
# 1.35 19-Apr-2017 nicm

load_cfg returns < 0 on error, not != 0. Problem reported by Kaushal Modi.


Revision tags: OPENBSD_6_1_BASE
# 1.34 14-Feb-2017 nicm

Make source-file look for files relative to the client working directory
(like load-buffer and save-buffer), from Chris Pickel. Also break the
where-is-this-file code out into its own function for loadb and saveb.


# 1.33 29-Jan-2017 nicm

Add -n to break-pane.


# 1.32 09-Jan-2017 nicm

source-file -q needs to apply to glob(3) too.


# 1.31 09-Jan-2017 nicm

Run the source-file pattern through glob(3).


# 1.30 16-Oct-2016 nicm

Mass rename struct cmd_q to struct cmdq_item and related.


# 1.29 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.28 14-Oct-2016 nicm

source-file and some other commands can recurse back into cmdq_continue,
which could potentially free the currently running command, so we need
to take a reference to it in cmdq_continue_one.

Fixes problem reported by Theo Buehler.


# 1.27 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.26 10-Oct-2016 nicm

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


Revision tags: OPENBSD_6_0_BASE
# 1.25 12-May-2016 tim

- Rework load_cfg() error handling a little.
- Add -q to source-file to suppress errors about nonexistent files.

Input and OK nicm@


# 1.24 29-Apr-2016 nicm

Final parts of command hooks, add before- and after- hooks to each command.


Revision tags: OPENBSD_5_9_BASE
# 1.23 13-Dec-2015 nicm

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


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


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.21 27-Oct-2014 nicm

Move cfg_causes local into cfg.c and remove struct causelist.


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


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.19 10-Oct-2013 nicm

Make cmdq->client_exit a tristate (-1 means "not set") so that if
explicitly set it can be copied from child to parent cmdq by if-shell
and source-file. This fixes using attach or new. From Chris Johnsen.


# 1.18 10-Oct-2013 nicm

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


Revision tags: OPENBSD_5_4_BASE
# 1.17 12-Apr-2013 nicm

Copy the client into the new cmdq in source-file so commands that work
on it (such as new-session) can work. Fixes issue reported by oss-adv at
users dot sf dot net.


# 1.16 25-Mar-2013 nicm

Continue the parent cmdq after sourcing a file.


# 1.15 24-Mar-2013 nicm

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

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

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

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


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

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


Revision tags: OPENBSD_5_2_BASE
# 1.13 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.12 10-Jul-2012 nicm

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


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.11 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.10 29-Dec-2010 nicm

Allow the config file parser and source-file to return "don't exit" to
the client to let attach work from configuration files.


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE
# 1.9 06-Feb-2010 nicm

Use the array.h code for the causes list.


# 1.8 06-Feb-2010 nicm

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


# 1.7 26-Nov-2009 nicm

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


# 1.6 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.5 21-Sep-2009 nicm

Use KEYC_NONE constant instead of 0 on init.


# 1.4 23-Aug-2009 nicm

When using source-file, run the commands in the context of the source-file
command rather than with no context. This makes things like attach work from a
file.


# 1.3 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.2 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.


Revision tags: OPENBSD_4_6_BASE
# 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.44 19-Dec-2019 nicm

When adding a list with multiple commands to the queue, the next item to
insert after needs to be the last one added, not the first. Reported by
Jason Kim in GitHub issue 2023.


# 1.43 18-Dec-2019 nicm

Do not rely on errno after glob(3) fails.


# 1.42 12-Dec-2019 nicm

Change source-file to use new file code which allows it to read from
stdin.


Revision tags: OPENBSD_6_6_BASE
# 1.41 05-Jun-2019 nicm

Add a -v flag to source-file to show the commands and line numbers.


# 1.40 28-May-2019 nicm

Exit 1 correctly if source-file fails.


# 1.39 28-May-2019 nicm

Allow source-file to take multiple arguments.


# 1.38 23-May-2019 nicm

Replace the split parser code (cfg.c and cmd-string.c) with a single
parser using yacc(1). This is a major change but is clearer and simpler
and allows some edge cases to be made more consistent, as well as
tidying up how aliases are handled. It will also allow some further
improvements later.

Entirely the same parser is now used for parsing the configuration file
and for string commands. This means that constructs previously only
available in .tmux.conf, such as %if, can now be used in string commands
(for example, those given to if-shell - not commands invoked from the
shell, they are still parsed by the shell itself).

The only syntax change I am aware of is that #{} outside quotes or a
comment is now considered a format and not a comment, so #{ is now a
syntax error (notably, if it is at the start of a line).

This also adds two new sections to the man page documenting the syntax
and outlining how parsing and command execution works.

Thanks to everyone who sent me test configs (they still all parse
without errors - but this doesn't mean they still work as intended!).

Thanks to Avi Halachmi for testing and man page improvements, also to
jmc@ for reviewing the man page changes.


# 1.37 20-May-2019 nicm

Fix ordering of source-file with multiple files and add flags to load_cfg.


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.36 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_2_BASE OPENBSD_6_3_BASE
# 1.35 19-Apr-2017 nicm

load_cfg returns < 0 on error, not != 0. Problem reported by Kaushal Modi.


Revision tags: OPENBSD_6_1_BASE
# 1.34 14-Feb-2017 nicm

Make source-file look for files relative to the client working directory
(like load-buffer and save-buffer), from Chris Pickel. Also break the
where-is-this-file code out into its own function for loadb and saveb.


# 1.33 29-Jan-2017 nicm

Add -n to break-pane.


# 1.32 09-Jan-2017 nicm

source-file -q needs to apply to glob(3) too.


# 1.31 09-Jan-2017 nicm

Run the source-file pattern through glob(3).


# 1.30 16-Oct-2016 nicm

Mass rename struct cmd_q to struct cmdq_item and related.


# 1.29 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.28 14-Oct-2016 nicm

source-file and some other commands can recurse back into cmdq_continue,
which could potentially free the currently running command, so we need
to take a reference to it in cmdq_continue_one.

Fixes problem reported by Theo Buehler.


# 1.27 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.26 10-Oct-2016 nicm

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


Revision tags: OPENBSD_6_0_BASE
# 1.25 12-May-2016 tim

- Rework load_cfg() error handling a little.
- Add -q to source-file to suppress errors about nonexistent files.

Input and OK nicm@


# 1.24 29-Apr-2016 nicm

Final parts of command hooks, add before- and after- hooks to each command.


Revision tags: OPENBSD_5_9_BASE
# 1.23 13-Dec-2015 nicm

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


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


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.21 27-Oct-2014 nicm

Move cfg_causes local into cfg.c and remove struct causelist.


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


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.19 10-Oct-2013 nicm

Make cmdq->client_exit a tristate (-1 means "not set") so that if
explicitly set it can be copied from child to parent cmdq by if-shell
and source-file. This fixes using attach or new. From Chris Johnsen.


# 1.18 10-Oct-2013 nicm

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


Revision tags: OPENBSD_5_4_BASE
# 1.17 12-Apr-2013 nicm

Copy the client into the new cmdq in source-file so commands that work
on it (such as new-session) can work. Fixes issue reported by oss-adv at
users dot sf dot net.


# 1.16 25-Mar-2013 nicm

Continue the parent cmdq after sourcing a file.


# 1.15 24-Mar-2013 nicm

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

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

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

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


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

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


Revision tags: OPENBSD_5_2_BASE
# 1.13 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.12 10-Jul-2012 nicm

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


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.11 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.10 29-Dec-2010 nicm

Allow the config file parser and source-file to return "don't exit" to
the client to let attach work from configuration files.


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE
# 1.9 06-Feb-2010 nicm

Use the array.h code for the causes list.


# 1.8 06-Feb-2010 nicm

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


# 1.7 26-Nov-2009 nicm

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


# 1.6 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.5 21-Sep-2009 nicm

Use KEYC_NONE constant instead of 0 on init.


# 1.4 23-Aug-2009 nicm

When using source-file, run the commands in the context of the source-file
command rather than with no context. This makes things like attach work from a
file.


# 1.3 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.2 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.


Revision tags: OPENBSD_4_6_BASE
# 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.43 18-Dec-2019 nicm

Do not rely on errno after glob(3) fails.


# 1.42 12-Dec-2019 nicm

Change source-file to use new file code which allows it to read from
stdin.


Revision tags: OPENBSD_6_6_BASE
# 1.41 05-Jun-2019 nicm

Add a -v flag to source-file to show the commands and line numbers.


# 1.40 28-May-2019 nicm

Exit 1 correctly if source-file fails.


# 1.39 28-May-2019 nicm

Allow source-file to take multiple arguments.


# 1.38 23-May-2019 nicm

Replace the split parser code (cfg.c and cmd-string.c) with a single
parser using yacc(1). This is a major change but is clearer and simpler
and allows some edge cases to be made more consistent, as well as
tidying up how aliases are handled. It will also allow some further
improvements later.

Entirely the same parser is now used for parsing the configuration file
and for string commands. This means that constructs previously only
available in .tmux.conf, such as %if, can now be used in string commands
(for example, those given to if-shell - not commands invoked from the
shell, they are still parsed by the shell itself).

The only syntax change I am aware of is that #{} outside quotes or a
comment is now considered a format and not a comment, so #{ is now a
syntax error (notably, if it is at the start of a line).

This also adds two new sections to the man page documenting the syntax
and outlining how parsing and command execution works.

Thanks to everyone who sent me test configs (they still all parse
without errors - but this doesn't mean they still work as intended!).

Thanks to Avi Halachmi for testing and man page improvements, also to
jmc@ for reviewing the man page changes.


# 1.37 20-May-2019 nicm

Fix ordering of source-file with multiple files and add flags to load_cfg.


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.36 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_2_BASE OPENBSD_6_3_BASE
# 1.35 19-Apr-2017 nicm

load_cfg returns < 0 on error, not != 0. Problem reported by Kaushal Modi.


Revision tags: OPENBSD_6_1_BASE
# 1.34 14-Feb-2017 nicm

Make source-file look for files relative to the client working directory
(like load-buffer and save-buffer), from Chris Pickel. Also break the
where-is-this-file code out into its own function for loadb and saveb.


# 1.33 29-Jan-2017 nicm

Add -n to break-pane.


# 1.32 09-Jan-2017 nicm

source-file -q needs to apply to glob(3) too.


# 1.31 09-Jan-2017 nicm

Run the source-file pattern through glob(3).


# 1.30 16-Oct-2016 nicm

Mass rename struct cmd_q to struct cmdq_item and related.


# 1.29 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.28 14-Oct-2016 nicm

source-file and some other commands can recurse back into cmdq_continue,
which could potentially free the currently running command, so we need
to take a reference to it in cmdq_continue_one.

Fixes problem reported by Theo Buehler.


# 1.27 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.26 10-Oct-2016 nicm

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


Revision tags: OPENBSD_6_0_BASE
# 1.25 12-May-2016 tim

- Rework load_cfg() error handling a little.
- Add -q to source-file to suppress errors about nonexistent files.

Input and OK nicm@


# 1.24 29-Apr-2016 nicm

Final parts of command hooks, add before- and after- hooks to each command.


Revision tags: OPENBSD_5_9_BASE
# 1.23 13-Dec-2015 nicm

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


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


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.21 27-Oct-2014 nicm

Move cfg_causes local into cfg.c and remove struct causelist.


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


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.19 10-Oct-2013 nicm

Make cmdq->client_exit a tristate (-1 means "not set") so that if
explicitly set it can be copied from child to parent cmdq by if-shell
and source-file. This fixes using attach or new. From Chris Johnsen.


# 1.18 10-Oct-2013 nicm

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


Revision tags: OPENBSD_5_4_BASE
# 1.17 12-Apr-2013 nicm

Copy the client into the new cmdq in source-file so commands that work
on it (such as new-session) can work. Fixes issue reported by oss-adv at
users dot sf dot net.


# 1.16 25-Mar-2013 nicm

Continue the parent cmdq after sourcing a file.


# 1.15 24-Mar-2013 nicm

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

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

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

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


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

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


Revision tags: OPENBSD_5_2_BASE
# 1.13 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.12 10-Jul-2012 nicm

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


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.11 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.10 29-Dec-2010 nicm

Allow the config file parser and source-file to return "don't exit" to
the client to let attach work from configuration files.


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE
# 1.9 06-Feb-2010 nicm

Use the array.h code for the causes list.


# 1.8 06-Feb-2010 nicm

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


# 1.7 26-Nov-2009 nicm

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


# 1.6 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.5 21-Sep-2009 nicm

Use KEYC_NONE constant instead of 0 on init.


# 1.4 23-Aug-2009 nicm

When using source-file, run the commands in the context of the source-file
command rather than with no context. This makes things like attach work from a
file.


# 1.3 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.2 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.


Revision tags: OPENBSD_4_6_BASE
# 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.42 12-Dec-2019 nicm

Change source-file to use new file code which allows it to read from
stdin.


Revision tags: OPENBSD_6_6_BASE
# 1.41 05-Jun-2019 nicm

Add a -v flag to source-file to show the commands and line numbers.


# 1.40 28-May-2019 nicm

Exit 1 correctly if source-file fails.


# 1.39 28-May-2019 nicm

Allow source-file to take multiple arguments.


# 1.38 23-May-2019 nicm

Replace the split parser code (cfg.c and cmd-string.c) with a single
parser using yacc(1). This is a major change but is clearer and simpler
and allows some edge cases to be made more consistent, as well as
tidying up how aliases are handled. It will also allow some further
improvements later.

Entirely the same parser is now used for parsing the configuration file
and for string commands. This means that constructs previously only
available in .tmux.conf, such as %if, can now be used in string commands
(for example, those given to if-shell - not commands invoked from the
shell, they are still parsed by the shell itself).

The only syntax change I am aware of is that #{} outside quotes or a
comment is now considered a format and not a comment, so #{ is now a
syntax error (notably, if it is at the start of a line).

This also adds two new sections to the man page documenting the syntax
and outlining how parsing and command execution works.

Thanks to everyone who sent me test configs (they still all parse
without errors - but this doesn't mean they still work as intended!).

Thanks to Avi Halachmi for testing and man page improvements, also to
jmc@ for reviewing the man page changes.


# 1.37 20-May-2019 nicm

Fix ordering of source-file with multiple files and add flags to load_cfg.


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.36 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_2_BASE OPENBSD_6_3_BASE
# 1.35 19-Apr-2017 nicm

load_cfg returns < 0 on error, not != 0. Problem reported by Kaushal Modi.


Revision tags: OPENBSD_6_1_BASE
# 1.34 14-Feb-2017 nicm

Make source-file look for files relative to the client working directory
(like load-buffer and save-buffer), from Chris Pickel. Also break the
where-is-this-file code out into its own function for loadb and saveb.


# 1.33 29-Jan-2017 nicm

Add -n to break-pane.


# 1.32 09-Jan-2017 nicm

source-file -q needs to apply to glob(3) too.


# 1.31 09-Jan-2017 nicm

Run the source-file pattern through glob(3).


# 1.30 16-Oct-2016 nicm

Mass rename struct cmd_q to struct cmdq_item and related.


# 1.29 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.28 14-Oct-2016 nicm

source-file and some other commands can recurse back into cmdq_continue,
which could potentially free the currently running command, so we need
to take a reference to it in cmdq_continue_one.

Fixes problem reported by Theo Buehler.


# 1.27 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.26 10-Oct-2016 nicm

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


Revision tags: OPENBSD_6_0_BASE
# 1.25 12-May-2016 tim

- Rework load_cfg() error handling a little.
- Add -q to source-file to suppress errors about nonexistent files.

Input and OK nicm@


# 1.24 29-Apr-2016 nicm

Final parts of command hooks, add before- and after- hooks to each command.


Revision tags: OPENBSD_5_9_BASE
# 1.23 13-Dec-2015 nicm

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


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


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.21 27-Oct-2014 nicm

Move cfg_causes local into cfg.c and remove struct causelist.


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


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.19 10-Oct-2013 nicm

Make cmdq->client_exit a tristate (-1 means "not set") so that if
explicitly set it can be copied from child to parent cmdq by if-shell
and source-file. This fixes using attach or new. From Chris Johnsen.


# 1.18 10-Oct-2013 nicm

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


Revision tags: OPENBSD_5_4_BASE
# 1.17 12-Apr-2013 nicm

Copy the client into the new cmdq in source-file so commands that work
on it (such as new-session) can work. Fixes issue reported by oss-adv at
users dot sf dot net.


# 1.16 25-Mar-2013 nicm

Continue the parent cmdq after sourcing a file.


# 1.15 24-Mar-2013 nicm

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

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

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

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


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

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


Revision tags: OPENBSD_5_2_BASE
# 1.13 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.12 10-Jul-2012 nicm

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


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.11 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.10 29-Dec-2010 nicm

Allow the config file parser and source-file to return "don't exit" to
the client to let attach work from configuration files.


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE
# 1.9 06-Feb-2010 nicm

Use the array.h code for the causes list.


# 1.8 06-Feb-2010 nicm

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


# 1.7 26-Nov-2009 nicm

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


# 1.6 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.5 21-Sep-2009 nicm

Use KEYC_NONE constant instead of 0 on init.


# 1.4 23-Aug-2009 nicm

When using source-file, run the commands in the context of the source-file
command rather than with no context. This makes things like attach work from a
file.


# 1.3 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.2 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.


Revision tags: OPENBSD_4_6_BASE
# 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.41 05-Jun-2019 nicm

Add a -v flag to source-file to show the commands and line numbers.


# 1.40 28-May-2019 nicm

Exit 1 correctly if source-file fails.


# 1.39 28-May-2019 nicm

Allow source-file to take multiple arguments.


# 1.38 23-May-2019 nicm

Replace the split parser code (cfg.c and cmd-string.c) with a single
parser using yacc(1). This is a major change but is clearer and simpler
and allows some edge cases to be made more consistent, as well as
tidying up how aliases are handled. It will also allow some further
improvements later.

Entirely the same parser is now used for parsing the configuration file
and for string commands. This means that constructs previously only
available in .tmux.conf, such as %if, can now be used in string commands
(for example, those given to if-shell - not commands invoked from the
shell, they are still parsed by the shell itself).

The only syntax change I am aware of is that #{} outside quotes or a
comment is now considered a format and not a comment, so #{ is now a
syntax error (notably, if it is at the start of a line).

This also adds two new sections to the man page documenting the syntax
and outlining how parsing and command execution works.

Thanks to everyone who sent me test configs (they still all parse
without errors - but this doesn't mean they still work as intended!).

Thanks to Avi Halachmi for testing and man page improvements, also to
jmc@ for reviewing the man page changes.


# 1.37 20-May-2019 nicm

Fix ordering of source-file with multiple files and add flags to load_cfg.


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.36 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_2_BASE OPENBSD_6_3_BASE
# 1.35 19-Apr-2017 nicm

load_cfg returns < 0 on error, not != 0. Problem reported by Kaushal Modi.


Revision tags: OPENBSD_6_1_BASE
# 1.34 14-Feb-2017 nicm

Make source-file look for files relative to the client working directory
(like load-buffer and save-buffer), from Chris Pickel. Also break the
where-is-this-file code out into its own function for loadb and saveb.


# 1.33 29-Jan-2017 nicm

Add -n to break-pane.


# 1.32 09-Jan-2017 nicm

source-file -q needs to apply to glob(3) too.


# 1.31 09-Jan-2017 nicm

Run the source-file pattern through glob(3).


# 1.30 16-Oct-2016 nicm

Mass rename struct cmd_q to struct cmdq_item and related.


# 1.29 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.28 14-Oct-2016 nicm

source-file and some other commands can recurse back into cmdq_continue,
which could potentially free the currently running command, so we need
to take a reference to it in cmdq_continue_one.

Fixes problem reported by Theo Buehler.


# 1.27 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.26 10-Oct-2016 nicm

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


Revision tags: OPENBSD_6_0_BASE
# 1.25 12-May-2016 tim

- Rework load_cfg() error handling a little.
- Add -q to source-file to suppress errors about nonexistent files.

Input and OK nicm@


# 1.24 29-Apr-2016 nicm

Final parts of command hooks, add before- and after- hooks to each command.


Revision tags: OPENBSD_5_9_BASE
# 1.23 13-Dec-2015 nicm

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


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


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.21 27-Oct-2014 nicm

Move cfg_causes local into cfg.c and remove struct causelist.


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


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.19 10-Oct-2013 nicm

Make cmdq->client_exit a tristate (-1 means "not set") so that if
explicitly set it can be copied from child to parent cmdq by if-shell
and source-file. This fixes using attach or new. From Chris Johnsen.


# 1.18 10-Oct-2013 nicm

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


Revision tags: OPENBSD_5_4_BASE
# 1.17 12-Apr-2013 nicm

Copy the client into the new cmdq in source-file so commands that work
on it (such as new-session) can work. Fixes issue reported by oss-adv at
users dot sf dot net.


# 1.16 25-Mar-2013 nicm

Continue the parent cmdq after sourcing a file.


# 1.15 24-Mar-2013 nicm

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

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

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

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


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

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


Revision tags: OPENBSD_5_2_BASE
# 1.13 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.12 10-Jul-2012 nicm

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


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.11 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.10 29-Dec-2010 nicm

Allow the config file parser and source-file to return "don't exit" to
the client to let attach work from configuration files.


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE
# 1.9 06-Feb-2010 nicm

Use the array.h code for the causes list.


# 1.8 06-Feb-2010 nicm

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


# 1.7 26-Nov-2009 nicm

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


# 1.6 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.5 21-Sep-2009 nicm

Use KEYC_NONE constant instead of 0 on init.


# 1.4 23-Aug-2009 nicm

When using source-file, run the commands in the context of the source-file
command rather than with no context. This makes things like attach work from a
file.


# 1.3 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.2 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.


Revision tags: OPENBSD_4_6_BASE
# 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.40 28-May-2019 nicm

Exit 1 correctly if source-file fails.


# 1.39 28-May-2019 nicm

Allow source-file to take multiple arguments.


# 1.38 23-May-2019 nicm

Replace the split parser code (cfg.c and cmd-string.c) with a single
parser using yacc(1). This is a major change but is clearer and simpler
and allows some edge cases to be made more consistent, as well as
tidying up how aliases are handled. It will also allow some further
improvements later.

Entirely the same parser is now used for parsing the configuration file
and for string commands. This means that constructs previously only
available in .tmux.conf, such as %if, can now be used in string commands
(for example, those given to if-shell - not commands invoked from the
shell, they are still parsed by the shell itself).

The only syntax change I am aware of is that #{} outside quotes or a
comment is now considered a format and not a comment, so #{ is now a
syntax error (notably, if it is at the start of a line).

This also adds two new sections to the man page documenting the syntax
and outlining how parsing and command execution works.

Thanks to everyone who sent me test configs (they still all parse
without errors - but this doesn't mean they still work as intended!).

Thanks to Avi Halachmi for testing and man page improvements, also to
jmc@ for reviewing the man page changes.


# 1.37 20-May-2019 nicm

Fix ordering of source-file with multiple files and add flags to load_cfg.


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.36 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_2_BASE OPENBSD_6_3_BASE
# 1.35 19-Apr-2017 nicm

load_cfg returns < 0 on error, not != 0. Problem reported by Kaushal Modi.


Revision tags: OPENBSD_6_1_BASE
# 1.34 14-Feb-2017 nicm

Make source-file look for files relative to the client working directory
(like load-buffer and save-buffer), from Chris Pickel. Also break the
where-is-this-file code out into its own function for loadb and saveb.


# 1.33 29-Jan-2017 nicm

Add -n to break-pane.


# 1.32 09-Jan-2017 nicm

source-file -q needs to apply to glob(3) too.


# 1.31 09-Jan-2017 nicm

Run the source-file pattern through glob(3).


# 1.30 16-Oct-2016 nicm

Mass rename struct cmd_q to struct cmdq_item and related.


# 1.29 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.28 14-Oct-2016 nicm

source-file and some other commands can recurse back into cmdq_continue,
which could potentially free the currently running command, so we need
to take a reference to it in cmdq_continue_one.

Fixes problem reported by Theo Buehler.


# 1.27 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.26 10-Oct-2016 nicm

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


Revision tags: OPENBSD_6_0_BASE
# 1.25 12-May-2016 tim

- Rework load_cfg() error handling a little.
- Add -q to source-file to suppress errors about nonexistent files.

Input and OK nicm@


# 1.24 29-Apr-2016 nicm

Final parts of command hooks, add before- and after- hooks to each command.


Revision tags: OPENBSD_5_9_BASE
# 1.23 13-Dec-2015 nicm

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


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


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.21 27-Oct-2014 nicm

Move cfg_causes local into cfg.c and remove struct causelist.


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


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.19 10-Oct-2013 nicm

Make cmdq->client_exit a tristate (-1 means "not set") so that if
explicitly set it can be copied from child to parent cmdq by if-shell
and source-file. This fixes using attach or new. From Chris Johnsen.


# 1.18 10-Oct-2013 nicm

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


Revision tags: OPENBSD_5_4_BASE
# 1.17 12-Apr-2013 nicm

Copy the client into the new cmdq in source-file so commands that work
on it (such as new-session) can work. Fixes issue reported by oss-adv at
users dot sf dot net.


# 1.16 25-Mar-2013 nicm

Continue the parent cmdq after sourcing a file.


# 1.15 24-Mar-2013 nicm

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

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

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

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


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

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


Revision tags: OPENBSD_5_2_BASE
# 1.13 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.12 10-Jul-2012 nicm

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


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.11 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.10 29-Dec-2010 nicm

Allow the config file parser and source-file to return "don't exit" to
the client to let attach work from configuration files.


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE
# 1.9 06-Feb-2010 nicm

Use the array.h code for the causes list.


# 1.8 06-Feb-2010 nicm

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


# 1.7 26-Nov-2009 nicm

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


# 1.6 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.5 21-Sep-2009 nicm

Use KEYC_NONE constant instead of 0 on init.


# 1.4 23-Aug-2009 nicm

When using source-file, run the commands in the context of the source-file
command rather than with no context. This makes things like attach work from a
file.


# 1.3 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.2 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.


Revision tags: OPENBSD_4_6_BASE
# 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.38 23-May-2019 nicm

Replace the split parser code (cfg.c and cmd-string.c) with a single
parser using yacc(1). This is a major change but is clearer and simpler
and allows some edge cases to be made more consistent, as well as
tidying up how aliases are handled. It will also allow some further
improvements later.

Entirely the same parser is now used for parsing the configuration file
and for string commands. This means that constructs previously only
available in .tmux.conf, such as %if, can now be used in string commands
(for example, those given to if-shell - not commands invoked from the
shell, they are still parsed by the shell itself).

The only syntax change I am aware of is that #{} outside quotes or a
comment is now considered a format and not a comment, so #{ is now a
syntax error (notably, if it is at the start of a line).

This also adds two new sections to the man page documenting the syntax
and outlining how parsing and command execution works.

Thanks to everyone who sent me test configs (they still all parse
without errors - but this doesn't mean they still work as intended!).

Thanks to Avi Halachmi for testing and man page improvements, also to
jmc@ for reviewing the man page changes.


# 1.37 20-May-2019 nicm

Fix ordering of source-file with multiple files and add flags to load_cfg.


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.36 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_2_BASE OPENBSD_6_3_BASE
# 1.35 19-Apr-2017 nicm

load_cfg returns < 0 on error, not != 0. Problem reported by Kaushal Modi.


Revision tags: OPENBSD_6_1_BASE
# 1.34 14-Feb-2017 nicm

Make source-file look for files relative to the client working directory
(like load-buffer and save-buffer), from Chris Pickel. Also break the
where-is-this-file code out into its own function for loadb and saveb.


# 1.33 29-Jan-2017 nicm

Add -n to break-pane.


# 1.32 09-Jan-2017 nicm

source-file -q needs to apply to glob(3) too.


# 1.31 09-Jan-2017 nicm

Run the source-file pattern through glob(3).


# 1.30 16-Oct-2016 nicm

Mass rename struct cmd_q to struct cmdq_item and related.


# 1.29 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.28 14-Oct-2016 nicm

source-file and some other commands can recurse back into cmdq_continue,
which could potentially free the currently running command, so we need
to take a reference to it in cmdq_continue_one.

Fixes problem reported by Theo Buehler.


# 1.27 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.26 10-Oct-2016 nicm

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


Revision tags: OPENBSD_6_0_BASE
# 1.25 12-May-2016 tim

- Rework load_cfg() error handling a little.
- Add -q to source-file to suppress errors about nonexistent files.

Input and OK nicm@


# 1.24 29-Apr-2016 nicm

Final parts of command hooks, add before- and after- hooks to each command.


Revision tags: OPENBSD_5_9_BASE
# 1.23 13-Dec-2015 nicm

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


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


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.21 27-Oct-2014 nicm

Move cfg_causes local into cfg.c and remove struct causelist.


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


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.19 10-Oct-2013 nicm

Make cmdq->client_exit a tristate (-1 means "not set") so that if
explicitly set it can be copied from child to parent cmdq by if-shell
and source-file. This fixes using attach or new. From Chris Johnsen.


# 1.18 10-Oct-2013 nicm

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


Revision tags: OPENBSD_5_4_BASE
# 1.17 12-Apr-2013 nicm

Copy the client into the new cmdq in source-file so commands that work
on it (such as new-session) can work. Fixes issue reported by oss-adv at
users dot sf dot net.


# 1.16 25-Mar-2013 nicm

Continue the parent cmdq after sourcing a file.


# 1.15 24-Mar-2013 nicm

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

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

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

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


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

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


Revision tags: OPENBSD_5_2_BASE
# 1.13 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.12 10-Jul-2012 nicm

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


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.11 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.10 29-Dec-2010 nicm

Allow the config file parser and source-file to return "don't exit" to
the client to let attach work from configuration files.


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE
# 1.9 06-Feb-2010 nicm

Use the array.h code for the causes list.


# 1.8 06-Feb-2010 nicm

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


# 1.7 26-Nov-2009 nicm

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


# 1.6 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.5 21-Sep-2009 nicm

Use KEYC_NONE constant instead of 0 on init.


# 1.4 23-Aug-2009 nicm

When using source-file, run the commands in the context of the source-file
command rather than with no context. This makes things like attach work from a
file.


# 1.3 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.2 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.


Revision tags: OPENBSD_4_6_BASE
# 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.37 20-May-2019 nicm

Fix ordering of source-file with multiple files and add flags to load_cfg.


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.36 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_2_BASE OPENBSD_6_3_BASE
# 1.35 19-Apr-2017 nicm

load_cfg returns < 0 on error, not != 0. Problem reported by Kaushal Modi.


Revision tags: OPENBSD_6_1_BASE
# 1.34 14-Feb-2017 nicm

Make source-file look for files relative to the client working directory
(like load-buffer and save-buffer), from Chris Pickel. Also break the
where-is-this-file code out into its own function for loadb and saveb.


# 1.33 29-Jan-2017 nicm

Add -n to break-pane.


# 1.32 09-Jan-2017 nicm

source-file -q needs to apply to glob(3) too.


# 1.31 09-Jan-2017 nicm

Run the source-file pattern through glob(3).


# 1.30 16-Oct-2016 nicm

Mass rename struct cmd_q to struct cmdq_item and related.


# 1.29 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.28 14-Oct-2016 nicm

source-file and some other commands can recurse back into cmdq_continue,
which could potentially free the currently running command, so we need
to take a reference to it in cmdq_continue_one.

Fixes problem reported by Theo Buehler.


# 1.27 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.26 10-Oct-2016 nicm

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


Revision tags: OPENBSD_6_0_BASE
# 1.25 12-May-2016 tim

- Rework load_cfg() error handling a little.
- Add -q to source-file to suppress errors about nonexistent files.

Input and OK nicm@


# 1.24 29-Apr-2016 nicm

Final parts of command hooks, add before- and after- hooks to each command.


Revision tags: OPENBSD_5_9_BASE
# 1.23 13-Dec-2015 nicm

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


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


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.21 27-Oct-2014 nicm

Move cfg_causes local into cfg.c and remove struct causelist.


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


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.19 10-Oct-2013 nicm

Make cmdq->client_exit a tristate (-1 means "not set") so that if
explicitly set it can be copied from child to parent cmdq by if-shell
and source-file. This fixes using attach or new. From Chris Johnsen.


# 1.18 10-Oct-2013 nicm

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


Revision tags: OPENBSD_5_4_BASE
# 1.17 12-Apr-2013 nicm

Copy the client into the new cmdq in source-file so commands that work
on it (such as new-session) can work. Fixes issue reported by oss-adv at
users dot sf dot net.


# 1.16 25-Mar-2013 nicm

Continue the parent cmdq after sourcing a file.


# 1.15 24-Mar-2013 nicm

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

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

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

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


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

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


Revision tags: OPENBSD_5_2_BASE
# 1.13 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.12 10-Jul-2012 nicm

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


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.11 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.10 29-Dec-2010 nicm

Allow the config file parser and source-file to return "don't exit" to
the client to let attach work from configuration files.


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE
# 1.9 06-Feb-2010 nicm

Use the array.h code for the causes list.


# 1.8 06-Feb-2010 nicm

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


# 1.7 26-Nov-2009 nicm

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


# 1.6 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.5 21-Sep-2009 nicm

Use KEYC_NONE constant instead of 0 on init.


# 1.4 23-Aug-2009 nicm

When using source-file, run the commands in the context of the source-file
command rather than with no context. This makes things like attach work from a
file.


# 1.3 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.2 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.


Revision tags: OPENBSD_4_6_BASE
# 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.36 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_2_BASE OPENBSD_6_3_BASE
# 1.35 19-Apr-2017 nicm

load_cfg returns < 0 on error, not != 0. Problem reported by Kaushal Modi.


Revision tags: OPENBSD_6_1_BASE
# 1.34 14-Feb-2017 nicm

Make source-file look for files relative to the client working directory
(like load-buffer and save-buffer), from Chris Pickel. Also break the
where-is-this-file code out into its own function for loadb and saveb.


# 1.33 29-Jan-2017 nicm

Add -n to break-pane.


# 1.32 09-Jan-2017 nicm

source-file -q needs to apply to glob(3) too.


# 1.31 09-Jan-2017 nicm

Run the source-file pattern through glob(3).


# 1.30 16-Oct-2016 nicm

Mass rename struct cmd_q to struct cmdq_item and related.


# 1.29 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.28 14-Oct-2016 nicm

source-file and some other commands can recurse back into cmdq_continue,
which could potentially free the currently running command, so we need
to take a reference to it in cmdq_continue_one.

Fixes problem reported by Theo Buehler.


# 1.27 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.26 10-Oct-2016 nicm

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


Revision tags: OPENBSD_6_0_BASE
# 1.25 12-May-2016 tim

- Rework load_cfg() error handling a little.
- Add -q to source-file to suppress errors about nonexistent files.

Input and OK nicm@


# 1.24 29-Apr-2016 nicm

Final parts of command hooks, add before- and after- hooks to each command.


Revision tags: OPENBSD_5_9_BASE
# 1.23 13-Dec-2015 nicm

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


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


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.21 27-Oct-2014 nicm

Move cfg_causes local into cfg.c and remove struct causelist.


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


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.19 10-Oct-2013 nicm

Make cmdq->client_exit a tristate (-1 means "not set") so that if
explicitly set it can be copied from child to parent cmdq by if-shell
and source-file. This fixes using attach or new. From Chris Johnsen.


# 1.18 10-Oct-2013 nicm

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


Revision tags: OPENBSD_5_4_BASE
# 1.17 12-Apr-2013 nicm

Copy the client into the new cmdq in source-file so commands that work
on it (such as new-session) can work. Fixes issue reported by oss-adv at
users dot sf dot net.


# 1.16 25-Mar-2013 nicm

Continue the parent cmdq after sourcing a file.


# 1.15 24-Mar-2013 nicm

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

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

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

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


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

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


Revision tags: OPENBSD_5_2_BASE
# 1.13 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.12 10-Jul-2012 nicm

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


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.11 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.10 29-Dec-2010 nicm

Allow the config file parser and source-file to return "don't exit" to
the client to let attach work from configuration files.


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE
# 1.9 06-Feb-2010 nicm

Use the array.h code for the causes list.


# 1.8 06-Feb-2010 nicm

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


# 1.7 26-Nov-2009 nicm

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


# 1.6 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.5 21-Sep-2009 nicm

Use KEYC_NONE constant instead of 0 on init.


# 1.4 23-Aug-2009 nicm

When using source-file, run the commands in the context of the source-file
command rather than with no context. This makes things like attach work from a
file.


# 1.3 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.2 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.


Revision tags: OPENBSD_4_6_BASE
# 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.35 19-Apr-2017 nicm

load_cfg returns < 0 on error, not != 0. Problem reported by Kaushal Modi.


Revision tags: OPENBSD_6_1_BASE
# 1.34 14-Feb-2017 nicm

Make source-file look for files relative to the client working directory
(like load-buffer and save-buffer), from Chris Pickel. Also break the
where-is-this-file code out into its own function for loadb and saveb.


# 1.33 29-Jan-2017 nicm

Add -n to break-pane.


# 1.32 09-Jan-2017 nicm

source-file -q needs to apply to glob(3) too.


# 1.31 09-Jan-2017 nicm

Run the source-file pattern through glob(3).


# 1.30 16-Oct-2016 nicm

Mass rename struct cmd_q to struct cmdq_item and related.


# 1.29 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.28 14-Oct-2016 nicm

source-file and some other commands can recurse back into cmdq_continue,
which could potentially free the currently running command, so we need
to take a reference to it in cmdq_continue_one.

Fixes problem reported by Theo Buehler.


# 1.27 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.26 10-Oct-2016 nicm

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


Revision tags: OPENBSD_6_0_BASE
# 1.25 12-May-2016 tim

- Rework load_cfg() error handling a little.
- Add -q to source-file to suppress errors about nonexistent files.

Input and OK nicm@


# 1.24 29-Apr-2016 nicm

Final parts of command hooks, add before- and after- hooks to each command.


Revision tags: OPENBSD_5_9_BASE
# 1.23 13-Dec-2015 nicm

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


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


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE
# 1.21 27-Oct-2014 nicm

Move cfg_causes local into cfg.c and remove struct causelist.


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


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE
# 1.19 10-Oct-2013 nicm

Make cmdq->client_exit a tristate (-1 means "not set") so that if
explicitly set it can be copied from child to parent cmdq by if-shell
and source-file. This fixes using attach or new. From Chris Johnsen.


# 1.18 10-Oct-2013 nicm

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


Revision tags: OPENBSD_5_4_BASE
# 1.17 12-Apr-2013 nicm

Copy the client into the new cmdq in source-file so commands that work
on it (such as new-session) can work. Fixes issue reported by oss-adv at
users dot sf dot net.


# 1.16 25-Mar-2013 nicm

Continue the parent cmdq after sourcing a file.


# 1.15 24-Mar-2013 nicm

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

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

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

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


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

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


Revision tags: OPENBSD_5_2_BASE
# 1.13 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.12 10-Jul-2012 nicm

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


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.11 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.10 29-Dec-2010 nicm

Allow the config file parser and source-file to return "don't exit" to
the client to let attach work from configuration files.


Revision tags: OPENBSD_4_7_BASE OPENBSD_4_8_BASE
# 1.9 06-Feb-2010 nicm

Use the array.h code for the causes list.


# 1.8 06-Feb-2010 nicm

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


# 1.7 26-Nov-2009 nicm

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


# 1.6 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.5 21-Sep-2009 nicm

Use KEYC_NONE constant instead of 0 on init.


# 1.4 23-Aug-2009 nicm

When using source-file, run the commands in the context of the source-file
command rather than with no context. This makes things like attach work from a
file.


# 1.3 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.2 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.


Revision tags: OPENBSD_4_6_BASE
# 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