LoginSignup
10
7

More than 5 years have passed since last update.

posh-gitのインストール&プロンプトカスタマイズ

Posted at

この記事について

  • 正直な所、自分用のメモ感は強いです

手順

Git for Windows の インストール

  • 公式サイト:Git for Windows
  • 下記からwindows用Gitをダウンロード、インストールを行う
  • 但し、Powershellでも使えるようなオプションを選ぶ必要 がある。
  • TODO:オプションについて

Posh-git の clone

Posh-git を実行可能にするために Powershell の スクリプト実行を変更

  • 実はこの手順、README.md の Prerequisites / 2番に同じ手順が記載されていますよ、と。

  • powershellは基本スクリプトの実行をポリシーで制限されているので、この制限を緩める必要があるので、下記コマンドにてスクリプトの実行を許可する。

Set-ExecutionPolicy RemoteSigned -Scope CurrentUser -Confirm

install.ps1 の実行

  • posh-git を展開したディレクトリに移動して、 install.ps1 を実行する。これによりプロファイルが作成されて、posh-gitを読み込むようなスクリプトが置かれる。

profileのカスタマイズ

%userprofile%\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1
  • 上記ファイルをカスタマイズすることによりposh-gitでカスタマイズしたプロンプトをさらにカスタマイズすることが可能
  • 自分は下記の様にした
function prompt {
    $origLastExitCode = $LASTEXITCODE
    Write-Host "PS " -nonewline
    Write-VcsStatus
    Write-Host ($ExecutionContext.SessionState.Path.CurrentLocation) -ForegroundColor Green
    $LASTEXITCODE = $origLastExitCode
    "$('>' * ($nestedPromptLevel + 1)) "
}

Import-Module posh-git
$global:GitPromptSettings.BeforeText = '['
$global:GitPromptSettings.AfterText  = '] '
10
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
7