From b5a01f7bb9307cbd16425f127b6b2fe650b4f9b2 Mon Sep 17 00:00:00 2001 From: eightpigs Date: Tue, 17 Apr 2018 10:10:03 +0800 Subject: [PATCH] optimize the code --- plugins/year-progress/year-progress.plugin.zsh | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/plugins/year-progress/year-progress.plugin.zsh b/plugins/year-progress/year-progress.plugin.zsh index cefebde8..0c21e8d3 100644 --- a/plugins/year-progress/year-progress.plugin.zsh +++ b/plugins/year-progress/year-progress.plugin.zsh @@ -12,31 +12,32 @@ year_progress() { fi # progress=current/year - value=`echo "$current $len" | awk '{printf ("%.2f\n",$1/$2)}'` + percent=$(($current*100/$len)) - val2=$(($current*100/$len)) - - info=$val2%' '$current/$len + # The information to be displayed is used to calculate the length. + info=$percent%' '$current/$len + # progress bar length = $COLUMNS - info.length cols=$(($COLUMNS-${#info})) # Fill the proportion of the screen scale=`echo "$cols" | awk '{printf ("%.2f\n",$1/100)}'` - val=`echo "$val2 $scale" | awk '{printf ("%.0f\n",$1*$2)}'` + # The length of the progress bar can be shown on a proportional basis. + valLen=`echo "$percent $scale" | awk '{printf ("%.0f\n",$1*$2)}'` echo - echo -n $val2%' ' + echo -n $percent%' ' # Previous days - for ((i=0; i<$val; i++)) + for ((i=0; i<$valLen; i++)) do echo -n "▓" done # The remaining days - for ((i=0; i<$((cols-$val)); i ++)) + for ((i=0; i<$(($cols-$valLen)); i++)) do echo -n "░" done