forked from raycast/script-commands
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathyear-progress.sh
executable file
·64 lines (49 loc) · 1.16 KB
/
year-progress.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/bin/bash
# Inspired by https://twitter.com/year_progress
# Required parameters:
# @raycast.schemaVersion 1
# @raycast.title Year Progress
# @raycast.mode inline
# Conditional parameters:
# @raycast.refreshTime 1h
# Optional parameters:
# @raycast.icon ⏱
# @raycast.packageName Dashboard
# Documentation:
# @raycast.author Thomas Paul Mann
# @raycast.authorURL https://github.com/thomaspaulmann
# @raycast.description See the year progress on your desktop.
# Configuration
OUTPUT_INCLUDES_BAR=true
BAR_LENGTH=33
# Main program
current_year=$(date +%Y)
current_day=$(date +%j)
if [ $((current_year % 400)) -eq 0 ]
then
DAYS=366
elif [ $((current_year % 100)) -eq 0 ]
then
DAYS=365
elif [ $((current_year % 4)) -eq 0 ]
then
DAYS=366
else
DAYS=365
fi
percentage=$((100 * 10#$current_day / $DAYS))
filled_element_count=$(($BAR_LENGTH * $percentage / 100))
blank_element_count=$(($BAR_LENGTH - $filled_element_count))
bar=""
for ((i = 0; i < $filled_element_count; i++)) {
bar=${bar}"▓"
}
for ((i = 0; i < $blank_element_count; i++)) {
bar=${bar}"░"
}
if [ "$OUTPUT_INCLUDES_BAR" = true ]
then
echo ${bar}" "${percentage}"%"
else
echo ${percentage}"%"
fi