|
1 | 1 | #!/bin/bash
|
2 | 2 |
|
3 |
| -# Define an array of clock emojis from 🕐 to 🕛 |
| 3 | +# Define arrays for French translations of day and month names |
| 4 | +declare -A days=( [Monday]="Lundi" [Tuesday]="Mardi" [Wednesday]="Mercredi" [Thursday]="Jeudi" [Friday]="Vendredi" [Saturday]="Samedi" [Sunday]="Dimanche" ) |
| 5 | +declare -A months=( [January]="Janvier" [February]="Février" [March]="Mars" [April]="Avril" [May]="Mai" [June]="Juin" [July]="Juillet" [August]="Août" [September]="Septembre" [October]="Octobre" [November]="Novembre" [December]="Décembre" ) |
4 | 6 |
|
5 |
| -# Function to translate English day names to French |
6 |
| -translate_day() { |
7 |
| - case $1 in |
8 |
| - Monday) echo "Lundi" ;; |
9 |
| - Tuesday) echo "Mardi" ;; |
10 |
| - Wednesday) echo "Mercredi" ;; |
11 |
| - Thursday) echo "Jeudi" ;; |
12 |
| - Friday) echo "Vendredi" ;; |
13 |
| - Saturday) echo "Samedi" ;; |
14 |
| - Sunday) echo "Dimanche" ;; |
15 |
| - *) echo "$1" ;; # Return the original name if not found |
16 |
| - esac |
17 |
| -} |
18 |
| - |
19 |
| -# Function to translate English month names to French |
20 |
| -translate_month() { |
21 |
| - case $1 in |
22 |
| - January) echo "Janvier" ;; |
23 |
| - February) echo "Février" ;; |
24 |
| - March) echo "Mars" ;; |
25 |
| - April) echo "Avril" ;; |
26 |
| - May) echo "Mai" ;; |
27 |
| - June) echo "Juin" ;; |
28 |
| - July) echo "Juillet" ;; |
29 |
| - August) echo "Août" ;; |
30 |
| - September) echo "Septembre" ;; |
31 |
| - October) echo "Octobre" ;; |
32 |
| - November) echo "Novembre" ;; |
33 |
| - December) echo "Décembre" ;; |
34 |
| - *) echo "$1" ;; # Return the original name if not found |
35 |
| - esac |
36 |
| -} |
37 |
| - |
38 |
| -# Get the last two digits of the year |
| 7 | +# Get the last two digits of the year and current date |
39 | 8 | YEAR=$(date +"%y")
|
40 |
| -DATE_YMD=$(date +"%Y %m %d") # Date in YYYY-MM-DD format |
| 9 | +DATE_YMD=$(date +"%Y-%m-%d") # Date in YYYY-MM-DD format |
41 | 10 | DATE_DMY=$(date +"%d-%m-%y") # Date in DD-MM-YY format
|
42 | 11 | EN_DAY=$(date +"%A")
|
43 | 12 | EN_MONTH=$(date +"%B")
|
44 |
| -FR_DAY=$(translate_day "$EN_DAY") |
45 |
| -FR_MONTH=$(translate_month "$EN_MONTH") |
46 |
| - |
| 13 | +FR_DAY=${days[$EN_DAY]} |
| 14 | +FR_MONTH=${months[$EN_MONTH]} |
47 | 15 |
|
48 | 16 | # Get the power status
|
49 | 17 | power_status=$(upower -i $(upower -e | grep '/battery') | grep -E "state|percentage")
|
50 | 18 |
|
51 |
| -while true; do |
52 |
| - # Get current time and date |
53 |
| - HOUR_12=$(date +"%I") # 12-hour format with leading zero |
54 |
| - MINUTE=$(date +"%M") # Get the minutes |
55 |
| - HOUR_24=$(date +"%H:%M") # 24-hour format (HH:MM) |
56 |
| - AMPM=$(date +"%p") # Get AM or PM |
57 |
| - # Translate to French |
58 |
| - DAY_NUM=$(date +"%d") |
59 |
| - # Get the free space and total space in human-readable format |
60 |
| - disk_info=$(df -h | grep '/dev/nvme0n1p2') |
61 |
| - percentage_used=$(echo "$disk_info" | awk '{print $5}') |
62 |
| - # Extract the free and total space from the output |
63 |
| - free_space=$(echo $disk_info | awk '{print $4}') |
64 |
| - # Extract the used and total space from the output |
65 |
| - used_space=$(echo $disk_info | awk '{print $3}') |
66 |
| - total_space=$(echo $disk_info | awk '{print $2}') |
67 |
| - disk_space="$percentage_used" |
68 |
| - |
69 |
| - # Get the first character of the minute |
70 |
| - MINUTE_FIRST_CHAR="${MINUTE:0:1}" |
71 |
| - # Check if HOUR_12 starts with a leading zero and remove it if present |
72 |
| - if [[ "${HOUR_12:0:1}" == "0" ]]; then |
73 |
| - HOUR_12="${HOUR_12:1:1}" |
74 |
| - fi |
75 |
| - |
76 |
| - padding=" " |
77 |
| - |
78 |
| - # Format output for lemonbar |
79 |
| - #OUTPUT="${padding}($HOUR_12:$MINUTE_FIRST_CHAR) - ($HOUR_24) - ($DATE)" |
80 |
| - |
81 |
| - |
82 |
| - romanise() { |
83 |
| - local input="$1" |
84 |
| - local result="$input" |
85 |
| - |
86 |
| - # Define a mapping of numbers to Roman numerals |
87 |
| - declare -A roman_map=( |
88 |
| - [10]="X" [11]="I" [12]="0" |
89 |
| - ) |
| 19 | +# Helper function for romanising numbers (simplified) |
| 20 | +romanise() { |
| 21 | + local input="$1" |
| 22 | + declare -A roman_map=( [10]="X" [11]="I" [12]="0" ) |
| 23 | + for num in "${!roman_map[@]}"; do |
| 24 | + input="${input//$num/${roman_map[$num]}}" |
| 25 | + done |
| 26 | + echo "$input" |
| 27 | +} |
90 | 28 |
|
91 |
| - # Replace exact matches in the input |
92 |
| - for num in "${!roman_map[@]}"; do |
93 |
| - result="${result//$num/${roman_map[$num]}}" |
94 |
| - done |
| 29 | +# Trap any error in the script and display an error message |
| 30 | +trap 'echo "Unexpected loop end for $0, no longer updating..." | tee -a /tmp/status_error.log; exit 1' ERR |
95 | 31 |
|
96 |
| - echo "$result" |
97 |
| - } |
98 | 32 |
|
99 |
| - # Optimised time |
100 |
| - |
101 |
| - # Even minute format: red text on black background |
102 |
| -# if [[ "$HOUR_12" == "12" ]]; then |
103 |
| -# HOUR_12="0" |
104 |
| -# elif [[ "$HOUR_12" == "11" ]]; then |
105 |
| -# HOUR_12="I" |
106 |
| -# elif [[ "$HOUR_12" == "10" ]]; then |
107 |
| -# HOUR_12="X" |
108 |
| -# fi |
109 |
| - |
110 |
| - HOUR_12=$(romanise $HOUR_12) |
111 |
| - #indice=" ${AMPM:0:1}" |
112 |
| - TIME="$HOUR_12:$MINUTE_FIRST_CHAR${indice}" |
113 |
| - DATE="$DATE_DMY" |
| 33 | +# Main loop |
| 34 | +while true; do |
| 35 | + # Get current time and date (simplified format) |
| 36 | + HOUR_12=$(date +"%-I") |
| 37 | + MINUTE=$(date +"%M") |
| 38 | + DAY_NUM=$(date +"%d") |
114 | 39 |
|
115 |
| - DATE=$(romanise $DATE) |
| 40 | + # Round minutes to nearest 10 |
| 41 | + MINUTE=$(( (10#$MINUTE + 5) / 10 * 10 )) |
| 42 | + if [ "$MINUTE" -gt 50 ]; then |
| 43 | + MINUTE="+" |
| 44 | + fi |
116 | 45 |
|
117 |
| - # Multiple time format |
| 46 | + HOUR_24=$(date +"%H:%M") |
| 47 | + TIME=$(romanise $HOUR_12):${MINUTE:0:1} |
118 | 48 |
|
119 |
| - # Check if the minute is even or odd |
120 |
| -# if (( MINUTE % 2 == 0 )); then |
121 |
| -# # Even minute format: red text on black background |
122 |
| -# if [[ "$HOUR_12" == "12" ]]; then |
123 |
| -# HOUR_12="0" |
124 |
| -# elif [[ "$HOUR_12" == "11" ]]; then |
125 |
| -# HOUR_12="I" |
126 |
| -# elif [[ "$HOUR_12" == "10" ]]; then |
127 |
| -# HOUR_12="X" |
128 |
| -# fi |
129 |
| -# |
130 |
| -# #indice=" ${AMPM:0:1}" |
131 |
| -# TIME="$HOUR_12:$MINUTE_FIRST_CHAR${indice}" |
132 |
| -# DATE="$DATE_DMY" |
133 |
| -# else |
134 |
| -# # Odd minute format: white text on blue background |
135 |
| -## if [[ "${HOUR_24:0:2}" == "00" ]] || [[ "${HOUR_24:0:2}" == "12" ]] ; then |
136 |
| -## HOUR_24="XX:$MINUTE" |
137 |
| -## fi |
138 |
| -# TIME="$HOUR_24" |
139 |
| -# DATE="$FR_DAY $DAY_NUM $FR_MONTH" |
140 |
| -# fi |
| 49 | + # Disk space usage |
| 50 | + disk_info=$(df -h | grep '/dev/nvme0n1p2') |
| 51 | + disk_space=$(echo "$disk_info" | awk '{print $5}') |
141 | 52 |
|
| 53 | + # Battery status |
142 | 54 | bat_text=""
|
143 |
| - |
144 | 55 | if echo "$power_status" | grep -q "discharging"; then
|
145 |
| - # pourcent |
146 |
| - pour_cent=$(acpi | awk '{print $4}') |
147 |
| - pour_cent=$(echo ${pour_cent} | sed 's/,//') |
148 |
| - if [ ${pour_cent//[!0-9]/} -gt $low ]; then |
149 |
| - BAT="${pour_cent}" |
150 |
| - else |
151 |
| - BAT="${pour_cent}" |
152 |
| - fi |
| 56 | + pour_cent=$(acpi | awk '{print $4}' | sed 's/,//') |
153 | 57 | n_pour_cent=${pour_cent%\%}
|
154 |
| - # Assume $pour_cent holds the battery percentage as an integer |
155 | 58 | if [ "$n_pour_cent" -ge 80 ]; then
|
156 |
| - battery_char="█" # Full battery |
| 59 | + battery_char="█" |
157 | 60 | elif [ "$n_pour_cent" -ge 60 ]; then
|
158 |
| - battery_char="▓" # 75% battery |
| 61 | + battery_char="▓" |
159 | 62 | elif [ "$n_pour_cent" -ge 40 ]; then
|
160 |
| - battery_char="▒" # 50% battery |
| 63 | + battery_char="▒" |
161 | 64 | elif [ "$n_pour_cent" -ge 20 ]; then
|
162 |
| - battery_char="░" # 25% battery |
| 65 | + battery_char="░" |
163 | 66 | else
|
164 |
| - battery_char="▁" # Low battery |
| 67 | + battery_char="▁" |
165 | 68 | fi
|
166 | 69 | bat_text="($battery_char $pour_cent)"
|
167 | 70 | fi
|
168 |
| - |
| 71 | + |
| 72 | + # Task from todo.tmp (if available) |
169 | 73 | task=""
|
170 |
| - # Check if /tmp/todo.md exists and is not empty |
171 | 74 | if [[ -s "/tmp/todo.tmp" ]]; then
|
172 |
| - # Pick a random line from /tmp/todo.md |
173 | 75 | line=$(shuf -n 1 "/tmp/todo.tmp")
|
174 |
| - # Remove the first 3 and last 3 characters |
175 | 76 | task="(${line:2:-11})"
|
176 | 77 | fi
|
177 |
| - offset="" |
178 |
| - # Output the formatted text to lemonbar |
179 |
| - echo "${offset}$bat_text [$TIME] [$DATE] [$disk_space] $task" |
180 | 78 |
|
181 |
| - # Sleep for 60 seconds to update the time |
| 79 | + # Output to lemonbar |
| 80 | + echo "$bat_text [$TIME] [$DATE_DMY] [$disk_space] $task" |
| 81 | + |
182 | 82 | sleep 60
|
183 | 83 | done
|
184 | 84 |
|
| 85 | +echo "Unexpected loop end for $0, no longer updating..." |
0 commit comments