From 981eb1a6320ef5381a5f20e1450b12d53d2a5e5a Mon Sep 17 00:00:00 2001 From: Florian Meinicke Date: Mon, 21 Oct 2019 18:51:56 +0200 Subject: [PATCH 1/3] Add option to display sudo-username. --- README.md | 1 + fish_prompt.fish | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 43ed9e4..05a22de 100644 --- a/README.md +++ b/README.md @@ -123,6 +123,7 @@ set -g theme_newline_prompt '$ ' - `theme_display_k8s_context`. This feature is disabled by default. Use `yes` to show the current kubernetes context (`> kubectl config current-context`). - `theme_display_user`. If set to `yes`, display username always, if set to `ssh`, only when an SSH-Session is detected, if set to no, never. - `theme_display_hostname`. Same behaviour as `theme_display_user`. +- `theme_display_sudo_user`. If set to `yes`, displays the sudo-username in a root shell. For example, when calling `sudo -s` and having this option set to `yes`, the username of the user, who called `sudo -s`, will be displayed. - `theme_show_exit_status`. Set this option to `yes` to have the prompt show the last exit code if it was non_zero instead of just the exclamation mark. - `theme_display_jobs_verbose`. If set to `yes` this option displays the number of currently running background jobs next to the percent sign. - `theme_git_worktree_support`. If you do any git worktree shenanigans, setting this to `yes` will fix incorrect project-relative path display. If you don't do any git worktree shenanigans, leave it disabled. It's faster this way :) diff --git a/fish_prompt.fish b/fish_prompt.fish index 9659c74..25713b1 100644 --- a/fish_prompt.fish +++ b/fish_prompt.fish @@ -33,6 +33,7 @@ # set -g theme_display_ruby no # set -g theme_display_user ssh # set -g theme_display_hostname ssh +# set -g theme_display_sudo_user yes # set -g theme_display_vi no # set -g theme_display_nvm yes # set -g theme_avoid_ambiguous_glyphs yes @@ -654,9 +655,12 @@ if not type -q prompt_hostname end function __bobthefish_prompt_user -S -d 'Display current user and hostname' - [ "$theme_display_user" = 'yes' -o \( "$theme_display_user" != 'no' -a -n "$SSH_CLIENT" \) -o \( -n "$default_user" -a "$USER" != "$default_user" \) -o -n "$SUDO_USER" ] + [ "$theme_display_user" = 'yes' -o \( "$theme_display_user" != 'no' -a -n "$SSH_CLIENT" \) -o \( -n "$default_user" -a "$USER" != "$default_user" \) ] and set -l display_user + [ "$theme_display_sudo_user" = 'yes' -a -n "$SUDO_USER" ] + and set -l display_sudo_user + [ "$theme_display_hostname" = 'yes' -o \( "$theme_display_hostname" != 'no' -a -n "$SSH_CLIENT" \) ] and set -l display_hostname @@ -665,6 +669,15 @@ function __bobthefish_prompt_user -S -d 'Display current user and hostname' echo -ns (whoami) end + if set -q display_sudo_user + if set -q display_user + echo -ns ' ' + else + __bobthefish_start_segment $color_username + end + echo -ns "($SUDO_USER)" + end + if set -q display_hostname if set -q display_user # reset colors without starting a new segment... From 108b6a45f64047fbfaa837047d85288c20eb3dc6 Mon Sep 17 00:00:00 2001 From: Florian Meinicke Date: Sun, 27 Oct 2019 10:20:59 +0100 Subject: [PATCH 2/3] Update condition for showing an extra space --- fish_prompt.fish | 1 + 1 file changed, 1 insertion(+) diff --git a/fish_prompt.fish b/fish_prompt.fish index 25713b1..309f3c7 100644 --- a/fish_prompt.fish +++ b/fish_prompt.fish @@ -692,6 +692,7 @@ function __bobthefish_prompt_user -S -d 'Display current user and hostname' end set -q display_user + or set -q display_sudo_user or set -q display_hostname and echo -ns ' ' end From 5902e1a49d64d7813228ed216c8b57c47eca82df Mon Sep 17 00:00:00 2001 From: Florian Meinicke Date: Sun, 27 Oct 2019 19:28:55 +0100 Subject: [PATCH 3/3] Don't start a new segment if either `display_user' or `display_sudo_user' is set --- fish_prompt.fish | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fish_prompt.fish b/fish_prompt.fish index 309f3c7..0a8f379 100644 --- a/fish_prompt.fish +++ b/fish_prompt.fish @@ -679,7 +679,7 @@ function __bobthefish_prompt_user -S -d 'Display current user and hostname' end if set -q display_hostname - if set -q display_user + if set -q display_user; or set -q display_sudo_user # reset colors without starting a new segment... # (so we can have a bold username and non-bold hostname) set_color normal