macOS で Powershell - rehabilitation 編 -3 : profile
Powershell では bash_profile のように、起動時に諸々の設定を施すための設定ファイルが使える。
macOS 版…というか Powershell netcore も Windows 版と同様に profile の設定ができる。
設定ファイルの path は $profile 変数にある
PS /Users/hoge> $profile /Users/hoge/.config/powershell/Microsoft.PowerShell_profile.ps1 PS /Users/hoge>
実は $profile が格納する設定ファイルパスは、他にもある。
$profile を get-member してみると…
PS /Users/hoge> $profile | gm TypeName: System.String Name MemberType Definition ---- ---------- ---------- Clone Method System.Object Clone(), System.Object ICloneable.... CompareTo Method int CompareTo(System.Object value), int CompareT... CopyTo Method void CopyTo(int sourceIndex, char[] destination,... …長いので途中省略… TrimEnd Method string TrimEnd(), string TrimEnd(char trimChar),... TrimStart Method string TrimStart(), string TrimStart(char trimCh... AllUsersAllHosts NoteProperty string AllUsersAllHosts=/usr/local/microsoft/pow... AllUsersCurrentHost NoteProperty string AllUsersCurrentHost=/usr/local/microsoft/... CurrentUserAllHosts NoteProperty string CurrentUserAllHosts=/Users/hoge/.conf... CurrentUserCurrentHost NoteProperty string CurrentUserCurrentHost=/Users/hoge/.c... Chars ParameterizedProperty char Chars(int index) {get;} Length Property int Length {get;} PS /Users/hoge>
MemberType = NoteProperty が profile 設定ファイルの path を指しており、名前の通りユーザーやホストにより保存場所を切り分けている。
というわけで、MemberType = NoteProperty に絞って format-list してみた。
PS /Users/hoge> $profile | gm | ? MemberType -eq NoteProperty | format-list TypeName : System.String Name : AllUsersAllHosts MemberType : NoteProperty Definition : string AllUsersAllHosts=/usr/local/microsoft/powershell/6/profile.ps1 TypeName : System.String Name : AllUsersCurrentHost MemberType : NoteProperty Definition : string AllUsersCurrentHost=/usr/local/microsoft/powershell/6/Microsoft.PowerShell_p rofile.ps1 TypeName : System.String Name : CurrentUserAllHosts MemberType : NoteProperty Definition : string CurrentUserAllHosts=/Users/hoge/.config/powershell/profile.ps1 TypeName : System.String Name : CurrentUserCurrentHost MemberType : NoteProperty Definition : string CurrentUserCurrentHost=/Users/hoge/.config/powershell/Microsoft.PowerShe ll_profile.ps1 PS /Users/hoge> $profile.CurrentUserCurrentHost /Users/hoge/.config/powershell/Microsoft.PowerShell_profile.ps1 PS /Users/hoge>
なお、profile を一度も設定していなければ $profile が返す path は実在してない。
S /Users/hoge> test-path -path $profile test-path : Access to the path '/Users/hoge/.config/powershell/Microsoft.PowerShell_profile.ps1' is denied. At line:1 char:1 + test-path -path $profile + ~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : PermissionDenied: (/Users/hoge...ell_profile.ps1:String) [Test-Path], UnauthorizedAccessException + FullyQualifiedErrorId : ItemExistsUnauthorizedAccessError,Microsoft.PowerShell.Commands.TestPathCommand False PS /Users/hoge>