summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornicm <nicm>2021-01-20 07:16:54 +0000
committernicm <nicm>2021-01-20 07:16:54 +0000
commitfb774b77d0f5ccb988b508b8a794633d4c9a5962 (patch)
tree6af7eebc80363f6d5e2c05ce7b1aae8796477842
parent0730dce5abf5e43f8e3820a1d4e8754e61874a3d (diff)
Change so that window_flags escapes # automatically which means configs
will not have to change. A new format window_raw_flags contains the old unescaped version.
-rw-r--r--cmd-list-windows.c4
-rw-r--r--control-notify.c2
-rw-r--r--format.c30
-rw-r--r--options-table.c4
-rw-r--r--tmux.17
-rw-r--r--tmux.h2
-rw-r--r--window.c7
7 files changed, 31 insertions, 25 deletions
diff --git a/cmd-list-windows.c b/cmd-list-windows.c
index 9c33c2d0..d6cc0b7a 100644
--- a/cmd-list-windows.c
+++ b/cmd-list-windows.c
@@ -28,14 +28,14 @@
*/
#define LIST_WINDOWS_TEMPLATE \
- "#{window_index}: #{window_name}#{window_flags} " \
+ "#{window_index}: #{window_name}#{window_raw_flags} " \
"(#{window_panes} panes) " \
"[#{window_width}x#{window_height}] " \
"[layout #{window_layout}] #{window_id}" \
"#{?window_active, (active),}";
#define LIST_WINDOWS_WITH_SESSION_TEMPLATE \
"#{session_name}:" \
- "#{window_index}: #{window_name}#{window_flags} " \
+ "#{window_index}: #{window_name}#{window_raw_flags} " \
"(#{window_panes} panes) " \
"[#{window_width}x#{window_height}] "
diff --git a/control-notify.c b/control-notify.c
index a1735d57..cc706ac2 100644
--- a/control-notify.c
+++ b/control-notify.c
@@ -49,7 +49,7 @@ control_notify_window_layout_changed(struct window *w)
char *cp;
template = "%layout-change #{window_id} #{window_layout} "
- "#{window_visible_layout} #{window_flags}";
+ "#{window_visible_layout} #{window_raw_flags}";
TAILQ_FOREACH(c, &clients, entry) {
if (!CONTROL_SHOULD_NOTIFY_CLIENT(c) || c->session == NULL)
diff --git a/format.c b/format.c
index 2d7402af..df1898a6 100644
--- a/format.c
+++ b/format.c
@@ -89,7 +89,7 @@ format_job_cmp(struct format_job *fj1, struct format_job *fj2)
#define FORMAT_TIMESTRING 0x1
#define FORMAT_BASENAME 0x2
#define FORMAT_DIRNAME 0x4
-#define FORMAT_QUOTE 0x8
+#define FORMAT_QUOTE_SHELL 0x8
#define FORMAT_LITERAL 0x10
#define FORMAT_EXPAND 0x20
#define FORMAT_EXPANDTIME 0x40
@@ -99,7 +99,7 @@ format_job_cmp(struct format_job *fj1, struct format_job *fj2)
#define FORMAT_PRETTY 0x400
#define FORMAT_LENGTH 0x800
#define FORMAT_WIDTH 0x1000
-#define FORMAT_ESCAPE 0x2000
+#define FORMAT_QUOTE_STYLE 0x2000
/* Limit on recursion. */
#define FORMAT_LOOP_LIMIT 10
@@ -1378,9 +1378,9 @@ format_add_cb(struct format_tree *ft, const char *key, format_cb cb)
fe->value = NULL;
}
-/* Quote special characters in string. */
+/* Quote shell special characters in string. */
static char *
-format_quote(const char *s)
+format_quote_shell(const char *s)
{
const char *cp;
char *out, *at;
@@ -1395,9 +1395,9 @@ format_quote(const char *s)
return (out);
}
-/* Escape #s in string. */
+/* Quote #s in string. */
static char *
-format_escape(const char *s)
+format_quote_style(const char *s)
{
const char *cp;
char *out, *at;
@@ -1552,14 +1552,14 @@ found:
found = xstrdup(dirname(saved));
free(saved);
}
- if (modifiers & FORMAT_QUOTE) {
+ if (modifiers & FORMAT_QUOTE_SHELL) {
saved = found;
- found = xstrdup(format_quote(saved));
+ found = xstrdup(format_quote_shell(saved));
free(saved);
}
- if (modifiers & FORMAT_ESCAPE) {
+ if (modifiers & FORMAT_QUOTE_STYLE) {
saved = found;
- found = xstrdup(format_escape(saved));
+ found = xstrdup(format_quote_style(saved));
free(saved);
}
return (found);
@@ -2240,9 +2240,10 @@ format_replace(struct format_expand_state *es, const char *key, size_t keylen,
break;
case 'q':
if (fm->argc < 1)
- modifiers |= FORMAT_QUOTE;
- else if (strchr(fm->argv[0], 'e') != NULL)
- modifiers |= FORMAT_ESCAPE;
+ modifiers |= FORMAT_QUOTE_SHELL;
+ else if (strchr(fm->argv[0], 'e') != NULL ||
+ strchr(fm->argv[0], 'h') != NULL)
+ modifiers |= FORMAT_QUOTE_STYLE;
break;
case 'E':
modifiers |= FORMAT_EXPAND;
@@ -2980,7 +2981,8 @@ format_defaults_winlink(struct format_tree *ft, struct winlink *wl)
format_add(ft, "window_index", "%d", wl->idx);
format_add_cb(ft, "window_stack_index", format_cb_window_stack_index);
- format_add(ft, "window_flags", "%s", window_printable_flags(wl));
+ format_add(ft, "window_flags", "%s", window_printable_flags(wl, 1));
+ format_add(ft, "window_raw_flags", "%s", window_printable_flags(wl, 0));
format_add(ft, "window_active", "%d", wl == s->curw);
format_add_cb(ft, "window_active_sessions",
format_cb_window_active_sessions);
diff --git a/options-table.c b/options-table.c
index a8276c86..74a59134 100644
--- a/options-table.c
+++ b/options-table.c
@@ -1018,7 +1018,7 @@ const struct options_table_entry options_table[] = {
{ .name = "window-status-current-format",
.type = OPTIONS_TABLE_STRING,
.scope = OPTIONS_TABLE_WINDOW,
- .default_str = "#I:#W#{?window_flags,#{q/e:window_flags}, }",
+ .default_str = "#I:#W#{?window_flags,#{window_flags}, }",
.text = "Format of the current window in the status line."
},
@@ -1034,7 +1034,7 @@ const struct options_table_entry options_table[] = {
{ .name = "window-status-format",
.type = OPTIONS_TABLE_STRING,
.scope = OPTIONS_TABLE_WINDOW,
- .default_str = "#I:#W#{?window_flags,#{q/e:window_flags}, }",
+ .default_str = "#I:#W#{?window_flags,#{window_flags}, }",
.text = "Format of windows in the status line, except the current "
"window."
},
diff --git a/tmux.1 b/tmux.1
index 93842482..8c812f38 100644
--- a/tmux.1
+++ b/tmux.1
@@ -4651,8 +4651,8 @@ of the variable respectively.
.Ql q:\&
will escape
.Xr sh 1
-special characters or with an
-.Ql e
+special characters or with a
+.Ql h
suffix, escape hash characters (so
.Ql #
becomes
@@ -4882,7 +4882,8 @@ The following variables are available, where appropriate:
.It Li "window_cell_height" Ta "" Ta "Height of each cell in pixels"
.It Li "window_cell_width" Ta "" Ta "Width of each cell in pixels"
.It Li "window_end_flag" Ta "" Ta "1 if window has the highest index"
-.It Li "window_flags" Ta "#F" Ta "Window flags"
+.It Li "window_flags" Ta "#F" Ta "Window flags with # escaped as ##"
+.It Li "window_raw_flags" Ta "" Ta "Window flags with nothing escaped"
.It Li "window_format" Ta "" Ta "1 if format is for a window"
.It Li "window_height" Ta "" Ta "Height of window"
.It Li "window_id" Ta "" Ta "Unique window ID"
diff --git a/tmux.h b/tmux.h
index 32f7fec7..c593a175 100644
--- a/tmux.h
+++ b/tmux.h
@@ -2761,7 +2761,7 @@ int window_pane_key(struct window_pane *, struct client *,
int window_pane_visible(struct window_pane *);
u_int window_pane_search(struct window_pane *, const char *, int,
int);
-const char *window_printable_flags(struct winlink *);
+const char *window_printable_flags(struct winlink *, int);
struct window_pane *window_pane_find_up(struct window_pane *);
struct window_pane *window_pane_find_down(struct window_pane *);
struct window_pane *window_pane_find_left(struct window_pane *);
diff --git a/window.c b/window.c
index 22986a04..6bfdb1cd 100644
--- a/window.c
+++ b/window.c
@@ -803,15 +803,18 @@ window_destroy_panes(struct window *w)
}
const char *
-window_printable_flags(struct winlink *wl)
+window_printable_flags(struct winlink *wl, int escape)
{
struct session *s = wl->session;
static char flags[32];
int pos;
pos = 0;
- if (wl->flags & WINLINK_ACTIVITY)
+ if (wl->flags & WINLINK_ACTIVITY) {
flags[pos++] = '#';
+ if (escape)
+ flags[pos++] = '#';
+ }
if (wl->flags & WINLINK_BELL)
flags[pos++] = '!';
if (wl->flags & WINLINK_SILENCE)