2024-11-16 00:41:42 +00:00
|
|
|
SH="$(cat /proc/$$/comm)"
|
|
|
|
|
2024-11-16 00:54:13 +00:00
|
|
|
shell_color() {
|
|
|
|
local code="${1}"
|
2024-11-16 01:19:41 +00:00
|
|
|
case "${SH}" in
|
|
|
|
"bash")
|
|
|
|
printf "\e[0"
|
|
|
|
if [ -n "${code}" ]; then
|
|
|
|
printf "%s" ";${code}"
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
printf "\033["
|
|
|
|
if [ -n "${code}" ]; then
|
|
|
|
printf "%s" "${code}"
|
|
|
|
else
|
|
|
|
printf "0"
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
printf "m"
|
2024-11-16 00:54:13 +00:00
|
|
|
}
|
2024-11-16 01:19:41 +00:00
|
|
|
SH_DEFAULT="$(shell_color)"
|
|
|
|
SH_GREEN="$(shell_color 31)"
|
|
|
|
SH_RED="$(shell_color 32)"
|
|
|
|
SH_BROWN="$(shell_color 33)"
|
|
|
|
SH_MAGENTA="$(shell_color 35)"
|
|
|
|
SH_CYAN="$(shell_color 36)"
|
2024-11-16 00:54:13 +00:00
|
|
|
|
2024-11-16 00:41:42 +00:00
|
|
|
case "${SH}" in
|
|
|
|
"bash")
|
|
|
|
# completion
|
|
|
|
file="/usr/share/bash-completion/bash_completion"
|
|
|
|
if [ -f "${file}" ]; then
|
|
|
|
. "${file}"
|
|
|
|
fi
|
|
|
|
# history
|
|
|
|
HISTCONTROL="ignorespace"
|
|
|
|
HISTSIZE=-1
|
|
|
|
HISTTIMEFORMAT="%Y%m%d %H%M%S "
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
;;
|
|
|
|
esac
|
2024-11-15 16:06:29 +00:00
|
|
|
|
|
|
|
# prompt
|
|
|
|
|
2024-11-12 08:56:52 +00:00
|
|
|
ps1() {
|
2024-11-16 00:41:42 +00:00
|
|
|
local date host id
|
2024-11-13 12:14:58 +00:00
|
|
|
local code="${1}"
|
|
|
|
date="$(date +%H:%M:%S)"
|
2024-11-12 09:18:44 +00:00
|
|
|
local git
|
2024-11-13 12:14:58 +00:00
|
|
|
host="$(hostname)"
|
2024-11-16 00:41:42 +00:00
|
|
|
id="$(id --user)"
|
2024-11-12 09:18:44 +00:00
|
|
|
local path="${PWD}"
|
|
|
|
local user="${USER}"
|
|
|
|
local view="└ "
|
2024-11-13 12:14:58 +00:00
|
|
|
if [ "${code}" -ne 0 ]; then
|
2024-11-16 01:19:41 +00:00
|
|
|
view="${view}${SH_GREEN}"
|
2024-11-12 09:18:44 +00:00
|
|
|
else
|
2024-11-16 01:19:41 +00:00
|
|
|
view="${view}${SH_RED}"
|
2024-11-12 09:18:44 +00:00
|
|
|
fi
|
2024-11-16 01:19:41 +00:00
|
|
|
view="${view}${code}${SH_DEFAULT} @ ${SH_BROWN}${date}${SH_DEFAULT}"
|
2024-11-16 00:41:42 +00:00
|
|
|
if [ "$(type -t __git_ps1)" = "function" ]; then
|
2024-11-12 09:18:44 +00:00
|
|
|
git="$(__git_ps1)"
|
2024-11-13 12:10:19 +00:00
|
|
|
if [ -n "${git}" ]; then
|
2024-11-16 01:19:41 +00:00
|
|
|
view="${view} –${SH_MAGENTA}${git}${SH_DEFAULT}"
|
2024-11-12 09:18:44 +00:00
|
|
|
fi
|
|
|
|
fi
|
2024-11-16 01:19:41 +00:00
|
|
|
view="${view}\n${SH_CYAN}${path}${SH_DEFAULT}"
|
2024-11-12 09:18:44 +00:00
|
|
|
view="${view}\n┌ "
|
2024-11-16 00:41:42 +00:00
|
|
|
if [ "${id}" -eq 0 ]; then
|
2024-11-16 01:19:41 +00:00
|
|
|
view="${view}${SH_GREEN}"
|
2024-11-12 09:18:44 +00:00
|
|
|
else
|
2024-11-16 01:19:41 +00:00
|
|
|
view="${view}${SH_RED}"
|
2024-11-12 09:18:44 +00:00
|
|
|
fi
|
2024-11-16 01:19:41 +00:00
|
|
|
view="${view}${user}${SH_DEFAULT} @ ${SH_BROWN}${host}${SH_DEFAULT}"
|
2024-11-12 09:18:44 +00:00
|
|
|
echo -e "${view}\n${PS2}"
|
2023-08-20 16:33:26 +00:00
|
|
|
}
|
|
|
|
|
2024-11-12 08:59:53 +00:00
|
|
|
PS1="\$(ps1 \${?})"
|
2024-11-12 08:56:52 +00:00
|
|
|
|
|
|
|
PS2="\
|
|
|
|
├ "
|