From 252236f2799d8077d0f1187252bd434b6202599a Mon Sep 17 00:00:00 2001 From: Matthieu Fronton Date: Mon, 9 Jul 2012 15:24:43 +0200 Subject: [PATCH] New theme with additionnal useful information using prompt colors --- themes/base.theme.bash | 55 +++++++++++++++++++++++++++++++++++ themes/frntn/frntn.theme.bash | 24 +++++++++++++++ 2 files changed, 79 insertions(+) create mode 100644 themes/frntn/frntn.theme.bash diff --git a/themes/base.theme.bash b/themes/base.theme.bash index c433ae19..ded8ffb2 100644 --- a/themes/base.theme.bash +++ b/themes/base.theme.bash @@ -144,6 +144,61 @@ function virtualenv_prompt { 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 function git_prompt_info { git_prompt_vars diff --git a/themes/frntn/frntn.theme.bash b/themes/frntn/frntn.theme.bash new file mode 100644 index 00000000..46d34e16 --- /dev/null +++ b/themes/frntn/frntn.theme.bash @@ -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;