61 lines
No EOL
1.6 KiB
Bash
61 lines
No EOL
1.6 KiB
Bash
# shellcheck shell=bash
|
|
|
|
PSBIN="${HOME}/.local/share/bash"
|
|
|
|
prompt() {
|
|
local status="$?" file
|
|
PS1="${PSFIX}"
|
|
PSSCM="$(source "${PSBIN}/prompt/prompt-scm.sh" 2>/dev/null )"
|
|
PSPIP="$(source "${PSBIN}/prompt/prompt-pip.sh" 2>/dev/null )"
|
|
|
|
# done refreshing, starting to assemble it.
|
|
PS1="${PS1}\\[\\e[0m\\]${PSSCM%% }${PSSCM:+" "}"
|
|
PS1="${PS1}\\[\\e[0m\\]${PSPIP%% }${PSPIP:+" "}"
|
|
# change prompt if last execution was not successful
|
|
if [[ "${status}" -gt 0 ]]; then
|
|
PS1="${PS1}\\[\\e[0;31m\\]\\$"
|
|
else
|
|
PS1="${PS1}\\[\\e[0;32m\\]\\$"
|
|
fi
|
|
# back to default
|
|
PS1="${PS1}\\[\\e[0m\\] "
|
|
}
|
|
|
|
# Use window titles only in known X terminals.
|
|
case ${TERM} in
|
|
xterm*|rxvt*|Eterm|aterm|kterm|gnome|screen)
|
|
PSTITLE='\[\e]0;\u@\h:\w\a\]'
|
|
;;
|
|
*)
|
|
PSTITLE=''
|
|
;;
|
|
esac
|
|
|
|
: "${PSUSERCOLOR:="1;33"}" # yellow by default
|
|
: "${PSHOSTCOLOR:="1;33"}" # yellow by default
|
|
|
|
typeset -A PSHOSTCOLORS
|
|
PSHOSTCOLORS[louis@desktop-louis]="38;5;164@1;30"
|
|
|
|
if [[ -n ${PSHOSTCOLORS[${USER}@${HOSTNAME}]} ]]; then
|
|
PSUSERCOLOR="${PSHOSTCOLORS["${USER}@${HOSTNAME}"]%@*}"
|
|
PSHOSTCOLOR="${PSHOSTCOLORS["${USER}@${HOSTNAME}"]##*@}"
|
|
fi
|
|
|
|
if [[ ${EUID} -eq 0 ]]; then
|
|
PSUSERCOLOR="38;5;160"
|
|
fi
|
|
|
|
# window title if the terminal can interpret this
|
|
PSFIX="${PSTITLE}"
|
|
# user, with color according to preference
|
|
PSFIX="${PSFIX}\\[\\e[${PSUSERCOLOR}m\\]\\u\\[\\e[0m\\]"
|
|
# @
|
|
PSFIX="${PSFIX}\\[\\e[0m\\]@"
|
|
# host, with color according to preference
|
|
PSFIX="${PSFIX}\\[\\e[${PSHOSTCOLOR}m\\]\\h\\[\\e[0m\\]"
|
|
# current working directory.
|
|
PSFIX="${PSFIX}\\[\\e[38;5;111m\\] \\W "
|
|
|
|
PROMPT_DIRTRIM=1
|
|
PROMPT_COMMAND+=('prompt') |