65 lines
1 KiB
Bash
65 lines
1 KiB
Bash
|
PROMPT_COMMAND=(__prompt_command "${PROMPT_COMMAND[@]}")
|
||
|
|
||
|
# custom terminal prompt format.
|
||
|
__prompt_command()
|
||
|
{
|
||
|
local last_status="${?}"
|
||
|
local is_error=false
|
||
|
local is_root=false
|
||
|
|
||
|
if [[ $last_status != 0 && $last_status != 130 ]]; then
|
||
|
is_error=true
|
||
|
fi
|
||
|
if [[ "$UID" -eq 0 ]]; then
|
||
|
is_root=true
|
||
|
fi
|
||
|
|
||
|
# add newline
|
||
|
PS1="\n"
|
||
|
|
||
|
# set error red
|
||
|
if $is_error; then
|
||
|
PS1+="\[${color_red}\]"
|
||
|
PS1+="["
|
||
|
else
|
||
|
PS1+="\[${color_default}\]"
|
||
|
PS1+="["
|
||
|
fi
|
||
|
|
||
|
# add time
|
||
|
PS1+="\[${color_white}\]"
|
||
|
PS1+="$(date +%H:%M) "
|
||
|
|
||
|
# set root red
|
||
|
if $is_root; then
|
||
|
PS1+="\[${color_red}\]"
|
||
|
else
|
||
|
PS1+="\[${color_cyan}\]"
|
||
|
fi
|
||
|
|
||
|
# add user, host and working dir
|
||
|
PS1+="\u@\h "
|
||
|
PS1+="\[${color_blue}\]"
|
||
|
PS1+="\w"
|
||
|
|
||
|
# set error red
|
||
|
if $is_error; then
|
||
|
PS1+="\[${color_red}\]"
|
||
|
PS1+="] "
|
||
|
else
|
||
|
PS1+="\[${color_default}\]"
|
||
|
PS1+="] "
|
||
|
fi
|
||
|
|
||
|
# command on new line
|
||
|
PS1+="\n"
|
||
|
PS1+="\[${color_default}\]"
|
||
|
|
||
|
# set user tag
|
||
|
if $is_root; then
|
||
|
PS1+="# "
|
||
|
else
|
||
|
PS1+="$ "
|
||
|
fi
|
||
|
}
|