From 408fd6c95dc0d8b9b46e54ec1cb726d6a9300522 Mon Sep 17 00:00:00 2001 From: Adam Perkowski Date: Sun, 15 Sep 2024 02:02:10 +0200 Subject: [PATCH 01/21] Revert commands - core Rust functionality --- core/src/inner.rs | 6 +++++- core/src/lib.rs | 1 + tui/src/hint.rs | 22 +++++++++++++++++----- tui/src/state.rs | 22 ++++++++++++++++------ 4 files changed, 39 insertions(+), 12 deletions(-) diff --git a/core/src/inner.rs b/core/src/inner.rs index f23d21044..206a89c48 100644 --- a/core/src/inner.rs +++ b/core/src/inner.rs @@ -25,6 +25,7 @@ pub fn get_tabs(validate: bool) -> Vec { let mut tree = Tree::new(ListNode { name: "root".to_string(), command: Command::None, + revert_command: Command::None, }); let mut root = tree.root_mut(); create_directory(data, &mut root, &directory); @@ -147,12 +148,14 @@ fn create_directory(data: Vec, node: &mut NodeMut, command_dir: let mut node = node.append(ListNode { name: entry.name, 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), + command: Command::Raw(format!(". {} run", command)), + revert_command: Command::Raw(format!(". {} revert", command)), }); } else if let Some(script) = entry.script { let dir = command_dir.join(script); @@ -162,6 +165,7 @@ fn create_directory(data: Vec, node: &mut NodeMut, command_dir: node.append(ListNode { name: entry.name, command: Command::LocalFile(dir), + revert_command: Command::None, }); } else { panic!("Entry must have data"); diff --git a/core/src/lib.rs b/core/src/lib.rs index 93ce0619e..1b9f684f0 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -22,4 +22,5 @@ pub struct Tab { pub struct ListNode { pub name: String, pub command: Command, + pub revert_command: Command, } diff --git a/tui/src/hint.rs b/tui/src/hint.rs index 27474ea99..1ac76281c 100644 --- a/tui/src/hint.rs +++ b/tui/src/hint.rs @@ -100,12 +100,24 @@ impl Shortcut { } } -fn get_list_item_shortcut(state: &AppState) -> Shortcut { +fn push_item_shortcut(mut hints: Vec, state: &AppState) -> Vec { 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 +131,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 +140,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/state.rs b/tui/src/state.rs index 267e6769c..a5dc65966 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) { let mut selected_index = self.selection.selected().unwrap_or(0); if !self.at_root() && selected_index == 0 { - return None; + return (None, None); } if !self.at_root() { selected_index = selected_index.saturating_sub(1); @@ -269,10 +270,13 @@ 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.command.clone()), + Some(item.node.revert_command.clone()), + ); } } - None + (None, None) } pub fn go_to_selected_dir(&mut self) { let mut selected_index = self.selection.selected().unwrap_or(0); @@ -335,20 +339,26 @@ 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().0 { 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().1 { + let command = RunningCommand::new(cmd); + self.spawn_float(command, 80, 80); + } + } fn spawn_float(&mut self, float: T, width: u16, height: u16) { self.focus = Focus::FloatingWindow(Float::new(Box::new(float), width, height)); } From 3ac40057d967aa44f18d5b6c343cf61a4de69ef0 Mon Sep 17 00:00:00 2001 From: Adam Perkowski Date: Sun, 15 Sep 2024 02:55:20 +0200 Subject: [PATCH 02/21] Forgot. --- core/src/inner.rs | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/core/src/inner.rs b/core/src/inner.rs index 206a89c48..793b45147 100644 --- a/core/src/inner.rs +++ b/core/src/inner.rs @@ -154,18 +154,33 @@ fn create_directory(data: Vec, node: &mut NodeMut, command_dir: } else if let Some(command) = entry.command { node.append(ListNode { name: entry.name, - command: Command::Raw(format!(". {} run", command)), - revert_command: Command::Raw(format!(". {} revert", command)), + command: Command::Raw(command.clone()), + revert_command: Command::Raw(command), }); } 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(); + + 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), - revert_command: Command::None, + command: cmd, + revert_command: rev_cmd, }); } else { panic!("Entry must have data"); From 0bba80671bcb493efee83e7cadd060dc31f90b4b Mon Sep 17 00:00:00 2001 From: nnyyxxxx Date: Sun, 15 Sep 2024 01:27:23 -0400 Subject: [PATCH 03/21] Add revert functionality to alacrittySetup --- tabs/applications-setup/alacritty-setup.sh | 36 ++++++++++++++++++++-- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/tabs/applications-setup/alacritty-setup.sh b/tabs/applications-setup/alacritty-setup.sh index a26b78f86..d5269c8a6 100755 --- a/tabs/applications-setup/alacritty-setup.sh +++ b/tabs/applications-setup/alacritty-setup.sh @@ -25,6 +25,36 @@ setupAlacritty() { wget -O "${HOME}/.config/alacritty/nordic.toml" "https://github.com/ChrisTitusTech/dwm-titus/raw/main/config/alacritty/nordic.toml" } -checkEnv -checkEscalationTool -setupAlacritty +revertAlacritty() { + echo "Reverting Alacritty setup..." + if [ -d "${HOME}/.config/alacritty-bak" ]; then + rm -rf "${HOME}/.config/alacritty" + mv "${HOME}/.config/alacritty-bak" "${HOME}/.config/alacritty" + + if command_exists alacritty; then + case ${PACKAGER} in + pacman) + $ESCALATION_TOOL ${PACKAGER} -R --noconfirm alacritty + ;; + *) + $ESCALATION_TOOL ${PACKAGER} remove -y alacritty + ;; + esac + echo "Alacritty uninstalled." + fi + else + echo "No backup found. Nothing to revert." + fi +} + +run() { + checkEnv + checkEscalationTool + setupAlacritty +} + +revert() { + checkEnv + checkEscalationTool + revertAlacritty +} \ No newline at end of file From c5744c97a0c7c0b7964ce16213b596a660d44a26 Mon Sep 17 00:00:00 2001 From: nnyyxxxx Date: Sun, 15 Sep 2024 02:01:22 -0400 Subject: [PATCH 04/21] Add choice to uninstalling Alacritty --- tabs/applications-setup/alacritty-setup.sh | 25 +++++++++++++--------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/tabs/applications-setup/alacritty-setup.sh b/tabs/applications-setup/alacritty-setup.sh index d5269c8a6..fb3353d30 100755 --- a/tabs/applications-setup/alacritty-setup.sh +++ b/tabs/applications-setup/alacritty-setup.sh @@ -30,17 +30,22 @@ revertAlacritty() { if [ -d "${HOME}/.config/alacritty-bak" ]; then rm -rf "${HOME}/.config/alacritty" mv "${HOME}/.config/alacritty-bak" "${HOME}/.config/alacritty" - + echo "Alacritty setup reverted" + if command_exists alacritty; then - case ${PACKAGER} in - pacman) - $ESCALATION_TOOL ${PACKAGER} -R --noconfirm alacritty - ;; - *) - $ESCALATION_TOOL ${PACKAGER} remove -y alacritty - ;; - esac - echo "Alacritty uninstalled." + 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} -R --noconfirm alacritty + ;; + *) + $ESCALATION_TOOL ${PACKAGER} remove -y alacritty + ;; + esac + echo "Alacritty uninstalled." + fi fi else echo "No backup found. Nothing to revert." From 3f2f13444e1643c24fe99b7dd16a50eb05d8b9a8 Mon Sep 17 00:00:00 2001 From: nnyyxxxx Date: Sun, 15 Sep 2024 02:19:28 -0400 Subject: [PATCH 05/21] Add Zsh revert functionality --- tabs/applications-setup/zsh-setup.sh | 44 +++++++++++++++++++++++++--- 1 file changed, 40 insertions(+), 4 deletions(-) diff --git a/tabs/applications-setup/zsh-setup.sh b/tabs/applications-setup/zsh-setup.sh index eaa608b5f..ec2a9e876 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 setup..." + 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} -R --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 From 5fb59e93cebedd7edc4951accbc7be1f5ef17bf4 Mon Sep 17 00:00:00 2001 From: nnyyxxxx Date: Sun, 15 Sep 2024 02:41:41 -0400 Subject: [PATCH 06/21] Add Rofi Revert functionality & Keep synergy --- tabs/applications-setup/alacritty-setup.sh | 2 +- tabs/applications-setup/rofi-setup.sh | 42 ++++++++++++++++++++-- 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/tabs/applications-setup/alacritty-setup.sh b/tabs/applications-setup/alacritty-setup.sh index fb3353d30..accef5a42 100755 --- a/tabs/applications-setup/alacritty-setup.sh +++ b/tabs/applications-setup/alacritty-setup.sh @@ -48,7 +48,7 @@ revertAlacritty() { fi fi else - echo "No backup found. Nothing to revert." + echo "No Alacritty configuration found. Nothing to revert." fi } diff --git a/tabs/applications-setup/rofi-setup.sh b/tabs/applications-setup/rofi-setup.sh index 9c06f953d..b6ee4924f 100755 --- a/tabs/applications-setup/rofi-setup.sh +++ b/tabs/applications-setup/rofi-setup.sh @@ -30,6 +30,42 @@ setupRofi() { wget -O "$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 setup..." + CONFIG_DIR="$HOME/.config/rofi" + + if [ -d "${CONFIG_DIR}" ]; then + rm -rf "$CONFIG_DIR" + 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} -R --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 From caf0a7bdfc17d5e9e966d2786c690edac8e1feed Mon Sep 17 00:00:00 2001 From: nnyyxxxx Date: Sun, 15 Sep 2024 03:05:38 -0400 Subject: [PATCH 07/21] Add Kitty revert functionality & keep synergy --- tabs/applications-setup/alacritty-setup.sh | 4 +-- tabs/applications-setup/kitty-setup.sh | 42 ++++++++++++++++++++-- tabs/applications-setup/rofi-setup.sh | 2 +- tabs/applications-setup/zsh-setup.sh | 2 +- 4 files changed, 43 insertions(+), 7 deletions(-) diff --git a/tabs/applications-setup/alacritty-setup.sh b/tabs/applications-setup/alacritty-setup.sh index accef5a42..e7be1f3e0 100755 --- a/tabs/applications-setup/alacritty-setup.sh +++ b/tabs/applications-setup/alacritty-setup.sh @@ -26,11 +26,11 @@ setupAlacritty() { } revertAlacritty() { - echo "Reverting Alacritty setup..." + 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 setup reverted" + echo "Alacritty configuration reverted" if command_exists alacritty; then printf "Do you want to uninstall Alacritty as well? (y/N): " diff --git a/tabs/applications-setup/kitty-setup.sh b/tabs/applications-setup/kitty-setup.sh index a9d262930..aac1fecb8 100755 --- a/tabs/applications-setup/kitty-setup.sh +++ b/tabs/applications-setup/kitty-setup.sh @@ -25,6 +25,42 @@ setupKitty() { wget -O "${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}" + 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}" -R --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/rofi-setup.sh b/tabs/applications-setup/rofi-setup.sh index b6ee4924f..334daf166 100755 --- a/tabs/applications-setup/rofi-setup.sh +++ b/tabs/applications-setup/rofi-setup.sh @@ -31,7 +31,7 @@ setupRofi() { } revertRofi() { - echo "Reverting Rofi setup..." + echo "Reverting Rofi configuration..." CONFIG_DIR="$HOME/.config/rofi" if [ -d "${CONFIG_DIR}" ]; then diff --git a/tabs/applications-setup/zsh-setup.sh b/tabs/applications-setup/zsh-setup.sh index ec2a9e876..6b7d58ee3 100644 --- a/tabs/applications-setup/zsh-setup.sh +++ b/tabs/applications-setup/zsh-setup.sh @@ -47,7 +47,7 @@ EOL } revertZSH() { - echo "Reverting ZSH setup..." + echo "Reverting ZSH configuration..." CONFIG_DIR="$HOME/.config/zsh" if [ -d "${CONFIG_DIR}" ]; then From 4247b55d6734c0cac923f221676a280b7b529288 Mon Sep 17 00:00:00 2001 From: nnyyxxxx Date: Sun, 15 Sep 2024 03:16:58 -0400 Subject: [PATCH 08/21] Add onto the existing revert functionality --- tabs/applications-setup/kitty-setup.sh | 1 + tabs/applications-setup/rofi-setup.sh | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/tabs/applications-setup/kitty-setup.sh b/tabs/applications-setup/kitty-setup.sh index aac1fecb8..08e61f128 100755 --- a/tabs/applications-setup/kitty-setup.sh +++ b/tabs/applications-setup/kitty-setup.sh @@ -31,6 +31,7 @@ revertKitty() { 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 diff --git a/tabs/applications-setup/rofi-setup.sh b/tabs/applications-setup/rofi-setup.sh index 334daf166..9aa09160d 100755 --- a/tabs/applications-setup/rofi-setup.sh +++ b/tabs/applications-setup/rofi-setup.sh @@ -18,7 +18,7 @@ setupRofi() { fi echo "Copy Rofi config files" if [ -d "$HOME/.config/rofi" ]; then - cp -r "$HOME/.config/rofi" "$HOME/.config/rofi.bak" + cp -r "$HOME/.config/rofi" "$HOME/.config/rofi-bak" fi mkdir -p "$HOME/.config/rofi" wget -O "$HOME/.config/rofi/powermenu.sh" https://github.com/ChrisTitusTech/dwm-titus/raw/main/config/rofi/powermenu.sh @@ -36,6 +36,7 @@ revertRofi() { 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 From 1845fa16fe80fc4d11eac866aba4e417843c0361 Mon Sep 17 00:00:00 2001 From: nnyyxxxx Date: Sun, 15 Sep 2024 04:08:50 -0400 Subject: [PATCH 09/21] Rns instead of R to remove installed deps as well --- tabs/applications-setup/alacritty-setup.sh | 2 +- tabs/applications-setup/kitty-setup.sh | 2 +- tabs/applications-setup/rofi-setup.sh | 2 +- tabs/applications-setup/zsh-setup.sh | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tabs/applications-setup/alacritty-setup.sh b/tabs/applications-setup/alacritty-setup.sh index e7be1f3e0..a2eb7b7b6 100755 --- a/tabs/applications-setup/alacritty-setup.sh +++ b/tabs/applications-setup/alacritty-setup.sh @@ -38,7 +38,7 @@ revertAlacritty() { if [ "$uninstall_choice" = "y" ] || [ "$uninstall_choice" = "Y" ]; then case ${PACKAGER} in pacman) - $ESCALATION_TOOL ${PACKAGER} -R --noconfirm alacritty + $ESCALATION_TOOL ${PACKAGER} -Rns --noconfirm alacritty ;; *) $ESCALATION_TOOL ${PACKAGER} remove -y alacritty diff --git a/tabs/applications-setup/kitty-setup.sh b/tabs/applications-setup/kitty-setup.sh index 08e61f128..cd9ef7686 100755 --- a/tabs/applications-setup/kitty-setup.sh +++ b/tabs/applications-setup/kitty-setup.sh @@ -40,7 +40,7 @@ revertKitty() { if [ "$uninstall_choice" = "y" ] || [ "$uninstall_choice" = "Y" ]; then case ${PACKAGER} in pacman) - $ESCALATION_TOOL "${PACKAGER}" -R --noconfirm kitty + $ESCALATION_TOOL "${PACKAGER}" -Rns --noconfirm kitty ;; *) $ESCALATION_TOOL "${PACKAGER}" remove -y kitty diff --git a/tabs/applications-setup/rofi-setup.sh b/tabs/applications-setup/rofi-setup.sh index 9aa09160d..675e80704 100755 --- a/tabs/applications-setup/rofi-setup.sh +++ b/tabs/applications-setup/rofi-setup.sh @@ -45,7 +45,7 @@ revertRofi() { if [ "$uninstall_choice" = "y" ] || [ "$uninstall_choice" = "Y" ]; then case ${PACKAGER} in pacman) - $ESCALATION_TOOL ${PACKAGER} -R --noconfirm rofi + $ESCALATION_TOOL ${PACKAGER} -Rns --noconfirm rofi ;; *) $ESCALATION_TOOL ${PACKAGER} remove -y rofi diff --git a/tabs/applications-setup/zsh-setup.sh b/tabs/applications-setup/zsh-setup.sh index 6b7d58ee3..d739251e8 100644 --- a/tabs/applications-setup/zsh-setup.sh +++ b/tabs/applications-setup/zsh-setup.sh @@ -60,7 +60,7 @@ revertZSH() { if [ "$uninstall_choice" = "y" ] || [ "$uninstall_choice" = "Y" ]; then case ${PACKAGER} in pacman) - $ESCALATION_TOOL ${PACKAGER} -R --noconfirm zsh + $ESCALATION_TOOL ${PACKAGER} -Rns --noconfirm zsh ;; *) $ESCALATION_TOOL ${PACKAGER} remove -y zsh From f06fc5a621859eb21a6d8ec77dc89c281dba4b6c Mon Sep 17 00:00:00 2001 From: nnyyxxxx Date: Sun, 15 Sep 2024 04:23:00 -0400 Subject: [PATCH 10/21] Add snapd removal revert & remove Arch packager --- tabs/system-setup/4-remove-snaps.sh | 38 +++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 7 deletions(-) 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 From 9a5839ea34b3fe97587b6294d999f08f36bda165 Mon Sep 17 00:00:00 2001 From: nnyyxxxx Date: Sun, 15 Sep 2024 05:03:51 -0400 Subject: [PATCH 11/21] Add Reverting not implemented function --- tabs/system-setup/system-update.sh | 23 ++++++++++++++----- tabs/utils/bluetooth-control.sh | 18 +++++++++++---- .../monitor-control/auto_detect_displays.sh | 14 ++++++++++- .../monitor-control/change_orientation.sh | 15 ++++++++++-- tabs/utils/monitor-control/disable_monitor.sh | 15 ++++++++++-- .../monitor-control/duplicate_displays.sh | 14 ++++++++++- tabs/utils/monitor-control/enable_monitor.sh | 15 ++++++++++-- tabs/utils/monitor-control/extend_displays.sh | 14 ++++++++++- .../monitor-control/manage_arrangement.sh | 15 ++++++++++-- tabs/utils/monitor-control/reset_scaling.sh | 15 ++++++++++-- tabs/utils/monitor-control/scale_monitor.sh | 15 ++++++++++-- .../monitor-control/set_primary_monitor.sh | 15 ++++++++++-- tabs/utils/monitor-control/set_resolutions.sh | 14 ++++++++++- .../monitor-control/utility_functions.sh | 15 ++++++++++-- tabs/utils/numlock.sh | 16 +++++++++++-- tabs/utils/wifi-control.sh | 18 +++++++++++---- 16 files changed, 215 insertions(+), 36 deletions(-) diff --git a/tabs/system-setup/system-update.sh b/tabs/system-setup/system-update.sh index 24c5eed2c..9ba9cbe63 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 ddb97c651..ea0df38b8 100644 --- a/tabs/utils/bluetooth-control.sh +++ b/tabs/utils/bluetooth-control.sh @@ -156,7 +156,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 86fcdcd95..baec8873d 100755 --- a/tabs/utils/monitor-control/auto_detect_displays.sh +++ b/tabs/utils/monitor-control/auto_detect_displays.sh @@ -30,4 +30,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 4ec802d43..b9d877c25 100755 --- a/tabs/utils/monitor-control/change_orientation.sh +++ b/tabs/utils/monitor-control/change_orientation.sh @@ -54,5 +54,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 b455848bb..2c0d57657 100755 --- a/tabs/utils/monitor-control/disable_monitor.sh +++ b/tabs/utils/monitor-control/disable_monitor.sh @@ -56,5 +56,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 c5cdf01ef..c571afe7c 100755 --- a/tabs/utils/monitor-control/duplicate_displays.sh +++ b/tabs/utils/monitor-control/duplicate_displays.sh @@ -13,4 +13,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 3525771f0..8aacfb8ba 100755 --- a/tabs/utils/monitor-control/enable_monitor.sh +++ b/tabs/utils/monitor-control/enable_monitor.sh @@ -54,5 +54,16 @@ confirm_action() { 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 4e215bfa1..3909356c0 100755 --- a/tabs/utils/monitor-control/extend_displays.sh +++ b/tabs/utils/monitor-control/extend_displays.sh @@ -13,4 +13,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 190498146..305d6225b 100755 --- a/tabs/utils/monitor-control/manage_arrangement.sh +++ b/tabs/utils/monitor-control/manage_arrangement.sh @@ -67,5 +67,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 813080654..02b0e7da1 100755 --- a/tabs/utils/monitor-control/reset_scaling.sh +++ b/tabs/utils/monitor-control/reset_scaling.sh @@ -19,5 +19,16 @@ reset_scaling() { echo -e "${GREEN}All monitor scalings have been reset to 1x1.${RESET}" } -# Call the reset_scaling function -reset_scaling +revertResetScaling() { + echo "Reverting is not implemented for this script." +} + +run() { + checkEnv + reset_scaling +} + +revert() { + checkEnv + revertResetScaling +} \ No newline at end of file diff --git a/tabs/utils/monitor-control/scale_monitor.sh b/tabs/utils/monitor-control/scale_monitor.sh index 708e1fb38..6a4949d82 100755 --- a/tabs/utils/monitor-control/scale_monitor.sh +++ b/tabs/utils/monitor-control/scale_monitor.sh @@ -40,5 +40,16 @@ scale_monitors() { echo -e "${GREEN}Scaling complete. All monitors are now scaled to ${max_width}x${max_height}.${RESET}" } -# 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 752dc784c..e496a1a8d 100755 --- a/tabs/utils/monitor-control/set_primary_monitor.sh +++ b/tabs/utils/monitor-control/set_primary_monitor.sh @@ -34,5 +34,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 2f3cb6a7f..e3c45bf5e 100755 --- a/tabs/utils/monitor-control/set_resolutions.sh +++ b/tabs/utils/monitor-control/set_resolutions.sh @@ -90,4 +90,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 bb4803908..cc53a2039 100755 --- a/tabs/utils/monitor-control/utility_functions.sh +++ b/tabs/utils/monitor-control/utility_functions.sh @@ -83,5 +83,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 739b127d3..69a516ca0 100644 --- a/tabs/utils/wifi-control.sh +++ b/tabs/utils/wifi-control.sh @@ -196,7 +196,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 From 8a33c788012f3315fb0f3d517cbd283436bf0529 Mon Sep 17 00:00:00 2001 From: nnyyxxxx Date: Sun, 15 Sep 2024 05:33:26 -0400 Subject: [PATCH 12/21] Add global theme revert --- tabs/system-setup/3-global-theme.sh | 60 ++++++++++++++++++++++++++--- 1 file changed, 55 insertions(+), 5 deletions(-) diff --git a/tabs/system-setup/3-global-theme.sh b/tabs/system-setup/3-global-theme.sh index 1f9c7ccef..97cf6614d 100644 --- a/tabs/system-setup/3-global-theme.sh +++ b/tabs/system-setup/3-global-theme.sh @@ -29,6 +29,9 @@ install_theme_tools() { configure_qt6ct() { 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] @@ -50,6 +53,9 @@ EOF configure_kvantum() { 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 "${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 From 291683855f17e6db722b4e32a7b5fb60b96e726b Mon Sep 17 00:00:00 2001 From: nnyyxxxx Date: Sun, 15 Sep 2024 05:46:12 -0400 Subject: [PATCH 13/21] Add compile-setup revert --- tabs/system-setup/1-compile-setup.sh | 36 ++++++++++------------------ 1 file changed, 13 insertions(+), 23 deletions(-) diff --git a/tabs/system-setup/1-compile-setup.sh b/tabs/system-setup/1-compile-setup.sh index 1a45d1538..746a18148 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 From 4d4e59c68cff88f00c9466570694bb781dc96d49 Mon Sep 17 00:00:00 2001 From: nnyyxxxx Date: Sun, 15 Sep 2024 05:50:02 -0400 Subject: [PATCH 14/21] Add Rpm-Fusion revert --- tabs/system-setup/fedora/rpm-fusion-setup.sh | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/tabs/system-setup/fedora/rpm-fusion-setup.sh b/tabs/system-setup/fedora/rpm-fusion-setup.sh index 190038375..a0e0c0dbd 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 From 65364fe45d963800c89427162294eedd0028e829 Mon Sep 17 00:00:00 2001 From: nnyyxxxx Date: Sun, 15 Sep 2024 05:53:44 -0400 Subject: [PATCH 15/21] Add Firewall-baslines revert --- tabs/security/firewall-baselines.sh | 42 ++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/tabs/security/firewall-baselines.sh b/tabs/security/firewall-baselines.sh index ee0441b6c..73505b039 100644 --- a/tabs/security/firewall-baselines.sh +++ b/tabs/security/firewall-baselines.sh @@ -43,7 +43,41 @@ configureUFW() { echo -e "${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 From 6859d535a71edffc8d0252ffd5461bc6aa7037ee Mon Sep 17 00:00:00 2001 From: nnyyxxxx Date: Sun, 15 Sep 2024 05:56:51 -0400 Subject: [PATCH 16/21] Add DwmTitus revert --- tabs/applications-setup/dwmtitus-setup.sh | 27 ++++++++++++++++------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/tabs/applications-setup/dwmtitus-setup.sh b/tabs/applications-setup/dwmtitus-setup.sh index 8c0fc97ac..02f26f4a7 100644 --- a/tabs/applications-setup/dwmtitus-setup.sh +++ b/tabs/applications-setup/dwmtitus-setup.sh @@ -295,11 +295,22 @@ setupDisplayManager() { } -checkEnv -checkEscalationTool -setupDisplayManager -setupDWM -makeDWM -install_nerd_font -clone_config_folders -configure_backgrounds +revertDwmTitusSetup() { + echo "Reverting is not implemented for this script." +} + +run() { + checkEnv + checkEscalationTool + setupDisplayManager + setupDWM + makeDWM + install_nerd_font + clone_config_folders + configure_backgrounds +} + +revert() { + checkEnv + revertDwmTitusSetup +} \ No newline at end of file From 530a66c19c0d68d1ff3ec7267b6d6091d1ca564e Mon Sep 17 00:00:00 2001 From: nnyyxxxx Date: Sun, 15 Sep 2024 06:00:03 -0400 Subject: [PATCH 17/21] Add D2rLootFilters revert --- tabs/gaming/diablo-ii/d2r-loot-filters.sh | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/tabs/gaming/diablo-ii/d2r-loot-filters.sh b/tabs/gaming/diablo-ii/d2r-loot-filters.sh index 1ec0ca637..c5fb229ff 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 From 8d5f19f6fd7fb4e9a3a1ce3dad9acbd9e4bf17e1 Mon Sep 17 00:00:00 2001 From: Adam Perkowski Date: Sun, 15 Sep 2024 15:39:17 +0200 Subject: [PATCH 18/21] Added `raw_command` and fixed previews --- core/src/inner.rs | 4 ++++ core/src/lib.rs | 1 + tui/src/state.rs | 11 ++++++----- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/core/src/inner.rs b/core/src/inner.rs index 793b45147..5b5b1239f 100644 --- a/core/src/inner.rs +++ b/core/src/inner.rs @@ -24,6 +24,7 @@ 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, }); @@ -147,6 +148,7 @@ 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, }); @@ -154,6 +156,7 @@ fn create_directory(data: Vec, node: &mut NodeMut, command_dir: } else if let Some(command) = entry.command { node.append(ListNode { name: entry.name, + raw_command: Command::Raw(command.clone()), command: Command::Raw(command.clone()), revert_command: Command::Raw(command), }); @@ -179,6 +182,7 @@ fn create_directory(data: Vec, node: &mut NodeMut, command_dir: node.append(ListNode { name: entry.name, + raw_command: Command::LocalFile(dir), command: cmd, revert_command: rev_cmd, }); diff --git a/core/src/lib.rs b/core/src/lib.rs index 1b9f684f0..c4b7ebae2 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -21,6 +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/tui/src/state.rs b/tui/src/state.rs index a5dc65966..75e21e798 100644 --- a/tui/src/state.rs +++ b/tui/src/state.rs @@ -258,11 +258,11 @@ impl AppState { self.selection.select(Some(0)); self.update_items(); } - pub fn get_selected_commands(&self) -> (Option, 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, None); + return (None, None, None); } if !self.at_root() { selected_index = selected_index.saturating_sub(1); @@ -271,12 +271,13 @@ impl AppState { if let Some(item) = self.filter.item_list().get(selected_index) { if !item.has_children { return ( + Some(item.node.raw_command.clone()), Some(item.node.command.clone()), Some(item.node.revert_command.clone()), ); } } - (None, None) + (None, None, None) } pub fn go_to_selected_dir(&mut self) { let mut selected_index = self.selection.selected().unwrap_or(0); @@ -346,7 +347,7 @@ impl AppState { } } fn handle_enter(&mut self) { - if let Some(cmd) = self.get_selected_commands().0 { + if let Some(cmd) = self.get_selected_commands().1 { let command = RunningCommand::new(cmd); self.spawn_float(command, 80, 80); } else { @@ -354,7 +355,7 @@ impl AppState { } } fn handle_revert(&mut self) { - if let Some(cmd) = self.get_selected_commands().1 { + if let Some(cmd) = self.get_selected_commands().2 { let command = RunningCommand::new(cmd); self.spawn_float(command, 80, 80); } From 7e0b14630d8275b76c165d0849d68bb19b2d2c77 Mon Sep 17 00:00:00 2001 From: Adam Perkowski Date: Sun, 15 Sep 2024 17:42:55 +0200 Subject: [PATCH 19/21] Added comments --- core/src/inner.rs | 3 ++- tui/src/hint.rs | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/core/src/inner.rs b/core/src/inner.rs index 5b5b1239f..9d8fcb37c 100644 --- a/core/src/inner.rs +++ b/core/src/inner.rs @@ -169,6 +169,7 @@ fn create_directory(data: Vec, node: &mut NodeMut, command_dir: 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(), @@ -182,7 +183,7 @@ fn create_directory(data: Vec, node: &mut NodeMut, command_dir: node.append(ListNode { name: entry.name, - raw_command: Command::LocalFile(dir), + raw_command: Command::LocalFile(dir), // Raw path to the script -> Command command: cmd, revert_command: rev_cmd, }); diff --git a/tui/src/hint.rs b/tui/src/hint.rs index 1ac76281c..8fe243631 100644 --- a/tui/src/hint.rs +++ b/tui/src/hint.rs @@ -101,6 +101,7 @@ impl 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() { hints.push(Shortcut::new( vec!["l", "Right", "Enter"], From 1e7b4883312a3481d04dc154d641d1a55d3fcb4f Mon Sep 17 00:00:00 2001 From: Adam Perkowski Date: Mon, 16 Sep 2024 22:24:41 +0200 Subject: [PATCH 20/21] mybash & neovim --- tabs/applications-setup/mybash-setup.sh | 155 ++++++++++++++++++++++++ tabs/applications-setup/neovim-setup.sh | 89 ++++++++++++++ tabs/applications-setup/tab_data.toml | 4 +- 3 files changed, 246 insertions(+), 2 deletions(-) create mode 100644 tabs/applications-setup/mybash-setup.sh create mode 100755 tabs/applications-setup/neovim-setup.sh 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/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" From 6598fa03f64e283023e3bf06b71948e7a486ffbc Mon Sep 17 00:00:00 2001 From: Adam Perkowski Date: Mon, 16 Sep 2024 22:47:36 +0200 Subject: [PATCH 21/21] Added Command::None exception & improved UX --- core/src/inner.rs | 2 +- tui/src/running_command.rs | 2 +- tui/src/state.rs | 14 ++++++++++++-- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/core/src/inner.rs b/core/src/inner.rs index 9d8fcb37c..2452ac936 100644 --- a/core/src/inner.rs +++ b/core/src/inner.rs @@ -158,7 +158,7 @@ fn create_directory(data: Vec, node: &mut NodeMut, command_dir: name: entry.name, raw_command: Command::Raw(command.clone()), command: Command::Raw(command.clone()), - revert_command: Command::Raw(command), + revert_command: Command::None, }); } else if let Some(script) = entry.script { let dir = command_dir.join(script.clone()); 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 75e21e798..ed099e126 100644 --- a/tui/src/state.rs +++ b/tui/src/state.rs @@ -356,8 +356,18 @@ impl AppState { } fn handle_revert(&mut self) { if let Some(cmd) = self.get_selected_commands().2 { - let command = RunningCommand::new(cmd); - self.spawn_float(command, 80, 80); + 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) {