From 9693b39da6ea10475083b1c106c58b3989f7f84d Mon Sep 17 00:00:00 2001 From: jitakirin Date: Thu, 21 May 2015 21:12:18 +0100 Subject: [PATCH] Port sudo indicator to powerline theme This ports sudo indicator feature to powerline theme, originally added to powerline-multiline theme in PR #452. --- themes/powerline/powerline.theme.bash | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/themes/powerline/powerline.theme.bash b/themes/powerline/powerline.theme.bash index 1bc4eca9..4e7320cb 100644 --- a/themes/powerline/powerline.theme.bash +++ b/themes/powerline/powerline.theme.bash @@ -4,7 +4,7 @@ THEME_PROMPT_SEPARATOR="" SHELL_SSH_CHAR=" " SHELL_THEME_PROMPT_COLOR=32 -SHELL_SSH_THEME_PROMPT_COLOR=208 +SHELL_THEME_PROMPT_COLOR_SUDO=202 VIRTUALENV_CHAR="ⓔ " VIRTUALENV_THEME_PROMPT_COLOR=35 @@ -37,13 +37,17 @@ function set_rgb_color { } function powerline_shell_prompt { - if [[ -n "${SSH_CLIENT}" ]]; then - SHELL_PROMPT="${bold_white}$(set_rgb_color - ${SHELL_SSH_THEME_PROMPT_COLOR}) ${SHELL_SSH_CHAR}\u@\h ${normal}" - LAST_THEME_COLOR=${SHELL_SSH_THEME_PROMPT_COLOR} - else - SHELL_PROMPT="${bold_white}$(set_rgb_color - ${SHELL_THEME_PROMPT_COLOR}) \u ${normal}" - LAST_THEME_COLOR=${SHELL_THEME_PROMPT_COLOR} + SHELL_PROMPT_COLOR=${SHELL_THEME_PROMPT_COLOR} + if sudo -n true &>/dev/null; then + SHELL_PROMPT_COLOR=${SHELL_THEME_PROMPT_COLOR_SUDO} fi + if [[ -n "${SSH_CLIENT}" ]]; then + SHELL_PROMPT="${SHELL_SSH_CHAR}\u@\h" + else + SHELL_PROMPT="\u" + fi + SHELL_PROMPT="${bold_white}$(set_rgb_color - ${SHELL_PROMPT_COLOR}) ${SHELL_PROMPT} ${normal}" + LAST_THEME_COLOR=${SHELL_PROMPT_COLOR} } function powerline_virtualenv_prompt {