mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-05-30 11:21:15 -03:00
Add a function to check if the user is root.
Add a helper function to check if the user is root. This function can be useful for the prompts for example. Modify the prompts made root checked to use the function instead. Add also the support of Administrator like a root user. Fixes: #7031
This commit is contained in:
committed by
Fabian Homborg
parent
de9e8cb897
commit
e2f03fa8a7
@@ -2,17 +2,18 @@
|
||||
function fish_prompt --description "Write out the prompt"
|
||||
set -l color_cwd
|
||||
set -l suffix
|
||||
switch "$USER"
|
||||
case root toor
|
||||
if set -q fish_color_cwd_root
|
||||
set color_cwd $fish_color_cwd_root
|
||||
else
|
||||
set color_cwd $fish_color_cwd
|
||||
end
|
||||
set suffix '#'
|
||||
case '*'
|
||||
|
||||
if fish_is_root_user
|
||||
if set -q fish_color_cwd_root
|
||||
set color_cwd $fish_color_cwd_root
|
||||
else
|
||||
set color_cwd $fish_color_cwd
|
||||
set suffix '>'
|
||||
end
|
||||
|
||||
set suffix '#'
|
||||
else
|
||||
set color_cwd $fish_color_cwd
|
||||
set suffix '>'
|
||||
end
|
||||
|
||||
echo -n -s "$USER" @ (prompt_hostname) ' ' (set_color $color_cwd) (prompt_pwd) (set_color normal) "$suffix "
|
||||
|
||||
@@ -8,17 +8,18 @@ function fish_prompt --description "Write out the prompt"
|
||||
|
||||
set -l color_cwd
|
||||
set -l suffix
|
||||
switch "$USER"
|
||||
case root toor
|
||||
if set -q fish_color_cwd_root
|
||||
set color_cwd $fish_color_cwd_root
|
||||
else
|
||||
set color_cwd $fish_color_cwd
|
||||
end
|
||||
set suffix '#'
|
||||
case '*'
|
||||
|
||||
if fish_is_root_user
|
||||
if set -q fish_color_cwd_root
|
||||
set color_cwd $fish_color_cwd_root
|
||||
else
|
||||
set color_cwd $fish_color_cwd
|
||||
set suffix '>'
|
||||
end
|
||||
|
||||
set suffix '#'
|
||||
else
|
||||
set color_cwd $fish_color_cwd
|
||||
set suffix '>'
|
||||
end
|
||||
|
||||
echo -n -s "$USER" @ (prompt_hostname) ' ' (set_color $color_cwd) (prompt_pwd) \
|
||||
|
||||
@@ -9,7 +9,7 @@ function fish_prompt --description 'Write out the prompt'
|
||||
# Color the prompt differently when we're root
|
||||
set -l color_cwd $fish_color_cwd
|
||||
set -l suffix '>'
|
||||
if contains -- $USER root toor
|
||||
if fish_is_root_user
|
||||
if set -q fish_color_cwd_root
|
||||
set color_cwd $fish_color_cwd_root
|
||||
end
|
||||
|
||||
@@ -4,10 +4,12 @@
|
||||
function fish_prompt --description 'Write out the prompt, prepending the Debian chroot environment if present'
|
||||
# Set variable identifying the chroot you work in (used in the prompt below)
|
||||
set -l debian_chroot $debian_chroot
|
||||
|
||||
if not set -q debian_chroot[1]
|
||||
and test -r /etc/debian_chroot
|
||||
set debian_chroot (cat /etc/debian_chroot)
|
||||
end
|
||||
|
||||
if not set -q __fish_debian_chroot_prompt
|
||||
and set -q debian_chroot[1]
|
||||
and test -n "$debian_chroot"
|
||||
@@ -19,16 +21,15 @@ function fish_prompt --description 'Write out the prompt, prepending the Debian
|
||||
echo -n -s (set_color yellow) "$__fish_debian_chroot_prompt" (set_color normal) ' '
|
||||
end
|
||||
|
||||
switch "$USER"
|
||||
case root toor
|
||||
echo -n -s "$USER" @ (prompt_hostname) ' ' (set -q fish_color_cwd_root
|
||||
and set_color $fish_color_cwd_root
|
||||
or set_color $fish_color_cwd) (prompt_pwd) \
|
||||
(set_color normal) '# '
|
||||
if fish_is_root_user
|
||||
echo -n -s "$USER" @ (prompt_hostname) ' ' (set -q fish_color_cwd_root
|
||||
and set_color $fish_color_cwd_root
|
||||
or set_color $fish_color_cwd) (prompt_pwd) \
|
||||
(set_color normal) '# '
|
||||
|
||||
case '*'
|
||||
echo -n -s "$USER" @ (prompt_hostname) ' ' (set_color $fish_color_cwd) (prompt_pwd) \
|
||||
(set_color normal) '> '
|
||||
else
|
||||
echo -n -s "$USER" @ (prompt_hostname) ' ' (set_color $fish_color_cwd) (prompt_pwd) \
|
||||
(set_color normal) '> '
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
@@ -6,18 +6,17 @@ function fish_prompt --description 'Informative prompt'
|
||||
set -l last_pipestatus $pipestatus
|
||||
set -l last_status $status
|
||||
|
||||
switch "$USER"
|
||||
case root toor
|
||||
printf '%s@%s %s%s%s# ' $USER (prompt_hostname) (set -q fish_color_cwd_root
|
||||
and set_color $fish_color_cwd_root
|
||||
or set_color $fish_color_cwd) \
|
||||
(prompt_pwd) (set_color normal)
|
||||
case '*'
|
||||
set -l pipestatus_string (__fish_print_pipestatus $last_status "[" "] " "|" (set_color $fish_color_status) \
|
||||
(set_color --bold $fish_color_status) $last_pipestatus)
|
||||
if fish_is_root_user
|
||||
printf '%s@%s %s%s%s# ' $USER (prompt_hostname) (set -q fish_color_cwd_root
|
||||
and set_color $fish_color_cwd_root
|
||||
or set_color $fish_color_cwd) \
|
||||
(prompt_pwd) (set_color normal)
|
||||
else
|
||||
set -l pipestatus_string (__fish_print_pipestatus $last_status "[" "] " "|" (set_color $fish_color_status) \
|
||||
(set_color --bold $fish_color_status) $last_pipestatus)
|
||||
|
||||
printf '[%s] %s%s@%s %s%s %s%s%s \f\r> ' (date "+%H:%M:%S") (set_color brblue) \
|
||||
$USER (prompt_hostname) (set_color $fish_color_cwd) $PWD $pipestatus_string \
|
||||
(set_color normal)
|
||||
printf '[%s] %s%s@%s %s%s %s%s%s \f\r> ' (date "+%H:%M:%S") (set_color brblue) \
|
||||
$USER (prompt_hostname) (set_color $fish_color_cwd) $PWD $pipestatus_string \
|
||||
(set_color normal)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -59,17 +59,16 @@ function fish_prompt --description 'Write out the prompt'
|
||||
|
||||
set -l color_cwd
|
||||
set -l suffix
|
||||
switch "$USER"
|
||||
case root toor
|
||||
if set -q fish_color_cwd_root
|
||||
set color_cwd $fish_color_cwd_root
|
||||
else
|
||||
set color_cwd $fish_color_cwd
|
||||
end
|
||||
set suffix '#'
|
||||
case '*'
|
||||
if fish_is_root_user
|
||||
if set -q fish_color_cwd_root
|
||||
set color_cwd $fish_color_cwd_root
|
||||
else
|
||||
set color_cwd $fish_color_cwd
|
||||
set suffix '$'
|
||||
end
|
||||
set suffix '#'
|
||||
else
|
||||
set color_cwd $fish_color_cwd
|
||||
set suffix '$'
|
||||
end
|
||||
|
||||
# PWD
|
||||
|
||||
@@ -20,8 +20,8 @@ function fish_prompt
|
||||
|
||||
# To:
|
||||
# ┬─[nim@Hattori:~/w/dashboard]─[11:37:14]─[V:django20]─[G:master↑1|●1✚1…1]─[B:85%, 05:41:42 remaining]
|
||||
# │ 2 15054 0% arrêtée sleep 100000
|
||||
# │ 1 15048 0% arrêtée sleep 100000
|
||||
# │ 2 15054 0% arrêtée sleep 100000
|
||||
# │ 1 15048 0% arrêtée sleep 100000
|
||||
# ╰─>$ echo there
|
||||
|
||||
set -l retc red
|
||||
@@ -53,19 +53,23 @@ function fish_prompt
|
||||
echo -n '┬─'
|
||||
set_color -o green
|
||||
echo -n [
|
||||
if test "$USER" = root -o "$USER" = toor
|
||||
|
||||
if fish_is_root_user
|
||||
set_color -o red
|
||||
else
|
||||
set_color -o yellow
|
||||
end
|
||||
|
||||
echo -n $USER
|
||||
set_color -o white
|
||||
echo -n @
|
||||
|
||||
if [ -z "$SSH_CLIENT" ]
|
||||
set_color -o blue
|
||||
else
|
||||
set_color -o cyan
|
||||
end
|
||||
|
||||
echo -n (prompt_hostname)
|
||||
set_color -o white
|
||||
echo -n :(prompt_pwd)
|
||||
@@ -79,6 +83,7 @@ function fish_prompt
|
||||
# The default mode prompt would be prefixed, which ruins our alignment.
|
||||
function fish_mode_prompt
|
||||
end
|
||||
|
||||
if test "$fish_key_bindings" = fish_vi_key_bindings
|
||||
or test "$fish_key_bindings" = fish_hybrid_key_bindings
|
||||
set -l mode
|
||||
@@ -121,12 +126,14 @@ function fish_prompt
|
||||
|
||||
# Background jobs
|
||||
set_color normal
|
||||
|
||||
for job in (jobs)
|
||||
set_color $retc
|
||||
echo -n '│ '
|
||||
set_color brown
|
||||
echo $job
|
||||
end
|
||||
|
||||
set_color normal
|
||||
set_color $retc
|
||||
echo -n '╰─>'
|
||||
|
||||
Reference in New Issue
Block a user