From 5592e225c9bc404dda6a7008885c06d6250fe29e Mon Sep 17 00:00:00 2001 From: Ilan Cosman Date: Fri, 23 Apr 2021 14:41:11 -0700 Subject: [PATCH] Convert many items to _tide_print_item --- functions/_tide_item_chruby.fish | 5 +--- functions/_tide_item_cmd_duration.fish | 8 +++--- functions/_tide_item_context.fish | 12 ++++----- functions/_tide_item_git.fish | 2 +- functions/_tide_item_jobs.fish | 6 ++--- functions/_tide_item_nvm.fish | 5 +--- functions/_tide_item_os.fish | 3 +-- functions/_tide_item_php.fish | 5 +--- functions/_tide_item_prompt_char.fish | 14 +++++----- functions/_tide_item_pwd.fish | 11 ++++---- functions/_tide_item_rust.fish | 5 +--- functions/_tide_item_status.fish | 20 +++++++------- functions/_tide_item_time.fish | 3 +-- functions/_tide_left_prompt.fish | 37 +++----------------------- functions/_tide_print_item.fish | 2 +- 15 files changed, 46 insertions(+), 92 deletions(-) diff --git a/functions/_tide_item_chruby.fish b/functions/_tide_item_chruby.fish index f4e5cd6..0d96705 100644 --- a/functions/_tide_item_chruby.fish +++ b/functions/_tide_item_chruby.fish @@ -1,6 +1,3 @@ function _tide_item_chruby - if test -n "$RUBY_VERSION" - set_color $tide_chruby_color - printf '%s' $tide_chruby_icon' ' $RUBY_VERSION - end + test -n "$RUBY_VERSION" && _tide_print_item ruby $RUBY_VERSION end diff --git a/functions/_tide_item_cmd_duration.fish b/functions/_tide_item_cmd_duration.fish index 755d6c8..76f731d 100644 --- a/functions/_tide_item_cmd_duration.fish +++ b/functions/_tide_item_cmd_duration.fish @@ -4,14 +4,12 @@ function _tide_item_cmd_duration set -l minutes (math --scale=0 "$CMD_DURATION/60000" % 60) set -l hours (math --scale=0 "$CMD_DURATION/3600000") - set_color $tide_cmd_duration_color - if test $hours != 0 - printf '%s' $tide_cmd_duration_icon' ' $hours'h ' $minutes'm ' $seconds's' + _tide_print_item cmd_duration $hours'h ' $minutes'm ' $seconds's' else if test $minutes != 0 - printf '%s' $tide_cmd_duration_icon' ' $minutes'm ' $seconds's' + _tide_print_item cmd_duration $minutes'm ' $seconds's' else if test $seconds != 0 - printf '%s' $tide_cmd_duration_icon' ' $seconds's' + _tide_print_item cmd_duration $seconds's' end end end diff --git a/functions/_tide_item_context.fish b/functions/_tide_item_context.fish index afe40e5..06fa300 100644 --- a/functions/_tide_item_context.fish +++ b/functions/_tide_item_context.fish @@ -1,12 +1,12 @@ function _tide_item_context if set -q SSH_TTY - set_color $tide_context_ssh_color - printf '%s' $USER'@'$hostname + set -g tide_context_color $tide_context_ssh_color + _tide_print_item context $USER'@'$hostname else if contains -- $USER root toor Administrator - set_color $tide_context_root_color - printf '%s' $USER'@'$hostname + set -g tide_context_color $tide_context_root_color + _tide_print_item context $USER'@'$hostname else if test "$tide_context_always_display" = true - set_color $tide_context_default_color - printf '%s' $USER'@'$hostname + set -g tide_context_color $tide_context_default_color + _tide_print_item context $USER'@'$hostname end end diff --git a/functions/_tide_item_git.fish b/functions/_tide_item_git.fish index d5aca2a..999641a 100644 --- a/functions/_tide_item_git.fish +++ b/functions/_tide_item_git.fish @@ -58,7 +58,7 @@ function _tide_item_git set -l untracked (string match --regex '^\?\?' $gitInfo | count) || set -e untracked # Print the information - printf '%s' \ + _tide_print_item git \ (set_color $tide_git_branch_color) $location \ (set_color $tide_git_operation_color) ' '$operation ' '$step/$totalSteps \ (set_color $tide_git_upstream_color) ' ⇣'$upstreamBehind ' ⇡'$upstreamAhead \ diff --git a/functions/_tide_item_jobs.fish b/functions/_tide_item_jobs.fish index 03746ee..4a9079f 100644 --- a/functions/_tide_item_jobs.fish +++ b/functions/_tide_item_jobs.fish @@ -1,11 +1,9 @@ function _tide_item_jobs if test $_tide_jobs_number != 0 - set_color $tide_jobs_color - if test "$tide_jobs_verbose" = true - printf '%s' $tide_jobs_icon' ' $_tide_jobs_number + _tide_print_item jobs $_tide_jobs_number else - printf '%s' $tide_jobs_icon + _tide_print_item jobs end end end diff --git a/functions/_tide_item_nvm.fish b/functions/_tide_item_nvm.fish index 8da1ab0..e2bdbd2 100644 --- a/functions/_tide_item_nvm.fish +++ b/functions/_tide_item_nvm.fish @@ -1,7 +1,4 @@ function _tide_item_nvm set -l nvmCurrent (nvm current) - if test "$nvmCurrent" != system - set_color $tide_nvm_color - printf '%s' $tide_nvm_icon' ' $nvmCurrent - end + test "$nvmCurrent" != system && _tide_print_item nvm $nvmCurrent end diff --git a/functions/_tide_item_os.fish b/functions/_tide_item_os.fish index 40daf7a..d663113 100644 --- a/functions/_tide_item_os.fish +++ b/functions/_tide_item_os.fish @@ -1,4 +1,3 @@ function _tide_item_os - set_color $tide_os_color - printf '%s' $_tide_os_icon + _tide_print_item os end diff --git a/functions/_tide_item_php.fish b/functions/_tide_item_php.fish index ee4f3ab..d494cf5 100644 --- a/functions/_tide_item_php.fish +++ b/functions/_tide_item_php.fish @@ -1,6 +1,3 @@ function _tide_item_php - if test -e composer.json - set_color $tide_php_color - printf '%s' $tide_php_icon' ' (php --version | string match --regex 'PHP ([\d.]+)')[2] - end + test -e composer.json && _tide_print_item php (php --version | string match --regex 'PHP ([\d.]+)')[2] end diff --git a/functions/_tide_item_prompt_char.fish b/functions/_tide_item_prompt_char.fish index 4da2818..bb86f83 100644 --- a/functions/_tide_item_prompt_char.fish +++ b/functions/_tide_item_prompt_char.fish @@ -1,22 +1,22 @@ function _tide_item_prompt_char if test $_tide_last_status = 0 - set_color $tide_prompt_char_success_color + set -g tide_prompt_char_color $tide_prompt_char_success_color else - set_color $tide_prompt_char_failure_color + set -g tide_prompt_char_color $tide_prompt_char_failure_color end if test "$fish_key_bindings" = fish_default_key_bindings - printf '%s' $tide_prompt_char_icon + _tide_print_item prompt_char else switch $fish_bind_mode case default - printf '%s' $tide_prompt_char_vi_default_icon + tide_prompt_char_icon=$tide_prompt_char_vi_default_icon _tide_print_item prompt_char case insert - printf '%s' $tide_prompt_char_vi_insert_icon + tide_prompt_char_icon=$tide_prompt_char_vi_insert_icon _tide_print_item prompt_char case replace replace_one - printf '%s' $tide_prompt_char_vi_replace_icon + tide_prompt_char_icon=$tide_prompt_char_vi_replace_icon _tide_print_item prompt_char case visual - printf '%s' $tide_prompt_char_vi_visual_icon + tide_prompt_char_icon=$tide_prompt_char_vi_visual_icon _tide_print_item prompt_char end end end diff --git a/functions/_tide_item_pwd.fish b/functions/_tide_item_pwd.fish index e5cda15..d4248d8 100644 --- a/functions/_tide_item_pwd.fish +++ b/functions/_tide_item_pwd.fish @@ -35,14 +35,15 @@ function _tide_item_pwd # All the actual printing if not test -w $PWD - printf '%s' $colorDirs $tide_pwd_unwritable_icon' ' + set -g tide_pwd_icon $colorDirs$tide_pwd_unwritable_icon else if test $PWD = $HOME - printf '%s' $colorDirs $tide_pwd_home_icon' ' + set -g tide_pwd_icon $colorDirs $tide_pwd_home_icon else - printf '%s' $colorDirs $tide_pwd_dir_icon' ' + set -g tide_pwd_icon $colorDirs$tide_pwd_dir_icon end - test "$splitPwd[1]" = '~' || printf '%s' / + set -l blah $splitPwdForOutput + test "$splitPwd[1]" = '~' || set -p blah '/' - string join -- / $splitPwdForOutput + _tide_print_item pwd (string join -- / $blah) end diff --git a/functions/_tide_item_rust.fish b/functions/_tide_item_rust.fish index d5c5264..fbc39dc 100644 --- a/functions/_tide_item_rust.fish +++ b/functions/_tide_item_rust.fish @@ -1,6 +1,3 @@ function _tide_item_rust - if test -e Cargo.toml - set_color $tide_rust_color - printf '%s' $tide_rust_icon' ' (rustc --version | string split ' ')[2] - end + test -e Cargo.toml && _tide_print_item rust (rustc --version | string split ' ')[2] end diff --git a/functions/_tide_item_status.fish b/functions/_tide_item_status.fish index 71a070e..2939d49 100644 --- a/functions/_tide_item_status.fish +++ b/functions/_tide_item_status.fish @@ -3,25 +3,25 @@ function _tide_item_status if test "$_tide_last_pipestatus" = 1 # If simple failure if not contains prompt_char $tide_left_prompt_items set -g tide_status_bg_color $tide_status_failure_bg_color - set_color $tide_status_failure_color - printf '%s' $tide_status_failure_icon' ' 1 + set -g tide_status_color $tide_status_failure_color + tide_status_icon=$tide_status_failure_icon _tide_print_item status 1 end else if test $_tide_last_status = 0 set -g tide_status_bg_color $tide_status_success_bg_color - set_color $tide_status_success_color - printf '%s' $tide_status_success_icon' ' + set -g tide_status_color $tide_status_success_color + tide_status_icon=$tide_status_success_icon _tide_print_item status \ + (fish_status_to_signal $_tide_last_pipestatus | string replace SIG '' | string join '|') else set -g tide_status_bg_color $tide_status_failure_bg_color - set_color $tide_status_failure_color - printf '%s' $tide_status_failure_icon' ' + set -g tide_status_color $tide_status_failure_color + tide_status_icon=$tide_status_failure_icon _tide_print_item status \ + (fish_status_to_signal $_tide_last_pipestatus | string replace SIG '' | string join '|') end - - fish_status_to_signal $_tide_last_pipestatus | string replace SIG '' | string join '|' end else if not contains prompt_char $tide_left_prompt_items set -g tide_status_bg_color $tide_status_success_bg_color - set_color $tide_status_success_color - printf '%s' $tide_status_success_icon + set -g tide_status_color $tide_status_success_color + tide_status_icon=$tide_status_success_icon _tide_print_item status end end diff --git a/functions/_tide_item_time.fish b/functions/_tide_item_time.fish index 2ee93bf..b8522bc 100644 --- a/functions/_tide_item_time.fish +++ b/functions/_tide_item_time.fish @@ -1,4 +1,3 @@ function _tide_item_time - set_color $tide_time_color - date +$tide_time_format + _tide_print_item time (date +$tide_time_format) end diff --git a/functions/_tide_left_prompt.fish b/functions/_tide_left_prompt.fish index bff4d5d..88d35e0 100644 --- a/functions/_tide_left_prompt.fish +++ b/functions/_tide_left_prompt.fish @@ -1,45 +1,16 @@ function _tide_left_prompt - set -l lastItem newline - for item in $tide_left_prompt_items if test "$item" = newline set_color $previousColor -b normal printf '%s' $tide_left_prompt_suffix\n + set -g tide_last_item newline else - set -l output (_tide_item_$item) - test -n "$output" || continue - - set -l colorName tide_"$item"_bg_color - set -l color $$colorName - - if test "$lastItem" = newline - if test "$item" != prompt_char - set_color $color -b normal - printf '%s' $tide_left_prompt_prefix - end - else if test "$color" = "$previousColor" - set_color $tide_left_prompt_item_separator_same_color_color - printf '%s' $tide_left_prompt_item_separator_same_color - else - set_color $previousColor -b $color - printf '%s' $tide_left_prompt_item_separator_diff_color - end - - set_color -b $color - - if test "$tide_left_prompt_pad_items" = true -a "$item" != prompt_char - printf '%s' " $output " - else - printf '%s' "$output" - end - - set previousColor $color + _tide_item_$item end - set lastItem $item end - if test "$lastItem" != newline -a "$lastItem" != prompt_char - set_color $previousColor -b normal + if test "$tide_last_item" != newline -a "$tide_last_item" != prompt_char + set_color $tide_previous_bg_color -b normal printf '%s' $tide_left_prompt_suffix end diff --git a/functions/_tide_print_item.fish b/functions/_tide_print_item.fish index 8f565f3..81aaecd 100644 --- a/functions/_tide_print_item.fish +++ b/functions/_tide_print_item.fish @@ -20,7 +20,7 @@ function _tide_print_item -a item set_color $itemColor -b $itemBgColor test "$tide_left_prompt_pad_items" = true -a "$item" != prompt_char && set -l padItem ' ' - itemIconName=tide_"$item"_icon printf '%s' $padItem $$itemIconName $argv[2..] $padItem + itemIconName=tide_"$item"_icon printf '%s' $padItem $$itemIconName' ' $argv[2..] $padItem set -g tide_previous_bg_color $itemBgColor set -g tide_last_item $item