幅広い知識と幅広いスキルを求められている系システムエンジニアです。リモートワークしかやりません。

PowerShell v6がβになっていたので触ってみた

久々に Mac でも使えるオープンソースの PowerShell のリポジトリをのぞいてみたら beta になっていたので触ってみました。

beta.7 になっている。

$ brew cask info powershell

powershell: 6.0.0-beta.7
https://github.com/PowerShell/PowerShell
Not installed
From: https://github.com/caskroom/homebrew-cask/blob/master/Casks/powershell.rb
==> Name
PowerShell
==> Artifacts
powershell-6.0.0-beta.7-osx.10.12-x64.pkg (Pkg)
==> Caveats
A OpenSSL-backed libcurl is required for custom handling of certificates.
This is rarely needed, but you can install it with
  brew install curl --with-openssl
See https://github.com/PowerShell/PowerShell/issues/2211

インストール!簡単!

brew cask install powershell

触ってみる

とりあえずいつも使っている fish から起動。

$ powershell
PowerShell v6.0.0-beta.7
Copyright (C) Microsoft Corporation. All rights reserved.

PS /Users/tmnm/dev/src/gitlab.com/tmnm/blog>

whoooeh windows っぽいシェルになりました(mac です)。PowerShell on Tmux on Alacritty :p

PS /Users/tmnm/dev/src/gitlab.com/tmnm/blog> get-host


Name             : ConsoleHost
Version          : 6.0.0
InstanceId       : 835b627c-bf66-4d35-b3fc-5b876f78d6ef
UI               : System.Management.Automation.Internal.Host.InternalHostUserInterface
CurrentCulture   : ja-JP
CurrentUICulture : ja-JP
PrivateData      : Microsoft.PowerShell.ConsoleHost+ConsoleColorProxy
DebuggerEnabled  : True
IsRunspacePushed : False
Runspace         : System.Management.Automation.Runspaces.LocalRunspace



PS /Users/tmnm/dev/src/gitlab.com/tmnm/blog> Get-Host


Name             : ConsoleHost
Version          : 6.0.0
InstanceId       : 835b627c-bf66-4d35-b3fc-5b876f78d6ef
UI               : System.Management.Automation.Internal.Host.InternalHostUserInterface
CurrentCulture   : ja-JP
CurrentUICulture : ja-JP
PrivateData      : Microsoft.PowerShell.ConsoleHost+ConsoleColorProxy
DebuggerEnabled  : True
IsRunspacePushed : False
Runspace         : System.Management.Automation.Runspaces.LocalRunspace

Windows と一緒で大文字小文字関係ないんですよね。

現在のディレクトリ以下のファイル数を拡張子でグルーピングしてトップ 10 を表示

PS /Users/tmnm/dev/src/gitlab.com/tmnm/blog> Get-ChildItem -Recurse | Group Extension | Sort-Object Count -Desc | Select -First 10

Count Name                      Group
----- ----                      -----
23869 .js                       {gatsby-config.js, gatsby-node.js, postcss.config.js, asn1.js...}
 6474                           {node_modules, public, src, LICENSE...}
 2953 .json                     {package.json, package.json, package.json, package.json...}
 2390 .md                       {README.md, README.md, readme.md, readme.md...}
  888 .test                     {comment_feature.test, eol-comment_feature.test, keyword_feature.test, number_feature.test...}
  723 .h                        {nan_callbacks_12_inl.h, nan_callbacks_pre_12_inl.h, nan_callbacks.h, nan_converters_43_inl.h...}
  351 .flow                     {index.js.flow, index.js.flow, index.js.flow, index.js.flow...}
  302 .map                      {lodash.map, ajv.min.js.map, index.js.map, bulma.css.map...}
  196 .dat                      {byte0000.dat, byte0001.dat, byte0002.dat, byte0003.dat...}
  144 .html                     {index.html, index.html, index.html, index.js.html...}

こういう処理をさせるなら PowerShell 最強でしょう。あとパフォーマンスも結構きびきび動きますね。いいですね。

コマンドの数は?

alpha バージョンの時は、

PowerShell for MacのCmdletの数 345 pic.twitter.com/emLHqjqcoA

— miiton (@MIITON) 2016年8月19日

で、今見ると、

PS /Users/tmnm/dev/src/gitlab.com/tmnm/blog> Get-Command | Measure-Object


Count    : 352
Average  :
Sum      :
Maximum  :
Minimum  :
Property :

Cmdlet は前に見た時から 7 つ増えて 352 個に。これ Function も含んでいるので正確じゃないですね。

PS /Users/tmnm/dev/src/gitlab.com/tmnm/blog> Get-Command | Group CommandType

Count Name                      Group
----- ----                      -----
  129 Function                  {Add-NodeKeys, AddDscResourceProperty, AddDscResourcePropertyFromMetadata, AfterAll...}
  223 Cmdlet                    {Add-Content, Add-History, Add-Member, Add-Type...}

こういう結果でした。

ちなみに私の最近の環境は Alacritty + tmux + fish ですが、もともとは Windows サーバーの お守りをしていた時に PowerShell をバリバリ使っていた時に

LinuxにPowerShellはよ

— miiton (@MIITON) 2016年5月24日

とのたまっていて、Windows サーバーのお守りから退いた時にこの PowerShell の発表があって やたらテンションが上がっていたのを覚えています。

すげーwww MacでPowerShellうごいたーーーwwww

— miiton (@MIITON) 2016年8月19日

デフォルトシェルにする?

さすがにしない...少数派すぎるので色々弊害が出そうです。
bash/zsh 前提で書かれているナレッジばかりですもんね。
ただ、ちょっとした集計処理とかには使うかもしれません。

ちなみに現在の Windows 10 の PowerShell は 5.1 でした

> Get-Host

Name             : ConsoleHost
Version          : 5.1.15063.608
InstanceId       : 5eb33054-b47a-4cce-971e-ac35201569dc
UI               : System.Management.Automation.Internal.Host.InternalHostUserInterface
CurrentCulture   : ja-JP
CurrentUICulture : ja-JP
PrivateData      : Microsoft.PowerShell.ConsoleHost+ConsoleColorProxy
DebuggerEnabled  : True
IsRunspacePushed : False
Runspace         : System.Management.Automation.Runspaces.LocalRunspace
© 2023 @miiton