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

This commit is contained in:
DaCrab
2024-09-20 17:05:16 +03:00
parent 9394790b00
commit 49d6fce2e3
3 changed files with 316 additions and 66 deletions

129
README.md
View File

@@ -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:
- **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`).
- 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`
### Aliases and Functions
Ensure you have the required permissions and a supported package manager before running the script.
- **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.
## Uninstallation
### Prompt Customization and History Management
To uninstall the `.bashrc` configuration, run:
- **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.
```sh
cd mybash
chmod +x uninstall.sh
./uninstall.sh
```
### System-Specific Aliases and Settings
The `uninstall.sh` script reverses the installation process by:
- **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`.
- Removing installed dependencies
- Uninstalling fonts
- Removing symbolic links to configuration files
- Deleting the `linuxtoolbox` directory
- Cleaning up additional utilities like `starship`, `fzf`, and `zoxide`
### Enhancements and Utilities
After running the script, it's recommended to restart your shell to apply the changes.
- **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.
## Configuration Files
### Advanced Functions
### `.bashrc`
- **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.
The `.bashrc` file defines aliases, functions, and environment variables to enhance your shell experience. Key features include:
### Installation and Configuration Helpers
- **Aliases**: Shortcuts for common commands (e.g., `alias cp='cp -i'`)
- **Functions**: Custom functions for tasks like extracting archives and copying files with progress
- **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.
### `starship.toml`
### Conclusion
The `starship.toml` file configures the [Starship](https://starship.rs/) prompt, providing a highly customizable and informative shell prompt. It includes:
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.
- **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
### `config.jsonc`
The `config.jsonc` file configures [fastfetch](https://github.com/AlexRogalskiy/fastfetch), a system information tool. It includes:
- **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
## Key Features
1. **Aliases and Functions**
- Shortcuts for common commands
- Custom functions for complex operations (e.g., extracting archives, copying with progress)
2. **Prompt Customization and History Management**
- Configures PROMPT_COMMAND for automatic history saving
- Manages history file size and handles duplicates
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
4. **Installation and Configuration Helpers**
- Auto-installs necessary utilities based on system type
- Provides functions to edit important configuration files
## Advanced Functions
- System information display
- Networking utilities (e.g., IP address checks)
- Resource monitoring tools
## System-Specific Configurations
- Editor settings (NeoVim as default)
- Conditional aliases based on system type
- Package manager-specific commands
## Conclusion
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!

View File

@@ -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

156
uninstall.sh Executable file
View File

@@ -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."