* add an mv protection ?
@ 2006-05-03 9:40 Marc Chantreux
2006-05-03 9:57 ` Frank Terbeck
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Marc Chantreux @ 2006-05-03 9:40 UTC (permalink / raw)
To: zsh-users
hi all,
imagine this case :
% echo *
a.pl b.pl
% mkdir old
% mv *pl
Here, i forget the target ( old ). The result is :
mv a.pl b.pl
i've lost the b.pl content!
is there a way to hook this case and ask a confirmation ?
thanks and regards
mc
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: add an mv protection ?
2006-05-03 9:40 add an mv protection ? Marc Chantreux
@ 2006-05-03 9:57 ` Frank Terbeck
2006-05-03 9:58 ` Peter Stephenson
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Frank Terbeck @ 2006-05-03 9:57 UTC (permalink / raw)
To: zsh-users
Marc Chantreux <marc.chantreux@ulpmm.u-strasbg.fr>:
> % echo *
> a.pl b.pl
> % mkdir old
> % mv *pl
>
> Here, i forget the target ( old ). The result is :
> mv a.pl b.pl
> i've lost the b.pl content!
> is there a way to hook this case and ask a confirmation ?
Hi Marc,
% man mv
[snip]
-i, --interactive
prompt before overwrite
[snap]
I don't know, if it's possible to check if an overwrite is intended or
not. So, if you really need it, I'd use "alias mv='mv -i'".
Regards, Frank
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: add an mv protection ?
2006-05-03 9:40 add an mv protection ? Marc Chantreux
2006-05-03 9:57 ` Frank Terbeck
@ 2006-05-03 9:58 ` Peter Stephenson
2006-05-03 10:06 ` Patrick Börjesson
2006-05-03 10:06 ` Marc Chantreux
3 siblings, 0 replies; 5+ messages in thread
From: Peter Stephenson @ 2006-05-03 9:58 UTC (permalink / raw)
To: zsh-users
Marc Chantreux wrote:
> % echo *
> a.pl b.pl
> % mkdir old
> % mv *pl
>
> Here, i forget the target ( old ). The result is :
>
> mv a.pl b.pl
>
> i've lost the b.pl content!
>
> is there a way to hook this case and ask a confirmation ?
Well, you can use a wrapper function:
mv() {
if (( $# == 1 )); then
print "mv: only one argument, did you mean that?"
return 1
fi
local -a args
args=(${~*})
print command mv $args
}
# careful to do this after the above or you create a function "noglob"
alias mv='noglob mv'
but this isn't quite good enough, since it doesn't handle options,
for example "mv -f *.pl" or "mv -i *.pl". An alternative approach would
be to check whether the final argument had wildcards in it, replacing
the "if" with:
if [[ $argv[-1] = *["*?[]()#"]* ]]; then
print "mv: last argument contains wildcards, aborted"
return 1
fi
but that's still not good enough if the destination might have quoted
wildcards in it. I suppose you could use:
local -a lastarg
lastarg=(${~argv[-1]})
if (( ${#lastarg} > 1 )); then
print "mv: last argument generates multiple files, aborted"
return 1
fi
although that might still be imperfect.
--
Peter Stephenson <pws@csr.com> Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK Tel: +44 (0)1223 692070
To access the latest news from CSR copy this link into a web browser: http://www.csr.com/email_sig.php
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: add an mv protection ?
2006-05-03 9:40 add an mv protection ? Marc Chantreux
2006-05-03 9:57 ` Frank Terbeck
2006-05-03 9:58 ` Peter Stephenson
@ 2006-05-03 10:06 ` Patrick Börjesson
2006-05-03 10:06 ` Marc Chantreux
3 siblings, 0 replies; 5+ messages in thread
From: Patrick Börjesson @ 2006-05-03 10:06 UTC (permalink / raw)
To: zsh-users
[-- Attachment #1: Type: text/plain, Size: 598 bytes --]
On 2006-05-03 11:40, Marc Chantreux uttered these thoughts:
> imagine this case :
>
> % echo *
> a.pl b.pl
> % mkdir old
> % mv *pl
>
> Here, i forget the target ( old ). The result is :
>
> mv a.pl b.pl
>
> i've lost the b.pl content!
>
> is there a way to hook this case and ask a confirmation ?
from "man mv":
-i Prompt for confirmation when destination exists. (In case both
-f and -i are given, the last one given takes effect.)
Regards,
Patrick Börjesson
--
() The ASCII Ribbon Campaign - against HTML Email
/\ and proprietary formats.
[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: add an mv protection ?
2006-05-03 9:40 add an mv protection ? Marc Chantreux
` (2 preceding siblings ...)
2006-05-03 10:06 ` Patrick Börjesson
@ 2006-05-03 10:06 ` Marc Chantreux
3 siblings, 0 replies; 5+ messages in thread
From: Marc Chantreux @ 2006-05-03 10:06 UTC (permalink / raw)
To: Marc Chantreux; +Cc: zsh-users
Thanks for your answers, I have more that i expected to write my own stuff.
thanks and regards !
mc
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2006-05-03 10:07 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-05-03 9:40 add an mv protection ? Marc Chantreux
2006-05-03 9:57 ` Frank Terbeck
2006-05-03 9:58 ` Peter Stephenson
2006-05-03 10:06 ` Patrick Börjesson
2006-05-03 10:06 ` Marc Chantreux
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).