Re: Xterm window title enhancement to hostname:/path II.



On Fri, Mar 18, 2005 at 04:55:16PM +0100, Pavel V?vra wrote:
Hi Pavel,
> 
> mc - root debi:/etc
> mc - root Firewall:/etc
> mc - root Planet:/etc
> mc - plamen workstation:/usr/src
> 
> This patch adds hostname to current path in x-terminal window with minimal source code changes into existing code. It works for me and I hope it will be useful for many network administrators too. I hope this patch is safe. It is restricted to hostnames up to 63 bytes long. Please include it into upstream if you'll find it useful. It is possible that during some days I'll add username to make information more complete and if it will be welcomed I'll sent it too. The best way is - of course - to make this feature configurable, but I am not experienced C programmer so I cannot do it :-(

In the patch file you should have put:

--- src/main.c  Fri Nov 14 21:43:12 2003
+++ src/main.c  Fri Mar 18 15:36:41 2005

instead of:

--- main.c  Fri Nov 14 21:43:12 2003
+++ main.c  Fri Mar 18 15:36:41 2005

otherwise the patch application can not understand what file to patch.
This is a simple correction (look at the attachment)
Bye

SteX

-- 
GPG key = D52DF829    --    SteX    --    <stefano melchior openlabs it>
Keyserver: http://keyserver.kjsl.com, User#324592, http://counter.li.org
http://www.openlabs.it/~stex          --            http://www.stex.name
--- src/main.c.orig	Fri Nov 14 21:43:12 2003
+++ src/main.c	Fri Mar 18 15:36:41 2005
@@ -1597,21 +1597,45 @@
 
 #define xtoolkit_panel_setup()
 
-/* Show current directory in the xterm title */
+/* Show hostname and current directory in the xterm title */
 void
 update_xterm_title_path (void)
 {
     unsigned char *p, *s;
+    char *pvp;
+    size_t pvlen;
+    int pvresult;
 
     if (xterm_flag && xterm_title) {
+	// currrent path
 	p = s = g_strdup (strip_home_and_password (current_panel->cwd));
+	// hostname
+	pvlen = strlen(p);
+ 	pvp = g_malloc (pvlen + 64); 	//approach - max hostname length
+        pvresult = gethostname(pvp, 63);
+	if (pvresult) {		// print just current path
+	    g_free (pvp);
+	    pvp = p;
+	} else {
+	    s = pvp;
+	    do {		// merge hostname with path
+		if (!is_printable (*s))
+		    *s = '?';
+	    } while (*++s!=0x00);
+	    *s++=':';
+	    strcpy (s, p);
+	    g_free (p);
+	}
+
 	do {
 	    if (!is_printable (*s))
 		*s = '?';
 	} while (*++s);
-	fprintf (stdout, "\33]0;mc - %s\7", p);
+// 	fprintf (stdout, "\33]0;mc - %s\7", p);
+	fprintf (stdout, "\33]0;mc - %s\7", pvp);
 	fflush (stdout);
-	g_free (p);
+// 	g_free (p);
+	g_free (pvp);
     }
 }
 

Attachment: signature.asc
Description: Digital signature



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]