-
-
Notifications
You must be signed in to change notification settings - Fork 75
/
.bashrc
219 lines (191 loc) · 5.77 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
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
# Configure color-scheme
COLOR_SCHEME=dark # dark/light
# --------------------------------- ALIASES -----------------------------------
alias ..='cd ..'
alias cp='cp -v'
alias rm='rm -I'
alias mv='mv -iv'
alias ln='ln -sriv'
alias xclip='xclip -selection c'
command -v vim > /dev/null && alias vi='vim'
# Shortcut to update my Arch Linux setup
command -v yay > /dev/null && update() {
set -e
yay -Syyu --answerupgrade None --answerclean All --answerdiff None --overwrite="*" flat-remix-gnome
sudo pacman -Rscn $(pacman -Qdqtt) 2>/dev/null
yay -Scc --noconfirm
flatpak update
flatpak remove --unused
}
# Shortcut to update my Debian/Kali setup
command -v apt > /dev/null && update() {
sudo sh -c "
set -e
export DEBIAN_FRONTEND=noninteractive
dpkg --configure -a
apt update
apt -y --fix-broken --fix-missing full-upgrade
apt -y autoremove --purge
apt clean
"
}
### Colorize commands
alias ls='ls --color=auto'
alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'
alias diff='diff --color=auto'
alias ip='ip --color=auto'
alias pacman='pacman --color=auto'
### LS & TREE
alias ll='ls -la'
alias la='ls -A'
alias l='ls -F'
command -v lsd > /dev/null && alias ls='lsd --group-dirs first' && \
alias tree='lsd --tree'
command -v colorls > /dev/null && alias ls='colorls --sd --gs' && \
alias tree='colorls --tree'
### CAT & LESS
command -v bat > /dev/null && \
alias bat='bat --theme=ansi' && \
alias cat='bat --pager=never' && \
alias less='bat'
# in debian the command is batcat
command -v batcat > /dev/null && \
alias batcat='batcat --theme=ansi' && \
alias cat='batcat --pager=never' && \
alias less='batcat'
### TOP
command -v htop > /dev/null && alias top='htop'
command -v gotop > /dev/null && alias top='gotop -p $([ "$COLOR_SCHEME" = "light" ] && echo "-c default-dark")'
command -v ytop > /dev/null && alias top='ytop -p $([ "$COLOR_SCHEME" = "light" ] && echo "-c default-dark")'
command -v btm > /dev/null && alias top='btm $([ "$COLOR_SCHEME" = "light" ] && echo "--color default-light")'
# themes for light/dark color-schemes inside ~/.config/bashtop; Press ESC to open the menu and change the theme
command -v bashtop > /dev/null && alias top='bashtop'
command -v bpytop > /dev/null && alias top='bpytop'
# --------------------------------- SETTINGS ----------------------------------
shopt -s globstar
shopt -s histappend
shopt -s checkwinsize
HISTCONTROL=ignoreboth
HISTSIZE=5000
HISTFILESIZE=5000
HISTFILE=~/.bash_history
# 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
# Add new line before prompt
PROMPT_COMMAND="PROMPT_COMMAND=echo"
# Prompt
PS1='\[\033[;32m\]┌──(\[\033[1;34m\]\u@\h\[\033[;32m\])-[\[\033[0;1m\]\w\[\033[;32m\]]\n\[\033[;32m\]└─\[\033[1;34m\]\$\[\033[0m\] '
# ----------------------------------- MISC -----------------------------------
export VISUAL=vim
export EDITOR=$VISUAL
# enable terminal linewrap
setterm -linewrap on 2> /dev/null
# colorize man pages
export LESS_TERMCAP_mb=$'\e[1;32m'
export LESS_TERMCAP_md=$'\e[1;32m'
export LESS_TERMCAP_me=$'\e[0m'
export LESS_TERMCAP_se=$'\e[0m'
export LESS_TERMCAP_so=$'\e[01;33m'
export LESS_TERMCAP_ue=$'\e[0m'
export LESS_TERMCAP_us=$'\e[1;4;31m'
export LESSHISTFILE=-
# colorize ls
[ -x /usr/bin/dircolors ] && eval "$(dircolors -b)"
# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*|Eterm|aterm|kterm|gnome*|alacritty)
PS1="\[\e]0;\u@\h: \w\a\]$PS1"
;;
esac
# -------------------------------- FUNCTIONS ---------------------------------
lazygit() {
USAGE="
lazygit [OPTION]... <msg>
GIT but lazy
Options:
--fixup <commit> runs 'git commit --fixup <commit> [...]'
--amend runs 'git commit --amend --no-edit [...]'
-f, --force runs 'git push --force-with-lease [...]'
-h, --help show this help text
"
while [ $# -gt 0 ]
do
key="$1"
case $key in
--fixup)
COMMIT="$2"
shift # past argument
shift # past value
;;
--amend)
AMEND=true
shift # past argument
;;
-f|--force)
FORCE=true
shift # past argument
;;
-h|--help)
echo "$USAGE"
EXIT=true
;;
*)
MESSAGE="$1"
shift # past argument
;;
esac
done
unset key
if [ -z "$EXIT" ]
then
git status .
git add .
if [ -n "$AMEND" ]
then
git commit --amend --no-edit
elif [ -n "$COMMIT" ]
then
git commit --fixup "$COMMIT"
GIT_SEQUENCE_EDITOR=: git rebase -i --autosquash "$COMMIT"^
else
git commit -m "$MESSAGE"
fi
git push origin HEAD $([ -n "$FORCE" ] && echo '--force-with-lease')
fi
unset USAGE COMMIT MESSAGE AMEND FORCE
}
glog() {
setterm -linewrap off 2> /dev/null
git --no-pager log --all --color=always --graph --abbrev-commit --decorate --date-order \
--format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %s%C(reset) %C(dim white)- %an%C(reset)%C(bold yellow)%d%C(reset)' "$@" \
| sed -E \
-e 's/\|(\x1b\[[0-9;]*m)+\\(\x1b\[[0-9;]*m)+ /├\1─╮\2/' \
-e 's/(\x1b\[[0-9;]+m)\|\x1b\[m\1\/\x1b\[m /\1├─╯\x1b\[m/' \
-e 's/\|(\x1b\[[0-9;]*m)+\\(\x1b\[[0-9;]*m)+/├\1╮\2/' \
-e 's/(\x1b\[[0-9;]+m)\|\x1b\[m\1\/\x1b\[m/\1├╯\x1b\[m/' \
-e 's/╮(\x1b\[[0-9;]*m)+\\/╮\1╰╮/' \
-e 's/╯(\x1b\[[0-9;]*m)+\//╯\1╭╯/' \
-e 's/(\||\\)\x1b\[m (\x1b\[[0-9;]*m)/╰╮\2/' \
-e 's/(\x1b\[[0-9;]*m)\\/\1╮/g' \
-e 's/(\x1b\[[0-9;]*m)\//\1╯/g' \
-e 's/^\*|(\x1b\[m )\*/\1⎬/g' \
-e 's/(\x1b\[[0-9;]*m)\|/\1│/g' \
| command less -r $([ $# -eq 0 ] && echo "+/[^/]HEAD")
setterm -linewrap on 2> /dev/null
}
find() {
if [ $# = 1 ]
then
command find . -iname "*$@*"
else
command find "$@"
fi
}