Make some usages more consistent and add -h to show usage, GitHub issue

4455 from David Mandelberg.
This commit is contained in:
nicm
2025-04-09 06:27:43 +00:00
parent a7991dcbad
commit b526e678b5
6 changed files with 17 additions and 15 deletions

View File

@ -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

View File

@ -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,

View File

@ -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 },

View File

@ -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 },

View File

@ -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

20
tmux.c
View File

@ -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");