From: Graham Knop Date: Fri, 15 Nov 2013 06:00:23 +0000 (-0500) Subject: detect powershell X-Git-Tag: v2.000_000~36 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=p5sagit%2Flocal-lib.git;a=commitdiff_plain;h=fc5f07c3c4e0726a494fc6c6199a627bf43b8dfb detect powershell --- diff --git a/lib/local/lib.pm b/lib/local/lib.pm index f7cb586..d65df50 100644 --- a/lib/local/lib.pm +++ b/lib/local/lib.pm @@ -520,38 +520,26 @@ ok(-d 't/var/splat'); =cut sub guess_shelltype { - my $shellbin = 'sh'; - if(defined $ENV{'SHELL'}) { - my @shell_bin_path_parts = File::Spec->splitpath($ENV{'SHELL'}); - $shellbin = $shell_bin_path_parts[-1]; + my $shellbin + = defined $ENV{SHELL} + ? (File::Spec->splitpath($ENV{SHELL}))[-1] + : ( $^O eq 'MSWin32' && exists $ENV{'!EXITCODE'} ) + ? 'bash' + : ( $^O eq 'MSWin32' && $ENV{PROMPT} && $ENV{COMSPEC} ) + ? (File::Spec->splitpath($ENV{COMSPEC}))[-1] + : ( $^O eq 'MSWin32' && !$ENV{PROMPT} ) + ? 'powershell.exe' + : 'sh'; + + for ($shellbin) { + return + /csh/ ? 'csh' + : /command\.com/ ? 'cmd' + : /cmd\.exe/ ? 'cmd' + : /4nt\.exe/ ? 'cmd' + : /powershell\.exe/ ? 'powershell' + : 'bourne'; } - my $shelltype = do { - local $_ = $shellbin; - if(/csh/) { - 'csh' - } else { - 'bourne' - } - }; - - # Both Win32 and Cygwin have $ENV{COMSPEC} set. - if (defined $ENV{'COMSPEC'} && $^O ne 'cygwin') { - my @shell_bin_path_parts = File::Spec->splitpath($ENV{'COMSPEC'}); - $shellbin = $shell_bin_path_parts[-1]; - $shelltype = do { - local $_ = $shellbin; - if(/command\.com/) { - 'cmd' - } elsif(/cmd\.exe/) { - 'cmd' - } elsif(/4nt\.exe/) { - 'cmd' - } else { - $shelltype - } - }; - } - return $shelltype; } 1;