-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmy_functions.sh
146 lines (122 loc) · 1.98 KB
/
my_functions.sh
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
[[ $functions_already_sourced == 1 ]] && {
#echo my_functions.sh already done
return
}
# echo my_functions.sh start
functions_already_sourced=1
if [ -n "$ZSH_VERSION" ]; then
SHELL_IS_ZSH=true
# assume Zsh
elif [ -n "$BASH_VERSION" ]; then
SHELL_IS_BASH=true
else
# something else
:
fi
is_bash() {
[[ $SHELL_IS_BASH == true ]]
}
is_zsh() {
[[ $SHELL_IS_ZSH == true ]]
}
command_exists() {
command -v $1 > /dev/null 2>&1
}
is_interactive() {
[[ $SHELL_IS_INTERACTIVE == true ]]
}
exec_if_exists() {
if [[ -x $1 ]]
then
echo exec $*
exec $*
fi
}
source_if_exists() {
for f in $*
do
if [[ -f $f ]]
then
echo $(yellow $(basename $f))
. $f
fi
done
}
source_first_if_exists() {
for f in $*
do
if [[ -f $f ]]
then
echo Source: $f
. $f
return
fi
done
}
append_path() {
PATH="${PATH}:$1"
PATH_ADDITIONS="${PATH_ADDITIONS}:$1"
export PATH
export PATH_ADDITIONS
}
append_path_if_exists() {
for d in $@
do
if [[ -d "$d" ]] ; then
append_path "$d"
fi
done
}
# insert_path() {
# echo "insert PATH '$1'"
# PATH="$1:${PATH}"
# export PATH
# }
prepend_path_if_exists() {
for d in $*
do
if [[ -d "$d" ]] ; then
PATH="$1:${PATH}"
export PATH
# insert_path "$d"
fi
done
}
# set window title
title() {
echo -ne "\033]0;"$1"\007"
}
#venv() {
# source_first_if_exists \
# venv/bin/activate \
# ~/projects/azure/dist/venv/bin/activate
#}
# "source it"
# e.g. sit kops
# quick way to source a startup file
# can optionally omit the suffix if you happen to know the basename
sit() {
d=~/dotfiles
source_first_if_exists \
$d/public.d/$1 \
$d/public.d/$1.sh \
$d/private.d/$1 \
$d/private.d/$1.sh
}
blue() {
str="$1"
echo "\e[0;34m${str}\e[0m"
}
red() {
str="$1"
echo "\e[0;31m${str}\e[0m"
}
yellow() {
str="$1"
echo "\e[0;33m${str}\e[0m"
}
lilac() {
str="$1"
echo "\e[0;36m${str}\e[0m"
}
#echo my_functions.sh end