forked from x/icebergs
97 lines
2.8 KiB
Go
97 lines
2.8 KiB
Go
package code
|
|
|
|
import (
|
|
"path"
|
|
|
|
ice "shylinux.com/x/icebergs"
|
|
"shylinux.com/x/icebergs/base/cli"
|
|
"shylinux.com/x/icebergs/base/mdb"
|
|
"shylinux.com/x/icebergs/base/nfs"
|
|
kit "shylinux.com/x/toolkits"
|
|
)
|
|
|
|
func _sh_main_script(m *ice.Message, arg ...string) (res []string) {
|
|
if kit.FileExists(kit.Path(arg[2], arg[1])) {
|
|
res = append(res, kit.Format("source %s", kit.Path(arg[2], arg[1])))
|
|
} else if b, ok := ice.Info.Pack[path.Join(arg[2], arg[1])]; ok && len(b) > 0 {
|
|
res = append(res, string(b))
|
|
}
|
|
m.Cmdy(cli.SYSTEM, SH, "-c", kit.Join(res, ice.NL))
|
|
if m.StatusTime(); cli.IsSuccess(m) {
|
|
m.SetAppend()
|
|
}
|
|
return
|
|
}
|
|
|
|
const SH = nfs.SH
|
|
|
|
func init() {
|
|
Index.Merge(&ice.Context{Name: SH, Help: "命令", Commands: map[string]*ice.Command{
|
|
SH: {Name: "sh path auto", Help: "命令", Action: ice.MergeAction(map[string]*ice.Action{
|
|
ice.CTX_INIT: {Name: "_init", Help: "初始化", Hand: func(m *ice.Message, arg ...string) {
|
|
for _, cmd := range []string{mdb.SEARCH, mdb.ENGINE, mdb.RENDER, mdb.PLUGIN} {
|
|
m.Cmd(cmd, mdb.CREATE, m.CommandKey(), m.PrefixKey())
|
|
}
|
|
LoadPlug(m, m.CommandKey())
|
|
}},
|
|
mdb.SEARCH: {Name: "search", Help: "搜索", Hand: func(m *ice.Message, arg ...string) {
|
|
if arg[0] == mdb.FOREACH {
|
|
return
|
|
}
|
|
m.Option(cli.CMD_DIR, kit.Select(ice.SRC, arg, 2))
|
|
m.Cmdy(mdb.SEARCH, MAN1, arg[1:])
|
|
m.Cmdy(mdb.SEARCH, MAN8, arg[1:])
|
|
_go_find(m, kit.Select(cli.MAIN, arg, 1), arg[2])
|
|
_go_grep(m, kit.Select(cli.MAIN, arg, 1), arg[2])
|
|
}},
|
|
mdb.ENGINE: {Name: "engine", Help: "引擎", Hand: func(m *ice.Message, arg ...string) {
|
|
_sh_main_script(m, arg...)
|
|
}},
|
|
mdb.RENDER: {Name: "render", Help: "渲染", Hand: func(m *ice.Message, arg ...string) {
|
|
_sh_main_script(m, arg...)
|
|
}},
|
|
}, PlugAction()), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
|
if len(arg) > 0 && kit.Ext(arg[0]) == SH {
|
|
_sh_main_script(m, SH, arg[0], ice.SRC)
|
|
return
|
|
}
|
|
m.Option(nfs.DIR_DEEP, ice.TRUE)
|
|
m.Option(nfs.DIR_ROOT, ice.SRC)
|
|
m.Option(nfs.DIR_REG, ".*.(sh)$")
|
|
m.Cmdy(nfs.DIR, arg)
|
|
}},
|
|
}, Configs: map[string]*ice.Config{
|
|
SH: {Name: SH, Help: "命令", Value: kit.Data(PLUG, kit.Dict(
|
|
SPLIT, kit.Dict(SPACE, " ", OPERATE, "{[(.,;!|<>)]}"),
|
|
PREFIX, kit.Dict("#!", COMMENT, "# ", COMMENT), SUFFIX, kit.Dict(" {", COMMENT),
|
|
PREPARE, kit.Dict(
|
|
KEYWORD, kit.Simple(
|
|
"require", "source", "return", "local", "export", "env",
|
|
|
|
"if", "then", "else", "fi",
|
|
"for", "while", "do", "done",
|
|
"esac", "case", "in",
|
|
|
|
"shift",
|
|
"echo",
|
|
"read",
|
|
"eval",
|
|
"kill",
|
|
"let",
|
|
"cd",
|
|
),
|
|
FUNCTION, kit.Simple(
|
|
"xargs",
|
|
"date", "uptime", "uname", "whoami",
|
|
"find", "grep", "sed", "awk",
|
|
"pwd",
|
|
"ls",
|
|
"ps",
|
|
"rm",
|
|
"go",
|
|
),
|
|
), KEYWORD, kit.Dict(),
|
|
))},
|
|
}})
|
|
}
|