Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add OS type detection and custom coloring for root user #227

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 79 additions & 3 deletions fish_prompt.fish
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,61 @@ end
# Status segment
# ==============================

function __bobthefish_prompt_currentos -S -d 'Display current OS version'
[ "$theme_display_currentos" = 'yes' ]
and set -l display_currentos

if set -q display_currentos

if ! set -q __bobthefish_os_type
if uname | grep -qi Darwin
set -gx __bobthefish_os_type "$os_type_darwin"
else if test -f /etc/synoinfo.conf
set -gx __bobthefish_os_type "$os_type_synology"
else if test -f /etc/linuxmint/info
set -gx __bobthefish_os_type "$os_type_mint"
else if test -f /etc/SuSE-release
set -gx __bobthefish_os_type "$os_type_suse"
else if test -f /etc/centos-release
set -gx __bobthefish_os_type "$os_type_centos"
else if test -f /etc/fedora-release
set -gx __bobthefish_os_type "$os_type_fedora"
else if test -f /etc/redhat-release
set -gx __bobthefish_os_type "$os_type_redhat"
else if test -f /etc/gentoo-release
set -gx __bobthefish_os_type "$os_type_gentoo"
else if test -f /etc/arch-release
set -gx __bobthefish_os_type "$os_type_arch"
else if test -f /etc/alpine-release
set -gx __bobthefish_os_type "$os_type_alpine"
else if test -f /etc/lsb-release
if cat /etc/lsb-release | grep -qi Ubuntu
set -gx __bobthefish_os_type "$os_type_ubuntu"
else if cat /etc/lsb-release | grep -qi elementary
set -gx __bobthefish_os_type "$os_type_elementary"
else if test -f /etc/debian_version
set -gx __bobthefish_os_type "$os_type_debian"
else
set -gx __bobthefish_os_type="$os_type_generic"
end
else if test -f /etc/debian_version
set -gx __bobthefish_os_type "$os_type_debian"
else if test -f /etc/os-release
if cat /etc/os-release | grep -q "Amazon";
set -gx __bobthefish_os_type="$os_type_amazon"
else
set -gx __bobthefish_os_type="$os_type_coreos"
end
else
set -gx __bobthefish_os_type "$os_type_generic"
end
end

__bobthefish_start_segment $color_currentos
echo -ns "$__bobthefish_os_type "
end
end

function __bobthefish_prompt_status -S -a last_status -d 'Display flags for a non-zero exit status, root user, and background jobs'
set -l nonzero
set -l superuser
Expand Down Expand Up @@ -654,6 +709,12 @@ if not type -q prompt_hostname
end

function __bobthefish_prompt_user -S -d 'Display current user and hostname'
[ "$theme_display_ssh_keylock" = 'yes' ]; and begin ; [ -n "$SSH_CLIENT" ]; or [ -n "$SSH_TTY" ]; or [ -n "$SSH_CONNECTION" ]; or tty | fgrep pts > /dev/null ; end
and set -l display_ssh_keylock

[ "$theme_display_split_user_hostname" = 'yes' ]
and set -l split_user_hostname

[ "$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

Expand All @@ -664,29 +725,43 @@ function __bobthefish_prompt_user -S -d 'Display current user and hostname'
and set -l display_hostname

if set -q display_user
__bobthefish_start_segment $color_username
if test (id -u) -eq 0; and set -q color_root_username
__bobthefish_start_segment $color_root_username
else
__bobthefish_start_segment $color_username
end
if set -q display_ssh_keylock; and ! set -q split_user_hostname
echo -ns " "
end
echo -ns (whoami)
end

if set -q display_sudo_user
if set -q display_ssh_keylock; and ! set -q split_user_hostname; and ! set -q display_user
echo -ns " "
end
if set -q display_user
echo -ns ' '
else
__bobthefish_start_segment $color_username
end
echo -ns "($SUDO_USER)"
end
echo -ns ' '

if set -q display_hostname
if set -q display_user
or set -q display_sudo_user
#if begin ; set -q display_user or set -q display_sudo_user ; end ; and ! set -q split_user_hostname
if ! set -q split_user_hostname ; and begin ; set -q display_user ; or set -q display_sudo_user ; end
# reset colors without starting a new segment...
# (so we can have a bold username and non-bold hostname)
set_color normal
set_color -b $color_hostname[1] $color_hostname[2..-1]
echo -ns '@' (prompt_hostname)
else
__bobthefish_start_segment $color_hostname
if set -q display_ssh_keylock
echo -ns " "
end
echo -ns (prompt_hostname)
end
end
Expand Down Expand Up @@ -1060,6 +1135,7 @@ function fish_prompt -d 'bobthefish, a fish theme optimized for awesome'
set -l __bobthefish_current_bg

# Status flags and input mode
__bobthefish_prompt_currentos
__bobthefish_prompt_status $last_status

# User / hostname info
Expand Down
29 changes: 28 additions & 1 deletion functions/__bobthefish_colors.fish
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,17 @@ function __bobthefish_colors -S -a color_scheme -d 'Define colors used by bobthe
set -x color_vagrant brcyan $colorfg
set -x color_k8s magenta white --bold
set -x color_username white black --bold
set -x color_root_username red white --bold
set -x color_hostname white black
set -x color_rvm brmagenta $colorfg --bold
set -x color_nvm brgreen $colorfg --bold
set -x color_virtualfish brblue $colorfg --bold
set -x color_virtualgo brblue $colorfg --bold
set -x color_desk brblue $colorfg --bold
set -x color_currentos green $colorfg --bold
set -x color_nix brblue $colorfg --bold

case 'terminal-light*'
case 'terminal-light*'
set -l colorfg white
[ "$color_scheme" = 'terminal-light-black' ]; and set colorfg black
set -x color_initial_segment_exit black red --bold
Expand All @@ -60,12 +62,14 @@ function __bobthefish_colors -S -a color_scheme -d 'Define colors used by bobthe
set -x color_vagrant brcyan $colorfg
set -x color_k8s magenta white --bold
set -x color_username black white --bold
set -x color_root_username red white --bold
set -x color_hostname black white
set -x color_rvm brmagenta $colorfg --bold
set -x color_nvm brgreen $colorfg --bold
set -x color_virtualfish brblue $colorfg --bold
set -x color_virtualgo brblue $colorfg --bold
set -x color_desk brblue $colorfg --bold
set -x color_currentos green $colorfg --bold
set -x color_nix brblue $colorfg --bold

case 'terminal2' 'terminal2-dark*'
Expand All @@ -92,12 +96,14 @@ function __bobthefish_colors -S -a color_scheme -d 'Define colors used by bobthe
set -x color_vagrant brcyan $colorfg
set -x color_k8s magenta white --bold
set -x color_username brgrey white --bold
set -x color_root_username red white --bold
set -x color_hostname brgrey white
set -x color_rvm brmagenta $colorfg --bold
set -x color_nvm brgreen $colorfg --bold
set -x color_virtualfish brblue $colorfg --bold
set -x color_virtualgo brblue $colorfg --bold
set -x color_desk brblue $colorfg --bold
set -x color_currentos green $colorfg --bold
set -x color_nix brblue $colorfg --bold

case 'terminal2-light*'
Expand All @@ -124,12 +130,14 @@ function __bobthefish_colors -S -a color_scheme -d 'Define colors used by bobthe
set -x color_vagrant brcyan $colorfg
set -x color_k8s magenta white --bold
set -x color_username grey black --bold
set -x color_root_username red black --bold
set -x color_hostname grey black
set -x color_rvm brmagenta $colorfg --bold
set -x color_nvm brgreen $colorfg --bold
set -x color_virtualfish brblue $colorfg --bold
set -x color_virtualgo brblue $colorfg --bold
set -x color_desk brblue $colorfg --bold
set -x color_currentos green $colorfg --bold
set -x color_nix brblue $colorfg --bold

case 'zenburn'
Expand Down Expand Up @@ -162,12 +170,14 @@ function __bobthefish_colors -S -a color_scheme -d 'Define colors used by bobthe
set -x color_vagrant $blue $green --bold
set -x color_k8s $green $white --bold
set -x color_username $grey $blue --bold
set -x color_root_username $gray $red --bold
set -x color_hostname $grey $blue
set -x color_rvm $red $grey --bold
set -x color_nvm $green $white --bold
set -x color_virtualfish $blue $grey --bold
set -x color_virtualgo $blue $grey --bold
set -x color_desk $blue $grey --bold
set -x color_currentos $green $white --bold
set -x color_nix $blue $grey --bold

case 'base16-light'
Expand Down Expand Up @@ -211,12 +221,14 @@ function __bobthefish_colors -S -a color_scheme -d 'Define colors used by bobthe
set -x color_vagrant $base0C $colorfg --bold
set -x color_k8s $base06 $colorfg --bold
set -x color_username $base02 $base0D --bold
set -x color_root_username $base08 $base0D --bold
set -x color_hostname $base02 $base0D
set -x color_rvm $base08 $colorfg --bold
set -x color_nvm $base0B $colorfg --bold
set -x color_virtualfish $base0D $colorfg --bold
set -x color_virtualgo $base0D $colorfg --bold
set -x color_desk $base0D $colorfg --bold
set -x color_currentos $base0B $colorfg --bold
set -x color_nix $base0D $colorfg --bold

case 'base16' 'base16-dark'
Expand Down Expand Up @@ -260,12 +272,14 @@ function __bobthefish_colors -S -a color_scheme -d 'Define colors used by bobthe
set -x color_vagrant $base0C $colorfg --bold
set -x color_k8s $base0B $colorfg --bold
set -x color_username $base02 $base0D --bold
set -x color_root_username $base08 $base0D --bold
set -x color_hostname $base02 $base0D
set -x color_rvm $base08 $colorfg --bold
set -x color_nvm $base0B $colorfg --bold
set -x color_virtualfish $base0D $colorfg --bold
set -x color_virtualgo $base0D $colorfg --bold
set -x color_desk $base0D $colorfg --bold
set -x color_currentos $base0B $colorfg --bold
set -x color_nix $base0D $colorfg --bold

case 'solarized-light'
Expand Down Expand Up @@ -309,12 +323,14 @@ function __bobthefish_colors -S -a color_scheme -d 'Define colors used by bobthe
set -x color_vagrant $violet $colorfg --bold
set -x color_k8s $green $colorfg --bold
set -x color_username $base2 $blue --bold
set -x color_root_username $base2 $red --bold
set -x color_hostname $base2 $blue
set -x color_rvm $red $colorfg --bold
set -x color_nvm $green $colorfg --bold
set -x color_virtualfish $cyan $colorfg --bold
set -x color_virtualgo $cyan $colorfg --bold
set -x color_desk $cyan $colorfg --bold
set -x color_currentos $green $colorfg --bold
set -x color_nix $cyan $colorfg --bold

case 'solarized' 'solarized-dark'
Expand Down Expand Up @@ -358,12 +374,14 @@ function __bobthefish_colors -S -a color_scheme -d 'Define colors used by bobthe
set -x color_vagrant $violet $colorfg --bold
set -x color_k8s $green $colorfg --bold
set -x color_username $base02 $blue --bold
set -x color_root_username $base2 $red --bold
set -x color_hostname $base02 $blue
set -x color_rvm $red $colorfg --bold
set -x color_nvm $green $colorfg --bold
set -x color_virtualfish $cyan $colorfg --bold
set -x color_virtualgo $cyan $colorfg --bold
set -x color_desk $cyan $colorfg --bold
set -x color_currentos $green $colorfg --bold
set -x color_nix $cyan $colorfg --bold

case 'light'
Expand Down Expand Up @@ -400,12 +418,14 @@ function __bobthefish_colors -S -a color_scheme -d 'Define colors used by bobthe
set -x color_vagrant $blue[1] $white --bold
set -x color_k8s $green[1] $colorfg --bold
set -x color_username $grey[1] $blue[3] --bold
set -x color_root_username $grey[1] $red --bold
set -x color_hostname $grey[1] $blue[3]
set -x color_rvm $ruby_red $grey[1] --bold
set -x color_nvm $green $grey[1] --bold
set -x color_virtualfish $blue[2] $grey[1] --bold
set -x color_virtualgo $blue[2] $grey[1] --bold
set -x color_desk $blue[2] $grey[1] --bold
set -x color_currentos $green $colorfg --bold
set -x color_nix $blue[2] $grey[1] --bold

case 'gruvbox'
Expand Down Expand Up @@ -441,12 +461,14 @@ function __bobthefish_colors -S -a color_scheme -d 'Define colors used by bobthe
set -x color_vagrant $blue[2] $fg[2] --bold
set -x color_k8s $green[2] $fg[2] --bold
set -x color_username $fg[3] $blue[2] --bold
set -x color_root_username $fg[3] $red --bold
set -x color_hostname $fg[3] $blue[2]
set -x color_rvm $red[2] $fg[2] --bold
set -x color_nvm $green[1] $fg[2] --bold
set -x color_virtualfish $blue[2] $fg[2] --bold
set -x color_virtualgo $blue[2] $fg[2] --bold
set -x color_desk $blue[2] $fg[2] --bold
set -x color_currentos $green $colorfg --bold
set -x color_nix $blue[2] $fg[2] --bold

case 'dracula' # https://draculatheme.com
Expand Down Expand Up @@ -484,12 +506,14 @@ function __bobthefish_colors -S -a color_scheme -d 'Define colors used by bobthe
set -x color_vagrant $pink $bg --bold
set -x color_k8s $green $fg --bold
set -x color_username $selection $cyan --bold
set -x color_root_username $selection $red --bold
set -x color_hostname $selection $cyan
set -x color_rvm $red $bg --bold
set -x color_nvm $green $bg --bold
set -x color_virtualfish $comment $bg --bold
set -x color_virtualgo $cyan $bg --bold
set -x color_desk $comment $bg --bold
set -x color_currentos $green $bg --bold
set -x color_nix $cyan $bg --bold

case 'nord'
Expand Down Expand Up @@ -539,6 +563,7 @@ function __bobthefish_colors -S -a color_scheme -d 'Define colors used by bobthe
set -x color_virtualfish $base09 $colorfg --bold
set -x color_virtualgo $base09 $colorfg --bold
set -x color_desk $base09 $colorfg --bold
set -x color_currentos $base09 $colorfg --bold

case '*' # default dark theme
# light medium dark
Expand Down Expand Up @@ -575,12 +600,14 @@ function __bobthefish_colors -S -a color_scheme -d 'Define colors used by bobthe
set -x color_vagrant $blue[1] $white --bold
set -x color_k8s $green[2] $white --bold
set -x color_username $grey[1] $blue[3] --bold
set -x color_root_username $grey[1] $red[1] --bold
set -x color_hostname $grey[1] $blue[3]
set -x color_rvm $ruby_red $grey[1] --bold
set -x color_nvm $green[1] $white --bold
set -x color_virtualfish $blue[2] $grey[1] --bold
set -x color_virtualgo $go_blue $black --bold
set -x color_desk $blue[2] $grey[1] --bold
set -x color_currentos $green $white --bold
set -x color_nix $blue[2] $grey[1] --bold
end
end
Expand Down
35 changes: 35 additions & 0 deletions functions/__bobthefish_glyphs.fish
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,23 @@ function __bobthefish_glyphs -S -d 'Define glyphs used by bobthefish'
set left_arrow_glyph ''
end

set os_type_darwin 'Mac'
set os_type_synology 'Syno'
set os_type_mint 'Mint'
set os_type_suse 'Suse'
set os_type_centos 'Cent'
set os_type_fedora 'Fed'
set os_type_redhat 'RHat'
set os_type_gentoo 'Gnto'
set os_type_arch 'Arch'
set os_type_alpine 'Alp'
set os_type_ubuntu 'Ubu'
set os_type_elementary 'Elem'
set os_type_debian 'Deb'
set os_type_generic 'Lin'
set os_type_amazon 'Amz'
set os_type_coreos 'Core'

# Use prettier Nerd Fonts glyphs
if [ "$theme_nerd_fonts" = "yes" ]
set branch_glyph \uF418
Expand Down Expand Up @@ -86,6 +103,24 @@ function __bobthefish_glyphs -S -d 'Define glyphs used by bobthefish'
set git_plus_glyph \uF0DE # fa-sort-asc
set git_minus_glyph \uF0DD # fa-sort-desc
set git_plus_minus_glyph \uF0DC # fa-sort

set os_type_darwin ''
set os_type_synology ''
set os_type_mint ''
set os_type_suse ''
set os_type_centos ''
set os_type_fedora ''
set os_type_redhat ''
set os_type_gentoo ''
set os_type_arch ''
set os_type_alpine ''
set os_type_ubuntu ''
set os_type_elementary ''
set os_type_debian ''
set os_type_generic ''
set os_type_amazon ''
set os_type_coreos ''

end

# Avoid ambiguous glyphs
Expand Down