In HEAD you can do tmux saveb -.

On Tue, May 10, 2011 at 06:12:28PM +0200, Pierre Habouzit wrote:
> use-case:  save-buffer "|xclip"
> 
> Signed-off-by: Pierre Habouzit <madco...@debian.org>
> ---
>  cmd-save-buffer.c |   15 ++++++++++++---
>  tmux.1            |    6 ++++++
>  2 files changed, 18 insertions(+), 3 deletions(-)
> 
> diff --git a/cmd-save-buffer.c b/cmd-save-buffer.c
> index d7b7738..a45fe43 100644
> --- a/cmd-save-buffer.c
> +++ b/cmd-save-buffer.c
> @@ -51,6 +51,7 @@ cmd_save_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
>       int                      buffer;
>       mode_t                   mask;
>       FILE                    *f;
> +     int                      is_cmd = 0;
>  
>       if (!args_has(args, 'b')) {
>               if ((pb = paste_get_top(&global_buffers)) == NULL) {
> @@ -81,7 +82,10 @@ cmd_save_buffer_exec(struct cmd *self, struct cmd_ctx *ctx)
>               bufferevent_write(c->stdout_event, pb->data, pb->size);
>       } else {
>               mask = umask(S_IRWXG | S_IRWXO);
> -             if (args_has(self->args, 'a'))
> +             if (*path == '|') {
> +                     is_cmd = 1;
> +                     f = popen(++path, "w");
> +             } else if (args_has(self->args, 'a'))
>                       f = fopen(path, "ab");
>               else
>                       f = fopen(path, "wb");
> @@ -92,10 +96,15 @@ cmd_save_buffer_exec(struct cmd *self, struct cmd_ctx 
> *ctx)
>               }
>               if (fwrite(pb->data, 1, pb->size, f) != pb->size) {
>                       ctx->error(ctx, "%s: fwrite error", path);
> -                     fclose(f);
> +                     if (is_cmd)
> +                             pclose(f);
> +                     else
> +                             fclose(f);
>                       return (-1);
>               }
> -             fclose(f);
> +             if (is_cmd ? pclose(f) : fclose(f)) {
> +                     ctx->error(ctx, "%s: fclose error", path);
> +             }
>       }
>  
>       return (0);
> diff --git a/tmux.1 b/tmux.1
> index d0a92a5..665dc51 100644
> --- a/tmux.1
> +++ b/tmux.1
> @@ -2750,6 +2750,12 @@ flag means to do no replacement (equivalent to a 
> separator of LF).
>  .D1 (alias: Ic saveb )
>  Save the contents of the specified paste buffer to
>  .Ar path .
> +If
> +.Ar path
> +starts with a pipe | then
> +.Ar path
> +is understood as a command run with
> +.Xr popen 3 .
>  The
>  .Fl a
>  option appends to rather than overwriting the file.
> -- 
> 1.7.5.1.290.g2095dc
> 
> 
> ------------------------------------------------------------------------------
> Achieve unprecedented app performance and reliability
> What every C/C++ and Fortran developer should know.
> Learn how Intel has extended the reach of its next-generation tools
> to help boost performance applications - inlcuding clusters.
> http://p.sf.net/sfu/intel-dev2devmay
> _______________________________________________
> tmux-users mailing list
> tmux-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/tmux-users

------------------------------------------------------------------------------
Achieve unprecedented app performance and reliability
What every C/C++ and Fortran developer should know.
Learn how Intel has extended the reach of its next-generation tools
to help boost performance applications - inlcuding clusters.
http://p.sf.net/sfu/intel-dev2devmay
_______________________________________________
tmux-users mailing list
tmux-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/tmux-users

Reply via email to