-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.bashrc
More file actions
394 lines (334 loc) · 11.3 KB
/
.bashrc
File metadata and controls
394 lines (334 loc) · 11.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
#!/usr/bin/env bash
# Check if running interactively
[[ $- != *i* ]] && return
#######################################################
# INITIALIZATION
#######################################################
# Display system info
command -v fastfetch >/dev/null 2>&1 && fastfetch
# Source system-wide bash configuration
[[ -f /etc/bashrc ]] && source /etc/bashrc
# Enable bash completion
if [[ -f /usr/share/bash-completion/bash_completion ]]; then
source /usr/share/bash-completion/bash_completion
elif [[ -f /etc/bash_completion ]]; then
source /etc/bash_completion
fi
#######################################################
# SHELL OPTIONS
#######################################################
# Update window size after each command
shopt -s checkwinsize
# Append to history instead of overwriting
shopt -s histappend
# Disable terminal bell
bind "set bell-style none" 2>/dev/null
# Case-insensitive completion
bind "set completion-ignore-case on" 2>/dev/null
# Show completion list immediately
bind "set show-all-if-ambiguous on" 2>/dev/null
# Allow Ctrl+S for forward history search
stty -ixon 2>/dev/null
#######################################################
# HISTORY CONFIGURATION
#######################################################
export HISTSIZE=10000
export HISTFILESIZE=20000
export HISTTIMEFORMAT="%F %T "
export HISTCONTROL="erasedups:ignoredups:ignorespace"
export PROMPT_COMMAND="history -a"
#######################################################
# ENVIRONMENT VARIABLES
#######################################################
# XDG Base Directory Specification
export XDG_CONFIG_HOME="$HOME/.config"
export XDG_DATA_HOME="$HOME/.local/share"
export XDG_STATE_HOME="$HOME/.local/state"
export XDG_CACHE_HOME="$HOME/.cache"
# Default editors
export EDITOR="nvim"
export VISUAL="nvim"
# Color support
export CLICOLOR=1
export LESS_TERMCAP_mb=$'\e[1;31m'
export LESS_TERMCAP_md=$'\e[1;31m'
export LESS_TERMCAP_me=$'\e[0m'
export LESS_TERMCAP_se=$'\e[0m'
export LESS_TERMCAP_so=$'\e[1;44;33m'
export LESS_TERMCAP_ue=$'\e[0m'
export LESS_TERMCAP_us=$'\e[1;32m'
# PATH additions
export PATH="$HOME/.local/bin:$HOME/.cargo/bin:$PATH"
#######################################################
# UTILITY FUNCTIONS
#######################################################
# Detect Linux distribution
get_distro() {
if [[ -f /etc/os-release ]]; then
source /etc/os-release
case "$ID" in
fedora|rhel|centos|rocky|almalinux) echo "redhat" ;;
ubuntu|debian|mint) echo "debian" ;;
arch|manjaro|endeavouros) echo "arch" ;;
opensuse*|sles) echo "suse" ;;
gentoo) echo "gentoo" ;;
*) echo "unknown" ;;
esac
else
echo "unknown"
fi
}
# Extract various archive formats
extract() {
for file in "$@"; do
if [[ -f "$file" ]]; then
case "$file" in
*.tar.bz2) tar xjf "$file" ;;
*.tar.gz) tar xzf "$file" ;;
*.tar.xz) tar xJf "$file" ;;
*.bz2) bunzip2 "$file" ;;
*.rar) unrar x "$file" ;;
*.gz) gunzip "$file" ;;
*.tar) tar xf "$file" ;;
*.tbz2) tar xjf "$file" ;;
*.tgz) tar xzf "$file" ;;
*.zip) unzip "$file" ;;
*.Z) uncompress "$file" ;;
*.7z) 7z x "$file" ;;
*) echo "Unknown archive format: $file" ;;
esac
else
echo "File not found: $file"
fi
done
}
# Create directory and cd into it
mkcd() {
mkdir -p "$1" && cd "$1"
}
# Go up n directories
up() {
local levels=${1:-1}
local path=""
for ((i=0; i<levels; i++)); do
path="../$path"
done
cd "$path"
}
# Auto-show directory contents (multi-column) after cd
cd() {
if [[ $# -eq 0 ]]; then
if builtin cd ~; then
if command -v eza >/dev/null 2>&1; then
eza --icons --group-directories-first
elif command -v exa >/dev/null 2>&1; then
exa --icons --group-directories-first
elif command -v lsd >/dev/null 2>&1; then
lsd --group-dirs=first --icon=auto
else
ls -CF --color=auto
fi
fi
else
if builtin cd "$@"; then
if command -v eza >/dev/null 2>&1; then
eza --icons --group-directories-first
elif command -v exa >/dev/null 2>&1; then
exa --icons --group-directories-first
elif command -v lsd >/dev/null 2>&1; then
lsd --group-dirs=first --icon=auto
else
ls -CF --color=auto
fi
fi
fi
}
# Search text in files
search() {
grep -rn --color=always "$1" . | less -R
}
# Get internal and external IP
myip() {
echo "Internal IP:"
ip route get 1.1.1.1 | awk '{print $7}' 2>/dev/null || echo "Not connected"
echo "External IP:"
curl -s ifconfig.me || echo "Unable to fetch"
}
# Quick commit
gcom() {
git add . && git commit -m "$1"
}
# Lazy git (add, commit, push)
lazy() {
git add . && git commit -m "$1" && git push
}
#######################################################
# ALIASES - NAVIGATION
#######################################################
alias ..='cd ..'
alias ...='cd ../..'
alias ....='cd ../../..'
alias ..1='cd ..'
alias ..2='cd ../..'
alias ..3='cd ../../..'
alias ~='cd ~'
#######################################################
# ALIASES - SYSTEM
#######################################################
alias c='clear'
alias h='history'
alias j='jobs -l'
alias path='echo -e ${PATH//:/\\n}'
alias now='date +"%T"'
alias nowdate='date +"%d-%m-%Y"'
alias reload='source ~/.bashrc'
alias please='sudo $(fc -ln -1)'
alias pathadd='export PATH="$PWD:$PATH" && echo $PATH'
#######################################################
# ALIASES - FILE OPERATIONS
#######################################################
alias cp='cp -i'
alias mv='mv -i'
alias rm='rm -i'
alias mkdir='mkdir -pv'
# Safe alternatives
command -v trash >/dev/null 2>&1 && alias rm='trash'
# Default ls aliases
alias ls='ls --color=auto -F'
alias ll='ls -alF'
alias la='ls -A'
alias l='ls -1F'
alias lt='ls -ltr'
alias lh='ls -lh'
alias tree='tree -C'
# Prefer eza (or exa) or lsd for icons and organized output
if command -v eza >/dev/null 2>&1; then
alias ls='eza -a -1 --icons --group-directories-first'
alias l='eza -1 --icons --group-directories-first'
alias la='eza -a -1 --icons --group-directories-first'
alias ll='eza -l --icons --group-directories-first --no-user --no-group --no-permissions --no-filesize --time=modified --time-style="%Y-%m-%d %H:%M"'
alias lt='eza -T --level=2 --icons --group-directories-first'
elif command -v exa >/dev/null 2>&1; then
alias ls='exa -a -1 --icons --group-directories-first'
alias l='exa -1 --icons --group-directories-first'
alias la='exa -a -1 --icons --group-directories-first'
alias ll='exa -l --icons --group-directories-first --no-user --no-group --no-permissions --no-filesize --time=modified --time-style="%Y-%m-%d %H:%M"'
alias lt='exa -T --level=2 --icons --group-directories-first'
elif command -v lsd >/dev/null 2>&1; then
alias ls='lsd -a -1 --group-dirs=first --icon=auto'
alias l='lsd -1 --group-dirs=first --icon=auto'
alias la='lsd -a -1 --group-dirs=first --icon=auto'
alias ll='lsd -l --group-dirs=first --icon=auto --blocks date,name --date "+%Y-%m-%d %H:%M"'
alias lt='lsd --tree --depth 2 --group-dirs=first --icon=auto'
fi
#######################################################
# ALIASES - TEXT PROCESSING
#######################################################
alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'
# Use modern alternatives if available
command -v rg >/dev/null 2>&1 && alias grep='rg'
command -v bat >/dev/null 2>&1 && alias cat='bat'
#######################################################
# ALIASES - ARCHIVES
#######################################################
alias untar='tar -xvf'
alias targz='tar -czvf'
#######################################################
# ALIASES - SYSTEM MONITORING
#######################################################
alias df='df -h'
alias du='du -h'
alias free='free -h'
alias ps='ps auxf'
alias psg='ps aux | grep'
alias top='htop'
alias ports='netstat -tulanp'
#######################################################
# ALIASES - PACKAGE MANAGEMENT
#######################################################
DISTRO=$(get_distro)
case "$DISTRO" in
"debian")
alias install='sudo apt install'
alias update='sudo apt update && sudo apt upgrade'
alias search='apt search'
alias remove='sudo apt remove'
;;
"redhat")
alias install='sudo dnf install'
alias update='sudo dnf update'
alias search='dnf search'
alias remove='sudo dnf remove'
;;
"arch")
alias install='sudo pacman -S'
alias update='sudo pacman -Syu'
alias search='pacman -Ss'
alias remove='sudo pacman -R'
;;
esac
#######################################################
# ALIASES - DEVELOPMENT
#######################################################
alias vim='nvim'
alias vi='nvim'
alias edit='$EDITOR'
# Git shortcuts
alias g='git'
alias gs='git status'
alias ga='git add'
alias gc='git commit'
alias gp='git push'
alias gl='git log --oneline'
alias gd='git diff'
alias ggraph='git log --graph --decorate --oneline --all'
alias gst='git status -sb'
alias gco='git checkout'
alias gb='git branch --all'
alias gclean='git fetch -p && git branch --merged | egrep -v "(^\*|main|master|dev)" | xargs -r git branch -d'
#######################################################
# ALIASES - DOCKER
#######################################################
alias d='docker'
alias dc='docker-compose'
alias dps='docker ps'
alias di='docker images'
alias dclean='docker system prune -af'
alias dcu='docker compose up -d'
alias dcd='docker compose down'
alias dcb='docker compose build'
alias dcl='docker compose logs -f'
#######################################################
# ALIASES - NETWORKING
#######################################################
alias ping='ping -c 5'
alias wget='wget -c'
alias curl='curl -L'
alias iplocal="hostname -I | awk '{print $1}'"
alias ippublic='curl -s https://ifconfig.me'
#######################################################
# ALIASES - SERVERS
#######################################################
alias serve='python3 -m http.server 8000'
alias servep='python3 -m http.server 8000 --bind 127.0.0.1'
#######################################################
# CUSTOM KEYBINDINGS
#######################################################
# Bind Ctrl+f to zi (zoxide interactive)
bind '"\C-f":"zi\n"' 2>/dev/null
#######################################################
# PROMPT AND SHELL ENHANCEMENTS
#######################################################
# Initialize starship prompt if available
command -v starship >/dev/null 2>&1 && eval "$(starship init bash)"
# Initialize zoxide if available
command -v zoxide >/dev/null 2>&1 && eval "$(zoxide init bash)"
#######################################################
# AUTO-START X11
#######################################################
# Auto-start X11 on tty1
if [[ -z "$DISPLAY" ]] && [[ "$(tty)" = "/dev/tty1" ]]; then
exec startx
fi