summaryrefslogtreecommitdiffstats
path: root/cmd-show-environment.c
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@openbsd.org>2012-03-22 11:11:57 +0000
committerNicholas Marriott <nicm@openbsd.org>2012-03-22 11:11:57 +0000
commitc0cfbe12e4089431a2cbc69ba7c6b919cc7d4054 (patch)
tree46541dddcd59970905172b6f3239846ff4586384 /cmd-show-environment.c
parent7c9d003e99eff8d9a935102e47662f681e7629bb (diff)
Accept an argument to show-environment to show one variable, based on a
diff from Kazuhiko Sakaguchi.
Diffstat (limited to 'cmd-show-environment.c')
-rw-r--r--cmd-show-environment.c17
1 files changed, 15 insertions, 2 deletions
diff --git a/cmd-show-environment.c b/cmd-show-environment.c
index e84ff685..17960321 100644
--- a/cmd-show-environment.c
+++ b/cmd-show-environment.c
@@ -31,8 +31,8 @@ int cmd_show_environment_exec(struct cmd *, struct cmd_ctx *);
const struct cmd_entry cmd_show_environment_entry = {
"show-environment", "showenv",
- "gt:", 0, 0,
- "[-g] " CMD_TARGET_SESSION_USAGE,
+ "gt:", 0, 1,
+ "[-g] " CMD_TARGET_SESSION_USAGE " [name]",
0,
NULL,
NULL,
@@ -55,6 +55,19 @@ cmd_show_environment_exec(struct cmd *self, struct cmd_ctx *ctx)
env = &s->environ;
}
+ if (args->argc != 0) {
+ envent = environ_find(env, args->argv[0]);
+ if (envent == NULL) {
+ ctx->error(ctx, "unknown variable: %s", args->argv[0]);
+ return (-1);
+ }
+ if (envent->value != NULL)
+ ctx->print(ctx, "%s=%s", envent->name, envent->value);
+ else
+ ctx->print(ctx, "-%s", envent->name);
+ return (0);
+ }
+
RB_FOREACH(envent, environ, env) {
if (envent->value != NULL)
ctx->print(ctx, "%s=%s", envent->name, envent->value);