#author("2024-11-11T09:06:27+09:00","default:nobuoki","nobuoki") #author("2024-11-11T09:07:06+09:00","default:nobuoki","nobuoki") * 基本事項 [#c5e513e4] - PowerShellのプロンプトは pronpt 関数で定義する -- cmd.exe で言うところの環境変数 PROMPT 相当 - PowerShellのエスケープ文字は ` (バッククオート)です - ~/.bashrc 的なもの -- shell:personal\WindowsPowerShell\profile.ps1 -- マイドキュメント(shell:personal)\WindowsPowerShell\profile.ps1 -- C:\WINDOWS\SYSTEM32\windowspowershell\v1.0\profile.ps1 (要 管理者権限) -- 参考: - [[PowerShellのプロンプト文字列をカスタマイズする - @IT>https://atmarkit.itmedia.co.jp/fwin2k/win2ktips/983psprompt/psprompt.html]] - [[タブや改行を文字列値に含める方法[PowerShell] : バヤシタ>https://bayashita.com/p/entry/show/91]] * デフォルトのプロンプト [#ib88d44d] cmd.exe: PROMPT $p$g$s 相当 #prism(powershell){{{ PS C:\Users\1000202334\Desktopn> }}} 定義(の中身)を表示させる - 参考:[[PowerShell/Functionの一覧および内容を表示する方法>https://win.just4fun.biz/?PowerShell/Function%E3%81%AE%E4%B8%80%E8%A6%A7%E3%81%8A%E3%82%88%E3%81%B3%E5%86%85%E5%AE%B9%E3%82%92%E8%A1%A8%E7%A4%BA%E3%81%99%E3%82%8B%E6%96%B9%E6%B3%95]] #prism(powershell){{{ PS C:\Users\1000202334\Desktop> (get-item function:prompt).Definition "PS " + $(get-location) + "> " PS C:\Users\1000202334\Desktop> }}} つまりこう #prism(powershell){{{ function prompt { "PS " + $(get-location) + "> " } }}} * 途中で改行する [#y6611e1a] cmd.exe: PROMPT $p$_$g$s 相当 #prism(powershell){{{ PS C:\Users\1000202334\Desktop > }}} profile.ps1 #prism(powershell){{{ function prompt { "PS " + $(get-location) + "`r`n> " } }}} powershellで設定 #prism(powershell){{{ # ユーザーのドキュメントディレクトリのパスを取得 $userDocuments = [Environment]::GetFolderPath('MyDocuments') # WindowsPowerShellディレクトリのパスを作成 $powershellDir = Join-Path $userDocuments "WindowsPowerShell" # ディレクトリが存在しない場合は作成 if (!(Test-Path $powershellDir)) { New-Item -ItemType Directory -Path $powershellDir } # profile.ps1ファイルを作成し、関数定義を書き込む $profilePath = Join-Path $powershellDir "profile.ps1" $content = @' function prompt { "PS " + $(get-location) + "`r`n> " } '@ Set-Content -Path $profilePath -Value $content }}}