Skip to content

Commit

Permalink
Merge branch '3088_terminal_cwd'
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
aborodin committed Feb 11, 2024
2 parents dc1aa3e + c3ffd4a commit 6b44fce
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/execute.c
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,7 @@ do_executev (const char *shell, int flags, char *const argv[])
{
update_panels (UP_OPTIMIZE, UP_KEEPSEL);
update_xterm_title_path ();
update_terminal_cwd ();
}

do_refresh ();
Expand Down Expand Up @@ -567,6 +568,7 @@ toggle_subshell (void)
{
update_panels (UP_OPTIMIZE, UP_KEEPSEL);
update_xterm_title_path ();
update_terminal_cwd ();
}

if (was_sigwinch != 0 || tty_got_winch ())
Expand Down
26 changes: 25 additions & 1 deletion src/filemanager/layout.c
Original file line number Diff line number Diff line change
Expand Up @@ -913,6 +913,7 @@ setup_panels (void)
widget_set_visibility (WIDGET (the_bar), mc_global.keybar_visible);

update_xterm_title_path ();
update_terminal_cwd ();

/* unlock */
if (active)
Expand Down Expand Up @@ -1567,7 +1568,7 @@ update_xterm_title_path (void)
g_free (login);
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);

if (!mc_global.tty.alternate_plus_minus)
Expand All @@ -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);
}
}

/* --------------------------------------------------------------------------------------------- */
1 change: 1 addition & 0 deletions src/filemanager/layout.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ int load_prompt (int fd, void *unused);
#endif

void update_xterm_title_path (void);
void update_terminal_cwd (void);

void title_path_prepare (char **path, char **login);

Expand Down
2 changes: 2 additions & 0 deletions src/filemanager/panel.c
Original file line number Diff line number Diff line change
Expand Up @@ -3436,6 +3436,7 @@ panel_do_cd_int (WPanel * panel, const vfs_path_t * new_dir_vpath, enum cd_enum
load_hint (FALSE);
panel->dirty = TRUE;
update_xterm_title_path ();
update_terminal_cwd ();

vfs_path_free (olddir_vpath, TRUE);

Expand Down Expand Up @@ -3823,6 +3824,7 @@ panel_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *d
subshell_chdir (panel->cwd_vpath);

update_xterm_title_path ();
update_terminal_cwd ();
select_item (panel);

bb = buttonbar_find (h);
Expand Down

0 comments on commit 6b44fce

Please sign in to comment.