From f3dc38dcae472286c7d7c2708e4dbfe70a6c2d57 Mon Sep 17 00:00:00 2001 From: nicm Date: Fri, 15 Nov 2019 11:16:53 +0000 Subject: [PATCH 1/2] Handle OSC 7 (a VTE extension) and put the result in a new format (pane_path). --- format.c | 1 + input.c | 7 +++++++ screen.c | 8 ++++++++ tmux.1 | 9 +++++---- tmux.h | 2 ++ 5 files changed, 23 insertions(+), 4 deletions(-) diff --git a/format.c b/format.c index 7d8700a6..5804692e 100644 --- a/format.c +++ b/format.c @@ -2267,6 +2267,7 @@ format_defaults_pane(struct format_tree *ft, struct window_pane *wp) format_add(ft, "pane_width", "%u", wp->sx); format_add(ft, "pane_height", "%u", wp->sy); format_add(ft, "pane_title", "%s", wp->base.title); + format_add(ft, "pane_path", "%s", wp->base.path); format_add(ft, "pane_id", "%%%u", wp->id); format_add(ft, "pane_active", "%d", wp == w->active); format_add(ft, "pane_input_off", "%d", !!(wp->flags & PANE_INPUTOFF)); diff --git a/input.c b/input.c index cec46a99..d2c1b8a6 100644 --- a/input.c +++ b/input.c @@ -132,6 +132,7 @@ static void input_set_state(struct window_pane *, static void input_reset_cell(struct input_ctx *); static void input_osc_4(struct input_ctx *, const char *); +static void input_osc_7(struct input_ctx *, const char *); static void input_osc_10(struct input_ctx *, const char *); static void input_osc_11(struct input_ctx *, const char *); static void input_osc_52(struct input_ctx *, const char *); @@ -2211,6 +2212,12 @@ input_exit_osc(struct input_ctx *ictx) case 4: input_osc_4(ictx, p); break; + case 7: + if (utf8_isvalid(p)) { + screen_set_path(sctx->s, p); + server_status_window(ictx->wp->window); + } + break; case 10: input_osc_10(ictx, p); break; diff --git a/screen.c b/screen.c index d24f4ba4..9db0f609 100644 --- a/screen.c +++ b/screen.c @@ -159,6 +159,14 @@ screen_set_title(struct screen *s, const char *title) utf8_stravis(&s->title, title, VIS_OCTAL|VIS_CSTYLE|VIS_TAB|VIS_NL); } +/* Set screen path. */ +void +screen_set_path(struct screen *s, const char *path) +{ + free(s->path); + utf8_stravis(&s->path, path, VIS_OCTAL|VIS_CSTYLE|VIS_TAB|VIS_NL); +} + /* Push the current title onto the stack. */ void screen_push_title(struct screen *s) diff --git a/tmux.1 b/tmux.1 index 3fb01ee4..e617ec61 100644 --- a/tmux.1 +++ b/tmux.1 @@ -4267,7 +4267,7 @@ The following variables are available, where appropriate: .It Li "pane_current_command" Ta "" Ta "Current command if available" .It Li "pane_dead" Ta "" Ta "1 if pane is dead" .It Li "pane_dead_status" Ta "" Ta "Exit status of process in dead pane" -.It Li "pane_format" Ta "" Ta "1 if format is for a pane (not assuming the current)" +.It Li "pane_format" Ta "" Ta "1 if format is for a pane" .It Li "pane_height" Ta "" Ta "Height of pane" .It Li "pane_id" Ta "#D" Ta "Unique pane ID" .It Li "pane_in_mode" Ta "" Ta "1 if pane is in a mode" @@ -4277,6 +4277,7 @@ The following variables are available, where appropriate: .It Li "pane_marked" Ta "" Ta "1 if this is the marked pane" .It Li "pane_marked_set" Ta "" Ta "1 if a marked pane is set" .It Li "pane_mode" Ta "" Ta "Name of pane mode, if any" +.It Li "pane_path" Ta "#T" Ta "Path of pane (can be set by application)" .It Li "pane_pid" Ta "" Ta "PID of first process in pane" .It Li "pane_pipe" Ta "" Ta "1 if pane is being piped" .It Li "pane_right" Ta "" Ta "Right of pane" @@ -4284,7 +4285,7 @@ The following variables are available, where appropriate: .It Li "pane_start_command" Ta "" Ta "Command pane started with" .It Li "pane_synchronized" Ta "" Ta "1 if pane is synchronized" .It Li "pane_tabs" Ta "" Ta "Pane tab positions" -.It Li "pane_title" Ta "#T" Ta "Title of pane" +.It Li "pane_title" Ta "#T" Ta "Title of pane (can be set by application)" .It Li "pane_top" Ta "" Ta "Top of pane" .It Li "pane_tty" Ta "" Ta "Pseudo terminal of pane" .It Li "pane_width" Ta "" Ta "Width of pane" @@ -4302,7 +4303,7 @@ The following variables are available, where appropriate: .It Li "session_alerts" Ta "" Ta "List of window indexes with alerts" .It Li "session_attached" Ta "" Ta "Number of clients session is attached to" .It Li "session_created" Ta "" Ta "Time session created" -.It Li "session_format" Ta "" Ta "1 if format is for a session (not assuming the current)" +.It Li "session_format" Ta "" Ta "1 if format is for a session" .It Li "session_group" Ta "" Ta "Name of session group" .It Li "session_group_list" Ta "" Ta "List of sessions in group" .It Li "session_group_size" Ta "" Ta "Size of session group" @@ -4322,7 +4323,7 @@ The following variables are available, where appropriate: .It Li "window_bigger" Ta "" Ta "1 if window is larger than client" .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_format" Ta "" Ta "1 if format is for a window (not assuming the current)" +.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" .It Li "window_index" Ta "#I" Ta "Index of window" diff --git a/tmux.h b/tmux.h index 894a9820..ac57dbf3 100644 --- a/tmux.h +++ b/tmux.h @@ -706,6 +706,7 @@ struct screen_sel; struct screen_titles; struct screen { char *title; + char *path; struct screen_titles *titles; struct grid *grid; /* grid data */ @@ -2359,6 +2360,7 @@ void screen_reset_tabs(struct screen *); void screen_set_cursor_style(struct screen *, u_int); void screen_set_cursor_colour(struct screen *, const char *); void screen_set_title(struct screen *, const char *); +void screen_set_path(struct screen *, const char *); void screen_push_title(struct screen *); void screen_pop_title(struct screen *); void screen_resize(struct screen *, u_int, u_int, int); From 5dfe9db78820aedd5d4dfe60728e871f935bff36 Mon Sep 17 00:00:00 2001 From: nicm Date: Fri, 15 Nov 2019 11:21:32 +0000 Subject: [PATCH 2/2] Do not add path if it is NULL, duh. --- format.c | 3 ++- input.c | 1 - 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/format.c b/format.c index 5804692e..71d4e116 100644 --- a/format.c +++ b/format.c @@ -2267,7 +2267,8 @@ format_defaults_pane(struct format_tree *ft, struct window_pane *wp) format_add(ft, "pane_width", "%u", wp->sx); format_add(ft, "pane_height", "%u", wp->sy); format_add(ft, "pane_title", "%s", wp->base.title); - format_add(ft, "pane_path", "%s", wp->base.path); + if (wp->base.path != NULL) + format_add(ft, "pane_path", "%s", wp->base.path); format_add(ft, "pane_id", "%%%u", wp->id); format_add(ft, "pane_active", "%d", wp == w->active); format_add(ft, "pane_input_off", "%d", !!(wp->flags & PANE_INPUTOFF)); diff --git a/input.c b/input.c index d2c1b8a6..96fd5d33 100644 --- a/input.c +++ b/input.c @@ -132,7 +132,6 @@ static void input_set_state(struct window_pane *, static void input_reset_cell(struct input_ctx *); static void input_osc_4(struct input_ctx *, const char *); -static void input_osc_7(struct input_ctx *, const char *); static void input_osc_10(struct input_ctx *, const char *); static void input_osc_11(struct input_ctx *, const char *); static void input_osc_52(struct input_ctx *, const char *);