Merge pull request #729 from Mikewl/usersudo

Added sudo state to prompt_user
pull/22/head
Ben Hilburn 7 years ago committed by GitHub
commit cfbbd213cb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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`.
@ -581,6 +581,7 @@ You can also override the icons by setting:
```
POWERLEVEL9K_USER_ICON="\uF415" # 
POWERLEVEL9K_ROOT_ICON="#"
POWERLEVEL9K_SUDO_ICON=$'\uF09C' # 
```
| Variable | Default Value | Description |

@ -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 ' # 🌱
@ -118,6 +119,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 ' # 🌱
@ -214,6 +216,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 ' # 🌱
@ -298,6 +301,7 @@ case $POWERLEVEL9K_MODE in
RIGHT_SUBSEGMENT_SEPARATOR $'\uE0B3' # 
CARRIAGE_RETURN_ICON $'\u21B5' # ↵
ROOT_ICON $'\uE614 ' # 
SUDO_ICON $'\uF09C' # 
RUBY_ICON $'\uF219 ' # 
AWS_ICON $'\uF270' # 
AWS_EB_ICON $'\UF1BD ' # 
@ -385,6 +389,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 ' # 🌱

@ -590,8 +590,10 @@ prompt_context() {
typeset -AH context_states
context_states=(
"ROOT" "yellow"
"SUDO" "yellow"
"DEFAULT" "yellow"
"REMOTE" "yellow"
"REMOTE_SUDO" "yellow"
)
local content=""
@ -607,8 +609,14 @@ prompt_context() {
if [[ $(print -P "%#") == '#' ]]; then
current_state="ROOT"
elif [[ -n "$SSH_CLIENT" || -n "$SSH_TTY" ]]; then
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
"$1_prompt_segment" "${0}_${current_state}" "$2" "$DEFAULT_COLOR" "${context_states[$current_state]}" "${content}"
}
@ -629,6 +637,14 @@ prompt_user() {
"FOREGROUND_COLOR" "yellow"
"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
user_state=(
"STATE" "DEFAULT"

Loading…
Cancel
Save