mirror of
				https://github.com/tmux/tmux.git
				synced 2025-10-26 12:27:15 +00:00 
			
		
		
		
	Allow source-file to take multiple arguments.
This commit is contained in:
		| @@ -38,8 +38,8 @@ const struct cmd_entry cmd_source_file_entry = { | ||||
| 	.name = "source-file", | ||||
| 	.alias = "source", | ||||
|  | ||||
| 	.args = { "nq", 1, 1 }, | ||||
| 	.usage = "[-nq] path", | ||||
| 	.args = { "nq", 1, -1 }, | ||||
| 	.usage = "[-nq] path ...", | ||||
|  | ||||
| 	.flags = 0, | ||||
| 	.exec = cmd_source_file_exec | ||||
| @@ -53,49 +53,54 @@ cmd_source_file_exec(struct cmd *self, struct cmdq_item *item) | ||||
| 	struct client		*c = item->client; | ||||
| 	struct cmdq_item	*new_item, *after; | ||||
| 	enum cmd_retval		 retval; | ||||
| 	char			*pattern, *tmp; | ||||
| 	const char		*path = args->argv[0]; | ||||
| 	char			*pattern, *cwd; | ||||
| 	const char		*path, *error; | ||||
| 	glob_t			 g; | ||||
| 	u_int			 i; | ||||
| 	int			 i; | ||||
| 	u_int			 j; | ||||
|  | ||||
| 	if (args_has(args, 'q')) | ||||
| 		flags |= CMD_PARSE_QUIET; | ||||
| 	if (args_has(args, 'n')) | ||||
| 		flags |= CMD_PARSE_PARSEONLY; | ||||
|  | ||||
| 	if (*path == '/') | ||||
| 		pattern = xstrdup(path); | ||||
| 	else { | ||||
| 		utf8_stravis(&tmp, server_client_get_cwd(c, NULL), VIS_GLOB); | ||||
| 		xasprintf(&pattern, "%s/%s", tmp, path); | ||||
| 		free(tmp); | ||||
| 	} | ||||
| 	log_debug("%s: %s", __func__, pattern); | ||||
| 	utf8_stravis(&cwd, server_client_get_cwd(c, NULL), VIS_GLOB); | ||||
|  | ||||
| 	retval = CMD_RETURN_NORMAL; | ||||
| 	for (i = 0; i < args->argc; i++) { | ||||
| 		path = args->argv[i]; | ||||
| 		if (*path == '/') | ||||
| 			pattern = xstrdup(path); | ||||
| 		else | ||||
| 			xasprintf(&pattern, "%s/%s", cwd, path); | ||||
| 		log_debug("%s: %s", __func__, pattern); | ||||
|  | ||||
| 		if (glob(pattern, 0, NULL, &g) != 0) { | ||||
| 			error = strerror(errno); | ||||
| 			if (errno != ENOENT || (~flags & CMD_PARSE_QUIET)) { | ||||
| 			cmdq_error(item, "%s: %s", path, strerror(errno)); | ||||
| 				cmdq_error(item, "%s: %s", path, error); | ||||
| 				retval = CMD_RETURN_ERROR; | ||||
| 			} | ||||
| 			free(pattern); | ||||
| 		return (retval); | ||||
| 			continue; | ||||
| 		} | ||||
| 		free(pattern); | ||||
|  | ||||
| 		after = item; | ||||
| 	for (i = 0; i < (u_int)g.gl_pathc; i++) { | ||||
| 		if (load_cfg(g.gl_pathv[i], c, after, flags, &new_item) < 0) | ||||
| 		for (j = 0; j < g.gl_pathc; j++) { | ||||
| 			path = g.gl_pathv[j]; | ||||
| 			if (load_cfg(path, c, after, flags, &new_item) < 0) | ||||
| 				retval = CMD_RETURN_ERROR; | ||||
| 			else if (new_item != NULL) | ||||
| 				after = new_item; | ||||
| 		} | ||||
| 		globfree(&g); | ||||
| 	} | ||||
| 	if (cfg_finished) { | ||||
| 		new_item = cmdq_get_callback(cmd_source_file_done, NULL); | ||||
| 		cmdq_insert_after(item, new_item); | ||||
| 	} | ||||
|  | ||||
| 	globfree(&g); | ||||
| 	free(cwd); | ||||
| 	return (retval); | ||||
| } | ||||
|  | ||||
|   | ||||
							
								
								
									
										7
									
								
								tmux.1
									
									
									
									
									
								
							
							
						
						
									
										7
									
								
								tmux.1
									
									
									
									
									
								
							| @@ -1239,13 +1239,14 @@ show debugging information about jobs and terminals. | ||||
| .It Xo Ic source-file | ||||
| .Op Fl nq | ||||
| .Ar path | ||||
| .Ar ... | ||||
| .Xc | ||||
| .D1 (alias: Ic source ) | ||||
| Execute commands from | ||||
| Execute commands from one or more files specified by | ||||
| .Ar path | ||||
| (which may be a | ||||
| (which may be | ||||
| .Xr glob 7 | ||||
| pattern). | ||||
| patterns). | ||||
| If | ||||
| .Fl q | ||||
| is given, no error will be returned if | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 nicm
					nicm