dotfiles
1# OS-aware .bashrc for both Git Bash (Windows) and WSL/Linux
2# Part of dotfiles managed at ~/Developer/dots
3
4# Detect OS
5case "$(uname -s)" in
6 Darwin*) OS_TYPE="mac";;
7 Linux*)
8 if grep -qi microsoft /proc/version 2>/dev/null; then
9 OS_TYPE="wsl"
10 else
11 OS_TYPE="linux"
12 fi
13 ;;
14 MINGW*|MSYS*|CYGWIN*) OS_TYPE="gitbash";;
15 *) OS_TYPE="unknown";;
16esac
17
18# Export OS_TYPE for prompts
19export OS_TYPE
20
21# If not running interactively, don't do anything
22case $- in
23 *i*) ;;
24 *) return;;
25esac
26
27# History settings
28export HISTSIZE=10000
29export HISTFILESIZE=10000
30export HISTCONTROL=ignoredups:erasedups
31
32# Append to history file, don't overwrite
33if [ "$OS_TYPE" != "gitbash" ]; then
34 shopt -s histappend
35fi
36
37# Check window size after each command
38if [ "$OS_TYPE" != "gitbash" ]; then
39 shopt -s checkwinsize
40fi
41
42# Git aliases (all platforms)
43alias gs='git status'
44alias ga='git add'
45alias gc='git commit'
46alias gp='git push'
47alias gl='git pull'
48alias gd='git diff'
49alias gco='git checkout'
50
51# Git tree alias
52git config --global alias.tree "log --oneline --decorate --all --graph"
53
54# Convenient aliases
55alias ll='ls -lah'
56alias la='ls -A'
57alias l='ls -CF'
58
59# cd up shortcuts
60alias ..='cd ..'
61alias ...='cd ../..'
62alias ....='cd ../../..'
63
64# Platform-specific configuration
65if [[ "$OS_TYPE" == "gitbash" ]]; then
66 # Git Bash / Windows specific
67 alias wsl='wsl.exe'
68 echo "Git Bash environment loaded. For full dev setup, use: wsl"
69
70elif [[ "$OS_TYPE" == "wsl" ]] || [[ "$OS_TYPE" == "linux" ]]; then
71 # WSL / Linux specific
72
73 # Enable color support
74 if [ -x /usr/bin/dircolors ]; then
75 test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
76 alias ls='ls --color=auto'
77 alias grep='grep --color=auto'
78 alias fgrep='fgrep --color=auto'
79 alias egrep='egrep --color=auto'
80 fi
81
82 # Alert alias for long running commands
83 alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"'
84
85 # Source bash aliases if exists
86 if [ -f ~/.bash_aliases ]; then
87 . ~/.bash_aliases
88 fi
89
90 # Enable programmable completion
91 if ! shopt -oq posix; then
92 if [ -f /usr/share/bash-completion/bash_completion ]; then
93 . /usr/share/bash-completion/bash_completion
94 elif [ -f /etc/bash_completion ]; then
95 . /etc/bash_completion
96 fi
97 fi
98
99 # SSH agent bridge (WSL specific)
100 if [ -f "$HOME/.agent-bridge.sh" ]; then
101 source "$HOME/.agent-bridge.sh"
102 fi
103
104 # Neovim alias if installed
105 if [ -x /opt/nvim-linux-x86_64/bin/nvim ]; then
106 alias nvim="/opt/nvim-linux-x86_64/bin/nvim"
107 export PATH="/opt/nvim-linux-x86_64/bin:$PATH"
108 fi
109fi
110
111# Add user bin to PATH (all platforms)
112export PATH="$HOME/.local/bin:$HOME/bin:$PATH"
113
114# Better ls colors (Git Bash)
115if [[ "$OS_TYPE" == "gitbash" ]] && command -v dircolors >/dev/null 2>&1; then
116 eval "$(dircolors -b)"
117fi
118
119# Initialize Starship prompt if available
120if command -v starship >/dev/null 2>&1; then
121 eval "$(starship init bash)"
122fi