From be554c4bf686794b8f4212c2cad0bd55c2d10176 Mon Sep 17 00:00:00 2001 From: eightpigs Date: Sat, 14 Apr 2018 19:21:13 +0800 Subject: [PATCH] add a year progress bar plug-in --- .../year-progress/year-progress.plugin.zsh | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 plugins/year-progress/year-progress.plugin.zsh diff --git a/plugins/year-progress/year-progress.plugin.zsh b/plugins/year-progress/year-progress.plugin.zsh new file mode 100644 index 000000000..4d6fe9121 --- /dev/null +++ b/plugins/year-progress/year-progress.plugin.zsh @@ -0,0 +1,54 @@ +year_progress() { + + year=`date +%Y` + current=`date +%j` + + # default common year: 365 + len=365 + + # leap year: 366 + if [[ ($(($year%4)) == 0 && $(($year%100)) != 0) || $(($year%400)) == 0 ]] ;then + len=366 + fi + + # progress=current/year + value=`echo "$current $len" | awk '{printf ("%.2f\n",$1/$2)}'` + + # Get the number of columns in the terminal + tput init + cols=`tput cols` + + val2=$(($current*100/$len)) + + info=$val2%' '$current/$len + + cols=$(($cols-${#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)}'` + + echo + + echo -n $val2%' ' + + # Previous days + for ((i=0; i<$val; i++)) + do + echo -n "▓" + done + + # The remaining days + for ((i=0; i<$((cols-$val)); i ++)) + do + echo -n "░" + done + + echo ' '$current/$len + + echo +} + +year_progress +