2022-01-15 19:00:35 +09:00
|
|
|
#! bash oh-my-bash.module
|
2017-10-10 18:07:01 +07:00
|
|
|
|
|
|
|
# Set term to 256color mode, if 256color is not supported, colors won't work properly
|
|
|
|
if [[ $COLORTERM = gnome-* && $TERM = xterm ]] && infocmp gnome-256color >/dev/null 2>&1; then
|
|
|
|
export TERM=gnome-256color
|
|
|
|
elif infocmp xterm-256color >/dev/null 2>&1; then
|
|
|
|
export TERM=xterm-256color
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Detect whether a rebbot is required
|
|
|
|
function show_reboot_required() {
|
|
|
|
if [ ! -z "$_bf_prompt_reboot_info" ]; then
|
|
|
|
if [ -f /var/run/reboot-required ]; then
|
|
|
|
printf "Reboot required!"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# Set different host color for local and remote sessions
|
|
|
|
function set_host_color() {
|
|
|
|
# Detect if connection is through SSH
|
|
|
|
if [[ ! -z $SSH_CLIENT ]]; then
|
|
|
|
printf "${lime_yellow}"
|
|
|
|
else
|
|
|
|
printf "${light_orange}"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# Set different username color for users and root
|
|
|
|
function set_user_color() {
|
|
|
|
case $(id -u) in
|
|
|
|
0)
|
2022-01-24 14:55:36 +09:00
|
|
|
printf "${_omb_prompt_brown}"
|
2017-10-10 18:07:01 +07:00
|
|
|
;;
|
|
|
|
*)
|
2022-01-24 14:55:36 +09:00
|
|
|
printf "${_omb_prompt_teal}"
|
2017-10-10 18:07:01 +07:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
2023-02-10 00:38:56 +09:00
|
|
|
function scm_prompt {
|
2017-10-10 18:07:01 +07:00
|
|
|
CHAR=$(scm_char)
|
|
|
|
if [ $CHAR = $SCM_NONE_CHAR ]
|
|
|
|
then
|
|
|
|
return
|
|
|
|
else
|
|
|
|
echo "[$(scm_char)$(scm_prompt_info)]"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# Define custom colors we need
|
|
|
|
# non-printable bytes in PS1 need to be contained within \[ \].
|
|
|
|
# Otherwise, bash will count them in the length of the prompt
|
|
|
|
function set_custom_colors() {
|
|
|
|
dark_grey="\[$(tput setaf 8)\]"
|
|
|
|
light_grey="\[$(tput setaf 248)\]"
|
|
|
|
|
|
|
|
light_orange="\[$(tput setaf 172)\]"
|
|
|
|
bright_yellow="\[$(tput setaf 220)\]"
|
|
|
|
lime_yellow="\[$(tput setaf 190)\]"
|
|
|
|
|
|
|
|
powder_blue="\[$(tput setaf 153)\]"
|
|
|
|
}
|
|
|
|
|
2023-02-10 00:38:56 +09:00
|
|
|
function __ps_time {
|
2022-01-19 16:52:15 +09:00
|
|
|
echo "$(clock_prompt)${_omb_prompt_normal}\n"
|
2017-10-10 18:07:01 +07:00
|
|
|
}
|
|
|
|
|
2022-01-11 12:40:43 +09:00
|
|
|
function _omb_theme_PROMPT_COMMAND() {
|
2022-01-19 16:52:15 +09:00
|
|
|
ps_reboot="${bright_yellow}$(show_reboot_required)${_omb_prompt_normal}\n"
|
2017-10-10 18:07:01 +07:00
|
|
|
|
2022-01-19 16:52:15 +09:00
|
|
|
ps_username="$(set_user_color)\u${_omb_prompt_normal}"
|
|
|
|
ps_uh_separator="${dark_grey}@${_omb_prompt_normal}"
|
|
|
|
ps_hostname="$(set_host_color)\h${_omb_prompt_normal}"
|
2017-10-10 18:07:01 +07:00
|
|
|
|
2022-01-24 14:55:36 +09:00
|
|
|
ps_path="${_omb_prompt_olive}\w${_omb_prompt_normal}"
|
2017-10-10 18:07:01 +07:00
|
|
|
ps_scm_prompt="${light_grey}$(scm_prompt)"
|
|
|
|
|
2022-01-19 16:52:15 +09:00
|
|
|
ps_user_mark="${_omb_prompt_normal} ${_omb_prompt_normal}"
|
|
|
|
ps_user_input="${_omb_prompt_normal}"
|
2017-10-10 18:07:01 +07:00
|
|
|
|
|
|
|
# Set prompt
|
|
|
|
PS1="$ps_reboot$(__ps_time)$ps_username$ps_uh_separator$ps_hostname $ps_path $ps_scm_prompt$ps_user_mark$ps_user_input"
|
|
|
|
}
|
|
|
|
|
|
|
|
# Initialize custom colors
|
|
|
|
set_custom_colors
|
|
|
|
|
|
|
|
THEME_CLOCK_COLOR=${THEME_CLOCK_COLOR:-"$dark_grey"}
|
|
|
|
|
|
|
|
# scm theming
|
|
|
|
SCM_THEME_PROMPT_PREFIX=""
|
|
|
|
SCM_THEME_PROMPT_SUFFIX=""
|
|
|
|
|
2022-01-24 14:55:36 +09:00
|
|
|
SCM_THEME_PROMPT_DIRTY=" ${_omb_prompt_bold_brown}✗${light_grey}"
|
lib, themes: Resolve conflicting variables
"lib" has used the variables "red", "green", "yellow", "blue", and
"purple" for outputting logs to stdout/stderr. On the other hand,
"themes" has used the same variables for including escape sequences in
PS1. These two sets of variables have different values, i.e., the
latter is enclosed by '\[' and '\]' and contains escaped '\e', which
means that there have been variable conflicts. In this commit, more
specific variables are used in these places to resolve the conflicts.
2022-01-19 17:23:35 +09:00
|
|
|
SCM_THEME_PROMPT_CLEAN=" ${_omb_prompt_green}✓${light_grey}"
|
|
|
|
SCM_GIT_CHAR="${_omb_prompt_green}±${light_grey}"
|
2022-01-24 14:55:36 +09:00
|
|
|
SCM_SVN_CHAR="${_omb_prompt_bold_teal}⑆${light_grey}"
|
|
|
|
SCM_HG_CHAR="${_omb_prompt_bold_brown}☿${light_grey}"
|
2017-10-10 18:07:01 +07:00
|
|
|
|
2022-01-11 12:40:43 +09:00
|
|
|
_omb_util_add_prompt_command _omb_theme_PROMPT_COMMAND
|