From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29451 invoked from network); 13 Mar 2004 17:48:46 -0000 Received: from sunsite.dk (130.225.247.90) by ns1.primenet.com.au with SMTP; 13 Mar 2004 17:48:46 -0000 Received: (qmail 7715 invoked by alias); 13 Mar 2004 17:48:25 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 7169 Received: (qmail 7703 invoked from network); 13 Mar 2004 17:48:24 -0000 Received: from localhost (HELO sunsite.dk) (127.0.0.1) by localhost with SMTP; 13 Mar 2004 17:48:24 -0000 X-MessageWall-Score: 0 (sunsite.dk) Received: from [80.91.224.249] by sunsite.dk (MessageWall 1.0.8) with SMTP; 13 Mar 2004 17:48:23 -0000 Received: from list by main.gmane.org with local (Exim 3.35 #1 (Debian)) id 1B2DFC-0006oO-00 for ; Sat, 13 Mar 2004 18:48:18 +0100 Received: from isi-dialin-129-193.isionline-dialin.de ([195.158.129.193]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sat, 13 Mar 2004 18:48:18 +0100 Received: from thorsten by isi-dialin-129-193.isionline-dialin.de with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sat, 13 Mar 2004 18:48:18 +0100 X-Injected-Via-Gmane: http://gmane.org/ To: zsh-users@sunsite.dk From: Thorsten Kampe Subject: Re: named directory expansion on strings Date: Sat, 13 Mar 2004 18:48:11 +0100 Message-ID: References: <1040313064100.ZM28748@candle.brasslantern.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-193.isionline-dialin.de User-Agent: 40tude_Dialog/2.0.10.1de Sender: news * Bart Schaefer (2004-03-13 07:41 +0100) > On Mar 13, 4:29am, Thorsten Kampe wrote: > } Is there a way to perform "named directory" expansion on strings? > > Sort of. See "print" in "man zshbuiltins" and look at the -D option. Yes, this was the reason why I asked. The "-D" option made the output for my "zcompile" script more readable, but it defeated the adjustment of my "[ ok ]" because it made a difference whether "~" was substituted in the path or not. So I wanted to compute the length of the output to compensate the "adjustment" to the right. Fortunately, I found a better way[1]. Any style comments on my first /really complicated/ ;-) zsh shell script welcome! > } Something like "autonamedirs" and the "%~" in the prompt... > } > } % file=/etc/foo > } % ETCDIR=/etc > } % echo `bar#!$whatever($file)` > > I take it that the stuff in backticks is something that you just made up > to represent an arbitrary cryptic zsh incantation? Yes. Unfortunately when making more complex zsh scripts it tends to go into the perl direction: code that has to be decrypted by an inaugurated before it makes sense. And even then it's: "no, no, I wrote '#.(' and not '.#(' which does something completely different". Long live the Zen of Python[2]. Thorsten [1] ,--- | #! /bin/zsh -f | emulate -LR zsh | | JUSTIFY=71 | | autoload -U colors | colors # zshcontrib(1) | | ltgreen=$fg_bold[green] | ltred=$fg_bold[red] | white=$fg_no_bold[white] | | for file in /etc/profile.d/zshell.zsh \ | /etc/zsh/zprofile \ | /etc/zprofile \ | ~/.zsh/.zlogin \ | ~/.zsh/.zshrc \ | ~/.zshenv | do | if [[ -e $file && ! -w $(dirname $file) ]]; then | print ${(r.$JUSTIFY.):-"${ltred}! ${white}ERROR: $file - directory not writable"} \ | "[ ${ltred}failed ${white}]" | elif [[ -r $file && -w $(dirname $file) ]]; then | # '$(print -D)' instead of simple 'print -D' because padding isn't aware | # of "~" named directory expansion in length calculation | print ${(r.$JUSTIFY.):-"${ltgreen}* ${white}compiling $(print -D $file)"} \ | "[ ${ltgreen}ok ${white}]" | zcompile -R $file | fi | done `--- [2] ,--- | Beautiful is better than ugly. | Explicit is better than implicit. | Simple is better than complex. | Complex is better than complicated. | Flat is better than nested. | Sparse is better than dense. | Readability counts. | Special cases aren't special enough to break the rules. | Although practicality beats purity. | Errors should never pass silently. | Unless explicitly silenced. | In the face of ambiguity, refuse the temptation to guess. | There should be one-- and preferably only one --obvious way to do it. | Although that way may not be obvious at first unless you're Dutch. | Now is better than never. | Although never is often better than *right* now. | If the implementation is hard to explain, it's a bad idea. | If the implementation is easy to explain, it may be a good idea. | Namespaces are one honking great idea -- let's do more of those! `---