On Wed, Jan 30, 2013 at 09:42:24PM -0300, Thiago Padilha wrote:
> Hi
>
> I have a shell function that accepts a pane id as argument. This function
> works fine when invoked interactively:
>
> $ shell_function $TMUX_PANE
>
> I would like to invoke this function from any pane, running a interactive
> shell or not, by binding this function to a key combination, however I
> can't figure out how to send the the focused pane id to the function.
>
> On the man page I read that some tmux commands accept a format string that
> can expand to information about tmux(including the current pane id) so I
> tried this(to no success, it seems run-shell doesn't expand the format
> string):
>
> run-shell 'shell_function #{pane_id}'
>
> Any tip on how I may accomplish this?
See the attached patch.
Note that this is ripped out of my on-going work for hook-support (and
tweaked a little to work on top of current tmux code).
It is not intended for submission to tmux since my work on hook-support will
obsolete it. Hence why there's no man page entries, etc.
-- Thomas Adam
commit 01130918229c394e39f29797db20203afe12b69e
Author: Thomas Adam <tho...@xteddy.org>
Date: Thu Jan 31 01:08:56 2013 +0000
Crude format additions for run-shell
Ripped this out of my hook-support work.
diff --git a/cmd-run-shell.c b/cmd-run-shell.c
index 44e796d..730e213 100644
--- a/cmd-run-shell.c
+++ b/cmd-run-shell.c
@@ -75,23 +75,40 @@ cmd_run_shell_exec(struct cmd *self, struct cmd_ctx *ctx)
{
struct args *args = self->args;
struct cmd_run_shell_data *cdata;
- const char *shellcmd = args->argv[0];
+ const char *shellcmd;
+ char *shellcmd_run;
struct window_pane *wp;
+ struct format_tree *ft;
+ struct session *s;
- if (cmd_find_pane(ctx, args_get(args, 't'), NULL, &wp) == NULL)
+ if (cmd_find_pane(ctx, args_get(args, 't'), &s, &wp) == NULL)
return (CMD_RETURN_ERROR);
cdata = xmalloc(sizeof *cdata);
- cdata->cmd = xstrdup(args->argv[0]);
cdata->wp_id = wp->id;
memcpy(&cdata->ctx, ctx, sizeof cdata->ctx);
+ shellcmd = args->argv[0];
+ ft = format_create();
+
if (ctx->cmdclient != NULL)
ctx->cmdclient->references++;
- if (ctx->curclient != NULL)
+ if (ctx->curclient != NULL) {
ctx->curclient->references++;
+ format_client(ft, ctx->curclient);
+ }
+
+ if (s != NULL)
+ format_session(ft, s);
+
+ format_window_pane(ft, wp);
+
+ shellcmd_run = format_expand(ft, shellcmd);
+
+ cdata->cmd = xstrdup(shellcmd_run);
+ job_run(shellcmd_run, cmd_run_shell_callback, cmd_run_shell_free, cdata);
- job_run(shellcmd, cmd_run_shell_callback, cmd_run_shell_free, cdata);
+ format_free(ft);
return (CMD_RETURN_YIELD); /* don't let client exit */
}
------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_jan
_______________________________________________
tmux-users mailing list
tmux-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tmux-users