2段bashとGitブランチ表示をやる
Posted on by おきん(blog)
Ubuntu 18.04の場合
.bashrcの末尾に追記
# source ~/.git-prompt.sh
if [ -f /etc/bash_completion ]; then
. /etc/bash_completion
fi
if [ -f /etc/bash_completion.d/git-prompt ]; then
export PS1='\[\033[01;32m\]\u@\h\[\033[01;33m\] \w$(__git_ps1) \n\[\033[01;34m\]\$\[\033[00m\] '
else
export PS1='\[\033[01;32m\]\u@\h\[\033[01;33m\] \w \n\[\033[01;34m\]\$\[\033[00m\] '
fi
Windowsの場合(PowerShell)
事前準備としてPowerShell(管理者)で、下記のコマンドを実行する
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned
C:\Users\<ユーザー名>\Documents\WindowsPowerShell\Profile.ps1 を作成して書き込む
(PowerShellの$profileに詳しければそれに合わせて追記することも可能)
function Get-GitBranch{
git branch 2>$null |
ForEach-Object {
if($_[0] -eq "*") {
$branch = ($_ -Split " ")[1]
return "(git:$branch)"
}
}
}
function prompt {
(Get-Host).UI.RawUI.WindowTitle = "Windows PowerShell $pwd"
$name = $pwd.Path
$gb = Get-GitBranch
Write-Host "" -NoNewLine -ForegroundColor White
Write-Host $env:USERNAME -NoNewLine -ForegroundColor Cyan
Write-Host "@$name " -NoNewLine -ForegroundColor White
Write-Host "$gb" -ForegroundColor Red
Write-Host ">" -NoNewLine -ForegroundColor White
return " "
}
参考
Ubuntu bashのプロンプトHack!!!!(gitブランチ表示)https://qiita.com/ryosukue/items/bc1eae639e3950790eb9 (2020/01/05閲覧)
PowerShellのプロンプトにGitのブランチを表示したくなった https://m0t0k1x2.tumblr.com/post/132379609864/powershell%E3%81%AE%E3%83%97%E3%83%AD%E3%83%B3%E3%83%97%E3%83%88%E3%81%ABgit%E3%81%AE%E3%83%96%E3%83%A9%E3%83%B3%E3%83%81%E3%82%92%E8%A1%A8%E7%A4%BA%E3%81%97%E3%81%9F%E3%81%8F%E3%81%AA%E3%81%A3%E3%81%9F (2020/01/05閲覧)
PowerShell で Profile を利用して スクリプトの自動読み込みをしてみよう https://tech.guitarrapc.com/entry/2013/09/23/164357(2020/01/05閲覧)
https://mi.okin-jp.net/@okin_p
https://misskey.io/@okin_p
https://twpf.jp/okin_p
http://profile.hatena.ne.jp/okin_p/
名前:おきん
やってること:面倒なことをPHPにやらせる、IPv6でなにかする、車で移動する
主なガジェット:Google Pixel 4a (5G) ,iPhone XS(ジャンク), iPad mini5, その他
種別:猫 over IPv6 run on PHP
パソコンやガジェットについて書いていく…予定。