From 8ed2265463b3feca7eba10a96b49beb0bfd92fdf Mon Sep 17 00:00:00 2001 From: nnyyxxxx Date: Thu, 12 Sep 2024 15:46:41 -0400 Subject: [PATCH 1/3] Move mybash and CTT nvim to Linutil with minor refactoring --- tabs/applications-setup/mybash-setup.sh | 114 ++++++++++++++++++++++++ tabs/applications-setup/neovim-setup.sh | 49 ++++++++++ tabs/applications-setup/tab_data.toml | 4 +- 3 files changed, 165 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 00000000..41460bcf --- /dev/null +++ b/tabs/applications-setup/mybash-setup.sh @@ -0,0 +1,114 @@ +#!/bin/sh -e + +. ../common-script.sh + +gitpath="$HOME/.local/share/mybash" + +cloneMyBash() { + 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" ]; 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!\nrestart your shell to see the changes.${RC}" +} + +checkEnv +checkEscalationTool +cloneMyBash +installDepend +installFont +installStarshipAndFzf +installZoxide +linkConfig \ 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 00000000..b1bfaa6b --- /dev/null +++ b/tabs/applications-setup/neovim-setup.sh @@ -0,0 +1,49 @@ +#!/bin/sh -e + +. ../common-script.sh + +gitpath="$HOME/.local/share/neovim" + +cloneNeovim() { + 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() { + [ -d "$HOME/.config/nvim" ] && cp -r "$HOME/.config/nvim" "$HOME/.config/nvim-backup" + 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. +} + +checkEnv +checkEscalationTool +cloneNeovim +setupNeovim +backupNeovimConfig +linkNeovimConfig \ No newline at end of file diff --git a/tabs/applications-setup/tab_data.toml b/tabs/applications-setup/tab_data.toml index 2ad73892..39cbd30e 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 55c6db1b1296025189fea4ae44cfa913b5c7e2f8 Mon Sep 17 00:00:00 2001 From: nnyyxxxx Date: Sat, 14 Sep 2024 08:07:22 -0400 Subject: [PATCH 2/3] Implement dir checking logic --- tabs/applications-setup/mybash-setup.sh | 4 ++++ tabs/applications-setup/neovim-setup.sh | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/tabs/applications-setup/mybash-setup.sh b/tabs/applications-setup/mybash-setup.sh index 41460bcf..a258afc4 100644 --- a/tabs/applications-setup/mybash-setup.sh +++ b/tabs/applications-setup/mybash-setup.sh @@ -5,6 +5,10 @@ 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" } diff --git a/tabs/applications-setup/neovim-setup.sh b/tabs/applications-setup/neovim-setup.sh index b1bfaa6b..f8788903 100755 --- a/tabs/applications-setup/neovim-setup.sh +++ b/tabs/applications-setup/neovim-setup.sh @@ -5,6 +5,10 @@ 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" } From 9228327f93345be9d4b05598ff5f6e33c2168f35 Mon Sep 17 00:00:00 2001 From: nnyyxxxx Date: Sun, 15 Sep 2024 08:08:18 -0400 Subject: [PATCH 3/3] Fix backup logic --- tabs/applications-setup/mybash-setup.sh | 4 ++-- tabs/applications-setup/neovim-setup.sh | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/tabs/applications-setup/mybash-setup.sh b/tabs/applications-setup/mybash-setup.sh index a258afc4..7bca14e2 100644 --- a/tabs/applications-setup/mybash-setup.sh +++ b/tabs/applications-setup/mybash-setup.sh @@ -88,7 +88,7 @@ installZoxide() { linkConfig() { OLD_BASHRC="$HOME/.bashrc" - if [ -e "$OLD_BASHRC" ]; then + 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}" @@ -105,7 +105,7 @@ linkConfig() { printf "%b\n" "${RED}Failed to create symbolic link for starship.toml${RC}" exit 1 } - printf "%b\n" "${GREEN}Done!\nrestart your shell to see the changes.${RC}" + printf "%b\n" "${GREEN}Done! restart your shell to see the changes.${RC}" } checkEnv diff --git a/tabs/applications-setup/neovim-setup.sh b/tabs/applications-setup/neovim-setup.sh index f8788903..0d3a2578 100755 --- a/tabs/applications-setup/neovim-setup.sh +++ b/tabs/applications-setup/neovim-setup.sh @@ -36,7 +36,9 @@ setupNeovim() { } backupNeovimConfig() { - [ -d "$HOME/.config/nvim" ] && cp -r "$HOME/.config/nvim" "$HOME/.config/nvim-backup" + 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" }