Merge pull request #729 from Mikewl/usersudo

Added sudo state to prompt_user
This commit is contained in:
Ben Hilburn 2018-03-06 21:18:05 -05:00 committed by GitHub
commit cfbbd213cb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 5 deletions

View File

@ -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 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 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 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`. elements (it is by default), and define a `DEFAULT_USER` in your `~/.zshrc`.
@ -581,6 +581,7 @@ You can also override the icons by setting:
``` ```
POWERLEVEL9K_USER_ICON="\uF415" #  POWERLEVEL9K_USER_ICON="\uF415" # 
POWERLEVEL9K_ROOT_ICON="#" POWERLEVEL9K_ROOT_ICON="#"
POWERLEVEL9K_SUDO_ICON=$'\uF09C' # 
``` ```
| Variable | Default Value | Description | | Variable | Default Value | Description |

View File

@ -27,6 +27,7 @@ case $POWERLEVEL9K_MODE in
RIGHT_SUBSEGMENT_SEPARATOR $'\uE0B3' #  RIGHT_SUBSEGMENT_SEPARATOR $'\uE0B3' # 
CARRIAGE_RETURN_ICON $'\u21B5' # ↵ CARRIAGE_RETURN_ICON $'\u21B5' # ↵
ROOT_ICON $'\uE801' #  ROOT_ICON $'\uE801' # 
SUDO_ICON $'\uF09C' # 
RUBY_ICON $'\uE847 ' #  RUBY_ICON $'\uE847 ' # 
AWS_ICON $'\uE895' #  AWS_ICON $'\uE895' # 
AWS_EB_ICON $'\U1F331 ' # 🌱 AWS_EB_ICON $'\U1F331 ' # 🌱
@ -118,6 +119,7 @@ case $POWERLEVEL9K_MODE in
RIGHT_SUBSEGMENT_SEPARATOR $'\uE0B3' #  RIGHT_SUBSEGMENT_SEPARATOR $'\uE0B3' # 
CARRIAGE_RETURN_ICON $'\u21B5' # ↵ CARRIAGE_RETURN_ICON $'\u21B5' # ↵
ROOT_ICON $'\uF201' #  ROOT_ICON $'\uF201' # 
SUDO_ICON $'\uF09C' # 
RUBY_ICON $'\uF219 ' #  RUBY_ICON $'\uF219 ' # 
AWS_ICON $'\uF270' #  AWS_ICON $'\uF270' # 
AWS_EB_ICON $'\U1F331 ' # 🌱 AWS_EB_ICON $'\U1F331 ' # 🌱
@ -214,6 +216,7 @@ case $POWERLEVEL9K_MODE in
RIGHT_SUBSEGMENT_SEPARATOR $'\uE0B3' #  RIGHT_SUBSEGMENT_SEPARATOR $'\uE0B3' # 
CARRIAGE_RETURN_ICON $'\u21B5' # ↵ CARRIAGE_RETURN_ICON $'\u21B5' # ↵
ROOT_ICON '\u'$CODEPOINT_OF_OCTICONS_ZAP #  ROOT_ICON '\u'$CODEPOINT_OF_OCTICONS_ZAP # 
SUDO_ICON '\u'$CODEPOINT_OF_AWESOME_UNLOCK # 
RUBY_ICON '\u'$CODEPOINT_OF_OCTICONS_RUBY' ' #  RUBY_ICON '\u'$CODEPOINT_OF_OCTICONS_RUBY' ' # 
AWS_ICON '\u'$CODEPOINT_OF_AWESOME_SERVER #  AWS_ICON '\u'$CODEPOINT_OF_AWESOME_SERVER # 
AWS_EB_ICON $'\U1F331 ' # 🌱 AWS_EB_ICON $'\U1F331 ' # 🌱
@ -298,6 +301,7 @@ case $POWERLEVEL9K_MODE in
RIGHT_SUBSEGMENT_SEPARATOR $'\uE0B3' #  RIGHT_SUBSEGMENT_SEPARATOR $'\uE0B3' # 
CARRIAGE_RETURN_ICON $'\u21B5' # ↵ CARRIAGE_RETURN_ICON $'\u21B5' # ↵
ROOT_ICON $'\uE614 ' #  ROOT_ICON $'\uE614 ' # 
SUDO_ICON $'\uF09C' # 
RUBY_ICON $'\uF219 ' #  RUBY_ICON $'\uF219 ' # 
AWS_ICON $'\uF270' #  AWS_ICON $'\uF270' # 
AWS_EB_ICON $'\UF1BD ' #  AWS_EB_ICON $'\UF1BD ' # 
@ -385,6 +389,7 @@ case $POWERLEVEL9K_MODE in
RIGHT_SUBSEGMENT_SEPARATOR $'\uE0B3' #  RIGHT_SUBSEGMENT_SEPARATOR $'\uE0B3' # 
CARRIAGE_RETURN_ICON $'\u21B5' # ↵ CARRIAGE_RETURN_ICON $'\u21B5' # ↵
ROOT_ICON $'\u26A1' # ⚡ ROOT_ICON $'\u26A1' # ⚡
SUDO_ICON $'\uE0A2' # 
RUBY_ICON '' RUBY_ICON ''
AWS_ICON 'AWS:' AWS_ICON 'AWS:'
AWS_EB_ICON $'\U1F331 ' # 🌱 AWS_EB_ICON $'\U1F331 ' # 🌱

View File

@ -589,9 +589,11 @@ prompt_context() {
local current_state="DEFAULT" local current_state="DEFAULT"
typeset -AH context_states typeset -AH context_states
context_states=( context_states=(
"ROOT" "yellow" "ROOT" "yellow"
"DEFAULT" "yellow" "SUDO" "yellow"
"REMOTE" "yellow" "DEFAULT" "yellow"
"REMOTE" "yellow"
"REMOTE_SUDO" "yellow"
) )
local content="" local content=""
@ -607,7 +609,13 @@ prompt_context() {
if [[ $(print -P "%#") == '#' ]]; then if [[ $(print -P "%#") == '#' ]]; then
current_state="ROOT" current_state="ROOT"
elif [[ -n "$SSH_CLIENT" || -n "$SSH_TTY" ]]; then 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 fi
"$1_prompt_segment" "${0}_${current_state}" "$2" "$DEFAULT_COLOR" "${context_states[$current_state]}" "${content}" "$1_prompt_segment" "${0}_${current_state}" "$2" "$DEFAULT_COLOR" "${context_states[$current_state]}" "${content}"
@ -629,6 +637,14 @@ prompt_user() {
"FOREGROUND_COLOR" "yellow" "FOREGROUND_COLOR" "yellow"
"VISUAL_IDENTIFIER" "ROOT_ICON" "VISUAL_IDENTIFIER" "ROOT_ICON"
) )
elif sudo -n true 2>/dev/null; then
user_state=(
"STATE" "SUDO"
"CONTENT" "${POWERLEVEL9K_USER_TEMPLATE}"
"BACKGROUND_COLOR" "${DEFAULT_COLOR}"
"FOREGROUND_COLOR" "yellow"
"VISUAL_IDENTIFIER" "SUDO_ICON"
)
else else
user_state=( user_state=(
"STATE" "DEFAULT" "STATE" "DEFAULT"