Skip to content

Commit f473cde

Browse files
Nyxnnyyxxxx
andauthored
Remove bashisms from set resolutions (#473)
Co-authored-by: nnyyxxxx <nnyyxxxx@users.noreply.github.com>
1 parent e783512 commit f473cde

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

tabs/utils/monitor-control/set_resolutions.sh

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ set_resolutions() {
2222
i=$((i + 1))
2323
done
2424

25-
read -p "Enter the choice (or 'q' to quit): " monitor_choice
25+
printf "%b\n" "Enter the choice (or 'q' to quit): "
26+
read -r monitor_choice
2627

2728
if [ "$monitor_choice" = "q" ]; then
2829
printf "%b\n" "${RED}Exiting...${RC}"
@@ -31,7 +32,8 @@ set_resolutions() {
3132

3233
if ! echo "$monitor_choice" | grep -qE '^[0-9]+$' || [ "$monitor_choice" -lt 1 ] || [ "$monitor_choice" -gt "$((i - 1))" ]; then
3334
printf "%b\n" "${RED}Invalid selection. Please try again.${RC}"
34-
read -p "Press [Enter] to continue..."
35+
printf "%b\n" "Press [Enter] to continue..."
36+
read -r dummy
3537
continue
3638
fi
3739

@@ -43,7 +45,7 @@ set_resolutions() {
4345

4446
i=1
4547
while read -r resolution; do
46-
resolution_map[$i]="$resolution"
48+
echo "$resolution" >> "$temp_res_file"
4749
i=$((i + 1))
4850
done < "$temp_res_file"
4951

@@ -54,7 +56,8 @@ set_resolutions() {
5456
awk '{print $1 ". " $2}' "$temp_res_file"
5557

5658
while true; do
57-
read -p "Enter the choice (or 'q' to quit): " resolution_choice
59+
printf "%b\n" "Enter the choice (or 'q' to quit): "
60+
read -r resolution_choice
5861

5962
if [ "$resolution_choice" = "q" ]; then
6063
printf "%b\n" "${RED}Exiting...${RC}"
@@ -67,10 +70,10 @@ set_resolutions() {
6770
continue
6871
fi
6972

70-
# Map the index to the actual resolution
71-
selected_resolution=${resolution_map[$resolution_choice]}
73+
selected_resolution=$(awk "NR==$resolution_choice" "$temp_res_file")
7274

73-
read -p "Set resolution for $monitor_name to $selected_resolution? (y/n): " confirm
75+
printf "%b\n" "Set resolution for $monitor_name to $selected_resolution? (y/n): "
76+
read -r confirm
7477
if echo "$confirm" | grep -qE '^[Yy]$'; then
7578
printf "%b\n" "${GREEN}Setting resolution for $monitor_name to $selected_resolution${RC}"
7679
execute_command "xrandr --output $monitor_name --mode $selected_resolution"

0 commit comments

Comments
 (0)