-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.bashrc
More file actions
513 lines (438 loc) · 17.1 KB
/
.bashrc
File metadata and controls
513 lines (438 loc) · 17.1 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
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
#!/bin/bash
######################################################################
#
# _|_|_| _|_| _|_|_| _| _| _|_|_| _|_|_|
# _| _| _| _| _| _| _| _| _| _|
# _|_|_| _|_|_|_| _|_| _|_|_|_| _|_|_| _|
# _| _| _| _| _| _| _| _| _| _|
# _| _|_|_| _| _| _|_|_| _| _| _| _| _|_|_|
#
######################################################################
#######################################################
# .BASHRC FILE MADE BY knowhere-coding
#######################################################
# If not running interactively, don't do anything
[[ $- != *i* ]] && return
#######################################################
# ENVIRONMENT VARIABLES
#######################################################
unset LS_COLORS
export LS_COLORS="\
no=38;5;255:\
di=38;5;198:\
ow=38;5;198:\
tw=38;5;198:\
fi=38;5;255:\
ex=:\
pi=38;5;208:\
ln=38;5;51:\
so=38;5;196:\
mi=38;5;196:\
sg=38;5;129:\
st=48;5;198:\
su=48;5;129:\
*.7z=38;5;214:\
*.apk=38;5;40:\
*.avi=38;5;147:\
*.awk=38;5;255:\
*.bat=38;5;34:\
*.bf=38;5;236:\
*.bmp=38;5;250:\
*.c=38;5;26:\
*.cmd=38;5;34:\
*.cpp=38;5;27:\
*.css=38;5;33:\
*.csv=38;5;2:\
*.doc=38;5;39:\
*.docx=38;5;39:\
*.exe=38;5;196:\
*.flv=38;5;255:\
*.gif=38;5;190:\
*.go=38;5;39:\
*.gz=38;5;214:\
*.h=38;5;26:\
*.hpp=38;5;27:\
*.htm=38;5;166:\
*.html=38;5;166:\
*.ico=38;5;190:\
*.ini=38;5;244:\
*.java=38;5;9:\
*.jl=38;5;43:\
*.jpg=38;5;190:\
*.jpeg=38;5;190:\
*.js=38;5;220:\
*.json=38;5;220:\
*.lua=38;5;20:\
*.md=38;5;159:\
*.mkv=38;5;147:\
*.mov=38;5;147:\
*.mp3=38;5;147:\
*.mp4=38;5;147:\
*.mpeg=38;5;147:\
*.ogg=38;5;147:\
*.pdf=38;5;160:\
*.php=38;5;57:\
*.pl=38;5;55:\
*.png=38;5;190:\
*.ppt=38;5;202:\
*.pptx=38;5;202:\
*.ps1=38;5;34:\
*.psm=38;5;34:\
*.psm1=38;5;34:\
*.py=38;5;32:\
*.qoi=38;5;190:\
*.r=38;5;32:\
*.rar=38;5;214:\
*.rb=38;5;124:\
*.rs=38;5;202:\
*.rtf=38;5;159:\
*.sh=38;5;34:\
*.sql=38;5;63:\
*.svg=38;5;190:\
*.swift=38;5;208:\
*.tar=38;5;214:\
*.tgz=38;5;214:\
*.toml=38;5;248:\
*.ts=38;5;27:\
*.tsv=38;5;2:\
*.txt=38;5;159:\
*.vbs=38;5;2:\
*.vb=38;5;2:\
*.vue=38;5;35:\
*.wav=38;5;147:\
*.wmv=38;5;147:\
*.xml=38;5;248:\
*.xlsx=38;5;2:\
*.yaml=38;5;248:\
*.zip=38;5;214:\
"
#######################################################
# SETUP
#######################################################
# colors
NONE="\[$(tput sgr0)\]"
BLUE="\[$(tput setaf 39)\]"
GREEN="\[$(tput setaf 40)\]"
LIGHT_BLUE="\[$(tput setaf 51)\]"
PURPLE="\[$(tput setaf 129)\]"
ERROR="\[$(tput setaf 196)\]"
PINK="\[$(tput setaf 198)\]"
ORANGE="\[$(tput setaf 208)\]"
GREY="\[$(tput setaf 242)\]"
COUNTER=-1
# ignore case on auto-completion
bind "set completion-ignore-case on"
# show auto-completion list automatically, without double tab
bind "set show-all-if-ambiguous On"
# enable programmable completion features
if ! shopt -oq posix; then
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
fi
# don't put duplicate lines or lines starting with space in the history
HISTCONTROL=ignoreboth
# append to the history file, don't overwrite it
shopt -s histappend
HISTSIZE=1000 # cached lines
HISTFILESIZE=2000 # saved lines
# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS
shopt -s checkwinsize
# make less more friendly for non-text input files
[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"
PROMPT_COMMAND="createPrompt"
#######################################################
# ALIASES
#######################################################
# Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# if [ -f ~/.bash_aliases ]; then
# . ~/.bash_aliases
# fi
# modified default commands ----------------------------------------------------------------
alias cp='cp -i' # copy interactive
alias mv='mv -i' # move interactive
alias mkdir='mkdir -p' # mkdir and necessary parent directories
alias ping='ping -c 10' # ping with limit 10
alias tree='tree -C' # tree with colors enabled
# change directory aliases -----------------------------------------------------------------
alias ..='cd ..' # cd up 1
alias ...='cd ../..' # cd up 2
alias ....='cd ../../..' # cd up 3
alias .....='cd ../../../..' # cd up 4
alias bd='cd "$OLDPWD"' # cd to previous directory
# useful ls aliases ------------------------------------------------------------------------
alias ls='ls --color=auto' # ls with colors enabled
alias ll='ls -alhF' # long format, showing hidden files and directories with indicators
alias la='ls -Al' # list all files and directories (including hidden) except . and ..
alias lt='ls -lt' # sort by modification time, newest first
alias ltr='ls -ltr' # sort by modification time, oldest first
alias lB='ls -lS' # sort by file size, largest first
alias lb='ls -lS --reverse' # sort by file size, smallest first
alias lh='ls -lh' # long format with human-readable file sizes
alias lsf='ls -p | grep -v / --color=none' # show only files (excluding directories)
alias lsd='ls -p | grep / --color=none' # show only directories (excluding files)
alias lsfc='echo "$(ls -p | grep -v / | wc -l) files"' # show the number of files
alias lsdc='echo "$(ls -p | grep / | wc -l) directories"' # show the number of directories
alias lfx='find . -maxdepth 1 -type f -exec ls -lh {} +\
| grep "./\w" --color=none \
| sed -E "s#\./##"; lsd' # long format for files short for directories
alias ldx='ll -d */; lsf' # long format for directories short for files
alias ltla='ls -Alth' # list all files sorted by their last modification time, including hidden files
alias lsl='du -hsx * | sort -rh | head -10' # list the top 10 largest files or directories in the current directory
# git --------------------------------------------------------------------------------------
alias gs='git status' # git status
alias ga='git add' # git add
alias gc='git commit' # git commit
alias gcm='git commit -m' # git commit -m
alias gd='git diff' # git diff
alias gl='git log' # git log
alias gco='git checkout' # git checkout
alias gb='git branch' # git branch
alias gbd='git branch -d' # git branch -d
alias gba='git branch -a' # git branch -a
alias gp='git pull' # git pull
alias gps='git push' # git push
alias gph='git push origin HEAD' # git push origin HEAD
alias gr='git remote -v' # git remote -v
alias grm='git remote -v prune origin' # git remote -v prune origin
alias gri='git rebase -i' # git rebase -i
alias gss='git stash save' # git stash save
alias gsl='git stash list' # git stash list
alias gsp='git stash pop' # git stash pop
alias gssu='git stash save --include-untracked' # git stash save --include-untracked
alias gst='git stash' # git stash
alias gm='git merge' # git merge
alias gaa='git add --all' # git add --all
alias gcl='git clone' # git clone
alias gcp='git cherry-pick' # git cherry-pick
alias grs='git reset' # git reset
alias gpf='git push --force' # git push --force
alias gg='git grep' # git grep
alias gpf!='git push --force-with-lease' # git push --force-with-lease
alias gbs="git branch --sort=-committerdate --format=\
'%(color:yellow)%(refname:short)%(color:reset) - \
%(color:blue)%(objectname:short)%(color:reset) - \
%(color:red)%(committerdate:relative)%(color:reset)'" # Show a compact git branch summary
alias glog="git log --graph --oneline --decorate --all" # Show a colored and graphical git log
alias gloga="git log --pretty=format:'%h %s (%an <%ae>)'" # Show a pretty Git log with author details
alias gtb="git for-each-ref --format='%(refname:short) \
<- %(upstream:short)' refs/heads/*" # Show the current branch's tracking branch
alias gcount="git shortlog -s -n" # Show the number of commits each contributor has made
alias grias="git rebase -i --autosquash" # Interactive rebase with autosquash
alias gignored="git ls-files --others --exclude-standard" # Show the list of ignored files
alias gssb="git status -sb" # Show the Git status with short and branch-specific info
alias gdm="git branch --merged \
| grep -v '*' \
| xargs -I % git branch -d %" # Delete all merged branches (use with caution)
alias gbdboth="git branch -d \$1 && \
git push origin --delete \$1" # Delete a branch both locally and remotely
# system -----------------------------------------------------------------------------------
alias sai='sudo apt install' # install package
alias sar='sudo apt remove' # remove package
alias update='sudo apt update' # update system
alias upgrade='sudo apt upgrade' # upgrade system
# other ------------------------------------------------------------------------------------
alias wttr='curl "wttr.in"' # weather info
alias ch='history -c && history -w && exit' # clear history and exit
alias ip='curl -s ifconfig.me' # show public ip address
#######################################################
# FUNCTIONS
#######################################################
# make directory and go there
function mkdg
{
mkdir $1
cd $1
}
# move a certain number of directories up
function up
{
if [ $# -eq 0 ]; then
echo "Error: Please provide the number of directories to move up."
return 1
fi
re='^[0-9]+$'
if ! [[ $1 =~ $re ]]; then
echo "Error: The parameter should be a positive integer."
return 1
fi
num_up=$1
current_dir=$(pwd)
if [ "$current_dir" = "/" ]; then
echo "Error: Already at the root directory. Cannot move further up."
return 1
fi
while [ $num_up -gt 0 ]; do
current_dir=$(dirname "$current_dir")
num_up=$((num_up - 1))
done
if [ ! -d "$current_dir" ]; then
echo "Error: The resulting directory does not exist."
return 1
fi
cd "$current_dir" || return 1
}
# remove files with summary output
function rms()
{
local count=0
for arg in "$@"; do
if [ -e "$arg" ]; then
/bin/rm -rf "$arg"
if [ $? -eq 0 ]; then
((count++))
fi
fi
done
echo "$count files deleted!"
}
# remove files with summary output savely
function rmss
{
local deleted_files=()
for arg in "$@"; do
if [ -e "$arg" ]; then
deleted_files+=("$arg")
fi
done
local count=${#deleted_files[@]}
if [ $count -eq 0 ]; then
echo "No files to delete."
return
fi
echo "Files to be deleted ($count files):"
printf '%s\n' "${deleted_files[@]}"
echo "---"
echo "$count files"
read -p "Do you want to proceed with the deletion (Y/n)? " choice
case "$choice" in
[Yy]* )
for file in "${deleted_files[@]}"; do
/bin/rm -f "$file"
done
echo "Deleted $count files."
;;
[Nn]* )
echo "Deletion canceled. Files were not deleted."
;;
* )
echo "Invalid input. Deletion canceled. Files were not deleted."
;;
esac
}
# search in all files
function search
{
grep -iIHrn "$1" . | less -r
}
# rot13 cipher
function rot13 ()
{
if [ $# -eq 0 ]; then
echo "Error: Please provide an input string."
else
echo $* | tr '[a-m][n-z][A-M][N-Z]' '[n-z][a-m][N-Z][A-M]'
fi
}
# rotX cipher
function rot {
if [[ $# -ne 2 ]]; then
echo "Error: Please provide two arguments - rotation value and input string."
return 1
fi
local rotation_value="$1"
local input_string="$2"
if ! [[ "$rotation_value" =~ ^[+-]?[0-9]+$ ]]; then
echo "Error: Rotation value must be an integer."
return 1
fi
if [[ "$rotation_value" -ge 26 || "$rotation_value" -le -26 ]]; then
echo "Error: Rotation value must be between -25 and 25 (exclusive)."
return 1
fi
local output_string=""
for ((i = 0; i < ${#input_string}; i++)); do
char="${input_string:i:1}"
if [[ "$char" =~ [A-Za-z] ]]; then
ascii_val=$(printf "%d" "'$char")
if [[ "$char" =~ [A-Z] ]]; then
base=65
else
base=97
fi
rotated_ascii_val=$(((ascii_val - base + rotation_value + 26) % 26 + base))
output_string+=$(printf \\$(printf "%o" "$rotated_ascii_val"))
else
output_string+="$char"
fi
done
echo "$output_string"
}
# call .bashrc file for activation
function ub
{
. ~/.bashrc
}
# bash prompt setup
function createPrompt
{
LAST_COMMAND=$? # save the exit code of the last command
GIT_BRANCH=$(git rev-parse --abbrev-ref HEAD 2> /dev/null) # git branch name if existing
# PROMPT ELEMENTS
PROMPT_BEFORE="\n"
PROMPT_COUNTER="$GREY[\#]$NONE"
#PROMPT_COUNTER="$GREY[$COUNTER]$NONE"
PROMPT_USER="$GREY[$BLUE\u$NONE$GREY@$NONE"
PROMPT_HOSTNAME="$GREEN\h$NONE"
PROMPT_GIT_BRANCH=""
PROMPT_SPACER="$GREY>$NONE"
PROMPT_PATH_PARENT=""
PROMPT_PATH="$PINK\W$GREY]$NONE"
PROMPT_STRING="$NONE\$$NONE"
# change the color to red when the last command throwed an error
if [[ $LAST_COMMAND -eq 0 ]]; then
#PROMPT_BEFORE="\n"
#COUNTER=$((COUNTER+1))
#PROMPT_COUNTER="$GREY[$COUNTER]$NONE"
PROMPT_STRING="$NONE\$$NONE"
else
#PROMPT_BEFORE="$ERROR ↬ Counter resetted! \n$NONE"
#COUNTER=0
#PROMPT_COUNTER="$GREY[$ERROR$COUNTER$GREY]$NONE"
PROMPT_STRING="$ERROR\$$NONE"
fi
# show git branch name if existing
if [[ -n $GIT_BRANCH ]] ; then
PROMPT_GIT_BRANCH="$GREY($PURPLE$GIT_BRANCH$GREY)$NONE"
fi
# show parent directory if not in ~ (HOME) or / (ROOT)
if [[ "$PWD" = "$HOME" || "$PWD" == "/" ]]; then
PROMPT_PATH_PARENT=""
else
PARENT_PATH=$(dirname $PWD | sed "s#.*/##")
PROMPT_PATH_PARENT="$GREY$PARENT_PATH/$NONE"
fi
PS1="$PROMPT_BEFORE$PROMPT_COUNTER$PROMPT_USER$PROMPT_HOSTNAME $PROMPT_GIT_BRANCH $PROMPT_SPACER $PROMPT_PATH_PARENT$PROMPT_PATH $PROMPT_STRING "
}
# print system summary
function sys()
{
G="$(tput setaf 242)"
N="$(tput sgr0)"
clear
printf "\n"
printf " %s\n" "${G}ADDRESS: $N$(curl -s ifconfig.me)"
printf " %s\n" "${G}USER: $N$(echo $USER)"
printf " %s\n" "${G}DATE: $N$(date)"
printf " %s\n" "${G}UPTIME: $N$(uptime -p)"
printf " %s\n" "${G}HOSTNAME: $N$(hostname)"
printf " %s\n" "${G}KERNEL: $N$(uname -rms)"
printf " %s\n" "${G}PACKAGES: $N$(dpkg --get-selections | wc -l)"
printf " %s\n" "${G}MEMORY: $N$(free -g -h | awk '/Mem/{print $3"/"$2}')"
}
sys