2024-08-15 03:41:41 +01:00
|
|
|
#!/bin/sh -e
|
|
|
|
|
2024-08-21 08:18:34 +01:00
|
|
|
. ./utility_functions.sh
|
2024-08-05 20:24:05 +01:00
|
|
|
|
2024-09-12 21:14:50 +01:00
|
|
|
. ../../common-script.sh
|
2024-08-05 20:24:05 +01:00
|
|
|
|
|
|
|
# Function to enable a monitor
|
|
|
|
enable_monitor() {
|
|
|
|
monitor_list=$(detect_connected_monitors)
|
2024-09-12 21:14:50 +01:00
|
|
|
monitor_array=$(echo "$monitor_list" | tr '\n' ' ')
|
2024-08-05 20:24:05 +01:00
|
|
|
|
|
|
|
clear
|
2024-09-12 21:14:50 +01:00
|
|
|
printf "%b\n" "${YELLOW}=========================================${RC}"
|
|
|
|
printf "%b\n" "${YELLOW} Enable Monitor${RC}"
|
|
|
|
printf "%b\n" "${YELLOW}=========================================${RC}"
|
|
|
|
printf "%b\n" "${YELLOW}Choose a monitor to enable:${RC}"
|
|
|
|
|
|
|
|
i=1
|
|
|
|
for monitor in $monitor_array; do
|
|
|
|
printf "%b\n" "$i. ${GREEN}$monitor${RC}"
|
|
|
|
i=$((i + 1))
|
2024-08-05 20:24:05 +01:00
|
|
|
done
|
|
|
|
|
|
|
|
read -p "Enter the number of the monitor: " monitor_choice
|
|
|
|
|
2024-09-12 21:14:50 +01:00
|
|
|
if ! echo "$monitor_choice" | grep -qE '^[0-9]+$' || [ "$monitor_choice" -lt 1 ] || [ "$monitor_choice" -gt "$((i - 1))" ]; then
|
|
|
|
printf "%b\n" "${RED}Invalid selection.${RC}"
|
2024-08-05 20:24:05 +01:00
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
2024-09-12 21:14:50 +01:00
|
|
|
monitor_name=$(echo "$monitor_array" | cut -d' ' -f"$monitor_choice")
|
2024-08-05 20:24:05 +01:00
|
|
|
|
2024-09-12 21:14:50 +01:00
|
|
|
if confirm_action "Enable $monitor_name?"; then
|
|
|
|
printf "%b\n" "${GREEN}Enabling $monitor_name${RC}"
|
2024-08-05 20:24:05 +01:00
|
|
|
execute_command "xrandr --output $monitor_name --auto"
|
2024-09-12 21:14:50 +01:00
|
|
|
printf "%b\n" "${GREEN}Monitor $monitor_name enabled successfully.${RC}"
|
2024-08-05 20:24:05 +01:00
|
|
|
else
|
2024-09-12 21:14:50 +01:00
|
|
|
printf "%b\n" "${RED}Action canceled.${RC}"
|
2024-08-05 20:24:05 +01:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# Call the enable_monitor function
|
|
|
|
enable_monitor
|