Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove bashisms from set resolutions #473

Merged
merged 1 commit into from
Sep 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions tabs/utils/monitor-control/set_resolutions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ set_resolutions() {
i=$((i + 1))
done

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

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

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

Expand All @@ -43,7 +45,7 @@ set_resolutions() {

i=1
while read -r resolution; do
resolution_map[$i]="$resolution"
echo "$resolution" >> "$temp_res_file"
i=$((i + 1))
done < "$temp_res_file"

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

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

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

# Map the index to the actual resolution
selected_resolution=${resolution_map[$resolution_choice]}
selected_resolution=$(awk "NR==$resolution_choice" "$temp_res_file")

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