From 7b8656f8e79fb369b91b93cb3cbbe437935bb893 Mon Sep 17 00:00:00 2001 From: Michael Louwrens Date: Sat, 10 Feb 2018 19:46:31 +0200 Subject: [PATCH 1/6] add sudo status to context and user prompts --- powerlevel9k.zsh-theme | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index c32ccd48..40b38a22 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -590,6 +590,7 @@ prompt_context() { typeset -AH context_states context_states=( "ROOT" "yellow" + "SUDO" "yellow" "DEFAULT" "yellow" "REMOTE" "yellow" ) @@ -608,6 +609,8 @@ prompt_context() { current_state="ROOT" elif [[ -n "$SSH_CLIENT" || -n "$SSH_TTY" ]]; then current_state="REMOTE" + elif sudo -n uptime >/dev/null 2>&1; then + current_statue="SUDO" fi "$1_prompt_segment" "${0}_${current_state}" "$2" "$DEFAULT_COLOR" "${context_states[$current_state]}" "${content}" @@ -629,6 +632,14 @@ prompt_user() { "FOREGROUND_COLOR" "yellow" "VISUAL_IDENTIFIER" "ROOT_ICON" ) + elif sudo -n uptime >/dev/null 2>&1; then + user_state=( + "STATE" "SUDO" + "CONTENT" "${POWERLEVEL9K_USER_TEMPLATE}" + "BACKGROUND_COLOR" "${DEFAULT_COLOR}" + "FOREGROUND_COLOR" "yellow" + "VISUAL_IDENTIFIER" "ROOT_ICON" + ) else user_state=( "STATE" "DEFAULT" From 06802647a1919c8f51bbead78104a6093e137e5a Mon Sep 17 00:00:00 2001 From: Michael Louwrens Date: Sat, 10 Feb 2018 20:50:59 +0200 Subject: [PATCH 2/6] change sudo detection method --- powerlevel9k.zsh-theme | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 40b38a22..17af7ccb 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -609,7 +609,7 @@ prompt_context() { current_state="ROOT" elif [[ -n "$SSH_CLIENT" || -n "$SSH_TTY" ]]; then current_state="REMOTE" - elif sudo -n uptime >/dev/null 2>&1; then + elif sudo -n true 2>/dev/null; then current_statue="SUDO" fi @@ -632,7 +632,7 @@ prompt_user() { "FOREGROUND_COLOR" "yellow" "VISUAL_IDENTIFIER" "ROOT_ICON" ) - elif sudo -n uptime >/dev/null 2>&1; then + elif sudo -n true 2>/dev/null; then user_state=( "STATE" "SUDO" "CONTENT" "${POWERLEVEL9K_USER_TEMPLATE}" From 0551854a9e09eb6b058710bb9af21327dfb13d54 Mon Sep 17 00:00:00 2001 From: Michael Louwrens Date: Sat, 10 Feb 2018 21:01:09 +0200 Subject: [PATCH 3/6] fix typo --- powerlevel9k.zsh-theme | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 17af7ccb..bce893fe 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -610,7 +610,7 @@ prompt_context() { elif [[ -n "$SSH_CLIENT" || -n "$SSH_TTY" ]]; then current_state="REMOTE" elif sudo -n true 2>/dev/null; then - current_statue="SUDO" + current_state="SUDO" fi "$1_prompt_segment" "${0}_${current_state}" "$2" "$DEFAULT_COLOR" "${context_states[$current_state]}" "${content}" From 38937858736ff8a7483dbdd353c36aa190028aab Mon Sep 17 00:00:00 2001 From: Michael Louwrens Date: Sat, 10 Feb 2018 21:24:06 +0200 Subject: [PATCH 4/6] try out sudo icon changes --- functions/icons.zsh | 2 ++ powerlevel9k.zsh-theme | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/functions/icons.zsh b/functions/icons.zsh index e642da00..b29d0108 100644 --- a/functions/icons.zsh +++ b/functions/icons.zsh @@ -258,6 +258,7 @@ case $POWERLEVEL9K_MODE in RIGHT_SUBSEGMENT_SEPARATOR $'\uE0B3' #  CARRIAGE_RETURN_ICON $'\u21B5' # ↵ ROOT_ICON $'\uE614 ' #  + SUDO_ICON $'\uE0A2' #  RUBY_ICON $'\uF219 ' #  AWS_ICON $'\uF270' #  AWS_EB_ICON $'\UF1BD ' #  @@ -332,6 +333,7 @@ case $POWERLEVEL9K_MODE in RIGHT_SUBSEGMENT_SEPARATOR $'\uE0B3' #  CARRIAGE_RETURN_ICON $'\u21B5' # ↵ ROOT_ICON $'\u26A1' # ⚡ + SUDO_ICON $'\uE0A2' #  RUBY_ICON '' AWS_ICON 'AWS:' AWS_EB_ICON $'\U1F331 ' # 🌱 diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index bce893fe..2267ce64 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -638,7 +638,7 @@ prompt_user() { "CONTENT" "${POWERLEVEL9K_USER_TEMPLATE}" "BACKGROUND_COLOR" "${DEFAULT_COLOR}" "FOREGROUND_COLOR" "yellow" - "VISUAL_IDENTIFIER" "ROOT_ICON" + "VISUAL_IDENTIFIER" "SUDO_ICON" ) else user_state=( From 7fff5bd7a6c7c6d38c5984a1fa30571e89d14d1e Mon Sep 17 00:00:00 2001 From: Michael Louwrens Date: Mon, 12 Feb 2018 11:28:00 +0200 Subject: [PATCH 5/6] add new icons and add remote_sudo --- functions/icons.zsh | 5 ++++- powerlevel9k.zsh-theme | 15 ++++++++++----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/functions/icons.zsh b/functions/icons.zsh index b29d0108..6000e108 100644 --- a/functions/icons.zsh +++ b/functions/icons.zsh @@ -27,6 +27,7 @@ case $POWERLEVEL9K_MODE in RIGHT_SUBSEGMENT_SEPARATOR $'\uE0B3' #  CARRIAGE_RETURN_ICON $'\u21B5' # ↵ ROOT_ICON $'\uE801' #  + SUDO_ICON $'\uF09C' #  RUBY_ICON $'\uE847 ' #  AWS_ICON $'\uE895' #  AWS_EB_ICON $'\U1F331 ' # 🌱 @@ -105,6 +106,7 @@ case $POWERLEVEL9K_MODE in RIGHT_SUBSEGMENT_SEPARATOR $'\uE0B3' #  CARRIAGE_RETURN_ICON $'\u21B5' # ↵ ROOT_ICON $'\uF201' #  + SUDO_ICON $'\uF09C' #  RUBY_ICON $'\uF219 ' #  AWS_ICON $'\uF270' #  AWS_EB_ICON $'\U1F331 ' # 🌱 @@ -188,6 +190,7 @@ case $POWERLEVEL9K_MODE in RIGHT_SUBSEGMENT_SEPARATOR $'\uE0B3' #  CARRIAGE_RETURN_ICON $'\u21B5' # ↵ ROOT_ICON '\u'$CODEPOINT_OF_OCTICONS_ZAP #  + SUDO_ICON '\u'$CODEPOINT_OF_AWESOME_UNLOCK #  RUBY_ICON '\u'$CODEPOINT_OF_OCTICONS_RUBY' ' #  AWS_ICON '\u'$CODEPOINT_OF_AWESOME_SERVER #  AWS_EB_ICON $'\U1F331 ' # 🌱 @@ -258,7 +261,7 @@ case $POWERLEVEL9K_MODE in RIGHT_SUBSEGMENT_SEPARATOR $'\uE0B3' #  CARRIAGE_RETURN_ICON $'\u21B5' # ↵ ROOT_ICON $'\uE614 ' #  - SUDO_ICON $'\uE0A2' #  + SUDO_ICON $'\uF09C' #  RUBY_ICON $'\uF219 ' #  AWS_ICON $'\uF270' #  AWS_EB_ICON $'\UF1BD ' #  diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 2267ce64..8eb13bde 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -589,10 +589,11 @@ prompt_context() { local current_state="DEFAULT" typeset -AH context_states context_states=( - "ROOT" "yellow" - "SUDO" "yellow" - "DEFAULT" "yellow" - "REMOTE" "yellow" + "ROOT" "yellow" + "SUDO" "yellow" + "DEFAULT" "yellow" + "REMOTE" "yellow" + "REMOTE_SUDO" "yellow" ) local content="" @@ -608,7 +609,11 @@ prompt_context() { if [[ $(print -P "%#") == '#' ]]; then current_state="ROOT" elif [[ -n "$SSH_CLIENT" || -n "$SSH_TTY" ]]; then - current_state="REMOTE" + if sudo -n true 2>/dev/null; then + current_state="REMOTE_SUDO" + else + current_state="REMOTE" + fi elif sudo -n true 2>/dev/null; then current_state="SUDO" fi From a4aacef7bc9663604682ab1afd5e76ef751d546e Mon Sep 17 00:00:00 2001 From: Michael Louwrens Date: Mon, 12 Feb 2018 11:39:53 +0200 Subject: [PATCH 6/6] Add information to readme --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 74edc446..4fb6614a 100644 --- a/README.md +++ b/README.md @@ -312,7 +312,7 @@ main theme distribution so that everyone can use it! The `context` segment (user@host string) is conditional. By default, it will only print if you are not your 'normal' user (including if you are root), or if -you are SSH'd to a remote host. +you are SSH'd to a remote host. `SUDO` and `REMOTE_SUDO` states are also available to show whether the current user or remote user has superuser privileges. To use this feature, make sure the `context` segment is enabled in your prompt elements (it is by default), and define a `DEFAULT_USER` in your `~/.zshrc`. @@ -580,6 +580,7 @@ You can also override the icons by setting: ``` POWERLEVEL9K_USER_ICON="\uF415" #  POWERLEVEL9K_ROOT_ICON="#" +POWERLEVEL9K_SUDO_ICON=$'\uF09C' #  ``` | Variable | Default Value | Description |