-
Notifications
You must be signed in to change notification settings - Fork 3
/
.bashrc
147 lines (126 loc) · 7.87 KB
/
.bashrc
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
#!/bin/bash
# shellcheck disable=SC2086,SC2154,SC1091
# ╔═════════════════════════════════════════════════════════════════╗
# ║ BASHRC ║
# ║ @depends .bash_alias ║
# ║ .bash_var ║
# ║ .bash_vendor ║
# ╚═════════════════════════════════════════════════════════════════╝
# Detect: Interactive Mode
# Use to prevent incorrect TTY errors with some scripts
[ -v PS1 ] && i9e=true || i9e=false
export INTERACTIVE_MODE=$i9e
export PATH=$PATH:/home/$USER/.local/bin # Set: Local bin to $PATH
export BROWSER=/usr/bin/brave-browser # Set: Local Browser (Affects: VSCode)
export EDITOR=vim
export GREP_COLORS='ms=01;38;5;190:mc=01;31:sl=:cx=:fn=35:ln=32:bn=32:se=36'
# XDG Directory Paths
# [See] ~/.profile for other app paths.
# [Spec] https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
# ───────────────────────────────────────────────────────────────────
export XDG_CONFIG_HOME=$HOME/.config # Config Files
export XDG_DATA_HOME=$HOME/.local/share # Shared Data
export XDG_STATE_HOME=$HOME/.local/state # Actions History, Logs, Recent Files
export XDG_CONFIG_DIRS=$XDG_CONFIG_DIRS:$XDG_CONFIG_HOME
export XDG_DATA_DIRS=$XDG_DATA_DIRS:$XDG_DATA_HOME
# [Example]
# ~/.config/bash_completions
# ~/.config/zsh
# ~/.config/docker
# Autoload Keychain SSH ID
if command -v keychain >/dev/null 2>&1; then
keychain --clear $HOME/.ssh/id_rsa --absolute --dir "${XDG_RUNTIME_DIR:-/tmp}/keychain"
fi
# ┌─────────────────────────────────────────────────────────────────┐
# │ Bash Includes │
# └─────────────────────────────────────────────────────────────────┘
# ╔═════════════════════════════════════════════════════════════════╗
# ║ Source Files: Bash Includes ║
# ╠═════════════════════════════════════════════════════════════════╣
# ║ (1) .bash_var comes first ║
# ║ (2) .bash_vendor come second (incase of alias-ing) ║
# ║ (3) ...rest ║
# ╚═════════════════════════════════════════════════════════════════╝
[[ -f $HOME/.bash_var ]] && . $HOME/.bash_var
[[ -f $HOME/.bash_vendor ]] && . $HOME/.bash_vendor
[[ -f $HOME/.bash_alias ]] && . $HOME/.bash_alias
[[ -f $HOME/.bash_fn ]] && . $HOME/.bash_fn
[[ -f $HOME/.private ]] && . $HOME/.private # .gitignore
# ┌─────────────────────────────────────────────────────────────────┐
# │ Display: PS1 Prompt │
# │ (Useful when on another server w/this .bash config │
# └─────────────────────────────────────────────────────────────────┘
# [Help] https://bashrcgenerator.com/
# [NoColor] export PS1="[\w]\$(git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/')\n\u@\h-> \[\033[0m\]"
# Function to get the current branch and indicate if it has uncommitted changes
git_info() {
local branch
local dirty=""
branch=$(git branch 2>/dev/null | grep -E '^\*' | sed 's/* //')
if [[ -n $branch ]]; then
# Check for uncommitted changes
[[ -n $(git status --porcelain 2>/dev/null) ]] && dirty="${IBYELLOW}⚒${RESET}"
echo -e "(${IYELLOW}${branch}${RESET})${dirty}"
fi
}
IN_SSH=""
if [[ -n $SSH_CLIENT ]]; then
HOSTNAME=$(hostname)
IN_SSH="[${IBYELLOW}SSH$RESET][${IBLUE}@${HOSTNAME}$RESET]"
fi
export PS1="$IN_SSH[$IBLUE\w$RESET]\$(git_info)\n\u@\h-> "
#export PS1="$IN_SSH[$IBLUE\w$RESET]\$(git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/($IYELLOW\1$RESET)/')\n\u@\h-> "
# ┌─────────────────────────────────────────────────────────────────┐
# │ Shell Options │
# └─────────────────────────────────────────────────────────────────┘
HISTCONTROL=ignoreboth
HISTSIZE=10000
HISTFILESIZE=20000
if [[ $SHELL =~ bash$ ]]; then
shopt -s histappend cdspell autocd
else
echo -e "[!] Use Bash for 'shopt' command, are you using zsh?"
fi
# Set variable identifying the chroot you work in
# (used in the prompt below)
if [ -z "$debian_chroot" ] && [ -r /etc/debian_chroot ]; then
debian_chroot=$(cat /etc/debian_chroot)
fi
# Make 'less' friendlier for non-text input files, see lesspipe(1)
[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"
# ┌─────────────────────────────────────────────────────────────────┐
# │ Bash Completion │
# └─────────────────────────────────────────────────────────────────┘
# Only run for interactive shells
if ! shopt -oq posix; then
# Local
if [ -d "$XDG_CONFIG_HOME/bash_completion" ]; then
for file in "$XDG_CONFIG_HOME"/bash_completion/*; do
[[ -f $file ]] && source "$file"
done
fi
# System
for file in /usr/share/bash-completion/bash_completion /etc/bash_completion; do
[[ -f $file ]] && source "$file" && break
done
fi
# ┌─────────────────────────────────────────────────────────────────┐
# │ Make $PATH readable │
# └─────────────────────────────────────────────────────────────────┘
# [Important] # Do not put in ~/.bash_alias, keep it here. This
# # Outputs the final $PATH value with all other files.
path() {
info "(List of \$PATH)"
tr ':' '\n' <<< "$PATH" | sort | uniq | while read -r line; do
if [[ $line == /home/* ]]; then
echo -e " \e${BLUE}$line${RESET}"
elif [[ $line == /usr/* ]]; then
echo -e " ${WHITE}$line${RESET}"
else
echo -e " ${YELLOW}$line${RESET}"
fi
done
# Basic Way:
# tr ':' '\n' <<< "$PATH" | sort | uniq | sed 's/^/ /'
info "(End of \$PATH)"
}