-
Notifications
You must be signed in to change notification settings - Fork 6
/
functions
51 lines (44 loc) · 1.13 KB
/
functions
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
#!/bin/bash
script_path() {
pushd . > /dev/null
local script_path="$1";
while([ -h "${script_path}" ]) do
cd "`dirname "${script_path}"`"
script_path="$(readlink "`basename "${script_path}"`")";
done
cd "`dirname "${script_path}"`" > /dev/null
script_path="`pwd`";
popd > /dev/null
echo $script_path
}
source_directories() {
local _directories=${@:1}
for _directory in $_directories; do
if [ -d $_directory ]; then
for file in $_directory/*; do
if [ -x $file ] && $(file $file | grep -q 'shell script'); then
source $file
fi
done
fi
done
}
register_alias() {
local _alias=$1
local _command=$2
alias "$_alias=$_command"
REGISTERED_ALIASES+=( $_alias )
}
unregister_alias() {
local _alias=$1
if [[ " ${REGISTERED_ALIASES[@]} " =~ " ${_alias} " ]]; then
unalias $_alias
REGISTERED_ALIASES=( ${REGISTERED_ALIASES[@]/$_alias} )
fi
}
unregister_aliases() {
for registered_alias in ${REGISTERED_ALIASES[@]}; do
unalias $registered_alias
done
unset REGISTERED_ALIASES
}