-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path.bashrc.seb
289 lines (234 loc) · 12 KB
/
.bashrc.seb
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
# vim: ft=bash noet:
test -z "$initDir" && export initDir=$HOME/.initBash
! declare 2>&1 | grep -wq ^colors= && [ $BASH_VERSINFO -ge 4 ] && source $initDir/.colors
function Debug { test "$debug" -gt 0 && echo "$bold${colors[blue]}$@$normal"; }
function Source { test "$debug" -gt 0 && { time . "$@";echo;true; } || { . "$@" ; } ; }
if tty -s;then function Echo { echo -e "$@"; } else function Echo { : ; } fi
if tty -s;then function Printf { printf "$@"; } else function Printf { : ; } fi
test "$debug" -gt 0 && Echo "\n=> \${BASH_SOURCE[*]} = ${BASH_SOURCE[*]}\n"
Debug "=> Running $(basename ${BASH_SOURCE[0]}) ..."
#Echo "$(date)"
sebInterpreter=$(ps -o args= $$ | awk '{gsub("^/.*/","",$1);print$1}')
( [ $sebInterpreter = bash ] || [ $sebInterpreter = zsh ] || [ $sebInterpreter = sh ] ) && local=local || local=typeset
unset sebInterpreter
[ "$debug" -gt 2 ] && set -x
set -o histexpand # Re-enable the history expansion disabled previously by my "echo" alias
#test -n "$bashRCLoaded" && return
bashRCLoaded=1
echo $OSTYPE | grep -q android && export osFamily=Android || export osFamily=$(uname -s)
[ $osFamily = Linux ] && export osID=$(Source /etc/os-release && echo $ID) osID_LIKE=$(Source /etc/os-release && echo $ID_LIKE)
archi=$(uname -m)
today=$(date +%Y-%m-%d)
function addmanpaths {
for manpath
do
test ! -d "$manpath" && continue
echo $MANPATH | \grep -wq "$manpath" || {
test -z "$MANPATH" && MANPATH=$manpath || MANPATH=$MANPATH:$manpath
}
done
export MANPATH
}
function addpaths {
for path
do
test ! -d "$path" && continue
echo $PATH | \grep -wq "$path" || PATH=$path:$PATH
done
export PATH
}
function addpathsAtTheEnd {
for path
do
test ! -d "$path" && continue
echo $PATH | \grep -wq "$path" || PATH=$PATH:$path
done
export PATH
}
if [ -n "$sourceHighlightPath" ];then
export LESSOPEN="| $sourceHighlightPath %s"
fi
test -d /usr/local/share/android-commandlinetools && export ANDROID_SDK_ROOT=/usr/local/share/android-commandlinetools
test -d $HOME/.android && export ANDROID_SDK_HOME=$HOME/.android
TeXLiveDIR=$(\ls -d /usr/local/texlive/*/bin/* 2>/dev/null | egrep "/texlive/[0-9]+/bin/$archi-${osFamily,,}")
#echo "=> BEFORE: PATH = $PATH"
systemPathsList="/sbin /usr/sbin /usr/local/sbin /usr/local/go/bin $GOPATH/bin /opt/local/bin /opt/local/sbin /usr/share/fslint/fslint /usr/local/opt/openjdk/bin $ANDROID_SDK_ROOT/cmdline-tools/latest/bin $ANDROID_SDK_ROOT/emulator $ANDROID_SDK_ROOT/platform-tools"
userPathsList="$GOPATH/bin $HOME/.opam/system/bin $HOME/perl5/bin $HOME/rvm/bin $HOME/local/sbin $HOME/local/bin $HOME/usr/bin $HOME/usr/local/bin $HOME/gnu/bin $HOME/.local/bin $HOME/shl $HOME/py $HOME/pl $HOME/bin $HOME/php"
addpathsAtTheEnd $systemPathsList
addpathsAtTheEnd $TeXLiveDIR
#addpathsAtTheEnd /home/linuxbrew/.linuxbrew/bin /home/linuxbrew/.linuxbrew/sbin
addpathsAtTheEnd $HOME/myScripts/shl $HOME/myScripts/py $HOME/myScripts/pl
addpathsAtTheEnd $userPathsList
addpathsAtTheEnd $HOME/.poetry/bin
#echo "=> AFTER: PATH = $PATH"
manPathsList="/opt/ffmpeg/share/man /opt/local/man $HOME/.local/share/man /usr/local/share/man /usr/share/man /usr/local/miniconda3/share/man /usr/local/miniconda2/share/man"
addmanpaths $manPathsList
#Definitions de mes fonctions bash pour Linux
[ -n "$BASH_VERSION" ] && test -r $initDir/.bash_functions && Source $initDir/.bash_functions
test -r $initDir/.bash_functions.seb && Source $initDir/.bash_functions.seb
type -P lpr >/dev/null 2>&1 && test -f $initDir/.bash_aliases.lpr && Source $initDir/.bash_aliases.lpr
type -P mpv >/dev/null 2>&1 && test -r $initDir/.bash_aliases.mpv && Source $initDir/.bash_aliases.mpv
type -P ffmpeg >/dev/null 2>&1 && test -r $initDir/.bash_aliases.AV && Source $initDir/.bash_aliases.AV
type -P mpv >/dev/null 2>&1 && test -r $initDir/.bash_functions.mpv && Source $initDir/.bash_functions.mpv
type -P units >/dev/null 2>&1 && test -r $initDir/.bash_functions.units && Source $initDir/.bash_functions.units
if type -P youtube-dl >/dev/null 2>&1 || type -P yt-dlp >/dev/null 2>&1;then
test -r $initDir/.bash_aliases.ytdl && Source $initDir/.bash_aliases.ytdl
test -r $initDir/.bash_functions.ytdl && Source $initDir/.bash_functions.ytdl
fi
test -r ~/.config/.bcrc && export BC_ENV_ARGS="-l $HOME/.config/.bcrc"
#Export de toutes les fonctions sauf celles dont le nom commence par "_"
#export -f $(declare -F | egrep -v " __?" | awk '{print$NF}')
user=$(\id -un)
hostname=$HOSTNAME
test -r $initDir/.bashrc.$osID && Source $initDir/.bashrc.$osID # Pour les OS derives de $osFamily
test -r $initDir/.colors && Source $initDir/.colors
test -n "$SSH_CLIENT" && sshPrompt=" : ${colors[red]}SSH "
#PROMPT_COMMAND='echo -ne "\033]0;$USER : $hostname @ $domain / $system : $(date +"%A %d %B %Y %H:%M") $PWD\007"'
PS1="$user : $blink${colors[red]}$hostname$normal$sshPrompt @ $bold${colors[blue]}$domain / $italics${colors[green]}$system : $bold${colors[blue]}\w$normal
"
jupyterRuntimeDIR=$(jupyter --runtime-dir 2>/dev/null)
if [ -n "$jupyterRuntimeDIR" ]
then
\pgrep -f jupyter-notebook >/dev/null 2>&1 && \mkdir -pv $jupyterRuntimeDIR
if [ -d $jupyterRuntimeDIR ]
then
test -k $jupyterRuntimeDIR || \chmod -v +t $jupyterRuntimeDIR # See : https://github.com/jupyter/notebook/issues/3718
fi
fi
\mkdir -pvm 700 ~/.ssh/sockets/
# When connecting through ssh, Removes the configured PulseAudio configuration from the X11 root window.
env | grep -q SSH_CLIENT && type -P pax11publish >/dev/null 2>&1 && pax11publish -r
if tty -s #Si c'est une session interactive
then
trap 'echo "=> Ignoring this step and continuing the script <$(basename $BASH_SOURCE)> ..." >&2' INT
if type -P aplay >/dev/null 2>&1 && LANG=C timeout 5 aplay -l 2>/dev/null | grep -wq "card"
then
audioCardNumber=$(LANG=C aplay -l 2>/dev/null | grep -wv HDMI | awk -F "[ :]" '/^card/{number=$2;exit}END{print number}')
# test $audioCardNumber && amixer -q -c $audioCardNumber -- sset Master 100%
fi
trap - INT
# type -P randverse >/dev/null 2>&1 && randverse && echo
fi
if type -P xdg-mime >/dev/null 2>&1 && [ $osID != sailfishos ]
then
xdg-mime query default application/pdf | grep -wq evince.desktop || xdg-mime default evince.desktop application/pdf
fi
#test -f ~/.rvm/scripts/rvm && Source ~/.rvm/scripts/rvm
if type -P pdflatex >/dev/null 2>&1
then
grep -qw pdflatex= $HOME/.pdfnup.conf || echo pdflatex=$(type -P pdflatex) >> $HOME/.pdfnup.conf
fi
tty -s && { # For interactive shell sessions
if type -P ssh-add >/dev/null 2>&1 && ! ssh-add -l 2>/dev/null | grep -q "$UPMC_ID"
then
if test -s ~/.ssh/.$UPMC_ID; then
if [ -z "$SSH_CLIENT" ] && ! tty | grep "/dev/tty[0-9]$" -q; then # Si on est PAS a l autre bout d une connection ssh et qu'on est pas sur la console
echo "=> Loading my ssh key from <$(basename $BASH_SOURCE)> ..."
trap 'echo "=> Ignoring this step and continuing the script <$(basename $BASH_SOURCE)> ..." >&2' INT
# Echo "=> Trying to load the ssh key for 10-15s ..." && set -x && time timeout -v -k 15s -s SIGKILL 10s ssh-add ~/.ssh/.$UPMC_ID
set +x
ssh-add ~/.ssh/.$UPMC_ID
retCode=$?
[ $retCode = 0 ] && Echo "=> ssh key successfully loaded." >&2 || Echo "=> Failed loading ssh key." >&2
echo >&2
set +x
trap - INT
fi
fi
fi
}
cd
if test -r /usr/share/bash-completion/bash_completion
then
Debug "=> Running /usr/share/bash-completion/bash_completion ..."
set -o | grep -q xtrace.*on && xtrace="set -o xtrace"
set +x
Source /usr/share/bash-completion/bash_completion
$xtrace
Debug "=> END of /usr/share/bash-completion/bash_completion ..."
fi
#[[ -s "$HOME/.rvm/scripts/rvm" ]] && Source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
# pidof cupsd >/dev/null && Echo "=> The cups admin console is available at http://localhost:631/admin\n"
type -P conda >/dev/null 2>&1 && test -r $initDir/.bashrc.conda && Source $initDir/.bashrc.conda
getprop 2>/dev/null | grep ro.build.version.release -q && test -r $initDir/.bash_aliases.getprop && Source $initDir/.bash_aliases.getprop
if type -P openssl >/dev/null 2>&1;then
test -r $initDir/.bashrc.openssl && Source $initDir/.bashrc.openssl
test -r $initDir/.bash_aliases.openssl && Source $initDir/.bash_aliases.openssl
test -r $initDir/.bash_functions.openssl && Source $initDir/.bash_functions.openssl
fi
if type -P brew >/dev/null 2>&1;then
test -r $initDir/.bashrc.brew && Source $initDir/.bashrc.brew
test -r $initDir/.bash_aliases.brew && Source $initDir/.bash_aliases.brew
test -r $initDir/.bash_functions.brew && Source $initDir/.bash_functions.brew
fi
if type -P smartctl >/dev/null 2>&1;then
test -r $initDir/.bash_functions.smartctl && Source $initDir/.bash_functions.smartctl
fi
if type -P docker >/dev/null 2>&1;then
test -r $initDir/.bash_functions.docker && Source $initDir/.bash_functions.docker
fi
if type -P adb >/dev/null 2>&1 && \pgrep -u $USER -f "adb -. " >/dev/null;then
test -r $initDir/.bash_aliases.adb && Source $initDir/.bash_aliases.adb
test -r $initDir/.bash_functions.adb && Source $initDir/.bash_functions.adb
fi
test -r $initDir/.bashrc.$osFamily && Source $initDir/.bashrc.$osFamily
#test -r $initDir/.bashrc.$osFamily.$HOSTNAME && Source $initDir/.bashrc.$osFamily.$HOSTNAME
test -r $initDir/.bashrc.$osID_LIKE && Source $initDir/.bashrc.$osID_LIKE # Si c'est un Linux de type Debian ou Redhat
#my git configuration
if type -P git >/dev/null 2>&1; then
# test -r $initDir/.bashrc.git && Source $initDir/.bashrc.git
test -r $initDir/.bash_aliases.git && Source $initDir/.bash_aliases.git
test -r $initDir/.bash_functions.git && Source $initDir/.bash_functions.git
fi
test -r $initDir/.bashrc.gpu && Source $initDir/.bashrc.gpu
# Load machine specific script
test -r $initDir/.bashrc.$HOSTNAME && Source $initDir/.bashrc.$HOSTNAME
#Definitions de mes alias
test -r $initDir/.bash_aliases && Source $initDir/.bash_aliases
test -r $initDir/.bash_aliases.$osFamily && Source $initDir/.bash_aliases.$osFamily #Pour Darwin ou Linux ou Android
test -r $initDir/.bash_aliases.$osID && Source $initDir/.bash_aliases.$osID # Pour les OS derives de $osFamily
type -P qemu-system-$archi >/dev/null 2>&1 && test -r $initDir/.bash_aliases.qemu && Source $initDir/.bash_aliases.qemu
test -r $initDir/.bash_functions.$osFamily && Source $initDir/.bash_functions.$osFamily #Pour Darwin ou Linux ou Android
test -r $initDir/.bash_functions.$osID && Source $initDir/.bash_functions.$osID # Pour les OS derives de $osFamily
case $OSTYPE in
linux-gnueabi)
type -P resize >/dev/null 2>&1 && resize
type -P busybox >/dev/null 2>&1 && test -r $initDir/.bash_aliases.busybox && Source $initDir/.bash_aliases.busybox
type -P toybox >/dev/null 2>&1 && test -r $initDir/.bash_aliases.toybox && Source $initDir/.bash_aliases.toybox
;;
linux-android)
if type -P termux-info >/dev/null;then
test -r $initDir/.bash_aliases.Linux && Source $initDir/.bash_aliases.Linux
test -r $initDir/.bash_functions.Linux && Source $initDir/.bash_functions.Linux
fi
;;
esac
if [ $osFamily = Linux ];then
if groups | \egrep -wq "sudo|adm|admin|root|wheel";
then
export GOBIN=/usr/local/bin
distribType=$(distribType)
test $distribType = debian && export sudo=sudo
test -r $initDir/.bash_aliases.admin && Source $initDir/.bash_aliases.admin
else
export GOBIN=~/go/bin
fi
sed="command sed -r"
calendar | grep '*'
elif [ $osFamily = Darwin ];then
export GOBIN=/usr/local/bin
sed="command sed -E"
fi
# Disable aliases for tools that are not found in $PATH
#for tool in curl ffmpeg ffprobe hexdump hw-probe lsb_release vim;do ! type -P $tool >/dev/null 2>&1 && alias | grep -q $tool && unalias $tool;done
#Echo "=> Undefining aliases for which the tools are not installed ..."
#time alias | $sed "s/alias //;s/=[']\w+=\S+ /=/;s/sudo -?\w? //;s/(command|time) //;s/[$]\(which (\w+)\)/\1/;s/\/\S+\///;s/='?\\\?/ /" | awk '!/^[.]+/{print$1" "$2}' | sort -u | Pgrep -v '\s?-|^$' | while read aliasName tool
#do
## echo "$tool" | grep -q -- "^-" && echo "=> aliasName = <$aliasName> tool = <$tool>" && continue
# ! type -P $tool >/dev/null 2>&1 && alias | grep -q $tool && unalias $aliasName #Does not work on Jolla1/SFOS3
# set +x
#done
#Echo "=> DONE !"
quoteCHAR="'\''"
set +x
Debug "=> END of $(basename ${BASH_SOURCE[0]})"