Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: My zshrc; any sugestions welcome
- X-seq: zsh-users 5026
- From: "Bart Schaefer" <schaefer@xxxxxxxxxxxxxxxx>
- To: Andy Spiegl <zsh.Andy@xxxxxxxxx>, zsh-users <zsh-users@xxxxxxxxxx>
- Subject: Re: My zshrc; any sugestions welcome
- Date: Sat, 1 Jun 2002 21:29:32 +0000
- In-reply-to: <20020531222348.A4491@xxxxxxxxxxxxxxxxxxx>
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- References: <20020325175935.A1729@xxxxxxxxxxxxx> <Pine.LNX.4.44.0203251101280.5070-100000@xxxxxxxxxxxxxxxx> <20020326103835.A175@xxxxxxxxxxxxx> <1020326151112.ZM32099@xxxxxxxxxxxxxxxxxxxxxxx> <20020326174631.A831@xxxxxxxxxxxxx> <1020326171031.ZM32266@xxxxxxxxxxxxxxxxxxxxxxx> <20020401123118.A381@xxxxxxxxxxxxx> <20020531222348.A4491@xxxxxxxxxxxxxxxxxxx>
On May 31, 10:23pm, Andy Spiegl wrote:
} Subject: Re: My zshrc; any sugestions welcome
}
} Hi Marijan,
}
} > > preexec () {
} > > print -Pn "\033]0;%n@%m ${${(@)${(z)1}:#*[[:punct:]]*}%% *} %~\007"
} > > }
} >
} > I just now noticed that it's not working for 'two_or_more' word job ex.
}
} Right, that's bothering me right now, too.
The function as quoted is designed to show only the command name.
The ${...%% *} in the expression above strips off everything after the
first word. Inside that, ${(@)...:#*[[:punct:]]*} removes all words that
contain punctuation (which would include file names with dots in them).
The intent was that, if for example you give a command such as
CVS_RSH=ssh cvs update
or
( scp some list of files remote:directory )
the variable assignments and parentheses will be discarded before figuring
out what command name to display.
} > With '$1' it works perfectly? (shows complete line).
} > Why is $1 bad?
} First I didn't understand it either, then I stumbled over more complicated
} command lines with quotes and stuff in it.
The real danger is that the command line will contain a control character
or the like which the terminal interprets, or (as in your next example)
that it will contain a backslash sequence like \n which `print' will turn
into something unwanted.
A secondary problem is that the command line may be much longer than you
really want to put into your title bar. What if the command is a multi-
line `for' or `while' loop?
} For example, try:
}
} echo hi | perl -ne 'print "oops\n"'
}
} This should just print:
} oops
} but with <$1> in preexec it prints:
}
} "'>" pts/17 ~oops
This happens because the \n in "oops\n" gets turned into a real newline
by `print -nP', and the newline terminates the title bar string the same
way that the \007 would have. A similar thing would happen if the command
contained an actual newline, such as a multi-line loop body would.
} I'd really get it to work the way you tried, but I can't figure it out. :-(
} Any suggestions anyone?
If you have zsh 4.0.x, you might try:
preexec () {
print -Pn "\033]0;%n@%m ${(Vq)2} %~\007"
}
The doc for preexec says "the second argument is a single-line, size-
limited version of the command (with things like function bodies elided)".
The (Vq) means to render any control characters in a visible format and
to quote any special characters in the string with backslashes.
There isn't any simple way to get the equivalent in 3.x.
--
Bart Schaefer Brass Lantern Enterprises
http://www.well.com/user/barts http://www.brasslantern.com
Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net
Messages sorted by:
Reverse Date,
Date,
Thread,
Author