-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcommons
executable file
·56 lines (52 loc) · 2.34 KB
/
commons
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
#!/usr/bin/env bash
# This script is meant to be sourced
#
# When you source this script, than you would be able to connect various modules,
# that can help you to add functionality to new script quickly.
if [ -z "$BASH_VERSION" ] && [ -z "$ZSH_VERSION" ]; then
echo "Sorry, but awesome shell commons can be used/sourced only with bash or zsh";
else
declare -f "awesome_shell_include" > /dev/null
if [ $? -ne 0 ]; then
[ -z "$awesome_shell_commons_file_dir" ] &&
awesome_shell_commons_file_dir=$( cd "$( dirname "${BASH_SOURCE[0]:-$0}" )" && pwd );
awesome_shell_includes_list=();
awesome_shell_arguments=("$@");
awesome_shell_include(){
local retries_remaining=2
while [[ $retries_remaining -gt 0 ]];do
retries_remaining=$((retries_remaining -1))
if [ -z "$awesome_shell_arguments" ];then
awesome_shell_arguments=("${BASH_ARGV[@]}")
fi;
for include in "${awesome_shell_includes_list[@]}"; do
if [ "$include" = "$*" ]; then
# Include only once
return;
fi;
done
local needs_retry=0
if [ -n "$awesome_shell_commit_ref" ];then
lib_content=$(cd "$awesome_shell_commons_file_dir" && git show "$awesome_shell_commit_ref:shell-libs/$*") && eval "$lib_content"
elif [ -f "$awesome_shell_commons_file_dir/shell-libs/$*" ]; then
source "$awesome_shell_commons_file_dir/shell-libs/$*"
else
needs_retry=1
echo "Will try to fetch upstream repo in order to find $*";
cd "$awesome_shell_commons_file_dir" && git pull origin 1>/dev/null 2>&1
if [ $? -eq 0 ];then
echo "awesome-shell updates have been fetched from origin";
else
retries_remaining=0
fi;
fi;
if [ $? -eq 0 ] && [ $needs_retry -eq 0 ];then
awesome_shell_includes_list+=("$*")
return 0
fi;
done
echo "Fatal error: cannot include required file $*";
exit 1;
}
fi;
fi;