Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 27 additions & 3 deletions core/src/inner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ pub fn get_tabs(validate: bool) -> Vec<Tab> {
.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);
Expand Down Expand Up @@ -146,22 +148,44 @@ fn create_directory(data: Vec<Entry>, node: &mut NodeMut<ListNode>, 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");
Expand Down
2 changes: 2 additions & 0 deletions core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
41 changes: 38 additions & 3 deletions tabs/applications-setup/alacritty-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
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
}
32 changes: 20 additions & 12 deletions tabs/applications-setup/dwmtitus-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -261,9 +261,6 @@ setupDisplayManager() {
;;
esac
fi



}

install_slstatus() {
Expand All @@ -284,12 +281,23 @@ install_slstatus() {
cd "$HOME"
}

checkEnv
checkEscalationTool
setupDisplayManager
setupDWM
makeDWM
install_slstatus
install_nerd_font
clone_config_folders
configure_backgrounds
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
}
43 changes: 40 additions & 3 deletions tabs/applications-setup/kitty-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
155 changes: 155 additions & 0 deletions tabs/applications-setup/mybash-setup.sh
Original file line number Diff line number Diff line change
@@ -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
}
Loading