diff --git a/src/commands/dotfiles/alacritty-setup.sh b/src/commands/dotfiles/alacritty-setup.sh index 2e2156d4..ca897362 100755 --- a/src/commands/dotfiles/alacritty-setup.sh +++ b/src/commands/dotfiles/alacritty-setup.sh @@ -1,10 +1,61 @@ #!/bin/sh -e +RC='\033[0m' +RED='\033[31m' +YELLOW='\033[33m' +GREEN='\033[32m' + +command_exists() { + which $1 >/dev/null 2>&1 +} + checkEnv() { - checkCommandRequirements 'curl groups sudo' - checkPackageManager 'apt-get dnf pacman zypper' - checkSuperUser - checkDistro + ## Check for requirements. + REQUIREMENTS='curl groups sudo' + for req in ${REQUIREMENTS}; do + if ! command_exists ${req}; then + echo -e "${RED}To run me, you need: ${REQUIREMENTS}${RC}" + exit 1 + fi + done + + ## Check Package Handler + PACKAGEMANAGER='apt-get dnf pacman zypper nix-env' + for pgm in ${PACKAGEMANAGER}; do + if command_exists ${pgm}; then + PACKAGER=${pgm} + echo "Using ${pgm}" + break + fi + done + + if [ -z "${PACKAGER}" ]; then + echo -e "${RED}Can't find a supported package manager${RC}" + exit 1 + fi + + ## Check SuperUser Group + SUPERUSERGROUP='wheel sudo root' + for sug in ${SUPERUSERGROUP}; do + if groups | grep -q ${sug}; then + SUGROUP=${sug} + echo "Super user group ${SUGROUP}" + break + fi + done + + ## Check if member of the sudo group. + if ! groups | grep -q ${SUGROUP}; then + echo -e "${RED}You need to be a member of the sudo group to run me!${RC}" + exit 1 + fi + + DTYPE="unknown" # Default to unknown + # Use /etc/os-release for modern distro identification + if [ -f /etc/os-release ]; then + . /etc/os-release + DTYPE=$ID + fi } setupAlacritty() { @@ -14,6 +65,9 @@ setupAlacritty() { pacman) sudo ${PACKAGER} -S --noconfirm alacritty ;; + nix-env) + sudo ${PACKAGER} -iA nixos.alacritty + ;; *) sudo ${PACKAGER} install -y alacritty ;; @@ -31,4 +85,4 @@ setupAlacritty() { } checkEnv -setupAlacritty +setupAlacritty \ No newline at end of file diff --git a/src/commands/dotfiles/kitty-setup.sh b/src/commands/dotfiles/kitty-setup.sh index 131d1f9a..bef3692e 100755 --- a/src/commands/dotfiles/kitty-setup.sh +++ b/src/commands/dotfiles/kitty-setup.sh @@ -1,10 +1,61 @@ #!/bin/sh -e +RC='\033[0m' +RED='\033[31m' +YELLOW='\033[33m' +GREEN='\033[32m' + +command_exists() { + which $1 >/dev/null 2>&1 +} + checkEnv() { - checkCommandRequirements 'curl groups sudo' - checkPackageManager 'apt-get dnf pacman zypper' - checkSuperUser - checkDistro + ## Check for requirements. + REQUIREMENTS='curl groups sudo' + for req in ${REQUIREMENTS}; do + if ! command_exists ${req}; then + echo -e "${RED}To run me, you need: ${REQUIREMENTS}${RC}" + exit 1 + fi + done + + ## Check Package Handler + PACKAGEMANAGER='apt-get dnf pacman zypper nix-env' + for pgm in ${PACKAGEMANAGER}; do + if command_exists ${pgm}; then + PACKAGER=${pgm} + echo "Using ${pgm}" + break + fi + done + + if [ -z "${PACKAGER}" ]; then + echo -e "${RED}Can't find a supported package manager${RC}" + exit 1 + fi + + ## Check SuperUser Group + SUPERUSERGROUP='wheel sudo root' + for sug in ${SUPERUSERGROUP}; do + if groups | grep -q ${sug}; then + SUGROUP=${sug} + echo "Super user group ${SUGROUP}" + break + fi + done + + ## Check if member of the sudo group. + if ! groups | grep -q ${SUGROUP}; then + echo -e "${RED}You need to be a member of the sudo group to run me!${RC}" + exit 1 + fi + + DTYPE="unknown" # Default to unknown + # Use /etc/os-release for modern distro identification + if [ -f /etc/os-release ]; then + . /etc/os-release + DTYPE=$ID + fi } setupKitty() { @@ -12,10 +63,13 @@ setupKitty() { if ! command_exists kitty; then case ${PACKAGER} in pacman) - sudo "${PACKAGER}" -S --noconfirm kitty + sudo ${PACKAGER} -S --noconfirm kitty + ;; + nix-env) + sudo ${PACKAGER} -iA nixos.kitty ;; *) - sudo "${PACKAGER}" install -y kitty + sudo ${PACKAGER} install -y kitty ;; esac else @@ -23,11 +77,11 @@ setupKitty() { fi echo "Copy Kitty config files" if [ -d "${HOME}/.config/kitty" ]; then - cp -r "${HOME}"/.config/kitty "${HOME}"/.config/kitty-bak + cp -r ${HOME}/.config/kitty ${HOME}/.config/kitty-bak fi - mkdir -p "${HOME}"/.config/kitty/ - wget -O "${HOME}"/.config/kitty/kitty.conf https://github.com/ChrisTitusTech/dwm-titus/raw/main/config/kitty/kitty.conf - wget -O "${HOME}"/.config/kitty/nord.conf https://github.com/ChrisTitusTech/dwm-titus/raw/main/config/kitty/nord.conf + mkdir -p ${HOME}/.config/kitty/ + wget -O ${HOME}/.config/kitty/kitty.conf https://github.com/ChrisTitusTech/dwm-titus/raw/main/config/kitty/kitty.conf + wget -O ${HOME}/.config/kitty/nord.conf https://github.com/ChrisTitusTech/dwm-titus/raw/main/config/kitty/nord.conf } checkEnv diff --git a/src/commands/dotfiles/rofi-setup.sh b/src/commands/dotfiles/rofi-setup.sh index aab942ed..4d873f90 100755 --- a/src/commands/dotfiles/rofi-setup.sh +++ b/src/commands/dotfiles/rofi-setup.sh @@ -1,10 +1,61 @@ #!/bin/sh -e +RC='\033[0m' +RED='\033[31m' +YELLOW='\033[33m' +GREEN='\033[32m' + +command_exists() { + which "$1" >/dev/null 2>&1 +} + checkEnv() { - checkCommandRequirements 'curl groups sudo' - checkPackageManager 'apt-get dnf pacman zypper' - checkSuperUser - checkDistro + ## Check for requirements. + REQUIREMENTS='curl groups sudo' + for req in $REQUIREMENTS; do + if ! command_exists "$req"; then + echo -e "${RED}To run me, you need: ${REQUIREMENTS}${RC}" + exit 1 + fi + done + + ## Check Package Handler + PACKAGEMANAGER='apt-get dnf pacman zypper nix-env' + for pgm in $PACKAGEMANAGER; do + if command_exists "$pgm"; then + PACKAGER="$pgm" + echo "Using $pgm" + break + fi + done + + if [ -z "$PACKAGER" ]; then + echo -e "${RED}Can't find a supported package manager${RC}" + exit 1 + fi + + ## Check SuperUser Group + SUPERUSERGROUP='wheel sudo root' + for sug in $SUPERUSERGROUP; do + if groups | grep -q "$sug"; then + SUGROUP="$sug" + echo "Super user group $SUGROUP" + break + fi + done + + ## Check if member of the sudo group. + if ! groups | grep -q "$SUGROUP"; then + echo -e "${RED}You need to be a member of the sudo group to run me!${RC}\n" + exit 1 + fi + + DTYPE="unknown" # Default to unknown + # Use /etc/os-release for modern distro identification + if [ -f /etc/os-release ]; then + . /etc/os-release + DTYPE="$ID" + fi } setupRofi() { @@ -14,6 +65,9 @@ setupRofi() { pacman) sudo "$PACKAGER" -S --noconfirm rofi ;; + nix-env) + sudo "$PACKAGER" -iA nixos.rofi + ;; *) sudo "$PACKAGER" install -y rofi ;; diff --git a/src/list.rs b/src/list.rs index b564bdea..dfd2558b 100644 --- a/src/list.rs +++ b/src/list.rs @@ -8,6 +8,7 @@ use ratatui::{ widgets::{Block, Borders, List, ListState}, Frame, }; +use std::process::Command; macro_rules! with_common_script { ($command:expr) => { @@ -114,8 +115,13 @@ impl CustomList { ListNode { name: "Rofi Setup", command: with_common_script!("commands/dotfiles/rofi-setup.sh"), - }, - } + } + }, + ListNode { + name: "Exit", + command: "exit", + }, + }); // We don't get a reference, but rather an id, because references are siginficantly more // paintfull to manage @@ -371,7 +377,16 @@ impl CustomList { self.list_state.select(Some(0)); return None; } else { - return Some(node.value().command); + let command = node.value().command; + if command == "exit" { + // Run the clear command + //using reset instead of clear due to terminal buffer + Command::new("reset").status().expect("Failed to clear terminal"); + // Exit the application + std::process::exit(0); + } else { + return Some(command); + } } } }