Xterm window title enhancement to hostname:/path



Hi developers,
  I've found a feature in last version of mc. It is really nice to change xterm window title to current path. One can check Window List in its Window Manager and find the right window there. It is really nice. But it is not enough if one is logged on another machines via ssh. Then Window list can look like:
mc - /etc
mc - /etc
mc - /etc
mc - /usr/src

Well, but what is the right window what I am looking for? I want to switch to configuration window of my firewall. I need a bit different list:

mc - debi:/etc
mc - Firewall:/etc
mc - Planet:/etc
mc - workstation:/usr/src

or better (not coded now)

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 :-(

Regards,
  Pavel
1600c1600
< /* Show current directory in the xterm title */
---
> /* Show hostname and current directory in the xterm title */
1604a1605,1607
>     char *pvp;
>     size_t pvlen;
>     int pvresult;
1606a1610
> 	// currrent path
1607a1612,1629
> 	// 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);
> 	}
> 
1612c1634,1635
< 	fprintf (stdout, "\33]0;mc - %s\7", p);
---
> // 	fprintf (stdout, "\33]0;mc - %s\7", p);
> 	fprintf (stdout, "\33]0;mc - %s\7", pvp);
1614c1637,1638
< 	g_free (p);
---
> // 	g_free (p);
> 	g_free (pvp);


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