zsh-users
 help / color / mirror / code / Atom feed
* list duplicate filenames which only vary by case
@ 2014-09-26  9:11 zzapper
  2014-09-26  9:26 ` Peter Stephenson
  2014-09-26  9:27 ` Mikael Magnusson
  0 siblings, 2 replies; 10+ messages in thread
From: zzapper @ 2014-09-26  9:11 UTC (permalink / raw)
  To: zsh-users

Hi

list files with duplicates in same directory
e.g.
house.jpg House.jpg hOUSE.jpg

I guess it needs a e[$REPLY...] clause

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

---
This email is free from viruses and malware because avast! Antivirus protection is active.
http://www.avast.com



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

* Re: list duplicate filenames which only vary by case
  2014-09-26  9:11 list duplicate filenames which only vary by case zzapper
@ 2014-09-26  9:26 ` Peter Stephenson
  2014-09-26  9:27 ` Mikael Magnusson
  1 sibling, 0 replies; 10+ messages in thread
From: Peter Stephenson @ 2014-09-26  9:26 UTC (permalink / raw)
  To: zsh-users

On Fri, 26 Sep 2014 09:11:07 +0000 (UTC)
zzapper <david@rayninfo.co.uk> wrote:
> list files with duplicates in same directory
> e.g.
> house.jpg House.jpg hOUSE.jpg

Assign the contents of the directory to an array and lower-case and sort
it.

local -a array
array=(*)
array=(${(Lo)array})

Now all you need to do is search for consecutive duplicate elements in
the array (exercise for the reader).  If you find one, say element i,

array=((#i)${array[i]})

should collect the ones with the names that match it.

pws


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

* Re: list duplicate filenames which only vary by case
  2014-09-26  9:11 list duplicate filenames which only vary by case zzapper
  2014-09-26  9:26 ` Peter Stephenson
@ 2014-09-26  9:27 ` Mikael Magnusson
  2014-09-26  9:29   ` Mikael Magnusson
  1 sibling, 1 reply; 10+ messages in thread
From: Mikael Magnusson @ 2014-09-26  9:27 UTC (permalink / raw)
  To: zzapper; +Cc: Zsh Users

On 26 September 2014 11:11, zzapper <david@rayninfo.co.uk> wrote:
> Hi
>
> list files with duplicates in same directory
> e.g.
> house.jpg House.jpg hOUSE.jpg
>
> I guess it needs a e[$REPLY...] clause

() { setopt localoptions nocaseglob; print -rl - *(e,'[[ -n
$REPLY(#q[2]) ]]',) }

I couldn't figure out any syntactically valid way to insert (#i) in
the glob. If that were possible you wouldn't need the function and
local option.

-- 
Mikael Magnusson


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

* Re: list duplicate filenames which only vary by case
  2014-09-26  9:27 ` Mikael Magnusson
@ 2014-09-26  9:29   ` Mikael Magnusson
  2014-09-26  9:35     ` Mikael Magnusson
  2014-09-26  9:40     ` Peter Stephenson
  0 siblings, 2 replies; 10+ messages in thread
From: Mikael Magnusson @ 2014-09-26  9:29 UTC (permalink / raw)
  To: zzapper; +Cc: Zsh Users

On 26 September 2014 11:27, Mikael Magnusson <mikachu@gmail.com> wrote:
> On 26 September 2014 11:11, zzapper <david@rayninfo.co.uk> wrote:
>> Hi
>>
>> list files with duplicates in same directory
>> e.g.
>> house.jpg House.jpg hOUSE.jpg
>>
>> I guess it needs a e[$REPLY...] clause
>
> () { setopt localoptions nocaseglob; print -rl - *(e,'[[ -n
> $REPLY(#q[2]) ]]',) }
>
> I couldn't figure out any syntactically valid way to insert (#i) in
> the glob. If that were possible you wouldn't need the function and
> local option.

Of course this also works.. duh :)
print -rl - *(e,'setopt nocaseglob; [[ -n $REPLY(#q[2]) ]]',)

-- 
Mikael Magnusson


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

* Re: list duplicate filenames which only vary by case
  2014-09-26  9:29   ` Mikael Magnusson
@ 2014-09-26  9:35     ` Mikael Magnusson
  2014-09-26  9:40     ` Peter Stephenson
  1 sibling, 0 replies; 10+ messages in thread
From: Mikael Magnusson @ 2014-09-26  9:35 UTC (permalink / raw)
  To: zzapper; +Cc: Zsh Users

On 26 September 2014 11:29, Mikael Magnusson <mikachu@gmail.com> wrote:
> On 26 September 2014 11:27, Mikael Magnusson <mikachu@gmail.com> wrote:
>> On 26 September 2014 11:11, zzapper <david@rayninfo.co.uk> wrote:
>>> Hi
>>>
>>> list files with duplicates in same directory
>>> e.g.
>>> house.jpg House.jpg hOUSE.jpg
>>>
>>> I guess it needs a e[$REPLY...] clause
>>
>> () { setopt localoptions nocaseglob; print -rl - *(e,'[[ -n
>> $REPLY(#q[2]) ]]',) }
>>
>> I couldn't figure out any syntactically valid way to insert (#i) in
>> the glob. If that were possible you wouldn't need the function and
>> local option.
>
> Of course this also works.. duh :)
> print -rl - *(e,'setopt nocaseglob; [[ -n $REPLY(#q[2]) ]]',)

Sorry for triple posting, the last version only "works" for external
commands, eg, when we fork before performing the glob, or it will
change the caseglob setting in the parent shell (for example when
using the print builtin), so I go back to recommending the first
version.

-- 
Mikael Magnusson


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

* Re: list duplicate filenames which only vary by case
  2014-09-26  9:29   ` Mikael Magnusson
  2014-09-26  9:35     ` Mikael Magnusson
@ 2014-09-26  9:40     ` Peter Stephenson
  2014-09-26 12:06       ` zzapper
  1 sibling, 1 reply; 10+ messages in thread
From: Peter Stephenson @ 2014-09-26  9:40 UTC (permalink / raw)
  To: Mikael Magnusson, Zsh Users

On Fri, 26 Sep 2014 11:29:34 +0200
Mikael Magnusson <mikachu@gmail.com> wrote:
> Of course this also works.. duh :)
> print -rl - *(e,'setopt nocaseglob; [[ -n $REPLY(#q[2]) ]]',)

That's neat, but the option setting leaks out...

print -rl - *(e,'() { setopt localoptions nocaseglob; [[ -n $REPLY(#q[2]) ]] }',)

or (tcm = test case match)

tcm() {
  setopt localoptions nocaseglob
  [[ -n $REPLY(#q[2]) ]]
}
print -rl - *(+tcm)

pws


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

* Re: list duplicate filenames which only vary by case
  2014-09-26  9:40     ` Peter Stephenson
@ 2014-09-26 12:06       ` zzapper
  2014-09-26 12:30         ` Mikael Magnusson
  0 siblings, 1 reply; 10+ messages in thread
From: zzapper @ 2014-09-26 12:06 UTC (permalink / raw)
  To: zsh-users

Peter Stephenson <p.stephenson@samsung.com> wrote in
news:20140926104037.2ec132df@pwslap01u.europe.root.pri: 

 touch {house,House,HOUSE,dog,cat}.jpg


On zsh 4.2.6 (x86_64-redhat-linux-gnu)

your solutions do not work!?

They list all of the above files instead of just house.*

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

---
This email is free from viruses and malware because avast! Antivirus protection is active.
http://www.avast.com



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

* Re: list duplicate filenames which only vary by case
  2014-09-26 12:06       ` zzapper
@ 2014-09-26 12:30         ` Mikael Magnusson
  2014-09-26 13:00           ` zzapper
  2014-09-27 11:01           ` zzapper
  0 siblings, 2 replies; 10+ messages in thread
From: Mikael Magnusson @ 2014-09-26 12:30 UTC (permalink / raw)
  To: zzapper; +Cc: Zsh Users

On 26 September 2014 14:06, zzapper <david@rayninfo.co.uk> wrote:
>
> your solutions do not work!?
>
> They list all of the above files instead of just house.*

If you use a zsh from ten years ago, you don't have anonymous
functions, you also cannot use globbing inside [[ ]].
tcm() {
  setopt localoptions nocaseglob
  local a
  a=( $REPLY([2]N) )
  [[ -n $a ]]
}
*(+tcm)

this should work in ancient zsh versions too, probably. If not, should
only need minor modifications.

-- 
Mikael Magnusson


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

* Re: list duplicate filenames which only vary by case
  2014-09-26 12:30         ` Mikael Magnusson
@ 2014-09-26 13:00           ` zzapper
  2014-09-27 11:01           ` zzapper
  1 sibling, 0 replies; 10+ messages in thread
From: zzapper @ 2014-09-26 13:00 UTC (permalink / raw)
  To: zsh-users



> tcm() {
>   setopt localoptions nocaseglob
>   local a
>   a=( $REPLY([2]N) )
>   [[ -n $a ]]
> }
> *(+tcm)
> 
> this should work in ancient zsh versions too, probably. If not, should
> only need minor modifications.
> 
Yep upgraded to  5.0.2 and worked just Dandy

http://michaelheap.com/installing-zsh-5-0-on-centos-5-7/


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

---
This email is free from viruses and malware because avast! Antivirus protection is active.
http://www.avast.com



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

* Re: list duplicate filenames which only vary by case
  2014-09-26 12:30         ` Mikael Magnusson
  2014-09-26 13:00           ` zzapper
@ 2014-09-27 11:01           ` zzapper
  1 sibling, 0 replies; 10+ messages in thread
From: zzapper @ 2014-09-27 11:01 UTC (permalink / raw)
  To: zsh-users

Mikael Magnusson <mikachu@gmail.com> wrote in news:CAHYJk3SVAvgCjeUy=
6MGD7sPBdBH56R7zExN5qo0km0p2eRW=g@mail.gmail.com:

> On 26 September 2014 14:06, zzapper <david@rayninfo.co.uk> wrote:
>>
>> your solutions do not work!?
>>
>> They list all of the above files instead of just house.*
> 
> If you use a zsh from ten years ago, you don't have anonymous
> functions, you also cannot use globbing inside [[ ]].
> tcm() {
>   setopt localoptions nocaseglob
>   local a
>   a=( $REPLY([2]N) )
>   [[ -n $a ]]
> }
> *(+tcm)
> 
> this should work in ancient zsh versions too, probably. If not, should
> only need minor modifications.
> 

MM
Your variation of the PWS's tcm  is the only thing that works for me on 
any version of zsh. thanks

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

---
This email is free from viruses and malware because avast! Antivirus protection is active.
http://www.avast.com



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

end of thread, other threads:[~2014-09-27 11:02 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-09-26  9:11 list duplicate filenames which only vary by case zzapper
2014-09-26  9:26 ` Peter Stephenson
2014-09-26  9:27 ` Mikael Magnusson
2014-09-26  9:29   ` Mikael Magnusson
2014-09-26  9:35     ` Mikael Magnusson
2014-09-26  9:40     ` Peter Stephenson
2014-09-26 12:06       ` zzapper
2014-09-26 12:30         ` Mikael Magnusson
2014-09-26 13:00           ` zzapper
2014-09-27 11:01           ` 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).