diff options
author | John Ankarström <john@ankarstrom.se> | 2021-07-12 13:24:49 +0200 |
---|---|---|
committer | John Ankarström <john@ankarstrom.se> | 2021-07-12 13:27:07 +0200 |
commit | 03d827e2fbc409ef97829f25b8eeca5204f81a3c (patch) | |
tree | 6099f0feb9adf3425fba87549b164043e18bd0c7 /re! | |
parent | 45cddd072119c5abd7ec076cf28d51ee01f125b7 (diff) | |
download | xutil-03d827e2fbc409ef97829f25b8eeca5204f81a3c.tar.gz |
Re-organize files
Diffstat (limited to 're!')
-rwxr-xr-x | re! | 48 |
1 files changed, 0 insertions, 48 deletions
@@ -1,48 +0,0 @@ -#!/usr/bin/env perl - -# re! -- rewrite shebangs - -use strict; - -my $test = 0; -sub usage { die "usage: $0 [-n] file ...\n" } - -if (@ARGV and $ARGV[0] eq '-n') { - $test = 1; - shift @ARGV; -} -usage if not @ARGV; - -for my $file (@ARGV) { - open my $o, '<', $file or die "could not open $file: $!\n"; - - # parse shebang - my $shebang = <$o>; - $shebang =~ /^#!/ or die "no shebang: $file\n"; - $shebang =~ /^#!\s*(\S+)\s*(.*)/; - my ($old, $args) = ($1, $2); - - # validate path - next if -x $old; - - # get new path - (my $basename = $old) =~ s,.*/,,; - chomp(my $new = `which $basename`); - $new or die "could not find $basename\n"; - next if $old eq $new; - - # print results if test - if ($test) { - print "$file: $old -> $new\n"; - next; - } - - # write new shebang - open my $n, '>', "$file.tmp" or die "could not open $file.tmp: $!\n"; - print $n "#!$new $args\n"; - print $n $_ while <$o>; - - close for ($o, $n); - system('mv', "$file.tmp", $file) == 0 - or die "could not overwrite $file\n"; -} |