mirror of
				https://github.com/tmux/tmux.git
				synced 2025-11-04 09:26:05 +00:00 
			
		
		
		
	Add -q flag to unbind-key to hide errors, GitHub issue 2381.
This commit is contained in:
		@@ -32,8 +32,8 @@ const struct cmd_entry cmd_unbind_key_entry = {
 | 
				
			|||||||
	.name = "unbind-key",
 | 
						.name = "unbind-key",
 | 
				
			||||||
	.alias = "unbind",
 | 
						.alias = "unbind",
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	.args = { "anT:", 0, 1 },
 | 
						.args = { "anqT:", 0, 1 },
 | 
				
			||||||
	.usage = "[-an] [-T key-table] key",
 | 
						.usage = "[-anq] [-T key-table] key",
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	.flags = CMD_AFTERHOOK,
 | 
						.flags = CMD_AFTERHOOK,
 | 
				
			||||||
	.exec = cmd_unbind_key_exec
 | 
						.exec = cmd_unbind_key_exec
 | 
				
			||||||
@@ -45,44 +45,54 @@ cmd_unbind_key_exec(struct cmd *self, struct cmdq_item *item)
 | 
				
			|||||||
	struct args	*args = cmd_get_args(self);
 | 
						struct args	*args = cmd_get_args(self);
 | 
				
			||||||
	key_code	 key;
 | 
						key_code	 key;
 | 
				
			||||||
	const char	*tablename;
 | 
						const char	*tablename;
 | 
				
			||||||
 | 
						int		 quiet = args_has(args, 'q');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (!args_has(args, 'a')) {
 | 
						if (args_has(args, 'a')) {
 | 
				
			||||||
		if (args->argc != 1) {
 | 
					 | 
				
			||||||
			cmdq_error(item, "missing key");
 | 
					 | 
				
			||||||
			return (CMD_RETURN_ERROR);
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		key = key_string_lookup_string(args->argv[0]);
 | 
					 | 
				
			||||||
		if (key == KEYC_NONE || key == KEYC_UNKNOWN) {
 | 
					 | 
				
			||||||
			cmdq_error(item, "unknown key: %s", args->argv[0]);
 | 
					 | 
				
			||||||
			return (CMD_RETURN_ERROR);
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	} else {
 | 
					 | 
				
			||||||
		if (args->argc != 0) {
 | 
							if (args->argc != 0) {
 | 
				
			||||||
 | 
								if (!quiet)
 | 
				
			||||||
				cmdq_error(item, "key given with -a");
 | 
									cmdq_error(item, "key given with -a");
 | 
				
			||||||
			return (CMD_RETURN_ERROR);
 | 
								return (CMD_RETURN_ERROR);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		key = KEYC_UNKNOWN;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (key == KEYC_UNKNOWN) {
 | 
					 | 
				
			||||||
		tablename = args_get(args, 'T');
 | 
							tablename = args_get(args, 'T');
 | 
				
			||||||
		if (tablename == NULL) {
 | 
							if (tablename == NULL) {
 | 
				
			||||||
			key_bindings_remove_table("root");
 | 
								if (args_has(args, 'n'))
 | 
				
			||||||
			key_bindings_remove_table("prefix");
 | 
									tablename = "root";
 | 
				
			||||||
			return (CMD_RETURN_NORMAL);
 | 
								else
 | 
				
			||||||
 | 
									tablename = "prefix";
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		if (key_bindings_get_table(tablename, 0) == NULL) {
 | 
							if (key_bindings_get_table(tablename, 0) == NULL) {
 | 
				
			||||||
			cmdq_error(item, "table %s doesn't exist", tablename);
 | 
								if (!quiet) {
 | 
				
			||||||
 | 
									cmdq_error(item, "table %s doesn't exist" ,
 | 
				
			||||||
 | 
									    tablename);
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
			return (CMD_RETURN_ERROR);
 | 
								return (CMD_RETURN_ERROR);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		key_bindings_remove_table(tablename);
 | 
							key_bindings_remove_table(tablename);
 | 
				
			||||||
		return (CMD_RETURN_NORMAL);
 | 
							return (CMD_RETURN_NORMAL);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (args->argc != 1) {
 | 
				
			||||||
 | 
							if (!quiet)
 | 
				
			||||||
 | 
								cmdq_error(item, "missing key");
 | 
				
			||||||
 | 
							return (CMD_RETURN_ERROR);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						key = key_string_lookup_string(args->argv[0]);
 | 
				
			||||||
 | 
						if (key == KEYC_NONE || key == KEYC_UNKNOWN) {
 | 
				
			||||||
 | 
							if (!quiet)
 | 
				
			||||||
 | 
								cmdq_error(item, "unknown key: %s", args->argv[0]);
 | 
				
			||||||
 | 
							return (CMD_RETURN_ERROR);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (args_has(args, 'T')) {
 | 
						if (args_has(args, 'T')) {
 | 
				
			||||||
		tablename = args_get(args, 'T');
 | 
							tablename = args_get(args, 'T');
 | 
				
			||||||
		if (key_bindings_get_table(tablename, 0) == NULL) {
 | 
							if (key_bindings_get_table(tablename, 0) == NULL) {
 | 
				
			||||||
			cmdq_error(item, "table %s doesn't exist", tablename);
 | 
								if (!quiet) {
 | 
				
			||||||
 | 
									cmdq_error(item, "table %s doesn't exist" ,
 | 
				
			||||||
 | 
									    tablename);
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
			return (CMD_RETURN_ERROR);
 | 
								return (CMD_RETURN_ERROR);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	} else if (args_has(args, 'n'))
 | 
						} else if (args_has(args, 'n'))
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										5
									
								
								tmux.1
									
									
									
									
									
								
							
							
						
						
									
										5
									
								
								tmux.1
									
									
									
									
									
								
							@@ -3039,7 +3039,7 @@ Send the prefix key, or with
 | 
				
			|||||||
.Fl 2
 | 
					.Fl 2
 | 
				
			||||||
the secondary prefix key, to a window as if it was pressed.
 | 
					the secondary prefix key, to a window as if it was pressed.
 | 
				
			||||||
.It Xo Ic unbind-key
 | 
					.It Xo Ic unbind-key
 | 
				
			||||||
.Op Fl an
 | 
					.Op Fl anq
 | 
				
			||||||
.Op Fl T Ar key-table
 | 
					.Op Fl T Ar key-table
 | 
				
			||||||
.Ar key
 | 
					.Ar key
 | 
				
			||||||
.Xc
 | 
					.Xc
 | 
				
			||||||
@@ -3054,6 +3054,9 @@ are the same as for
 | 
				
			|||||||
If
 | 
					If
 | 
				
			||||||
.Fl a
 | 
					.Fl a
 | 
				
			||||||
is present, all key bindings are removed.
 | 
					is present, all key bindings are removed.
 | 
				
			||||||
 | 
					The
 | 
				
			||||||
 | 
					.Fl q
 | 
				
			||||||
 | 
					option prevents errors being returned.
 | 
				
			||||||
.El
 | 
					.El
 | 
				
			||||||
.Sh OPTIONS
 | 
					.Sh OPTIONS
 | 
				
			||||||
The appearance and behaviour of
 | 
					The appearance and behaviour of
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user