From b6930851b856455be68c2beb8d60d31f1a480d74 Mon Sep 17 00:00:00 2001 From: Les De Ridder Date: Sun, 24 Mar 2019 08:37:21 +0100 Subject: [PATCH] Don't output colours when stdout isn't connected to a terminal --- saury | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/saury b/saury index db3c18e..fe6f970 100755 --- a/saury +++ b/saury @@ -90,7 +90,9 @@ function aur_search set popularity $results[(math $i \* 7)] set_color --bold - echo -n (set_color CC3399)aur/(set_color normal; set_color --bold)$name + echo -n (string join "" \ + (set_color CC3399) "aur/" \ + (set_color normal; set_color --bold) "$name") echo -n ' ' if test $out_of_date = "true" @@ -106,7 +108,12 @@ function aur_search echo -n " ($package_base)" end - echo -n (set_color normal; set_color --bold)' ('(set_color CC6733)"+$votes"(set_color normal; set_color --bold)' | '(set_color CC6733)$popularity(set_color normal; set_color --bold)')' + echo -n (string join "" \ + (set_color normal; set_color --bold) ' (' \ + (set_color CC6733) "+$votes" \ + (set_color normal; set_color --bold) ' | ' \ + (set_color CC6733) "$popularity" \ + (set_color normal; set_color --bold) ')') echo @@ -144,6 +151,11 @@ function on_start set -q fish_term24bit or set -g fish_term24bit 1 end + + if not test -t 1 + function set_color + end + end end function on_exit @@ -158,7 +170,7 @@ function main argparse -n $saury_name -x 'V,A' -x $aur_sync_exclusive_options \ 'h/help' 'V/version' 'A/aur-sync' $aur_sync_options -- $argv \ - ^| sed 's/:/':(set_color red)'/;s/$/'(set_color normal)'/' | head -1 + ^| sed (string join '' 's/:/:' (set_color red) '/;s/$/' (set_color normal) '/') | head -1 if not set --local --query argv # if argparse didn't locally set $argv, it encountered an error