From mboxrd@z Thu Jan 1 00:00:00 1970
Return-Path:
Received: (qmail 6485 invoked from network); 11 May 2005 15:21:33 -0000
Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88)
by ns1.primenet.com.au with SMTP; 11 May 2005 15:21:33 -0000
Received: (qmail 12725 invoked from network); 11 May 2005 15:21:26 -0000
Received: from sunsite.dk (130.225.247.90)
by a.mx.sunsite.dk with SMTP; 11 May 2005 15:21:26 -0000
Received: (qmail 16858 invoked by alias); 11 May 2005 15:21:21 -0000
Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm
Precedence: bulk
X-No-Archive: yes
X-Seq: 21256
Received: (qmail 16838 invoked from network); 11 May 2005 15:21:20 -0000
Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88)
by sunsite.dk with SMTP; 11 May 2005 15:21:20 -0000
Received: (qmail 12481 invoked from network); 11 May 2005 15:21:20 -0000
Received: from acolyte.scowler.net (216.254.112.45)
by a.mx.sunsite.dk with SMTP; 11 May 2005 15:21:12 -0000
Received: by acolyte.scowler.net (Postfix, from userid 1000)
id 6CC5270054; Wed, 11 May 2005 11:21:05 -0400 (EDT)
Date: Wed, 11 May 2005 11:21:05 -0400
From: Clint Adams
To: Zsh hackers list
Subject: Re: yodl and Z shell documentation (was localtraps)
Message-ID: <20050511152105.GA20726@scowler.net>
Mail-Followup-To: Zsh hackers list
References: <20050501185447.GA24296@quark.hightek.org> <200505031004.j43A47jB014589@news01.csr.com> <20050503192011.GA34761@quark.hightek.org> <13873.1115198811@csr.com> <16447.1115718327@trentino.groupinfra.com> <1050510141032.ZM15068@candle.brasslantern.com> <20470.1115736124@trentino.groupinfra.com> <1050510154359.ZM15169@candle.brasslantern.com> <11241.1115805556@trentino.groupinfra.com> <1050511150910.ZM16083@candle.brasslantern.com>
Mime-Version: 1.0
Content-Type: multipart/mixed; boundary="Q68bSM7Ycu6FN28Q"
Content-Disposition: inline
In-Reply-To: <1050511150910.ZM16083@candle.brasslantern.com>
User-Agent: Mutt/1.5.9i
X-Spam-Checker-Version: SpamAssassin 3.0.2 on a.mx.sunsite.dk
X-Spam-Level:
X-Spam-Status: No, score=-2.6 required=6.0 tests=AWL,BAYES_00 autolearn=ham
version=3.0.2
X-Spam-Hits: -2.6
--Q68bSM7Ycu6FN28Q
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
> As, say, China is somewhat more populous than Australia.
I'm going to attach my incomplete DocBook version of the FAQ
before I lose it in some catastrophic disk and power failure.
--Q68bSM7Ycu6FN28Q
Content-Type: application/xml
Content-Disposition: attachment; filename="FAQ.xml"
Content-Transfer-Encoding: quoted-printable
=0A=0A=0A Z-Shell Frequently-Asked Questions=0A=0A myd=
it(Archive-Name:) unix-faq/shell/zsh=0Amydit(Last-Modified:) 2005/01/11=0Am=
ydit(Submitted-By:) email(pws@pwstephenson.fsnet.co.uk (Peter Stephenson))=
=0Amydit(Posting-Frequency:) Monthly=0Amydit(Copyright:) (C) P.W. Stephenso=
n, 1995--2005 (see end of document)=0A=0A This document con=
tains a list of frequently-asked (or otherwise=0Asignificant) questions con=
cerning the Z-shell, a command interpreter=0Afor many UNIX systems which is=
freely available to anyone with FTP=0Aaccess. Zsh is among the most power=
ful freely available Bourne-like=0Ashell for interactive use.=0A=0A<=
para>If you have never heard of sh,=0A csh or ksh, then you are=0Aprobably better off to star=
t by reading a general introduction to UNIX=0Arather than this document.
=0A=0AIf you just want to know how to get your hands on the lates=
t version,=0A skip to question ; if you want to kn=
ow what to do with=0A insoluble problems, go to .=0A=0Awhentxt(Notation: Quotes `like this' are ordinary tex=
tual quotation=0A marks. Other uses of quotation marks are input to the=0A=
shell.)=0A=0A=0A =0A Introducing zsh an=
d how to install it=0A=0A =0A Sources of information=0A=0A =0A Information on zsh is available via the World Wide Web. The URL=0A =
is .=0A The server provides this=
FAQ and much else and is=0A now maintained by=0A =
KarstenThygesen and=0A others =
(mail zsh@sunsite.dk=0A with any related messages). The FA=
Q is at=0A.=0A The site also co=
ntains some contributed zsh scripts and functions;=0A we are delighted to =
add more, or simply links to your own collection.=0A =0A=0A =
=0A This document was originally written in YODL, allowing it to be conver=
ted=0A easily into various other formats. The master source file lives at=
=0A =0Aand the plain t=
ext version=0A can be found at .=0A=0A Another useful source of information is the collection o=
f FAQ articles=0A posted frequently to the Usenet news groups comp.unix.qu=
estions,=0A comp.unix.shells and comp.answers with answers to general ques=
tions=0A about UNIX. The fifth of the seven articles deals with shells,=
=0A including zsh, with a brief description of differences. There is=0A =
also a separate FAQ on shell differences and how to change your=0A shell. =
Usenet FAQs are available via FTP from rtfm.mit.edu and=0A mirrors and al=
so on the World Wide Web; see=0A =0A =0A =0A =0A USA
=0A UK
=0A =
Netherlands
=0A =
=0A =0A =0A=0A =0A You can also get it v=
ia email by emailing=0A mail-server@rtfm.mit.edu=0A with, =
in the body of the message, mytt(send faqs/unix-faq/shell/zsh).=0A =
=0A=0A =0A The latest version of this FAQ is also available directl=
y from any=0A of the zsh archive sites listed in question .=0A =0A=0A =0A I have put together a user guide =
to complement the manual by=0A explaining the most useful features of zsh =
in a more easy to read way.=0A This can be found at the zsh web site:=0A =
=0A =0A=0A =0A (As a method of reading the following in Emacs, you can type tt(\M-2=
=0A \C-x $) to make all the indented text vanish, then tt(\M-0 \C-x $)=0A =
when you are on the title you want.)=0A =0A=0A =0A For any=
more eclectic information, you should contact the mailing=0A list: see q=
uestion .=0A =0A =0A=0A What is it?=0A =0A =0A Zsh is a UNIX command interpreter (shell) w=
hich of the standard=0A shells most resembles the Korn shell (ksh); its co=
mpatibility with=0A the 1988 Korn shell has been gradually increasing. It=
includes=0A enhancements of many types, notably in the command-line edito=
r,=0A options for customising its behaviour, filename globbing, features=
=0A to make C-shell (csh) users feel more at home and extra features=0A d=
rawn from tcsh (another `custom' shell).=0A=0A It was written by Paul Fals=
tad when a student at Princeton; however,=0A Paul doesn't maintain it any =
more and enquiries should be sent to=0A the mailing list (see question ).=0A Zsh is distributed under a standard Berkel=
ey style copyright.=0A=0A For more information, the files Doc/intro.txt or=
Doc/intro.troff=0A included with the source distribution are highly recom=
mended. A list=0A of features is given in FEATURES, also with the source.=
=0A =0A =0A=0A =
What is it good at?=0A =0A =
=0A Here are some things that zsh is particularly good at. No claim of=0A=
exclusivity is made, especially as shells copy one another, though=0A in=
the areas of command line editing and globbing zsh is well ahead=0A of th=
e competition. I am not aware of a major interactive feature=0A in any ot=
her freely-available shell which zsh does not also have=0A (except smallne=
ss).=0A=0A =0A Command line editing:=
=0A =0A programmable completion: incorpor=
ates the ability to use the=0A full power of zsh's globbing and shell pr=
ogramming=0A features,=0A multi-lin=
e commands editable as a single buffer (even files!),=0A =
variable editing (vared),=0A command buffer stack,=0A pri=
nt text straight into the buffer for immediate editing (print -z),=
listitem>=0A execution of unbound commands,=0A menu completion in two flavours,=0A variable, editing function and option name comple=
tion,=0A inline expansion of variables=
and history commands. =0A =0A =0A Globbing --- extremely powerful, including:=0A =0A recursive globbing (cf. find),=
=0A file attribute qualifiers (size, t=
ype, etc. also cf. find),=0A full alte=
rnation and negation of patterns.=0A =
=0A =0A Handling of multiple redirections (s=
impler than tee).=0A Large number of opt=
ions for tailoring.=0A Path expansion (=
=3Dfoo -> /usr/bin/foo).=0A Adaptable me=
ssages for spelling, watch, time as well as prompt=0A (including condit=
ional expressions).=0A Named directories=
=2E=0A Comprehensive integer and floatin=
g point arithmetic.=0A Manipulation of a=
rrays (including reverse subscripting).=0A Associative arrays (key-to-value hashes)=0A Spelling correction.=0A =0A =0A =0A=0A On what =
machines will it run?=0A =0A =0A =
=0A=0A From version 3.0, zsh uses GNU autoconf as the installation=
=0A mechanism. This considerably increases flexibility over the old=0A `=
buildzsh' mechanism. Consequently, zsh should compile and run on=0A any m=
odern version of UNIX, and a great many not-so-modern versions=0A too. Th=
e file MACHINES in the distribution has more details.=0A =0A =0A There are also now separate ports for Windows and OS/2, see `Where=0A=
do I get it' below.=0A =0A=0A =0A If you need to change s=
omething to support a new machine, it would be=0A appreciated if you could=
add any necessary preprocessor code and=0A alter configure.in and acconfi=
g.h to configure zsh automatically,=0A then send the required context diff=
s to the list (see question=0A ). Please mak=
e sure you have the latest version first.=0A =0A=0A =0A To =
get it to work, retrieve the source distribution (see question=0A ), un-gzip it, un-tar it and read the INSTALL file in the =
top=0A directory. Also read the MACHINES file for up-to-date=0A informat=
ion on compilation on certain architectures.=0A =0A=0A =
=0A Note for users of nawk=0A =0A (The following i=
nformation comes from Zoltan=0A Hidvegi): On some systems nawk is broken a=
nd produces an incorrect=0A signames.h file. This makes the signals code u=
nusable. This often happens=0A on Ultrix, HP-UX, IRIX (?). Install gawk if=
you experience such problems.=0A =0A =0A=0A=0A=
=0A =0A What's the latest ver=
sion?=0A =0A =0A Zsh 4.2.3 is the l=
atest production version.=0A =0A=0A =0A There will not be a=
ny further 4.0 releases now that 4.2 has become=0A the stable version.=0A =
=0A=0A =0A A beta of the next version is sometimes availabl=
e. Development of zsh is=0A patch by patch, with each intermediate versio=
n publicly available. Note=0A that this `open' development system does me=
an bugs are sometimes=0A introduced into the most recent archived version.=
These are usually=0A fixed quickly. If you are really interested in get=
ting the latest=0A improvements, and less worried about providing a stable=
environment,=0A development versions are uploaded quite frequently to the=
archive in the=0A tt(development) subdirectory.=0A =0A=0A =
=0A Note also that as the shell changes, it may become incompatible with=
=0A older versions; see the end of question =
=0A for a partial list.=0A Changes of this kind are almost always forced =
by an awkward or=0A unnecessary feature in the original design (as perceiv=
ed by current=0A users), or to enhance compatibility with other Bourne she=
ll=0A derivatives, or (mostly in the 3.0 series) to provide POSIX complian=
cy.=0A =0A=0A =0A =
=0A Where do I get it?=0A =0A=0A The coordinator of development is currently me; the alias=0A <=
email>coordinator@zsh.org can be used to contact whoever is in the =
hot=0A seat. The following are known mirrors (kept frequently up to date)=
; the=0A first is the official archive site, currently in Australia. All =
are=0A available by anonymous FTP. The major sites keep test versions in =
the=0A `testing' subdirectory: such up-to-the-minute development versions =
should=0A only be retrieved if you actually plan to help test the latest v=
ersion of=0A the shell. The following list also appears on the WWW at=0A =
.=0A =0A=0A =0A=
=0A =0A Home site
=0A
=0A Australia
=0A Denmark =0A Finland
=0A France =
=0A Germany
=0A =
=
=0A Hungary
=0A (also =0A
=0A Israel=0A
=
=0A =0A
=0A Italy =
=0A Japan
=0A =
=0A =
Norway
=0A Poland
=
=0A Romania
=0A
=0A Slovenia
=0A =
Sweden
=0A UK
=0A (also by FSP at port 21)
=0A
=0A USA
=0A =
=0A
=0A =
=0A
=0A =
=0A =0A=0A =0A The Windows port m=
entioned above is maintained separately by=0A Amo=
lDeshpande=0A amold@m=
icrosoft.com; please mail Amol directly about any=0A Windows-speci=
fic problems. This is based on 3.0.5, and probably will=0A not be develop=
ed further. You can get it from:=0A =0A=0A =0A <=
tgroup cols=3D'2'>=0A =0A
=0A =
=0A =0A =0A=0A =0A There is no port of v=
ersion 4 for Windows, but newer releases compile under=0A Cygwin, a freely=
available UNIX-style environment for the Win32 API. You=0A can find info=
rmation about this at =0A =0A =0A=0A =0A Likewise the OS/2 port is available from=
=0A TAMURAKent=0A kent@tril.ibm.co.jp at=0A =0A=0A =0A =0A =0A <=
entry>=0A =0A
=0A =0A =0A =0A =0A =0A Starting from mid-October 1997, there is an archive =
of patches sent=0A to the maintainers' mailing list. Note that these may =
not all be=0A added to the shell, and some may already have been; you simp=
ly have=0A to search for something you might want which is not in the vers=
ion=0A you have. Also, there may be some prerequisites earlier in the=0A =
archive. It can be found on the zsh WWW pages (as described in=0A at:=0A =0A=0A =0A =0A =0A =0A =0A
=0A =
=0A =0A =0A =0A
=0A=0A <=
qandaentry>=0A =0A I don't have root access: how do I mak=
e zsh my login shell?=0A =0A =0A =0A U=
nfortunately, on many machines you can't use=0A chsh t=
o change your=0A shell unless the name of the shell is contained in /etc/s=
hells, so if=0A you have your own copy of zsh you need some sleight-of-han=
d to use it=0A when you log on. (Simply typing zsh is =
not really a solution since=0A you still have your original login shell wa=
iting for when you exit.)=0A =0A=0A =0A The basic idea is t=
o use mytt(exec <zsh-path>) to replace the current=0A shell with zsh=
=2E Often you can do this in a login file such as .profile =0A (if your s=
hell is sh or ksh) or .login (if it's csh). Make sure you=0A have some wa=
y of altering the file (e.g. via FTP) before you try this as=0A mytt(exec)=
is often rather unforgiving. =0A =0A=0A =0A If you have zs=
h in a subdirectory mytt(bin) of your home directory,=0A put this in .prof=
ile:=0A =0A [ -f $HOME/bin/zsh ] && exec $HOME/=
bin/zsh -l=0A =0A or if your login shell is csh or tcsh,=
put this in .login:=0A =0A if ( -f ~/bin/zsh ) exec ~/=
bin/zsh -l=0A =0A (in each case the mytt(-l) tells zsh i=
t is a login shell).=0A =0A=0A =0A If you want to check thi=
s works before committing yourself to it,=0A you can make the login shell =
ask whether to exec zsh. The following=0A work for Bourne-like shells:=0A=
=0A [ -f $HOME/bin/zsh ] && {=0A ec=
ho "Type Y to run zsh: \c"=0A read line=0A [ "$line" =
=3D Y ] && exec $HOME/bin/zsh -l=0A }=0A =0A =
and for C-shell-like shells:=0A =0A if ( -f ~/bin/zsh )=
then=0A echo -n "Type Y to run zsh: "=0A if ( "$<=
" =3D=3D Y ) exec ~/bin/zsh -l=0A endif=0A =0A =0A=0A =0A It's not a good idea to put this (even without the -l) =
into .cshrc,=0A at least without some tests on what the csh is supposed to=
be doing,=0A as that will cause _every_ instance of csh to turn into a zs=
h and=0A will cause csh scripts (yes, unfortunately some people write thes=
e)=0A which do not call `csh -f' to fail. If you want to tell xterm to=0A=
run zsh, change the SHELL environment variable to the full path of=0A zs=
h at the same time as you exec zsh (in fact, this is sensible for=0A consi=
stency even if you aren't using xterm). If you have to exec=0A zsh from y=
our .cshrc, a minimum safety check is mytt(if ($?prompt) exec=0A zsh).=0A =
=0A=0A =0A If you like your login shell to appear in the pr=
ocess list as mytt(-zsh),=0A you can link mytt(zsh) to mytt(-zsh) (e.g. by=
mytt(ln -s ~/bin/zsh =0A ~/bin/-zsh)) and change the exec to mytt(exec -z=
sh). (Make sure=0A mytt(-zsh) is in your path.) This has the same effect =
as the mytt(-l)=0A option. =0A =0A=0A =0A Footnote: if you=
DO have root access, make sure zsh goes in=0A /etc/shells on all appropri=
ate machines, including NIS clients, or you=0A may have problems with FTP =
to that machine.=0A =0A =0A =0A =0A=0AHow does zsh differ from...?=0A=0AAs=
has already been mentioned, zsh is most similar to ksh, while many=0Aof th=
e additions are to please csh users. Here are some more detailed=0Anotes. =
See also the article `UNIX shell differences and how to change=0Ayour shel=
l' posted frequently to the USENET group comp.unix.shell.=0A=0A=0ADifferences from sh and ksh=0A =
=0A=0A Most features of ksh (and hence also of sh) are impl=
emented in zsh;=0A problems can arise because the implementation is slight=
ly different.=0A Note also that not all ksh's are the same either. I have=
based this=0A on the 11/16/88f version of ksh; differences from ksh93 wil=
l be more=0A substantial.=0A =0A=0A =0A As a summary of th=
e status:=0A enumerate(=0A myeit() because of all the options it is not s=
afe to assume a general=0A zsh run by a user will behave as if sh or ks=
h compatible;=0A myeit() invoking zsh as sh or ksh (or if either is a symb=
olic link to=0A zsh) sets appropriate options and improves compatibilit=
y (from=0A within zsh itself, calling mytt(ARGV0=3Dsh zsh) will also wo=
rk);=0A myeit() from version 3.0 onward the degree of compatibility with s=
h=0A under these circumstances is very high: zsh can now be used=0A =
with GNU configure or perl's Configure, for example;=0A myeit() the degr=
ee of compatibility with ksh is also high, but a few=0A things are miss=
ing: for example the more sophisticated=0A pattern-matching expression=
s are different for versions before=0A 3.1.3 --- see the detailed list =
below;=0A myeit() also from 3.0, the command `emulate' is available: `emul=
ate=0A ksh' and `emulate sh' set various options as well as changing th=
e=0A effect of single-letter option flags as if the shell had been=0A =
invoked with the appropriate name. Including the command=0A `emulat=
e sh; setopt localoptions' in a shell function will=0A turn on sh emula=
tion for that function only. In version 4 (and in=0A 3.0.6 through 8),=
this can be abbreviated as `emulate -L sh'.=0A =0A=0A =0A=
The classic difference is word splitting, discussed in question \=0Alink(=
3.1)(31);=0A this catches out very many beginning zsh users. As explained=
there,=0A this is actually a bug in every other shell. The answer is to =
set=0A tt(SH_WORD_SPLIT) for backward compatibility. The next most classi=
c=0A difference is that unmatched glob patterns cause the command to abort=
;=0A set tt(NO_NOMATCH) for those.=0A =0A=0A =0A Here is a=
list of various options which will increase ksh=0A compatibility, though =
maybe decrease zsh's abilities: see the manual=0A entries for tt(GLOB_SUBS=
T), tt(IGNORE_BRACES) (though brace expansion occurs=0A in some versions o=
f ksh), tt(KSH_ARRAYS), tt(KSH_GLOB), tt(KSH_OPTION_PRINT),=0A tt(LOCAL_OP=
TIONS), tt(NO_BAD_PATTERN), tt(NO_BANG_HIST), tt(NO_EQUALS), \=0Att(NO_HUP)=
,=0A tt(NO_NOMATCH), tt(NO_RCS), tt(NO_SHORT_LOOPS), tt(PROMPT_SUBST), \=
=0Att(RM_STAR_SILENT),=0A tt(POSIX_BUILTINS), tt(SH_FILE_EXPANSION), tt(SH=
_GLOB), \=0Att(SH_OPTION_LETTERS),=0A tt(SH_WORD_SPLIT) (see question link=
(3.1)(31)) and tt(SINGLE_LINE_ZLE).=0A Note that you can also disable any =
built-in commands which get in=0A your way. If invoked as `ksh', the shel=
l will try to set suitable=0A options.=0A =0A=0A =0A Here =
are some differences from ksh which might prove significant for=0A ksh pro=
grammers, some of which may be interpreted as bugs; there=0A must be more.=
Note that this list is deliberately rather full and=0A that most of the =
items are fairly minor. Those marked `*' perform=0A in a ksh-like manner =
if the shell is invoked with the name `ksh', or=0A if `emulate ksh' is in =
effect. Capitalised words with underlines=0A refer to shell options. =0A =
=0A=0A =0A itemize(=0A it() Syntax:=0A itemize(=0A it(=
)* Shell word splitting: see question link(3.1)(31).=0A it()* Arrays are=
(by default) more csh-like than ksh-like:=0A subscripts start at 1,=
not 0; tt(array[0]) refers to tt(array[1]);=0A mytt($array) refers =
to the whole array, not tt($array[0]);=0A braces are unnecessary: tt=
($a[1] =3D=3D ${a[1]}), etc.=0A Set the tt(KSH_ARRAYS) option for co=
mpatibility.=0A it() Coprocesses are established by mytt(coproc); mytt(=
|&) behaves like=0A csh. Handling of coprocess file descriptors=
is also different.=0A it() In mytt(cmd1 && cmd2 &), only m=
ytt(cmd2) instead of the whole=0A expression is run in the backgroun=
d in zsh. The manual implies=0A this is a bug. Use mytt({ cmd1 &am=
p;& cmd2 } &) as a workaround.=0A )=0A it() Command line substitu=
tions, globbing etc.:=0A itemize(=0A it()* Failure to match a globbing =
pattern causes an error (use=0A tt(NO_NOMATCH)).=0A it()* The res=
ults of parameter substitutions are treated as plain text:=0A mytt(f=
oo=3D"*"; print $foo) prints all files in ksh but mytt(*) in zsh=0A =
(use tt(GLOB_SUBST)).=0A it()* tt($PSn) do not do parameter substitution=
by default (use \=0APROMPT_SUBST).=0A it()* Standard globbing does not =
allow ksh-style `pattern-lists'.=0A Equivalents:=0A verb(=0A-------=
---------------------------------------------------------------=0A ksh=
zsh Meaning=0A ------ ------ ----=
-----=0A !(foo) ^foo Anything but foo.=0A =
or foo1~foo2 Anything matching foo1 but foo2[1].=0A@(foo1|foo2|..=
=2E) (foo1|foo2|...) One of foo1 or foo2 or ...=0A ?(foo) (=
foo|) Zero or one occurrences of foo.=0A *(foo) (foo)# =
Zero or more occurrences of foo.=0A +(foo) (foo)## =
One or more occurrences of foo.=0A----------------------------------------=
------------------------------=0A )=0A The mytt(^), mytt(~) and m=
ytt(#) (but not mytt(|))forms require \=0Att(EXTENDED_GLOB).=0A From v=
ersion 3.1.3, the ksh forms are fully supported when the=0A option tt(=
KSH_GLOB) is in effect; for previous versions you=0A must use the tabl=
e above.=0A=0A [1] Note that mytt(~) is the only globbing operator to =
have a lower=0A precedence than mytt(/). For example, mytt(**/foo~*=
bar*) matches any=0A file in a subdirectory called mytt(foo), except=
where mytt(bar)=0A occurred somewhere in the path (e.g. mytt(users/=
barstaff/foo) will=0A be excluded by the mytt(~) operator). As the =
mytt(**) operator cannot=0A be grouped (inside parentheses it is tre=
ated as mytt(*)), this is=0A the way to exclude some subdirectories =
=66rom matching a mytt(**).=0A it() Unquoted assignments do file expans=
ion after mytt(:)s (intended for=0A PATHs). =0A it() mytt(typese=
t) and mytt(integer) have special behaviour for=0A assignments in ks=
h, but not in zsh. For example, this doesn't=0A work in zsh:=0A =0A integer k=3D$(wc -l ~/.zshrc)=0A =0A because the return value from tt(wc) includes leading=0A =
whitespace which causes wordsplitting. Ksh handles the=0A as=
signment specially as a single word.=0A )=0A it() Command execution:=0A =
itemize(=0A it()* There is no tt($ENV) variable (use /etc/zshrc<=
/filename>, ~/.zshrc; =0A note also tt($Z=
DOTDIR)).=0A it() tt($PATH) is not searched for commands specified=0A =
at invocation without -c.=0A )=0A it() Aliases and functions:=0A i=
temize(=0A it() The order in which aliases and functions are defined is=
significant:=0A function definitions with () expand aliases -- see =
question \=0Alink(2.3)(23).=0A it() Aliases and functions cannot be exp=
orted.=0A it() There are no tracked aliases: command hashing replaces t=
hese.=0A it() The use of aliases for key bindings is replaced by `bindk=
ey'.=0A it()* Options are not local to functions (use LOCAL_OPTIONS; not=
e this=0A may always be unset locally to propagate options settings =
=66rom a=0A function to the calling level).=0A it() Functions de=
fined with `function funcname { body }' behave the=0A same way as th=
ose defined with `funcname () { body }'. In ksh,=0A the former beha=
ve as if the body were read from a file with `.',=0A and only the la=
tter behave as true functions.=0A )=0A it() Traps and signals:=0A item=
ize(=0A it()* Traps are not local to functions. The option LOCAL_TRAPS =
is=0A available from 3.1.6.=0A it() TRAPERR has become TRAPZER=
R (this was forced by UNICOS which=0A has SIGERR).=0A )=0A it() Ed=
iting:=0A itemize(=0A it() The options tt(gmacs), tt(viraw) are not su=
pported.=0A Use bindkey to change the editing behaviour: mytt(set -o=
{emacs,vi})=0A becomes `bindkey -{e,v}', although `set -o emacs' an=
d `set -o vi'=0A are supported for compatibility; for gmacs, go to e=
macs mode and=0A use `bindkey \^t gosmacs-transpose-characters'.=0A =
it() The mytt(keyword) option does not exist and mytt(-k) is instead=0A=
interactivecomments. (mytt(keyword) is not in recent versions=0A =
of ksh either.)=0A it()* Management of histories in multiple shell=
s is different:=0A the history list is not saved and restored after =
each command.=0A The option tt(SHARE_HISTORY) appeared in 3.1.6 and =
is set in ksh=0A compatibility mode to remedy this.=0A it() mytt=
(\) does not escape editing chars (use mytt(^V)).=0A it() Not all ksh b=
indings are set (e.g. mytt(<ESC>#); try=0A mytt(<ESC>q)).=0A=
it()* mytt(#) in an interactive shell is not treated as a comment by=0A=
default. =0A )=0A it() Built-in commands:=0A itemize(=0A it()=
Some built-ins (tt(r), tt(autoload), tt(history), tt(integer) ...)=0A =
were aliases in ksh. =0A it() There is no built-in command newgrp: =
use e.g. mytt(alias=0A newgrp=3D"exec newgrp")=0A it() mytt(jobs=
) has no mytt(-n) flag.=0A )=0A it() Other idiosyncrasies:=0A itemize(=
=0A it() mytt(select) always redisplays the list of selections on each =
loop.=0A )=0A )=0A=0A =0A =0A =0A =0A Similarities with csh=0A =
=0A=0A Although certain features aim to ease the withdraw=
al symptoms of csh=0A (ab)users, the syntax is in general rather different=
and you should=0A certainly not try to run scripts without modification. =
The c2z script=0A is provided with the source (in Misc/c2z) to help conve=
rt .cshrc=0A and .login files; see also the next question concerning alias=
es,=0A particularly those with arguments.=0A=0A Csh-compatibility additio=
ns include:=0A itemize(=0A it() tt(logout), tt(rehash), tt(source), tt((=
un)limit) built-in commands.=0A it() tt(*rc) file for interactive shells.=
=0A it() Directory stacks.=0A it() tt(cshjunkie*), tt(ignoreeof) option=
s.=0A it() The tt(CSH_NULL_GLOB) option.=0A it() tt(>&), tt(|&am=
p;) etc. redirection.=0A (Note that mytt(>file 2>&1) is the =
standard Bourne shell command for=0A csh's mytt(>&file).)=0A i=
t() tt(foreach ...) loops; alternative syntax for other loops.=0A it() A=
lternative syntax mytt(if ( ... ) ...), though this still doesn't=0A w=
ork like csh: it expects a command in the parentheses. Also=0A mytt(f=
or), mytt(which).=0A it() tt($PROMPT) as well as tt($PS1), tt($status) as=
well as tt($?),=0A tt($#argv) as well as tt($#), .... =0A it() Esca=
pe sequences via tt(%) for prompts.=0A it() Special array variables tt($P=
ATH) etc. are colon-separated, tt($path)=0A are arrays.=0A it() tt(!=
)-type history (which may be turned off via mytt(setopt=0A nobanghist)=
).=0A it() Arrays have csh-like features (see under link(2.1)(21)).=0A )=
=0A=0A=0A =0A =0AWhy do my csh aliases not work? (Plus other alias=0A pitfalls.)=
=0A=0A=0A First of all, check you are using the s=
yntax=0A =0A alias newcmd=3D'list of commands'=0A =0A and not=0A =0A alias newcmd 'list of =
commands'=0A =0A which won't work. (It tells you if `new=
cmd' and `list of commands' are=0A already defined as aliases.)=0A=0A Oth=
erwise, your aliases probably contain references to the command=0A line of=
the form mytt(\!*), etc. Zsh does not handle this behaviour as it=0A has=
shell functions which provide a way of solving this problem more=0A consi=
stent with other forms of argument handling. For example, the=0A csh alia=
s=0A verb(=0A alias cd 'cd \!*; echo $cwd'=0A )=0A can be replaced by=
the zsh function,=0A verb(=0A cd() { builtin cd "$@"; echo $PWD; }=0A =
)=0A (the `builtin' tells zsh to use its own `cd', avoiding an infinite l=
oop)=0A or, perhaps better,=0A verb(=0A cd() { builtin cd "$@"; print =
-D $PWD; }=0A )=0A (which converts your home directory to a tt(~)). In f=
act, this problem is=0A better solved by defining the special function chp=
wd() (see the manual).=0A Note also that the mytt(;) at the end of the fun=
ction is optional in zsh,=0A but not in ksh or sh (for sh's where it exist=
s).=0A=0A Here is Bart Schaefer's guide to converting csh aliases for zsh.=
=0A=0A enumerate(=0A myeit() If the csh alias references "parameters" (tt=
(\!:1), tt(\!*) etc.),=0A then in zsh you need a function (referencing =
tt($1), tt($*) etc.).=0A Otherwise, you can use a zsh alias.=0A=0A mye=
it() If you use a zsh function, you need to refer _at_least_ to=0A tt($=
*) in the body (inside the tt({ })). Parameters don't magically=0A app=
ear inside the tt({ }) the way they get appended to an alias.=0A=0A myeit(=
) If the csh alias references its own name (tt(alias rm "rm -i")),=0A t=
hen in a zsh function you need the "command" keyword=0A (function tt(rm=
() { command rm -i "$@" })), but in a zsh alias=0A you don't (tt(alias =
rm=3D"rm -i")).=0A=0A myeit() If you have aliases that refer to each other=
(tt(alias ls "ls -C";=0A alias lf "ls -F" =3D=3D> lf =3D=3D ls -C -F))=
then you must either:=0A itemize(=0A it() convert all of them to z=
sh functions; or=0A it() after converting, be sure your .zshrc defin=
es all of your=0A aliases before it defines any of your functions=
=2E=0A )=0A=0A Those first four are all you really need, but he=
re are four more for=0A heavy csh alias junkies:=0A=0A myeit() Mapping=
from csh alias "parameter referencing" into zsh function=0A (assuming =
tt(SH_WORD_SPLIT) and tt(KSH_ARRAYS) are NOT set in zsh):=0A verb(=0A=
csh zsh=0A =3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=0A \!* $* (or $argv)=0A \!^ =
$1 (or $argv[1])=0A \!:1 $1=0A \!:2 =
$2 (or $argv[2], etc.)=0A \!$ $*[$#] =
(or $argv[$#], or $*[-1])=0A \!:1-4 $*[1,4]=0A \!:1- =
$*[1,$#-1] (or $*[1,-2])=0A \!^- $*[1,$#-1]=0A =
\!*:q "$@"=0A \!*:x $=3D* ($*:x doesn't wor=
k (yet))=0A )=0A=0A myeit() Remember that it is NOT a syntax error =
in a zsh function to=0A refer to a position (tt($1), tt($2), etc.) grea=
ter than the number of=0A parameters. (E.g., in a csh alias, a referenc=
e to tt(\!:5) will=0A cause an error if 4 or fewer arguments are given;=
in a zsh=0A function, tt($5) is the empty string if there are 4 or few=
er=0A parameters.)=0A=0A myeit() To begin a zsh alias with a - (dash, =
hyphen) character, use=0A mytt(alias --):=0A verb(=0A =
csh zsh=0A =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=0A alias - "fg %-" alias -- -=3D"fg %-"=0A =
)=0A=0A myeit() Stay away from mytt(alias -g) in zsh until you REALLY kn=
ow what=0A you're doing.=0A )=0A=0A There is one other serious proble=
m with aliases: consider=0A verb(=0A alias l=3D'/bin/ls -F'=0A l() {=
/bin/ls -la "$@" | more }=0A )=0A mytt(l) in the function definition is =
in command position and is expanded=0A as an alias, defining mytt(/bin/ls)=
and mytt(-F) as functions which call=0A mytt(/bin/ls), which gets a bit r=
ecursive. This can be avoided if you use=0A mytt(function) to define a fu=
nction, which doesn't expand aliases. It is=0A possible to argue for extr=
a warnings somewhere in this mess.=0A=0A Bart Schaefer's rule is: Define =
first those aliases you expect to=0A use in the body of a function, but de=
fine the function first if the=0A alias has the same name as the function.=
=0A=0A=0A =0A =
Similarities with tcsh=0A =0A=0A (The s=
ections on csh apply too, of course.) Certain features have=0A been borro=
wed from tcsh, including tt($watch), tt(run-help), tt($savehist),=0A perio=
dic commands etc., extended prompts, tt(sched) and tt(which) built-ins.=0A =
Programmable completion was inspired by, but is entirely different to,=0A =
tcsh's mytt(complete). (There is a perl script called tt(lete2ctl) in the=
=0A Misc directory of the source distribution to convert mytt(complete) to=
\=0Amytt(compctl)=0A statements.) This list is not definitive: some feat=
ures have gone in=0A the other direction.=0A=0A If you're missing the edi=
tor function tt(run-fg-editor), try something=0A with mytt(bindkey -s) (wh=
ich binds a string to a keystroke), e.g.=0A verb(=0A bindkey -s '^z' '\=
eqfg %$EDITOR:t\n'=0A )=0A which pushes the current line onto the stack a=
nd tries to bring a job=0A with the basename of your editor into the foreg=
round. mytt(bindkey -s)=0A allows limitless possibilities along these lin=
es. You can execute=0A any command in the middle of editing a line in the=
same way,=0A corresponding to tcsh's mytt(-c) option:=0A verb(=0A bin=
dkey -s '^p' '\eqpwd\n'=0A )=0A In both these examples, the mytt(\eq) sav=
es the current input line to=0A be restored after the command runs; a bett=
er effect with multiline=0A buffers is achieved if you also have=0A verb(=
=0A bindkey '\eq' push-input=0A )=0A to save the entire buffer. In ve=
rsion 4 and recent versions of zsh 3.1,=0A you have the following more sop=
histicated option,=0A verb(=0A run-fg-editor() {=0A zle push-input=
=0A BUFFER=3D"fg %$EDITOR:t"=0A zle accept-line=0A }=0A zle=
-N run-fg-editor=0A )=0A and can now bind tt(run-fg-editor) just like an=
y other editor function.=0A=0A=0A =0A =0A Similarities with bash=0A =
=0A=0A The Bourne-Again Shell, bash, is another enhanced =
Bourne-like shell;=0A the most obvious difference from zsh is that it does=
not attempt to=0A emulate the Korn shell. Since both shells are under ac=
tive=0A development it is probably not sensible to be too specific here.=
=0A Broadly, bash has paid more attention to standards compliancy=0A (i.e=
=2E POSIX) for longer, and has so far avoided the more abstruse=0A interac=
tive features (programmable completion, etc.) that zsh has.=0A=0A In recen=
t years there has been a certain amount of crossover in the=0A extensions,=
however. Zsh (as of 3.1.6) has bash's `tt(${var/old/new})'=0A feature fo=
r replacing the text tt(old) with the text tt(new) in the=0A parameter tt(=
$var). Note one difference here: while both shells=0A implement the synt=
ax `tt(${var/#old/new})' and `tt(${var/%old/new})' for=0A anchoring the ma=
tch of tt(old) to the start or end of the parameter text,=0A respectively,=
in zsh you can't put the `tt(#)' or `tt(%)' inside a=0A parameter: in ot=
her words `tt({var/$old/new})' where tt(old) begins with=0A a `tt(#)' trea=
ts that as an ordinary character in zsh, unlike bash. To=0A do this sort =
of thing in zsh you can use (from 3.1.7) the new syntax=0A for anchors in =
any pattern, `tt((#s))' to match the start of a string,=0A and `tt((#e))' =
to match the end. These require the option=0A tt(EXTENDED_GLOB) to be set=
=2E=0A=0A=0A =0A =0A Shouldn't zsh be more/less like=0A ksh/(t)csh?=0A =0A=0A People often ask why zsh has all these `un=
necessary' csh-like features,=0A or alternatively why zsh doesn't understa=
nd more csh syntax. This is=0A far from a definitive answer and the debat=
e will no doubt continue.=0A=0A Paul's object in writing zsh was to produc=
e a ksh-like shell which=0A would have features familiar to csh users. Fo=
r a long time, csh was=0A the preferred interactive shell and there is a s=
trong resistance to=0A changing to something unfamiliar, hence the additio=
nal syntax and=0A tt(CSH_JUNKIE) options. This argument still holds. On =
the other hand,=0A the arguments for having what is close to a plug-in rep=
lacement for ksh=0A are, if anything, even more powerful: the deficiencie=
s of csh as a=0A programming language are well known (look in any Usenet F=
AQ archive, e.g.=0A =0A if you are in any do=
ubt) and zsh is able to run many standard=0A scripts such as /etc/rc.=0A=
=0A Of course, this makes zsh rather large and feature-ridden so that it=
=0A seems to appeal mainly to hackers. The only answer, perhaps not=0A e=
ntirely satisfactory, is that you have to ignore the bits you don't=0A wan=
t. The introduction of loadable in modules in version 3.1 should=0A help.=
=0A=0A=0A =0A =0A What is zsh's support for=0A Unicode/UTF-8?=
=0A =0A =0A `Unicode', or UCS for Universal Character =
Set, is the modern way=0A of specifying character sets. It replaces a lar=
ge number of ad hoc=0A ways of supporting character sets beyond ASCII. `U=
TF-8' is an=0A encoding of Unicode that is particularly natural on Unix-li=
ke systems.=0A=0A =0A=0A =0A =0A =0A Does zsh support UTF-8?=0A =0A =0A =0A=
=0A zsh's built-in printf command supports "\u" and "\U" escapes=
=0A to output arbitrary Unicode characters. ZLE (the Zsh Line Editor) has=
=0A no concept of character encodings, and is confused by multi-octet=0A =
encodings.=0A =0A =0A =0A=0A <=
question>=0A Why doesn't zsh have proper UTF-8 support?=0A <=
/question>=0A=0A =0A The code has not been written yet.=0A =
=0A=0A =0A What=
makes UTF-8 support difficult to implement?=0A =0A=0A =
=0A In order to handle arbitrary encodings the correct way, =
significant=0A and intrusive changes must be made to the shell.=0A =0A=0A =0A Why can't z=
sh just use readline?=0A =0A=0A =0A ZLE =
is not encapsulated from the rest of the shell. Isolating it=0A such that=
it could be replaced by readline would be a significant=0A effort. Furth=
ermore, using readline would effect a significant loss of=0A features.=0A =
=0A=0A =0A What=
changes are planned?=0A =0A=0A =0A Intr=
oduction of Unicode support will be gradual, so if you are=0A interested i=
n being involved you should join the zsh-workers mailing=0A list. As a fi=
rst step ZLE will be rewritten to use wide characters=0A internally. Char=
acter based widgets can then operate on a single wide=0A character instead=
of a single byte, and the proper display width can be=0A calculated with =
wcswidth().=0A =0A=0A =0A
=0A=0A=0A How to get various things to work)=
=0A=0AWhy does mytt($var) where mytt(va=
r=3D"foo bar")=0A not do what I expect?=0A =0A=0A In most Bourne-shell derivatives, multiple-word variables such as=
=0A verb(=0A var=3D"foo bar"=0A )=0A are split into words when passed=
to a command or used in a mytt(for foo in=0A $var) loop. By default, zsh=
does not have that behaviour: the=0A variable remains intact. (This is n=
ot a bug! See below.) The option=0A tt(SH_WORD_SPLIT) exists to provide =
compatibility.=0A=0A For example, defining the function args to show the n=
umber of its=0A arguments:=0A verb(=0A args() { echo $#; }=0A )=0A a=
nd with our definition of `var',=0A verb(=0A args $var=0A )=0A produc=
es the output `1'. After=0A verb(=0A setopt shwordsplit=0A )=0A the =
same function produces the output `2', as with sh and ksh.=0A=0A Unless yo=
u need strict sh/ksh compatibility, you should ask yourself=0A whether you=
really want this behaviour, as it can produce unexpected=0A effects for v=
ariables with entirely innocuous embedded spaces. This=0A can cause horre=
ndous quoting problems when invoking scripts from=0A other shells. The na=
tural way to produce word-splitting behaviour=0A in zsh is via arrays. Fo=
r example,=0A verb(=0A set -A array one two three twenty=0A )=0A (or=
=0A verb(=0A array=3D(one two three twenty)=0A )=0A if you prefer), f=
ollowed by=0A verb(=0A args $array=0A )=0A produces the output `4', r=
egardless of the setting of tt(SH_WORD_SPLIT).=0A Arrays are also much mor=
e versatile than single strings. Probably=0A if this mechanism had always=
been available there would never have=0A been automatic word splitting in=
scalars, which is a sort of=0A uncontrollable poor man's array.=0A=0A No=
te that this happens regardless of the value of the internal field=0A sepa=
rator, tt($IFS); in other words, with mytt(IFS=3D:; foo=3Da:b; args $foo)=
=0A you get the answer 1.=0A=0A Other ways of causing word splitting incl=
ude a judicious use of=0A `eval':=0A verb(=0A sentence=3D"Longtemps, j=
e me suis couch\\'e de bonne heure."=0A eval "words=3D($sentence)"=0A )=
=0A after which $words is an array with the words of $sentence (note=0A c=
haracters special to the shell, such as the mytt(') in this example,=0A mu=
st already be quoted), or, less standard but more reliable,=0A turning on =
tt(SH_WORD_SPLIT) for one variable only:=0A verb(=0A args ${=3Dsentence=
}=0A )=0A always returns 8 with the above definition of mytt(args). (In =
older=0A versions of zsh, tt(${=3Dfoo}) toggled tt(SH_WORD_SPLIT); now it =
forces it on.)=0A=0A Note also the tt("$@") method of word splitting is al=
ways available in zsh=0A functions and scripts (though strictly this does =
array splitting, not=0A word splitting). This is more portable than the t=
t($*), since it=0A will work regardless of the tt(SH_WORD_SPLIT) setting; =
the other=0A difference is that tt($*) removes empty arguments from the ar=
ray.=0A You can fix the first half of that objection by using tt(${=3D=3D*=
}),=0A which turns off tt(SH_WORD_SPLIT) for the duration of the expansion=
=2E=0A=0A tt(SH_WORD_SPLIT) is set when zsh is invoked with the names `ksh=
' or `sh',=0A or (entirely equivalent) when mytt(emulate ksh) or mytt(emul=
ate sh) is in=0A effect.=0A=0A There is one other effect of word splittin=
g which differs between ksh=0A and zsh. In ksh, the builtin commands that=
declare parameters such=0A as tt(typeset) and tt(export) force word-split=
ting not to take place=0A after on an assignment argument:=0A verb(=0A =
typeset param=3D`echo foo bar`=0A )=0A in ksh will create a parameter wi=
th value mytt(foo bar), but in zsh will=0A create a parameter tt(param) wi=
th value tt(foo) and a parameter tt(bar)=0A whose value is empty. Contras=
t this with a normal assignment (no=0A tt(typeset) or other command in fro=
nt), which never causes a word split=0A unless you have tt(GLOB_ASSIGN) se=
t. From zsh version 4.0.2 the option=0A tt(KSH_TYPESET), set automaticall=
y in compatibility mode, fixes this=0A problem. Note that in bash this be=
haviour occurs with all arguments that=0A look like assignments, whatever =
the command name; to get this behaviour=0A in zsh you have to set the opti=
on tt(MAGIC_EQUAL_SUBST).=0A=0A =0A In which startup file do I=0A put...?=0A =0A=0A When zsh starts up, there are four file=
s you can change which it will=0A run under various circumstances: .zshenv, .zprofile, .zshrc=0A and .zlogin. They are usually in your ho=
me directory, but the=0A variable tt($ZDOTDIR) may be set to alter that. =
Here are a few simple=0A hints about how to use them. There are also file=
s which the system=0A administrator can set for all shells; you can avoid =
running all except=0A tt(/etc/zshenv) by starting zsh with the tt(-f) opti=
on --- for this=0A reason it is important for administrators to make sure =
tt(/etc/zshenv)=0A is as brief as possible.=0A=0A The order in which the =
four files are searched (none of them myem(need)=0A to exist) is the one j=
ust given. However, .zprofile and .zlogin=
filename>=0A are only run when the shell is a login shell --- when you fir=
st login,=0A of course, and whenever you start zsh with the tt(-l) option.=
All=0A login shells are interactive. The order is the only difference=
=0A between those; you should decide whether you need things set before or=
=0A after .zshrc. These files are a good place to s=
et environment=0A variables (i.e. mytt(export) commands), since they are p=
assed on to=0A all shells without you having to set them again, and also t=
o check=0A that your terminal is set up properly (except that if you want =
to=0A change settings for terminal emulator windows like tt(xterm) you wil=
l=0A need to put those in .zshrc, since usually you =
do not get a login=0A shell here). =0A=0A The only file you can alter wh=
ich is started with every zsh (unless=0A you use the tt(-f) option) is .zshenv, so this is a good place to \=0A put=0A things=
you want even if the shell is non-interactive: options for=0A changing th=
e syntax, like tt(EXTENDED_GLOB), any changes to set with=0A mytt(limit), =
any more variables you want to make sure are set as for=0A example tt($fpa=
th) to find functions. You almost certainly do not=0A want .zs=
henv to produce any output. Some people prefer not to=0A use <=
filename >.zshenv for setting options, as this affects scripts; =
but=0A making zsh scripts portable usually requires special handling anywa=
y.=0A=0A Finally, .zshrc is run for every interactiv=
e shell; that includes=0A login shells, but also any other time you start =
up a shell, such as=0A simply by typing mytt(zsh) or opening a new termina=
l emulator window.=0A This file is the place to change the editing behavio=
ur via options or=0A mytt(bindkey), control how your history is saved, set=
aliases unless=0A you want to use them in scripts too, and for any other =
clutter which=0A can't be exported but you only use when interacting direc=
tly with the=0A shell. You probably don't want .zshrc to produce output, either,=0A since there are occasions when this can b=
e a problem, such as when=0A using mytt(rsh) from another host. See link(=
3.21)(321) for what to \=0A put in .zshrc=0A to sav=
e your history.=0A=0A=0A =0A =
=0A What is the difference between `export'=0A and =
the tt(ALL_EXPORT)=0A option?=0A =
=0A=0A Normally, you would put a variable into the environment by using=0A=
mytt(export var). The command mytt(setopt allexport) causes all=0A vari=
ables which are subsequently set (N.B. not all the ones which=0A already e=
xist) to be put into the environment.=0A=0A This may seem a useful shortha=
nd, but in practice it can have=0A unhelpful side effects:=0A enumerate(=
=0A myeit() Since every variable is in the environment as well as remember=
ed=0A by the shell, the memory for it needs to be allocated twice.=0A =
This is bigger as well as slower.=0A myeit() It really is mybf(every) v=
ariable which is exported, even loop=0A variables in mytt(for) loops. =
This is probably a waste.=0A myeit() An arbitrary variable created by the =
user might have a special=0A meaning to a command. Since all shell var=
iables are visible to=0A commands, there is no protection against this.=
=0A )=0A For these reasons it is usually best to avoid tt(ALL_EXPORT) unl=
ess you=0A have a specific use for it. One safe use is to set it before=
=0A creating a list of variables in an initialisation file, then unset=0A =
it immediately afterwards. Only those variables will be automatically=0A =
exported.=0A=0A=0A =0A =0A =
How do I turn off spelling=0A correction/globbing for=
a single=0A command?=0A =0A=0A In=
the first case, you presumably have mytt(setopt correctall) in an=0A init=
ialisation file, so that zsh checks the spelling of each word in=0A the co=
mmand line. You probably do not want this behaviour for=0A commands which=
do not operate on existing files.=0A=0A The answer is to alias the offend=
ing command to itself with=0A mytt(nocorrect) stuck on the front, e.g.=0A =
verb(=0A alias mkdir=3D'nocorrect mkdir'=0A )=0A=0A To turn off globb=
ing, the rationale is identical:=0A verb(=0A alias mkdir=3D'noglob mkdi=
r'=0A )=0A You can have both tt(nocorrect) and tt(noglob), if you like, b=
ut the=0A tt(nocorrect) must come first, since it is needed by the line ed=
itor,=0A while tt(noglob) is only handled when the command is examined.=0A=
=0A Note also that a shell function won't work: the no... directives must=
=0A be expanded before the rest of the command line is parsed.=0A=0A=0A =
=0A =0A How d=
o I get the meta key to work on my=0A xterm?=0A <=
answer>=0A=0A As stated in the manual, zsh needs to be told about th=
e meta key by=0A using mytt(bindkey -me) or mytt(bindkey -mv) in your .zsh=
rc or on the=0A command line. You probably also need to tell the terminal=
driver to=0A allow the `meta' bit of the character through; mytt(stty pas=
s8) is the=0A usual incantation. Sample .zshrc entry:=0A verb(=0A [[ =
$TERM =3D "xterm" ]] && stty pass8 && bindkey -me=0A )=0A =
or, on SYSVR4-ish systems without pass8,=0A verb(=0A [[ $TERM =3D "xte=
rm" ]] && stty -parenb -istrip cs8 && bindkey -me=0A )=0A =
(disable parity detection, don't strip high bit, use 8-bit characters).=0A=
Make sure this comes myem(before) any bindkey entries in your .zshrc whic=
h=0A redefine keys normally defined in the emacs/vi keymap. You may also=
=0A need to set the tt(eightBitOutput) resource in your tt(~/.Xdefaults)=
=0A file, although this is on by default and it's unlikely anybody will=0A=
have tinkered with it.=0A=0A You don't need the mytt(bindkey) to be able=
to define your own sequences=0A with the meta key, though you still need =
the mytt(stty).=0A=0A=0A =0A =
=0A How do I automatically display the=0A directory=
in my xterm title=0A bar?=0A =0A=
=0A You should use the special function mytt(chpwd), which is called when=
=0A the directory changes. The following checks that standard output is=
=0A a terminal, then puts the directory in the title bar if the terminal=
=0A is an tt(xterm) or some close relative, or a tt(sun-cmd).=0A =0A ver=
b(=0A chpwd() {=0A [[ -t 1 ]] || return=0A case $TERM in=0A sun=
-cmd+CHAR(41) print -Pn "\e]l%~\e\\"=0A ;;=0A *xterm*|rxvt|(dt|=
k|E)term+CHAR(41) print -Pn "\e]2;%~\a"=0A ;;=0A esac=0A }=0A )=
=0A=0A Change mytt(%~) if you want the message to be different. (The mytt=
(-P)=0A option interprets such sequences just like in prompts, in this cas=
e=0A producing the current directory; you can of course use mytt($PWD) her=
e,=0A but that won't use the mytt(~) notation which I find clearer.) Note=
that=0A when the tt(xterm) starts up you will probably want to call tt(ch=
pwd)=0A directly: just put mytt(chpwd) in .zshrc aft=
er it is defined or \=0A autoloaded.=0A=0A=0A =0A =0A How do I make the completion li=
st use=0A eight bit characters?=0A =
=0A=0A If you are sure your terminal handles this, the easiest way from ve=
rsions=0A 3.0.6 and 3.1 of the shell is to set the option tt(PRINT_EIGHT_B=
IT). In=0A principle, this will work automatically if your computer uses =
the=0A `locale' system and your locale variables are set properly, as zsh=
=0A understands this. However, it is quite complicated, so if it isn't=0A=
already set up, trying the option is a lot easier. For earlier versions=
=0A of zsh 3, you are stuck with trying to understand locales, see the=0A =
tt(setlocale(3)) and tt(zshparam(1)) manual pages: the simplest=0A possib=
ility may be to set tt(LC_ALL=3Den_US). For older versions of the=0A shel=
l, there is no easy way out.=0A=0A=0A =0A =
=0A Why do the cursor (arrow) keys not=0A =
work?=0A =0A=0A The cursor keys send=
different codes depending on the terminal; zsh=0A only binds the most wel=
l known versions. If you see these problems,=0A try putting the following=
in your .zshrc:=0A=0A verb(=0A bindkey "$(echotc=
kl)" backward-char=0A bindkey "$(echotc kr)" forward-char=0A bindkey=
"$(echotc ku)" up-line-or-history=0A bindkey "$(echotc kd)" down-line-o=
r-history=0A )=0A =0A If you use vi mode, use mytt(vi-backward-char) and=
mytt(vi-forward-char)=0A where appropriate. As of version 4.0.1, zsh att=
empts to look up these=0A codes and to set the key bindings for you (both =
emacs and vi), but in=0A some circumstances this may not work.=0A=0A Note=
, however, that up to version 3.0 binding arbitrary multiple key=0A sequen=
ces can cause problems, so check that this works with your set=0A up first=
=2E Also, from version 3.1.3, more sequences are supported by=0A default,=
namely those in the form mytt(<ESC>O) followed by tt(A),=0A tt(B), =
tt(C) or tt(D), as well as the corresponding set beginning=0A mytt(<ESC=
>[), so this may be redundant.=0A=0A A particular problem which sometim=
es occurs is that there are two=0A different modes for arrow keys, normal =
mode and keypad mode, which=0A send different sequences. Although this is=
largely a historical=0A artifact, it sometimes happens that your terminal=
can be switched from=0A one mode to the other, for example by a rogue pro=
gramme that sends the=0A sequence to switch one way, but not the sequence =
to switch back. Thus=0A you are stuck with the effects. Luckily in this =
case the arrow key=0A sequences are likely to be standard, and you can sim=
ply bind both sets.=0A The following code does this.=0A verb(=0A bindk=
ey '\e[A' up-line-or-history=0A bindkey '\e[B' down-line-or-history=0A=
bindkey '\e[C' forward-char=0A bindkey '\e[D' backward-char=0A =
bindkey '\eOA' up-line-or-history=0A bindkey '\eOB' down-line-or-histo=
ry=0A bindkey '\eOC' forward-char=0A bindkey '\eOD' backward-char=
=0A )=0A For most even vaguely VT100-compatible terminals, the above eigh=
t=0A instructions are a fairly safe bet for your .zshrc. Of course=0A you can substitute variant functions for the second arg=
ument here too.=0A=0A=0A =0A =
=0A Why does my terminal act funny in some=0A way?<=
/para>=0A =0A=0A If you are using an OpenWindo=
ws cmdtool as your terminal, any=0A escape sequences (such as those produc=
ed by cursor keys) will be=0A swallowed up and never reach zsh. Either us=
e shelltool or avoid=0A commands with escape sequences. You can also disa=
ble scrolling from=0A the cmdtool pane menu (which effectively turns it in=
to a shelltool).=0A If you still want scrolling, try using an xterm with t=
he scrollbar=0A activated.=0A=0A If that's not the problem, and you are u=
sing stty to change some tty=0A settings, make sure you haven't asked zsh =
to freeze the tty settings:=0A type=0A verb(=0A ttyctl -u=0A )=0A be=
fore any stty commands you use.=0A=0A On the other hand, if you aren't usi=
ng stty and have problems you may=0A need the opposite: mytt(ttyctl -f) f=
reezes the terminal to protect it=0A from hiccups introduced by other prog=
rammes (kermit has been known to=0A do this).=0A=0A A problem I have expe=
rienced myself (on an AIX 3.2 workstation with=0A xterm) is that termcap d=
einitialization sequences sent by `less'=0A were causing automargins to be=
turned off --- not actually a shell=0A problem, but you might have though=
t it was. The fix is to put `tt(X)'=0A into the environment variable tt(L=
ESS) to stop the sequences being sent.=0A Other programs (though not zsh) =
may also send that sequence.=0A=0A If myem(that)'s not the problem, and yo=
u are having difficulties with=0A external commands (not part of zsh), and=
you think some terminal=0A setting is wrong (e.g. tt(^V) is getting inter=
preted as `literal next=0A character' when you don't want it to be), try=
=0A verb(=0A ttyctl -u=0A STTY=3D'lnext "^-"' commandname=0A )=0A =
(in this example). Note that zsh doesn't reset the terminal completely=0A =
afterwards: just the modes it uses itself and a number of special=0A proc=
essing characters (see the tt(stty(1)) manual page).=0A=0A=0A =0A =0A Why does zsh not=
work in an Emacs shell=0A mode any more?=0A =0A=0A (This information comes from Bart Schaefer and other zsh-=
workers.)=0A=0A Emacs 19.29 or thereabouts stopped using a terminal type o=
f "emacs"=0A in shell buffers, and instead sets it to "dumb". Zsh only ki=
cks in=0A its special I'm-inside-emacs initialization when the terminal ty=
pe=0A is "emacs".=0A=0A Probably the most reliable way of dealing with th=
is is to look for=0A the environment variable mytt($EMACS), which is set t=
o mytt(t) in=0A Emacs' shell mode. Putting=0A verb(=0A [[ $EMACS =3D =
t ]] && unsetopt zle=0A )=0A in your .zshrc should be sufficient.=
=0A=0A Another method is to put=0A verb(=0A #!/bin/sh=0A TERM=3Dema=
cs exec zsh=0A )=0A into a file ~/bin/eshell, then mytt(chmod +x ~/bin/es=
hell), and=0A tell emacs to use that as the shell by adding=0A verb(=0A =
(setenv "ESHELL" (expand-file-name "~/bin/eshell"))=0A )=0A to ~/.emacs=
=2E=0A=0A=0A =0A =0A Why do my autoloaded functions not=0A autoload [the first=0A=
time]?=0A =0A=0A The problem is t=
hat there are two possible ways of autoloading a=0A function (see the AUTO=
LOADING FUNCTIONS section of the zsh manual=0A page zshmisc for more detai=
led information):=0A enumerate(=0A myeit() The file contains just the bod=
y of the function, i.e.=0A there should be no line at the beginning say=
ing mytt(function foo {)=0A or mytt(foo () {), and consequently no matc=
hing mytt(}) at the end.=0A This is the traditional zsh method. The ad=
vantage is that the=0A file is called exactly like a script, so can dou=
ble as both.=0A To define a function mytt(xhead () { print -n "\033]2;$=
*\a"; }),=0A the file would just contain mytt(print -n "\033]2;$*\a"). =
=0A myeit() The file contains the entire definition, and maybe even=0A =
other code: it is run when the function needs to be loaded, then=0A =
the function itself is called up. This is the method in ksh.=0A To def=
ine the same function mytt(xhead), the whole of the=0A usual definition=
should be in the file.=0A )=0A=0A In old versions of zsh, before 3.0, on=
ly the first behaviour was=0A allowed, so you had to make sure the file fo=
und for autoload just=0A contained the function body. You could still def=
ine other functions=0A in the file with the standard form for definitions,=
though they=0A would be redefined each time you called the main function.=
=0A=0A In version 3.0.x, the second behaviour is activated if the file=0A =
defines the autoloaded function. Unfortunately, this is=0A incompatible =
with the old zsh behaviour which allowed you to=0A redefine the function w=
hen you called it.=0A=0A From version 3.1, there is an option tt(KSH_AUTOL=
OAD) to allow full ksh=0A compatiblity, i.e. the function myem(must) be in=
the second form=0A above. If that is not set, zsh tries to guess which f=
orm you are=0A using: if the file contains only a complete definition of =
the=0A function in the second form, and nothing else apart from comments=
=0A and whitespace, it will use the function defined in the file;=0A othe=
rwise, it will assume the old behaviour. The option is set=0A if mytt(emu=
late ksh) is in effect, of course.=0A =0A (A neat trick to autoload all f=
unctions in a given directory is to=0A include a line like mytt(autoload ~=
/fns/*(:t)) in .zshrc; the bit in=0A parentheses removes the directory par=
t of the filenames, leaving=0A just the function names.)=0A=0A=0A =0A How does base arit=
hmetic work?=0A =0A =0A=0A The ksh=
syntax is now understood, i.e.=0A verb(=0A let 'foo =3D 16#ff'=0A )=
=0A or equivalently=0A verb(=0A (( foo =3D 16#ff ))=0A )=0A or even=
=0A verb(=0A foo=3D$((16#ff))=0A )=0A The original syntax was=0A ver=
b(=0A (( foo =3D [16]ff ))=0A )=0A --- this was based on a misundersta=
nding of the ksh manual page. It=0A still works but its use is deprecated=
=2E Then=0A verb(=0A echo $foo=0A )=0A gives the answer `255'. It i=
s possible to declare variables explicitly=0A to be integers, via=0A verb=
(=0A typeset -i foo=0A )=0A which has a different effect: namely the b=
ase used in the first=0A assignment (hexadecimal in the example) is subseq=
uently used whenever=0A `foo' is displayed (although the internal represen=
tation is unchanged).=0A To ensure foo is always displayed in decimal, dec=
lare it as=0A verb(=0A typeset -i 10 foo=0A )=0A which requests base =
10 for output. You can change the output base of an=0A existing variable =
in this fashion. Using the mytt($(( ... ))) method will=0A always display=
in decimal, except that in 3.1.9 there is a new feature=0A for selecting =
a base for displaying here:=0A verb(=0A print $(( [#16] 255 ))=0A )=0A=
=0A=0A =0A =0A How do I get a newline in my=0A prompt?
=0A =0A=0A You can place a literal newline in quotes, i.e.=0A ver=
b(=0A PROMPT=3D"Hi Joe,=0A what now?%# "=0A )=0A If you have the ba=
d taste to set the option cshjunkiequotes, which=0A inhibits such behaviou=
r, you will have to bracket this with=0A mytt(unsetopt cshjunkiequotes) an=
d mytt(setopt cshjunkiequotes), or put it=0A in your .zshrc before the option is set.=0A=0A In recent versions of zsh (not 3.0=
), there is a form of quoting which=0A interprets print sequences like `tt=
(\n)' but otherwise acts like single=0A quotes: surround the string with t=
t($'...'). Hence:=0A verb(=0A PROMPT=3D$'Hi Joe,\nwhat now?%# '=0A )=
=0A is a neat way of doing what you want. Note that it is the quotes, not=
=0A the prompt expansion, which turns the `tt(\n)' into a newline.=0A=0A=
=0A =0A =0A Why does mytt(bindkey ^a command-name) or=0A mytt(stty intr ^-) do so=
mething=0A funny?=0A =0A=0A You pr=
obably have the extendedglob option set in which case tt(^) and tt(#)=0A a=
re metacharacters. tt(^a) matches any file except one called tt(a), so the=
=0A line is interpreted as bindkey followed by a list of files. Quote the=
=0A tt(^) with a backslash or put quotation marks around tt(^a).=0A=0A=0A =
=0A =0A Why=
can't I bind tt(\C-s) and tt(\C-q)=0A any more?=0A =
=0A=0A The control-s and control-q keys now do flow contr=
ol by default,=0A unless you have turned this off with mytt(stty -ixon) or=
redefined the=0A keys which control it with mytt(stty start) or mytt(stty=
stop). (This is=0A done by the system, not zsh; the shell simply respect=
s these=0A settings.) In other words, tt(\C-s) stops all output to the te=
rminal,=0A while tt(\C-q) resumes it.=0A=0A There is an option tt(NO_FLOW=
_CONTROL) to stop zsh from allowing flow=0A control and hence restoring th=
e use of the keys: put mytt(setopt=0A noflowcontrol) in your .z=
shrc file.=0A=0A=0A =0A =0A How do I execute command mytt(foo) within=0A =
function mytt(foo)?=0A =0A=0A The c=
ommand mytt(command foo) does just that. You don't need this with=0A alia=
ses, but you do with functions. Note that error messages like=0A verb(=0A=
zsh: job table full or recursion limit exceeded=0A )=0A are a good si=
gn that you tried calling `foo' in function `foo' without=0A using `comman=
d'. If mytt(foo) is a builtin rather than an external=0A command, use myt=
t(builtin foo) instead.=0A=0A=0A =0A Why do history substitutions with=0A single ban=
gs do something=0A funny?=0A =0A=0A=
If you have a command like "tt(echo !-2:$ !$)", the first history=0A sub=
stitution then sets a default to which later history substitutions=0A with=
single unqualified bangs refer, so that !$ becomes equivalent to=0A tt(!-=
2:$). The option tt(CSH_JUNKIE_HISTORY) makes all single bangs refer=0A t=
o the last command.=0A=0A=0AWhy does zsh kill off all my background jobs when I logout?=0A=0A Simple answer: you haven't asked it not t=
o. Zsh (unlike [t]csh) gives=0A you the option of having background jobs =
killed or not: the mytt(nohup)=0A option exists if you don't want them kil=
led. Note that you can always=0A run programs with mytt(nohup) in front o=
f the pipeline whether or not the=0A option is set, which will prevent tha=
t job from being killed on=0A logout. (mytt(nohup) is actually an externa=
l command.)=0A=0A The mytt(disown) builtin is very useful in this respect:=
if zsh informs=0A you that you have background jobs when you try to logou=
t, you can=0A mytt(disown) all the ones you don't want killed when you exi=
t. This is=0A also a good way of making jobs you don't need the shell to =
know about=0A (such as commands which create new windows) invisible to the=
shell.=0A Likewise, you can start a background job with mytt(&!) inst=
ead of just=0A mytt(&) at the end, which will automatically disown the=
job.=0A=0A=0A =0A=0A =0A <=
question>How do I list all my history=0A entries?=0A =0A =0A=0A Tell zsh to start from entry 1: myt=
t(history 1). Those entries at the=0A start which are no longer in memory=
will be silently omitted.=0A=0A =0A =0A=0A =
How does the alternative loop syntax, e.g. myt=
t(while {...} {...}) \=0A work?=0A=0A =
=0A Zsh provides an alternative to the traditional sh-like forms with mytt=
(do),=0A verb(=0A while TEST; do COMMANDS; done=0A )=0A allowing you =
to have the COMMANDS delimited with some other command=0A structure, often=
mytt({...}). The rules are quite complicated and=0A in most scripts it i=
s probably safer --- and certainly more=0A compatible --- to stick with th=
e sh-like rules. If you are=0A wondering, the following is a rough guide.=
=0A=0A To make it work you must make sure the TEST itself is clearly=0A d=
elimited. For example, this works:=0A verb(=0A while (( i++ < 10 ))=
{ echo i is $i; }=0A )=0A but this does myem(not):=0A verb(=0A while=
let "i++ < 10"; { echo i is $i; } # Wrong!=0A )=0A The reason is th=
at after mytt(while), any sort of command list is valid.=0A This includes =
the whole list mytt(let "i++ < 10"; { echo i $i; });=0A the parser simp=
ly doesn't know when to stop. Furthermore, it is=0A wrong to miss out the=
semicolon, as this makes the mytt({...}) part=0A of the argument to mytt(=
let). A newline behaves the same as a=0A semicolon, so you can't put the =
brace on the next line as in C.=0A=0A So when using this syntax, the test =
following the mytt(while) must=0A be wrapped up: any of mytt(((...))), my=
tt([[...]]), mytt({...}) or=0A mytt((...)) will have this effect. (They h=
ave their usual syntactic=0A meanings too, of course; they are not interch=
angeable.) Note that=0A here too it is wrong to put in the semicolon, as =
then the case=0A becomes identical to the preceding one:=0A verb(=0A w=
hile (( i++ < 10 )); { echo i is $i; } # Wrong!=0A )=0A=0A The same =
is true of the mytt(if) and mytt(until) constructs:=0A verb(=0A if { tr=
ue } { echo yes } else { echo no }=0A )=0A but with mytt(for), which only=
needs a list of words, you can get=0A away with it:=0A verb(=0A for f=
oo in a b; { echo foo is $a; bar=3D$foo; }=0A )=0A since the parser knows=
it only needs everything up to the first=0A semicolon. For the same reaso=
n, there is no problem with the mytt(repeat),=0A mytt(case) or mytt(select=
) constructs; in fact, mytt(repeat) doesn't even=0A need the semicolon sin=
ce it knows the repeat count is just one word.=0A=0A This is independent o=
f the behaviour of the SHORTLOOPS option (see=0A manual), which you are in=
any case encouraged even more strongly not=0A to use in programs as it ca=
n be very confusing.=0A=0A=0A =0A =0A Why is my history not being saved?=0Alabel(321)=0A=0A In zsh, you need to set three variab=
les to make sure your history is=0A written out when the shell exits. For=
example,=0A verb(=0A HISTSIZE=3D200=0A HISTFILE=3D~/.zsh_history=0A=
SAVEHIST=3D200=0A )=0A tt($HISTSIZE) tells the shell how many lines t=
o keep internally,=0A tt($HISTFILE) tells it where to write the history, a=
nd tt($SAVEHIST),=0A the easiest one to forget, tells it how many to write=
out. The=0A simplest possibility is to set it to the same as tt($HISTSIZ=
E) as=0A above. There are also various options affecting history; see the=
=0A manual.=0A=0A=0AHow do I get a variable's value to be evaluated as another variable?=0A=0A The problem is that you have a variable=
tt($E) containing the string=0A mytt(EDITOR), and a variable tt($EDITOR) =
containing the string mytt(emacs),=0A or something such. How do you get f=
rom tt($E) to emacs in one easy=0A stage?=0A=0A There is no standard sing=
le-stage way of doing this. However, there=0A is a zsh idiom (available i=
n all versions of zsh since 3.0) for this:=0A verb(=0A print ${(e)E:+\$=
$E}=0A )=0A Ignore the mytt((e)) for now. The mytt(:+) means: if the var=
iable=0A tt($E) is set, substitute the following, i.e. mytt(\$$E). This i=
s=0A expanded to mytt($EDITOR) by the normal rules. Finally, the mytt((e)=
) \=0A means=0A `evaluate the expression you just made'. This gives mytt=
(emacs).=0A=0A For a standard shell way of doing this, you are stuck with =
mytt(eval):=0A verb(=0A eval echo \$$E=0A )=0A produces the same resu=
lt.=0A=0A Versions since 3.1.6 allow you to do this directly with a new fl=
ag;=0A mytt(${(P)E}).=0A=0A As a slight aside, sometimes people note that=
the syntax mytt(${${E}})=0A is valid and expect it to have this effect. =
It probably ought to, but=0A in the early days of zsh it was found conveni=
ent to have this way of=0A producing different substitutions on the same p=
arameter; for example,=0A mytt(${${file##**/}%.*}) removes everything up t=
o the last slash in=0A mytt($file), then everything from the last dot on, =
inclusive (try=0A it, this works). So in mytt(${${E}}), the internal mytt=
(${...})=0A actually does nothing.=0A=0A=0AHow do I prevent the prompt overwriting output wh=
en there is no newline?=0A=0A The problem =
is, for example,=0A verb(=0A % echo -n foo=0A % =0A )=0A and the t=
t(foo) has been overwritten by the prompt tt(%). The reason this=0A happe=
ns is that the option tt(PROMPT_CR) is enabled by default, and it=0A outpu=
ts a carriage return before the prompt in order to ensure that the=0A line=
editor knows what column it is in (this is needed to position the=0A righ=
t-side prompt correctly (mytt($RPROMPT), mytt($RPS1)) and to avoid screen=
=0A corruption when performing line editing). If you add tt(unsetopt prom=
ptcr)=0A to your .zshrc, you will see any partial ou=
tput, but your screen may=0A look weird until you press return or refresh =
the screen.=0A=0A Another solution for many terminals is to define a precm=
d function that=0A outputs a screen-width of spaces, like this:=0A verb(=
=0A function precmd {=0A echo -n ${(l:$COLUMNS:::):-}=0A }=0A )=
=0A (Explanation: an empty parameter expansion is padded out to the number=
of=0A columns on the screen.) That precmd function will only bump the sc=
reen=0A down to a new line if there was output on the prompt line, otherwi=
se the=0A extra spaces get removed by the tt(PROMPT_CR) action. Although =
this=0A typically looks fine it may result in the preceding spaces being i=
ncluded=0A when you select a line of text with the mouse.=0A=0A One final=
alternative is to put a newline in your prompt -- see question=0A link(3.=
13)(313) for that.=0A=0A=0AWhat's wrong with cut and paste on my xterm?
=0A=0A On the majority of modern UNIX systems, cutting text from=
one window and=0A pasting it into another should work fine. On a few, ho=
wever, there are=0A problems due to issues about how the terminal is handl=
ed: most programs=0A expect the terminal to be in `canonical input mode',=
which means that the=0A program is passed a whole line of input at a time=
, while for editing=0A the shell needs a single character at a time and mu=
st be in=0A `non-canonical input mode'. On the systems in question, input=
can be=0A lost or re-ordered when the mode changes. There are actually t=
wo=0A slightly different problems:=0A enumerate(=0A myeit() When you pas=
te something in while a programme is running, so that=0A the shell only=
retrieves it later. Traditionally, there was a test=0A which was used=
only on systems where the problem was known to exist,=0A so it is poss=
ible some other systems were not handled (for example,=0A certain versi=
ons of IRIX, it appears); also, continuation lines were=0A not handled =
properly. A more reliable approach appears from versions=0A 3.0.6 and =
3.1.6.=0A myeit() When the shell is waiting for input, and you paste in a =
chunk of=0A text consisting of more than one complete set of commands.=
=0A Unfortunately, this is a much harder problem: the line editor is=0A=
already active, and needs to be turned off when the first command is=
=0A executed. The shell doesn't even know if the remaining text is inp=
ut=0A to a command or for the shell, so there's simply nothing it can d=
o.=0A However, if you have problems you can trick it: type `tt({)' on a=
line=0A by itself, then paste the input, then type `tt(})' on a line b=
y=0A itself. The shell will not execute anything until the final brace=
is=0A read; all input is read as continuation lines (this may require =
the=0A fixes referred to above in order to be reliable).=0A )=0A=0AHow do I get coloured=
prompts on my colour xterm?=0A=0A (Or `co=
lor xterm', if you're reading this in black and white.) You need=0A to fi=
nd the sequences which generate the various colours from the manual=0A for=
your terminal emulator; these are ANSI standard on those I know about=0A =
which support colour. With a recent (post 3.1.6) distribution of zsh,=0A =
there is a theme system to handle this for you; even if you don't see that,=
=0A the installed function `mytt(colors)' (meaning `colours', if you're no=
t=0A reading this in black and white) gives the escape sequences. You wil=
l end=0A up with code looking like this (borrowed from Oliver Kiddle):=0A =
verb(=0A PS1=3D$'%{\e[1;31m%}<the rest of your prompt here>%{\e[0=
m%}'=0A )=0A The mytt($') form of quoting turns the `mytt(\e)' into a rea=
l escape=0A character; this only works from about version 3.1.4, so if you=
're using=0A 3.0.x, you need to do something like=0A verb(=0A PS1=3D"$=
(print '%{\e[1;31m%}<the rest goes here>%{\e[0m%}')"=0A )=0A The `m=
ytt(%{...%})' is used in prompts for strings which will=0A not appear as c=
haracters, so that the prompt code doesn't miscalculate the=0A length of t=
he prompt which would have a bad effect on editing. The=0A resulting `myt=
t(<ESC>[1;31m)' makes the prompt red, and the=0A `mytt(<ESC>[0=
m)' puts printing back to normal so that the rest of the line=0A is unchan=
ged.=0A=0A =0A =0A =
=0A Why is my output duplicated with `tt(foo 2>&1 >foo.out =
| bar)'?=0A =0A =0A=0A This is a s=
lightly unexpected effect of the option tt(MULTIOS), which is=0A set by de=
fault. Let's look more closely:=0A verb(=0A foo 2>&1 >foo.out |=
bar=0A )=0A What you're probably expecting is that the command mytt(foo)=
sends its=0A standard output to the pipe and so to the input of the comma=
nd mytt(bar),=0A while it sends its standard error to the file mytt(foo.ou=
t). What you=0A actually see is that the output is going both to the pipe=
and into the=0A file. To be more explicit, here's the same example with =
real commands:=0A verb(=0A % { print output; print error >&2 } 2=
>&1 >foo.out | sed 's/error/erratic'=0A erratic=0A output=0A =
% cat foo.out=0A output=0A )=0A and you can see `tt(output)' appears=
twice.=0A=0A It becomes clearer what's going on if we write:=0A verb(=0A=
% print output >foo1.out >foo2.out=0A % cat foo1.out=0A output=0A=
% cat foo2.out=0A output=0A )=0A You might recognise this as a sta=
ndard feature of zsh, called `tt(multios)'=0A and controlled by the option=
of the same name, whereby output is copied=0A to both files when the redi=
rector appears twice. What's going on in the=0A first example is exactly =
the same, however the second redirector is=0A disguised as a pipe. So if =
you want to turn this effect off, you need=0A to unset the option mytt(MUL=
TIOS).=0A=0A=0A=0A=0A=0A=0AThe mysteries of completion)=0A=0A=0AWhat is completion?=0A=0A `Completi=
on' is where you hit a particular command key (TAB is the=0A standard one)=
and the shell tries to guess the word you are typing=0A and finish it for=
you --- a godsend for long file names, in=0A particular, but in zsh there=
are many, many more possibilities than=0A that.=0A=0A There is also a re=
lated process, `expansion', where the shell sees=0A you have typed somethi=
ng which would be turned by the shell into=0A something else, such as a va=
riable turning into its value ($PWD=0A becomes /home/users/mydir) or a his=
tory reference (!! becomes=0A everything on the last command line). In zs=
h, when you hit TAB it=0A will look to see if there is an expansion to be =
done; if there is,=0A it does that, otherwise it tries to perform completi=
on. (You can=0A see if the word would be expanded --- not completed --- b=
y TAB by=0A typing mytt(\C-x g), which lists expansions.) Expansion is ge=
nerally=0A fairly intuitive and not under user control; for the rest of th=
e=0A chapter I will discuss completion only.=0A=0A An elegant completion =
system appeared in version 4, replacing the old=0A tt(compctl) command. T=
his is based on functions called automatically for=0A completion in partic=
ular contexts (for example, there is a function=0A called tt(_cd) to handl=
e completion for the tt(cd) command) and is=0A installed automatically wit=
h the shell, so all you need to do, in=0A principal, is to arrange for thi=
s to be loaded. Putting `tt(autoload -U=0A compinit; compinit)' in your <=
filename >.zshrc should be enough if the system is=0A installed=
properly.=0A=0A=0AWhat sorts of things can be completed?=0A=
=0A The simplest sort is filename completion, mentioned above. Unless=0A =
you have made special arrangements, as described below, then after=0A you=
type a command name, anything else you type is assumed by the=0A completi=
on system to be a filename. If you type part of a word and=0A hit TAB, zs=
h will see if it matches the first part a filename and=0A if it does it wi=
ll automatically insert the rest.=0A=0A The other simple type is command c=
ompletion, which applies=0A (naturally) to the first word on the line. In=
this case, zsh=0A assumes the word is some command to be executed lying i=
n your $PATH=0A (or something else you can execute, like a builtin command=
, a=0A function or an alias) and tries to complete that.=0A=0A However, t=
he new completion system is highly sensitive to context=0A and comes with =
completions for many UNIX commands. These are=0A automatically loaded whe=
n you run tt(compinit) as described above.=0A So the real answer to the qu=
estion `what can be completed?' is=0A `anything where an automated guess i=
s possible'. Just hit TAB=0A and see if the shell manages to guess correc=
tly.=0A=0A=0AHow d=
oes zsh deal with ambiguous completions?=0A=
=0A Often there will be more than one possible completion: two files=0A s=
tart with the same characters, for example. Zsh has a lot of=0A flexibili=
ty for what it does here via its options. The default is=0A for it to bee=
p and completion to stop until you type another=0A character. You can typ=
e tt(\C-D) to see all the possible completions.=0A (That's assuming you're=
at the end of the line, otherwise tt(\C-D) will=0A delete the next charac=
ter and you have to use tt(ESC-\C-D).) This can be=0A changed by the foll=
owing options, among others:=0A itemize(=0A it() with tt(NO_BEEP) set, t=
hat annoying beep goes away=0A it() with tt(NO_LIST_BEEP), beeping is onl=
y turned off for ambiguous=0A completions=0A it() with tt(AUTO_LIST)=
set, when the completion is ambiguous you get a=0A list without havin=
g to type tt(\C-D)=0A it() with tt(BASH_AUTO_LIST) set, the list only hap=
pens the second=0A time you hit tab on an ambiguous completion=0A it=
() with tt(LIST_AMBIGUOUS), this is modified so that nothing is listed if=
=0A there is an unambiguous prefix or suffix to be inserted --- this=
=0A can be combined with tt(BASH_AUTO_LIST), so that where both are=0A=
applicable you need to hit tab three times for a listing.=0A it() w=
ith tt(MENU_COMPLETE) set, one completion is always inserted=0A comple=
tely, then when you hit TAB it changes to the next, and so=0A on until=
you get back to where you started=0A it() with tt(AUTO_MENU), you only g=
et the menu behaviour when you hit TAB=0A again on the ambiguous compl=
etion.=0A it() Finally, although it affects all completion lists, includi=
ng=0A those explicitly requested, note also tt(ALWAYS_LAST_PROMPT), wh=
ich=0A causes the cursor to return to the line you were editing after=
=0A printing the list, provided that is short enough.=0A )=0A Combin=
ations of these are possible; for example, tt(AUTO_LIST) and=0A tt(AUTO_ME=
NU) together give an intuitive combination. Note that=0A from version 3.1=
tt(LIST_AMBIGUOUS) is set by default; if you use=0A autolist, you may wel=
l want to `unsetopt listambiguous'.=0A=0A=0AHow do I complete in the middle of words / just w=
hat's before the cursor?=0A=0A Sometimes y=
ou have a word on the command-line which is incomplete in the=0A middle. =
Normally if you hit tab in zsh, it will simply go to the end of=0A the wor=
d and try to complete there. However, there are two ways of=0A changing t=
his.=0A=0A First, there is the option COMPLETE_IN_WORD. This tries to fil=
l in=0A the word at the point of the cursor. For example, if the current=
=0A directory contains mytt(foobar), then with the option set, you can=0A =
complete mytt(fbar) to mytt(foobar) by moving the cursor to the=0A mytt(b=
) and hitting tab.=0A=0A To complete just what's before the cursor, ignori=
ng anything after, you=0A need the function tt(expand-or-complete-prefix):=
it works mostly like the=0A usual function bound to tab, but it ignores a=
nything on the right of the=0A cursor. If you always want this behaviour =
(some other shells do this),=0A bind it to tab; otherwise put another bind=
ing, e.g. mytt(^X TAB) in=0A ~/.zshrc:=0A verb(=0A =
bindkey "^X^I" expand-or-complete-prefix=0A )=0A=0A The completion sys=
tem's handling of filenames allows you to complete=0A multiple segments of=
a path in one go, so for example tt(/u/l/b)=0A can expand to tt(/usr/loca=
l/bin) or anything else that matches. This=0A saves you having to expand =
the middle part of the path separately.=0A=0A=0A =0A How do I get started with programmable=
completion?=0A=0A The main resource is th=
e tt(zshcompsys) manual page. It's complicated,=0A I'm afraid, far too mu=
ch to go into here. See also the user guide=0A referred to above, or copy=
one of the very many existing functions. For=0A a professionally produce=
d guide, see the book `From Bash to Z Shell:=0A Conquering the Command Lin=
e' by Oliver Kiddle, Jerry Peek and Peter=0A Stephenson (me), published by=
Apress, ISBN 1-59059-376-6. Chapter 10=0A tells you how to configure the=
completion system and chapter 15 how=0A to write your own completion func=
tions.=0A=0A=0A =0A =0A Suppose I want to complete all files during a special completion?=
=0A =0A=0A If you're using the completio=
n system the shell will decide what=0A to complete when you hit TAB. That=
's usually the right thing for=0A the context, but sometimes you just want=
to complete files, like=0A TAB used to do in the old days. You can set u=
p this up as follows:=0A =0A zle -C complete-file compl=
ete-word _generic=0A zstyle ':completion:complete-file::::' completer _f=
iles=0A bindkey '^xF' complete-file=0A =0A This turns=
the key tt(\C-x F) into a command tt(complete-file) which=0A goes straigh=
t to the completion system's file completion command,=0A ignoring the norm=
al context. Change the binding how you like.=0A=0A Note the way the form =
of completion to use is specified by picking a=0A `completer' called `tt(_=
files)'. You can define any completion=0A to be bound to a keystroke by p=
utting the appropriate completion=0A function at that point. Then change =
all occurrences of=0A `tt(complete-file)' to a name of your own.=0A=0A If=
you simply want to try filename completion as a default when other=0A com=
pletions fail, add it to the `tt(completer)' style for normal=0A completio=
n, for example:=0A =0A zstyle ':completion:*' completer=
_complete _ignored _files=0A =0A This adds filename com=
pletion to the end of the default types of=0A completion. Your actual com=
pleter style may include other actions,=0A such as expansion or approximat=
e completion.=0A=0A=0A
=0A=
The future of zsh=0A=0A =0A What bugs are currently known and unfixed? (Plus recent \=0A =
important changes)=0A=0A =0A Bugs tend=
to be tracked on the zsh-workers mailing list; see the=0A next section. =
Check the mailing list to see if a bug has been=0A reported. (There is a =
bug tracker at the zsh development site=0A at Sourceforge, but it's not in=
active use.)=0A=0A To see how recent versions of the shell have changed, =
look at=0A the README file in the source distribution. This indicates the=
=0A most important changes, and in particular draws attention to=0A incom=
patibilities you might notice.=0A=0A=0A
=0A =
=0A Where do I report bugs, =
get more info / who's working on zsh?=0A =0A =
=0A =0A=0A The shell is being maintained by various (entirely self=
-appointed)=0A subscribers to the mailing list,=0A zsh-workers@sun=
site.dk=0A so mail on any issues (bug reports, suggestions, compla=
ints...)=0A related to the development of the shell should be sent there. =
If=0A you want someone to mail you directly, say so. Most patches to zsh=
=0A appear there first.=0A=0A =0A =0A=0A Note that this lo=
cation has just changed (January 1999), and the=0A instructions to go with=
it are slightly different --- in particular,=0A if you are already subscr=
ibed, the instructions about how to=0A unsubscribe are different.=0A=0A=0A=
=0A =0A Please note when reporting bugs that many exist on=
ly on certain=0A architectures, which the developers may not have access t=
o. In=0A this case debugging information, as detailed as possible, is=0A =
particularly welcome.=0A=0A=0A =0A =0A Two progressively l=
ower volume lists exist, one with messages=0A concerning the use of zsh,=
=0A zsh-users@sunsite.dk=0A and one just containing announ=
cements: about releases, about major=0A changes in the shell, or this FAQ=
, for example,=0A zsh-announce@sunsite.dk=0A (posting to t=
he last one is currently restricted).=0A=0A=0A =0A =0A Note=
that you should only join one of these lists: people on=0A zsh-workers r=
eceive all the lists, and people on zsh-users will=0A also receive the ann=
ouncements list.=0A=0A=0A =0A =0A The lists are handled by =
an automated server. The instructions for=0A zsh-announce and zsh-users a=
re the same as for zsh-workers: just=0A change zsh-workers to whatever in =
the following.=0A=0A=0A =0A =0A To join zsh-workers, send e=
mail to=0A zsh-workers-subscribe@sunsite.dk=0A (the actual=
content is unimportant). Replace tt(subscribe) with=0A tt(unsubscribe) t=
o unsubscribe. The mailing software=0A (ezmlm)=
has=0A various bells and whistles: you can retrieve archived messages.=0A=
Mail zsh-workers-help@sunsite.dk for detailed information.=
=0A Adminstrative matters are best sent to=0A zsh-workers-owner@su=
nsite.dk. The list maintainer's=0A real name is Karsten=0A Thygesen=0A =
karthy@kom.auc.dk.=0A =0A=0A =0A =0A An a=
rchive of mailings for the last few years can be found at=0A at the main zsh archive in Australia.=0A=0A=
=0A =0A =0A Of course, you can also post zsh queries to the=
Usenet group=0A comp.unix.shell; if all else fails, you could even e-mail=
me.=0A =0A=0A =0A =
What's on the wish-list?=0A=0A The c=
ode bears the marks of the ages and many things could be done much=0A bett=
er with a rewrite. A more efficient set of code for=0A lexing/parsing/exe=
cution might also be an advantage. Volunteers are=0A particularly welcome=
for these tasks.=0A=0A Some future possibilities which have been suggeste=
d:=0A =0A The shell, in particular the lin=
e editor, should support Unicode=0A characters. Initial support for th=
is should appear in version 4.3,=0A but this is a large job.=0A The parameter code could do with tidying up,=
maybe with more of the=0A features made available in ksh93.=
listitem>=0A Configuration files to enable zsh startup fil=
es to be created=0A with the Dotfile Generator.=0A Further improvements in integrating the line editor with shel=
l=0A functions.=0A POSIX compatibilit=
y could be improved.=0A Option for glo=
b qualifiers to follow perl syntax (a traditional=0A item).=0A =0A=0A =0A =0A Did zsh have problems in the year 2000?=0A =0A =0A=0A Not that I heard of; it's u=
p to you to be careful with two-digit dates,=0A though, which are produced=
by the prompt escapes mytt(%W) and mytt(%D),=0A and also by the command `=
tt(print -P)'. Earlier versions of zsh may=0A show problems here.=0A=0A=
=0Ansect(Acknowledgments:)=0A=0AThanks to zsh-list, in particular Bart Scha=
efer, for suggestions=0Aregarding this document. Zsh has been in the hands=
of archivists Jim=0AMattson, Bas de Bakker, Richard Coleman, Zoltan Hidveg=
i and Andrew=0AMain, and the mailing list has been run by Peter Gray, Rick =
Ohnemus,=0ARichard Coleman and Karsten Thygesen, all of whom deserve thanks=
=2E The=0Aworld is eternally in the debt of Paul Falstad for inventing zsh=
in=0Athe first place (though the wizzo extended completion is by Sven=0AWi=
schnowsky).=0A=0A=0Ansect(Copyright Information:)=0A=0AThis document is cop=
yright © P.W. Stephenson, 1995, 1996, 1997,=0A1998, 1999, 2000. This t=
ext originates in the U.K. and the author asserts=0Ahis moral rights under =
the Copyrights, Designs and Patents Act, 1988.=0A=0APermission is hereby gr=
anted, without written agreement and without=0Alicense or royalty fees, to =
use, copy, modify, and distribute this=0Adocumentation for any purpose, pro=
vided that the above copyright=0Anotice appears in all copies of this docum=
entation. Remember,=0Ahowever, that this document changes monthly and it m=
ay be more useful=0Ato provide a pointer to it rather than the entire text.=
A suitable=0Apointer is "information on the Z-shell can be obtained on th=
e World=0AWide Web at URL .=0A=0A=0A=0A=0A=0A =0A=0A
--Q68bSM7Ycu6FN28Q--