On Sun, Mar 02, 2003 at 03:42:39PM +0100, Adam Byrtek / alpha wrote:
> I just like to ask you, what other format variables might be useful
> for users (pid, edited/viewed file name...)? I will appreciate any
> suggestions.

Nevermind. I decided to support standard bash PS1 substitutions (but
begginning with '%', not '\', because it is more mc-ish) to make
configuration easier for those familiar with bash PS1.

If you want to test it, try the patch. This command gives you
everything you could have in the title:

MC_XTITLE="%%%$ [EMAIL PROTECTED](%H) %w(%W) <%p> mc %V [%t]" mc

Documentation:
%% - percent '%' character
%$ - '#' for root, '$' for normal user
%w - working directory
%W - working directory (last component only)
%p - process id (pid)
%u - username
%h - hostname
%H - hostname.domainname
%t - tty connected to stdin
%V - mc version

The default is "%w - mc"

Regards

-- 

  _.|._ |_  _.   :  Adam Byrtek /alpha/
 (_|||_)| |(_|   :  email  alpha@(irc.pl|debian.org)
     |           :  jabber alpha.pl(at)jabber.org, pgp 0xB25952C0
Index: main.c
===================================================================
RCS file: /cvs/gnome/mc/src/main.c,v
retrieving revision 1.281
diff -u -r1.281 main.c
--- main.c      27 Feb 2003 05:09:35 -0000      1.281
+++ main.c      2 Mar 2003 19:07:53 -0000
@@ -1839,17 +1839,95 @@
 void
 update_xterm_title_path (void)
 {
+    int i = 0;
     unsigned char *p, *s;
+    unsigned char title [BUF_MEDIUM+1];
 
     if (xterm_flag && xterm_title) {
-       p = s = g_strdup (strip_home_and_password (cpanel->cwd));
+       /* Use special environment variable to format title */
+       if ((p = getenv ("MC_XTITLE")) == NULL) {
+           p = "%w - mc";
+       }
+       
        do {
+           if (*p != '%') {
+               title [i++] = *p;
+               continue;
+           }
+           if (!*++p)
+               break;
+           
+           /* Substitute '%' special characters
+            * (meaning the same as for bash, but preceded by '%', not '\')
+            */
+           s = NULL;
+           switch (*p) {
+           case '%' : /* %% - percent '%' character */
+               title [i++] = '%';
+               break;
+           case '$' : /* %$ - '#' for root, '$' for normal user */
+               title [i++] = (geteuid()==0 ? '#' : '$');
+               break;
+           case 'w' : /* %w - working directory */
+               s = g_strdup (strip_home_and_password (cpanel->cwd)); 
+               break;
+           case 'W' : /* %W - working directory (last component only) */
+               s = g_strdup (x_basename (strip_home_and_password (cpanel->cwd)));
+               break;
+           case 'p' : /* %p - process id (pid) */
+               s = g_strdup_printf ("%d", getpid ()); 
+               break;
+           case 'u' : /* %u - username */
+               s = g_strdup (getpwuid (getuid ()) -> pw_name); 
+               break;
+           case 'h' : /* %h - hostname */
+               if (gethostname (title+i, BUF_MEDIUM-i) == 0) {
+                   title [BUF_MEDIUM] = '\0';
+                   i = strlen (title);
+               }
+               break;
+           case 'H' : /* %H - hostname.domainname */
+               if (gethostname (title+i, BUF_MEDIUM-i) == 0) {
+                   title [BUF_MEDIUM] = '\0';
+                   i = strlen (title);
+               }
+               if (i < BUF_MEDIUM-1) {
+                   title[i++]='.';
+                   if (getdomainname (title+i, BUF_MEDIUM-i) == 0) {
+                       title [BUF_MEDIUM] = '\0';
+                       i = strlen (title);
+                   }
+               }
+               break;
+           case 't' : /* %t - tty connected to stdin */
+               s = g_strdup (ttyname (0));
+               break;
+           case 'V' : /* %V - mc version */
+               s = g_strdup (VERSION);
+               break;
+           }
+
+           /* Append substituted string */
+           if (s) {
+               strncpy (title+i, s, BUF_MEDIUM-i);
+               title [BUF_MEDIUM] = '\0';
+               i = strlen (title);
+               g_free (s);
+           }
+       } while (*++p && i<BUF_MEDIUM);
+        title [i] = '\0';
+       
+       /* Replace non-printable characters with '?' */
+       s = title;
+       while (*s) {
            if (!is_printable (*s))
                *s = '?';
-       } while (*++s);
-       fprintf (stdout, "\33]0;mc - %s\7", p);
+           s++;
+       } 
+       
+       /* Use xterm escape sequence to set window title */
+       fprintf (stdout, "\33]0;%s\7", title);
        fflush (stdout);
-       g_free (p);
     }
 }
 
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/mc/src/ChangeLog,v
retrieving revision 1.1133
diff -u -u -0 -r1.1133 ChangeLog
--- ChangeLog   27 Feb 2003 04:57:58 -0000      1.1133
+++ ChangeLog   2 Mar 2003 19:08:07 -0000
@@ -0,0 +1,5 @@
+2003-03-02  Adam Byrtek  <[EMAIL PROTECTED]>
+
+       * main.c (update_xterm_title_path): Support for format string
+       in MC_XTITLE environment variable added.
+

Reply via email to