summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Adam <thomas@xteddy.org>2016-03-03 16:01:11 +0000
committerThomas Adam <thomas@xteddy.org>2016-03-03 16:01:11 +0000
commit6c35d17800b5d745272c45bb4c71bde80780c415 (patch)
tree818b03a3534a51d98277f2badc0df2159522510d
parent45d62482daf5264c47d68ae07061ea99382c7a54 (diff)
parentdf0983af39922f2ee747a244c1c718ba7ca28910 (diff)
Merge branch 'obsd-master'
-rw-r--r--cmd-find.c10
-rw-r--r--cmd-set-environment.c15
-rw-r--r--cmd-set-option.c38
-rw-r--r--cmd-show-environment.c21
-rw-r--r--cmd-show-options.c31
5 files changed, 82 insertions, 33 deletions
diff --git a/cmd-find.c b/cmd-find.c
index f6094ced..f95c143b 100644
--- a/cmd-find.c
+++ b/cmd-find.c
@@ -400,6 +400,7 @@ int
cmd_find_get_session(struct cmd_find_state *fs, const char *session)
{
struct session *s, *s_loop;
+ struct client *c;
log_debug("%s: %s", __func__, session);
@@ -416,6 +417,13 @@ cmd_find_get_session(struct cmd_find_state *fs, const char *session)
if (fs->s != NULL)
return (0);
+ /* Look for as a client. */
+ c = cmd_find_client(NULL, session, 1);
+ if (c != NULL && c->session != NULL) {
+ fs->s = c->session;
+ return (0);
+ }
+
/* Stop now if exact only. */
if (fs->flags & CMD_FIND_EXACT_SESSION)
return (-1);
@@ -1208,7 +1216,7 @@ cmd_find_client(struct cmd_q *cmdq, const char *target, int quiet)
const char *path;
/* A NULL argument means the current client. */
- if (target == NULL) {
+ if (cmdq != NULL && target == NULL) {
c = cmd_find_current_client(cmdq);
if (c == NULL && !quiet)
cmdq_error(cmdq, "no current client");
diff --git a/cmd-set-environment.c b/cmd-set-environment.c
index 55bdaa9a..ba295ea6 100644
--- a/cmd-set-environment.c
+++ b/cmd-set-environment.c
@@ -47,7 +47,7 @@ cmd_set_environment_exec(struct cmd *self, struct cmd_q *cmdq)
{
struct args *args = self->args;
struct environ *env;
- const char *name, *value;
+ const char *name, *value, *target;
name = args->argv[0];
if (*name == '\0') {
@@ -64,10 +64,19 @@ cmd_set_environment_exec(struct cmd *self, struct cmd_q *cmdq)
else
value = args->argv[1];
- if (args_has(self->args, 'g') || cmdq->state.tflag.s == NULL)
+ if (args_has(self->args, 'g'))
env = global_environ;
- else
+ else {
+ if (cmdq->state.tflag.s == NULL) {
+ target = args_get(args, 't');
+ if (target != NULL)
+ cmdq_error(cmdq, "no such session: %s", target);
+ else
+ cmdq_error(cmdq, "no current session");
+ return (CMD_RETURN_ERROR);
+ }
env = cmdq->state.tflag.s->environ;
+ }
if (args_has(self->args, 'u')) {
if (value != NULL) {
diff --git a/cmd-set-option.c b/cmd-set-option.c
index 7fc81286..b1771436 100644
--- a/cmd-set-option.c
+++ b/cmd-set-option.c
@@ -100,7 +100,7 @@ cmd_set_option_exec(struct cmd *self, struct cmd_q *cmdq)
struct client *c;
const struct options_table_entry *oe;
struct options *oo;
- const char *optstr, *valstr;
+ const char *optstr, *valstr, *target;
/* Get the option name and value. */
optstr = args->argv[0];
@@ -140,29 +140,29 @@ cmd_set_option_exec(struct cmd *self, struct cmd_q *cmdq)
else if (oe->scope == OPTIONS_TABLE_WINDOW) {
if (args_has(self->args, 'g'))
oo = global_w_options;
- else {
- if (wl == NULL) {
- cmdq_error(cmdq,
- "couldn't set '%s'%s", optstr,
- (!args_has(args, 't') && !args_has(args,
- 'g')) ? " need target window or -g" : "");
- return (CMD_RETURN_ERROR);
- }
+ else if (wl == NULL) {
+ target = args_get(args, 't');
+ if (target != NULL) {
+ cmdq_error(cmdq, "no such window: %s",
+ target);
+ } else
+ cmdq_error(cmdq, "no current window");
+ return (CMD_RETURN_ERROR);
+ } else
oo = wl->window->options;
- }
} else if (oe->scope == OPTIONS_TABLE_SESSION) {
if (args_has(self->args, 'g'))
oo = global_s_options;
- else {
- if (s == NULL) {
- cmdq_error(cmdq,
- "couldn't set '%s'%s", optstr,
- (!args_has(args, 't') && !args_has(args,
- 'g')) ? " need target session or -g" : "");
- return (CMD_RETURN_ERROR);
- }
+ else if (s == NULL) {
+ target = args_get(args, 't');
+ if (target != NULL) {
+ cmdq_error(cmdq, "no such session: %s",
+ target);
+ } else
+ cmdq_error(cmdq, "no current session");
+ return (CMD_RETURN_ERROR);
+ } else
oo = s->options;
- }
} else {
cmdq_error(cmdq, "unknown table");
return (CMD_RETURN_ERROR);
diff --git a/cmd-show-environment.c b/cmd-show-environment.c
index 83661c44..29e89274 100644
--- a/cmd-show-environment.c
+++ b/cmd-show-environment.c
@@ -93,11 +93,28 @@ cmd_show_environment_exec(struct cmd *self, struct cmd_q *cmdq)
struct args *args = self->args;
struct environ *env;
struct environ_entry *envent;
+ const char *target;
- if (args_has(self->args, 'g') || cmdq->state.tflag.s == NULL)
+ if ((target = args_get(args, 't')) != NULL) {
+ if (cmdq->state.tflag.s == NULL) {
+ cmdq_error(cmdq, "no such session: %s", target);
+ return (CMD_RETURN_ERROR);
+ }
+ }
+
+ if (args_has(self->args, 'g'))
env = global_environ;
- else
+ else {
+ if (cmdq->state.tflag.s == NULL) {
+ target = args_get(args, 't');
+ if (target != NULL)
+ cmdq_error(cmdq, "no such session: %s", target);
+ else
+ cmdq_error(cmdq, "no current session");
+ return (CMD_RETURN_ERROR);
+ }
env = cmdq->state.tflag.s->environ;
+ }
if (args->argc != 0) {
envent = environ_find(env, args->argv[0]);
diff --git a/cmd-show-options.c b/cmd-show-options.c
index fec2f1de..322f532c 100644
--- a/cmd-show-options.c
+++ b/cmd-show-options.c
@@ -63,12 +63,13 @@ const struct cmd_entry cmd_show_window_options_entry = {
enum cmd_retval
cmd_show_options_exec(struct cmd *self, struct cmd_q *cmdq)
{
- struct args *args = self->args;
- struct session *s = cmdq->state.tflag.s;
- struct winlink *wl = cmdq->state.tflag.wl;
- struct options *oo;
- enum options_table_scope scope;
- int quiet;
+ struct args *args = self->args;
+ struct session *s = cmdq->state.tflag.s;
+ struct winlink *wl = cmdq->state.tflag.wl;
+ struct options *oo;
+ enum options_table_scope scope;
+ int quiet;
+ const char *target;
if (args_has(self->args, 's')) {
oo = global_options;
@@ -78,13 +79,27 @@ cmd_show_options_exec(struct cmd *self, struct cmd_q *cmdq)
scope = OPTIONS_TABLE_WINDOW;
if (args_has(self->args, 'g'))
oo = global_w_options;
- else
+ else if (wl == NULL) {
+ target = args_get(args, 't');
+ if (target != NULL) {
+ cmdq_error(cmdq, "no such window: %s", target);
+ } else
+ cmdq_error(cmdq, "no current window");
+ return (CMD_RETURN_ERROR);
+ } else
oo = wl->window->options;
} else {
scope = OPTIONS_TABLE_SESSION;
if (args_has(self->args, 'g'))
oo = global_s_options;
- else
+ else if (s == NULL) {
+ target = args_get(args, 't');
+ if (target != NULL) {
+ cmdq_error(cmdq, "no such session: %s", target);
+ } else
+ cmdq_error(cmdq, "no current session");
+ return (CMD_RETURN_ERROR);
+ } else
oo = s->options;
}