zsh-users
 help / color / mirror / code / Atom feed
From: Thorsten Kampe <thorsten@thorstenkampe.de>
To: zsh-users@sunsite.dk
Subject: Re: named directory expansion on strings
Date: Sat, 13 Mar 2004 18:48:11 +0100	[thread overview]
Message-ID: <eern2388dxq8.dlg@thorstenkampe.de> (raw)
In-Reply-To: <1040313064100.ZM28748@candle.brasslantern.com>

* 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!
`---


  reply	other threads:[~2004-03-13 17:48 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-03-13  3:29 Thorsten Kampe
2004-03-13  6:41 ` Bart Schaefer
2004-03-13 17:48   ` Thorsten Kampe [this message]
2004-03-14 18:54     ` Bart Schaefer
2004-03-14 21:24       ` Thorsten Kampe
2004-03-14 21:57       ` Python/zsh/perl [was: named directory expansion on strings] Vincent Stemen
2004-03-15  4:00         ` Jos Backus
2004-03-15  7:04         ` [OT]Python/zsh/perl " Bob Schmertz
2004-03-15 23:37           ` [OT]Python/zsh/perl Vincent Stemen
2004-03-17  4:03           ` [OT]Python/zsh/perl [was: named directory expansion on strings] Eric Mangold
2004-03-14 22:19       ` named directory expansion on strings Thorsten Kampe
2004-03-14 23:19         ` Bart Schaefer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=eern2388dxq8.dlg@thorstenkampe.de \
    --to=thorsten@thorstenkampe.de \
    --cc=zsh-users@sunsite.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).