mirror of
https://github.com/ChrisTitusTech/mybash.git
synced 2026-04-02 10:38:14 +00:00
Merge pull request #93 from dacrab/main
-Script optimization - organization
This commit is contained in:
131
README.md
131
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
|
||||
```
|
||||
git clone --depth=1 https://github.com/ChrisTitusTech/mybash.git
|
||||
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/dacrab/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!
|
||||
186
config.jsonc
186
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}╰───────────────────────────────╯"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
338
setup.sh
338
setup.sh
@@ -1,67 +1,73 @@
|
||||
#!/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
|
||||
# Helper functions
|
||||
print_colored() {
|
||||
printf "${1}%s${RC}\n" "$2"
|
||||
}
|
||||
|
||||
command_exists() {
|
||||
command -v "$1" >/dev/null 2>&1
|
||||
}
|
||||
|
||||
checkEnv() {
|
||||
## Check for requirements.
|
||||
# Setup functions
|
||||
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() {
|
||||
# Check for required commands
|
||||
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
|
||||
# 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"
|
||||
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
|
||||
|
||||
# Determine sudo command
|
||||
if command_exists sudo; then
|
||||
SUDO_CMD="sudo"
|
||||
elif command_exists doas && [ -f "/etc/doas.conf" ]; then
|
||||
@@ -69,84 +75,93 @@ checkEnv() {
|
||||
else
|
||||
SUDO_CMD="su -c"
|
||||
fi
|
||||
printf "Using %s as privilege escalation software\n" "$SUDO_CMD"
|
||||
|
||||
echo "Using $SUDO_CMD as privilege escalation software"
|
||||
|
||||
## Check if the current directory is writable.
|
||||
# Check write permissions
|
||||
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
|
||||
|
||||
# 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}"
|
||||
if [ "$PACKAGER" = "pacman" ]; then
|
||||
if ! command_exists yay && ! command_exists paru; then
|
||||
echo "Installing yay as AUR helper..."
|
||||
${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"
|
||||
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."
|
||||
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
|
||||
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
|
||||
elif [ "$PACKAGER" = "dnf" ]; then
|
||||
${SUDO_CMD} ${PACKAGER} install -y ${DEPENDENCIES}
|
||||
else
|
||||
${SUDO_CMD} ${PACKAGER} install -yq ${DEPENDENCIES}
|
||||
fi
|
||||
print_colored "$YELLOW" "Installing dependencies..."
|
||||
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
|
||||
|
||||
# Check to see if the MesloLGS Nerd Font is installed (Change this to whatever font you would like)
|
||||
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
|
||||
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 $FONT_URL -O "$TEMP_DIR"/"${FONT_NAME}".zip
|
||||
@@ -155,129 +170,100 @@ installDepend() {
|
||||
mv "${TEMP_DIR}"/*.ttf "$FONT_DIR"/"$FONT_NAME"
|
||||
# Update the font cache
|
||||
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"
|
||||
else
|
||||
git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf
|
||||
~/.fzf/install
|
||||
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
|
||||
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_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
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
else
|
||||
printf "Starship already installed\n"
|
||||
fi
|
||||
|
||||
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_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
|
||||
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"
|
||||
BASH_PROFILE="$USER_HOME/.bash_profile"
|
||||
|
||||
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
|
||||
|
||||
# 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
|
||||
}
|
||||
|
||||
checkEnv
|
||||
installDepend
|
||||
installStarshipAndFzf
|
||||
installZoxide
|
||||
install_additional_dependencies
|
||||
# Main execution
|
||||
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
|
||||
|
||||
156
uninstall.sh
Executable file
156
uninstall.sh
Executable 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."
|
||||
Reference in New Issue
Block a user