From b526e678b50e197fdc9e70ff072f75abd1167a26 Mon Sep 17 00:00:00 2001 From: nicm Date: Wed, 9 Apr 2025 06:27:43 +0000 Subject: [PATCH] Make some usages more consistent and add -h to show usage, GitHub issue 4455 from David Mandelberg. --- cmd-command-prompt.c | 2 +- cmd-confirm-before.c | 2 +- cmd-set-environment.c | 2 +- cmd-show-environment.c | 2 +- cmd-show-prompt-history.c | 4 ++-- tmux.c | 20 +++++++++++--------- 6 files changed, 17 insertions(+), 15 deletions(-) diff --git a/cmd-command-prompt.c b/cmd-command-prompt.c index 60f7ca37..36a1f03c 100644 --- a/cmd-command-prompt.c +++ b/cmd-command-prompt.c @@ -44,7 +44,7 @@ const struct cmd_entry cmd_command_prompt_entry = { .args = { "1bFkiI:Np:t:T:", 0, 1, cmd_command_prompt_args_parse }, .usage = "[-1bFkiN] [-I inputs] [-p prompts] " CMD_TARGET_CLIENT_USAGE - " [-T type] [template]", + " [-T prompt-type] [template]", .flags = CMD_CLIENT_TFLAG, .exec = cmd_command_prompt_exec diff --git a/cmd-confirm-before.c b/cmd-confirm-before.c index af630b1e..1f592ae0 100644 --- a/cmd-confirm-before.c +++ b/cmd-confirm-before.c @@ -42,7 +42,7 @@ const struct cmd_entry cmd_confirm_before_entry = { .alias = "confirm", .args = { "bc:p:t:y", 1, 1, cmd_confirm_before_args_parse }, - .usage = "[-by] [-c confirm_key] [-p prompt] " CMD_TARGET_CLIENT_USAGE + .usage = "[-by] [-c confirm-key] [-p prompt] " CMD_TARGET_CLIENT_USAGE " command", .flags = CMD_CLIENT_TFLAG, diff --git a/cmd-set-environment.c b/cmd-set-environment.c index cec1f3e3..78c32452 100644 --- a/cmd-set-environment.c +++ b/cmd-set-environment.c @@ -35,7 +35,7 @@ const struct cmd_entry cmd_set_environment_entry = { .alias = "setenv", .args = { "Fhgrt:u", 1, 2, NULL }, - .usage = "[-Fhgru] " CMD_TARGET_SESSION_USAGE " name [value]", + .usage = "[-Fhgru] " CMD_TARGET_SESSION_USAGE " variable [value]", .target = { 't', CMD_FIND_SESSION, CMD_FIND_CANFAIL }, diff --git a/cmd-show-environment.c b/cmd-show-environment.c index b52db366..3440c33e 100644 --- a/cmd-show-environment.c +++ b/cmd-show-environment.c @@ -39,7 +39,7 @@ const struct cmd_entry cmd_show_environment_entry = { .alias = "showenv", .args = { "hgst:", 0, 1, NULL }, - .usage = "[-hgs] " CMD_TARGET_SESSION_USAGE " [name]", + .usage = "[-hgs] " CMD_TARGET_SESSION_USAGE " [variable]", .target = { 't', CMD_FIND_SESSION, CMD_FIND_CANFAIL }, diff --git a/cmd-show-prompt-history.c b/cmd-show-prompt-history.c index c85950b0..1b95bcaf 100644 --- a/cmd-show-prompt-history.c +++ b/cmd-show-prompt-history.c @@ -32,7 +32,7 @@ const struct cmd_entry cmd_show_prompt_history_entry = { .alias = "showphist", .args = { "T:", 0, 0, NULL }, - .usage = "[-T type]", + .usage = "[-T prompt-type]", .flags = CMD_AFTERHOOK, .exec = cmd_show_prompt_history_exec @@ -43,7 +43,7 @@ const struct cmd_entry cmd_clear_prompt_history_entry = { .alias = "clearphist", .args = { "T:", 0, 0, NULL }, - .usage = "[-T type]", + .usage = "[-T prompt-type]", .flags = CMD_AFTERHOOK, .exec = cmd_show_prompt_history_exec diff --git a/tmux.c b/tmux.c index 38ffa05c..28cb9f70 100644 --- a/tmux.c +++ b/tmux.c @@ -47,20 +47,20 @@ const char *socket_path; int ptm_fd = -1; const char *shell_command; -static __dead void usage(void); +static __dead void usage(int); static char *make_label(const char *, char **); static int areshell(const char *); static const char *getshell(void); static __dead void -usage(void) +usage(int status) { - fprintf(stderr, - "usage: %s [-2CDlNuVv] [-c shell-command] [-f file] [-L socket-name]\n" + fprintf(status ? stderr : stdout, + "usage: %s [-2CDhlNuVv] [-c shell-command] [-f file] [-L socket-name]\n" " [-S socket-path] [-T features] [command [flags]]\n", getprogname()); - exit(1); + exit(status); } static const char * @@ -389,7 +389,7 @@ main(int argc, char **argv) environ_set(global_environ, "PWD", 0, "%s", cwd); expand_paths(TMUX_CONF, &cfg_files, &cfg_nfiles, 1); - while ((opt = getopt(argc, argv, "2c:CDdf:lL:NqS:T:uUvV")) != -1) { + while ((opt = getopt(argc, argv, "2c:CDdf:hlL:NqS:T:uUvV")) != -1) { switch (opt) { case '2': tty_add_features(&feat, "256", ":,"); @@ -418,6 +418,8 @@ main(int argc, char **argv) cfg_files[cfg_nfiles++] = xstrdup(optarg); cfg_quiet = 0; break; + case 'h': + usage(0); case 'V': printf("tmux %s\n", getversion()); exit(0); @@ -447,16 +449,16 @@ main(int argc, char **argv) log_add_level(); break; default: - usage(); + usage(1); } } argc -= optind; argv += optind; if (shell_command != NULL && argc != 0) - usage(); + usage(1); if ((flags & CLIENT_NOFORK) && argc != 0) - usage(); + usage(1); if ((ptm_fd = getptmfd()) == -1) err(1, "getptmfd");