nixos support + graphical exit

This commit is contained in:
guruswarupa 2024-07-24 15:53:12 +05:30
parent bbe2f9eba2
commit a8e6612a81
4 changed files with 199 additions and 22 deletions

View File

@ -1,10 +1,61 @@
#!/bin/sh -e #!/bin/sh -e
RC='\033[0m'
RED='\033[31m'
YELLOW='\033[33m'
GREEN='\033[32m'
command_exists() {
which $1 >/dev/null 2>&1
}
checkEnv() { checkEnv() {
checkCommandRequirements 'curl groups sudo' ## Check for requirements.
checkPackageManager 'apt-get dnf pacman zypper' REQUIREMENTS='curl groups sudo'
checkSuperUser for req in ${REQUIREMENTS}; do
checkDistro 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() { setupAlacritty() {
@ -14,6 +65,9 @@ setupAlacritty() {
pacman) pacman)
sudo ${PACKAGER} -S --noconfirm alacritty sudo ${PACKAGER} -S --noconfirm alacritty
;; ;;
nix-env)
sudo ${PACKAGER} -iA nixos.alacritty
;;
*) *)
sudo ${PACKAGER} install -y alacritty sudo ${PACKAGER} install -y alacritty
;; ;;

View File

@ -1,10 +1,61 @@
#!/bin/sh -e #!/bin/sh -e
RC='\033[0m'
RED='\033[31m'
YELLOW='\033[33m'
GREEN='\033[32m'
command_exists() {
which $1 >/dev/null 2>&1
}
checkEnv() { checkEnv() {
checkCommandRequirements 'curl groups sudo' ## Check for requirements.
checkPackageManager 'apt-get dnf pacman zypper' REQUIREMENTS='curl groups sudo'
checkSuperUser for req in ${REQUIREMENTS}; do
checkDistro 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() { setupKitty() {
@ -12,10 +63,13 @@ setupKitty() {
if ! command_exists kitty; then if ! command_exists kitty; then
case ${PACKAGER} in case ${PACKAGER} in
pacman) 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 esac
else else
@ -23,11 +77,11 @@ setupKitty() {
fi fi
echo "Copy Kitty config files" echo "Copy Kitty config files"
if [ -d "${HOME}/.config/kitty" ]; then 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 fi
mkdir -p "${HOME}"/.config/kitty/ 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/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 wget -O ${HOME}/.config/kitty/nord.conf https://github.com/ChrisTitusTech/dwm-titus/raw/main/config/kitty/nord.conf
} }
checkEnv checkEnv

View File

@ -1,10 +1,61 @@
#!/bin/sh -e #!/bin/sh -e
RC='\033[0m'
RED='\033[31m'
YELLOW='\033[33m'
GREEN='\033[32m'
command_exists() {
which "$1" >/dev/null 2>&1
}
checkEnv() { checkEnv() {
checkCommandRequirements 'curl groups sudo' ## Check for requirements.
checkPackageManager 'apt-get dnf pacman zypper' REQUIREMENTS='curl groups sudo'
checkSuperUser for req in $REQUIREMENTS; do
checkDistro 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() { setupRofi() {
@ -14,6 +65,9 @@ setupRofi() {
pacman) pacman)
sudo "$PACKAGER" -S --noconfirm rofi sudo "$PACKAGER" -S --noconfirm rofi
;; ;;
nix-env)
sudo "$PACKAGER" -iA nixos.rofi
;;
*) *)
sudo "$PACKAGER" install -y rofi sudo "$PACKAGER" install -y rofi
;; ;;

View File

@ -8,6 +8,7 @@ use ratatui::{
widgets::{Block, Borders, List, ListState}, widgets::{Block, Borders, List, ListState},
Frame, Frame,
}; };
use std::process::Command;
macro_rules! with_common_script { macro_rules! with_common_script {
($command:expr) => { ($command:expr) => {
@ -114,8 +115,13 @@ impl CustomList {
ListNode { ListNode {
name: "Rofi Setup", name: "Rofi Setup",
command: with_common_script!("commands/dotfiles/rofi-setup.sh"), 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 // We don't get a reference, but rather an id, because references are siginficantly more
// paintfull to manage // paintfull to manage
@ -371,7 +377,16 @@ impl CustomList {
self.list_state.select(Some(0)); self.list_state.select(Some(0));
return None; return None;
} else { } 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);
}
} }
} }
} }