Skip to content

Latest commit

Β 

History

History
581 lines (464 loc) Β· 12.3 KB

File metadata and controls

581 lines (464 loc) Β· 12.3 KB

🐚 Bash Configuration

Modern, modular Bash configuration mirroring the Zsh setup for consistency across shells

πŸ“ Architecture

~/.bash_profile              # Login shell entry point (sources .bashrc)
~/.bashrc                    # Main configuration entry point
~/.bash/                     # Modular configuration directory
  β”œβ”€β”€ 00-env.bash           # Environment & theme configurations
  β”œβ”€β”€ 01-path.bash          # PATH management with lazy loading
  β”œβ”€β”€ 10-aliases.bash       # Command aliases & shortcuts
  β”œβ”€β”€ 20-functions.bash     # Custom shell functions
  └── 99-integrations.bash  # External tool integrations

Note for macOS users: On macOS, terminals start login shells which read .bash_profile, not .bashrc. The .bash_profile simply sources .bashrc to unify behavior across platforms.

🎯 Why Bash?

While Zsh is the primary shell, Bash configuration is maintained for:

  • πŸ–₯️ Minimal servers - When only Bash is available
  • 🐳 Containers - Docker/Kubernetes debugging
  • πŸ”§ Recovery mode - System troubleshooting
  • 🌐 Universal compatibility - Works everywhere

🎨 Theme: Catppuccin Mocha / Snazzy

Platform-specific theming with automatic detection:

Platform Theme Colors
🍎 macOS Catppuccin Mocha Purple/Pink
🐧 Linux Snazzy Cyan/Yellow
πŸ“ Raspberry Pi Snazzy Cyan/Yellow

πŸš€ Modern CLI Tools

Same modern tool aliases as Zsh:

Traditional Modern Alias
ls eza ls, ll, l, lt
cat bat cat
cd zoxide z
vim neovim vim
curl xh http

πŸ“ File-by-File Documentation

~/.bash_profile

Purpose: Login shell entry point (macOS terminal sessions)

Features:

  • Sources ~/.bashrc for all configuration
  • Required on macOS where terminals start login shells
# Source .bashrc for interactive shell configuration
if [[ -f "${HOME}/.bashrc" ]]; then
  source "${HOME}/.bashrc"
fi

~/.bashrc

Purpose: Main configuration entry point

Features:

  • Interactive shell detection
  • Shell options (histappend, autocd, globstar, etc.)
  • Modular config loading from ~/.bash/
  • Starship prompt initialization

Shell Options:

shopt -s histappend       # Append to history
shopt -s checkwinsize     # Update terminal size
shopt -s cdspell          # Correct cd typos
shopt -s autocd           # cd without typing cd
shopt -s globstar         # ** recursive glob
shopt -s nocaseglob       # Case-insensitive glob

00-env.bash

Purpose: Core environment variables, platform detection, and cache helper

πŸš€ _cache_eval() Helper

Caches shell-init command output for 24 hours with automatic invalidation:

_cache_eval "name" "command"  # Caches 'command' output to ~/.cache/shell/name.bash

Features:

  • Invalidates cache when binary path changes (e.g., Homebrew β†’ Pacman, install β†’ uninstall)
  • Tracks binary path in .meta file
  • Falls back to live eval if cache is stale or missing
  • Used for: Starship, Zoxide, Atuin, Carapace initialization

Sections:

🌍 Platform Detection

IS_MACOS=true/false
IS_LINUX=true/false
IS_RPI=true/false
IS_UBUNTU=true/false
IS_FEDORA=true/false
IS_ARCH=true/false
PLATFORM=macos/linux/rpi/ubuntu/debian/fedora/arch/omarchy/toolbox
MACHINE_PROFILE=mac-personal/mac-pro/ubuntu-desktop/ubuntu-server/rpi/arch-desktop/arch-server/omarchy/fedora-desktop/fedora-server/fedora-atomic/debian/toolbox

🏠 Hostname Icons (Starship)

macOS:       ⌘
bbh-network: 🌐
omv-*:       🐟
Other Linux: πŸ“

🌐 Locale

LANG=en_US.UTF-8
LC_ALL=en_US.UTF-8

πŸ“œ History

HISTFILE=~/.bash_history
HISTSIZE=50000
HISTFILESIZE=50000
HISTCONTROL=ignoreboth:erasedups
HISTIGNORE="ls:cd:exit:clear:history"

🎨 Theme Configuration

macOS (Catppuccin Mocha):

STARSHIP_CONFIG=~/.config/starship/starship-desktop.toml
FZF_DEFAULT_OPTS="--color=bg+:#313244,bg:#1e1e2e..."
BAT_THEME="Catppuccin Mocha"
LS_COLORS=$(vivid generate catppuccin-mocha)

Linux/RPi (Snazzy):

STARSHIP_CONFIG=~/.config/starship/starship-ssh.toml
FZF_DEFAULT_OPTS="--color=bg+:#3a3d4d,bg:#282a36..."
BAT_THEME="ansi"
LS_COLORS=$(vivid generate snazzy)

01-path.bash

Purpose: PATH management with performance optimization

Helper Functions:

path_prepend "/path"  # Add to beginning if exists
path_append "/path"   # Add to end if exists

PATH Priority (highest first):

  1. ~/.local/bin
  2. ~/.cargo/bin
  3. ~/.antigravity/antigravity/bin (macOS)
  4. ~/.jenv/bin (macOS)
  5. ~/.rbenv/shims (macOS)
  6. ~/.tmuxifier/bin (macOS)
  7. System paths
  8. /opt/X11/bin, /Library/TeX/texbin (macOS)
  9. ~/.lmstudio/bin

⚑ Lazy Loading (macOS):

# pyenv loads only when first called
pyenv() {
  unset -f pyenv
  eval "$(command pyenv init -)"
  pyenv "$@"
}

# jenv loads only when first called  
jenv() {
  unset -f jenv
  eval "$(command jenv init -)"
  jenv "$@"
}

10-aliases.bash

Purpose: Command shortcuts (identical to Zsh)

πŸ”§ Configuration

bashconfig    # Edit ~/.bashrc with nvim

πŸš€ Modern Replacements

vim='nvim'
cat='bat'
http='xh'
la='tree'

πŸ“‚ Eza (ls replacement)

ls='eza --color=always --icons'
ll='eza -l --color=always --icons --git -a'
l='eza -l --icons --git -a'
lt='eza --tree --level=2 --long --icons --git'
ltree='eza --tree --level=2 --icons --git'
zl='eza -lagX --icons --color=always'

πŸ“ Navigation

..      # cd ..
...     # cd ../..
....    # cd ../../..
.....   # cd ../../../..
......  # cd ../../../../..
iclouddrive  # cd to iCloud Drive

πŸ”€ Git

gc='git commit -m'
gca='git commit -a -m'
gp='git push origin HEAD'
gpu='git pull origin'
gst='git status'
glog='git log --graph --pretty=...'
gdiff='git diff'
gco='git checkout'
gb='git branch'
gba='git branch -a'
gadd='git add'
ga='git add -p'
gcoall='git checkout -- .'
gr='git remote'
gre='git reset'

🐳 Docker

dco='docker compose'
dps='docker ps'
dpa='docker ps -a'
dl='docker ps -l -q'
dx='docker exec -it'

☸️ Kubernetes

k='kubectl'
ka='kubectl apply -f'
kg='kubectl get'
kd='kubectl describe'
kdel='kubectl delete'
kl='kubectl logs -f'
kgpo='kubectl get pod'
kgd='kubectl get deployments'
kc='kubectx'
kns='kubens'
ke='kubectl exec -it'
kcns='kubectl config set-context --current --namespace'

πŸ” Security & Pentesting

gobust='gobuster dir --wordlist ~/security/wordlists/diccnoext.txt --wildcard --url'
dirsearch='python dirsearch.py -w db/dicc.txt -b -u'
massdns='~/hacking/tools/massdns/bin/massdns -r ...'
server='python -m http.server 4445'
tunnel='ngrok http 4445'
fuzz='ffuf -w ~/hacking/SecLists/content_discovery_all.txt -mc all -u'
nm='nmap -sC -sV -oN nmap'

πŸ” SSH

sshpw='ssh -o PreferredAuthentications=password'

20-functions.bash

Purpose: Custom shell functions

πŸ“‚ cx - Change directory and list

cx /path/to/dir  # cd + automatic eza listing

πŸ” fcd - Fuzzy directory navigation

fcd  # Interactive FZF directory picker, then cd

πŸ“‹ f - Copy file path with FZF

f  # Select file with FZF, copy path to clipboard

✏️ fv - Open file in nvim with FZF

fv  # Select file with FZF, open in neovim

πŸ”— ssh - Tmux window naming wrapper

ssh user@host  # Automatically renames tmux window to hostname
               # Restores window name after disconnect

πŸ€– update-ai - Update CLI AI tools

update-ai  # Updates Claude Code, Copilot CLI, and Codex CLI

🎯 sysup - Update OS packages

sysup  # Updates OS packages (apt/dnf/pacman), Flatpak, Homebrew, and AI tools

99-integrations.bash

Purpose: External tool integrations

πŸ” FZF

# Loads from ~/.fzf.bash or system location
# Provides Ctrl+R history, Ctrl+T file finder

πŸ“ Bash Completion

# macOS: Homebrew bash-completion
# Linux: /etc/bash_completion or /usr/share/bash-completion/

☸️ Kubectl Completion

source <(kubectl completion bash)
complete -o default -F __start_kubectl k  # Alias completion

⎈ Helm Completion

source <(helm completion bash)

🐳 Docker Completion

# Loads from /usr/share/bash-completion/completions/docker

πŸš€ Zoxide

eval "$(zoxide init bash)"  # Enables 'z' command

πŸ“œ Atuin

eval "$(atuin init bash)"  # Magical shell history

πŸ“‚ Direnv

eval "$(direnv hook bash)"  # Auto-load .envrc files

🐳 OrbStack (macOS)

source ~/.orbstack/shell/init.bash

❄️ Nix

source /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh

🀬 TheFuck

eval "$(thefuck --alias)"  # Enables 'fuck' command

☁️ AWS Completion

complete -C aws_completer aws

πŸ”€ Git Completion

# Loads from system or Homebrew location

πŸ—οΈ Terraform Completion

complete -C terraform terraform

πŸ”— Zsh ↔ Bash Comparison

Feature Zsh Bash
Framework Oh-My-Zsh None (manual)
Plugins 8 OMZ plugins bash-completion
Autosuggestions zsh-autosuggestions N/A (use atuin)
Syntax highlighting zsh-syntax-highlighting N/A
Prompt Starship Starship βœ…
PATH uniqueness typeset -U path Helper functions
Function removal unfunction unset -f
Completion compinit bash-completion

⚑ Performance

Startup Optimization

  1. Lazy Loading - pyenv/jenv load on first use
  2. Conditional Sources - Only load if tool exists
  3. No Heavy Framework - Pure bash, no bloat

Benchmarking

# Time bash startup
time bash -i -c exit

# Detailed profiling
bash -x ~/.bashrc 2>&1 | head -50

🎯 Common Use Cases

Quick Navigation

z project        # Jump to frequently used directory
fcd              # Fuzzy find and cd to directory
..               # Go up one level

File Operations

ls               # List with icons (eza)
ll               # Long listing with git status
lt               # Tree view
cat file.txt     # Syntax highlighted (bat)
fv               # Fuzzy find and edit

Git Workflow

gst              # git status
ga               # git add -p (interactive)
gc "message"     # git commit -m
gp               # git push origin HEAD
glog             # Beautiful git log

Docker/Kubernetes

dco up           # docker compose up
k get pods       # kubectl get pods
kl pod-name      # kubectl logs -f

πŸ”§ Customization

Adding Aliases

Edit ~/.bash/10-aliases.bash:

alias myalias='command'

Adding Functions

Edit ~/.bash/20-functions.bash:

myfunction() {
  # Your code
}

Adding Environment Variables

Edit ~/.bash/00-env.bash:

export MY_VAR="value"

Adding Tool Integrations

Edit ~/.bash/99-integrations.bash:

if command -v newtool >/dev/null 2>&1; then
  eval "$(newtool init bash)"
fi

πŸ› Troubleshooting

Slow Startup?

# Profile startup
time bash -i -c exit

# Check what's loading
bash -x ~/.bashrc 2>&1 | head -100

Completion Not Working?

# Check bash-completion is loaded
type _init_completion

# Reinstall on macOS
brew reinstall bash-completion@2

Colors Not Working?

# Check LS_COLORS
echo $LS_COLORS

# Check vivid
vivid generate catppuccin-mocha

Tool Not Found?

# Check PATH
echo $PATH | tr ':' '\n'

# Check if tool exists
which toolname
command -v toolname

πŸ“¦ Required Tools

# Core (install via Homebrew or apt)
brew install eza bat fd ripgrep vivid fzf zoxide atuin direnv neovim starship

# Optional
brew install xh thefuck

πŸ“š Resources


Last updated: 2026-03-28 Maintained by: Jerome Soyer (@jsoyer)