posh-gitは大変便利ですが、ディレクトリ階層が深くなるとプロンプト表示が長くなりすぎなので、改良してみました。
カレントディレクトリ19文字を超えたら、右から16文字を切り出して表示するようにしています。
マイドキュメントのWindowsPowerShellフォルダにあるMicrosoft.PowerShell_profile.ps1ファイルを以下のように編集します。posh-gitはPsGetでインストールした状態を前提としているのでImport-ModuleのPATH指定は適宜ご自身の環境に合わせてください。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Push-Location (Split-Path -Path $MyInvocation.MyCommand.Definition -Parent) | |
# Load posh-git module from current directory | |
Import-Module .\Modules\posh-git | |
# If module is installed in a default location ($env:PSModulePath), | |
# use this instead (see about_Modules for more information): | |
# Import-Module posh-git | |
#Set up a simple prompt, adding the git prompt parts inside git repos | |
function global:prompt { | |
$realLASTEXITCODE = $LASTEXITCODE | |
# # Reset color, which can be messed up by Enable-GitColors | |
# $Host.UI.RawUI.ForegroundColor = $GitPromptSettings.DefaultForegroundColor | |
$pro = '' | |
if ($pwd.ProviderPath.ToString().Length -gt 19) { | |
if ((Split-Path($pwd.ProviderPath) -Leaf).ToString().Length -gt 16) { #C:\分は削除して | |
$pro = $pwd.Drive.Name + ':..' + (Split-Path($pwd.ProviderPath) -Leaf) | |
} | |
else { | |
$start = $pwd.ProviderPath.ToString().Length - 16 | |
$pro = $pwd.Drive.Name + ':..' + $pwd.ProviderPath.Substring($start) | |
} | |
} | |
else { | |
$pro = $pwd.ProviderPath | |
} | |
Write-Host($pro) -nonewline | |
Write-VcsStatus | |
$global:LASTEXITCODE = $realLASTEXITCODE | |
return "> " | |
} | |
Pop-Location | |
Start-SshAgent -Quiet |
こんな表示になります。
コメント