mirror of
				https://github.com/tmux/tmux.git
				synced 2025-11-03 16:46:18 +00:00 
			
		
		
		
	Add a -o option to set-option to prevent setting an option already set, from
Thiago Padilha.
This commit is contained in:
		@@ -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,
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										6
									
								
								tmux.1
									
									
									
									
									
								
							
							
						
						
									
										6
									
								
								tmux.1
									
									
									
									
									
								
							@@ -1996,7 +1996,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
 | 
			
		||||
@@ -2025,6 +2025,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
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user