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", | 	.name = "source-file", | ||||||
| 	.alias = "source", | 	.alias = "source", | ||||||
|  |  | ||||||
| 	.args = { "nq", 1, 1 }, | 	.args = { "nq", 1, -1 }, | ||||||
| 	.usage = "[-nq] path", | 	.usage = "[-nq] path ...", | ||||||
|  |  | ||||||
| 	.flags = 0, | 	.flags = 0, | ||||||
| 	.exec = cmd_source_file_exec | 	.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 client		*c = item->client; | ||||||
| 	struct cmdq_item	*new_item, *after; | 	struct cmdq_item	*new_item, *after; | ||||||
| 	enum cmd_retval		 retval; | 	enum cmd_retval		 retval; | ||||||
| 	char			*pattern, *tmp; | 	char			*pattern, *cwd; | ||||||
| 	const char		*path = args->argv[0]; | 	const char		*path, *error; | ||||||
| 	glob_t			 g; | 	glob_t			 g; | ||||||
| 	u_int			 i; | 	int			 i; | ||||||
|  | 	u_int			 j; | ||||||
|  |  | ||||||
| 	if (args_has(args, 'q')) | 	if (args_has(args, 'q')) | ||||||
| 		flags |= CMD_PARSE_QUIET; | 		flags |= CMD_PARSE_QUIET; | ||||||
| 	if (args_has(args, 'n')) | 	if (args_has(args, 'n')) | ||||||
| 		flags |= CMD_PARSE_PARSEONLY; | 		flags |= CMD_PARSE_PARSEONLY; | ||||||
|  | 	utf8_stravis(&cwd, server_client_get_cwd(c, NULL), VIS_GLOB); | ||||||
| 	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); |  | ||||||
|  |  | ||||||
| 	retval = CMD_RETURN_NORMAL; | 	retval = CMD_RETURN_NORMAL; | ||||||
| 	if (glob(pattern, 0, NULL, &g) != 0) { | 	for (i = 0; i < args->argc; i++) { | ||||||
| 		if (errno != ENOENT || (~flags & CMD_PARSE_QUIET)) { | 		path = args->argv[i]; | ||||||
| 			cmdq_error(item, "%s: %s", path, strerror(errno)); | 		if (*path == '/') | ||||||
| 			retval = CMD_RETURN_ERROR; | 			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, error); | ||||||
|  | 				retval = CMD_RETURN_ERROR; | ||||||
|  | 			} | ||||||
|  | 			free(pattern); | ||||||
|  | 			continue; | ||||||
| 		} | 		} | ||||||
| 		free(pattern); | 		free(pattern); | ||||||
| 		return (retval); |  | ||||||
| 	} |  | ||||||
| 	free(pattern); |  | ||||||
|  |  | ||||||
| 	after = item; | 		after = item; | ||||||
| 	for (i = 0; i < (u_int)g.gl_pathc; i++) { | 		for (j = 0; j < g.gl_pathc; j++) { | ||||||
| 		if (load_cfg(g.gl_pathv[i], c, after, flags, &new_item) < 0) | 			path = g.gl_pathv[j]; | ||||||
| 			retval = CMD_RETURN_ERROR; | 			if (load_cfg(path, c, after, flags, &new_item) < 0) | ||||||
| 		else if (new_item != NULL) | 				retval = CMD_RETURN_ERROR; | ||||||
| 			after = new_item; | 			else if (new_item != NULL) | ||||||
|  | 				after = new_item; | ||||||
|  | 		} | ||||||
|  | 		globfree(&g); | ||||||
| 	} | 	} | ||||||
| 	if (cfg_finished) { | 	if (cfg_finished) { | ||||||
| 		new_item = cmdq_get_callback(cmd_source_file_done, NULL); | 		new_item = cmdq_get_callback(cmd_source_file_done, NULL); | ||||||
| 		cmdq_insert_after(item, new_item); | 		cmdq_insert_after(item, new_item); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	globfree(&g); | 	free(cwd); | ||||||
| 	return (retval); | 	return (retval); | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
							
								
								
									
										7
									
								
								tmux.1
									
									
									
									
									
								
							
							
						
						
									
										7
									
								
								tmux.1
									
									
									
									
									
								
							| @@ -1239,13 +1239,14 @@ show debugging information about jobs and terminals. | |||||||
| .It Xo Ic source-file | .It Xo Ic source-file | ||||||
| .Op Fl nq | .Op Fl nq | ||||||
| .Ar path | .Ar path | ||||||
|  | .Ar ... | ||||||
| .Xc | .Xc | ||||||
| .D1 (alias: Ic source ) | .D1 (alias: Ic source ) | ||||||
| Execute commands from | Execute commands from one or more files specified by | ||||||
| .Ar path | .Ar path | ||||||
| (which may be a | (which may be | ||||||
| .Xr glob 7 | .Xr glob 7 | ||||||
| pattern). | patterns). | ||||||
| If | If | ||||||
| .Fl q | .Fl q | ||||||
| is given, no error will be returned if | is given, no error will be returned if | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 nicm
					nicm