Skip to content

Instantly share code, notes, and snippets.

@blzjns
Last active February 15, 2020 04:42
Show Gist options
  • Save blzjns/372a84f95b78e3f2b580a3aabbdbf41a to your computer and use it in GitHub Desktop.
Save blzjns/372a84f95b78e3f2b580a3aabbdbf41a to your computer and use it in GitHub Desktop.
Custom git bash command-line header. Displays user name, current path, repo name, and repo branch
displayUserTxt=">_ blzjns"
userBgColor="\e[7;49;32m"
branchColor="\e[1;35m"
pathColor="\e[0;33m"
repoColor="\e[36m"
boldTxt=$(tput bold)
noTextFmt="\e[0m"
if test -f /etc/profile.d/git-sdk.sh; then
TITLEPREFIX=SDK-${MSYSTEM#MINGW}
else
TITLEPREFIX=$MSYSTEM
fi
if test -f ~/.config/git/git-prompt.sh; then
. ~/.config/git/git-prompt.sh
else
function getPathInfo() {
local path=$(echo $1 | sed "s/\/c/'C:'/g")
echo -e "$pathColor$boldTxt@ (path)$noTextFmt $path"
}
function getRepoName() {
if git rev-parse --show-toplevel >/dev/null 2>&1; then
local repoBaseName=$(basename $(git rev-parse --show-toplevel))
echo -e "$repoColor☁ (repo)$noTextFmt $repoBaseName"
else
echo ""
fi
}
function getBranchName() {
if git rev-parse --show-toplevel >/dev/null 2>&1; then
local branchName=$(__git_ps1 | sed "s/[),(,' ']//g")
echo -e "$branchColor⌥ (branch)$noTextFmt $branchName"
fi
}
function getUserInfo() {
echo -e "$userBgColor$boldTxt$displayUserTxt$noTextFmt"
}
function getHeader() {
local user="$(getUserInfo)"
local path="$(getPathInfo) $1"
local repo="$(getRepoName)"
local headerTxt=$([ ! -z "$repo" ] && echo "\n$user\n $path\n $repo\n $(getBranchName)\n " || echo "\n$user\n$path\n ")
echo -e "$headerTxt"
}
PS1="\[\033]0;$TITLEPREFIX:$PWD\007\]" # set window title
if test -z "$WINELOADERNOEXEC"; then
GIT_EXEC_PATH="$(git --exec-path 2>/dev/null)"
COMPLETION_PATH="${GIT_EXEC_PATH%/libexec/git-core}"
COMPLETION_PATH="${COMPLETION_PATH%/lib/git-core}"
COMPLETION_PATH="$COMPLETION_PATH/share/git/completion"
if test -f "$COMPLETION_PATH/git-prompt.sh"; then
. "$COMPLETION_PATH/git-completion.bash"
. "$COMPLETION_PATH/git-prompt.sh"
fi
fi
PS1="$PS1"'`getHeader \w`'
PS1="$PS1 $noTextFmt" # change color
PS1="$PS1 \n" # new line
PS1="$PS1$ " # prompt always: "$ "
fi
MSYS2_PS1="$PS1" # for detection by MSYS2 SDK's bash.basrc
# Evaluate all user-specific Bash completion scripts (if any)
if test -z "$WINELOADERNOEXEC"; then
for c in "$HOME"/bash_completion.d/*.bash; do
# Handle absence of any scripts (or the folder) gracefully
test ! -f "$c" ||
. "$c"
done
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment