From 9394790b00410eb58c3150b6f00fb5fac0a408d0 Mon Sep 17 00:00:00 2001 From: Vaggelis kavouras Date: Thu, 19 Sep 2024 15:05:54 +0300 Subject: [PATCH 1/4] -Script optimization - organization -Fixed the colors not showing - fixed the issuue where it didnt donwload Meslo fonts and got the "show-progress unknown" error Fedora Linux 40 (Workstation Edition) x86_64 Linux 6.10.10-200.fc40.x86_64 bash 5.2.26 --- setup.sh | 254 +++++++++++++++++++++++-------------------------------- 1 file changed, 106 insertions(+), 148 deletions(-) diff --git a/setup.sh b/setup.sh index bc0f7be..5f28fe1 100755 --- a/setup.sh +++ b/setup.sh @@ -1,64 +1,67 @@ #!/bin/sh -e -RC='\033[0m' -RED='\033[31m' -YELLOW='\033[33m' -GREEN='\033[32m' +# Define color codes using tput for better compatibility +RC=$(tput sgr0) +RED=$(tput setaf 1) +YELLOW=$(tput setaf 3) +GREEN=$(tput setaf 2) -# Check if the home directory and linuxtoolbox folder exist, create them if they don't LINUXTOOLBOXDIR="$HOME/linuxtoolbox" - -if [ ! -d "$LINUXTOOLBOXDIR" ]; then - echo "${YELLOW}Creating linuxtoolbox directory: $LINUXTOOLBOXDIR${RC}" - mkdir -p "$LINUXTOOLBOXDIR" - echo "${GREEN}linuxtoolbox directory created: $LINUXTOOLBOXDIR${RC}" -fi - -if [ -d "$LINUXTOOLBOXDIR/mybash" ]; then rm -rf "$LINUXTOOLBOXDIR/mybash"; fi - -echo "${YELLOW}Cloning mybash repository into: $LINUXTOOLBOXDIR/mybash${RC}" -git clone https://github.com/ChrisTitusTech/mybash "$LINUXTOOLBOXDIR/mybash" -if [ $? -eq 0 ]; then - echo "${GREEN}Successfully cloned mybash repository${RC}" -else - echo "${RED}Failed to clone mybash repository${RC}" - exit 1 -fi - -# add variables to top level so can easily be accessed by all functions PACKAGER="" SUDO_CMD="" SUGROUP="" GITPATH="" -cd "$LINUXTOOLBOXDIR/mybash" || exit +print_colored() { + color=$1 + message=$2 + printf "${color}%s${RC}\n" "$message" +} command_exists() { command -v "$1" >/dev/null 2>&1 } -checkEnv() { - ## Check for requirements. +setup_directories() { + if [ ! -d "$LINUXTOOLBOXDIR" ]; then + print_colored "$YELLOW" "Creating linuxtoolbox directory: $LINUXTOOLBOXDIR" + mkdir -p "$LINUXTOOLBOXDIR" + print_colored "$GREEN" "linuxtoolbox directory created: $LINUXTOOLBOXDIR" + fi + + if [ -d "$LINUXTOOLBOXDIR/mybash" ]; then rm -rf "$LINUXTOOLBOXDIR/mybash"; fi + + print_colored "$YELLOW" "Cloning mybash repository into: $LINUXTOOLBOXDIR/mybash" + if git clone https://github.com/ChrisTitusTech/mybash "$LINUXTOOLBOXDIR/mybash"; then + print_colored "$GREEN" "Successfully cloned mybash repository" + else + print_colored "$RED" "Failed to clone mybash repository" + exit 1 + fi + + cd "$LINUXTOOLBOXDIR/mybash" || exit +} + +check_environment() { REQUIREMENTS='curl groups sudo' for req in $REQUIREMENTS; do if ! command_exists "$req"; then - echo "${RED}To run me, you need: $REQUIREMENTS${RC}" + print_colored "$RED" "To run me, you need: $REQUIREMENTS" exit 1 fi done - ## Check Package Handler PACKAGEMANAGER='nala apt dnf yum pacman zypper emerge xbps-install nix-env' for pgm in $PACKAGEMANAGER; do if command_exists "$pgm"; then PACKAGER="$pgm" - echo "Using $pgm" + printf "Using %s\n" "$pgm" break fi done if [ -z "$PACKAGER" ]; then - echo "${RED}Can't find a supported package manager${RC}" + print_colored "$RED" "Can't find a supported package manager" exit 1 fi @@ -70,214 +73,169 @@ checkEnv() { SUDO_CMD="su -c" fi - echo "Using $SUDO_CMD as privilege escalation software" + printf "Using %s as privilege escalation software\n" "$SUDO_CMD" - ## Check if the current directory is writable. GITPATH=$(dirname "$(realpath "$0")") if [ ! -w "$GITPATH" ]; then - echo "${RED}Can't write to $GITPATH${RC}" + print_colored "$RED" "Can't write to $GITPATH" exit 1 fi - ## Check SuperUser Group - SUPERUSERGROUP='wheel sudo root' for sug in $SUPERUSERGROUP; do if groups | grep -q "$sug"; then SUGROUP="$sug" - echo "Super user group $SUGROUP" + printf "Super user group %s\n" "$SUGROUP" break fi done - ## Check if member of the sudo group. if ! groups | grep -q "$SUGROUP"; then - echo "${RED}You need to be a member of the sudo group to run me!${RC}" + print_colored "$RED" "You need to be a member of the sudo group to run me!" exit 1 fi } -installDepend() { - ## Check for dependencies. - DEPENDENCIES='bash bash-completion tar bat tree multitail fastfetch wget unzip fontconfig' +install_dependencies() { + DEPENDENCIES='bash bash-completion tar bat tree multitail fastfetch wget unzip fontconfig trash-cli' if ! command_exists nvim; then DEPENDENCIES="${DEPENDENCIES} neovim" fi - echo "${YELLOW}Installing dependencies...${RC}" + print_colored "$YELLOW" "Installing dependencies..." if [ "$PACKAGER" = "pacman" ]; then if ! command_exists yay && ! command_exists paru; then - echo "Installing yay as AUR helper..." + printf "Installing yay as AUR helper...\n" ${SUDO_CMD} ${PACKAGER} --noconfirm -S base-devel cd /opt && ${SUDO_CMD} git clone https://aur.archlinux.org/yay-git.git && ${SUDO_CMD} chown -R "${USER}:${USER}" ./yay-git cd yay-git && makepkg --noconfirm -si else - echo "AUR helper already installed" + printf "AUR helper already installed\n" fi if command_exists yay; then AUR_HELPER="yay" elif command_exists paru; then AUR_HELPER="paru" else - echo "No AUR helper found. Please install yay or paru." + printf "No AUR helper found. Please install yay or paru.\n" exit 1 fi ${AUR_HELPER} --noconfirm -S ${DEPENDENCIES} elif [ "$PACKAGER" = "nala" ]; then ${SUDO_CMD} ${PACKAGER} install -y ${DEPENDENCIES} elif [ "$PACKAGER" = "emerge" ]; then - ${SUDO_CMD} ${PACKAGER} -v app-shells/bash app-shells/bash-completion app-arch/tar app-editors/neovim sys-apps/bat app-text/tree app-text/multitail app-misc/fastfetch + ${SUDO_CMD} ${PACKAGER} -v app-shells/bash app-shells/bash-completion app-arch/tar app-editors/neovim sys-apps/bat app-text/tree app-text/multitail app-misc/fastfetch app-misc/trash-cli elif [ "$PACKAGER" = "xbps-install" ]; then ${SUDO_CMD} ${PACKAGER} -v ${DEPENDENCIES} elif [ "$PACKAGER" = "nix-env" ]; then - ${SUDO_CMD} ${PACKAGER} -iA nixos.bash nixos.bash-completion nixos.gnutar nixos.neovim nixos.bat nixos.tree nixos.multitail nixos.fastfetch nixos.pkgs.starship + ${SUDO_CMD} ${PACKAGER} -iA nixos.bash nixos.bash-completion nixos.gnutar nixos.neovim nixos.bat nixos.tree nixos.multitail nixos.fastfetch nixos.pkgs.starship nixos.trash-cli elif [ "$PACKAGER" = "dnf" ]; then ${SUDO_CMD} ${PACKAGER} install -y ${DEPENDENCIES} else ${SUDO_CMD} ${PACKAGER} install -yq ${DEPENDENCIES} fi - # Check to see if the MesloLGS Nerd Font is installed (Change this to whatever font you would like) + install_font +} + +install_font() { FONT_NAME="MesloLGS Nerd Font Mono" if fc-list :family | grep -iq "$FONT_NAME"; then - echo "Font '$FONT_NAME' is installed." + printf "Font '%s' is installed.\n" "$FONT_NAME" else - echo "Installing font '$FONT_NAME'" - # Change this URL to correspond with the correct font + printf "Installing font '%s'\n" "$FONT_NAME" FONT_URL="https://github.com/ryanoasis/nerd-fonts/releases/latest/download/Meslo.zip" FONT_DIR="$HOME/.local/share/fonts" - # check if the file is accessible if wget -q --spider "$FONT_URL"; then TEMP_DIR=$(mktemp -d) - wget -q --show-progress $FONT_URL -O "$TEMP_DIR"/"${FONT_NAME}".zip - unzip "$TEMP_DIR"/"${FONT_NAME}".zip -d "$TEMP_DIR" - mkdir -p "$FONT_DIR"/"$FONT_NAME" - mv "${TEMP_DIR}"/*.ttf "$FONT_DIR"/"$FONT_NAME" - # Update the font cache + wget -q "$FONT_URL" -O "$TEMP_DIR/${FONT_NAME}.zip" + 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 - # delete the files created from this rm -rf "${TEMP_DIR}" - echo "'$FONT_NAME' installed successfully." + printf "'%s' installed successfully.\n" "$FONT_NAME" else - echo "Font '$FONT_NAME' not installed. Font URL is not accessible." + printf "Font '%s' not installed. Font URL is not accessible.\n" "$FONT_NAME" fi fi } -installStarshipAndFzf() { - if command_exists starship; then - echo "Starship already installed" - return - fi - - if ! curl -sS https://starship.rs/install.sh | sh; then - echo "${RED}Something went wrong during starship install!${RC}" - exit 1 - fi - if command_exists fzf; then - echo "Fzf already installed" +install_starship_and_fzf() { + if ! command_exists starship; then + if ! curl -sS https://starship.rs/install.sh | sh; then + print_colored "$RED" "Something went wrong during starship install!" + exit 1 + fi else - git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf - ~/.fzf/install + printf "Starship already installed\n" fi -} -installZoxide() { - if command_exists zoxide; then - echo "Zoxide already installed" - return - fi - - if ! curl -sS https://raw.githubusercontent.com/ajeetdsouza/zoxide/main/install.sh | sh; then - echo "${RED}Something went wrong during zoxide install!${RC}" - exit 1 + if ! command_exists fzf; then + if [ -d "$HOME/.fzf" ]; then + print_colored "$YELLOW" "FZF directory already exists. Skipping installation." + else + git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf + ~/.fzf/install + fi + else + printf "Fzf already installed\n" fi } -install_additional_dependencies() { - # we have PACKAGER so just use it - # for now just going to return early as we have already installed neovim in `installDepend` - # so I am not sure why we are trying to install it again - return - case "$PACKAGER" in - *apt) - if [ ! -d "/opt/neovim" ]; then - curl -LO https://github.com/neovim/neovim/releases/latest/download/nvim.appimage - chmod u+x nvim.appimage - ./nvim.appimage --appimage-extract - ${SUDO_CMD} mv squashfs-root /opt/neovim - ${SUDO_CMD} ln -s /opt/neovim/AppRun /usr/bin/nvim - fi - ;; - *zypper) - ${SUDO_CMD} zypper refresh - ${SUDO_CMD} zypper -n install neovim # -y doesn't work on opensuse -n is short for -non-interactive which is equivalent to -y - ;; - *dnf) - ${SUDO_CMD} dnf check-update - ${SUDO_CMD} dnf install -y neovim - ;; - *pacman) - ${SUDO_CMD} pacman -Syu - ${SUDO_CMD} pacman -S --noconfirm neovim - ;; - *) - echo "No supported package manager found. Please install neovim manually." +install_zoxide() { + if ! command_exists zoxide; then + if ! curl -sS https://raw.githubusercontent.com/ajeetdsouza/zoxide/main/install.sh | sh; then + print_colored "$RED" "Something went wrong during zoxide install!" exit 1 - ;; - esac + fi + else + printf "Zoxide already installed\n" + fi } create_fastfetch_config() { - ## Get the correct user home directory. USER_HOME=$(getent passwd "${SUDO_USER:-$USER}" | cut -d: -f6) + CONFIG_DIR="$USER_HOME/.config/fastfetch" + CONFIG_FILE="$CONFIG_DIR/config.jsonc" - if [ ! -d "$USER_HOME/.config/fastfetch" ]; then - mkdir -p "$USER_HOME/.config/fastfetch" - fi - # Check if the fastfetch config file exists - if [ -e "$USER_HOME/.config/fastfetch/config.jsonc" ]; then - rm -f "$USER_HOME/.config/fastfetch/config.jsonc" - fi - ln -svf "$GITPATH/config.jsonc" "$USER_HOME/.config/fastfetch/config.jsonc" || { - echo "${RED}Failed to create symbolic link for fastfetch config${RC}" + mkdir -p "$CONFIG_DIR" + [ -e "$CONFIG_FILE" ] && rm -f "$CONFIG_FILE" + + if ! ln -svf "$GITPATH/config.jsonc" "$CONFIG_FILE"; then + print_colored "$RED" "Failed to create symbolic link for fastfetch config" exit 1 - } + fi } -linkConfig() { - ## Get the correct user home directory. +link_config() { USER_HOME=$(getent passwd "${SUDO_USER:-$USER}" | cut -d: -f6) - ## Check if a bashrc file is already there. OLD_BASHRC="$USER_HOME/.bashrc" + if [ -e "$OLD_BASHRC" ]; then - echo "${YELLOW}Moving old bash config file to $USER_HOME/.bashrc.bak${RC}" + print_colored "$YELLOW" "Moving old bash config file to $USER_HOME/.bashrc.bak" if ! mv "$OLD_BASHRC" "$USER_HOME/.bashrc.bak"; then - echo "${RED}Can't move the old bash config file!${RC}" + print_colored "$RED" "Can't move the old bash config file!" exit 1 fi fi - echo "${YELLOW}Linking new bash config file...${RC}" - ln -svf "$GITPATH/.bashrc" "$USER_HOME/.bashrc" || { - echo "${RED}Failed to create symbolic link for .bashrc${RC}" + print_colored "$YELLOW" "Linking new bash config file..." + if ! ln -svf "$GITPATH/.bashrc" "$USER_HOME/.bashrc" || ! ln -svf "$GITPATH/starship.toml" "$USER_HOME/.config/starship.toml"; then + print_colored "$RED" "Failed to create symbolic links" exit 1 - } - ln -svf "$GITPATH/starship.toml" "$USER_HOME/.config/starship.toml" || { - echo "${RED}Failed to create symbolic link for starship.toml${RC}" - exit 1 - } + fi } -checkEnv -installDepend -installStarshipAndFzf -installZoxide -install_additional_dependencies +setup_directories +check_environment +install_dependencies +install_starship_and_fzf +install_zoxide create_fastfetch_config -if linkConfig; then - echo "${GREEN}Done!\nrestart your shell to see the changes.${RC}" +if link_config; then + print_colored "$GREEN" "Done!\nrestart your shell to see the changes." else - echo "${RED}Something went wrong!${RC}" + print_colored "$RED" "Something went wrong!" fi From 49d6fce2e310d5afd4d8873518a4d1cdd44dd900 Mon Sep 17 00:00:00 2001 From: DaCrab Date: Fri, 20 Sep 2024 17:05:16 +0300 Subject: [PATCH 2/4] made an uninstall file to completely remove all the cofig and dependencies improved the setup to create a new file to use with BlackBox (or with other terminals improved readme to include the new uninstall script --- README.md | 129 ++++++++++++++++++++++++++++++++---------- setup.sh | 97 ++++++++++++++++++++------------ uninstall.sh | 156 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 316 insertions(+), 66 deletions(-) create mode 100755 uninstall.sh diff --git a/README.md b/README.md index f4da045..acf7569 100644 --- a/README.md +++ b/README.md @@ -1,54 +1,121 @@ -## Overview of ChrisTitusTech's `.bashrc` Configuration +# ChrisTitusTech's `.bashrc` Configuration -The `.bashrc` file is a script that runs every time a new terminal session is started in Unix-like operating systems. It is used to configure the shell session, set up aliases, define functions, and more, making the terminal easier to use and more powerful. Below is a summary of the key sections and functionalities defined in the provided `.bashrc` file. +## Overview -## How to install -``` +This repository provides a comprehensive `.bashrc` configuration along with supporting scripts and configuration files to enhance your terminal experience in Unix-like operating systems. It configures the shell session by setting up aliases, defining functions, customizing the prompt, and more, significantly improving the terminal's usability and power. + +## Table of Contents + +- [Installation](#installation) +- [Uninstallation](#uninstallation) +- [Configuration Files](#configuration-files) + - [.bashrc](#bashrc) + - [starship.toml](#starshiptoml) + - [config.jsonc](#configjsonc) +- [Key Features](#key-features) +- [Advanced Functions](#advanced-functions) +- [System-Specific Configurations](#system-specific-configurations) +- [Conclusion](#conclusion) + +## Installation + +To install the `.bashrc` configuration, execute the following commands in your terminal: + +```sh git clone --depth=1 https://github.com/ChrisTitusTech/mybash.git cd mybash -chmod +x setup.sh ./setup.sh ``` -### Initial Setup and System Checks +The `setup.sh` script automates the installation process by: + +- Creating necessary directories (`linuxtoolbox/mybash`) +- Cloning the repository +- Installing dependencies (bash-completion, neovim, starship, fzf, zoxide) +- Installing the MesloLGS Nerd Font required for the prompt +- Linking configuration files (`.bashrc` and `starship.toml`) to your home directory +- Setting up additional utilities like `fastfetch` + +Ensure you have the required permissions and a supported package manager before running the script. + +## Uninstallation + +To uninstall the `.bashrc` configuration, run: + +```sh +cd mybash +chmod +x uninstall.sh +./uninstall.sh +``` + +The `uninstall.sh` script reverses the installation process by: + +- Removing installed dependencies +- Uninstalling fonts +- Removing symbolic links to configuration files +- Deleting the `linuxtoolbox` directory +- Cleaning up additional utilities like `starship`, `fzf`, and `zoxide` + +After running the script, it's recommended to restart your shell to apply the changes. + +## Configuration Files + +### `.bashrc` + +The `.bashrc` file defines aliases, functions, and environment variables to enhance your shell experience. Key features include: + +- **Aliases**: Shortcuts for common commands (e.g., `alias cp='cp -i'`) +- **Functions**: Custom functions for tasks like extracting archives and copying files with progress + +### `starship.toml` + +The `starship.toml` file configures the [Starship](https://starship.rs/) prompt, providing a highly customizable and informative shell prompt. It includes: -- **Environment Checks**: The script checks if it is running in an interactive mode and sets up the environment accordingly. -- **System Utilities**: It checks for the presence of utilities like `fastfetch`, `bash-completion`, and system-specific configurations (`/etc/bashrc`). +- **Theme Settings**: Defines colors and symbols for different prompt segments +- **Module Configurations**: Customizes modules like `python`, `git`, `docker_context`, and various programming languages +- **Format Customization**: Structures the layout and truncation of paths for a cleaner look -### Aliases and Functions +### `config.jsonc` -- **Aliases**: Shortcuts for common commands are set up to enhance productivity. For example, `alias cp='cp -i'` makes the `cp` command interactive, asking for confirmation before overwriting files. -- **Functions**: Custom functions for complex operations like `extract()` for extracting various archive types, and `cpp()` for copying files with a progress bar. +The `config.jsonc` file configures [fastfetch](https://github.com/AlexRogalskiy/fastfetch), a system information tool. It includes: -### Prompt Customization and History Management +- **Logo and Display Settings**: Customizes the appearance of system logos and separators +- **Modules**: Defines which system information modules to display, such as CPU, GPU, OS, kernel, and uptime +- **Custom Sections**: Adds custom formatted sections for hardware and software information -- **Prompt Command**: The `PROMPT_COMMAND` variable is set to automatically save the command history after each command. -- **History Control**: Settings to manage the size of the history file and how duplicates are handled. +## Key Features -### System-Specific Aliases and Settings +1. **Aliases and Functions** + - Shortcuts for common commands + - Custom functions for complex operations (e.g., extracting archives, copying with progress) -- **Editor Settings**: Sets `nvim` (NeoVim) as the default editor. -- **Conditional Aliases**: Depending on the system type (like Fedora), it sets specific aliases, e.g., replacing `cat` with `bat`. +2. **Prompt Customization and History Management** + - Configures PROMPT_COMMAND for automatic history saving + - Manages history file size and handles duplicates -### Enhancements and Utilities +3. **Enhancements and Utilities** + - Improves command output readability with colors + - Introduces safer file operations (e.g., using `trash` instead of `rm`) + - Integrates Zoxide for easy directory navigation -- **Color and Formatting**: Enhancements for command output readability using colors and formatting for tools like `ls`, `grep`, and `man`. -- **Navigation Shortcuts**: Aliases to simplify directory navigation, e.g., `alias ..='cd ..'` to go up one directory. -- **Safety Features**: Aliases for safer file operations, like using `trash` instead of `rm` for deleting files, to prevent accidental data loss. -- **Extensive Zoxide support**: Easily navigate with `z`, `zi`, or pressing Ctrl+f to launch zi to see frequently used navigation directories. +4. **Installation and Configuration Helpers** + - Auto-installs necessary utilities based on system type + - Provides functions to edit important configuration files -### Advanced Functions +## Advanced Functions -- **System Information**: Functions to display system information like `distribution()` to identify the Linux distribution. -- **Networking Utilities**: Tools to check internal and external IP addresses. -- **Resource Monitoring**: Commands to monitor system resources like disk usage and open ports. +- System information display +- Networking utilities (e.g., IP address checks) +- Resource monitoring tools -### Installation and Configuration Helpers +## System-Specific Configurations -- **Auto-Install**: A function `install_bashrc_support()` to automatically install necessary utilities based on the system type. -- **Configuration Editors**: Functions to edit important configuration files directly, e.g., `apacheconfig()` for Apache server configurations. +- Editor settings (NeoVim as default) +- Conditional aliases based on system type +- Package manager-specific commands -### Conclusion +## Conclusion -This `.bashrc` file is a comprehensive setup that not only enhances the shell experience with useful aliases and functions but also provides system-specific configurations and safety features to cater to different user needs and system types. It is designed to make the terminal more user-friendly, efficient, and powerful for an average user. +This `.bashrc` configuration offers a powerful and customizable terminal environment suitable for various Unix-like systems. It enhances productivity through smart aliases, functions, and integrated tools while maintaining flexibility for system-specific needs. Whether you're a developer, system administrator, or power user, this setup aims to make your terminal experience more efficient and enjoyable. +For any issues, suggestions, or contributions, please open an issue or pull request in this repository. We welcome community involvement to make this configuration even better! \ No newline at end of file diff --git a/setup.sh b/setup.sh index 5f28fe1..930ecf5 100755 --- a/setup.sh +++ b/setup.sh @@ -12,16 +12,16 @@ SUDO_CMD="" SUGROUP="" GITPATH="" +# Helper functions print_colored() { - color=$1 - message=$2 - printf "${color}%s${RC}\n" "$message" + printf "${1}%s${RC}\n" "$2" } command_exists() { command -v "$1" >/dev/null 2>&1 } +# Setup functions setup_directories() { if [ ! -d "$LINUXTOOLBOXDIR" ]; then print_colored "$YELLOW" "Creating linuxtoolbox directory: $LINUXTOOLBOXDIR" @@ -43,6 +43,7 @@ setup_directories() { } check_environment() { + # Check for required commands REQUIREMENTS='curl groups sudo' for req in $REQUIREMENTS; do if ! command_exists "$req"; then @@ -51,6 +52,7 @@ check_environment() { fi done + # Determine package manager PACKAGEMANAGER='nala apt dnf yum pacman zypper emerge xbps-install nix-env' for pgm in $PACKAGEMANAGER; do if command_exists "$pgm"; then @@ -65,6 +67,7 @@ check_environment() { exit 1 fi + # Determine sudo command if command_exists sudo; then SUDO_CMD="sudo" elif command_exists doas && [ -f "/etc/doas.conf" ]; then @@ -72,15 +75,16 @@ check_environment() { else SUDO_CMD="su -c" fi - printf "Using %s as privilege escalation software\n" "$SUDO_CMD" + # Check write permissions GITPATH=$(dirname "$(realpath "$0")") if [ ! -w "$GITPATH" ]; then print_colored "$RED" "Can't write to $GITPATH" exit 1 fi + # Check superuser group SUPERUSERGROUP='wheel sudo root' for sug in $SUPERUSERGROUP; do if groups | grep -q "$sug"; then @@ -103,41 +107,53 @@ install_dependencies() { fi print_colored "$YELLOW" "Installing dependencies..." - if [ "$PACKAGER" = "pacman" ]; then - if ! command_exists yay && ! command_exists paru; then - printf "Installing yay as AUR helper...\n" - ${SUDO_CMD} ${PACKAGER} --noconfirm -S base-devel - cd /opt && ${SUDO_CMD} git clone https://aur.archlinux.org/yay-git.git && ${SUDO_CMD} chown -R "${USER}:${USER}" ./yay-git - cd yay-git && makepkg --noconfirm -si - else - printf "AUR helper already installed\n" - fi - if command_exists yay; then - AUR_HELPER="yay" - elif command_exists paru; then - AUR_HELPER="paru" - else - printf "No AUR helper found. Please install yay or paru.\n" - exit 1 - fi - ${AUR_HELPER} --noconfirm -S ${DEPENDENCIES} - elif [ "$PACKAGER" = "nala" ]; then - ${SUDO_CMD} ${PACKAGER} install -y ${DEPENDENCIES} - elif [ "$PACKAGER" = "emerge" ]; then - ${SUDO_CMD} ${PACKAGER} -v app-shells/bash app-shells/bash-completion app-arch/tar app-editors/neovim sys-apps/bat app-text/tree app-text/multitail app-misc/fastfetch app-misc/trash-cli - elif [ "$PACKAGER" = "xbps-install" ]; then - ${SUDO_CMD} ${PACKAGER} -v ${DEPENDENCIES} - elif [ "$PACKAGER" = "nix-env" ]; then - ${SUDO_CMD} ${PACKAGER} -iA nixos.bash nixos.bash-completion nixos.gnutar nixos.neovim nixos.bat nixos.tree nixos.multitail nixos.fastfetch nixos.pkgs.starship nixos.trash-cli - elif [ "$PACKAGER" = "dnf" ]; then - ${SUDO_CMD} ${PACKAGER} install -y ${DEPENDENCIES} - else - ${SUDO_CMD} ${PACKAGER} install -yq ${DEPENDENCIES} - fi + case "$PACKAGER" in + pacman) + install_pacman_dependencies + ;; + nala) + ${SUDO_CMD} ${PACKAGER} install -y ${DEPENDENCIES} + ;; + emerge) + ${SUDO_CMD} ${PACKAGER} -v app-shells/bash app-shells/bash-completion app-arch/tar app-editors/neovim sys-apps/bat app-text/tree app-text/multitail app-misc/fastfetch app-misc/trash-cli + ;; + xbps-install) + ${SUDO_CMD} ${PACKAGER} -v ${DEPENDENCIES} + ;; + nix-env) + ${SUDO_CMD} ${PACKAGER} -iA nixos.bash nixos.bash-completion nixos.gnutar nixos.neovim nixos.bat nixos.tree nixos.multitail nixos.fastfetch nixos.pkgs.starship nixos.trash-cli + ;; + dnf) + ${SUDO_CMD} ${PACKAGER} install -y ${DEPENDENCIES} + ;; + *) + ${SUDO_CMD} ${PACKAGER} install -yq ${DEPENDENCIES} + ;; + esac install_font } +install_pacman_dependencies() { + if ! command_exists yay && ! command_exists paru; then + printf "Installing yay as AUR helper...\n" + ${SUDO_CMD} ${PACKAGER} --noconfirm -S base-devel + cd /opt && ${SUDO_CMD} git clone https://aur.archlinux.org/yay-git.git && ${SUDO_CMD} chown -R "${USER}:${USER}" ./yay-git + cd yay-git && makepkg --noconfirm -si + else + printf "AUR helper already installed\n" + fi + if command_exists yay; then + AUR_HELPER="yay" + elif command_exists paru; then + AUR_HELPER="paru" + else + printf "No AUR helper found. Please install yay or paru.\n" + exit 1 + fi + ${AUR_HELPER} --noconfirm -S ${DEPENDENCIES} +} + install_font() { FONT_NAME="MesloLGS Nerd Font Mono" if fc-list :family | grep -iq "$FONT_NAME"; then @@ -211,6 +227,7 @@ create_fastfetch_config() { link_config() { USER_HOME=$(getent passwd "${SUDO_USER:-$USER}" | cut -d: -f6) OLD_BASHRC="$USER_HOME/.bashrc" + BASH_PROFILE="$USER_HOME/.bash_profile" if [ -e "$OLD_BASHRC" ]; then print_colored "$YELLOW" "Moving old bash config file to $USER_HOME/.bashrc.bak" @@ -225,8 +242,18 @@ link_config() { print_colored "$RED" "Failed to create symbolic links" exit 1 fi + + # Create .bash_profile if it doesn't exist + if [ ! -f "$BASH_PROFILE" ]; then + print_colored "$YELLOW" "Creating .bash_profile..." + echo "[ -f ~/.bashrc ] && . ~/.bashrc" > "$BASH_PROFILE" + print_colored "$GREEN" ".bash_profile created and configured to source .bashrc" + else + print_colored "$YELLOW" ".bash_profile already exists. Please ensure it sources .bashrc if needed." + fi } +# Main execution setup_directories check_environment install_dependencies diff --git a/uninstall.sh b/uninstall.sh new file mode 100755 index 0000000..ae4f51b --- /dev/null +++ b/uninstall.sh @@ -0,0 +1,156 @@ +#!/bin/sh -e + +# Define color codes using tput for better compatibility +RC=$(tput sgr0) +RED=$(tput setaf 1) +YELLOW=$(tput setaf 3) +GREEN=$(tput setaf 2) + +LINUXTOOLBOXDIR="$HOME/linuxtoolbox" +PACKAGER="" +SUDO_CMD="" + +print_colored() { + color=$1 + message=$2 + printf "${color}%s${RC}\n" "$message" +} + +command_exists() { + command -v "$1" >/dev/null 2>&1 +} + +determine_package_manager() { + PACKAGEMANAGER='nala apt dnf yum pacman zypper emerge xbps-install nix-env' + for pgm in $PACKAGEMANAGER; do + if command_exists "$pgm"; then + PACKAGER="$pgm" + printf "Using %s\n" "$pgm" + break + fi + done + + if [ -z "$PACKAGER" ]; then + print_colored "$RED" "Can't find a supported package manager" + exit 1 + fi +} + +determine_sudo_command() { + if command_exists sudo; then + SUDO_CMD="sudo" + elif command_exists doas && [ -f "/etc/doas.conf" ]; then + SUDO_CMD="doas" + else + SUDO_CMD="su -c" + fi + + printf "Using %s as privilege escalation software\n" "$SUDO_CMD" +} + +uninstall_dependencies() { + DEPENDENCIES='bash-completion bat tree multitail fastfetch neovim trash-cli' + + print_colored "$YELLOW" "Uninstalling dependencies..." + if [ "$PACKAGER" = "pacman" ]; then + if command_exists yay; then + yay -Rns --noconfirm ${DEPENDENCIES} + elif command_exists paru; then + paru -Rns --noconfirm ${DEPENDENCIES} + else + ${SUDO_CMD} pacman -Rns --noconfirm ${DEPENDENCIES} + fi + elif [ "$PACKAGER" = "nala" ] || [ "$PACKAGER" = "apt" ]; then + ${SUDO_CMD} ${PACKAGER} purge -y ${DEPENDENCIES} + elif [ "$PACKAGER" = "emerge" ]; then + ${SUDO_CMD} ${PACKAGER} --deselect app-shells/bash-completion sys-apps/bat app-text/tree app-text/multitail app-misc/fastfetch app-editors/neovim app-misc/trash-cli + elif [ "$PACKAGER" = "xbps-install" ]; then + ${SUDO_CMD} xbps-remove -Ry ${DEPENDENCIES} + elif [ "$PACKAGER" = "nix-env" ]; then + ${SUDO_CMD} ${PACKAGER} -e bash-completion bat tree multitail fastfetch neovim trash-cli + elif [ "$PACKAGER" = "dnf" ] || [ "$PACKAGER" = "yum" ]; then + ${SUDO_CMD} ${PACKAGER} remove -y ${DEPENDENCIES} + else + ${SUDO_CMD} ${PACKAGER} remove -y ${DEPENDENCIES} + fi +} + +uninstall_font() { + FONT_NAME="MesloLGS Nerd Font Mono" + FONT_DIR="$HOME/.local/share/fonts/$FONT_NAME" + + if [ -d "$FONT_DIR" ]; then + print_colored "$YELLOW" "Removing font: $FONT_NAME" + rm -rf "$FONT_DIR" + fc-cache -fv + print_colored "$GREEN" "Font removed: $FONT_NAME" + else + print_colored "$YELLOW" "Font not found: $FONT_NAME" + fi +} + +uninstall_starship_and_fzf() { + if command_exists starship; then + print_colored "$YELLOW" "Uninstalling Starship..." + ${SUDO_CMD} rm -f "$(command -v starship)" + print_colored "$GREEN" "Starship uninstalled" + fi + + if [ -d "$HOME/.fzf" ]; then + print_colored "$YELLOW" "Uninstalling fzf..." + "$HOME/.fzf/uninstall" + rm -rf "$HOME/.fzf" + print_colored "$GREEN" "fzf uninstalled" + fi +} + +uninstall_zoxide() { + if command_exists zoxide; then + print_colored "$YELLOW" "Uninstalling Zoxide..." + ${SUDO_CMD} rm -f "$(command -v zoxide)" + print_colored "$GREEN" "Zoxide uninstalled" + fi +} + +remove_configs() { + USER_HOME=$(getent passwd "${SUDO_USER:-$USER}" | cut -d: -f6) + + print_colored "$YELLOW" "Removing configuration files..." + + # Remove .bashrc symlink and restore backup if it exists + if [ -L "$USER_HOME/.bashrc" ]; then + rm "$USER_HOME/.bashrc" + if [ -f "$USER_HOME/.bashrc.bak" ]; then + mv "$USER_HOME/.bashrc.bak" "$USER_HOME/.bashrc" + print_colored "$GREEN" "Restored original .bashrc" + fi + fi + + # Remove starship config + rm -f "$USER_HOME/.config/starship.toml" + + # Remove fastfetch config + rm -f "$USER_HOME/.config/fastfetch/config.jsonc" + + print_colored "$GREEN" "Configuration files removed" +} + +remove_linuxtoolbox() { + if [ -d "$LINUXTOOLBOXDIR" ]; then + print_colored "$YELLOW" "Removing linuxtoolbox directory..." + rm -rf "$LINUXTOOLBOXDIR" + print_colored "$GREEN" "linuxtoolbox directory removed" + fi +} + +# Main execution +determine_package_manager +determine_sudo_command +uninstall_dependencies +uninstall_font +uninstall_starship_and_fzf +uninstall_zoxide +remove_configs +remove_linuxtoolbox + +print_colored "$GREEN" "Uninstallation complete. Please restart your shell for changes to take effect." \ No newline at end of file From 35094feddb40b52511b9d85ff3385d70b2b5ce9d Mon Sep 17 00:00:00 2001 From: dacrab Date: Mon, 13 Jan 2025 23:03:27 +0200 Subject: [PATCH 3/4] update to use @dacrab 's fastfetch config --- config.jsonc | 186 ++++++++++++++++++++++++++++++--------------------- 1 file changed, 108 insertions(+), 78 deletions(-) diff --git a/config.jsonc b/config.jsonc index 3a85404..11073cf 100644 --- a/config.jsonc +++ b/config.jsonc @@ -1,86 +1,116 @@ { "$schema": "https://github.com/fastfetch-cli/fastfetch/raw/dev/doc/json_schema.json", "logo": { - "type": "builtin", - "color": { - "1": "white", - "2": "cyan" - } + "padding": { + "top": 2, + "left": 1, + "right": 2 + } }, "display": { - "separator": "  ", - "color": "cyan" + "separator": " " }, "modules": [ - { - "type": "custom", // HardwareStart - "format": "┌─────────── \u001b[1mHardware Information\u001b[0m ───────────┐" // `\u001b` is `\033`, or `\e` - }, - { - "type": "host", - "key": " 󰌢" - }, - { - "type": "cpu", - "key": " " - }, - { - "type": "gpu", - "detectionMethod": "pci", - "key": " " - }, - { - "type": "display", - "key": " 󱄄" - }, - { - "type": "memory", - "key": " " - }, - { - "type": "custom", // SoftwareStart - "format": "├─────────── \u001b[1mSoftware Information\u001b[0m ───────────┤" - }, - { - "type": "os", - "key": " " // Just get your distro's logo off nerdfonts.com, - }, - { - "type": "kernel", - "key": " ", - "format": "{1} {2}" - }, - { - "type": "wm", - "key": " " - }, - { - "type": "shell", - "key": " " - }, - { - "type": "custom", - "format": "|──────────────\u001b[1mUptime / Age\u001b[0m──────────────────|" - }, - { - "type": "command", - "key": " OS Age ", - "keyColor": "magenta", - "text": "birth_install=$(stat -c %W /); current=$(date +%s); time_progression=$((current - birth_install)); days_difference=$((time_progression / 86400)); echo $days_difference days" - }, - { - "type": "uptime", - "key": " Uptime ", - "keyColor": "magenta" - }, - { - "type": "custom", // InformationEnd - "format": "└────────────────────────────────────────────┘" - }, - { - "type": "colors", - "paddingLeft": 2, - "symbol": "circle" - } + // Title + { + "type": "title", + "format": "{#1}╭───────────── {#}{user-name-colored}" + }, + // System Information + { + "type": "custom", + "format": "{#1}│ {#}System Information" + }, + { + "type": "os", + "key": "{#separator}│ {#keys}󰍹 OS" + }, + { + "type": "kernel", + "key": "{#separator}│ {#keys}󰒋 Kernel" + }, + { + "type": "uptime", + "key": "{#separator}│ {#keys}󰅐 Uptime" + }, + { + "type": "packages", + "key": "{#separator}│ {#keys}󰏖 Packages", + "format": "{all}" + }, + { + "type": "custom", + "format": "{#1}│" + }, + // Desktop Environment + { + "type": "custom", + "format": "{#1}│ {#}Desktop Environment" + }, + { + "type": "de", + "key": "{#separator}│ {#keys}󰧨 DE" + }, + { + "type": "wm", + "key": "{#separator}│ {#keys}󱂬 WM" + }, + { + "type": "wmtheme", + "key": "{#separator}│ {#keys}󰉼 Theme" + }, + { + "type": "display", + "key": "{#separator}│ {#keys}󰹑 Resolution" + }, + { + "type": "shell", + "key": "{#separator}│ {#keys}󰞷 Shell" + }, + { + "type": "terminalfont", + "key": "{#separator}│ {#keys}󰛖 Font" + }, + { + "type": "custom", + "format": "{#1}│" + }, + // Hardware Information + { + "type": "custom", + "format": "{#1}│ {#}Hardware Information" + }, + { + "type": "cpu", + "key": "{#separator}│ {#keys}󰻠 CPU" + }, + { + "type": "gpu", + "key": "{#separator}│ {#keys}󰢮 GPU" + }, + { + "type": "memory", + "key": "{#separator}│ {#keys}󰍛 Memory" + }, + { + "type": "disk", + "key": "{#separator}│ {#keys}󰋊 Disk (/)", + "folders": "/" + }, + { + "type": "custom", + "format": "{#1}│" + }, + // Colors + { + "type": "colors", + "key": "{#separator}│", + "symbol": "circle" + }, + // Footer + { + "type": "custom", + "format": "{#1}╰───────────────────────────────╯" + } ] -} + } \ No newline at end of file From 5c5394c90485666008f55f26b8ae6763eb4ecab2 Mon Sep 17 00:00:00 2001 From: dacrab Date: Mon, 13 Jan 2025 23:04:07 +0200 Subject: [PATCH 4/4] update readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index acf7569..2bf911f 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ This repository provides a comprehensive `.bashrc` configuration along with supp To install the `.bashrc` configuration, execute the following commands in your terminal: ```sh -git clone --depth=1 https://github.com/ChrisTitusTech/mybash.git +git clone --depth=1 https://github.com/dacrab/mybash.git cd mybash ./setup.sh ```