-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.bashrc.init
More file actions
75 lines (65 loc) · 1.24 KB
/
Copy path.bashrc.init
File metadata and controls
75 lines (65 loc) · 1.24 KB
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
#!/usr/bin/env bash
#
# .bashrc.init
#
DEFAULT="\e[0m"
GREEN="\e[32m"
CYAN="\e[36m"
export HOST_OS=$(uname -s)
shopt -s nocasematch
function isInteractiveShell()
{
# Main purpose/usage is inside functions, or during .bashrc processing(often via logPrint)
[ -t 1 ]
}
function logPrint()
{
if isInteractiveShell
then
echo -e $*$DEFAULT;
fi
}
function isSuse()
{
grep -qi suse /etc/os-release
}
function isBsd()
{
if [ -z "$HOST_OS" ]
then
export HOST_OS=$(uname -s)
if uname -s | grep -iq bsd
then
return 0
fi
elif [[ $HOST_OS =~ bsd ]]
then
return 0
fi
return 1
}
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"