New theme with additionnal useful information using prompt colors

pull/146/head
Matthieu Fronton 2012-07-09 15:24:43 +02:00
parent 1ed27354c0
commit 252236f279
2 changed files with 79 additions and 0 deletions

View File

@ -144,6 +144,61 @@ function virtualenv_prompt {
fi fi
} }
# conditional colors
function user_type_color_prompt {
if [ ${UID} -eq 0 ] ; then
if [ "${USER}" == "${LOGNAME}" ]; then
if [[ ${SUDO_USER} ]]; then
echo -e "$bold_red"
else
echo -e "$red"
fi
else
echo -e "$yellow"
fi
else
if [ ${USER} == ${LOGNAME} ]; then
echo -e "$green"
else
echo -e "$orange"
fi
fi
}
function host_connection_color_prompt {
if [[ ${SSH_CLIENT} ]] || [[ ${SSH2_CLIENT} ]]; then
SSH_FLAG=1
fi
if [[ ${SSH_FLAG} -eq 1 ]]; then
echo -e "$cyan"
elif [[ -n ${SESS_SRC} ]]; then
if [[ "${SESS_SRC}" = "(:0.0)" ]]; then
echo -e "$green"
else
local parent_process=$(cat /proc/${PPID}/cmdline)
if [[ "$parent_process" = "in.rlogind*" ]]; then
echo -e "$orange"
elif [[ "$parent_process" = "in.telnetd*" ]]; then
echo -e "$yellow"
else
echo -e "$bold_red"
fi
fi
elif [[ "${SESS_SRC}" = "" ]]; then
echo -e "$green"
else
echo -e "$red"
fi
}
function writeable_path_color_prompt {
if [[ -w $PWD ]]; then
echo -e "$green"
else
echo -e "$red"
fi
}
# backwards-compatibility # backwards-compatibility
function git_prompt_info { function git_prompt_info {
git_prompt_vars git_prompt_vars

View File

@ -0,0 +1,24 @@
#!/usr/bin/env bash
SCM_THEME_PROMPT_DIRTY=" ${red}"
SCM_THEME_PROMPT_CLEAN=" ${bold_green}"
SCM_THEME_PROMPT_PREFIX=" |"
SCM_THEME_PROMPT_SUFFIX="${green}|"
GIT_THEME_PROMPT_DIRTY=" ${red}"
GIT_THEME_PROMPT_CLEAN=" ${bold_green}"
GIT_THEME_PROMPT_PREFIX=" ${green}|"
GIT_THEME_PROMPT_SUFFIX="${green}|"
RVM_THEME_PROMPT_PREFIX="|"
RVM_THEME_PROMPT_SUFFIX="|"
function prompt_command() {
# Adding timestamp
# Adding full information about the current position using ssh/scp format => user@host:path
# Colors on user is based on privileges (root, su, ...)
# Colors on host is based on connection (ssh, local, telnet, ...)
# Colors on path is based on credentials (write access or not)
PS1="\n${reset_color}[\T]${purple}$(ruby_version_prompt) $(user_type_color_prompt)\u${reset_color}@$(host_connection_color_prompt)\h${reset_color}:$(writeable_path_color_prompt)\w\n${bold_cyan}$(scm_char)${green}$(scm_prompt_info) ${green}${reset_color} "
}
PROMPT_COMMAND=prompt_command;