mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2026-05-29 04:53:17 +02:00
add a year progress bar plug-in
This commit is contained in:
parent
62b8a70a7c
commit
be554c4bf6
1 changed files with 54 additions and 0 deletions
54
plugins/year-progress/year-progress.plugin.zsh
Normal file
54
plugins/year-progress/year-progress.plugin.zsh
Normal file
|
|
@ -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
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue