-
Notifications
You must be signed in to change notification settings - Fork 0
/
.bashrc
362 lines (319 loc) · 9.64 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
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
test -f ~/.bashrc-local.sh && . ~/.bashrc-local.sh
#{{{ Prompt String
# https://ss64.com/bash/syntax-prompt.html
# Heavily inspired by @necolas’s prompt:
# https://github.com/necolas/dotfiles
if [[ $COLORTERM = gnome-* && $TERM = xterm ]] && infocmp gnome-256color >/dev/null 2>&1; then
export TERM='gnome-256color';
elif infocmp xterm-256color >/dev/null 2>&1; then
export TERM='xterm-256color';
fi;
# https://misc.flogisoft.com/bash/tip_colors_and_formatting
BFG_RESET_ALL="\[\e[0m\]"
# FG USADO PARA COLORIR FUNDO DA OU TEXTO
BG_DEFAULT="\[\e[49m\]"
BG_BLACK="\[\e[40m\]"
BG_WHITE="\[\e[107m\]"
BG_RED="\[\e[41m\]"
BG_RED_LIGHT="\[\e[101m\]"
BG_GREEN="\[\e[42m\]"
BG_GREEN_LIGHT="\[\e[102m\]"
BG_YELLOW="\[\e[43m\]"
BG_YELLOW_LIGHT="\[\e[103m\]"
BG_BLUE="\[\e[44m\]"
BG_BLUE_LIGHT="\[\e[104m\]"
BG_MAGENTA="\[\e[45m\]"
BG_MAGENTA_LIGHT="\[\e[105m\]"
BG_CYAN="\[\e[46m\]"
BG_CYAN_LIGHT="\[\e[106m\]"
BG_GRAY_LIGHT="\[\e[47m\]"
BG_GRAY_DARK="\[\e[100m\]"
# FG USADO PARA COLORIR OU TEXTO
FG_BLINK="\[\e[5m\]"
FG_BOLD="\[\e[1m\]"
FG_DIM="\[\e[2m\]"
FG_UNDERLINE="\[\e[4m\]"
FG_DEFAULT="\[\e[39m\]"
FG_BLACK="\[\e[30m\]"
FG_WHITE="\[\e[97m\]"
FG_RED="\[\e[31m\]"
FG_RED_LIGHT="\[\e[91m\]"
FG_GREEN="\[\e[32m\]"
FG_GREEN_LIGHT="\[\e[92m\]"
FG_YELLOW="\[\e[33m\]"
FG_YELLOW_LIGHT="\[\e[93m\]"
FG_BLUE="\[\e[34m\]"
FG_BLUE_LIGHT="\[\e[94m\]"
FG_MAGENTA="\[\e[35m\]"
FG_MAGENTA_LIGHT="\[\e[95m\]"
FG_CYAN="\[\e[36m\]"
FG_CYAN_LIGHT="\[\e[96m\]"
FG_GRAY_LIGHT="\[\e[37m\]"
FG_GRAY_DARK="\[\e[90m\]"
TEST_COLORS_PROMPT="$(for i in {40..47} {100..107} {30..37} {90..97} ; do echo -en "\e[${i}m # \e[0m" ; done ; echo)"
prompt_git() {
local s='';
local branchName='';
# Check if the current directory is in a Git repository.
if [ $(git rev-parse --is-inside-work-tree &>/dev/null; echo "${?}") == '0' ]; then
# check if the current directory is in .git before running git checks
if [ "$(git rev-parse --is-inside-git-dir 2> /dev/null)" == 'false' ]; then
# Ensure the index is up to date.
git update-index --really-refresh -q &>/dev/null;
# Check for uncommitted changes in the index.
if ! $(git diff --quiet --ignore-submodules --cached); then s+='+'; fi;
# Check for unstaged changes.
if ! $(git diff-files --quiet --ignore-submodules --); then s+='!'; fi;
# Check for untracked files.
if [ -n "$(git ls-files --others --exclude-standard)" ]; then s+='?'; fi;
# Check for stashed files.
if $(git rev-parse --verify refs/stash &>/dev/null); then s+='$'; fi;
fi;
# Get the short symbolic ref.
# If HEAD isn’t a symbolic ref, get the short SHA for the latest commit
# Otherwise, just give up.
branchName="$(git symbolic-ref --quiet --short HEAD 2> /dev/null || \
git rev-parse --short HEAD 2> /dev/null || \
echo '(unknown)')";
[ -n "${s}" ] && s=" [${s}]";
echo -e " ${1}${branchName}${s}";
else
return;
fi;
}
ps1_simple(){
# Como PS é modificado através de função
# para evitar duplicação ele precisa ser inicializado.
# A melhor forma é no início pois evita que seja dentro de if
PS1=""
PS2=""
# Highlight the user name when logged in as root.
if [[ "${USER}" == "root" ]]; then
userStyle="$FG_RED";
else
userStyle="$FG_CYAN";
fi;
# Highlight the hostname when connected via SSH.
if [[ "${SSH_TTY}" ]]; then
hostStyle="$BG_BOLD$FG_RED";
else
hostStyle="$FG_YELLOW";
fi;
PS1+="$BG_DEFAULT$FG_CYAN["
PS1+="$FG_BLUE_LIGHT\u"
#PS1+="@"
#PS1+="\h"
PS1+="$FG_CYAN]"
PS1+="$BG_DEFAULT$FG_BLUE_LIGHT["
PS1+="$BG_DEFAULT$FG_MAGENTA_LIGHT"
PS1+='$(echo $(dirname $(echo \w | sed "s;$HOME;~;"))/ |sed -e "s;\(/\.\?.\)[^/]*;\1;g" -e "s;/h/s;~;" -e "s;\./;;")\W'
PS1+="$BG_DEFAULT$FG_BLUE_LIGHT]"
if [ ! -w "$PWD" ]; then
# Current directory is not writable
PS1+="$BG_DEFAULT$FG_GRAY_DARK "
fi
PS1+="$BG_DEFAULT$FG_YELLOW$(prompt_git)$BG_DEFAULT"; # Git repository details
PS1+="$BG_DEFAULT$FG_WHITE \$ $BFG_RESET_ALL";
PS1+="$BFG_RESET_ALL"; # reset bg and fg colors
export PS1;
PS2="$BG_DEFAULT$FG_YELLOW→ ";
PS2+="$BFG_RESET_ALL"; # reset bg and fg colors
export PS2;
}
PROMPT_COMMAND="ps1_simple; $PROMPT_COMMAND"
#}}}
#{{{ Aliases
alias c="clear"
alias m="make -f meumakefile"
alias g="git"
alias xcb='tr -d "\n" | xclip -selection clipboard'
alias pwdx='pwd | tr -d "\n" | xclip -selection clipboard'
alias op='xdg-open .'
alias anbox='anbox launch --package=org.anbox.appmgr --component=org.anbox.appmgr.AppViewActivity' # adb install ~/path/to/app.apk
alias dc="docker-compose"
alias dce="docker-compose exec"
alias dca="docker-compose exec app"
#{{{ CD
alias cdf="cd $HOME/dev/dotfiles"
alias cdev="cd $HOME/dev"
alias cdphp="cd $HOME/dev/php"
alias d='cd ~/dev/desh; ls -alf --color; echo -e "\n-> dev trash dashboard\n-> to clean: rm -rf * .*"'
alias .b='. ~/.bashrc'
alias ..='cd ..'
alias ...='cd ../..'
alias ....='cd ../../..'
#}}}
#{{{ LS
alias ll='ls -alF --color'
alias l='ls -aXF --color'
alias lm='ls -alS --block-size=M'
#}}}
#{{{ PHP
alias sail='[ -f sail ] && bash sail || bash vendor/bin/sail'
alias s='[ -f sail ] && bash sail || bash vendor/bin/sail'
alias sa='[ -f sail ] && bash sail || bash vendor/bin/sail art'
alias sc='[ -f sail ] && bash sail || bash vendor/bin/sail composer'
alias sup='[ -f sail ] && bash sail || bash vendor/bin/sail up -d'
alias sd='[ -f sail ] && bash sail || bash vendor/bin/sail down'
alias sam='[ -f sail ] && bash sail || bash vendor/bin/sail artisan migrate:fresh --seed'
alias sao='[ -f sail ] && bash sail || bash vendor/bin/sail artisan optimize:clear'
alias saq='[ -f sail ] && bash sail || bash vendor/bin/sail composer art queue:work'
alias sci='[ -f sail ] && bash sail || bash vendor/bin/sail composer ide'
alias sp='[ -f sail ] && bash sail || bash vendor/bin/sail php'
alias spp='[ -f sail ] && bash sail || bash vendor/bin/sail php ./vendor/bin/pint'
alias sppd='[ -f sail ] && bash sail || bash vendor/bin/sail php ./vendor/bin/pint --dirty'
alias sn='[ -f sail ] && bash sail || bash vendor/bin/sail npm'
alias tdd='gon -c '
alias tdds='gon -c ./vendor/bin/sail test '
alias tddsf='gon -c ./vendor/bin/sail test --filter '
#}}}
#{{{ Vim
alias n="nvim"
alias v="vim"
#}}}
#}}}
#{{{ Functions
# DESC: Ver previsão do tempo para Porto Alegre
# USE: wttr
wttr(){
curl wttr.in/porto+alegre?lang=pt-br
}
# DESC: Repetir um mesmo comando com Enter
# USE: wrl echo "a"
wrl(){
while $@; read line; do true; done;
# simplificação
# $@;
# while read line; do $@; done;
}
# DESC: Simplificar comando de execução imnline do Laravel Tinker
# USE: tinker "Storage::put(time().'.txt', 'hello')"
tinker(){
sail art tinker --execute="$@"
}
# DESC: Repetir X vezes o comando Y
# USE: fori 10 echo "olha"
fori(){
local FORI1=$1
shift 1
for i in $(seq 1 $FORI1); do
$@
done;
}
# DESC: Criar e entrar na pasta
# USE: mk folder
mk(){
mkdir $1;
cd $1;
}
# DESC: Arquivos basicos dos meus repositórios com git
# USE: gi
gi(){
cp ~/dev/dotfiles/modelos/git/UNLICENSE UNLICENSE;
cp ~/dev/dotfiles/modelos/git/CONTRIBUTING.md CONTRIBUTING.md;
(echo -n '# '; pwd | rev | cut -d '/' -f1 | rev) >> README.md;
echo -e "\n-> don't forget to use git init or git flow init and create branch master";
}
# DESC: Extração de arquivos
# USE: extract imazip.zip
extract() {
if [ -f $1 ]; then
case $1 in
*.tar.bz2)
tar xjf $1
;;
*.tar.gz)
tar xzf $1
;;
*.bz2)
bunzip2 $1
;;
*.rar)
rar x $1
;;
*.gz)
gunzip $1
;;
*.tar)
tar xf $1
;;
*.tbz2)
tar xjf $1
;;
*.tgz)
tar xzf $1
;;
*.zip)
unzip $1
;;
*.Z)
uncompress $1
;;
*)
echo "'$1' cannot be extracted via extract()"
;;
esac
else
echo "'$1' is not a valid file"
fi
}
#{{{ Pendrives
# DESC: Formatar pendrive
# USE: fmtpendrive sdb1
fmtpendrive(){
# identificar pendrive: sudo fdisk -l
sudo mkfs.vfat -I /dev/$1
}
#}}}
#{{{
# DESC: exibir um gopherzinho
# USE: gopher
# USE: gopher vampire
gopher(){
pink=`tput setaf 213`
cyan=`tput setaf 14`
beige=`tput setaf 215`
white=`tput setaf 15`
black=`tput setaf 0`
red=`tput setaf 9`
base=$cyan
reset=`tput sgr0`
eye=" ^ "
teeth="${white}UU"
if [[ "$1" == "vampire" ]]
then
eye=" o "
teeth="${red}VV"
fi
echo "${base} ´.-::::::-.´"
echo "${base} .:-::::::::::::::-:."
echo "${base} ´_::${white}: :: :${base}::_´"
echo "${base} .:${white}(${eye}::${eye})${base}:."
echo "${base} ´::${white}: ${beige}(${black}..${beige})${white} :${base}::."
echo "${base} ´:::::::${teeth}${base}:::::::´"
echo "${base} .::::::::::::::::."
echo "${beige} O${base}::::::::::::::::${beige}O"
echo "${base} -::::::::::::::::-"
echo "${base} ´::::::::::::::::´"
echo "${base} .::::::::::::::."
echo "${beige} oO${base}:::::::${beige}Oo"
echo "${reset}"
}
#}}}
#}}}
#{{{ Exports
export GOPATH=$HOME/go
# export VISUAL=nvim
export VISUAL=vim
export EDITOR=$VISUAL
export DF=$HOME/dev/dotfiles
export IS=$HOME/dev/is
export PATH=$HOME/bin:$HOME/.local/bin:$HOME/Android/Sdk:/usr/local/go/bin:$GOPATH/bin:$PATH;
#}}}
#{{{ Inputrc
# Desabilitar case-sensitive
set completion-ignore-case on
# Mostrar possíveis complementações
set show-all-if-ambiguous on
#}}}
# vim:fdm=marker: