From 1cb1fb5bd401cf26568a2dc480a8548af3b43930 Mon Sep 17 00:00:00 2001 From: Nicholas Marriott Date: Mon, 4 Mar 2013 09:00:24 +0000 Subject: [PATCH] Add -q flags to shut up errors to capture-pane and show-options, from George Nachman. --- cmd-capture-pane.c | 91 ++++++++++++++++++++++++---------------------- cmd-show-options.c | 20 ++++++---- tmux.1 | 12 +++++- 3 files changed, 70 insertions(+), 53 deletions(-) diff --git a/cmd-capture-pane.c b/cmd-capture-pane.c index a6767141..118bf946 100644 --- a/cmd-capture-pane.c +++ b/cmd-capture-pane.c @@ -31,8 +31,8 @@ enum cmd_retval cmd_capture_pane_exec(struct cmd *, struct cmd_q *); const struct cmd_entry cmd_capture_pane_entry = { "capture-pane", "capturep", - "ab:CeE:JpS:t:", 0, 0, - "[-aCeJp] [-b buffer-index] [-E end-line] [-S start-line]" + "ab:CeE:JpqS:t:", 0, 0, + "[-aCeJpq] [-b buffer-index] [-E end-line] [-S start-line]" CMD_TARGET_PANE_USAGE, 0, NULL, @@ -62,7 +62,7 @@ cmd_capture_pane_exec(struct cmd *self, struct cmd_q *cmdq) s = NULL; gd = wp->saved_grid; sx = screen_size_x(&wp->base); - if (gd == NULL) { + if (gd == NULL && !args_has(args, 'q')) { cmdq_error(cmdq, "no alternate screen"); return (CMD_RETURN_ERROR); } @@ -75,54 +75,57 @@ cmd_capture_pane_exec(struct cmd *self, struct cmd_q *cmdq) buf = NULL; len = 0; - n = args_strtonum(args, 'S', INT_MIN, SHRT_MAX, &cause); - if (cause != NULL) { - top = gd->hsize; - free(cause); - } else if (n < 0 && (u_int) -n > gd->hsize) - top = 0; - else - top = gd->hsize + n; - if (top > gd->hsize + gd->sy - 1) - top = gd->hsize + gd->sy - 1; + if (gd != NULL) { + n = args_strtonum(args, 'S', INT_MIN, SHRT_MAX, &cause); + if (cause != NULL) { + top = gd->hsize; + free(cause); + } else if (n < 0 && (u_int) -n > gd->hsize) + top = 0; + else + top = gd->hsize + n; + if (top > gd->hsize + gd->sy - 1) + top = gd->hsize + gd->sy - 1; - n = args_strtonum(args, 'E', INT_MIN, SHRT_MAX, &cause); - if (cause != NULL) { - bottom = gd->hsize + gd->sy - 1; - free(cause); - } else if (n < 0 && (u_int) -n > gd->hsize) - bottom = 0; - else - bottom = gd->hsize + n; - if (bottom > gd->hsize + gd->sy - 1) - bottom = gd->hsize + gd->sy - 1; + n = args_strtonum(args, 'E', INT_MIN, SHRT_MAX, &cause); + if (cause != NULL) { + bottom = gd->hsize + gd->sy - 1; + free(cause); + } else if (n < 0 && (u_int) -n > gd->hsize) + bottom = 0; + else + bottom = gd->hsize + n; + if (bottom > gd->hsize + gd->sy - 1) + bottom = gd->hsize + gd->sy - 1; - if (bottom < top) { - tmp = bottom; - bottom = top; - top = tmp; - } + if (bottom < top) { + tmp = bottom; + bottom = top; + top = tmp; + } - with_codes = args_has(args, 'e'); - escape_c0 = args_has(args, 'C'); - join_lines = args_has(args, 'J'); + with_codes = args_has(args, 'e'); + escape_c0 = args_has(args, 'C'); + join_lines = args_has(args, 'J'); - gc = NULL; - for (i = top; i <= bottom; i++) { - line = grid_string_cells(gd, 0, i, sx, &gc, with_codes, - escape_c0); - linelen = strlen(line); + gc = NULL; + for (i = top; i <= bottom; i++) { + line = grid_string_cells(gd, 0, i, sx, &gc, with_codes, + escape_c0); + linelen = strlen(line); - buf = xrealloc(buf, 1, len + linelen + 1); - memcpy(buf + len, line, linelen); - len += linelen; + buf = xrealloc(buf, 1, len + linelen + 1); + memcpy(buf + len, line, linelen); + len += linelen; - gl = grid_peek_line(gd, i); - if (!join_lines || !(gl->flags & GRID_LINE_WRAPPED)) - buf[len++] = '\n'; + gl = grid_peek_line(gd, i); + if (!join_lines || !(gl->flags & GRID_LINE_WRAPPED)) + buf[len++] = '\n'; - free(line); - } + free(line); + } + } else + buf = xstrdup(""); if (args_has(args, 'p')) { c = cmdq->client; diff --git a/cmd-show-options.c b/cmd-show-options.c index 2770bd4f..e2f78e12 100644 --- a/cmd-show-options.c +++ b/cmd-show-options.c @@ -30,14 +30,14 @@ enum cmd_retval cmd_show_options_exec(struct cmd *, struct cmd_q *); enum cmd_retval cmd_show_options_one(struct cmd *, struct cmd_q *, - struct options *); + struct options *, int); enum cmd_retval cmd_show_options_all(struct cmd *, struct cmd_q *, const struct options_table_entry *, struct options *); const struct cmd_entry cmd_show_options_entry = { "show-options", "show", - "gst:vw", 0, 1, - "[-gsvw] [-t target-session|target-window] [option]", + "gqst:vw", 0, 1, + "[-gqsvw] [-t target-session|target-window] [option]", 0, NULL, NULL, @@ -62,6 +62,7 @@ cmd_show_options_exec(struct cmd *self, struct cmd_q *cmdq) struct winlink *wl; const struct options_table_entry *table; struct options *oo; + int quiet; if (args_has(self->args, 's')) { oo = &global_options; @@ -89,15 +90,16 @@ cmd_show_options_exec(struct cmd *self, struct cmd_q *cmdq) } } - if (args->argc != 0) - return (cmd_show_options_one(self, cmdq, oo)); - else + quiet = args_has(self->args, 'q'); + if (args->argc == 0) return (cmd_show_options_all(self, cmdq, table, oo)); + else + return (cmd_show_options_one(self, cmdq, oo, quiet)); } enum cmd_retval cmd_show_options_one(struct cmd *self, struct cmd_q *cmdq, - struct options *oo) + struct options *oo, int quiet) { struct args *args = self->args; const struct options_table_entry *table, *oe; @@ -106,6 +108,8 @@ cmd_show_options_one(struct cmd *self, struct cmd_q *cmdq, if (*args->argv[0] == '@') { if ((o = options_find1(oo, args->argv[0])) == NULL) { + if (quiet) + return (CMD_RETURN_NORMAL); cmdq_error(cmdq, "unknown option: %s", args->argv[0]); return (CMD_RETURN_ERROR); } @@ -122,6 +126,8 @@ cmd_show_options_one(struct cmd *self, struct cmd_q *cmdq, return (CMD_RETURN_ERROR); } if (oe == NULL) { + if (quiet) + return (CMD_RETURN_NORMAL); cmdq_error(cmdq, "unknown option: %s", args->argv[0]); return (CMD_RETURN_ERROR); } diff --git a/tmux.1 b/tmux.1 index 60877006..a094d58b 100644 --- a/tmux.1 +++ b/tmux.1 @@ -1066,7 +1066,7 @@ By default, it uses the format but a different format may be specified with .Fl F . .It Xo Ic capture-pane -.Op Fl aep +.Op Fl aepq .Op Fl b Ar buffer-index .Op Fl E Ar end-line .Op Fl S Ar start-line @@ -1082,6 +1082,9 @@ or a new buffer if omitted. If .Fl a is given, the alternate screen is used, and the history is not accessible. +If no alternate screen exists, an error will be returned unless +.Fl q +is given. If .Fl e is given, the output includes escape sequences for text and background @@ -2952,7 +2955,7 @@ If this option is set, searches will wrap around the end of the pane contents. The default is on. .El .It Xo Ic show-options -.Op Fl gsvw +.Op Fl gqsvw .Op Fl t Ar target-session | Ar target-window .Op Ar option .Xc @@ -2970,6 +2973,11 @@ Global session or window options are listed if is used. .Fl v shows only the option value, not the name. +If +.Fl q +is set, no error will be returned if +.Ar option +is unset. .It Xo Ic show-window-options .Op Fl gv .Op Fl t Ar target-window