diff options
author | 2017-02-14 18:13:05 +0000 | |
---|---|---|
committer | 2017-02-14 18:13:05 +0000 | |
commit | 527df7dd49b24ff83b46f68eec4e25ae659c9a03 (patch) | |
tree | 63a272f3a16ce8342f729800efdbadf87c78c30b /usr.bin/tmux/cmd-source-file.c | |
parent | Missing opening brace. Spotted by Hiltjo Posthuma. (diff) | |
download | wireguard-openbsd-527df7dd49b24ff83b46f68eec4e25ae659c9a03.tar.xz wireguard-openbsd-527df7dd49b24ff83b46f68eec4e25ae659c9a03.zip |
Make source-file look for files relative to the client working directory
(like load-buffer and save-buffer), from Chris Pickel. Also break the
where-is-this-file code out into its own function for loadb and saveb.
Diffstat (limited to 'usr.bin/tmux/cmd-source-file.c')
-rw-r--r-- | usr.bin/tmux/cmd-source-file.c | 30 |
1 files changed, 22 insertions, 8 deletions
diff --git a/usr.bin/tmux/cmd-source-file.c b/usr.bin/tmux/cmd-source-file.c index d24f7b68a30..b497f860348 100644 --- a/usr.bin/tmux/cmd-source-file.c +++ b/usr.bin/tmux/cmd-source-file.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-source-file.c,v 1.33 2017/01/29 22:10:55 nicm Exp $ */ +/* $OpenBSD: cmd-source-file.c,v 1.34 2017/02/14 18:13:05 nicm Exp $ */ /* * Copyright (c) 2008 Tiago Cunha <me@tiagocunha.org> @@ -22,6 +22,7 @@ #include <glob.h> #include <stdlib.h> #include <string.h> +#include <vis.h> #include "tmux.h" @@ -48,22 +49,35 @@ static enum cmd_retval cmd_source_file_exec(struct cmd *self, struct cmdq_item *item) { struct args *args = self->args; + int quiet = args_has(args, 'q'); struct client *c = item->client; - int quiet; struct cmdq_item *new_item; enum cmd_retval retval; + char *pattern, *tmp; + const char *path = args->argv[0]; glob_t g; u_int i; - quiet = args_has(args, 'q'); - if (glob(args->argv[0], 0, NULL, &g) != 0) { - if (quiet && errno == ENOENT) - return (CMD_RETURN_NORMAL); - cmdq_error(item, "%s: %s", args->argv[0], strerror(errno)); - return (CMD_RETURN_ERROR); + if (*path == '/') + pattern = xstrdup(path); + else { + utf8_stravis(&tmp, server_client_get_cwd(c), VIS_GLOB); + xasprintf(&pattern, "%s/%s", tmp, path); + free(tmp); } + log_debug("%s: %s", __func__, pattern); retval = CMD_RETURN_NORMAL; + if (glob(pattern, 0, NULL, &g) != 0) { + if (!quiet || errno != ENOENT) { + cmdq_error(item, "%s: %s", path, strerror(errno)); + retval = CMD_RETURN_ERROR; + } + free(pattern); + return (retval); + } + free(pattern); + for (i = 0; i < (u_int)g.gl_pathc; i++) { if (load_cfg(g.gl_pathv[i], c, item, quiet) != 0) retval = CMD_RETURN_ERROR; |