* file names in arrays
@ 2005-06-30 15:51 zzapper
2005-06-30 17:12 ` Philippe Troin
2005-07-02 20:51 ` Bart Schaefer
0 siblings, 2 replies; 7+ messages in thread
From: zzapper @ 2005-06-30 15:51 UTC (permalink / raw)
To: zsh-users
Hi,
At the risk of being abused, RTFM etc etc
Has anyone got a script where a number of file names resulting from say a find/grep are loaded into
an array.
And then this array is looped thru with a promt deciding what might happen to these files, mv,rm,cp
edit etc
--
zzapper
vim -c ":%s%s*%Cyrnfr)fcbafbe[Oenz(Zbbyranne%|:%s)[[()])-)Ig|norm Vg?"
http://www.rayninfo.co.uk/tips/ vim, zsh & success tips
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: file names in arrays
2005-06-30 15:51 file names in arrays zzapper
@ 2005-06-30 17:12 ` Philippe Troin
2005-07-02 20:51 ` Bart Schaefer
1 sibling, 0 replies; 7+ messages in thread
From: Philippe Troin @ 2005-06-30 17:12 UTC (permalink / raw)
To: zzapper; +Cc: zsh-users
zzapper <david@tvis.co.uk> writes:
> Hi,
> At the risk of being abused, RTFM etc etc
>
> Has anyone got a script where a number of file names resulting from
> say a find/grep are loaded into an array.
>
> And then this array is looped thru with a promt deciding what might
> happen to these files, mv,rm,cp edit etc
a=(${(ps:\0:)"$(find /path -print0)"})
for i in $a
do
while :
do
print -n "Frob $i? (y/n) "
read r
case $r in
([yY]) frob $i; break;;
([nN]) break;;
(*) print "invalid input";;
esac
done
done
You get the idea...
Phil.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: file names in arrays
2005-06-30 15:51 file names in arrays zzapper
2005-06-30 17:12 ` Philippe Troin
@ 2005-07-02 20:51 ` Bart Schaefer
2005-07-04 12:06 ` zzapper
1 sibling, 1 reply; 7+ messages in thread
From: Bart Schaefer @ 2005-07-02 20:51 UTC (permalink / raw)
To: zsh-users
On Jun 30, 4:51pm, zzapper wrote:
}
} At the risk of being abused, RTFM etc etc
}
} Has anyone got a script where a number of file names resulting from
} say a find/grep are loaded into an array.
Go to http://www.zsh.org/cgi-bin/mla/wilma/users and search for "keeper".
} And then this array is looped thru with a promt deciding what might
} happen to these files, mv,rm,cp edit etc
Isn't the answer to this the same as -- or awfully similar to, at any
rate -- the answer to your "Creating a Case statement dynamically"
thread from a couple of days earlier?
local file command target
find "$@" | keep
for file in $kept
do
PS3="Action on $file: "
target=''
select command in mv cp rm gvim
do
case $REPLY in
((Q|q)*) break 2;;
(<1->)
case $command in
(cp|mv) vared -e -p "$command $file " target &&
[[ -n $target ]] && $command $file $target
(?*) $command $file;;
(*) break;;
esac;;
(*) break;;
esac
done
done
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: file names in arrays
2005-07-02 20:51 ` Bart Schaefer
@ 2005-07-04 12:06 ` zzapper
2005-07-04 14:09 ` Bart Schaefer
0 siblings, 1 reply; 7+ messages in thread
From: zzapper @ 2005-07-04 12:06 UTC (permalink / raw)
To: zsh-users
On Sat, 02 Jul 2005 20:51:37 +0000, wrote:
>On Jun 30, 4:51pm, zzapper wrote:
>}
>} At the risk of being abused, RTFM etc etc
>}
>} Has anyone got a script where a number of file names resulting from
>} say a find/grep are loaded into an array.
>
>Go to http://www.zsh.org/cgi-bin/mla/wilma/users and search for "keeper".
>
>} And then this array is looped thru with a promt deciding what might
>} happen to these files, mv,rm,cp edit etc
>
>Isn't the answer to this the same as -- or awfully similar to, at any
>rate -- the answer to your "Creating a Case statement dynamically"
>thread from a couple of days earlier?
>
>
> local file command target
> find "$@" | keep
> for file in $kept
> do
> PS3="Action on $file: "
> target=''
> select command in mv cp rm gvim
> do
> case $REPLY in
> ((Q|q)*) break 2;;
> (<1->)
> case $command in
> (cp|mv) vared -e -p "$command $file " target &&
> [[ -n $target ]] && $command $file $target
> (?*) $command $file;;
> (*) break;;
> esac;;
> (*) break;;
> esac
> done
> done
Bart,
Yes it's similar to my previous thread, but hopefully more general. I'd found a useful solution, but
didn't use arrays, so I ended up repeating operations.
Your script above blows up for me on
pick3:17: parse error near `$command' (the vared line)
zsh 4.2.4 (i686-pc-cygwin)
--
zzapper
vim -c ":%s%s*%Cyrnfr)fcbafbe[Oenz(Zbbyranne%|:%s)[[()])-)Ig|norm Vg?"
http://www.rayninfo.co.uk/tips/ vim, zsh & success tips
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: file names in arrays
2005-07-04 12:06 ` zzapper
@ 2005-07-04 14:09 ` Bart Schaefer
2005-07-04 15:31 ` zzapper
0 siblings, 1 reply; 7+ messages in thread
From: Bart Schaefer @ 2005-07-04 14:09 UTC (permalink / raw)
To: zzapper; +Cc: zsh-users
On Jul 4, 1:06pm, zzapper wrote:
} Subject: Re: file names in arrays
}
} > (cp|mv) vared -e -p "$command $file " target &&
} > [[ -n $target ]] && $command $file $target
;;
} > (?*) $command $file;;
}
} pick3:17: parse error near `$command' (the vared line)
Cut'n'paste lossage. Sorry.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: file names in arrays
2005-07-04 14:09 ` Bart Schaefer
@ 2005-07-04 15:31 ` zzapper
2005-07-04 17:33 ` zzapper
0 siblings, 1 reply; 7+ messages in thread
From: zzapper @ 2005-07-04 15:31 UTC (permalink / raw)
To: zsh-users
On Mon, 04 Jul 2005 14:09:58 +0000, wrote:
>On Jul 4, 1:06pm, zzapper wrote:
>} Subject: Re: file names in arrays
>}
>} > (cp|mv) vared -e -p "$command $file " target &&
>} > [[ -n $target ]] && $command $file $target
> ;;
>} > (?*) $command $file;;
>}
>} pick3:17: parse error near `$command' (the vared line)
>
>Cut'n'paste lossage. Sorry.
Bart,
And I was looking for some complex bug, and failed to spot the obvious
--
zzapper
vim -c ":%s%s*%Cyrnfr)fcbafbe[Oenz(Zbbyranne%|:%s)[[()])-)Ig|norm Vg?"
http://www.rayninfo.co.uk/tips/ vim, zsh & success tips
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: file names in arrays
2005-07-04 15:31 ` zzapper
@ 2005-07-04 17:33 ` zzapper
0 siblings, 0 replies; 7+ messages in thread
From: zzapper @ 2005-07-04 17:33 UTC (permalink / raw)
To: zsh-users
On Mon, 04 Jul 2005 16:31:03 +0100, wrote:
>On Mon, 04 Jul 2005 14:09:58 +0000, wrote:
>
>>
>>Cut'n'paste lossage. Sorry.
>Bart,
>And I was looking for some complex bug, and failed to spot the obvious
Bart,
I may combine your script with that of Phillipe as Select had two disadvantages in this case (it
uses numerics, whereas I'd prefer the menonmic v for vi c for cp m for mv etc, also because select
automatically repeats on an empty return, whereas I want it to goto next. Nevertheless your script
is a mini-tutorial in scripting
--
zzapper
vim -c ":%s%s*%Cyrnfr)fcbafbe[Oenz(Zbbyranne%|:%s)[[()])-)Ig|norm Vg?"
http://www.rayninfo.co.uk/tips/ vim, zsh & success tips
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2005-07-04 17:34 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-06-30 15:51 file names in arrays zzapper
2005-06-30 17:12 ` Philippe Troin
2005-07-02 20:51 ` Bart Schaefer
2005-07-04 12:06 ` zzapper
2005-07-04 14:09 ` Bart Schaefer
2005-07-04 15:31 ` zzapper
2005-07-04 17:33 ` 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).