From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 319 invoked from network); 12 Mar 2004 22:34:05 -0000 Received: from sunsite.dk (130.225.247.90) by ns1.primenet.com.au with SMTP; 12 Mar 2004 22:34:05 -0000 Received: (qmail 7571 invoked by alias); 12 Mar 2004 22:33:41 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 7161 Received: (qmail 7558 invoked from network); 12 Mar 2004 22:33:40 -0000 Received: from localhost (HELO sunsite.dk) (127.0.0.1) by localhost with SMTP; 12 Mar 2004 22:33:40 -0000 X-MessageWall-Score: 0 (sunsite.dk) Received: from [80.91.224.249] by sunsite.dk (MessageWall 1.0.8) with SMTP; 12 Mar 2004 22:33:40 -0000 Received: from list by main.gmane.org with local (Exim 3.35 #1 (Debian)) id 1B1vDo-00022k-00 for ; Fri, 12 Mar 2004 23:33:40 +0100 Received: from isi-dialin-129-252.isionline-dialin.de ([195.158.129.252]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 12 Mar 2004 23:33:39 +0100 Received: from thorsten by isi-dialin-129-252.isionline-dialin.de with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 12 Mar 2004 23:33:39 +0100 X-Injected-Via-Gmane: http://gmane.org/ To: zsh-users@sunsite.dk From: Thorsten Kampe Subject: Re: Justifying text output Date: Fri, 12 Mar 2004 23:33:34 +0100 Message-ID: <33snq6yy99bx$.dlg@thorstenkampe.de> References: <1mm7og67rpkdy.dlg@thorstenkampe.de> <2136.1079089152@csr.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Complaints-To: usenet@sea.gmane.org X-Gmane-NNTP-Posting-Host: isi-dialin-129-252.isionline-dialin.de User-Agent: 40tude_Dialog/2.0.10.1de Sender: news * Peter Stephenson (2004-03-12 11:59 +0100) > Thorsten Kampe wrote: >> I wrote a little script[1] that compiles the main zsh config files. Is >> there any way to make the "[ ok ]"/"[ failed ]" messages on the right >> justified? > > There are various ways; most involve assigning the variable-length part > of the message to a string. You should probably not put any escape > characters in there so it doesn't include them in the length > calculation (though if the escape sequences are all the same you would > get away with it). > > The standard ksh way is (using a simplified example) to specify left > justification for a parameter: A "parameter" is a variable in "zshspeak"? And typeset declares the type of the variable because Bourne shells "think" everything is a string? ("Unlike many other programming languages, Bash does not segregate its variables by "type". Essentially, Bash variables are character strings" -- Advanced bash scripting Guide) > typeset -L 40 msg > for msg in "message one" "a longer message here" "short"; do > print ${msg} "[ WOW ]" > done > [...] > You can avoid using the `-L 40' if you change ${msg} to ${(r.40.)msg}. > That's a zsh extension which pads to the given width with spaces. The > `r' appears instead of `l' because it indicates where the padding goes, > not where the justification is. Where is that documented? > However, you can actually get away without assigning the message to a > parameter: > > print ${(r.40.):-"message one"} "WOW" > print ${(r.40.):-"a longer message here"} "WOW" > print ${(r.40.):-"short"} "WOW" Again: I couldn't find anything about than in the manpage (man zshbuiltins for "printf"). What does ":-" do? Substring selection. String formatting? > That works because zsh treats the absence of a parameter name as an > unset parameter, so it uses the normal logic for :-. In other words, > `if the length of the parameter is zero, substitute the following string > instead'. The (r.40.) padding flag works just the same. You can > include further substitutions in the text, so this would still work in > your case. Plain magic to me. Thorsten