Skip to content

Commit f7c9349

Browse files
author
harveyshao
committed
opt code
1 parent a752656 commit f7c9349

File tree

3 files changed

+28
-76
lines changed

3 files changed

+28
-76
lines changed

conf.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,3 @@
33
require sys/sys.sh
44
require dev/dev.sh
55
require app/app.sh
6-

index.sh

Lines changed: 4 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@ _down_big_file() { # 下载文件 dir url
1010
wget -O $1 "$ctx_dev/$2?pod=$ctx_pod"
1111
fi
1212
}
13-
_down_files() { # 下载文件 file...
14-
for file in "$@"; do _down_file $file publish/${file##*/}; done
15-
}
1613
_down_file() { # 下载文件 dir url
1714
echo $1| grep "/" &>/dev/null && mkdir -p ${1%*/*}; if curl -h &>/dev/null; then
1815
curl -o $1 -fsSL $ctx_dev/$2
@@ -23,26 +20,8 @@ _down_file() { # 下载文件 dir url
2320
_temp_file() { # 加载文件 url arg...
2421
ctx_temp=$(mktemp) && _down_file $ctx_temp $1 && shift && source $ctx_temp "$@"
2522
}
26-
_down_tars() { # 下载文件 file...
27-
for file in "$@"; do _down_tar $file publish/$file; done
28-
}
29-
_down_tar() { # 下载文件 file path
30-
[ -f $1 ] && return; _down_big_file "$@" && tar -xf $1
31-
}
32-
3323
prepare_script() {
34-
for script in "$@"; do _temp_file $script; done
35-
}
36-
prepare_package() {
37-
_down_tars contexts.bin.tar.gz contexts.src.tar.gz
38-
local back=$PWD; cd ~/; _down_tars contexts.home.tar.gz; cd $back
39-
export VIM=$PWD/usr/install/vim-vim-12be734/_install/share/vim/vim82/
40-
export LD_LIBRARY_PATH=$PWD/usr/local/lib
41-
42-
ish_sys_path_load
43-
git config --global init.templatedir $PWD/usr/install/git-2.31.1/_install/share/git-core/templates/
44-
git config --global url."$ctx_dev".insteadOf https://shylinux.com
45-
git config --global init.defaultBranch master
24+
_temp_file plug.sh && require conf.sh
4625
}
4726
prepare_system() {
4827
case "$(uname)" in
@@ -58,10 +37,6 @@ prepare_system() {
5837
;;
5938
esac
6039
}
61-
prepare_tmux() {
62-
_down_file etc/tmux.conf dev/tmux/tmux.conf
63-
_down_file bin/tmux.sh dev/tmux/local.sh
64-
}
6540
prepare_ice() {
6641
local bin="ice"
6742
case `uname -s` in
@@ -78,37 +53,23 @@ prepare_ice() {
7853
esac
7954
_down_big_file bin/ice.bin publish/$bin && chmod u+x bin/ice.bin; [ -f bin/ice.bin ]
8055
}
81-
8256
main() {
8357
case "$1" in
8458
intshell) # 安装环境
8559
[ -f $PWD/.ish/plug.sh ] && source $PWD/.ish/plug.sh && return
8660
[ -f $HOME/.ish/plug.sh ] && source $HOME/.ish/plug.sh && return
87-
git clone https://shylinux.com/x/intshell $PWD/.ish
61+
prepare_system && git clone https://shylinux.com/x/intshell $PWD/.ish
8862
source $PWD/.ish/plug.sh; require conf.sh; require miss.sh
8963
;;
90-
project) # 创建项目
91-
prepare_script plug.sh conf.sh miss.sh; prepare_system
92-
ish_miss_prepare_compile
93-
ish_miss_prepare_develop
94-
ish_miss_prepare_install
95-
ish_miss_prepare_contexts
96-
export PATH=${PWD}/bin:$PATH ctx_log=${ctx_log:=/dev/stdout}
97-
go get shylinux.com/x/ice
98-
shift && make && ish_miss_serve "$@"
99-
;;
10064
source) # 源码安装
101-
prepare_system
102-
git clone https://shylinux.com/x/contexts
65+
prepare_system && git clone https://shylinux.com/x/contexts
10366
shift && cd contexts && source etc/miss.sh "$@"
10467
;;
10568
binary) # 应用安装
106-
export ctx_log=${ctx_log:=/dev/stdout} ctx_dev="https://shylinux.com"
10769
shift && prepare_ice && bin/ice.bin forever start dev "" "$@"
10870
;;
10971
*) # 终端环境
110-
prepare_script plug.sh conf.sh miss.sh
111-
_temp_file require/src/main.sh "$@"
72+
prepare_script; if echo $1|grep ".sh$" &>/dev/null; then require "$@"; else require src/main.sh "$@"; fi
11273
;;
11374
esac
11475
}

plug.sh

Lines changed: 24 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
## 1.配置 # {
44
ISH_CONF_HOME=${ISH_CONF_HOME:="$HOME/.ish/pluged"}
55
ISH_CONF_PATH=${ISH_CONF_PATH:="$PWD/.ish/pluged"}
6-
76
ISH_CONF_LOG=${ISH_CONF_LOG:="/dev/stderr"}
87
ISH_CONF_LEVEL=${ISH_CONF_LEVEL:="notice debug"}
98
ISH_CONF_COLOR=${ISH_CONF_COLOR:="true"}
@@ -35,17 +34,15 @@ ish_log() {
3534
ish_log_debug() { ish_log "debug" "$@" `_fileline 2 2`; }
3635
ish_log_require() { ish_log "require" "$@"; }
3736
ish_log_request() { ish_log "request" "$@"; }
38-
ish_log_source() { ish_log "source" "$@"; }
3937
ish_log_notice() { ish_log "notice" "$@"; }
4038
ish_log_alias() { ish_log "alias" "$@"; }
4139
# }
4240
## 3.加载 # {
4341
require_path() { # 目录 repos
44-
for name in "$@"; do
45-
[ -e $name ] && echo $name && continue
42+
for name in "$@"; do [ -f $name ] && echo $name && continue
4643
for p in $PWD/.ish/pluged $ISH_CONF_PATH $ISH_CONF_HOME; do
47-
[ -e $p/$name ] && echo $p/$name && break
48-
[ -e ${p%/*}/$name ] && echo ${p%/*}/$name && break
44+
[ -f $p/$name ] && echo $p/$name && break
45+
[ -f ${p%/*}/$name ] && echo ${p%/*}/$name && break
4946
done
5047
done
5148
}
@@ -63,37 +60,32 @@ require_pull() { # 更新 repos
6360
local back=$PWD; cd "$(require_fork $1)" && ish_log_notice pwd $PWD && git pull; cd $back; echo
6461
}
6562
require_temp() { # 下载 file
66-
for name in "$@"; do local temp=$(mktemp); ish_log_request "$temp <= $ctx_dev/$name"
67-
echo $name| grep "^src/" &>/dev/null && name="require/$name"
68-
if curl -h &>/dev/null; then
69-
curl --create-dirs -fsSL -o $temp $ctx_dev/$name && echo $temp
70-
else
71-
wget -O $temp -q $ctx_dev/$name && echo $temp
72-
fi
73-
done
63+
for file in "$@"; do
64+
local temp=$(mktemp); if curl -h &>/dev/null; then
65+
curl -o $temp --create-dirs -fssl $file
66+
else
67+
wget -O $temp -q $file
68+
fi && echo $temp
69+
done 2>/dev/null
7470
}
7571
require() { # require [mod] file arg...
76-
local mod=$1 && shift
77-
local file=$(require_path $mod)
78-
[ -f "$file" ] || if echo $mod| grep "^git" &>/dev/null; then
72+
local mod=$1 && shift; local file=$(require_path $mod)
73+
[ -f "$file" ] || if echo $mod| grep ".git$" &>/dev/null; then
7974
file=$(require_fork "$mod")/$1 && shift
80-
elif echo $mod| grep "shylinux.com/x/" &>/dev/null; then
75+
elif echo $mod| grep "^shylinux.com/x/" &>/dev/null; then
8176
file=$(require_fork "$mod")/$1 && shift
82-
else
77+
elif echo $mod| grep "^git" &>/dev/null; then
78+
file=$(require_fork "$mod")/$1 && shift
79+
elif echo $mod| grep "^http" &>/dev/null; then
8380
file=$(require_temp $mod)
84-
fi; [ -f "$file" ] || return 0
85-
86-
local back=$PWD && [ -d "${file%/*}" ] && cd ${file%/*}
87-
ISH_CTX_MODULE=$(_name ish_${name}) ISH_CTX_SCRIPT=$1 _load $file "$@"
88-
cd $back; return 0
89-
}
90-
_load() {
91-
local file=$1 && shift
92-
ish_log_source "$file "$@""
93-
source ./${file##*/} "$@"
94-
}
95-
_name() {
96-
local name="$*" && echo ${name//[^a-zA-Z0-9_]/_}
81+
elif echo $mod| grep "^/" &>/dev/null; then
82+
file=$(require_temp $ctx_dev$mod)
83+
elif echo $mod| grep "^src/" &>/dev/null; then
84+
file=$(require_temp $ctx_dev/require/$mod)
85+
else
86+
file=$(require_temp $ctx_dev/$mod); [ -z "$file" ] && file=$(require_temp $ctx_dev/require/${ISH_CTX_MODULE%/*}/$mod)
87+
fi; [ -f "$file" ] || return 0; ish_log_require "$file <= $mod"; eval "url=$(echo "$mod"|grep -o "?.*"|tr "?&" " ")"
88+
ISH_CTX_MODULE=$mod ISH_CTX_SCRIPT=$file source $file "$@"
9789
}
9890
_fileline() {
9991
local index1=$((${1}-1))

0 commit comments

Comments
 (0)