zsh-users
 help / color / mirror / code / Atom feed
* echo-ing case insensitively
@ 2003-02-12 22:59 Eric Smith
  2003-02-13  4:59 ` Bart Schaefer
  0 siblings, 1 reply; 4+ messages in thread
From: Eric Smith @ 2003-02-12 22:59 UTC (permalink / raw)
  To: Zsh Users

I do not use directories much - I prefer underscores in filenames.
The following serves me well (with most of my data in a single dir):
se () {
        if [ $2 ]
        then
                echo $1/*$2* | sed -e 's/ /\
/g'
        else
                echo *$1* | sed -e 's/ /\
/g'
        fi
}

What I want to do though is give this function an argument like
say - `draft' and I want to see:
today_draft
Draft.mail
some_other_DRAFT

(Breaking mailing-list convention with a followup question)

I want to type `draft' at the prompt and press <tab> and then
get all the options above to show as possible expansions.

How?

Thanks.

-- 
Eric Smith


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: echo-ing case insensitively
  2003-02-12 22:59 echo-ing case insensitively Eric Smith
@ 2003-02-13  4:59 ` Bart Schaefer
  2003-02-13 14:57   ` Eric Smith
  0 siblings, 1 reply; 4+ messages in thread
From: Bart Schaefer @ 2003-02-13  4:59 UTC (permalink / raw)
  To: Zsh Users

On Feb 12, 11:59pm, Eric Smith wrote:
>
> I do not use directories much - I prefer underscores in filenames.

I suspect I know what you mean, but it's really not clear what the
second clause has to do with the first.

> What I want to do though is give this function an argument like
> say - `draft' and I want to see:
> today_draft
> Draft.mail
> some_other_DRAFT

	se () {
	    setopt localoptions extendedglob noshwordsplit
	    if [[ -n $2 ]]
	    then print -l (#i)$1/*$2*
	    else print -l (#i)*$1*
	    fi
	} 

> I want to type `draft' at the prompt and press <tab> and then
> get all the options above to show as possible expansions.
> 
> How?

Which of compctl or compsys are you using?


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: echo-ing case insensitively
  2003-02-13  4:59 ` Bart Schaefer
@ 2003-02-13 14:57   ` Eric Smith
  2003-02-23  1:47     ` Bart Schaefer
  0 siblings, 1 reply; 4+ messages in thread
From: Eric Smith @ 2003-02-13 14:57 UTC (permalink / raw)
  To: Zsh Users

Bart Schaefer said:
> On Feb 12, 11:59pm, Eric Smith wrote:
> >
> > I do not use directories much - I prefer underscores in filenames.
> 
> I suspect I know what you mean, but it's really not clear what the
> second clause has to do with the first.

It was a cryptic reference to my ideology which you are provoking me 
now to impose on others....
<rant>
Well I find directories that enforce a one-dimensional hierarchy
very restrictive and maps poorly to the real world.  Accordingly
I use underscores in filenames to create "namespaces" like others would
create dirs.  But the freedom of not using directories allows files
to live under many different classes or categories simultaneously.

Then when you use the enhanced print function that you kindly offered,
it instantaneously finds files by any key word.  Faster than ls, find or
locate and real-time with the file-system.

Nest challenge would be to give se() multiple words and it will match
any file with those strings in it - you can trivially implement this
with:

se draft|grep -i recent|grep -i whatever

But that is not zshellese and is of course very boring (and inefficient).
</rant>

> Which of compctl or compsys are you using?

The latter (of course).

Thanks for your help.

-- 
Eric Smith


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: echo-ing case insensitively
  2003-02-13 14:57   ` Eric Smith
@ 2003-02-23  1:47     ` Bart Schaefer
  0 siblings, 0 replies; 4+ messages in thread
From: Bart Schaefer @ 2003-02-23  1:47 UTC (permalink / raw)
  To: Zsh Users

[I've been on vacation for a week, hence the long delay in responding ...
also, I've just noticed that my machine rebooted with the clock off by an
hour, so this message may appear to have been sent before others I sent
earlier.  Sigh.]

On Feb 13,  3:57pm, Eric Smith wrote:
>
> <rant>
> Well I find directories that enforce a one-dimensional hierarchy
> very restrictive and maps poorly to the real world.  Accordingly
> I use underscores in filenames to create "namespaces" like others would
> create dirs.  But the freedom of not using directories allows files
> to live under many different classes or categories simultaneously.

I was under the impression that this is what "ln" was for.

How do you go about getting a list of existing classes or categories?
Not of the files within one of them, but of the classes themselves?

> Nest challenge would be to give se() multiple words and it will match
> any file with those strings in it

You've got a basic design problem there, in that "se" as you previously
specified it can already be given multiple words:  it treats two words
as a directory name followed by a file substring.

I take it you want the files that have ALL of the specified words in the
name, in any order, rather than files that have ANY of the words?

ANY of the words is something like:

	se () {
	    setopt localoptions extendedglob noshwordsplit
	    print -l **/(#i)*(${(j:|:)~${(q)*}})*
	} 

ALL of the words, in any order, pretty much requires a loop:

	se () {
	    setopt localoptions extendedglob noshwordsplit
	    local -a possible; possible=( **/(#i)*$1* )
	    shift
	    while (( $# ))
	    do
		possible=( ${(M)possible:#(#i)*$1*} )
		shift
	    done
	    (( $#possible )) && print -l $possible
	} 

Your original question:

> I want to type `draft' at the prompt and press <tab> and then
> get all the options above to show as possible expansions.

I'm going to presume you mean you want this at any place where a file
name would normally be completed.

To accomplish this, you have to create a completer to replace the
supplied `_files' completer.  Something like this:

    _files () {
        local -a possible
        possible=( $(se $words[CURRENT]) )
        if (( $#possible ))
	then
	    compadd -f -U -a -- possible
	else
	    # Copy entire content of supplied _files here
	fi
    }

It's rather too bad that _files doesn't have a _dispatch hook the way
_value and _redirect do ... but even that would apply only in 4.1.x,
not 4.0.x.  

There may be some way to accomplish what you want using a matcher-list
entry, but I haven't been able to work out what it would be.

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2003-02-23  1:48 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-02-12 22:59 echo-ing case insensitively Eric Smith
2003-02-13  4:59 ` Bart Schaefer
2003-02-13 14:57   ` Eric Smith
2003-02-23  1:47     ` Bart Schaefer

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).