diff --git a/core/src/inner.rs b/core/src/inner.rs index f23d21044..2452ac936 100644 --- a/core/src/inner.rs +++ b/core/src/inner.rs @@ -24,7 +24,9 @@ pub fn get_tabs(validate: bool) -> Vec { .map(|(TabEntry { name, data }, directory)| { let mut tree = Tree::new(ListNode { name: "root".to_string(), + raw_command: Command::None, command: Command::None, + revert_command: Command::None, }); let mut root = tree.root_mut(); create_directory(data, &mut root, &directory); @@ -146,22 +148,44 @@ fn create_directory(data: Vec, node: &mut NodeMut, command_dir: if let Some(entries) = entry.entries { let mut node = node.append(ListNode { name: entry.name, + raw_command: Command::None, command: Command::None, + revert_command: Command::None, }); create_directory(entries, &mut node, command_dir); } else if let Some(command) = entry.command { node.append(ListNode { name: entry.name, - command: Command::Raw(command), + raw_command: Command::Raw(command.clone()), + command: Command::Raw(command.clone()), + revert_command: Command::None, }); } else if let Some(script) = entry.script { - let dir = command_dir.join(script); + let dir = command_dir.join(script.clone()); if !dir.exists() { panic!("Script {} does not exist", dir.display()); } + + let cmd_path = dir.parent().unwrap(); + let script_name = dir.file_name().unwrap().to_str().unwrap(); + + // Commands for run and revert script functions + let cmd = Command::Raw(format!( + "cd {} && . ./{} && run", + cmd_path.display(), + script_name + )); + let rev_cmd = Command::Raw(format!( + "cd {} && . ./{} && revert", + cmd_path.display(), + script_name + )); + node.append(ListNode { name: entry.name, - command: Command::LocalFile(dir), + raw_command: Command::LocalFile(dir), // Raw path to the script -> Command + command: cmd, + revert_command: rev_cmd, }); } else { panic!("Entry must have data"); diff --git a/core/src/lib.rs b/core/src/lib.rs index 93ce0619e..c4b7ebae2 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -21,5 +21,7 @@ pub struct Tab { #[derive(Clone, Hash, Eq, PartialEq)] pub struct ListNode { pub name: String, + pub raw_command: Command, pub command: Command, + pub revert_command: Command, } diff --git a/tabs/applications-setup/alacritty-setup.sh b/tabs/applications-setup/alacritty-setup.sh index 09c9e8d01..b6540e53a 100755 --- a/tabs/applications-setup/alacritty-setup.sh +++ b/tabs/applications-setup/alacritty-setup.sh @@ -25,6 +25,41 @@ setupAlacritty() { curl -sSLo "${HOME}/.config/alacritty/nordic.toml" "https://github.com/ChrisTitusTech/dwm-titus/raw/main/config/alacritty/nordic.toml" } -checkEnv -checkEscalationTool -setupAlacritty \ No newline at end of file +revertAlacritty() { + echo "Reverting Alacritty configuration..." + if [ -d "${HOME}/.config/alacritty-bak" ]; then + rm -rf "${HOME}/.config/alacritty" + mv "${HOME}/.config/alacritty-bak" "${HOME}/.config/alacritty" + echo "Alacritty configuration reverted" + + if command_exists alacritty; then + printf "Do you want to uninstall Alacritty as well? (y/N): " + read uninstall_choice + if [ "$uninstall_choice" = "y" ] || [ "$uninstall_choice" = "Y" ]; then + case ${PACKAGER} in + pacman) + $ESCALATION_TOOL ${PACKAGER} -Rns --noconfirm alacritty + ;; + *) + $ESCALATION_TOOL ${PACKAGER} remove -y alacritty + ;; + esac + echo "Alacritty uninstalled." + fi + fi + else + echo "No Alacritty configuration found. Nothing to revert." + fi +} + +run() { + checkEnv + checkEscalationTool + setupAlacritty +} + +revert() { + checkEnv + checkEscalationTool + revertAlacritty +} \ No newline at end of file diff --git a/tabs/applications-setup/dwmtitus-setup.sh b/tabs/applications-setup/dwmtitus-setup.sh index be70f8c89..47c8631fa 100755 --- a/tabs/applications-setup/dwmtitus-setup.sh +++ b/tabs/applications-setup/dwmtitus-setup.sh @@ -261,9 +261,6 @@ setupDisplayManager() { ;; esac fi - - - } install_slstatus() { @@ -284,12 +281,23 @@ install_slstatus() { cd "$HOME" } -checkEnv -checkEscalationTool -setupDisplayManager -setupDWM -makeDWM -install_slstatus -install_nerd_font -clone_config_folders -configure_backgrounds \ No newline at end of file +revertDwmTitusSetup() { + echo "Reverting is not implemented for this script." +} + +run() { + checkEnv + checkEscalationTool + setupDisplayManager + setupDWM + makeDWM + install_slstatus + install_nerd_font + clone_config_folders + configure_backgrounds +} + +revert() { + checkEnv + revertDwmTitusSetup +} diff --git a/tabs/applications-setup/kitty-setup.sh b/tabs/applications-setup/kitty-setup.sh index 9baee95c3..fcecf8a9a 100755 --- a/tabs/applications-setup/kitty-setup.sh +++ b/tabs/applications-setup/kitty-setup.sh @@ -25,6 +25,43 @@ setupKitty() { curl -sSLo "${HOME}/.config/kitty/nord.conf" https://github.com/ChrisTitusTech/dwm-titus/raw/main/config/kitty/nord.conf } -checkEnv -checkEscalationTool -setupKitty +revertKitty() { + echo "Reverting Kitty configuration..." + CONFIG_DIR="${HOME}/.config/kitty" + + if [ -d "${CONFIG_DIR}" ]; then + rm -rf "${CONFIG_DIR}" + mv "${HOME}/.config/kitty-bak" "${HOME}/.config/kitty" + echo "Kitty configuration reverted." + + if command_exists kitty; then + printf "Do you want to uninstall Kitty as well? (y/N): " + read uninstall_choice + if [ "$uninstall_choice" = "y" ] || [ "$uninstall_choice" = "Y" ]; then + case ${PACKAGER} in + pacman) + $ESCALATION_TOOL "${PACKAGER}" -Rns --noconfirm kitty + ;; + *) + $ESCALATION_TOOL "${PACKAGER}" remove -y kitty + ;; + esac + echo "Kitty uninstalled." + fi + fi + else + echo "No Kitty configuration found. Nothing to revert." + fi +} + +run() { + checkEnv + checkEscalationTool + setupKitty +} + +revert() { + checkEnv + checkEscalationTool + revertKitty +} diff --git a/tabs/applications-setup/mybash-setup.sh b/tabs/applications-setup/mybash-setup.sh new file mode 100644 index 000000000..05dc2ad08 --- /dev/null +++ b/tabs/applications-setup/mybash-setup.sh @@ -0,0 +1,155 @@ +#!/bin/sh -e + +. ../common-script.sh + +gitpath="$HOME/.local/share/mybash" + +cloneMyBash() { + # Check if the dir exists before attempting to clone into it. + if [ -d "$gitpath" ]; then + rm -rf "$gitpath" + fi + mkdir -p "$HOME/.local/share" # Only create the dir if it doesn't exist. + cd "$HOME" && git clone https://github.com/ChrisTitusTech/mybash.git "$gitpath" +} + +installDepend() { + echo "Install mybash if not already installed" + case "$PACKAGER" in + pacman) + $ESCALATION_TOOL "$PACKAGER" -S --needed --noconfirm bash bash-completion tar bat tree unzip fontconfig + ;; + apt) + $ESCALATION_TOOL "$PACKAGER" install -y bash bash-completion tar bat tree unzip fontconfig + ;; + dnf) + $ESCALATION_TOOL "$PACKAGER" install -y bash bash-completion tar bat tree unzip fontconfig + ;; + zypper) + $ESCALATION_TOOL "$PACKAGER" install -y bash bash-completion tar bat tree unzip fontconfig + ;; + *) + printf "%b\n" "${RED}Unsupported package manager: $PACKAGER${RC}" # The packages above were grabbed out of the original mybash-setup-script. + exit 1 + ;; + esac +} + +installFont() { + # Check to see if the MesloLGS Nerd Font is installed (Change this to whatever font you would like) + FONT_NAME="MesloLGS Nerd Font Mono" + if fc-list :family | grep -iq "$FONT_NAME"; then + echo "Font '$FONT_NAME' is installed." + else + echo "Installing font '$FONT_NAME'" + # Change this URL to correspond with the correct font + FONT_URL="https://github.com/ryanoasis/nerd-fonts/releases/latest/download/Meslo.zip" + FONT_DIR="$HOME/.local/share/fonts" + TEMP_DIR=$(mktemp -d) + curl -sSLo "$TEMP_DIR"/"${FONT_NAME}".zip "$FONT_URL" + unzip "$TEMP_DIR"/"${FONT_NAME}".zip -d "$TEMP_DIR" + mkdir -p "$FONT_DIR"/"$FONT_NAME" + mv "${TEMP_DIR}"/*.ttf "$FONT_DIR"/"$FONT_NAME" + fc-cache -fv + rm -rf "${TEMP_DIR}" + echo "'$FONT_NAME' installed successfully." + fi +} + +installStarshipAndFzf() { + if command_exists starship; then + echo "Starship already installed" + return + fi + + if ! curl -sSL https://starship.rs/install.sh | sh; then + printf "%b\n" "${RED}Something went wrong during starship install!${RC}" + exit 1 + fi + if command_exists fzf; then + echo "Fzf already installed" + else + git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf + $ESCALATION_TOOL ~/.fzf/install + fi +} + +installZoxide() { + if command_exists zoxide; then + echo "Zoxide already installed" + return + fi + + if ! curl -sSL https://raw.githubusercontent.com/ajeetdsouza/zoxide/main/install.sh | sh; then + printf "%b\n" "${RED}Something went wrong during zoxide install!${RC}" + exit 1 + fi +} + +linkConfig() { + OLD_BASHRC="$HOME/.bashrc" + if [ -e "$OLD_BASHRC" ] && [ ! -e "$HOME/.bashrc.bak" ]; then + printf "%b\n" "${YELLOW}Moving old bash config file to $HOME/.bashrc.bak${RC}" + if ! mv "$OLD_BASHRC" "$HOME/.bashrc.bak"; then + printf "%b\n" "${RED}Can't move the old bash config file!${RC}" + exit 1 + fi + fi + + printf "%b\n" "${YELLOW}Linking new bash config file...${RC}" + ln -svf "$gitpath/.bashrc" "$HOME/.bashrc" || { + printf "%b\n" "${RED}Failed to create symbolic link for .bashrc${RC}" + exit 1 + } + ln -svf "$gitpath/starship.toml" "$HOME/.config/starship.toml" || { + printf "%b\n" "${RED}Failed to create symbolic link for starship.toml${RC}" + exit 1 + } + printf "%b\n" "${GREEN}Done! restart your shell to see the changes.${RC}" +} + +revertMybash() { + OLD_BASHRC="$HOME/.bashrc.bak" + + if [ ! -f "$OLD_BASHRC" ]; then + printf "%b\n" "${RED}Backup not found. Failed to revert changes.${RC}" + exit 1 + fi + + if [ -d "$gitpath" ]; then + rm -rf "$gitpath" + fi + + printf "%b\n" "${YELLOW}Removing mybash files${RC}" + if ! rm "$HOME/.bashrc"; then + printf "%b\n" "${RED}Failed to remove $HOME/.bashrc${RC}" + fi + if ! rm "$HOME/.config/starship.toml"; then + printf "%b\n" "${RED}Failed to remove $HOME/.config/starship.toml${RC}" + fi + + printf "%b\n" "${YELLOW}Moving back old bash config file to $HOME/.bashrc${RC}" + if ! mv "$OLD_BASHRC" "$HOME/.bashrc"; then + printf "%b\n" "${RED}Can't move the old bash config file!${RC}" + exit 1 + fi + + printf "%b\n" "${GREEN}Done! restart your shell to see the changes.${RC}" +} + +run() { + checkEnv + checkEscalationTool + cloneMyBash + installDepend + installFont + installStarshipAndFzf + installZoxide + linkConfig +} + +revert() { + checkEnv + checkEscalationTool + revertMybash +} \ No newline at end of file diff --git a/tabs/applications-setup/neovim-setup.sh b/tabs/applications-setup/neovim-setup.sh new file mode 100755 index 000000000..9836aeb40 --- /dev/null +++ b/tabs/applications-setup/neovim-setup.sh @@ -0,0 +1,89 @@ +#!/bin/sh -e + +. ../common-script.sh + +gitpath="$HOME/.local/share/neovim" + +cloneNeovim() { + # Check if the dir exists before attempting to clone into it. + if [ -d "$gitpath" ]; then + rm -rf "$gitpath" + fi + mkdir -p "$HOME/.local/share" # Only create the dir if it doesn't exist. + cd "$HOME" && git clone https://github.com/ChrisTitusTech/neovim.git "$HOME/.local/share/neovim" +} + +setupNeovim() { + echo "Install Neovim if not already installed" + case "$PACKAGER" in + pacman) + $ESCALATION_TOOL "$PACKAGER" -S --needed --noconfirm neovim ripgrep fzf python-virtualenv luarocks go shellcheck + ;; + apt) + $ESCALATION_TOOL "$PACKAGER" install -y neovim ripgrep fd-find python3-venv luarocks golang-go shellcheck + ;; + dnf) + $ESCALATION_TOOL "$PACKAGER" install -y neovim ripgrep fzf python3-virtualenv luarocks golang ShellCheck + ;; + zypper) + $ESCALATION_TOOL "$PACKAGER" install -y neovim ripgrep fzf python3-virtualenv luarocks golang ShellCheck + ;; + *) + printf "%b\n" "${RED}Unsupported package manager: $PACKAGER${RC}" # The packages above were grabbed out of the original nvim-setup-script. + exit 1 + ;; + esac +} + +backupNeovimConfig() { + if [ -d "$HOME/.config/nvim" ] && [ ! -d "$HOME/.config/nvim-backup" ]; then + cp -r "$HOME/.config/nvim" "$HOME/.config/nvim-backup" + fi + rm -rf "$HOME/.config/nvim" +} + +linkNeovimConfig() { + mkdir -p "$HOME/.config/nvim" + ln -s "$gitpath/titus-kickstart/"* "$HOME/.config/nvim/" # Wild card is used here to link all contents of titus-kickstart. +} + +revertNeovimSetup() { + OLD_CONFIG="$HOME/.config/nvim-backup" + + if [ ! -d "$OLD_CONFIG" ]; then + printf "%b\n" "${RED}Backup not found. Failed to revert changes.${RC}" + exit 1 + fi + + if [ -d "$gitpath" ]; then + rm -rf "$gitpath" + fi + + printf "%b\n" "${YELLOW}Removing created nvim files${RC}" + if ! rm -rf "$HOME/.config/nvim"; then + printf "%b\n" "${RED}Failed to remove $HOME/.config/nvim${RC}" + fi + + printf "%b\n" "${YELLOW}Moving back old config files to $HOME/.config/nvim${RC}" + if ! mv "$OLD_CONFIG" "$HOME/.config/nvim"; then + printf "%b\n" "${RED}Can't move config files!${RC}" + exit 1 + fi + + printf "%b\n" "${GREEN}Done! restart your shell to see the changes.${RC}" +} + +run() { + checkEnv + checkEscalationTool + cloneNeovim + setupNeovim + backupNeovimConfig + linkNeovimConfig +} + +revert() { + checkEnv + checkEscalationTool + revertNeovimSetup +} \ No newline at end of file diff --git a/tabs/applications-setup/rofi-setup.sh b/tabs/applications-setup/rofi-setup.sh index ef4fe2325..cbabea6bb 100755 --- a/tabs/applications-setup/rofi-setup.sh +++ b/tabs/applications-setup/rofi-setup.sh @@ -30,6 +30,43 @@ setupRofi() { curl -sSLo "$HOME/.config/rofi/themes/powermenu.rasi" https://github.com/ChrisTitusTech/dwm-titus/raw/main/config/rofi/themes/powermenu.rasi } -checkEnv -checkEscalationTool -setupRofi +revertRofi() { + echo "Reverting Rofi configuration..." + CONFIG_DIR="$HOME/.config/rofi" + + if [ -d "${CONFIG_DIR}" ]; then + rm -rf "$CONFIG_DIR" + mv "${HOME}/.config/rofi-bak" "${HOME}/.config/rofi" + echo "Rofi configuration reverted." + + if command_exists rofi; then + printf "Do you want to uninstall Rofi as well? (y/N): " + read uninstall_choice + if [ "$uninstall_choice" = "y" ] || [ "$uninstall_choice" = "Y" ]; then + case ${PACKAGER} in + pacman) + $ESCALATION_TOOL ${PACKAGER} -Rns --noconfirm rofi + ;; + *) + $ESCALATION_TOOL ${PACKAGER} remove -y rofi + ;; + esac + echo "Rofi uninstalled." + fi + fi + else + echo "No Rofi configuration found. Nothing to revert." + fi +} + +run() { + checkEnv + checkEscalationTool + setupRofi +} + +revert() { + checkEnv + checkEscalationTool + revertRofi +} \ No newline at end of file diff --git a/tabs/applications-setup/tab_data.toml b/tabs/applications-setup/tab_data.toml index 2ad738920..39cbd30ed 100644 --- a/tabs/applications-setup/tab_data.toml +++ b/tabs/applications-setup/tab_data.toml @@ -6,7 +6,7 @@ script = "alacritty-setup.sh" [[data]] name = "Bash Prompt" -command = "bash -c \"$(curl -s https://raw.githubusercontent.com/ChrisTitusTech/mybash/main/setup.sh)\"" +script = "mybash-setup.sh" [[data]] name = "DWM-Titus" @@ -18,7 +18,7 @@ script = "kitty-setup.sh" [[data]] name = "Neovim" -command = "bash -c \"$(curl -s https://raw.githubusercontent.com/ChrisTitusTech/neovim/main/setup.sh)\"" +script = "neovim-setup.sh" [[data]] name = "Rofi" diff --git a/tabs/applications-setup/zsh-setup.sh b/tabs/applications-setup/zsh-setup.sh index eaa608b5f..d739251e8 100644 --- a/tabs/applications-setup/zsh-setup.sh +++ b/tabs/applications-setup/zsh-setup.sh @@ -46,7 +46,43 @@ EOL echo 'export ZDOTDIR="$HOME/.config/zsh"' | $ESCALATION_TOOL tee -a /etc/zsh/zshenv } -checkEnv -checkEscalationTool -install_zsh -setup_zsh_config +revertZSH() { + echo "Reverting ZSH configuration..." + CONFIG_DIR="$HOME/.config/zsh" + + if [ -d "${CONFIG_DIR}" ]; then + rm -rf "$CONFIG_DIR" + echo "ZSH configuration reverted." + + if command_exists zsh; then + printf "Do you want to uninstall ZSH as well? (y/N): " + read uninstall_choice + if [ "$uninstall_choice" = "y" ] || [ "$uninstall_choice" = "Y" ]; then + case ${PACKAGER} in + pacman) + $ESCALATION_TOOL ${PACKAGER} -Rns --noconfirm zsh + ;; + *) + $ESCALATION_TOOL ${PACKAGER} remove -y zsh + ;; + esac + echo "ZSH uninstalled." + fi + fi + else + echo "No ZSH configuration found. Nothing to revert." + fi +} + +run() { + checkEnv + checkEscalationTool + install_zsh + setup_zsh_config +} + +revert() { + checkEnv + checkEscalationTool + revertZSH +} \ No newline at end of file diff --git a/tabs/gaming/diablo-ii/d2r-loot-filters.sh b/tabs/gaming/diablo-ii/d2r-loot-filters.sh index 1fa43fabd..2d4ed2cde 100755 --- a/tabs/gaming/diablo-ii/d2r-loot-filters.sh +++ b/tabs/gaming/diablo-ii/d2r-loot-filters.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/bin/sh -e # Search for possible Diablo II Resurrected folder locations echo "Searching for Diablo II Resurrected folders..." @@ -70,9 +70,6 @@ select_path() { clear # Clear the screen after selection } -# Use the select_path function -select_path - # Validate the path if [ ! -d "$d2r_path" ]; then echo "Error: The specified path does not exist." @@ -106,4 +103,19 @@ echo "4. Select 'Game Settings'" echo "5. In the 'Additional command line arguments' field, enter: -mod lootfilter -txt" echo "6. Click 'Done' to save the changes" echo -echo "After completing these steps, launch Diablo II: Resurrected through Battle.net to use the loot filter." \ No newline at end of file +echo "After completing these steps, launch Diablo II: Resurrected through Battle.net to use the loot filter." + +# I don't play diablo II, If someone could implement this for me that would be great. +revertD2rLootFilterSetup() { + echo "Reverting is not implemented for this script." +} + +run() { + checkEnv + select_path +} + +revert() { + checkEnv + revertD2rLootFilterSetup +} \ No newline at end of file diff --git a/tabs/security/firewall-baselines.sh b/tabs/security/firewall-baselines.sh index 5abb0c766..dc30afe4f 100644 --- a/tabs/security/firewall-baselines.sh +++ b/tabs/security/firewall-baselines.sh @@ -43,7 +43,41 @@ configureUFW() { printf "%b\n" "${GREEN}Enabled Firewall with Baselines!${RC}" } -checkEnv -checkEscalationTool -installPkg -configureUFW +revertFirewall() { + echo "Reverting firewall baselines..." + + $ESCALATION_TOOL ufw disable + echo "UFW disabled." + + $ESCALATION_TOOL ufw reset + echo "UFW rules reset to default." + + if command_exists ufw; then + printf "Do you want to uninstall UFW as well? (y/N): " + read uninstall_choice + if [ "$uninstall_choice" = "y" ] || [ "$uninstall_choice" = "Y" ]; then + case ${PACKAGER} in + pacman) + $ESCALATION_TOOL ${PACKAGER} -Rns --noconfirm ufw + ;; + *) + $ESCALATION_TOOL ${PACKAGER} remove -y ufw + ;; + esac + echo "UFW uninstalled." + fi + fi +} + +run() { + checkEnv + checkEscalationTool + installPkg + configureUFW +} + +revert() { + checkEnv + checkEscalationTool + revertFirewall +} \ No newline at end of file diff --git a/tabs/system-setup/1-compile-setup.sh b/tabs/system-setup/1-compile-setup.sh index a9d21890d..ca2deb120 100755 --- a/tabs/system-setup/1-compile-setup.sh +++ b/tabs/system-setup/1-compile-setup.sh @@ -43,28 +43,18 @@ installDepend() { esac } -install_additional_dependencies() { - case $(command -v apt || command -v zypper || command -v dnf || command -v pacman) in - *apt) - # Add additional dependencies for apt if needed - ;; - *zypper) - # Add additional dependencies for zypper if needed - ;; - *dnf) - # Add additional dependencies for dnf if needed - ;; - *pacman) - # Add additional dependencies for pacman if needed - ;; - *) - # Add additional dependencies for other package managers if needed - ;; - esac +revertCompileSetup() { + echo "Reverting is not implemented for this script." +} + +run() { + checkEnv + checkAURHelper + checkEscalationTool + installDepend } -checkEnv -checkAURHelper -checkEscalationTool -installDepend -install_additional_dependencies \ No newline at end of file +revert() { + checkEnv + revertCompileSetup +} \ No newline at end of file diff --git a/tabs/system-setup/3-global-theme.sh b/tabs/system-setup/3-global-theme.sh index c3e360da5..5b4e66757 100644 --- a/tabs/system-setup/3-global-theme.sh +++ b/tabs/system-setup/3-global-theme.sh @@ -28,7 +28,10 @@ install_theme_tools() { } configure_qt6ct() { - printf "%b\n" "${YELLOW}Configuring qt6ct...${RC}\n" + printf "${YELLOW}Configuring qt6ct...${RC}\n" + if [ -d "${HOME}/.config/qt6ct" ] && [ ! -d "${HOME}/.config/qt6ct-bak" ]; then + cp -r "${HOME}/.config/qt6ct" "${HOME}/.config/qt6ct-bak" + fi mkdir -p "$HOME/.config/qt6ct" cat < "$HOME/.config/qt6ct/qt6ct.conf" [Appearance] @@ -49,7 +52,10 @@ EOF } configure_kvantum() { - printf "%b\n" "${YELLOW}Configuring Kvantum...${RC}\n" + printf "${YELLOW}Configuring Kvantum...${RC}\n" + if [ -d "${HOME}/.config/Kvantum" ] && [ ! -d "${HOME}/.config/Kvantum-bak" ]; then + cp -r "${HOME}/.config/Kvantum" "${HOME}/.config/Kvantum-bak" + fi mkdir -p "$HOME/.config/Kvantum" cat < "$HOME/.config/Kvantum/kvantum.kvconfig" [General] @@ -58,8 +64,52 @@ EOF printf "%b\n" "${GREEN}Kvantum configured successfully.${RC}\n" } -checkEnv -checkEscalationTool -install_theme_tools -configure_qt6ct -configure_kvantum +revertGlobalTheme() { + echo "Reverting global theme setup..." + + if [ -d "$HOME/.config/qt6ct-bak" ]; then + rm -rf "$HOME/.config/qt6ct" + mv "$HOME/.config/qt6ct-bak" "$HOME/.config/qt6ct" + echo "qt6ct configuration reverted." + else + echo "No qt6ct configuration found. Nothing to revert." + fi + + if [ -d "$HOME/.config/Kvantum-bak" ]; then + rm -rf "$HOME/.config/Kvantum" + mv "$HOME/.config/Kvantum-bak" "$HOME/.config/Kvantum" + echo "Kvantum configuration reverted." + else + echo "No Kvantum configuration found. Nothing to revert." + fi + + if command_exists qt6ct || command_exists kvantum; then + printf "Do you want to uninstall the theme tools as well? (y/N): " + read uninstall_choice + if [ "$uninstall_choice" = "y" ] || [ "$uninstall_choice" = "Y" ]; then + case $PACKAGER in + pacman) + $ESCALATION_TOOL ${PACKAGER} -Rns --noconfirm qt6ct kvantum + ;; + *) + $ESCALATION_TOOL ${PACKAGER} remove -y qt6ct kvantum + ;; + esac + echo "Theme tools uninstalled." + fi + fi +} + +run() { + checkEnv + checkEscalationTool + install_theme_tools + configure_qt6ct + configure_kvantum +} + +revert() { + checkEnv + checkEscalationTool + revertGlobalTheme +} \ No newline at end of file diff --git a/tabs/system-setup/4-remove-snaps.sh b/tabs/system-setup/4-remove-snaps.sh index f804aa5b8..2fd80c932 100644 --- a/tabs/system-setup/4-remove-snaps.sh +++ b/tabs/system-setup/4-remove-snaps.sh @@ -2,11 +2,9 @@ . ../common-script.sh +# Snapd is not a valid package on Arch. removeSnaps() { case $PACKAGER in - pacman) - $ESCALATION_TOOL ${PACKAGER} -Rns snapd - ;; apt-get|nala) $ESCALATION_TOOL ${PACKAGER} autoremove --purge snapd if [ "$ID" = ubuntu ]; then @@ -20,11 +18,37 @@ removeSnaps() { $ESCALATION_TOOL ${PACKAGER} remove snapd ;; *) - echo "Removing snapd not implemented for this package manager" + echo "Removing snapd is not implemented for this package manager" ;; esac } -checkEnv -checkEscalationTool -removeSnaps +revertSnapRemoval() { + echo "Reverting snapd removal..." + case $PACKAGER in + apt-get|nala) + $ESCALATION_TOOL ${PACKAGER} install -y snapd + ;; + dnf) + $ESCALATION_TOOL ${PACKAGER} install snapd + ;; + zypper) + $ESCALATION_TOOL ${PACKAGER} install snapd + ;; + *) + echo "Reverting snapd is not implemented for this package manager" + ;; + esac +} + +run() { + checkEnv + checkEscalationTool + removeSnaps +} + +revert() { + checkEnv + checkEscalationTool + revertSnapRemoval +} \ No newline at end of file diff --git a/tabs/system-setup/fedora/rpm-fusion-setup.sh b/tabs/system-setup/fedora/rpm-fusion-setup.sh index 52396d5df..deb0710c0 100644 --- a/tabs/system-setup/fedora/rpm-fusion-setup.sh +++ b/tabs/system-setup/fedora/rpm-fusion-setup.sh @@ -22,5 +22,17 @@ installRPMFusion() { esac } -checkEnv -installRPMFusion +# Not sure how to implement reverting rpm-fusion, I will look back into this in the future. +revertRpmFusionSetup() { + echo "Reverting is not implemented for this script." +} + +run() { + checkEnv + installRPMFusion +} + +revert() { + checkEnv + revertRpmFusionSetup +} \ No newline at end of file diff --git a/tabs/system-setup/system-update.sh b/tabs/system-setup/system-update.sh index e6b32af6d..b4a5610a0 100755 --- a/tabs/system-setup/system-update.sh +++ b/tabs/system-setup/system-update.sh @@ -95,9 +95,20 @@ updateFlatpaks() { fi } -checkEnv -checkAURHelper -checkEscalationTool -fastUpdate -updateSystem -updateFlatpaks \ No newline at end of file +revertSystemUpdate() { + echo "Reverting is not implemented for this script." +} + +run() { + checkEnv + checkAURHelper + checkEscalationTool + fastUpdate + updateSystem + updateFlatpaks +} + +revert() { + checkEnv + revertSystemUpdate +} \ No newline at end of file diff --git a/tabs/utils/bluetooth-control.sh b/tabs/utils/bluetooth-control.sh index 508d3708a..e4fc8e515 100644 --- a/tabs/utils/bluetooth-control.sh +++ b/tabs/utils/bluetooth-control.sh @@ -145,7 +145,17 @@ remove_device() { prompt_for_mac "remove" "remove" "Enter the number of the device to remove: " "Removing device completed." "Failed to remove device." } -# Initialize -checkEnv -setupBluetooth -main_menu +revertBluetoothControl() { + echo "Reverting is not implemented for this script." +} + +run() { + checkEnv + setupBluetooth + main_menu +} + +revert() { + checkEnv + revertBluetoothControl +} \ No newline at end of file diff --git a/tabs/utils/monitor-control/auto_detect_displays.sh b/tabs/utils/monitor-control/auto_detect_displays.sh index 175ed4dda..d9c43a5f4 100755 --- a/tabs/utils/monitor-control/auto_detect_displays.sh +++ b/tabs/utils/monitor-control/auto_detect_displays.sh @@ -40,4 +40,16 @@ auto_detect_displays() { fi } -auto_detect_displays +revertAutoDetectDisplays() { + echo "Reverting is not implemented for this script." +} + +run() { + checkEnv + auto_detect_displays +} + +revert() { + checkEnv + revertAutoDetectDisplays +} \ No newline at end of file diff --git a/tabs/utils/monitor-control/change_orientation.sh b/tabs/utils/monitor-control/change_orientation.sh index 8d8679659..96a1fcdc7 100755 --- a/tabs/utils/monitor-control/change_orientation.sh +++ b/tabs/utils/monitor-control/change_orientation.sh @@ -58,5 +58,16 @@ change_orientation() { fi } -# Call the change_orientation function -change_orientation +revertChangeOrientation() { + echo "Reverting is not implemented for this script." +} + +run() { + checkEnv + change_orientation +} + +revert() { + checkEnv + revertChangeOrientation +} \ No newline at end of file diff --git a/tabs/utils/monitor-control/disable_monitor.sh b/tabs/utils/monitor-control/disable_monitor.sh index a1eafc527..c0fd85ca5 100755 --- a/tabs/utils/monitor-control/disable_monitor.sh +++ b/tabs/utils/monitor-control/disable_monitor.sh @@ -52,5 +52,16 @@ confirm_action() { fi } -# Call the disable_monitor function -disable_monitor +revertDisableMonitor() { + echo "Reverting is not implemented for this script." +} + +run() { + checkEnv + disable_monitor +} + +revert() { + checkEnv + revertDisableMonitor +} \ No newline at end of file diff --git a/tabs/utils/monitor-control/duplicate_displays.sh b/tabs/utils/monitor-control/duplicate_displays.sh index aee3a15f8..a9fbb12ba 100755 --- a/tabs/utils/monitor-control/duplicate_displays.sh +++ b/tabs/utils/monitor-control/duplicate_displays.sh @@ -15,4 +15,16 @@ duplicate_displays() { done } -duplicate_displays +revertDuplicateDisplays() { + echo "Reverting is not implemented for this script." +} + +run() { + checkEnv + duplicate_displays +} + +revert() { + checkEnv + revertDuplicateDisplays +} \ No newline at end of file diff --git a/tabs/utils/monitor-control/enable_monitor.sh b/tabs/utils/monitor-control/enable_monitor.sh index 6d6ec5b63..60be98d85 100755 --- a/tabs/utils/monitor-control/enable_monitor.sh +++ b/tabs/utils/monitor-control/enable_monitor.sh @@ -39,5 +39,16 @@ enable_monitor() { fi } -# Call the enable_monitor function -enable_monitor +revertEnableMonitor() { + echo "Reverting is not implemented for this script." +} + +run() { + checkEnv + enable_monitor +} + +revert() { + checkEnv + revertEnableMonitor +} \ No newline at end of file diff --git a/tabs/utils/monitor-control/extend_displays.sh b/tabs/utils/monitor-control/extend_displays.sh index dca8a1b23..b22b95810 100755 --- a/tabs/utils/monitor-control/extend_displays.sh +++ b/tabs/utils/monitor-control/extend_displays.sh @@ -21,4 +21,16 @@ extend_displays() { done } -extend_displays +revertExtendDisplays() { + echo "Reverting is not implemented for this script." +} + +run() { + checkEnv + extend_displays +} + +revert() { + checkEnv + revertExtendDisplays +} \ No newline at end of file diff --git a/tabs/utils/monitor-control/manage_arrangement.sh b/tabs/utils/monitor-control/manage_arrangement.sh index 268b930f0..db29ed192 100755 --- a/tabs/utils/monitor-control/manage_arrangement.sh +++ b/tabs/utils/monitor-control/manage_arrangement.sh @@ -71,5 +71,16 @@ manage_arrangement() { fi } -# Call the manage_arrangement function -manage_arrangement +revertManageArrangement() { + echo "Reverting is not implemented for this script." +} + +run() { + checkEnv + manage_arrangement +} + +revert() { + checkEnv + revertManageArrangement +} \ No newline at end of file diff --git a/tabs/utils/monitor-control/reset_scaling.sh b/tabs/utils/monitor-control/reset_scaling.sh index ffca6c1b1..a89eb786d 100755 --- a/tabs/utils/monitor-control/reset_scaling.sh +++ b/tabs/utils/monitor-control/reset_scaling.sh @@ -21,5 +21,16 @@ Reset_scaling() { printf "%b\n" "${GREEN}All monitor scalings have been Reset to 1x1.${RC}" } -# Call the Reset_scaling function -Reset_scaling +revertResetScaling() { + echo "Reverting is not implemented for this script." +} + +run() { + checkEnv + reset_scaling +} + +revert() { + checkEnv + revertResetScaling +} diff --git a/tabs/utils/monitor-control/scale_monitor.sh b/tabs/utils/monitor-control/scale_monitor.sh index ac386d777..139c508d7 100755 --- a/tabs/utils/monitor-control/scale_monitor.sh +++ b/tabs/utils/monitor-control/scale_monitor.sh @@ -40,5 +40,16 @@ scale_monitors() { printf "%b\n" "${GREEN}Scaling complete. All monitors are now scaled to ${max_width}x${max_height}.${RC}" } -# Call the scale_monitors function -scale_monitors +revertScaleMonitor() { + echo "Reverting is not implemented for this script." +} + +run() { + checkEnv + scale_monitors +} + +revert() { + checkEnv + revertScaleMonitor +} \ No newline at end of file diff --git a/tabs/utils/monitor-control/set_primary_monitor.sh b/tabs/utils/monitor-control/set_primary_monitor.sh index 143a8379d..08271a76e 100755 --- a/tabs/utils/monitor-control/set_primary_monitor.sh +++ b/tabs/utils/monitor-control/set_primary_monitor.sh @@ -38,5 +38,16 @@ set_primary_monitor() { fi } -# Call the set_primary_monitor function -set_primary_monitor +revertSetPrimaryMonitor() { + echo "Reverting is not implemented for this script." +} + +run() { + checkEnv + set_primary_monitor +} + +revert() { + checkEnv + revertSetPrimaryMonitor +} \ No newline at end of file diff --git a/tabs/utils/monitor-control/set_resolutions.sh b/tabs/utils/monitor-control/set_resolutions.sh index 1a6c6fa71..077615ba9 100755 --- a/tabs/utils/monitor-control/set_resolutions.sh +++ b/tabs/utils/monitor-control/set_resolutions.sh @@ -84,4 +84,16 @@ set_resolutions() { done } -set_resolutions +revertSetResolutions() { + echo "Reverting is not implemented for this script." +} + +run() { + checkEnv + setup_xrandr +} + +revert() { + checkEnv + revertSetResolutions +} \ No newline at end of file diff --git a/tabs/utils/monitor-control/utility_functions.sh b/tabs/utils/monitor-control/utility_functions.sh index 48b4c8da9..5ecac7c00 100755 --- a/tabs/utils/monitor-control/utility_functions.sh +++ b/tabs/utils/monitor-control/utility_functions.sh @@ -82,5 +82,16 @@ confirm_action() { fi } -checkEnv -setup_xrandr \ No newline at end of file +revertUtilityFunctions() { + echo "Reverting is not implemented for this script." +} + +run() { + checkEnv + setup_xrandr +} + +revert() { + checkEnv + revertUtilityFunctions +} \ No newline at end of file diff --git a/tabs/utils/numlock.sh b/tabs/utils/numlock.sh index 2b23c3f16..053fceff8 100755 --- a/tabs/utils/numlock.sh +++ b/tabs/utils/numlock.sh @@ -60,5 +60,17 @@ numlockSetup() { fi } -checkEscalationTool -numlockSetup +revertNumlockSetup() { + echo "Reverting is not implemented for this script." +} + +run() { + checkEnv + checkEscalationTool + numlockSetup +} + +revert() { + checkEnv + revertNumlockSetup +} \ No newline at end of file diff --git a/tabs/utils/wifi-control.sh b/tabs/utils/wifi-control.sh index 036e2a28c..fce4369dc 100644 --- a/tabs/utils/wifi-control.sh +++ b/tabs/utils/wifi-control.sh @@ -184,7 +184,17 @@ remove_network() { prompt_for_network "remove" "Enter the number of the network to remove: " "Network removed successfully." "Failed to remove the network." } -# Initialize -checkEnv -setupNetworkManager -main_menu +revertWifiControl() { + echo "Reverting is not implemented for this script." +} + +run() { + checkEnv + setupNetworkManager + main_menu +} + +revert() { + checkEnv + revertWifiControl +} \ No newline at end of file diff --git a/tui/src/hint.rs b/tui/src/hint.rs index 27474ea99..8fe243631 100644 --- a/tui/src/hint.rs +++ b/tui/src/hint.rs @@ -100,12 +100,25 @@ impl Shortcut { } } -fn get_list_item_shortcut(state: &AppState) -> Shortcut { +fn push_item_shortcut(mut hints: Vec, state: &AppState) -> Vec { + // This adds state-specific shortucts to the vector if state.selected_item_is_dir() { - Shortcut::new(vec!["l", "Right", "Enter"], "Go to selected dir") + hints.push(Shortcut::new( + vec!["l", "Right", "Enter"], + "Go to selected dir", + )) } else { - Shortcut::new(vec!["l", "Right", "Enter"], "Run selected command") + hints.push(Shortcut::new( + vec!["l", "Right", "Enter"], + "Run selected command", + )); + hints.push(Shortcut::new( + vec!["r"], + "Revert changes made by this command", + )) } + + hints } pub fn draw_shortcuts(state: &AppState, frame: &mut Frame, area: Rect) { @@ -119,7 +132,7 @@ pub fn draw_shortcuts(state: &AppState, frame: &mut Frame, area: Rect) { hints.push(Shortcut::new(vec!["q", "CTRL-c"], "Exit linutil")); if state.at_root() { hints.push(Shortcut::new(vec!["h", "Left", "Tab"], "Focus tab list")); - hints.push(get_list_item_shortcut(state)); + hints = push_item_shortcut(hints, state); } else { if state.selected_item_is_up_dir() { hints.push(Shortcut::new( @@ -128,7 +141,7 @@ pub fn draw_shortcuts(state: &AppState, frame: &mut Frame, area: Rect) { )); } else { hints.push(Shortcut::new(vec!["h", "Left"], "Go to parrent directory")); - hints.push(get_list_item_shortcut(state)); + hints = push_item_shortcut(hints, state); if state.selected_item_is_cmd() { hints.push(Shortcut::new(vec!["p"], "Enable preview")); } diff --git a/tui/src/running_command.rs b/tui/src/running_command.rs index d8df34028..b474e9a93 100644 --- a/tui/src/running_command.rs +++ b/tui/src/running_command.rs @@ -152,7 +152,7 @@ impl RunningCommand { cmd.cwd(parent); } } - Command::None => panic!("Command::None was treated as a command"), + Command::None => (), } // Open a pseudo-terminal with initial size diff --git a/tui/src/state.rs b/tui/src/state.rs index 267e6769c..ed099e126 100644 --- a/tui/src/state.rs +++ b/tui/src/state.rs @@ -222,6 +222,7 @@ impl AppState { KeyCode::Char('k') | KeyCode::Up => self.selection.select_previous(), KeyCode::Char('p') => self.enable_preview(), KeyCode::Enter | KeyCode::Char('l') | KeyCode::Right => self.handle_enter(), + KeyCode::Char('r') => self.handle_revert(), KeyCode::Char('h') | KeyCode::Left => { if self.at_root() { self.focus = Focus::TabList; @@ -257,11 +258,11 @@ impl AppState { self.selection.select(Some(0)); self.update_items(); } - pub fn get_selected_command(&self) -> Option { + pub fn get_selected_commands(&self) -> (Option, Option, Option) { let mut selected_index = self.selection.selected().unwrap_or(0); if !self.at_root() && selected_index == 0 { - return None; + return (None, None, None); } if !self.at_root() { selected_index = selected_index.saturating_sub(1); @@ -269,10 +270,14 @@ impl AppState { if let Some(item) = self.filter.item_list().get(selected_index) { if !item.has_children { - return Some(item.node.command.clone()); + return ( + Some(item.node.raw_command.clone()), + Some(item.node.command.clone()), + Some(item.node.revert_command.clone()), + ); } } - None + (None, None, None) } pub fn go_to_selected_dir(&mut self) { let mut selected_index = self.selection.selected().unwrap_or(0); @@ -335,20 +340,36 @@ impl AppState { !self.at_root() && selected_index == 0 } fn enable_preview(&mut self) { - if let Some(command) = self.get_selected_command() { + if let Some(command) = self.get_selected_commands().0 { if let Some(preview) = FloatingText::from_command(&command) { self.spawn_float(preview, 80, 80); } } } fn handle_enter(&mut self) { - if let Some(cmd) = self.get_selected_command() { + if let Some(cmd) = self.get_selected_commands().1 { let command = RunningCommand::new(cmd); self.spawn_float(command, 80, 80); } else { self.go_to_selected_dir(); } } + fn handle_revert(&mut self) { + if let Some(cmd) = self.get_selected_commands().2 { + if cmd != Command::None { + let command = RunningCommand::new(cmd); + self.spawn_float(command, 80, 80); + } else { + self.spawn_float( + FloatingText::new(vec![ + "Revert functionality not found for this command.".to_string() + ]), + 38, + 10, + ); + } + } + } fn spawn_float(&mut self, float: T, width: u16, height: u16) { self.focus = Focus::FloatingWindow(Float::new(Box::new(float), width, height)); }