Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: My zshrc; any sugestions welcome

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