|
@@ -5,6 +5,7 @@ use strict;
|
5
|
5
|
use warnings;
|
6
|
6
|
|
7
|
7
|
sub usage; sub mkexec; sub guesstype; sub getcmd; sub launch_editor;
|
|
8
|
+sub nextarg { $ARGV[0] }
|
8
|
9
|
|
9
|
10
|
my $DEFAULT_TYPE = 'pl';
|
10
|
11
|
my $DEFAULT_MODE = 0755;
|
|
@@ -15,9 +16,10 @@ my $DEFAULT_FORCE = 0;
|
15
|
16
|
## INIT ## -------------------------------------------------------------------
|
16
|
17
|
## '''' ## ' ' ' ' ' ' ' ' ' ' '
|
17
|
18
|
|
18
|
|
-my $force = $ARGV[0] == '-f' ? shift : $DEFAULT_FORCE;
|
19
|
|
-my $name = shift or usage;
|
20
|
|
-my $type = ($ARGV[0] ? shift : guesstype $name);
|
|
19
|
+defined nextarg() or usage;
|
|
20
|
+my $force = (nextarg() eq '-f' ? shift : $DEFAULT_FORCE);
|
|
21
|
+my $name = (defined nextarg() ? shift : usage);
|
|
22
|
+my $type = (defined nextarg() ? shift : guesstype $name);
|
21
|
23
|
|
22
|
24
|
my $bangs = {
|
23
|
25
|
pl => `which perl`,
|
|
@@ -46,7 +48,8 @@ $cmds->{editor}->{run} = "editor '%s'";
|
46
|
48
|
## ''' ## # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
47
|
49
|
|
48
|
50
|
if (exists $bangs->{$type}) {
|
49
|
|
- -e $name and not $force || mkexec $name, mkbody($type);
|
|
51
|
+ -e $name and not $force
|
|
52
|
+ or mkexec $name, mkbody($type);
|
50
|
53
|
chmod $DEFAULT_MODE, $name;
|
51
|
54
|
launch_editor $name;
|
52
|
55
|
} else {
|
|
@@ -78,10 +81,10 @@ sub mkbody {
|
78
|
81
|
|
79
|
82
|
sub mkexec {
|
80
|
83
|
my ($name, $body) = @_;
|
81
|
|
- open EXE, ">", $name || die "cannot open $name for writing: $!\n";
|
82
|
|
- -W EXE || die "file $name is not writable\n";
|
|
84
|
+ open EXE, ">", $name or die "cannot open $name for writing: $!\n";
|
|
85
|
+ -W EXE or die "file $name is not writable\n";
|
83
|
86
|
print EXE $body;
|
84
|
|
- close EXE || die "cannot close $name: $!\n";
|
|
87
|
+ close EXE or die "cannot close $name: $!\n";
|
85
|
88
|
}
|
86
|
89
|
|
87
|
90
|
sub get_cmd {
|