Initial settings
- Common aliases - Distro-specific aliases - Shell prompt - README
This commit is contained in:
parent
cbbd2bcec0
commit
2444248a8c
69
README.md
69
README.md
@ -1,3 +1,68 @@
|
||||
# dotfiles_bash
|
||||
# Bash Dotfiles
|
||||
|
||||
Bash Shell Configurations
|
||||
System-wide `bash` Shell Configurations!
|
||||
|
||||
## Features
|
||||
- **Centralized** - All configs in `/etc/bash/`.
|
||||
- **System-wide** - Common configs for all users.
|
||||
- **Modular structure** - Split by function (aliases, prompts, etc.)
|
||||
- **OS-aware aliases** - Distro-specific aliases for appropriate package manager commands.
|
||||
- **Colors!** - Use of colors where possible.
|
||||
|
||||
## How to use
|
||||
|
||||
1. Clone this repo to `/etc`.
|
||||
```bash
|
||||
git clone https://git.candifloss.cc/candifloss/dotfiles_bash.git /etc/bash
|
||||
```
|
||||
|
||||
2. Add this to the end of `/etc/bash.bashrc`:
|
||||
```bash
|
||||
if [ -d /etc/bash ]; then # Check if the dir exists
|
||||
for file in /etc/bash/*.sh; do # Include all the files in the dir
|
||||
if [ -r "$file" ]; then # Check if the file exists
|
||||
. "$file"
|
||||
fi
|
||||
done
|
||||
fi
|
||||
```
|
||||
|
||||
## File structure
|
||||
```
|
||||
/etc/bash/ # `mkdir` or `git clone` to this directory
|
||||
├── bash_alias_common.sh # Common aliases
|
||||
├── bash_alias_distro.sh # Distro-specific aliases
|
||||
├── bash_prompt.sh # Shell prompt
|
||||
├── LICENSE # Repo license
|
||||
└── README.md # This file
|
||||
```
|
||||
|
||||
## Trouble-shooting
|
||||
|
||||
- Alias not working?
|
||||
Run `alias | grep <command>` to find overrides
|
||||
|
||||
- Settings over-ridden?
|
||||
These files can override your aliases and other settings (check in order):
|
||||
|
||||
1. `/etc/profile`
|
||||
2. `/etc/bash.bashrc`
|
||||
3. `~/.bash_profile`
|
||||
4. `~/.bash_login`
|
||||
5. `~/.profile`
|
||||
6. `~/.bashrc`
|
||||
|
||||
- Permission errors
|
||||
```bash
|
||||
sudo chmod -R 755 /etc/bash
|
||||
```
|
||||
|
||||
- Debug Loading Order
|
||||
Check which files are loaded
|
||||
|
||||
```bash
|
||||
bash --login --verbose --norc 2>&1 | grep -E '^\+.*\. '
|
||||
```
|
||||
|
||||
- Colors missing?
|
||||
Check the `TERM` variables and your terminal's capabilities.
|
61
bash_alias_common.sh
Normal file
61
bash_alias_common.sh
Normal file
@ -0,0 +1,61 @@
|
||||
#---------------------------------------------------------------------
|
||||
# Navigation
|
||||
#---------------------------------------------------------------------
|
||||
alias ..='cd ..' # Go up one directory
|
||||
alias ...='cd ../..' # Go up two directories
|
||||
alias ....='cd ../../..' # Go up three directories
|
||||
alias ~='cd ~' # Go to home directory
|
||||
alias -- -='cd -' # Go to previous directory
|
||||
|
||||
#---------------------------------------------------------------------
|
||||
# Listing (using lsd)
|
||||
#---------------------------------------------------------------------
|
||||
alias ls='lsd --color=always' # Basic colored listing
|
||||
alias l='lsd -lh' # Detailed list
|
||||
alias la='lsd -alh' # All files (including hidden) with details
|
||||
alias lt='lsd --tree' # Tree view
|
||||
alias l.='lsd -d .*' # Only hidden files
|
||||
|
||||
#---------------------------------------------------------------------
|
||||
# Safety & Confirmation
|
||||
#---------------------------------------------------------------------
|
||||
alias rm='rm -iv' # Confirm before deleting (verbose)
|
||||
alias cp='cp -iv' # Confirm before overwriting (verbose)
|
||||
alias mv='mv -iv' # Confirm before moving (verbose)
|
||||
alias mkdir='mkdir -pv' # Create parent directories if needed (verbose)
|
||||
|
||||
#---------------------------------------------------------------------
|
||||
# Improved CLI Tools
|
||||
#---------------------------------------------------------------------
|
||||
alias grep='grep --color=always' # Always colorize grep output
|
||||
alias egrep='egrep --color=always'
|
||||
alias fgrep='fgrep --color=always'
|
||||
alias diff='diff --color=always'
|
||||
alias ip='ip -color=always'
|
||||
alias less='less -R' # Use bat as less replacement
|
||||
|
||||
#---------------------------------------------------------------------
|
||||
# Bat (cat replacement)
|
||||
#---------------------------------------------------------------------
|
||||
alias cat='bat -pP' # Plain paging with syntax highlighting
|
||||
alias bless='bat --paging=always --style=plain' # Full pager mode
|
||||
|
||||
#---------------------------------------------------------------------
|
||||
# Miscellaneous
|
||||
#---------------------------------------------------------------------
|
||||
alias c='clear' # Clear screen
|
||||
alias h='history' # Show history
|
||||
alias j='jobs -l' # List jobs
|
||||
alias vi='vim' # Always use vim
|
||||
alias df='df -h' # Human-readable disk space
|
||||
alias du='du -h' # Human-readable directory sizes
|
||||
alias free='free -h' # Human-readable memory usage
|
||||
|
||||
#---------------------------------------------------------------------
|
||||
# Color Support
|
||||
#---------------------------------------------------------------------
|
||||
# Enable color support for various commands
|
||||
if [ -x /usr/bin/dircolors ]; then
|
||||
test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
|
||||
fi
|
||||
|
57
bash_alias_distro.sh
Normal file
57
bash_alias_distro.sh
Normal file
@ -0,0 +1,57 @@
|
||||
#!/usr/bin/env bash
|
||||
# OS-specific aliases
|
||||
|
||||
# Manually set OS (comment out for auto-detection)
|
||||
export OS="debian"
|
||||
|
||||
# OS Detection (if not manually set)
|
||||
if [[ -z "$OS" ]]; then
|
||||
if [[ -f /etc/os-release ]]; then
|
||||
OS=$(grep -oP '^ID=\K.+' /etc/os-release | tr -d '"')
|
||||
elif [[ $(uname) == "FreeBSD" ]]; then
|
||||
OS="freebsd"
|
||||
fi
|
||||
export OS
|
||||
fi
|
||||
|
||||
# OS-Specific Aliases
|
||||
case "$OS" in
|
||||
debian)
|
||||
alias inst='sudo apt-get install -y'
|
||||
alias updt='sudo apt-get update && sudo apt-get upgrade -y && rustup update'
|
||||
;;
|
||||
ubuntu)
|
||||
alias inst='sudo apt-get install -y'
|
||||
alias updt='sudo apt-get update && sudo apt-get upgrade -y && sudo snap refresh && rustup update'
|
||||
;;
|
||||
arch|manjaro)
|
||||
alias inst='sudo pacman -S'
|
||||
alias updt='sudo pacman -Syuu --noconfirm && paru -Syu --noconfirm && rustup update'
|
||||
;;
|
||||
fedora|centos|rhel|rocky|almalinux)
|
||||
alias inst='sudo dnf install -y'
|
||||
alias updt='sudo dnf upgrade -y && rustup update'
|
||||
;;
|
||||
opensuse*|tumbleweed)
|
||||
alias inst='sudo zypper install -y'
|
||||
alias updt='sudo zypper refresh && sudo zypper update -y && rustup update'
|
||||
;;
|
||||
void)
|
||||
alias inst='sudo xbps-install -Sy'
|
||||
alias updt='sudo xbps-install -Su && rustup update'
|
||||
;;
|
||||
alpine)
|
||||
alias inst='sudo apk add'
|
||||
alias updt='sudo apk update && sudo apk upgrade && rustup update'
|
||||
;;
|
||||
freebsd)
|
||||
alias inst='sudo pkg install -y'
|
||||
alias updt='sudo pkg update && sudo pkg upgrade -y && rustup update'
|
||||
;;
|
||||
*)
|
||||
echo "No OS-specific aliases for OS: $OS" >&2
|
||||
;;
|
||||
esac
|
||||
|
||||
# Cleanup (unset helper functions if needed)
|
||||
unset -f _detect_os 2>/dev/null
|
29
bash_prompt.sh
Normal file
29
bash_prompt.sh
Normal file
@ -0,0 +1,29 @@
|
||||
set_prompt() {
|
||||
local EXIT_STATUS="$?"
|
||||
local COLOR_RESET='\[\033[0m\]'
|
||||
|
||||
# User settings
|
||||
if (( EUID == 0 )); then
|
||||
local COLOR_USER='\[\033[38;2;180;40;120m\]' # Purple-red (root)
|
||||
local PROMPT_SYMBOL='#'
|
||||
else
|
||||
local COLOR_USER='\[\033[38;2;44;162;221m\]' # Azure blue (user)
|
||||
local PROMPT_SYMBOL='$'
|
||||
fi
|
||||
|
||||
# Host and path
|
||||
local COLOR_HOST='\[\033[38;2;44;180;70m\]' # Emerald green
|
||||
local COLOR_PATH='\[\033[38;2;126;98;247m\]' # Soft purple
|
||||
|
||||
# Dynamic symbol color
|
||||
if (( EXIT_STATUS != 0 )); then
|
||||
local COLOR_SYMBOL='\[\033[38;2;255;50;50m\]' # Bright red (error)
|
||||
else
|
||||
local COLOR_SYMBOL='\[\033[38;2;67;91;18m\]' # Olive green (success)
|
||||
fi
|
||||
|
||||
# Final prompt assembly
|
||||
PS1="${COLOR_USER}\u${COLOR_RESET}@${COLOR_HOST}\h${COLOR_RESET}:${COLOR_PATH}\w${COLOR_RESET}${COLOR_SYMBOL}${PROMPT_SYMBOL}${COLOR_RESET} "
|
||||
}
|
||||
|
||||
PROMPT_COMMAND=set_prompt
|
Loading…
x
Reference in New Issue
Block a user