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

Re: named directory expansion on strings



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



Messages sorted by: Reverse Date, Date, Thread, Author