diff options
author | Nicholas Marriott <nicm@cvs.openbsd.org> | 2018-05-24 09:42:50 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@cvs.openbsd.org> | 2018-05-24 09:42:50 +0000 |
commit | 31afe17b33a4799bc776cfe1f2d496c7c446d3f0 (patch) | |
tree | 4c64d0d7da21784371e533d1c0d568a7f6df51f4 /usr.bin | |
parent | 99ae952fb5951366f160e00bcb8af3ad15f5fed0 (diff) |
Make server_client_get_cwd used (almost) everywhere we need to work out
the cwd, and do not fall back to "." as it is pretty useless. GitHub
issue 1331.
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/tmux/cmd-if-shell.c | 14 | ||||
-rw-r--r-- | usr.bin/tmux/cmd-new-session.c | 6 | ||||
-rw-r--r-- | usr.bin/tmux/cmd-new-window.c | 6 | ||||
-rw-r--r-- | usr.bin/tmux/cmd-run-shell.c | 14 | ||||
-rw-r--r-- | usr.bin/tmux/cmd-source-file.c | 4 | ||||
-rw-r--r-- | usr.bin/tmux/cmd-split-window.c | 6 | ||||
-rw-r--r-- | usr.bin/tmux/server-client.c | 14 | ||||
-rw-r--r-- | usr.bin/tmux/tmux.h | 4 | ||||
-rw-r--r-- | usr.bin/tmux/window.c | 5 |
9 files changed, 28 insertions, 45 deletions
diff --git a/usr.bin/tmux/cmd-if-shell.c b/usr.bin/tmux/cmd-if-shell.c index 6740546601f..d093073ccd2 100644 --- a/usr.bin/tmux/cmd-if-shell.c +++ b/usr.bin/tmux/cmd-if-shell.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-if-shell.c,v 1.57 2018/03/08 08:09:10 nicm Exp $ */ +/* $OpenBSD: cmd-if-shell.c,v 1.58 2018/05/24 09:42:49 nicm Exp $ */ /* * Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org> @@ -73,14 +73,6 @@ cmd_if_shell_exec(struct cmd *self, struct cmdq_item *item) struct session *s = item->target.s; struct winlink *wl = item->target.wl; struct window_pane *wp = item->target.wp; - const char *cwd; - - if (item->client != NULL && item->client->session == NULL) - cwd = item->client->cwd; - else if (s != NULL) - cwd = s->cwd; - else - cwd = NULL; shellcmd = format_single(item, args->argv[0], c, s, wl, wp); if (args_has(args, 'F')) { @@ -128,8 +120,8 @@ cmd_if_shell_exec(struct cmd *self, struct cmdq_item *item) cdata->item = NULL; memcpy(&cdata->mouse, &shared->mouse, sizeof cdata->mouse); - job_run(shellcmd, s, cwd, NULL, cmd_if_shell_callback, - cmd_if_shell_free, cdata, 0); + job_run(shellcmd, s, server_client_get_cwd(item->client, s), NULL, + cmd_if_shell_callback, cmd_if_shell_free, cdata, 0); free(shellcmd); if (args_has(args, 'b')) diff --git a/usr.bin/tmux/cmd-new-session.c b/usr.bin/tmux/cmd-new-session.c index aaadb90b1ce..039943c1727 100644 --- a/usr.bin/tmux/cmd-new-session.c +++ b/usr.bin/tmux/cmd-new-session.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-new-session.c,v 1.110 2018/03/01 12:53:08 nicm Exp $ */ +/* $OpenBSD: cmd-new-session.c,v 1.111 2018/05/24 09:42:49 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -156,10 +156,8 @@ cmd_new_session_exec(struct cmd *self, struct cmdq_item *item) /* Get the new session working directory. */ if ((tmp = args_get(args, 'c')) != NULL) cwd = format_single(item, tmp, c, NULL, NULL, NULL); - else if (c != NULL && c->session == NULL && c->cwd != NULL) - cwd = xstrdup(c->cwd); else - cwd = xstrdup("."); + cwd = xstrdup(server_client_get_cwd(c, NULL)); /* * If this is a new client, check for nesting and save the termios diff --git a/usr.bin/tmux/cmd-new-window.c b/usr.bin/tmux/cmd-new-window.c index bef114a97fd..f4004cd9772 100644 --- a/usr.bin/tmux/cmd-new-window.c +++ b/usr.bin/tmux/cmd-new-window.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-new-window.c,v 1.74 2018/05/03 16:56:59 nicm Exp $ */ +/* $OpenBSD: cmd-new-window.c,v 1.75 2018/05/24 09:42:49 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -95,10 +95,8 @@ cmd_new_window_exec(struct cmd *self, struct cmdq_item *item) if ((tmp = args_get(args, 'c')) != NULL) cwd = format_single(item, tmp, c, s, NULL, NULL); - else if (item->client != NULL && item->client->session == NULL) - cwd = xstrdup(item->client->cwd); else - cwd = xstrdup(s->cwd); + cwd = xstrdup(server_client_get_cwd(item->client, s)); if ((tmp = args_get(args, 'n')) != NULL) name = format_single(item, tmp, c, s, NULL, NULL); diff --git a/usr.bin/tmux/cmd-run-shell.c b/usr.bin/tmux/cmd-run-shell.c index 0950c81bd8b..f97191ed3d6 100644 --- a/usr.bin/tmux/cmd-run-shell.c +++ b/usr.bin/tmux/cmd-run-shell.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-run-shell.c,v 1.52 2018/03/08 08:09:10 nicm Exp $ */ +/* $OpenBSD: cmd-run-shell.c,v 1.53 2018/05/24 09:42:49 nicm Exp $ */ /* * Copyright (c) 2009 Tiago Cunha <me@tiagocunha.org> @@ -90,14 +90,6 @@ cmd_run_shell_exec(struct cmd *self, struct cmdq_item *item) struct session *s = item->target.s; struct winlink *wl = item->target.wl; struct window_pane *wp = item->target.wp; - const char *cwd; - - if (item->client != NULL && item->client->session == NULL) - cwd = item->client->cwd; - else if (s != NULL) - cwd = s->cwd; - else - cwd = NULL; cdata = xcalloc(1, sizeof *cdata); cdata->cmd = format_single(item, args->argv[0], c, s, wl, wp); @@ -110,8 +102,8 @@ cmd_run_shell_exec(struct cmd *self, struct cmdq_item *item) if (!args_has(args, 'b')) cdata->item = item; - job_run(cdata->cmd, s, cwd, NULL, cmd_run_shell_callback, - cmd_run_shell_free, cdata, 0); + job_run(cdata->cmd, s, server_client_get_cwd(item->client, s), NULL, + cmd_run_shell_callback, cmd_run_shell_free, cdata, 0); if (args_has(args, 'b')) return (CMD_RETURN_NORMAL); diff --git a/usr.bin/tmux/cmd-source-file.c b/usr.bin/tmux/cmd-source-file.c index 609866eec37..6c55a446e07 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.35 2017/04/19 16:59:54 nicm Exp $ */ +/* $OpenBSD: cmd-source-file.c,v 1.36 2018/05/24 09:42:49 nicm Exp $ */ /* * Copyright (c) 2008 Tiago Cunha <me@tiagocunha.org> @@ -61,7 +61,7 @@ cmd_source_file_exec(struct cmd *self, struct cmdq_item *item) if (*path == '/') pattern = xstrdup(path); else { - utf8_stravis(&tmp, server_client_get_cwd(c), VIS_GLOB); + utf8_stravis(&tmp, server_client_get_cwd(c, NULL), VIS_GLOB); xasprintf(&pattern, "%s/%s", tmp, path); free(tmp); } diff --git a/usr.bin/tmux/cmd-split-window.c b/usr.bin/tmux/cmd-split-window.c index 6aa6cea2f0c..0e96d041d6a 100644 --- a/usr.bin/tmux/cmd-split-window.c +++ b/usr.bin/tmux/cmd-split-window.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd-split-window.c,v 1.89 2018/03/16 15:15:39 nicm Exp $ */ +/* $OpenBSD: cmd-split-window.c,v 1.90 2018/05/24 09:42:49 nicm Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -88,10 +88,8 @@ cmd_split_window_exec(struct cmd *self, struct cmdq_item *item) if ((tmp = args_get(args, 'c')) != NULL) cwd = format_single(item, tmp, c, s, NULL, NULL); - else if (item->client != NULL && item->client->session == NULL) - cwd = xstrdup(item->client->cwd); else - cwd = xstrdup(s->cwd); + cwd = xstrdup(server_client_get_cwd(item->client, s)); type = LAYOUT_TOPBOTTOM; if (args_has(args, 'h')) diff --git a/usr.bin/tmux/server-client.c b/usr.bin/tmux/server-client.c index 2ff84e0ea4a..7c7da257448 100644 --- a/usr.bin/tmux/server-client.c +++ b/usr.bin/tmux/server-client.c @@ -1,4 +1,4 @@ -/* $OpenBSD: server-client.c,v 1.249 2018/03/08 08:09:10 nicm Exp $ */ +/* $OpenBSD: server-client.c,v 1.250 2018/05/24 09:42:49 nicm Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -1847,15 +1847,19 @@ server_client_add_message(struct client *c, const char *fmt, ...) /* Get client working directory. */ const char * -server_client_get_cwd(struct client *c) +server_client_get_cwd(struct client *c, struct session *s) { - struct session *s; + const char *home; if (c != NULL && c->session == NULL && c->cwd != NULL) return (c->cwd); + if (s != NULL && s->cwd != NULL) + return (s->cwd); if (c != NULL && (s = c->session) != NULL && s->cwd != NULL) return (s->cwd); - return ("."); + if ((home = find_home()) != NULL) + return (home); + return ("/"); } /* Resolve an absolute path or relative to client working directory. */ @@ -1867,7 +1871,7 @@ server_client_get_path(struct client *c, const char *file) if (*file == '/') path = xstrdup(file); else - xasprintf(&path, "%s/%s", server_client_get_cwd(c), file); + xasprintf(&path, "%s/%s", server_client_get_cwd(c, NULL), file); if (realpath(path, resolved) == NULL) return (path); free(path); diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h index 0ccdc9dea3b..180cf10e332 100644 --- a/usr.bin/tmux/tmux.h +++ b/usr.bin/tmux/tmux.h @@ -1,4 +1,4 @@ -/* $OpenBSD: tmux.h,v 1.824 2018/04/18 14:35:37 nicm Exp $ */ +/* $OpenBSD: tmux.h,v 1.825 2018/05/24 09:42:49 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -1906,7 +1906,7 @@ void server_client_push_stderr(struct client *); void printflike(2, 3) server_client_add_message(struct client *, const char *, ...); char *server_client_get_path(struct client *, const char *); -const char *server_client_get_cwd(struct client *); +const char *server_client_get_cwd(struct client *, struct session *); /* server-fn.c */ void server_redraw_client(struct client *); diff --git a/usr.bin/tmux/window.c b/usr.bin/tmux/window.c index 4f4e485d7a8..4df0bddd172 100644 --- a/usr.bin/tmux/window.c +++ b/usr.bin/tmux/window.c @@ -1,4 +1,4 @@ -/* $OpenBSD: window.c,v 1.209 2018/05/24 09:34:54 nicm Exp $ */ +/* $OpenBSD: window.c,v 1.210 2018/05/24 09:42:49 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -918,7 +918,8 @@ window_pane_spawn(struct window_pane *wp, int argc, char **argv, cmd = cmd_stringify_argv(wp->argc, wp->argv); log_debug("%s: shell=%s", __func__, wp->shell); - log_debug("%s: command=%s", __func__, cmd); + log_debug("%s: cmd=%s", __func__, cmd); + log_debug("%s: cwd=%s", __func__, cwd); for (i = 0; i < wp->argc; i++) log_debug("%s: argv[%d]=%s", __func__, i, wp->argv[i]); environ_log(env, "%s: environment ", __func__); |