-
Notifications
You must be signed in to change notification settings - Fork 8
/
nox.sh
executable file
·51 lines (40 loc) · 1.05 KB
/
nox.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
#!/bin/sh
source $NOX_ROOT/common/utils.sh
function _usage_of_nox() {
cat << EOF
Usage:
nox subcmd1 [subcmd2] [-option] [value] ...
Description:
使用 Tab 提示,选择对应的子命令,从而索引到指定的脚本。使用选项/参数为脚本提供运行参数。
Option:
--help|-h: -- using help
--debug|-x: -- debug mode
EOF
}
function _search_and_execut_script() {
local path="$NOX_SCRIPTS"
while [[ ! -z $1 && ! $1 =~ ^- ]]; do
path="$path/$1"
shift 1
done
local script="$path.sh"
if [[ ! -x $script ]]; then
error "$script not exist."
exit 1
fi
zsh $script $*
}
function nox() {
if [[ $# -eq 0 || $1 == "-h" || $1 == "--help" ]]; then
_usage_of_nox
exit 1
fi
if [[ $1 == "-x" || $1 == "--debug" ]]; then
set -x
fi
_search_and_execut_script $*
if [[ $1 == "-x" || $1 == "--debug" ]]; then
set +x
fi
}
nox $*