Merge branch '3088_terminal_cwd'

* 3088_terminal_cwd:
  Use ESC_STR macro in escape sequences.
  (update_xterm_title_path): change the escape sequence's terminator
  Ticket #3088: tell the current directory to the terminal
This commit is contained in:
Andrew Borodin 2024-02-11 19:28:07 +03:00
commit 6b44fce839
4 changed files with 30 additions and 1 deletions

View File

@ -373,6 +373,7 @@ do_executev (const char *shell, int flags, char *const argv[])
{ {
update_panels (UP_OPTIMIZE, UP_KEEPSEL); update_panels (UP_OPTIMIZE, UP_KEEPSEL);
update_xterm_title_path (); update_xterm_title_path ();
update_terminal_cwd ();
} }
do_refresh (); do_refresh ();
@ -567,6 +568,7 @@ toggle_subshell (void)
{ {
update_panels (UP_OPTIMIZE, UP_KEEPSEL); update_panels (UP_OPTIMIZE, UP_KEEPSEL);
update_xterm_title_path (); update_xterm_title_path ();
update_terminal_cwd ();
} }
if (was_sigwinch != 0 || tty_got_winch ()) if (was_sigwinch != 0 || tty_got_winch ())

View File

@ -913,6 +913,7 @@ setup_panels (void)
widget_set_visibility (WIDGET (the_bar), mc_global.keybar_visible); widget_set_visibility (WIDGET (the_bar), mc_global.keybar_visible);
update_xterm_title_path (); update_xterm_title_path ();
update_terminal_cwd ();
/* unlock */ /* unlock */
if (active) if (active)
@ -1567,7 +1568,7 @@ update_xterm_title_path (void)
g_free (login); g_free (login);
g_free (path); g_free (path);
fprintf (stdout, "\33]0;%s\7", str_term_form (p)); fprintf (stdout, ESC_STR "]0;%s" ESC_STR "\\", str_term_form (p));
g_free (p); g_free (p);
if (!mc_global.tty.alternate_plus_minus) if (!mc_global.tty.alternate_plus_minus)
@ -1577,3 +1578,26 @@ update_xterm_title_path (void)
} }
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */
/** Tell the current directory to the terminal so it can open new tabs there */
void
update_terminal_cwd (void)
{
if (mc_global.tty.xterm_flag && vfs_current_is_local ())
{
const gchar *host;
char *path, *path_uri;
host = g_get_host_name ();
path = vfs_path_to_str_flags (current_panel->cwd_vpath, 0, VPF_NONE);
path_uri = g_uri_escape_string (path, "/", FALSE);
fprintf (stdout, ESC_STR "]7;file://%s%s" ESC_STR "\\", host, path_uri);
(void) fflush (stdout);
g_free (path_uri);
g_free (path);
}
}
/* --------------------------------------------------------------------------------------------- */

View File

@ -90,6 +90,7 @@ int load_prompt (int fd, void *unused);
#endif #endif
void update_xterm_title_path (void); void update_xterm_title_path (void);
void update_terminal_cwd (void);
void title_path_prepare (char **path, char **login); void title_path_prepare (char **path, char **login);

View File

@ -3436,6 +3436,7 @@ panel_do_cd_int (WPanel * panel, const vfs_path_t * new_dir_vpath, enum cd_enum
load_hint (FALSE); load_hint (FALSE);
panel->dirty = TRUE; panel->dirty = TRUE;
update_xterm_title_path (); update_xterm_title_path ();
update_terminal_cwd ();
vfs_path_free (olddir_vpath, TRUE); vfs_path_free (olddir_vpath, TRUE);
@ -3823,6 +3824,7 @@ panel_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *d
subshell_chdir (panel->cwd_vpath); subshell_chdir (panel->cwd_vpath);
update_xterm_title_path (); update_xterm_title_path ();
update_terminal_cwd ();
select_item (panel); select_item (panel);
bb = buttonbar_find (h); bb = buttonbar_find (h);