mirror of
https://github.com/openbsd/src.git
synced 2025-01-10 06:47:55 -08:00
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.
This commit is contained in:
parent
6f43ff909c
commit
8a00c84cfc
@ -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'))
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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'))
|
||||
|
@ -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);
|
||||
|
@ -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 *);
|
||||
|
@ -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__);
|
||||
|
Loading…
Reference in New Issue
Block a user