-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path.prefix
136 lines (109 loc) · 3.49 KB
/
.prefix
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
#!/bin/bash -l
#
# .prefix
#
# Matcha 1.0, Created by gradyzhuo, enoch_lee.
# Copyright © 2017, Matcha Inc. All rights reserved.
#
declare -x MATCHA_VERSION='1.0'
declare -x INSTALL_LIB_TARGET="$HOME/.matcha"
declare -x COMMAND_BASE
declare -x COMMAND
declare -f command_exists
declare -f welcome
declare -f tips
declare -f @exec
declare -f @exists
declare -f @log
declare -f @print
declare -f @prints
declare -f @phase
declare -f matcha_session_update
function @print(){
pc "$@"
}
function @prints(){
pcs "$@"
}
function @phase() {
title="$1"
echo ""
@print -c cyan -s bold "++ $title ----------"
}
function welcome(){
@print ''
@print -c green -s bold '##############################'
@print -c green -s bold '# #'
@print -c green -s bold '# ~~ Welcome ~~ #'
@print -c green -s bold '# Matcha Scripting #'
@print -c green -s bold '# Version 1.0 #'
@print -c green -s bold '# #'
@print -c green -s bold '##############################'
@print ''
}
function tips(){
@print -c "green" "============================"
@print -c "green" -s "bold" "Now you can \`@import module\` module to do something."
@print -c "green" -s "bold" 'Try it!\n```\n @print -c "blue" Hello Matcha!\n```'
@prints "-c green -s bold 'And you will see the result: '" "-c blue 'Hello Matcha!'"
@print -c green -s bold "Enjoy it!"
@print -c "green" "============================"
}
function @import() {
declare module=$(basename "$1")
declare -i SILENT_IMPORT=1
if [[ "$@" == *"--silent"* ]]; then
SILENT_IMPORT=0
fi
[[ "$module" == "" && $SILENT_IMPORT == 1 ]] && echo -e "\033[36;1m-- Module name can't be empty! ----------\033[m" && return 1;
declare module_dir=$(dirname "$1")
declare module_path="$module_dir/$module"
if [[ ! -e "$module_path/@.imports" ]]; then
module_path="$MODULES_FOLDER/$module"
fi
if [[ -L "$module_path.mm" ]]; then
real=$(readlink "$module_path.mm")
module_path=$(dirname "$real")
fi
if [[ -e "$module_path" ]]; then
pushd "$module_path" >/dev/null 2>&1
source @.imports >/dev/null
popd >/dev/null 2>&1
[[ $SILENT_IMPORT == 1 ]] && echo -e "\033[36;1m>> Module [$module] import succeed.\033[m" && return 0;
else
[[ $SILENT_IMPORT == 1 ]] && echo -e "\033[36;1m-- Module [$module] not found! ----------\033[m" && return 1;
fi
}
function @exec() {
matcha "$@"
}
function shell_function_exists() {
declare -f -F $1 >/dev/null 2>&1
echo "$?"
}
function shell_command_exists() {
command -v $1 >/dev/null 2>&1
echo "$?"
}
# -f : function
# -c : command
function @exists() {
_type="$1"
_command="$2"
if [[ "$_type" == "-f" ]]; then
shell_function_exists $_command
fi
if [[ "$_type" == "-c" ]]; then
shell_command_exists $_command
fi
}
function @log() {
title="$1"
DATETIME="$(date +"%y-%m-%d %H:%M:%S")"
@print -c cyan -s bold "[$DATETIME] $title"
}
function @error() {
title="$1"
DATETIME="$(date +"%y-%m-%d %H:%M:%S")"
@print -c cyan -s bold "[$DATETIME] $title" 1>&2
}