Commit | Line | Data |
378cc40b |
1 | #!/usr/bin/perl |
2 | |
79072805 |
3 | # $RCSfile: vanish,v $$Revision: 4.1 $$Date: 92/08/07 17:20:54 $ |
378cc40b |
4 | |
5 | sub 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 | |
27 | while ($ARGV[0] =~ /^-/) { |
28 | $_ = shift; |
29 | /^-f/ && ($force = ' >/dev/null 2>&1'); |
30 | /^-i/ && ($interactive = 1); |
31 | if (/^-+$/) { |
32 | $startfiles = '- '; |
33 | last; |
34 | } |
35 | } |
36 | |
37 | chop($pwd = `pwd`); |
38 | |
39 | while ($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 | |
65 | do it() if $olddir; |