dotfiles/bash/.bashrc.d/ps1
2026-03-28 23:29:53 +01:00

28 lines
719 B
Bash

#!/usr/bin/env bash
function git_prompt() {
local branch
branch=$(git symbolic-ref --short HEAD 2>/dev/null) || return
echo " (${branch})"
}
function set_prompt() {
local exit_code=$?
local reset="\001\033[0m\002"
local color_user="\001\033[38;5;109m\002"
local color_host="\001\033[38;5;144m\002"
local color_path="\001\033[38;5;246m\002"
local color_error="\001\033[31;49m\002"
local prompt_symbol
if [[ $exit_code -ne 0 ]]; then
prompt_symbol="${color_error}\$${reset}"
else
prompt_symbol="\$"
fi
PS1="${color_user}\u${reset}@${color_host}\h${reset} [ ${color_path}\w${reset}\$(git_prompt) ]${prompt_symbol} "
}
PROMPT_COMMAND=set_prompt