diff --git a/src/filemanager/midnight.c b/src/filemanager/midnight.c index d797e6ff6..ed5e8af43 100644 --- a/src/filemanager/midnight.c +++ b/src/filemanager/midnight.c @@ -429,36 +429,18 @@ midnight_get_shortcut (unsigned long command) static char * midnight_get_title (const Dlg_head * h, size_t len) { - /* TODO: share code with update_xterm_title_path() */ - - char *path_origin, *p; char *path; - char host[BUF_TINY]; - struct passwd *pw = NULL; - char *login = NULL; - int res = 0; + char *login; + char *p; (void) h; - path_origin = - vfs_path_to_str_flags (current_panel->cwd_vpath, 0, VPF_STRIP_HOME | VPF_STRIP_PASSWORD); + title_path_prepare (&path, &login); - res = gethostname (host, sizeof (host)); - if (res != 0) - host[0] = '\0'; - else - host[sizeof (host) - 1] = '\0'; - - pw = getpwuid (getuid ()); - if (pw != NULL) - login = g_strdup_printf ("%s@%s", pw->pw_name, host); - else - login = g_strdup (host); - - p = g_strdup_printf ("%s [%s]:%s", _("Panels:"), login, path_origin); - g_free (path_origin); - path = g_strdup (str_trunc (p, len - 4)); + p = g_strdup_printf ("%s [%s]:%s", _("Panels:"), login, path); + g_free (path); g_free (login); + path = g_strdup (str_trunc (p, len - 4)); g_free (p); return path; diff --git a/src/main.c b/src/main.c index 206e89279..58983fdf2 100644 --- a/src/main.c +++ b/src/main.c @@ -334,23 +334,19 @@ load_prompt (int fd, void *unused) /* --------------------------------------------------------------------------------------------- */ -/** Show current directory in the xterm title */ void -update_xterm_title_path (void) +title_path_prepare (char **path, char **login) { - /* TODO: share code with midnight_get_title () */ - char *path; char host[BUF_TINY]; - char *p; struct passwd *pw = NULL; - char *login = NULL; int res = 0; - if (!(mc_global.tty.xterm_flag && xterm_title)) - return; + *login = NULL; - path = vfs_path_to_str_flags (current_panel->cwd_vpath, 0, VPF_STRIP_HOME | VPF_STRIP_PASSWORD); + + *path = + vfs_path_to_str_flags (current_panel->cwd_vpath, 0, VPF_STRIP_HOME | VPF_STRIP_PASSWORD); res = gethostname (host, sizeof (host)); if (res) { /* On success, res = 0 */ @@ -363,12 +359,29 @@ update_xterm_title_path (void) pw = getpwuid (getuid ()); if (pw) { - login = g_strdup_printf ("%s@%s", pw->pw_name, host); + *login = g_strdup_printf ("%s@%s", pw->pw_name, host); } else { - login = g_strdup (host); + *login = g_strdup (host); } +} + +/* --------------------------------------------------------------------------------------------- */ + +/** Show current directory in the xterm title */ +void +update_xterm_title_path (void) +{ + char *p; + char *path; + char *login; + + if (!(mc_global.tty.xterm_flag && xterm_title)) + return; + + title_path_prepare (&path, &login); + p = g_strdup_printf ("mc [%s]:%s", login, path); fprintf (stdout, "\33]0;%s\7", str_term_form (p)); g_free (login); diff --git a/src/main.h b/src/main.h index fae8c4653..eebf64056 100644 --- a/src/main.h +++ b/src/main.h @@ -93,6 +93,8 @@ int load_prompt (int fd, void *unused); gboolean do_cd (const vfs_path_t * new_dir_vpath, enum cd_enum cd_type); void update_xterm_title_path (void); +void title_path_prepare (char **path, char **login); + /*** inline functions ****************************************************************************/ #endif /* MC__MAIN_H */