File mc-userhost.patch of Package mc46
--- mc-4.6.1a/src/main.c.userhost 2005-10-16 18:11:07.000000000 +0200
+++ mc-4.6.1a/src/main.c 2005-10-16 18:14:26.000000000 +0200
@@ -29,6 +29,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <pwd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
@@ -1608,9 +1609,22 @@ void
update_xterm_title_path (void)
{
char *p, *s;
+ char h[64];
+ struct passwd *pw;
if (xterm_flag && xterm_title) {
p = s = g_strdup (strip_home_and_password (current_panel->cwd));
+ if ( !gethostname (h, 64) ) {
+ h[63] = '\0'; /* Be sure the hostname is NUL terminated */
+ s = g_strdup_printf ("%s:%s", h, s);
+ g_free (p);
+ p = s;
+ }
+ if ( (pw = getpwuid(getuid())) ) {
+ s = g_strdup_printf ("%s@%s", pw->pw_name, s);
+ g_free (p);
+ p = s;
+ }
do {
#ifndef UTF8
if (!is_printable ((unsigned char) *s))
--- mc-4.6.1a/src/main.h.viewfile 2005-09-05 04:10:48.000000000 +0200
+++ mc-4.6.1a/src/main.h 2005-10-17 14:41:46.000000000 +0200
@@ -50,6 +50,7 @@
extern int fast_refresh;
extern int navigate_with_arrows;
extern int force_ugly_line_drawing;
+extern char *xterm_title_str;
extern int drop_menus;
extern int cd_symlinks;
extern int show_all_if_ambiguous;
--- mc-4.6.1a/src/view.c.viewfile 2005-10-17 14:41:46.000000000 +0200
+++ mc-4.6.1a/src/view.c 2005-10-17 15:11:54.000000000 +0200
@@ -3344,6 +3344,11 @@ mc_internal_viewer (const char *command,
WButtonBar *bar;
Dlg_head *view_dlg;
+ if (xterm_flag && xterm_title && xterm_title_str) {
+ fprintf (stdout, "\33]0;mc - %s/%s\7", xterm_title_str, file);
+ fflush(stdout);
+ }
+
/* Create dialog and widgets, put them on the dialog */
view_dlg =
create_dlg (0, 0, LINES, COLS, NULL, view_dialog_callback,
@@ -3367,6 +3372,8 @@ mc_internal_viewer (const char *command,
}
destroy_dlg (view_dlg);
+ update_xterm_title_path();
+
return succeeded;
}
--- mc-4.6.1a/src/main.c.viewfile 2005-10-17 14:41:46.000000000 +0200
+++ mc-4.6.1a/src/main.c 2005-10-17 14:41:46.000000000 +0200
@@ -196,6 +196,9 @@
/* If true, assume we are running on an xterm terminal */
static int force_xterm = 0;
+/* The xterm title */
+char *xterm_title_str = NULL;
+
/* If on, default for "No" in delete operations */
int safe_delete = 0;
@@ -1617,6 +1620,7 @@ update_xterm_title_path (void)
struct passwd *pw;
if (xterm_flag && xterm_title) {
+ if ( xterm_title_str ) g_free (xterm_title_str);
p = s = g_strdup (strip_home_and_password (current_panel->cwd));
if ( !gethostname (h, 64) ) {
h[63] = '\0'; /* Be sure the hostname is NUL terminated */
@@ -1643,7 +1643,7 @@
numeric_keypad_mode ();
fprintf (stdout, "\33]0;mc - %s\7", p);
fflush (stdout);
- g_free (p);
+ xterm_title_str = p;
}
}
--- mc-4.6.1a/edit/editwidget.c.viewfile 2005-10-17 14:41:46.000000000 +0200
+++ mc-4.6.1a/edit/editwidget.c 2005-10-17 14:41:46.000000000 +0200
@@ -44,6 +44,9 @@
#include "../src/widget.h" /* buttonbar_redraw() */
#include "../src/menu.h" /* menubar_new() */
#include "../src/key.h" /* is_idle() */
+#include "../src/main.h" /* xterm_title_str */
+#include "../src/win.h" /* xterm_flag */
+#include "../src/layout.h" /* xterm_title */
WEdit *wedit;
struct WMenu *edit_menubar;
@@ -177,6 +177,11 @@
Dlg_head *edit_dlg;
WButtonBar *edit_bar;
+ if (xterm_flag && xterm_title && xterm_title_str) {
+ fprintf (stdout, "\33]0;mc - %s/%s\7", xterm_title_str, _file);
+ fflush(stdout);
+ }
+
if (!made_directory) {
char *dir = mhl_str_dir_plus_file (home_dir, EDIT_DIR);
made_directory = (mkdir (dir, 0700) != -1 || errno == EEXIST);
@@ -219,6 +227,8 @@ edit_file (const char *_file, int line)
edit_done_menu (edit_menubar); /* editmenu.c */
destroy_dlg (edit_dlg);
+
+ update_xterm_title_path();
return 1;
}