diff options
author | Nicholas Marriott <nicm@cvs.openbsd.org> | 2013-03-24 09:55:03 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@cvs.openbsd.org> | 2013-03-24 09:55:03 +0000 |
commit | e6e3e05e33040b1ac0ab0fd4e1a39aa94323411d (patch) | |
tree | 86fb99204925caf50082cf0347daaeb20ba2d823 /usr.bin | |
parent | 850baabe4d0cd3495529b1629355880ad8e5863b (diff) |
Add a -o option to set-option to prevent setting an option already set,
from Thiago Padilha.
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/tmux/cmd-set-option.c | 22 | ||||
-rw-r--r-- | usr.bin/tmux/tmux.1 | 8 |
2 files changed, 22 insertions, 8 deletions
diff --git a/usr.bin/tmux/cmd-set-option.c b/usr.bin/tmux/cmd-set-option.c index 5a867ae64af..bd801c1a7c5 100644 --- a/usr.bin/tmux/cmd-set-option.c +++ b/usr.bin/tmux/cmd-set-option.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-set-option.c,v 1.60 2013/03/24 09:54:10 nicm Exp $ */ +/* $OpenBSD: cmd-set-option.c,v 1.61 2013/03/24 09:55:02 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -30,7 +30,7 @@ enum cmd_retval cmd_set_option_exec(struct cmd *, struct cmd_q *); enum cmd_retval cmd_set_option_user(struct cmd *, struct cmd_q *, - const char *, const char *); + const char *, const char *); int cmd_set_option_unset(struct cmd *, struct cmd_q *, const struct options_table_entry *, struct options *, @@ -63,8 +63,8 @@ struct options_entry *cmd_set_option_choice(struct cmd *, struct cmd_q *, const struct cmd_entry cmd_set_option_entry = { "set-option", "set", - "agqst:uw", 1, 2, - "[-agsquw] [-t target-session|target-window] option [value]", + "agoqst:uw", 1, 2, + "[-agosquw] [-t target-session|target-window] option [value]", 0, NULL, NULL, @@ -73,8 +73,8 @@ const struct cmd_entry cmd_set_option_entry = { const struct cmd_entry cmd_set_window_option_entry = { "set-window-option", "setw", - "agqt:u", 1, 2, - "[-agqu] " CMD_TARGET_WINDOW_USAGE " option [value]", + "agoqt:u", 1, 2, + "[-agoqu] " CMD_TARGET_WINDOW_USAGE " option [value]", 0, NULL, NULL, @@ -151,6 +151,11 @@ cmd_set_option_exec(struct cmd *self, struct cmd_q *cmdq) if (cmd_set_option_unset(self, cmdq, oe, oo, valstr) != 0) return (CMD_RETURN_ERROR); } else { + if (args_has(args, 'o') && options_find1(oo, optstr) != NULL) { + if (!args_has(args, 'q')) + cmdq_print(cmdq, "already set: %s", optstr); + return (CMD_RETURN_NORMAL); + } if (cmd_set_option_set(self, cmdq, oe, oo, valstr) != 0) return (CMD_RETURN_ERROR); } @@ -227,6 +232,11 @@ cmd_set_option_user(struct cmd *self, struct cmd_q *cmdq, const char* optstr, cmdq_error(cmdq, "empty value"); return (CMD_RETURN_ERROR); } + if (args_has(args, 'o') && options_find1(oo, optstr) != NULL) { + if (!args_has(args, 'q')) + cmdq_print(cmdq, "already set: %s", optstr); + return (CMD_RETURN_NORMAL); + } options_set_string(oo, optstr, "%s", valstr); if (!args_has(args, 'q')) { cmdq_info(cmdq, "set option: %s -> %s", optstr, diff --git a/usr.bin/tmux/tmux.1 b/usr.bin/tmux/tmux.1 index 3978c8e8244..7ea64491bf2 100644 --- a/usr.bin/tmux/tmux.1 +++ b/usr.bin/tmux/tmux.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: tmux.1,v 1.335 2013/03/24 09:54:10 nicm Exp $ +.\" $OpenBSD: tmux.1,v 1.336 2013/03/24 09:55:02 nicm Exp $ .\" .\" Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> .\" @@ -1992,7 +1992,7 @@ abc123 Commands which set options are as follows: .Bl -tag -width Ds .It Xo Ic set-option -.Op Fl agqsuw +.Op Fl agoqsuw .Op Fl t Ar target-session | Ar target-window .Ar option Ar value .Xc @@ -2021,6 +2021,10 @@ options. It is not possible to unset a global option. .Pp The +.Fl o +flag prevents setting an option that is already set. +.Pp +The .Fl q flag suppresses the informational message (as if the .Ic quiet |