mirror of
https://github.com/ChrisTitusTech/linutil.git
synced 2024-11-28 15:56:02 +00:00
nixos support + graphical exit
This commit is contained in:
parent
bbe2f9eba2
commit
a8e6612a81
|
@ -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
|
||||
;;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
;;
|
||||
|
|
19
src/list.rs
19
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user