main/client: be POSIXLY_CORRECT when parsing command line

This means command line parsing stops when it encounters the first
nonoption argument.

The result is that one no longer need to use '--' to ensure arguments
are passed to the shell/command, instead of parsed by foot.

That is, instead of

  foot -- sh -c true

one can now do

  foot sh -c true

Arguments to foot *must* go before the command:

  foot --fullscreen sh -c true
This commit is contained in:
Daniel Eklöf 2020-05-08 18:43:03 +02:00
parent 56d53ec2a1
commit 5b70f94827
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
5 changed files with 15 additions and 12 deletions

View file

@ -43,6 +43,9 @@
* The four primary font variants (normal, bold, italic, bold italic) * The four primary font variants (normal, bold, italic, bold italic)
are now loaded in parallel. This speeds up both the initial startup are now loaded in parallel. This speeds up both the initial startup
time, as well as a DPI changes. time, as well as a DPI changes.
* Command line parsing no longer tries to parse arguments following
the command-to-execute. This means one can now write `foot sh -c
true` instead of `foot -- sh -c true`.
### Deprecated ### Deprecated

View file

@ -28,8 +28,8 @@ sig_handler(int signo)
static void static void
print_usage(const char *prog_name) print_usage(const char *prog_name)
{ {
printf("Usage: %s [OPTIONS]...\n", prog_name); printf("Usage: %s [OPTIONS...]", prog_name);
printf("Usage: %s [OPTIONS]... -- command\n", prog_name); printf("Usage: %s [OPTIONS...] [ARGS...]\n", prog_name);
printf("\n"); printf("\n");
printf("Options:\n"); printf("Options:\n");
printf(" -t,--term=TERM value to set the environment variable TERM to (foot)\n" printf(" -t,--term=TERM value to set the environment variable TERM to (foot)\n"
@ -74,7 +74,7 @@ main(int argc, char *const *argv)
bool fullscreen = false; bool fullscreen = false;
while (true) { while (true) {
int c = getopt_long(argc, argv, ":t:a:s:l::hv", longopts, NULL); int c = getopt_long(argc, argv, "+:t:a:s:l::hv", longopts, NULL);
if (c == -1) if (c == -1)
break; break;

View file

@ -5,10 +5,10 @@ foot - Wayland terminal emulator
# SYNOPSIS # SYNOPSIS
*foot* [_OPTIONS_]++ *foot* [_OPTIONS_]++
*foot* [_OPTIONS_] -- <_command_> *foot* [_OPTIONS_] <_command_> [_COMMAND OPTIONS_]
All trailing (non-option) arguments are treated as a command to All trailing (non-option) arguments are treated as a command, and its
execute (instead of the shell). arguments, to execute (instead of the default shell).
# OPTIONS # OPTIONS

View file

@ -5,10 +5,10 @@ footclient - start new terminals in a foot server
# SYNOPSIS # SYNOPSIS
*foot* [_OPTIONS_]++ *foot* [_OPTIONS_]++
*foot* [_OPTIONS_] -- <command> *foot* [_OPTIONS_] <_command_> [_COMMAND OPTIONS_]
All trailing (non-option) arguments are treated as a command to All trailing (non-option) arguments are treated as a command, and its
execute (instead of the shell). arguments, to execute (instead of the default shell).
# OPTIONS # OPTIONS

6
main.c
View file

@ -39,8 +39,8 @@ static void
print_usage(const char *prog_name) print_usage(const char *prog_name)
{ {
printf( printf(
"Usage: %s [OPTIONS]...\n" "Usage: %s [OPTIONS...]\n"
"Usage: %s [OPTIONS]... -- command\n" "Usage: %s [OPTIONS...] command [ARGS...]\n"
"\n" "\n"
"Options:\n" "Options:\n"
" -c,--config=PATH load configuration from PATH (XDG_CONFIG_HOME/footrc)\n" " -c,--config=PATH load configuration from PATH (XDG_CONFIG_HOME/footrc)\n"
@ -179,7 +179,7 @@ main(int argc, char *const *argv)
bool log_syslog = true; bool log_syslog = true;
while (true) { while (true) {
int c = getopt_long(argc, argv, "c:t:a:Lf:g:s::Pp:l::Svh", longopts, NULL); int c = getopt_long(argc, argv, "+c:t:a:Lf:g:s::Pp:l::Svh", longopts, NULL);
if (c == -1) if (c == -1)
break; break;