handle sysnames in labels

This commit is contained in:
rsc 2005-01-30 16:27:45 +00:00
parent 0b22e9bd85
commit efe1241109
3 changed files with 37 additions and 11 deletions

View file

@ -6,6 +6,9 @@ label, awd \- set window label
.I string .I string
.br .br
.B awd .B awd
[
.I sysname
]
.SH DESCRIPTION .SH DESCRIPTION
.I Label .I Label
sets the label of the current sets the label of the current
@ -25,6 +28,14 @@ and
windows assume the label is a directory name. windows assume the label is a directory name.
When unrooted file names are plumbed in the window, When unrooted file names are plumbed in the window,
they are evaluated relative to the directory named in the label. they are evaluated relative to the directory named in the label.
.PP
The label may have a suffix
BI /- sysname \fR,
which is not interpreted as part of the directory during plumbing.
.I Awd
sets the window name to the current directory with a
.BI /- sysname
suffix, using the name of the current system by default.
.SH EXAMPLE .SH EXAMPLE
One can use the following One can use the following
.IR sh (1) .IR sh (1)
@ -64,8 +75,3 @@ fn cd {
.I Awd .I Awd
is also documented in is also documented in
.IR acme (1). .IR acme (1).
.PP
.I Awd
does not append the
.BI - label
suffix that it does on Plan 9.

View file

@ -1834,7 +1834,8 @@ int
label(Rune *sr, int n) label(Rune *sr, int n)
{ {
Rune *sl, *el, *er, *r; Rune *sl, *el, *er, *r;
char *p;
er = sr+n; er = sr+n;
for(r=er-1; r>=sr; r--) for(r=er-1; r>=sr; r--)
if(*r == '\007') if(*r == '\007')
@ -1854,6 +1855,14 @@ label(Rune *sr, int n)
snprint(wdir, sizeof wdir, "%.*S", (el-1)-(sl+3), sl+3); snprint(wdir, sizeof wdir, "%.*S", (el-1)-(sl+3), sl+3);
drawsetlabel(wdir); drawsetlabel(wdir);
/* remove trailing /-sysname if present */
p = strrchr(wdir, '/');
if(p && *(p+1) == '-'){
if(p == wdir)
p++;
*p = 0;
}
runemove(sl, el, er-el); runemove(sl, el, er-el);
n -= (el-sl); n -= (el-sl);
return n; return n;

View file

@ -489,11 +489,11 @@ stdoutproc(void *v)
} }
} }
char wdir[256]; char wdir[512];
int int
label(char *sr, int n) label(char *sr, int n)
{ {
char *sl, *el, *er, *r; char *sl, *el, *er, *r, *p;
er = sr+n; er = sr+n;
for(r=er-1; r>=sr; r--) for(r=er-1; r>=sr; r--)
@ -503,8 +503,8 @@ label(char *sr, int n)
return n; return n;
el = r+1; el = r+1;
if(el-sr > sizeof wdir) if(el-sr > sizeof wdir - strlen(name) - 20)
sr = el - sizeof wdir; sr = el - sizeof wdir - strlen(name) - 20;
for(sl=el-3; sl>=sr; sl--) for(sl=el-3; sl>=sr; sl--)
if(sl[0]=='\033' && sl[1]==']' && sl[2]==';') if(sl[0]=='\033' && sl[1]==']' && sl[2]==';')
break; break;
@ -512,7 +512,18 @@ label(char *sr, int n)
return n; return n;
*r = 0; *r = 0;
snprint(wdir, sizeof wdir, "name %s/-%s\n0\n", sl+3, name); /*
* add /-sysname if not present
*/
snprint(wdir, sizeof wdir, "name %s", sl+3);
p = strrchr(wdir, '/');
if(p==nil || *(p+1) != '-'){
p = wdir+strlen(wdir);
if(*(p-1) != '/')
*p++ = '/';
strcpy(p, name);
}
strcat(wdir, "\n0\n");
fswrite(ctlfd, wdir, strlen(wdir)); fswrite(ctlfd, wdir, strlen(wdir));
memmove(sl, el, er-el); memmove(sl, el, er-el);