| 1 | package Shell::Config::Generate; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 13 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 13 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 13 | ▶ | use 5.008001; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 13 | ▶ | use Shell::Guess; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 13 | ▶ | use Carp qw( croak ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 13 | ▶ | use Exporter (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | # ABSTRACT: Portably generate config for any shell | ||||||||||||||||||||||||||||||||||||||||||
| 11 | 13 | our $VERSION = '0.36'; # VERSION | |||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | sub new | ||||||||||||||||||||||||||||||||||||||||||
| 15 | 27 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | 27 | my($class) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 17 | 27 | bless { commands => [], echo_off => 0 }, $class; | |||||||||||||||||||||||||||||||||||||||||
| 18 | } | ||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | sub set | ||||||||||||||||||||||||||||||||||||||||||
| 22 | 9 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 23 | 9 | my($self, $name, $value) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||
| 25 | 9 | push @{ $self->{commands} }, ['set', $name, $value]; | |||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||
| 27 | 9 | $self; | |||||||||||||||||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | sub set_path | ||||||||||||||||||||||||||||||||||||||||||
| 32 | 4 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_path: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 33 | 4 | my($self, $name, @list) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | 4 | push @{ $self->{commands} }, [ 'set_path', $name, @list ]; | |||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||
| 37 | 4 | $self; | |||||||||||||||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||
| 41 | sub append_path | ||||||||||||||||||||||||||||||||||||||||||
| 42 | 8 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
append_path: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | 8 | my($self, $name, @list) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||
| 45 | 8 | ▶ | push @{ $self->{commands} }, [ 'append_path', $name, @list ] | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | if @list > 0; | ||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||
| 48 | 8 | $self; | |||||||||||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||
| 52 | sub prepend_path | ||||||||||||||||||||||||||||||||||||||||||
| 53 | 8 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
prepend_path: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 54 | 8 | my($self, $name, @list) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||
| 56 | 8 | ▶ | push @{ $self->{commands} }, [ 'prepend_path', $name, @list ] | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | if @list > 0; | ||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||
| 59 | 8 | $self; | |||||||||||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||
| 63 | sub comment | ||||||||||||||||||||||||||||||||||||||||||
| 64 | 4 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
comment: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 65 | 4 | my($self, @comments) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||
| 67 | 4 | push @{ $self->{commands} }, ['comment', $_] for @comments; | |||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||
| 69 | 4 | $self; | |||||||||||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||
| 73 | sub shebang | ||||||||||||||||||||||||||||||||||||||||||
| 74 | 4 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
shebang: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 75 | 4 | my($self, $location) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 76 | 4 | $self->{shebang} = $location; | |||||||||||||||||||||||||||||||||||||||||
| 77 | 4 | $self; | |||||||||||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||
| 81 | sub echo_off | ||||||||||||||||||||||||||||||||||||||||||
| 82 | 3 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
echo_off: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 83 | 3 | my($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 84 | 3 | $self->{echo_off} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 85 | 3 | $self; | |||||||||||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||
| 89 | sub echo_on | ||||||||||||||||||||||||||||||||||||||||||
| 90 | 1 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
echo_on: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 91 | 1 | my($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 92 | 1 | $self->{echo_off} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 93 | 1 | $self; | |||||||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||
| 96 | sub _value_escape_csh | ||||||||||||||||||||||||||||||||||||||||||
| 97 | 2 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_value_escape_csh: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 98 | 2 | my $value = shift() . ''; | |||||||||||||||||||||||||||||||||||||||||
| 99 | 2 | $value =~ s/([\n!])/\\$1/g; | |||||||||||||||||||||||||||||||||||||||||
| 100 | 2 | $value =~ s/(')/'"$1"'/g; | |||||||||||||||||||||||||||||||||||||||||
| 101 | 2 | $value; | |||||||||||||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||
| 104 | sub _value_escape_fish | ||||||||||||||||||||||||||||||||||||||||||
| 105 | 4 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_value_escape_fish: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 106 | 4 | my $value = shift() . ''; | |||||||||||||||||||||||||||||||||||||||||
| 107 | 4 | $value =~ s/([\n])/\\$1/g; | |||||||||||||||||||||||||||||||||||||||||
| 108 | 4 | $value =~ s/(')/'"$1"'/g; | |||||||||||||||||||||||||||||||||||||||||
| 109 | 4 | $value; | |||||||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||
| 112 | sub _value_escape_sh | ||||||||||||||||||||||||||||||||||||||||||
| 113 | 110 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_value_escape_sh: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 114 | 110 | my $value = shift() . ''; | |||||||||||||||||||||||||||||||||||||||||
| 115 | 110 | $value =~ s/(')/'"$1"'/g; | |||||||||||||||||||||||||||||||||||||||||
| 116 | 110 | $value; | |||||||||||||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||
| 119 | sub _value_escape_win32 | ||||||||||||||||||||||||||||||||||||||||||
| 120 | 8 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_value_escape_win32: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 121 | 8 | my $value = shift() . ''; | |||||||||||||||||||||||||||||||||||||||||
| 122 | 8 | $value =~ s/%/%%/g; | |||||||||||||||||||||||||||||||||||||||||
| 123 | 8 | $value =~ s/([&^|<>()])/^$1/g; | |||||||||||||||||||||||||||||||||||||||||
| 124 | 8 | $value =~ s/\n/^\n\n/g; | |||||||||||||||||||||||||||||||||||||||||
| 125 | 8 | $value; | |||||||||||||||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||
| 128 | # `0 Null | ||||||||||||||||||||||||||||||||||||||||||
| 129 | # `a Alert bell/beep | ||||||||||||||||||||||||||||||||||||||||||
| 130 | # `b Backspace | ||||||||||||||||||||||||||||||||||||||||||
| 131 | # `f Form feed (use with printer output) | ||||||||||||||||||||||||||||||||||||||||||
| 132 | # `n New line | ||||||||||||||||||||||||||||||||||||||||||
| 133 | # `r Carriage return | ||||||||||||||||||||||||||||||||||||||||||
| 134 | # `r`n Carriage return + New line | ||||||||||||||||||||||||||||||||||||||||||
| 135 | # `t Horizontal tab | ||||||||||||||||||||||||||||||||||||||||||
| 136 | # `v Vertical tab (use with printer output) | ||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||
| 138 | 13 | my %ps = ( # microsoft would have to be different | |||||||||||||||||||||||||||||||||||||||||
| 139 | "\0" => '`0', | ||||||||||||||||||||||||||||||||||||||||||
| 140 | "\a" => '`a', | ||||||||||||||||||||||||||||||||||||||||||
| 141 | "\b" => '`b', | ||||||||||||||||||||||||||||||||||||||||||
| 142 | "\f" => '`f', | ||||||||||||||||||||||||||||||||||||||||||
| 143 | "\r" => '`r', | ||||||||||||||||||||||||||||||||||||||||||
| 144 | "\n" => '`n', | ||||||||||||||||||||||||||||||||||||||||||
| 145 | "\t" => '`t', | ||||||||||||||||||||||||||||||||||||||||||
| 146 | #"\v" => '`v', | ||||||||||||||||||||||||||||||||||||||||||
| 147 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||
| 149 | sub _value_escape_powershell | ||||||||||||||||||||||||||||||||||||||||||
| 150 | 3 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_value_escape_powershell: called CC=1 SCAR=0.1
| |||||||||||||||||||||||||||||||||||||||||||
| 151 | 3 | my $value = shift() . ''; | |||||||||||||||||||||||||||||||||||||||||
| 152 | 3 | $value =~ s/(["'`\$#()])/`$1/g; | |||||||||||||||||||||||||||||||||||||||||
| 153 | 0 | $value =~ s/([\0\a\b\f\r\n\t])/$ps{$1}/eg; | |||||||||||||||||||||||||||||||||||||||||
| 154 | 3 | $value; | |||||||||||||||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||
| 157 | sub _quote_word_sh | ||||||||||||||||||||||||||||||||||||||||||
| 158 | 20 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_quote_word_sh: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 159 | 20 | "'" . _value_escape_sh(shift) . "'"; | |||||||||||||||||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||
| 162 | sub _quote_word_csh | ||||||||||||||||||||||||||||||||||||||||||
| 163 | 2 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_quote_word_csh: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 164 | 2 | "'" . _value_escape_csh(shift) . "'"; | |||||||||||||||||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||
| 167 | sub _quote_word_fish | ||||||||||||||||||||||||||||||||||||||||||
| 168 | 4 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_quote_word_fish: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 169 | 4 | "'" . _value_escape_fish(shift) . "'"; | |||||||||||||||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||
| 172 | sub _quote_word_win32 | ||||||||||||||||||||||||||||||||||||||||||
| 173 | 8 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_quote_word_win32: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 174 | 8 | my $value = _value_escape_win32(shift); | |||||||||||||||||||||||||||||||||||||||||
| 175 | 8 | ▶ | $value =~ /\s/ ? qq{"$value"} : $value; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||||||
| 178 | sub _quote_word_powershell | ||||||||||||||||||||||||||||||||||||||||||
| 179 | 12 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_quote_word_powershell: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 180 | 12 | my $value = shift() . ''; | |||||||||||||||||||||||||||||||||||||||||
| 181 | 12 | $value =~ s/(')/''/g; | |||||||||||||||||||||||||||||||||||||||||
| 182 | 12 | "'$value'"; | |||||||||||||||||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||
| 186 | sub unset | ||||||||||||||||||||||||||||||||||||||||||
| 187 | 1 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
unset: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 188 | 1 | my($self, $name) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||||||||||
| 190 | 1 | push @{ $self->{commands} }, ['unset', $name]; | |||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||
| 192 | 1 | $self; | |||||||||||||||||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||||||
| 196 | sub set_alias | ||||||||||||||||||||||||||||||||||||||||||
| 197 | 3 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_alias: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 198 | 3 | my($self, $alias, $command) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||||||||
| 200 | 3 | push @{ $self->{commands} }, ['alias', $alias, $command]; | |||||||||||||||||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||||||
| 204 | sub set_path_sep | ||||||||||||||||||||||||||||||||||||||||||
| 205 | 9 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_path_sep: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 206 | 9 | my($self, $sep) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 207 | 9 | push @{ $self->{commands} }, ['set_path_sep', $sep]; | |||||||||||||||||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||||||||||||||
| 211 | sub generate | ||||||||||||||||||||||||||||||||||||||||||
| 212 | 72 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
generate: called CC=4 SCAR=14.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 213 | 72 | my($self, $shell) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||||||||||||
| 215 | 72 | ▶ | if(defined $shell) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 216 | { | ||||||||||||||||||||||||||||||||||||||||||
| 217 | 72 | ▶ | if(ref($shell) eq '') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 218 | { | ||||||||||||||||||||||||||||||||||||||||||
| 219 | 2 | my $method = join '_', $shell, 'shell'; | |||||||||||||||||||||||||||||||||||||||||
| 220 | 2 | ▶ | if(Shell::Guess->can($method)) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 221 | { | ||||||||||||||||||||||||||||||||||||||||||
| 222 | 2 | $shell = Shell::Guess->$method; | |||||||||||||||||||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||||||||||||||||||||
| 224 | else | ||||||||||||||||||||||||||||||||||||||||||
| 225 | { | ||||||||||||||||||||||||||||||||||||||||||
| 226 | 0 | croak("unknown shell type: $shell"); | |||||||||||||||||||||||||||||||||||||||||
| 227 | } | ||||||||||||||||||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||||||||||||||||
| 230 | else | ||||||||||||||||||||||||||||||||||||||||||
| 231 | { | ||||||||||||||||||||||||||||||||||||||||||
| 232 | 0 | $shell = Shell::Guess->running_shell; | |||||||||||||||||||||||||||||||||||||||||
| 233 | } | ||||||||||||||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||||||||||||
| 235 | 72 | $self->_generate($shell); | |||||||||||||||||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||||||||||
| 238 | sub _generate | ||||||||||||||||||||||||||||||||||||||||||
| 239 | 68 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_generate: called CC=62 SCAR=58.3
| |||||||||||||||||||||||||||||||||||||||||||
| 240 | 68 | my($self, $shell) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||||||||||||||
| 242 | 68 | my $buffer = ''; | |||||||||||||||||||||||||||||||||||||||||
| 243 | 68 | ▶ | my $sep = $shell->is_win32 ? ';' : ':'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||||||||
| 245 | 68 | ▶ | if(exists $self->{shebang} && $shell->is_unix) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
exists $self->{"shebang"} and $shell->is_unix
MC/DC100%2/2
exists $self->{"shebang"} and $shell->is_unix
exists $self->{"shebang"}
$shell->is_unix
Truth table100%3/3
A and B
A= exists $self->{"shebang"}B= $shell->is_unix
| |||||||||||||||||||||||||||||||||||||||||||
| 246 | { | ||||||||||||||||||||||||||||||||||||||||||
| 247 | 3 | ▶ | if(defined $self->{shebang}) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 248 | 1 | { $buffer .= "#!" . $self->{shebang} . "\n" } | |||||||||||||||||||||||||||||||||||||||||
| 249 | else | ||||||||||||||||||||||||||||||||||||||||||
| 250 | 2 | { $buffer .= "#!" . $shell->default_location . "\n" } | |||||||||||||||||||||||||||||||||||||||||
| 251 | } | ||||||||||||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||||||||||||
| 253 | 68 | ▶ | if($self->{echo_off} && ($shell->is_cmd || $shell->is_command)) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$self->{"echo_off"} and $shell->is_cmd || $shell->is_command
$shell->is_cmd or $shell->is_command
MC/DC66%2/3
$self->{"echo_off"} and $shell->is_cmd || $shell->is_command
$self->{"echo_off"}
$shell->is_cmd
$shell->is_command
Truth table75%3/4
A and B or C
A= $self->{"echo_off"}B= $shell->is_cmdC= $shell->is_command
| |||||||||||||||||||||||||||||||||||||||||||
| 254 | { | ||||||||||||||||||||||||||||||||||||||||||
| 255 | 1 | $buffer .= '@echo off' . "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 256 | } | ||||||||||||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||||||||||
| 258 | 68 | foreach my $args (map { [@$_] } @{ $self->{commands} }) | |||||||||||||||||||||||||||||||||||||||||
| 259 | { | ||||||||||||||||||||||||||||||||||||||||||
| 260 | 119 | my $command = shift @$args; | |||||||||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||||||||||
| 262 | 119 | ▶ | if($command eq 'set_path_sep') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 263 | { | ||||||||||||||||||||||||||||||||||||||||||
| 264 | 18 | $sep = shift @$args; | |||||||||||||||||||||||||||||||||||||||||
| 265 | 18 | next; | |||||||||||||||||||||||||||||||||||||||||
| 266 | } | ||||||||||||||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||||||||||||
| 268 | # rewrite set_path as set | ||||||||||||||||||||||||||||||||||||||||||
| 269 | 101 | ▶ | if($command eq 'set_path') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 270 | { | ||||||||||||||||||||||||||||||||||||||||||
| 271 | 8 | $command = 'set'; | |||||||||||||||||||||||||||||||||||||||||
| 272 | 8 | my $name = shift @$args; | |||||||||||||||||||||||||||||||||||||||||
| 273 | 8 | $args = [$name, join $sep, @$args]; | |||||||||||||||||||||||||||||||||||||||||
| 274 | } | ||||||||||||||||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||||||||||||||||
| 276 | 101 | ▶ | if($command eq 'set') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 5 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 277 | { | ||||||||||||||||||||||||||||||||||||||||||
| 278 | 26 | my($name, $value) = @$args; | |||||||||||||||||||||||||||||||||||||||||
| 279 | 26 | ▶ | if($shell->is_c) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 5 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 280 | { | ||||||||||||||||||||||||||||||||||||||||||
| 281 | 0 | $value = _value_escape_csh($value); | |||||||||||||||||||||||||||||||||||||||||
| 282 | 0 | $buffer .= "setenv $name '$value';\n"; | |||||||||||||||||||||||||||||||||||||||||
| 283 | } | ||||||||||||||||||||||||||||||||||||||||||
| 284 | elsif($shell->is_fish) | ||||||||||||||||||||||||||||||||||||||||||
| 285 | { | ||||||||||||||||||||||||||||||||||||||||||
| 286 | 0 | $value = _value_escape_fish($value); | |||||||||||||||||||||||||||||||||||||||||
| 287 | 0 | $buffer .= "set -x $name '$value';\n"; | |||||||||||||||||||||||||||||||||||||||||
| 288 | } | ||||||||||||||||||||||||||||||||||||||||||
| 289 | elsif($shell->is_bourne) | ||||||||||||||||||||||||||||||||||||||||||
| 290 | { | ||||||||||||||||||||||||||||||||||||||||||
| 291 | 26 | $value = _value_escape_sh($value); | |||||||||||||||||||||||||||||||||||||||||
| 292 | 26 | $buffer .= "$name='$value';\n"; | |||||||||||||||||||||||||||||||||||||||||
| 293 | 26 | $buffer .= "export $name;\n"; | |||||||||||||||||||||||||||||||||||||||||
| 294 | } | ||||||||||||||||||||||||||||||||||||||||||
| 295 | ▶ | elsif($shell->is_cmd || $shell->is_command) | |||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$shell->is_cmd or $shell->is_command
MC/DC0%0/2
$shell->is_cmd or $shell->is_command
$shell->is_cmd
$shell->is_command
Truth table0%0/3
A or B
A= $shell->is_cmdB= $shell->is_command
| |||||||||||||||||||||||||||||||||||||||||||
| 296 | { | ||||||||||||||||||||||||||||||||||||||||||
| 297 | 0 | $value = _value_escape_win32($value); | |||||||||||||||||||||||||||||||||||||||||
| 298 | 0 | $buffer .= "set $name=$value\n"; | |||||||||||||||||||||||||||||||||||||||||
| 299 | } | ||||||||||||||||||||||||||||||||||||||||||
| 300 | elsif($shell->is_power) | ||||||||||||||||||||||||||||||||||||||||||
| 301 | { | ||||||||||||||||||||||||||||||||||||||||||
| 302 | 0 | $value = _value_escape_powershell($value); | |||||||||||||||||||||||||||||||||||||||||
| 303 | 0 | $buffer .= "\$env:$name = \"$value\"\n"; | |||||||||||||||||||||||||||||||||||||||||
| 304 | } | ||||||||||||||||||||||||||||||||||||||||||
| 305 | else | ||||||||||||||||||||||||||||||||||||||||||
| 306 | { | ||||||||||||||||||||||||||||||||||||||||||
| 307 | 0 | croak 'don\'t know how to "set" with ' . $shell->name; | |||||||||||||||||||||||||||||||||||||||||
| 308 | } | ||||||||||||||||||||||||||||||||||||||||||
| 309 | } | ||||||||||||||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||||||||||||||
| 311 | ▶ | elsif($command eq 'append_path' || $command eq 'prepend_path') | |||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$command eq "append_path" or $command eq "prepend_path"
MC/DC100%2/2
$command eq "append_path" or $command eq "prepend_path"
$command eq "append_path"
$command eq "prepend_path"
Truth table100%3/3
A or B
A= $command eq "append_path"B= $command eq "prepend_path"
| |||||||||||||||||||||||||||||||||||||||||||
| 312 | { | ||||||||||||||||||||||||||||||||||||||||||
| 313 | 32 | my($name, @values) = @$args; | |||||||||||||||||||||||||||||||||||||||||
| 314 | 32 | ▶ | if($shell->is_c) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 315 | { | ||||||||||||||||||||||||||||||||||||||||||
| 316 | 0 | my $value = join $sep, map { _value_escape_csh($_) } @values; | |||||||||||||||||||||||||||||||||||||||||
| 317 | 0 | $buffer .= "test \"\$?$name\" = 0 && setenv $name '$value' || "; | |||||||||||||||||||||||||||||||||||||||||
| 318 | 0 | ▶ | if($command eq 'prepend_path') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 319 | 0 | { $buffer .= "setenv $name '$value$sep'\"\$$name\"" } | |||||||||||||||||||||||||||||||||||||||||
| 320 | else | ||||||||||||||||||||||||||||||||||||||||||
| 321 | 0 | { $buffer .= "setenv $name \"\$$name\"'$sep$value'" } | |||||||||||||||||||||||||||||||||||||||||
| 322 | 0 | $buffer .= ";\n"; | |||||||||||||||||||||||||||||||||||||||||
| 323 | } | ||||||||||||||||||||||||||||||||||||||||||
| 324 | elsif($shell->is_bourne) | ||||||||||||||||||||||||||||||||||||||||||
| 325 | { | ||||||||||||||||||||||||||||||||||||||||||
| 326 | 32 | my $value = join $sep, map { _value_escape_sh($_) } @values; | |||||||||||||||||||||||||||||||||||||||||
| 327 | 32 | $buffer .= "if [ -n \"\$$name\" ] ; then\n"; | |||||||||||||||||||||||||||||||||||||||||
| 328 | 32 | ▶ | if($command eq 'prepend_path') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 329 | 16 | { $buffer .= " $name='$value$sep'\$$name;\n export $name;\n" } | |||||||||||||||||||||||||||||||||||||||||
| 330 | else | ||||||||||||||||||||||||||||||||||||||||||
| 331 | 16 | { $buffer .= " $name=\$$name'$sep$value';\n export $name\n" } | |||||||||||||||||||||||||||||||||||||||||
| 332 | 32 | $buffer .= "else\n"; | |||||||||||||||||||||||||||||||||||||||||
| 333 | 32 | $buffer .= " $name='$value';\n export $name;\n"; | |||||||||||||||||||||||||||||||||||||||||
| 334 | 32 | $buffer .= "fi;\n"; | |||||||||||||||||||||||||||||||||||||||||
| 335 | } | ||||||||||||||||||||||||||||||||||||||||||
| 336 | elsif($shell->is_fish) | ||||||||||||||||||||||||||||||||||||||||||
| 337 | { | ||||||||||||||||||||||||||||||||||||||||||
| 338 | 0 | my $value = join ' ', map { _value_escape_fish($_) } @values; | |||||||||||||||||||||||||||||||||||||||||
| 339 | 0 | $buffer .= "if [ \"\$$name\" == \"\" ]; set -x $name $value; else; "; | |||||||||||||||||||||||||||||||||||||||||
| 340 | 0 | ▶ | if($command eq 'prepend_path') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 341 | 0 | { $buffer .= "set -x $name $value \$$name;" } | |||||||||||||||||||||||||||||||||||||||||
| 342 | else | ||||||||||||||||||||||||||||||||||||||||||
| 343 | 0 | { $buffer .= "set -x $name \$$name $value;" } | |||||||||||||||||||||||||||||||||||||||||
| 344 | 0 | $buffer .= "end\n"; | |||||||||||||||||||||||||||||||||||||||||
| 345 | } | ||||||||||||||||||||||||||||||||||||||||||
| 346 | ▶ | elsif($shell->is_cmd || $shell->is_command || $shell->is_power) | |||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/6
$shell->is_cmd or $shell->is_command or $shell->is_power
$shell->is_cmd or $shell->is_command
MC/DC0%0/3
$shell->is_cmd or $shell->is_command or $shell->is_power
$shell->is_cmd
$shell->is_command
$shell->is_power
Truth table0%0/4
A or B or C
A= $shell->is_cmdB= $shell->is_commandC= $shell->is_power
| |||||||||||||||||||||||||||||||||||||||||||
| 347 | { | ||||||||||||||||||||||||||||||||||||||||||
| 348 | 0 | ▶ | my $value = join $sep, map { $shell->is_power ? _value_escape_powershell($_) : _value_escape_win32($_) } @values; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 349 | 0 | ▶ | if($shell->is_power) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 350 | { | ||||||||||||||||||||||||||||||||||||||||||
| 351 | 0 | $buffer .= "if(\$env:$name) { "; | |||||||||||||||||||||||||||||||||||||||||
| 352 | 0 | ▶ | if($command eq 'prepend_path') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 353 | 0 | { $buffer .= "\$env:$name = \"$value$sep\" + \$env:$name" } | |||||||||||||||||||||||||||||||||||||||||
| 354 | else | ||||||||||||||||||||||||||||||||||||||||||
| 355 | 0 | { $buffer .= "\$env:$name = \$env:$name + \"$sep$value\"" } | |||||||||||||||||||||||||||||||||||||||||
| 356 | 0 | $buffer .= " } else { \$env:$name = \"$value\" }\n"; | |||||||||||||||||||||||||||||||||||||||||
| 357 | } | ||||||||||||||||||||||||||||||||||||||||||
| 358 | else | ||||||||||||||||||||||||||||||||||||||||||
| 359 | { | ||||||||||||||||||||||||||||||||||||||||||
| 360 | 0 | $buffer .= "if defined $name (set "; | |||||||||||||||||||||||||||||||||||||||||
| 361 | 0 | ▶ | if($command eq 'prepend_path') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 362 | 0 | { $buffer .= "$name=$value$sep%$name%" } | |||||||||||||||||||||||||||||||||||||||||
| 363 | else | ||||||||||||||||||||||||||||||||||||||||||
| 364 | 0 | { $buffer .= "$name=%$name%$sep$value" } | |||||||||||||||||||||||||||||||||||||||||
| 365 | 0 | $buffer .=") else (set $name=$value)\n"; | |||||||||||||||||||||||||||||||||||||||||
| 366 | } | ||||||||||||||||||||||||||||||||||||||||||
| 367 | } | ||||||||||||||||||||||||||||||||||||||||||
| 368 | else | ||||||||||||||||||||||||||||||||||||||||||
| 369 | { | ||||||||||||||||||||||||||||||||||||||||||
| 370 | 0 | croak 'don\'t know how to "append_path" with ' . $shell->name; | |||||||||||||||||||||||||||||||||||||||||
| 371 | } | ||||||||||||||||||||||||||||||||||||||||||
| 372 | } | ||||||||||||||||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||||||||||||||||
| 374 | elsif($command eq 'unset') | ||||||||||||||||||||||||||||||||||||||||||
| 375 | { | ||||||||||||||||||||||||||||||||||||||||||
| 376 | 2 | my($name) = @$args; | |||||||||||||||||||||||||||||||||||||||||
| 377 | 2 | ▶ | if($shell->is_c) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 5 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 378 | { | ||||||||||||||||||||||||||||||||||||||||||
| 379 | 0 | $buffer .= "unsetenv $name;\n"; | |||||||||||||||||||||||||||||||||||||||||
| 380 | } | ||||||||||||||||||||||||||||||||||||||||||
| 381 | elsif($shell->is_fish) | ||||||||||||||||||||||||||||||||||||||||||
| 382 | { | ||||||||||||||||||||||||||||||||||||||||||
| 383 | 0 | $buffer .= "set -e $name;\n"; | |||||||||||||||||||||||||||||||||||||||||
| 384 | } | ||||||||||||||||||||||||||||||||||||||||||
| 385 | elsif($shell->is_bourne) | ||||||||||||||||||||||||||||||||||||||||||
| 386 | { | ||||||||||||||||||||||||||||||||||||||||||
| 387 | 2 | $buffer .= "unset $name;\n"; | |||||||||||||||||||||||||||||||||||||||||
| 388 | } | ||||||||||||||||||||||||||||||||||||||||||
| 389 | ▶ | elsif($shell->is_cmd || $shell->is_command) | |||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$shell->is_cmd or $shell->is_command
MC/DC0%0/2
$shell->is_cmd or $shell->is_command
$shell->is_cmd
$shell->is_command
Truth table0%0/3
A or B
A= $shell->is_cmdB= $shell->is_command
| |||||||||||||||||||||||||||||||||||||||||||
| 390 | { | ||||||||||||||||||||||||||||||||||||||||||
| 391 | 0 | $buffer .= "set $name=\n"; | |||||||||||||||||||||||||||||||||||||||||
| 392 | } | ||||||||||||||||||||||||||||||||||||||||||
| 393 | elsif($shell->is_power) | ||||||||||||||||||||||||||||||||||||||||||
| 394 | { | ||||||||||||||||||||||||||||||||||||||||||
| 395 | 0 | $buffer .= "Remove-Item -Path Env:\\$name -ErrorAction SilentlyContinue\n"; | |||||||||||||||||||||||||||||||||||||||||
| 396 | } | ||||||||||||||||||||||||||||||||||||||||||
| 397 | else | ||||||||||||||||||||||||||||||||||||||||||
| 398 | { | ||||||||||||||||||||||||||||||||||||||||||
| 399 | 0 | croak 'don\'t know how to "unset" with ' . $shell->name; | |||||||||||||||||||||||||||||||||||||||||
| 400 | } | ||||||||||||||||||||||||||||||||||||||||||
| 401 | } | ||||||||||||||||||||||||||||||||||||||||||
| 402 | |||||||||||||||||||||||||||||||||||||||||||
| 403 | elsif($command eq 'comment') | ||||||||||||||||||||||||||||||||||||||||||
| 404 | { | ||||||||||||||||||||||||||||||||||||||||||
| 405 | 10 | ▶ | if($shell->is_unix || $shell->is_power) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%1/3
$shell->is_unix or $shell->is_power
MC/DC0%0/2
$shell->is_unix or $shell->is_power
$shell->is_unix
$shell->is_power
Truth table33%1/3
A or B
A= $shell->is_unixB= $shell->is_power
| |||||||||||||||||||||||||||||||||||||||||||
| 406 | { | ||||||||||||||||||||||||||||||||||||||||||
| 407 | 10 | $buffer .= "# $_\n" for map { split /\n/, } @$args; | |||||||||||||||||||||||||||||||||||||||||
| 408 | } | ||||||||||||||||||||||||||||||||||||||||||
| 409 | ▶ | elsif($shell->is_cmd || $shell->is_command) | |||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$shell->is_cmd or $shell->is_command
MC/DC0%0/2
$shell->is_cmd or $shell->is_command
$shell->is_cmd
$shell->is_command
Truth table0%0/3
A or B
A= $shell->is_cmdB= $shell->is_command
| |||||||||||||||||||||||||||||||||||||||||||
| 410 | { | ||||||||||||||||||||||||||||||||||||||||||
| 411 | 0 | $buffer .= "rem $_\n" for map { split /\n/, } @$args; | |||||||||||||||||||||||||||||||||||||||||
| 412 | } | ||||||||||||||||||||||||||||||||||||||||||
| 413 | else | ||||||||||||||||||||||||||||||||||||||||||
| 414 | { | ||||||||||||||||||||||||||||||||||||||||||
| 415 | 0 | croak 'don\'t know how to "comment" with ' . $shell->name; | |||||||||||||||||||||||||||||||||||||||||
| 416 | } | ||||||||||||||||||||||||||||||||||||||||||
| 417 | } | ||||||||||||||||||||||||||||||||||||||||||
| 418 | |||||||||||||||||||||||||||||||||||||||||||
| 419 | elsif($command eq 'alias') | ||||||||||||||||||||||||||||||||||||||||||
| 420 | { | ||||||||||||||||||||||||||||||||||||||||||
| 421 | 31 | my($alias, $cmd) = @$args; | |||||||||||||||||||||||||||||||||||||||||
| 422 | 31 | ▶ | my @words = ref($cmd) eq 'ARRAY' ? @$cmd : (); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 423 | |||||||||||||||||||||||||||||||||||||||||||
| 424 | 31 | ▶ | if($shell->is_bourne) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 5 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 425 | { | ||||||||||||||||||||||||||||||||||||||||||
| 426 | 10 | ▶ | my $value = @words ? join(' ', map { _quote_word_sh($_) } @words) : $cmd; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 427 | 10 | $buffer .= "alias $alias=\"$value\";\n"; | |||||||||||||||||||||||||||||||||||||||||
| 428 | } | ||||||||||||||||||||||||||||||||||||||||||
| 429 | elsif($shell->is_c) | ||||||||||||||||||||||||||||||||||||||||||
| 430 | { | ||||||||||||||||||||||||||||||||||||||||||
| 431 | 9 | my $value; | |||||||||||||||||||||||||||||||||||||||||
| 432 | 9 | ▶ | if(@words) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 433 | { | ||||||||||||||||||||||||||||||||||||||||||
| 434 | 5 | for(@words) | |||||||||||||||||||||||||||||||||||||||||
| 435 | { | ||||||||||||||||||||||||||||||||||||||||||
| 436 | 18 | ▶ | croak "cannot generate alias '$alias' for " . $shell->name | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 437 | . ": word '$_' contains a space, which is not supported" | ||||||||||||||||||||||||||||||||||||||||||
| 438 | . " for alias commands on csh/tcsh" | ||||||||||||||||||||||||||||||||||||||||||
| 439 | if /\s/; | ||||||||||||||||||||||||||||||||||||||||||
| 440 | } | ||||||||||||||||||||||||||||||||||||||||||
| 441 | 1 | $value = join ' ', map { _quote_word_csh($_) } @words; | |||||||||||||||||||||||||||||||||||||||||
| 442 | } | ||||||||||||||||||||||||||||||||||||||||||
| 443 | else | ||||||||||||||||||||||||||||||||||||||||||
| 444 | { | ||||||||||||||||||||||||||||||||||||||||||
| 445 | 4 | $value = $cmd; | |||||||||||||||||||||||||||||||||||||||||
| 446 | } | ||||||||||||||||||||||||||||||||||||||||||
| 447 | 5 | $buffer .= "alias $alias $value;\n"; | |||||||||||||||||||||||||||||||||||||||||
| 448 | } | ||||||||||||||||||||||||||||||||||||||||||
| 449 | ▶ | elsif($shell->is_cmd || $shell->is_command) | |||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$shell->is_cmd or $shell->is_command
MC/DC100%2/2
$shell->is_cmd or $shell->is_command
$shell->is_cmd
$shell->is_command
Truth table100%3/3
A or B
A= $shell->is_cmdB= $shell->is_command
| |||||||||||||||||||||||||||||||||||||||||||
| 450 | { | ||||||||||||||||||||||||||||||||||||||||||
| 451 | 4 | ▶ | my $value = @words ? join(' ', map { _quote_word_win32($_) } @words) : $cmd; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 452 | 4 | $buffer .= "DOSKEY $alias=$value \$*\n"; | |||||||||||||||||||||||||||||||||||||||||
| 453 | } | ||||||||||||||||||||||||||||||||||||||||||
| 454 | elsif($shell->is_power) | ||||||||||||||||||||||||||||||||||||||||||
| 455 | { | ||||||||||||||||||||||||||||||||||||||||||
| 456 | 6 | ▶ | if(@words) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 457 | { | ||||||||||||||||||||||||||||||||||||||||||
| 458 | 3 | my $value = join ' ', map { _quote_word_powershell($_) } @words; | |||||||||||||||||||||||||||||||||||||||||
| 459 | 3 | $buffer .= sprintf("function %s { & %s \$args }\n", $alias, $value); | |||||||||||||||||||||||||||||||||||||||||
| 460 | } | ||||||||||||||||||||||||||||||||||||||||||
| 461 | else | ||||||||||||||||||||||||||||||||||||||||||
| 462 | { | ||||||||||||||||||||||||||||||||||||||||||
| 463 | 3 | $buffer .= sprintf("function %s { %s \$args }\n", $alias, _value_escape_powershell($cmd)); | |||||||||||||||||||||||||||||||||||||||||
| 464 | } | ||||||||||||||||||||||||||||||||||||||||||
| 465 | } | ||||||||||||||||||||||||||||||||||||||||||
| 466 | elsif($shell->is_fish) | ||||||||||||||||||||||||||||||||||||||||||
| 467 | { | ||||||||||||||||||||||||||||||||||||||||||
| 468 | 2 | ▶ | if(@words) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 469 | { | ||||||||||||||||||||||||||||||||||||||||||
| 470 | 1 | my $value = join ' ', map { _quote_word_fish($_) } @words; | |||||||||||||||||||||||||||||||||||||||||
| 471 | 1 | $buffer .= "alias $alias \"$value\";\n"; | |||||||||||||||||||||||||||||||||||||||||
| 472 | } | ||||||||||||||||||||||||||||||||||||||||||
| 473 | else | ||||||||||||||||||||||||||||||||||||||||||
| 474 | { | ||||||||||||||||||||||||||||||||||||||||||
| 475 | 1 | $buffer .= "alias $alias '$cmd';\n"; | |||||||||||||||||||||||||||||||||||||||||
| 476 | } | ||||||||||||||||||||||||||||||||||||||||||
| 477 | } | ||||||||||||||||||||||||||||||||||||||||||
| 478 | else | ||||||||||||||||||||||||||||||||||||||||||
| 479 | { | ||||||||||||||||||||||||||||||||||||||||||
| 480 | 0 | croak 'don\'t know how to "alias" with ' . $shell->name; | |||||||||||||||||||||||||||||||||||||||||
| 481 | } | ||||||||||||||||||||||||||||||||||||||||||
| 482 | } | ||||||||||||||||||||||||||||||||||||||||||
| 483 | } | ||||||||||||||||||||||||||||||||||||||||||
| 484 | |||||||||||||||||||||||||||||||||||||||||||
| 485 | 64 | $buffer; | |||||||||||||||||||||||||||||||||||||||||
| 486 | } | ||||||||||||||||||||||||||||||||||||||||||
| 487 | |||||||||||||||||||||||||||||||||||||||||||
| 488 | |||||||||||||||||||||||||||||||||||||||||||
| 489 | sub generate_file | ||||||||||||||||||||||||||||||||||||||||||
| 490 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
generate_file: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 491 | 0 | my($self, $shell, $filename) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 492 | 0 | my $fh; | |||||||||||||||||||||||||||||||||||||||||
| 493 | 0 | ▶ | open($fh, '>', $filename) or die "cannot open $filename: $!"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 494 | 0 | ▶ | print $fh $self->generate($shell) or die "cannot write $filename: $!"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 495 | 0 | ▶ | close $fh or die "error closing $filename: $!"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 496 | } | ||||||||||||||||||||||||||||||||||||||||||
| 497 | |||||||||||||||||||||||||||||||||||||||||||
| 498 | 13 | *import = \&Exporter::import; | |||||||||||||||||||||||||||||||||||||||||
| 499 | |||||||||||||||||||||||||||||||||||||||||||
| 500 | 13 | our @EXPORT_OK = qw( win32_space_be_gone cmd_escape_path powershell_escape_path ); | |||||||||||||||||||||||||||||||||||||||||
| 501 | |||||||||||||||||||||||||||||||||||||||||||
| 502 | |||||||||||||||||||||||||||||||||||||||||||
| 503 | 0 | ▶ | *_win_to_posix_path = $^O =~ /^(cygwin|msys)$/ ? \&Cygwin::win_to_posix_path : sub { $_[0] }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 504 | 0 | ▶ | *_posix_to_win_path = $^O =~ /^(cygwin|msys)$/ ? \&Cygwin::posix_to_win_path : sub { $_[0] }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 505 | |||||||||||||||||||||||||||||||||||||||||||
| 506 | sub win32_space_be_gone | ||||||||||||||||||||||||||||||||||||||||||
| 507 | 1 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
win32_space_be_gone: called CC=5 SCAR=30.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 508 | 1 | ▶ | return @_ if $^O !~ /^(MSWin32|cygwin|msys)$/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 509 | map { | ||||||||||||||||||||||||||||||||||||||||||
| 510 | 0 | my $path = $_; | |||||||||||||||||||||||||||||||||||||||||
| 511 | 0 | ▶ | if($path =~ /\s/) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 512 | { | ||||||||||||||||||||||||||||||||||||||||||
| 513 | 0 | my $short = Win32::GetShortPathName(_posix_to_win_path($path)); | |||||||||||||||||||||||||||||||||||||||||
| 514 | 0 | ▶ | $path = _win_to_posix_path($short) if defined $short && $short !~ /\s/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $short and not $short =~ /\s/
MC/DC0%0/2
defined $short and not $short =~ /\s/
defined $short
not $short =~ /\s/
Truth table0%0/3
A and not(B)
A= defined $shortB= not $short =~ /\s/
| |||||||||||||||||||||||||||||||||||||||||||
| 515 | } | ||||||||||||||||||||||||||||||||||||||||||
| 516 | 0 | $path; | |||||||||||||||||||||||||||||||||||||||||
| 517 | } @_; | ||||||||||||||||||||||||||||||||||||||||||
| 518 | } | ||||||||||||||||||||||||||||||||||||||||||
| 519 | |||||||||||||||||||||||||||||||||||||||||||
| 520 | |||||||||||||||||||||||||||||||||||||||||||
| 521 | sub cmd_escape_path | ||||||||||||||||||||||||||||||||||||||||||
| 522 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
cmd_escape_path: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 523 | 0 | my $path = shift() . ''; | |||||||||||||||||||||||||||||||||||||||||
| 524 | 0 | $path =~ s/%/%%/g; | |||||||||||||||||||||||||||||||||||||||||
| 525 | 0 | $path =~ s/([&^|<>])/^$1/g; | |||||||||||||||||||||||||||||||||||||||||
| 526 | 0 | $path =~ s/\n/^\n\n/g; | |||||||||||||||||||||||||||||||||||||||||
| 527 | 0 | "\"$path\""; | |||||||||||||||||||||||||||||||||||||||||
| 528 | } | ||||||||||||||||||||||||||||||||||||||||||
| 529 | |||||||||||||||||||||||||||||||||||||||||||
| 530 | |||||||||||||||||||||||||||||||||||||||||||
| 531 | sub powershell_escape_path | ||||||||||||||||||||||||||||||||||||||||||
| 532 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
powershell_escape_path: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 533 | 0 | map { my $p = _value_escape_powershell($_); $p =~ s/ /` /g; $p } @_; | |||||||||||||||||||||||||||||||||||||||||
| 534 | } | ||||||||||||||||||||||||||||||||||||||||||
| 535 | |||||||||||||||||||||||||||||||||||||||||||
| 536 | 13 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 537 | |||||||||||||||||||||||||||||||||||||||||||
| 538 | __END__ | ||||||||||||||||||||||||||||||||||||||||||