Skip to content

Instantly share code, notes, and snippets.

@AyresMonteiro
Last active October 4, 2025 16:27
Show Gist options
  • Save AyresMonteiro/c2a048e9ff051069b745f66ae1aecbfa to your computer and use it in GitHub Desktop.
Save AyresMonteiro/c2a048e9ff051069b745f66ae1aecbfa to your computer and use it in GitHub Desktop.
[Debian] Add it to ~/.bashrc and show current git branch on bash
# You need to acquire a copy of that script from git source code
# then place it in your home dir
source ~/git-prompt.sh
# Function to safely wrap __git_ps1 for use in PS1
git_branch_prompt() {
local branch
branch="$(__git_ps1 ' (%s)')"
if [ -n "$branch" ]; then
echo "\[\033[1;33m\]$branch\[\033[0m\]"
else
echo ""
fi
}
# Function to get venv name and append it to ps1 in runtime
venv_prompt() {
if [ -n "$VIRTUAL_ENV" ]; then
# Get just the venv folder name (e.g., "venv" from "/path/to/venv")
local venv_name=$(basename "$VIRTUAL_ENV")
echo " \[\033[1;36m\]($venv_name)\[\033[0m\]"
else
echo ""
fi
}
# Function to get current date/time in dd/MM HH:mm format
datetime_prompt() {
echo "\[\033[1;37m\]$(date '+%d/%m %H:%M')\[\033[0m\]"
}
chroot_prompt() {
if [[ -n "$debian_chroot" ]]; then
echo -e "\[\033[0;33m\](${debian_chroot})\[\033[0m\]"
fi
}
COMPLETE_CURRENT_DATE="\D{%F %T}"
CURRENT_DATE="\D{%T}"
YELLOW="\e[33m"
BOLD="\e[1m"
BOLD_YELLOW="\e[1;33m"
BOLD_RED="\e[1;91m"
COLOR_END="\e[0m"
COLORED_DATE="${BOLD_YELLOW}[${CURRENT_DATE}]${COLOR_END}"
COLORED_USER="\[\033[01;32m\]\u\[\033[00m\]"
COLORED_PATH="\[\033[01;34m\]\w\[\033[00m\]"
COLORED_DIR="\[\033[01;34m\]\W\[\033[00m\]"
COLORED_GIT_BRANCH="${BOLD_YELLOW}\$(git_branch_prompt)${COLOR_END}"
COLORED_INDICATOR="\[\033[1m\]/>\[\033[0m\]"
BASE_PS1="\[\e]0;Ayres' Terminal - \W\a\]${debian_chroot:+($debian_chroot)}"
# Set PROMPT_COMMAND to update the PS1 before each prompt
PROMPT_COMMAND='PS1="${BASE_PS1}$(datetime_prompt)$(chroot_prompt)$(venv_prompt) ${COLORED_USER} ${COLORED_DIR}$(git_branch_prompt) ${COLORED_INDICATOR} "'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment