-
Notifications
You must be signed in to change notification settings - Fork 0
/
.bashrc
163 lines (126 loc) · 3.11 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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#################
# Bash settings #
#################
# stop if non-interactive
case $- in
*i*) ;;
*) return;;
esac
# load bash completion
if ! shopt -oq posix; then
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
fi
# shopt
shopt -s autocd
shopt -s checkwinsize
shopt -s histappend
shopt -s dotglob
shopt -s globstar
# history settings
HISTCONTROL=ignoreboth
HISTSIZE=10000
SAVEHIST=10000
#################
# PATH variable #
#################
PRIVATE_BIN_PATH="${HOME}/.bin"
if [[ -d $PRIVATE_BIN_PATH ]] && [[ ":$PATH:" != *":$PRIVATE_BIN_PATH:"* ]]; then
export PATH="${PRIVATE_BIN_PATH}:${PATH}"
fi
#################
# Custom prompt #
#################
PROMPT_COMMAND=__render_prompt
__render_prompt () {
local ecode="$?"
local fmtcode="$(printf "%03d" "$ecode")"
# reset
PS1='\[\e[0m\]'
# exit code
PS1+='['
if [[ $ecode == "0" ]]; then
PS1+='\[\033[32m\]'
PS1+=$' \xe2\x9c\x93 '
else
PS1+='\[\033[31m\]'
PS1+="$fmtcode"
fi
PS1+='\[\033[0m\]] '
# hostname/user:
PS1+='\[\e[32m\]\h\[\e[0m\]'
PS1+='/'
PS1+='\[\e[96m\]\u\[\e[0m\]'
PS1+=':'
# pwd (abbreviated)
PS1+="\[\e[95m\]"
PS1+="$(
if [[ $PWD = / ]]; then
printf '/'
else
p="${PWD#${HOME}}"
[[ $PWD != $p ]] && printf "~"
IFS=/
for d in ${p:1}; do
[[ ${d:0:1} == "." ]] && printf "/${d:0:2}" || printf "/${d:0:1}"
done
[[ ${d:0:1} == "." ]] && printf "${d:2}" || printf "${d:1}"
fi
)"
PS1+='\[\e[00m\]'
# privilege
if [[ $UID == "0" ]]; then
PS1+='# '
else
PS1+='$ '
fi
}
###########
# Aliases #
###########
# vim all the things
if [[ -x "$(command -v vim)" ]]; then
alias vi='vim'
export EDITOR="vim"
export VISUAL="vim"
fi
# ls shortcuts
if [[ -x "$(command -v exa)" ]]; then
alias ls="exa --header --git --group --group-directories-first --color-scale --color=always"
alias lm="exa --header --long --group --sort=modified --reverse --color always --color-scale"
alias lt="exa --long --tree --git-ignore"
else
alias ls='ls --group-directories-first -h --color=auto'
fi
alias ll='ls -l'
alias la='ls -la'
# docker-compose
alias dc="docker-compose"
alias dcr="docker-compose down && docker-compose up -d"
alias dcpu="docker-compose pull && docker-compose up -d"
# git
alias gitlog="git log --graph --oneline --decorate --all"
# in case someone fucked up again... (me)
alias fuck='sudo env "PATH=$PATH" $(fc -ln -1)'
# list all currently listening tcp sockets
alias lssockets='ss -nrlpt'
# pretty mount table
alias mountfmt="mount | column -t | sort"
# upload to https://0x0.st
0x0 () {
echo ">> $(curl -s --fail -F "file=@$1" "https://0x0.st" || echo "error uploading $1")"
}
# config management with git
dotconf () {
local cdir="$HOME/.dotconf"
[[ -d $cdir ]] || mkdir -p $cdir
[[ -f $cdir/HEAD ]] || git init --bare $cdir
git --git-dir=$cdir --work-tree=$HOME/ "$@"
}
###################
# Update dotfiles #
###################
(dotconf pull >/dev/null 2>&1 &)