perl 3.0: (no announcement message available)
[p5sagit/p5-mst-13.2.git] / eg / van / vanish
CommitLineData
378cc40b 1#!/usr/bin/perl
2
a687059c 3# $Header: vanish,v 3.0 89/10/18 15:16:46 lwall Locked $
378cc40b 4
5sub it {
6 if ($olddir ne '.') {
7 chop($pwd = `pwd`) if $pwd eq '';
8 (chdir $olddir) || die "Directory $olddir is not accesible";
9 }
10 if (!-d .deleted) {
11 print `mkdir .deleted; chmod 775 .deleted`;
12 die "You can't remove files from $olddir" if $?;
13 }
14 $filelist =~ s/ $//;
15 $filelist =~ s/#/\\#/g;
16 if ($filelist !~ /^[ \t]*$/) {
17 open(lastcmd,'>.deleted/.lastcmd');
18 print lastcmd $filelist,"\n";
19 close(lastcmd);
20 print `/bin/mv $startfiles$filelist .deleted$force`;
21 }
22 if ($olddir ne '.') {
a687059c 23 (chdir $pwd) || die "Can't get back to original directory $pwd: $!\n";
378cc40b 24 }
25}
26
27while ($ARGV[0] =~ /^-/) {
28 $_ = shift;
29 /^-f/ && ($force = ' >/dev/null 2>&1');
30 /^-i/ && ($interactive = 1);
31 if (/^-+$/) {
32 $startfiles = '- ';
33 last;
34 }
35}
36
37chop($pwd = `pwd`);
38
39while ($file = shift) {
40 if ($file =~ s|^(.*)/||) {
41 $dir = $1;
42 }
43 else {
44 $dir = '.';
45 }
46
47 if ($interactive) {
48 print "vanish: remove $dir/$file? ";
49 next unless <stdin> =~ /^y/i;
50 }
51
52 if ($file eq '.deleted') {
53 print stderr "To delete .deleted (the trashcan) use the 'empty' command.\n";
54 next;
55 }
56
57 if ($dir ne $olddir) {
58 do it() if $olddir;
59 $olddir = $dir;
60 }
61
62 $filelist .= $file; $filelist .= ' ';
63}
64
65do it() if $olddir;