Connection: via IPv4
Your IP : 3.19.31.73
In English

2段bashとGitブランチ表示をやる

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 " "
}

 

参考

This post was last modified on 2023年4月27日 7:41 PM

Share
Published by
おきん(blog)

Recent Posts

[メモ]JellyfinでEntraID認証

概要 メディアサーバーのJel…

2週間 ago

MastodonでhCaptchaを使う

概要 Mastodonサーバー…

2か月 ago

Redisを6.0から7.xに更新する

概要 Ubuntu 22.04…

2か月 ago

CodiMDでEntra IDを使う

出来ること CodiMDのログ…

3か月 ago

CloudflareをDDNSみたいに使う

やりたいこと Cloudfla…

3か月 ago

This website uses cookies.