forked from lqueryvg/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmy_functions.sh
112 lines (96 loc) · 1.58 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
[[ $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
command_exists() {
command -v $1 > /dev/null 2>&1
}
exec_if_exists() {
if [[ -x $1 ]]
then
echo exec $*
exec $*
fi
}
source_if_exists() {
for f in $*
do
if [[ -f $f ]]
then
echo source $(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() {
echo " PATH+ '$1'"
PATH="${PATH}:$1"
export PATH
}
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/profile.d/$1 \
$d/profile.d/$1.sh \
$d/local.d/$1 \
$d/local.d/$1.sh
}
#echo my_functions.sh end