Last active
May 11, 2018 18:03
-
-
Save edwingustafson/ed4bcb3800e5116ae364e496ad418825 to your computer and use it in GitHub Desktop.
Mercurial and Git repository bash prompt
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
# Default prompt | |
DEFAULT_PROMPT="\u@\h:\w$ " | |
# Separator | |
SEPARATOR=· | |
# Use the compiled front-end to Mercurial | |
HG=/usr/bin/chg | |
# Disable all Mercurial extensions | |
HGRCPATH= | |
# Plain, parseable output | |
HGPLAIN=1 | |
function make_prompt { | |
local HG_ROOT=$(${HG} root 2>/dev/null) | |
local GIT_ROOT=$(git rev-parse --show-toplevel 2>/dev/null) | |
if [ -n "${HG_ROOT}" ]; then | |
# Mercurial project | |
local VCS=hg | |
local PROJECT_BRANCH=$(${HG} identify -b) | |
local PROJECT_PATH="${PWD#$HG_ROOT}" | |
local PROJECT_NAME=${HG_ROOT##*/} | |
export PS1="${VCS}${SEPARATOR}${PROJECT_BRANCH}@${PROJECT_NAME}:${PROJECT_PATH:=/}$ " | |
elif [ -n "${GIT_ROOT}" ]; then | |
# Git project | |
local VCS=git | |
local PROJECT_BRANCH=$(git branch | grep '^*' | awk '{print $2}') | |
local PROJECT_PATH="${PWD#$GIT_ROOT}" | |
local PROJECT_NAME=${GIT_ROOT##*/} | |
export PS1="${VCS}${SEPARATOR}${PROJECT_BRANCH}@${PROJECT_NAME}:${PROJECT_PATH:=/}$ " | |
else | |
export PS1=${DEFAULT_PROMPT} | |
fi | |
} | |
export PROMPT_COMMAND=make_prompt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment