Skip to content

Instantly share code, notes, and snippets.

@cdleary
Created June 10, 2013 07:47
Show Gist options
  • Save cdleary/5747136 to your computer and use it in GitHub Desktop.
Save cdleary/5747136 to your computer and use it in GitHub Desktop.
Add a "show args" command to tmux 1.8.
diff --git a/Makefile.in b/Makefile.in
index 98c0e13..ed537a4 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -151,6 +151,7 @@ dist_tmux_OBJECTS = arguments.$(OBJEXT) attributes.$(OBJEXT) \
cmd-set-buffer.$(OBJEXT) cmd-set-environment.$(OBJEXT) \
cmd-set-option.$(OBJEXT) cmd-show-environment.$(OBJEXT) \
cmd-show-messages.$(OBJEXT) cmd-show-options.$(OBJEXT) \
+ cmd-show-args.$(OBJEXT) \
cmd-source-file.$(OBJEXT) cmd-split-window.$(OBJEXT) \
cmd-start-server.$(OBJEXT) cmd-string.$(OBJEXT) \
cmd-suspend-client.$(OBJEXT) cmd-swap-pane.$(OBJEXT) \
diff --git a/cmd-show-args.c b/cmd-show-args.c
new file mode 100644
index 0000000..cdd101c
--- /dev/null
+++ b/cmd-show-args.c
@@ -0,0 +1,61 @@
+/* $Id$ */
+
+/*
+ * Copyright (c) 2013 Christopher D. Leary <cdleary@acm.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
+ * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
+ * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <sys/types.h>
+
+#include <stdlib.h>
+#include <unistd.h>
+
+#include "tmux.h"
+
+/*
+ * Show arguments used to spawn a pane.
+ */
+
+enum cmd_retval cmd_show_args_exec(struct cmd *, struct cmd_q *);
+
+const struct cmd_entry cmd_show_args_entry = {
+ "show-args", "argv",
+ "", 0, 0,
+ "",
+ 0,
+ NULL,
+ NULL,
+ cmd_show_args_exec
+};
+
+enum cmd_retval
+cmd_show_args_exec(struct cmd *self, struct cmd_q *cmdq)
+{
+ struct args *args = self->args;
+ struct winlink *wl;
+ struct window *w;
+ struct window_pane *wp;
+ struct session *s;
+ struct environ env;
+ const char *cmd;
+ char *cause;
+ u_int idx;
+
+ if ((wl = cmd_find_pane(cmdq, args_get(args, 't'), &s, &wp)) == NULL)
+ return (CMD_RETURN_ERROR);
+
+ cmdq_print(cmdq, "%s", wp->cmd);
+
+ return (CMD_RETURN_NORMAL);
+}
diff --git a/cmd.c b/cmd.c
index eecac46..cfa4144 100644
--- a/cmd.c
+++ b/cmd.c
@@ -85,6 +85,7 @@ const struct cmd_entry *cmd_table[] = {
&cmd_resize_pane_entry,
&cmd_respawn_pane_entry,
&cmd_respawn_window_entry,
+ &cmd_show_args_entry,
&cmd_rotate_window_entry,
&cmd_run_shell_entry,
&cmd_save_buffer_entry,
diff --git a/tmux.h b/tmux.h
index 9c91d6a..82a6756 100644
--- a/tmux.h
+++ b/tmux.h
@@ -1810,6 +1810,7 @@ extern const struct cmd_entry cmd_rename_window_entry;
extern const struct cmd_entry cmd_resize_pane_entry;
extern const struct cmd_entry cmd_respawn_pane_entry;
extern const struct cmd_entry cmd_respawn_window_entry;
+extern const struct cmd_entry cmd_show_args_entry;
extern const struct cmd_entry cmd_rotate_window_entry;
extern const struct cmd_entry cmd_run_shell_entry;
extern const struct cmd_entry cmd_save_buffer_entry;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment