zsh-users
 help / color / mirror / code / Atom feed
* cd $(locate zoo.txt|head -1)(:h)
@ 2016-02-12 13:52 zzapper
  2016-02-12 18:32 ` zzapper
  0 siblings, 1 reply; 4+ messages in thread
From: zzapper @ 2016-02-12 13:52 UTC (permalink / raw)
  To: zsh-users

cd $(locate zoo.txt|head -1)(:h)

I'd like to make this a bit more versatile, i.e detect more than one result 
and may be offer a list?


-- 
zzapper
https://twitter.com/dailyzshtip

---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus



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

* Re: cd $(locate zoo.txt|head -1)(:h)
  2016-02-12 13:52 cd $(locate zoo.txt|head -1)(:h) zzapper
@ 2016-02-12 18:32 ` zzapper
  2016-02-12 20:01   ` Bart Schaefer
  0 siblings, 1 reply; 4+ messages in thread
From: zzapper @ 2016-02-12 18:32 UTC (permalink / raw)
  To: zsh-users

zzapper <david@rayninfo.co.uk> wrote in
news:XnsA5AC8D35FCD60davidrayninfocouk@80.91.229.13: 

> cd $(locate zoo.txt|head -1)(:h)
> 
> I'd like to make this a bit more versatile, i.e detect more than one
> result and may be offer a list?

 cd $(locate -r -l1 "/zoo.txt$")(:h)



-- 
zzapper
https://twitter.com/dailyzshtip

---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus



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

* Re: cd $(locate zoo.txt|head -1)(:h)
  2016-02-12 18:32 ` zzapper
@ 2016-02-12 20:01   ` Bart Schaefer
  2016-02-12 20:45     ` zzapper
  0 siblings, 1 reply; 4+ messages in thread
From: Bart Schaefer @ 2016-02-12 20:01 UTC (permalink / raw)
  To: zsh-users

On Feb 12,  6:32pm, zzapper wrote:
} Subject: Re: cd $(locate zoo.txt|head -1)(:h)
}
} zzapper <david@rayninfo.co.uk> wrote in
} news:XnsA5AC8D35FCD60davidrayninfocouk@80.91.229.13: 
} 
} > cd $(locate zoo.txt|head -1)(:h)
} > 
} > I'd like to make this a bit more versatile, i.e detect more than one
} > result and may be offer a list?
} 
}  cd $(locate -r -l1 "/zoo.txt$")(:h)

Are you answering yourself or changing the question?

(By the way, that doesn't work for me; on my system the -r option has
to be immediately followed by the regular expression, so this searches
for files whose names contain "-l1".)

Obviously if you just execute that command as typed and the locate
finds more than one file, "cd" is going to choke on it.  So are you
asking for a "cd" function that does something clever when handed a
bunch of contradictory arguments?

Conversely if you press TAB the default thing is going to expand all
the names on the command line, which probably also isn't what you
are looking for.  So maybe you're looking for a completer that runs
"locate" to get the list of matches?

_locate () {
  local -a expl files
  [[ -o magicequalsubst ]] && compset -P '*='
  files=($(_call_program locate locate -l1 -r "/$words[CURRENT]\$")) 2>/dev/null
  if (( $#files ))
  then
    local -au dirs=(${(D)${(b)files:h}}) 
    compstate[pattern_match]='*' 
    _wanted directories expl "directories containing $words[CURRENT]" \
	compadd -QU -f -a dirs
  else
    return 1
  fi
}

That could obviously use some work, e.g., you might want more regex
decoration around $words[CURRENT], which ought to be controlled by a
zstyle, etc.  However adding this completer should make

 % cd zoo.txt<TAB>

display a list of the directories that contain a zoo.txt file.


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

* Re: cd $(locate zoo.txt|head -1)(:h)
  2016-02-12 20:01   ` Bart Schaefer
@ 2016-02-12 20:45     ` zzapper
  0 siblings, 0 replies; 4+ messages in thread
From: zzapper @ 2016-02-12 20:45 UTC (permalink / raw)
  To: zsh-users

Bart Schaefer <schaefer@brasslantern.com> wrote in
news:160212120144.ZM15028@torch.brasslantern.com: 


)
> 
> Are you answering yourself or changing the question?
A bit of both!
> 
> (By the way, that doesn't work for me; on my system the -r option has
> to be immediately followed by the regular expression, so this searches
> for files whose names contain "-l1".)
> 
.
> 
Yes it was naughty/wrong to add the -l1 in between the -r and the 
expression (hadn't noticed).
Indeed suddenly what I want to do (see below) works

cd ${$(locate -r "/zoo.txt$")[1]:h}

or the simpler

cd ${$(locate zoo.txt)[1]:h}

echo $(locate -c -r "/zoo.txt$") matches

I've been round the mulberry bush to get this far thanks!

-- 
zzapper
https://twitter.com/dailyzshtip

---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus



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

end of thread, other threads:[~2016-02-12 20:45 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-02-12 13:52 cd $(locate zoo.txt|head -1)(:h) zzapper
2016-02-12 18:32 ` zzapper
2016-02-12 20:01   ` Bart Schaefer
2016-02-12 20:45     ` zzapper

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