-
Notifications
You must be signed in to change notification settings - Fork 0
/
.bashrc.init
64 lines (56 loc) · 1.05 KB
/
.bashrc.init
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
#!/usr/bin/env bash
#
# .bashrc.init
#
DEFAULT="\e[0m";
GREEN="\e[32m";
CYAN="\e[36m";
function isInteractiveShell()
{
# Main purpose/usage is inside functions, or during .bashrc processing(often via logPrint)
if [ -t 1 ] ; then
return 0
else
return 1
fi
}
function logPrint()
{
if isInteractiveShell
then
echo -e $*$DEFAULT;
fi
}
function isSuse()
{
grep -qi suse /etc/os-release
}
function isBsd()
{
uname -a | egrep -iq bsd
}
function addToPath()
{
DST=$(readlink -fn $1)
if [ $? -ne 0 ]
then
echo "Not a valid dir: $1"
return
fi
if [[ $PATH =~ $DST ]]
then
logPrint "PATH already contains $1 (as $DST)"
else
if [ -L "$1" ]
then
WHERE="end"
export PATH="$PATH:$DST"
else
WHERE="beginning"
export PATH="$DST:$PATH"
fi
logPrint "Adding $1 to $BOLD$WHERE$UNBOLD of PATH"
fi
}
export -f logPrint isBsd isSuse isInteractiveShell addToPath
logPrint "${GREEN}Read bashrc.init$DEFAULT"