-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbash_additions.sh
171 lines (131 loc) · 3.32 KB
/
bash_additions.sh
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
#!/bin/bash
# add content directly to ~.bashrc or load it with `source /path/to/bashrc_additions.sh`
#
# optional additional environment needed to be set manually in ~.bashrc variables for some
# functions:
# - custom_var_bookmarks: for custom function `c`, uncomment below or copy
# custom_var_bookmarks=/path/to/bookmarks/
# - custom_var_scripts: for loading additional custom scripts into $PATH, uncomment below or copy
# custom_var_scripts=/path/to/scripts/
# aliases
# general aliases
alias l='ls -lha --group-directories-first'
alias r='rsync -a'
alias m='flatpak run org.gnome.Meld'
alias p='pwd'
# git aliases
alias gs='git status'
alias gb='git branch'
alias gr='git remote -v'
alias gl='git log --graph --all'
alias gd='git diff'
alias gdc='git diff --cached'
alias ga='git add'
alias gc='git commit -m'
alias gpl='git pull'
alias gps='git push'
# function `c`
# convenient folder change with integrated bookmarks autocomplete
# add folder with custom sym links (treated as bookmarks) to CDPATH, so that `cd` can use it
# anywhere
if [[ ":${CDPATH}:" != *":${custom_var_bookmarks}:"* ]]; then
export CDPATH="${custom_var_bookmarks}:$CDPATH"
fi
# reuse autocomplete functionality of `cd`
complete -o nospace -F _cd c
c() {
# if no param is passed, go one folder above
if [ $# -eq 0 ]; then
cd .. && l
# if param is passed, go there
else
cd -P "$1" > /dev/null && l
fi
pwd
}
# function `t`
# quick tree call, with optional first parameter being depth and seccond a specific folder
t() {
if [[ "$1" =~ ^[0-9]+$ ]]; then
if [[ "$2" != "" ]]; then
tree -a -L "$1" "$2"
else
tree -a -L "$1"
fi
elif [[ "$1" != "" ]]; then
tree -a "$1"
else
tree -a
fi
}
# function `f`
# quick find
f() {
find -L . -iname "*$1*"
}
# function `g`
# quick grep
g() {
grep -R --color -inr -F "$1" .
}
# function `gf`
# quick grep and find
gf() {
g "$1"
f "$1"
}
# function `d`
# quick trash
d() {
trash-put "$@"
}
# function `o`
# open file with default gui application
o() {
xdg-open "$@" &> /dev/null
}
# function `s`
# quick cat
s() {
cat "$@"
}
# add custom scripts folder to $PATH
if [[ ":$PATH:" != *":${custom_var_scripts}:"* ]]; then
export PATH="${custom_var_scripts}:$PATH"
fi
# commandline status and coloring
# show only user, no host, and only current folder
# for normal user (cyan):
export PS1="\[\e\[\033[30;01;106m\]\W\[\033[00m\] "
# for root (red):
#export PS1="\[\e\[\033[30;01;101m\]\W\[\033[00m\] "
# show current folder as terminal title (and show `root` explicitley)
# for normal user:
PROMPT_COMMAND='echo -ne "\033]0;${PWD/${PWD%*/*}\/}\007"'
# for root:
#PROMPT_COMMAND='echo -ne "\033]0;root: ${PWD/${PWD%*/*}\/}\007"'
# various input controls
# disable XOFF, so that ctrl+s can be used for going back in bash reverse-i search (ctrl-r)
stty -ixon
# add hidden files to bash expansion
shopt -s dotglob
# change interrupt to ctrl-x
stty intr ^X
# remap delete word from ctrl-w to ctrl-backpsace
stty werase \^H
# unlimited history
HISTSIZE=-1
HISTFILESIZE=-1
# append all history
shopt -s histappend
# Immediately append commands to the history file
PROMPT_COMMAND='history -a'
# ignore duplicates
HISTCONTROL=ignoreboth:erasedups
# veld helper
function vu {
docker compose -f "$1" up --force-recreate
}
function vr {
docker compose -f "$1" run "$2" "$3"
}