cmd-list-buffers.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /* $OpenBSD$ */
  2. /*
  3. * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
  4. *
  5. * Permission to use, copy, modify, and distribute this software for any
  6. * purpose with or without fee is hereby granted, provided that the above
  7. * copyright notice and this permission notice appear in all copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  10. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  11. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  12. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  13. * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
  14. * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
  15. * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  16. */
  17. #include <sys/types.h>
  18. #include <stdlib.h>
  19. #include <string.h>
  20. #include "tmux.h"
  21. /*
  22. * List paste buffers.
  23. */
  24. #define LIST_BUFFERS_TEMPLATE \
  25. "#{buffer_name}: #{buffer_size} bytes: \"#{buffer_sample}\""
  26. enum cmd_retval cmd_list_buffers_exec(struct cmd *, struct cmd_q *);
  27. const struct cmd_entry cmd_list_buffers_entry = {
  28. .name = "list-buffers",
  29. .alias = "lsb",
  30. .args = { "F:", 0, 0 },
  31. .usage = "[-F format]",
  32. .flags = 0,
  33. .exec = cmd_list_buffers_exec
  34. };
  35. enum cmd_retval
  36. cmd_list_buffers_exec(struct cmd *self, struct cmd_q *cmdq)
  37. {
  38. struct args *args = self->args;
  39. struct paste_buffer *pb;
  40. struct format_tree *ft;
  41. char *line;
  42. const char *template;
  43. if ((template = args_get(args, 'F')) == NULL)
  44. template = LIST_BUFFERS_TEMPLATE;
  45. pb = NULL;
  46. while ((pb = paste_walk(pb)) != NULL) {
  47. ft = format_create(cmdq, 0);
  48. format_defaults_paste_buffer(ft, pb);
  49. line = format_expand(ft, template);
  50. cmdq_print(cmdq, "%s", line);
  51. free(line);
  52. format_free(ft);
  53. }
  54. return (CMD_RETURN_NORMAL);
  55. }