Skip to content

Commit

Permalink
Merge pull request #163 from jeevithakannan2/utilities
Browse files Browse the repository at this point in the history
Fixes for utilities
  • Loading branch information
ChrisTitusTech authored Sep 4, 2024
2 parents 752b85e + d563622 commit d62f9ef
Show file tree
Hide file tree
Showing 15 changed files with 154 additions and 45 deletions.
33 changes: 32 additions & 1 deletion src/commands/utils/bluetooth-control.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,33 @@
#!/bin/bash
#!/bin/sh -e

. ../common-script.sh

# Function to check bluetoothctl is installed
setupBluetooth() {
echo "Install bluetoothctl if not already installed..."
if ! command_exists bluetoothctl; then
case ${PACKAGER} in
pacman)
$ESCALATION_TOOL "${PACKAGER}" -S --noconfirm bluez-utils
;;
*)
$ESCALATION_TOOL "${PACKAGER}" install -y bluez
;;
esac
else
echo "Bluetoothctl is already installed."
fi

# Check if bluetooth service is running
if ! systemctl is-active --quiet bluetooth; then
echo "Bluetooth service is not running. Starting it now..."
$ESCALATION_TOOL systemctl start bluetooth

if systemctl is-active --quiet bluetooth; then
echo "bluetooth service started successfully."
fi
fi
}

# Function to display colored text
colored_echo() {
Expand Down Expand Up @@ -128,4 +157,6 @@ remove_device() {
}

# Initialize
checkEnv
setupBluetooth
main_menu
5 changes: 3 additions & 2 deletions src/commands/utils/monitor-control/auto_detect_displays.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/bin/bash
source ./utility_functions.sh
#!/bin/sh -e

. ./utility_functions.sh

# Function to auto-detect displays and set common resolution
auto_detect_displays() {
Expand Down
7 changes: 4 additions & 3 deletions src/commands/utils/monitor-control/change_orientation.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#!/bin/bash
source ./utility_functions.sh
#!/bin/sh -e

. ./utility_functions.sh

# Function to change monitor orientation
change_orientation() {
monitor_list=$(detect_connected_monitors)
IFS=$'\n' read -r -d '' -a monitor_array <<<"$monitor_list"
IFS=$'\n' read -r -a monitor_array <<<"$monitor_list"

clear
echo -e "${BLUE}=========================================${RESET}"
Expand Down
7 changes: 4 additions & 3 deletions src/commands/utils/monitor-control/disable_monitor.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/bin/bash
source ./utility_functions.sh
#!/bin/sh -e

. ./utility_functions.sh

RESET='\033[0m'
BOLD='\033[1m'
Expand All @@ -12,7 +13,7 @@ CYAN='\033[36m'
# Function to disable a monitor
disable_monitor() {
monitor_list=$(detect_connected_monitors)
IFS=$'\n' read -r -d '' -a monitor_array <<<"$monitor_list"
IFS=$'\n' read -r -a monitor_array <<<"$monitor_list"

clear
echo -e "${BLUE}=========================================${RESET}"
Expand Down
19 changes: 10 additions & 9 deletions src/commands/utils/monitor-control/duplicate_displays.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
#!/bin/bash
source ./utility_functions.sh
#!/bin/sh -e

. ./utility_functions.sh

# Function to duplicate displays
duplicate_displays() {
primary=$(detect_connected_monitors | head -n 1)
for monitor in $(detect_connected_monitors | tail -n +2); do
if confirm_action "Duplicate $monitor to $primary?"; then
echo "Duplicating $monitor to $primary"
execute_command "xrandr --output $monitor --same-as $primary"
fi
done
primary=$(detect_connected_monitors | head -n 1)
for monitor in $(detect_connected_monitors | tail -n +2); do
if confirm_action "Duplicate $monitor to $primary?"; then
echo "Duplicating $monitor to $primary"
execute_command "xrandr --output $monitor --same-as $primary"
fi
done
}

duplicate_displays
7 changes: 4 additions & 3 deletions src/commands/utils/monitor-control/enable_monitor.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/bin/bash
source ./utility_functions.sh
#!/bin/sh -e

. ./utility_functions.sh

RESET='\033[0m'
BOLD='\033[1m'
Expand All @@ -12,7 +13,7 @@ CYAN='\033[36m'
# Function to enable a monitor
enable_monitor() {
monitor_list=$(detect_connected_monitors)
IFS=$'\n' read -r -d '' -a monitor_array <<<"$monitor_list"
IFS=$'\n' read -r -a monitor_array <<<"$monitor_list"

clear
echo -e "${BLUE}=========================================${RESET}"
Expand Down
5 changes: 3 additions & 2 deletions src/commands/utils/monitor-control/extend_displays.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/bin/bash
source ./utility_functions.sh
#!/bin/sh -e

. ./utility_functions.sh

# Function to extend displays
extend_displays() {
Expand Down
7 changes: 4 additions & 3 deletions src/commands/utils/monitor-control/manage_arrangement.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#!/bin/bash
source ./utility_functions.sh
#!/bin/sh -e

. ./utility_functions.sh

# Function to manage monitor arrangement
manage_arrangement() {
monitor_list=$(detect_connected_monitors)
IFS=$'\n' read -r -d '' -a monitor_array <<<"$monitor_list"
IFS=$'\n' read -r -a monitor_array <<<"$monitor_list"

clear
echo -e "${BLUE}=========================================${RESET}"
Expand Down
7 changes: 4 additions & 3 deletions src/commands/utils/monitor-control/reset_scaling.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/bin/bash
source ./utility_functions.sh
#!/bin/sh -e

. ./utility_functions.sh

# Function to reset scaling back to 1 (native resolution) for all monitors
reset_scaling() {
Expand All @@ -8,7 +9,7 @@ reset_scaling() {
echo -e "${BLUE}=========================================${RESET}"

monitor_list=$(detect_connected_monitors)
IFS=$'\n' read -r -d '' -a monitor_array <<<"$monitor_list"
IFS=$'\n' read -r -a monitor_array <<<"$monitor_list"

for monitor in "${monitor_array[@]}"; do
echo -e "${CYAN}Resetting scaling for $monitor to 1x1 (native resolution)${RESET}"
Expand Down
7 changes: 4 additions & 3 deletions src/commands/utils/monitor-control/scale_monitor.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/bin/bash
source ./utility_functions.sh
#!/bin/sh -e

. ./utility_functions.sh

# Function to scale smaller monitors to the highest resolution of a bigger monitor
scale_monitors() {
Expand All @@ -8,7 +9,7 @@ scale_monitors() {
echo -e "${BLUE}=========================================${RESET}"

monitor_list=$(detect_connected_monitors)
IFS=$'\n' read -r -d '' -a monitor_array <<<"$monitor_list"
IFS=$'\n' read -r -a monitor_array <<<"$monitor_list"

# Get the highest resolution among all monitors
max_width=0
Expand Down
7 changes: 4 additions & 3 deletions src/commands/utils/monitor-control/set_primary_monitor.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#!/bin/bash
source ./utility_functions.sh
#!/bin/sh -e

. ./utility_functions.sh

# Function to set a monitor as primary
set_primary_monitor() {
monitor_list=$(detect_connected_monitors)
IFS=$'\n' read -r -d '' -a monitor_array <<<"$monitor_list"
IFS=$'\n' read -r -a monitor_array <<<"$monitor_list"

clear
echo -e "${BLUE}=========================================${RESET}"
Expand Down
7 changes: 4 additions & 3 deletions src/commands/utils/monitor-control/set_resolutions.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/bin/bash
source ./utility_functions.sh
#!/bin/sh -e

. ./utility_functions.sh

RESET='\033[0m'
BOLD='\033[1m'
Expand All @@ -12,7 +13,7 @@ CYAN='\033[36m'
# Function to set resolutions
set_resolutions() {
monitor_list=$(detect_connected_monitors)
IFS=$'\n' read -r -d '' -a monitor_array <<<"$monitor_list"
IFS=$'\n' read -r -a monitor_array <<<"$monitor_list"

while true; do
clear
Expand Down
40 changes: 39 additions & 1 deletion src/commands/utils/monitor-control/utility_functions.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,39 @@
#!/bin/bash
#!/bin/sh -e

. ../../common-script.sh

# Function to check bluetoothctl is installed
setup_xrandr() {
echo "Install xrandr if not already installed..."
if ! command_exists xrandr; then
case ${PACKAGER} in
pacman)
$ESCALATION_TOOL "${PACKAGER}" -S --noconfirm xorg-xrandr
;;
apt-get)
$ESCALATION_TOOL "${PACKAGER}" install -y x11-xserver-utils
;;
*)
$ESCALATION_TOOL "${PACKAGER}" install -y xorg-x11-server-utils
;;
esac
else
echo "xrandr is already installed."
fi
}

# Function to display colored text
colored_echo() {
local color=$1
local text=$2
case $color in
red) echo -e "\033[31m$text\033[0m" ;;
green) echo -e "\033[32m$text\033[0m" ;;
yellow) echo -e "\033[33m$text\033[0m" ;;
blue) echo -e "\033[34m$text\033[0m" ;;
*) echo "$text" ;;
esac
}

# Function to execute xrandr commands and handle errors
execute_command() {
Expand Down Expand Up @@ -47,3 +82,6 @@ confirm_action() {
return 1
fi
}

checkEnv
setup_xrandr
4 changes: 0 additions & 4 deletions src/commands/utils/tab_data.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ matches = true
data = { environment = "DISPLAY" }
values = [":0", ":1", ":2", ":3", ":4", ":5", ":6", ":7", ":8", ":9"]

[[data.entries]]
name = "Set Resolution"
script = "monitor-control/set_resolutions.sh"

[[data.entries]]
name = "Duplicate Displays"
script = "monitor-control/duplicate_displays.sh"
Expand Down
37 changes: 35 additions & 2 deletions src/commands/utils/wifi-control.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,36 @@
@@ -0,0 +1,168 @@
#!/bin/bash
#!/bin/sh -e

. ../common-script.sh

# Function to check if NetworkManager is installed
setupNetworkManager() {
echo "Install NetworkManger if not already installed..."
if ! command_exists nmcli; then
case ${PACKAGER} in
pacman)
$ESCALATION_TOOL "${PACKAGER}" -S --noconfirm networkmanager
;;
dnf)
$ESCALATION_TOOL "${PACKAGER}" install -y NetworkManager-1
;;
*)
$ESCALATION_TOOL "${PACKAGER}" install -y network-manager
;;
esac
else
echo "NetworkManager is already installed."
fi

# Check if NetworkManager service is running
if ! systemctl is-active --quiet NetworkManager; then
echo "NetworkManager service is not running. Starting it now..."
$ESCALATION_TOOL systemctl start NetworkManager

if systemctl is-active --quiet NetworkManager; then
echo "NetworkManager service started successfully."
fi
fi
}

# Function to display colored text
colored_echo() {
Expand Down Expand Up @@ -166,4 +197,6 @@ remove_network() {
}

# Initialize
checkEnv
setupNetworkManager
main_menu

0 comments on commit d62f9ef

Please sign in to comment.