-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.bashrc
304 lines (248 loc) · 7.48 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
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
### SET XDG USER DIRECTORES ###
export XDG_CONFIG_HOME=$HOME/.config
export XDG_CACHE_HOME=$HOME/.cache
export XDG_DATA_HOME=$HOME/.local/share
export XDG_STATE_HOME=$HOME/.local/state
### EXPORT ###
export TERM="xterm-256color" # For getting proper colors
export WGETRC=$XDG_CONFIG_HOME/wgetrc # To set xdg base directory for wget
export HISTCONTROL=ignoredups:erasedups:ignorespace # No duplicate entries and no lines that start with a space
export LESSHISTFILE=- # Prevent creation of ~/.lesshst file
export PYTHONSTARTUP="$XDG_CONFIG_HOME/python/pythonrc" # Change python history file location
### COLORISE LESS ###
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'
### HISTORY SETTINGS ###
HISTSIZE=10000
SAVEHIST=10000
HISTFILE=$XDG_DATA_HOME/bash/bash_history
# Set colors for ls command
if [ -f "$XDG_CONFIG_HOME/lscolors/lscolors.sh" ]; then
. "$XDG_CONFIG_HOME"/lscolors/lscolors.sh
fi
### SET MANPAGER ###
if command -v bat > /dev/null; then
export MANPAGER="sh -c 'col -bx | bat -l man -p'"
export MANROFFOPT="-c"
elif command -v batcat > /dev/null; then
export MANPAGER="sh -c 'col -bx | batcat -l man -p'"
export MANROFFOPT="-c"
else
export MANPAGER='less'
export LESS='-R --use-color -Dd+r$Du+b$'
export MANROFFOPT='-P -c'
fi
### BASH COMPLETION ###
if [ -f /usr/share/bash-completion/bash_completion ]; then
. /usr/share/bash-completion/bash_completion
elif [ -f /etc/bash_completion ]; then
. /etc/bash_completion
fi
# If not running interactively, don't do anything
[[ $- != *i* ]] && return
### PATH ###
if [ -d "$HOME/.bin" ]; then
PATH="$HOME/.bin:$PATH"
fi
if [ -d "$HOME/.local/bin" ]; then
PATH="$HOME/.local/bin:$PATH"
fi
if [ -d "$HOME/Applications" ]; then
PATH="$HOME/Applications:$PATH"
fi
if [ -d "/var/lib/flatpak/exports/bin/" ]; then
PATH="/var/lib/flatpak/exports/bin/:$PATH"
fi
if [ -d "/usr/games/" ]; then
PATH="/usr/games/:$PATH"
fi
if [ -d "/snap/bin/" ]; then
PATH="/snap/bin/:$PATH"
fi
if [ -d "/home/linuxbrew/.linuxbrew/sbin" ]; then
PATH="/home/linuxbrew/.linuxbrew/sbin:$PATH"
fi
if [ -d "/home/linuxbrew/.linuxbrew/bin" ]; then
PATH="/home/linuxbrew/.linuxbrew/bin:$PATH"
fi
if [ -d "$HOME/github/flutter" ]; then
PATH="$HOME/github/flutter/bin:$PATH"
fi
if [ -d "$HOME/.local/share/android/sdk" ]; then
ANDROID_HOME="$HOME/.local/share/android/sdk"
fi
if [ -d "$ANDROID_HOME/cmdline-tools/latest/bin" ]; then
PATH="$ANDROID_HOME/cmdline-tools/latest/bin:$PATH"
fi
if [ -d "/opt/nvim-linux64/" ]; then
PATH="$PATH:/opt/nvim-linux64/bin/"
fi
### SET EDITOR ###
if command -v nvim > /dev/null; then
export EDITOR="nvim"
export VISUAL="nvim"
export SUDO_EDITOR="nvim"
fi
### SHOPT ###
shopt -s autocd # change to named directory
shopt -s cdspell # autocorrects cd misspellings
shopt -s cmdhist # save multi-line commands in history as single line
shopt -s dotglob # show hidden files in tab completion
shopt -s histappend # do not overwrite history
shopt -s expand_aliases # expand aliases
shopt -s checkwinsize # checks term size when bash regains control
# Ignore upper and lowercase when TAB completion
bind "set completion-ignore-case on"
# Show auto-completion list automatically, without double tab
bind "set show-all-if-ambiguous On"
### ALIASES ###
# To select correct neovim
if command -v nvim > /dev/null; then
alias vim='nvim'
fi
# To set XDG Base Directory for wget
[ -f "$XDG_CONFIG_HOME"/wgetrc ] || touch "$XDG_CONFIG_HOME"/wgetrc && alias wget='wget --hsts-file=$XDG_CACHE_HOME/wget-hsts'
# Tree command - Show all files including hidden ones
alias tree='tree -a'
# Better ls commands
if command -v lsd > /dev/null; then
alias ls='lsd -A'
alias ll &> /dev/null && unalias ll # Delete alias ll if it exists
function ll {
if [ "$1" = "-g" ]; then
shift
lsd -Al --blocks permission,user,group,size,date,name --date +%d\ %b\ %H:%M --size short --group-directories-first "$@"
elif [ "$1" = "-y" ]; then
shift
lsd -Al --blocks permission,user,group,size,date,name --date +%d\ %b\ %Y\ %H:%M --size short --group-directories-first "$@"
else
lsd -Al --blocks permission,user,size,date,name --date +%d\ %b\ %H:%M --size short --group-directories-first "$@"
fi
}
alias lt='lsd -A --tree --group-directories-first -I .git'
else
alias ls='ls -A --color=auto --group-directories-first'
alias ll='ls -Alh --color=auto --group-directories-first'
alias lt='tree --dirsfirst -I .git'
fi
# Colorize grep output (good for log files)
alias grep='grep -i --color=auto'
alias egrep='grep -E'
alias fgrep='grep -f'
alias rgrep='grep -r'
alias rg='rg -i'
# Adding flags
alias df='df -h' # human-readable sizes
alias free='free -m' # show sizes in MB
# Add verbose output to cp, mv & mkdir
alias cp='cp -iv'
alias mv='mv -iv'
alias mkdir='mkdir -pv'
# Enable command-line trash
if command -v trash > /dev/null; then
alias rm='trash'
fi
# Colorize cat command
if command -v bat > /dev/null; then
alias cat='bat --style=plain'
elif command -v batcat > /dev/null; then
alias cat='batcat --style=plain'
fi
# Reason for space at the end: To make aliases work even if preceded by sudo
alias sudo='sudo '
# Change apt command to nala
if command -v nala > /dev/null; then
alias apt='nala'
fi
# Allows shellcheck to follow any file the script may source
alias shellcheck='shellcheck -x'
# Force start btop even if no UTF-8 locale was detected
alias btop='btop --utf-force'
# Colorise ip command
alias ip='ip -color=auto'
### RANDOM COLOR SCRIPT ###
# Get this script from my Github: github.com/shreyas-a-s/shell-color-scripts
if command -v colorscript > /dev/null; then
colorscript random
fi
### AUTOJUMP
if [ -f "/usr/share/autojump/autojump.zsh" ]; then
. /usr/share/autojump/autojump.bash
elif command -v zoxide > /dev/null; then
eval "$(zoxide init bash)"
fi
### FUNCTIONS ###
# Git functions
function gcom {
git add .
git commit -m "$@"
}
function lazyg {
git add .
git commit -m "$@"
git push
}
function gbranch {
git checkout -b "$1"
git push -u origin "$1"
}
function gdelete {
git push -d origin "$1"
git checkout -
git branch -d "$1"
}
# Create and go to the directory
function mkdircd {
mkdir -p "$1"
cd "$1"
}
# My Ping ;)
function ping {
if [ -z "$1" ]; then
command ping -c 1 example.org
else
command ping -c 1 "$@"
fi
}
### COMMAND-LINE PASTEBINS ###
# Function to use ix.io
function ix {
curl -F "f:1=@$1" https://ix.io
printf "\n"
}
# Function to use paste.rs
function paste {
curl --data-binary "@$1" https://paste.rs
printf "\n"
}
# Function to use 0x0.st
function 0x0 {
curl -F "file=@$1" https://0x0.st
printf "\n"
}
# Colorise diff
function diff {
if command -v bat > /dev/null; then
command diff -r "$@" | bat --style=plain -l diff
elif command -v batcat > /dev/null; then
command diff -r "$@" | batcat --style=plain -l diff
else
command diff -r --color=auto "$@"
fi
}
### COMMAND-NOT-FOUND ###
# pkgfile "command not found" handler for bash
if [ -f /usr/share/doc/pkgfile/command-not-found.bash ]; then
. /usr/share/doc/pkgfile/command-not-found.bash
fi
### SETTING THE STARSHIP PROMPT ###
if command -v starship > /dev/null; then
eval "$(starship init bash)"
else
PS1='\[\033[0;34m\]\w\[\033[0m\] $ '
fi