* Re: globbing problem
[not found] <20130303092908.0562f2d1__42920.4312772073$1362301372$gmane$org@arcor.com>
@ 2013-03-03 14:40 ` Christian Neukirchen
2013-03-03 18:42 ` Bart Schaefer
0 siblings, 1 reply; 3+ messages in thread
From: Christian Neukirchen @ 2013-03-03 14:40 UTC (permalink / raw)
To: zsh-workers
Manfred Lotz <manfred.lotz@arcor.de> writes:
> function lsd() {
> if (( $# > 0 )); then
> ls -d "$*"(/)
> else
> ls -d *(/)
> fi
> }
>
>
> alias lsd='noglob lsd'
> $ lsd m*
> ls: cannot access m*(/): No such file or directory
>
> doesn't work.
>
> What is my mistake?
You need to force globbing. Try this:
lsd() { local -a pat; pat=(${^*:-*}'(/N)'); ls -d ${~pat} }
(How to do it without a temporary variable?)
--
Christian Neukirchen <chneukirchen@gmail.com> http://chneukirchen.org
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: globbing problem
2013-03-03 14:40 ` globbing problem Christian Neukirchen
@ 2013-03-03 18:42 ` Bart Schaefer
2013-03-03 19:08 ` Christian Neukirchen
0 siblings, 1 reply; 3+ messages in thread
From: Bart Schaefer @ 2013-03-03 18:42 UTC (permalink / raw)
To: zsh-workers
On Mar 3, 3:40pm, Christian Neukirchen wrote:
} Subject: Re: globbing problem
}
} Manfred Lotz <manfred.lotz@arcor.de> writes:
}
} > function lsd() {
} > if (( $# > 0 )); then
} > ls -d "$*"(/)
} > else
} > ls -d *(/)
} > fi
} > }
} >
} > alias lsd='noglob lsd'
}
} You need to force globbing. Try this:
}
} lsd() { local -a pat; pat=(${^*:-*}'(/N)'); ls -d ${~pat} }
}
} (How to do it without a temporary variable?)
By simply doing it without a temporary variable!
lsd() { ls -d ${^~*:-*}(/) }
If you throw in the (N) like Christian did, "lsd notadirectory" will give
you "./" which may or may not be what you want.
If you want to be able to handle other "ls" options ("lsd -l m*") then
you'll need temporaries to capture the options and patterns separately.
But handling all the possible options of "ls" is a large task all by
itself ...
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: globbing problem
2013-03-03 18:42 ` Bart Schaefer
@ 2013-03-03 19:08 ` Christian Neukirchen
0 siblings, 0 replies; 3+ messages in thread
From: Christian Neukirchen @ 2013-03-03 19:08 UTC (permalink / raw)
To: zsh-workers
Bart Schaefer <schaefer@brasslantern.com> writes:
> On Mar 3, 3:40pm, Christian Neukirchen wrote:
> } Subject: Re: globbing problem
> }
> } Manfred Lotz <manfred.lotz@arcor.de> writes:
> }
> } > function lsd() {
> } > if (( $# > 0 )); then
> } > ls -d "$*"(/)
> } > else
> } > ls -d *(/)
> } > fi
> } > }
> } >
> } > alias lsd='noglob lsd'
> }
> } You need to force globbing. Try this:
> }
> } lsd() { local -a pat; pat=(${^*:-*}'(/N)'); ls -d ${~pat} }
> }
> } (How to do it without a temporary variable?)
>
> By simply doing it without a temporary variable!
>
> lsd() { ls -d ${^~*:-*}(/) }
>
> If you throw in the (N) like Christian did, "lsd notadirectory" will give
> you "./" which may or may not be what you want.
Meh, I tried to do something like ${~${^...}}} and failed. ;)
--
Christian Neukirchen <chneukirchen@gmail.com> http://chneukirchen.org
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2013-03-03 19:09 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <20130303092908.0562f2d1__42920.4312772073$1362301372$gmane$org@arcor.com>
2013-03-03 14:40 ` globbing problem Christian Neukirchen
2013-03-03 18:42 ` Bart Schaefer
2013-03-03 19:08 ` Christian Neukirchen
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).