Add tide_context_hostname_parts

This commit is contained in:
Ilan Cosman 2022-09-05 14:07:29 -04:00
parent 10b74059ad
commit b508a7f52b
5 changed files with 20 additions and 6 deletions

View File

@ -1,9 +1,15 @@
function _tide_item_context
if set -q SSH_TTY
tide_context_color=$tide_context_color_ssh _tide_print_item context $USER@$hostname
set -lx tide_context_color $tide_context_color_ssh
test "$tide_context_hostname_parts" = 0 && _tide_print_item context $USER ||
h=(string split . $hostname) _tide_print_item context $USER@(string join . $h[..$tide_context_hostname_parts])
else if test "$EUID" = 0
tide_context_color=$tide_context_color_root _tide_print_item context $USER@$hostname
set -lx tide_context_color $tide_context_color_root
test "$tide_context_hostname_parts" = 0 && _tide_print_item context $USER ||
h=(string split . $hostname) _tide_print_item context $USER@(string join . $h[..$tide_context_hostname_parts])
else if test "$tide_context_always_display" = true
tide_context_color=$tide_context_color_default _tide_print_item context $USER@$hostname
set -lx tide_context_color $tide_context_color_default
test "$tide_context_hostname_parts" = 0 && _tide_print_item context $USER ||
h=(string split . $hostname) _tide_print_item context $USER@(string join . $h[..$tide_context_hostname_parts])
end
end

View File

@ -20,6 +20,7 @@ tide_context_bg_color 444444
tide_context_color_default D7AF87
tide_context_color_root $_tide_color_gold
tide_context_color_ssh D7AF87
tide_context_hostname_parts 1
tide_crystal_bg_color 444444
tide_crystal_color FFFFFF
tide_crystal_icon

View File

@ -20,6 +20,7 @@ tide_context_bg_color normal
tide_context_color_default D7AF87
tide_context_color_root $_tide_color_gold
tide_context_color_ssh D7AF87
tide_context_hostname_parts 1
tide_crystal_bg_color normal
tide_crystal_color FFFFFF
tide_crystal_icon

View File

@ -20,6 +20,7 @@ tide_context_bg_color 444444
tide_context_color_default D7AF87
tide_context_color_root $_tide_color_gold
tide_context_color_ssh D7AF87
tide_context_hostname_parts 1
tide_crystal_bg_color FFFFFF
tide_crystal_color 000000
tide_crystal_icon

View File

@ -5,14 +5,19 @@ function _context
_tide_decolor (_tide_item_context)
end
set -lx tide_context_hostname_parts 5
set -lx tide_context_always_display false
_context # Check:
set -lx tide_context_always_display true
_context # CHECK: {{.*@.*}}
_context # CHECK: {{[^@]*@[^@]*}}
set -g SSH_TTY /dev/pts/0
_context # CHECK: {{.*@.*}}
_context # CHECK: {{[^@]*@[^@]*}}
set EUID 0
_context # CHECK: {{.*@.*}}
_context # CHECK: {{[^@]*@[^@]*}}
set -lx tide_context_hostname_parts 0
_context # CHECK: {{[^@]*}}