-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.bashrc
335 lines (279 loc) · 9.51 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
#
# ~/.bashrc
# 2024 by mountaineerbr
# _ _ ___
# ._ _ _ ___ _ _ ._ _ _| |_ ___ <_>._ _ ___ ___ _ _ | . > _ _
# | ' ' |/ . \| | || ' | | | <_> || || ' |/ ._>/ ._>| '_>| . \| '_>
# |_|_|_|\___/`___||_|_| |_| <___||_||_|_|\___.\___.|_| |___/|_|
#
# _ ___
# ___ ___ ___ _| |_ | . | _ _ _ ___ _ _
# / | '<_> |<_-< | | | || | | |<_> || | |'
# \_|_.<___|/__/ |_| |_|_||__/_/ <___|`_. |
# <___''
# This file is sourced by all *interactive* bash shells on startup,
# including some apparently interactive shells such as scp and rcp
# that can't tolerate any output. So make sure this doesn't display
# anything or bad things will happen !
# Test for an interactive shell. There is no need to set anything
# past this point for scp and rcp, and it's important to refrain from
# outputting anything in those cases.
# If not running interactively, don't do anything
[[ $- != *i* ]] && return
#https://wiki.archlinux.org/index.php/Talk:Bash
#PS1 prompt
#colours
endc='\[\033[00m\]'
bwhite='\[\033[01;37;40m\]'
bcyan='\[\033[01;36m\]'
bgreen='\[\033[01;32m\]'
bpink='\[\033[01;35m\]'
bred='\[\033[01;31m\]'
yellow='\[\033[00;33m\]'
#common user
c0="$bgreen"
#root user
((EUID)) || c0="$bpink"
#widgets (ninja escaping required)
#check subshell level (needs run only once)
#OBS: SHLVL config depends on on your specific windowing system!
prompt_ssl_max=3
prompt_ssl=$( ((SHLVL >= prompt_ssl_max)) && echo "${yellow}+${endc}" )
#basic git integration (prints branch name)
prompt_git="\$( branch=\$(git rev-parse --abbrev-ref HEAD 2>/dev/null) && echo \"[${yellow}\${branch}${endc}] \" )"
#check exit code of last command line
prompt_exit="\$( ((e=\$? , e)) && echo \"${bred}\${e}${endc} \" )"
#check how many background jobs
#prompt_jobs='$([[ \j -gt 0 ]] && echo %\j)'
prompt_jobs='$([[ \j -gt 0 ]] && echo "(%\j)")'
#https://stackoverflow.com/questions/12646917/show-job-count-in-bash-prompt-only-if-nonzero
#number of trailing directory components to retain when expanding \w and \W
PROMPT_DIRTRIM=3
#set ps1 string
#PS1="${prompt_exit}${c0}\u${bwhite} \h:${bcyan}\w${endc} ${prompt_git}(\!${prompt_jobs})${prompt_ssl}\$ "
PS1="${prompt_exit}${c0}\u ${bwhite}\h:${bcyan}\w${endc} ${prompt_git}\${prompt_git:+ }${prompt_jobs}${prompt_ssl}\$ "
#keep environment clean
unset end bwhite bcyan bgreen bpink bred yellow c0 prompt_ssl_max prompt_ssl prompt_git prompt_exit prompt_jobs
#Brazilian flag prompt
#PS1='\[\e[1;33;42m\]<\[\e[1;36;42m\]•\[\e[1;33;42m\]>\[\e[m\] \w \$ '
#set XTerm title to current dir (see also TMUX set-titles)
_set_xterm_title()
{
[[ -t 1 ]] || return
[[ -z "$TMUX" ]] || return
case $TERM in
(sun-cmd)
printf "\e]l%s\e\\" "${PWD/#$HOME/\~}"
;;
(*xterm*|rxvt|dtterm|kterm|Eterm)
printf "\e]2;%s\a" "${PWD/#$HOME/\~}"
;;
esac
}
#commands to run prior issuing primary prompt
PROMPT_COMMAND=( _set_xterm_title )
#https://tldp.org/HOWTO/Xterm-Title-3.html
#https://scriptingosx.com/2019/05/show-exit-code-in-your-bash-prompt/
#https://www.maketecheasier.com/8-useful-and-interesting-bash-prompts/#respond
#https://misc.flogisoft.com/bash/tip_colors_and_formatting
#https://www.reddit.com/r/linux/comments/94nh4w/what_is_your_ps1/
#history appending & relaoding the 'history list'
# ( -a ) append history lines from this session to the history file
# ( -n ) read all history lines not already read
# from the history file and append them to the history list
#PROMPT_COMMAND+=('history -a' 'history -c' 'history -r')
PROMPT_COMMAND="${PROMPT_COMMAND%%;}; history -a; history -c; history -r"
#https://unix.stackexchange.com/questions/18212/bash-history-ignoredups-and-erasedups-setting-conflict-with-common-history
#https://www.shellhacks.com/tune-command-line-history-bash/
#http://web.archive.org/web/20090815205011/http://www.cuberick.com/2008/11/update-bash-history-in-realtime.html
#run `help history'
#history configuration
#max 'history file' size (in lines)
HISTSIZE=10000
#for 'history list' size
HISTFILESIZE=10000
#default HISTFILESIZE is set to follow HISTSIZE
#set custom history file
#HISTFILE="${HOME}/.bash_history"
#history duplicate controls
#history erases duplicates
HISTCONTROL=erasedups:ignoredups
#HISTCONTROL is a colon-separated list of values
#history ignore cmds
HISTIGNORE=bash:q:exit:x:su:sdh:sdr:shutdown
#history date format
HISTTIMEFORMAT="[%F %T]: "
#HISTTIMEFORMAT=$( echo -e "\033[0;32m[%F %T]:\033[0m " )
#end colour code: \033[0m
#https://gist.github.com/avelino/3188137
#globs will ignore filenames with control characters, leading dashes,
#or begin with a ".", as well as traditional hidden files (names beginning
#with "."), yet accept reasonable patterns (including those beginning with
#"./" and "../" and even multiple "../")
#GLOBIGNORE=`printf '.[!/.]*:..[!/]*:*/.[!/.]*:*/..[!/]*:*[\001-\037\177]*:-*'`
#https://dwheeler.com/essays/fixing-unix-linux-filenames.html
#SHell OPTions
#disable history substitution
set +H
#enable vi mode
#set -o vi
set -o noclobber #override with >|
#glob
shopt -s globstar #nocaseglob
#globs for excluding . and ..
#{ **/.[^.]*/**/*rc **/..?*/**/*rc ;}
#https://unix.stackexchange.com/questions/75786/how-do-i-specify-arguments-to-return-all-dot-files-but-not-and
#lastpipe
#shopt -s lastpipe
#in interactive shell job control is active; disbale with 'set +m'
#if set, and job control is not active, the shell runs the last command of a pipeline not executed in the background in the current shell environment.
#history appending instead of overwriting
shopt -s histappend
#same as if i'history -a' is set in COMMAND_PROMPT
#history verificatioin before exec
# Results of history substitution are not immediately
# passed to the shell parser (histverify)
shopt -s histreedit
#history cmd edition
# User is given the opportunity to re-edit a
# failed history substitution (histreedit)
shopt -s histverify
#history & multi-line
# Easy re-editing of multi-line commands
# Bash attempts to save all lines of a
# multiple-line cmd in the same history entry
shopt -s cmdhist lithist
#cd magic for minor spelling fixes
# Minor errors in spelling of directory component
# in a cd command will be corrected. The errors
# checked for are transposed char, missing char,
# and one char too many.
shopt -s cdspell
#cd auto type
# Add "cd" when entering just a path
# Bash automatically prepend cd
shopt -s autocd
#bash won't get SIGWINCH if another process is in the foreground.
#enable checkwinsize so that bash will check the terminal size when it regains control.
#http://cnswww.cns.cwru.edu/~chet/bash/FAQ (E11)
shopt -s checkwinsize
#alias expansion
#shopt -s expand_aliases
#accidental exiting
#Ctrl+D conveniently exits Bash, sometimes too conveniently
#specify that it must be pressed twice to exit
#export IGNOREEOF=1
#dirs stack
#add current dir to stack (top of stack is nought)
#alias p.='pushd .'
#check dirs stack
#alias d='dirs -v'
#hack the cd command to remember where you have been
#function cd
#{
# if [ $# -eq 0 ]; then
# pushd ~ > /dev/null
# elif [ " $1" = " -" ]; then
# pushd "$OLDPWD" > /dev/null
# else
# pushd "$@" > /dev/null
# fi
#}
#https://www.redhat.com/sysadmin/cd-command
##shell globbing
noglob_helper() {
"$@"
case "$shopts" in
*noglob*) ;;
*) set +f ;;
esac
unset shopts
}
alias noglob='shopts="$SHELLOPTS"; set -f; noglob_helper'
#check: https://www.chiark.greenend.org.uk/~sgtatham/aliases.html
#custom ls
l()
{
ls -hF --group-directories-first "${@}" \
| cut -c1-22 | column -c 80
}
la()
{
ls -ahF --group-directories-first "${@}" \
| cut -c1-22 | column -c 80
}
alias ll="ls++ --potsf"
#https://unix.stackexchange.com/questions/112335/can-i-truncate-long-file-names-in-ls-listing/112341#112341
#cd and ls dir
cl()
{
local dir="$*"
# if no dir given, go home
(($# < 1)) && dir="$HOME"
# use your preferred ls command
builtin cd "$dir" && ls -F --color=auto
}
#https://opensource.com/article/19/7/bash-aliases
#quit like in z-shell
alias bye=exit
#print compat
alias print=echo
# Enable aliases to be sudo’ed
#alias sudo='sudo '
# repeat loop
# usage: repeat 10 echo foo
repeat()
{
local i= count="$1"
shift
for i in $(seq 1 "$count")
do eval "$@"
done
}
##bash semaphore
#usage: semaphore [maximum_jobs] [sleep_time]
#example: while true ;do semaphore ; (cmd ;cmd) & done
semaphore()
{
local jobs
while jobs=( $(jobs -p) ) ;((${#jobs[@]} > ${1:-4})) ;do sleep ${2:-0.2} ;done
}
# Subfunction needed by `repeat'.
#seq ()
#{
# local lower upper output;
# lower=$1 upper=$2;
#
# if [ $lower -ge $upper ]; then return; fi
# while [ $lower -le $upper ];
# do
# echo -n "$lower "
# lower=$(($lower + 1))
# done
# echo "$lower"
#}
#some interesting stuff
#/usr/share/doc/bash/examples/{functions,misc,scripts,startup-files}
#also in bash source package
# Instalacao das Funcoes ZZ (www.funcoeszz.net)
export ZZOFF="" # desligue funcoes indesejadas
export ZZPATH="$HOME/bin/more/funcoeszz/funcoeszz" # script
export ZZDIR="$HOME/bin/more/funcoeszz/zz" # pasta zz/
#source "$ZZPATH"
#ligar funcoezz
alias ZZ='source "'"$ZZPATH"'"'
#sources
for f in \
/usr/share/bash-completion/bash_completion \
/usr/share/doc/pkgfile/command-not-found.bash \
~/.rc
do [[ -e "$f" ]] && . "$f"
done ;unset f
#the fuck
eval "$(thefuck --alias)"
##https://github.com/scop/bash-completion
##complete Cmd Names (-c and subsequent cmds)
##complete file names ( -f )
#complete -cf sudo
##this complete built-in may interfere with bash-completions
##https://forum.manjaro.org/t/how-to-auto-complete-a-command-with-sudo-privilege/50263/24