Windowsのプロンプトを何とかしたい - ぶやかー

目次 Outline

Powershell

プロファイルに書く。
ファイル名:Microsoft.PowerShell_profile.ps1
ディレクトリ: C:\Users\<ユーザ名>\Documents\WindowsPowerShell
デフォルトではこのファイル、ディレクトリがないので、自分で勝手に作成する仕様とおもわれる。

ファイル強制的に作る

New-Item -path $profile -type file -force

Microsoft.PowerShell_profile.ps1にプロンプトの定義を書く

function prompt {
  $branch = ""
  if (git branch) {
    (git branch | select-string "^\*").ToString() | set-variable -name branch
    $branch = $branch.trim() -replace "^\* *", ""
  }
  Write-Host("") -NoNewline -ForegroundColor White
  Write-Host($(get-location)) -NoNewline -ForegroundColor Cyan
  Write-Host("") -NoNewline -ForegroundColor White
  if ($branch -ne "") {
    Write-Host(" (") -NoNewline -ForegroundColor White
    Write-Host($branch) -NoNewline -ForegroundColor Yellow
    Write-Host(")") -NoNewline -ForegroundColor White
  }
  return "`n$ "
}

こんな感じのプロンプトになる。と思う。

C:\Users\<Username>
$

この記事を書いた人 Wrote this article

kmatsunuma

TOP