From 76adc035dd478c8c786d5ed1ffe386278088a906 Mon Sep 17 00:00:00 2001 From: shaoying Date: Tue, 15 Sep 2020 21:18:02 +0800 Subject: [PATCH] add inner.split --- base/mdb/mdb.go | 62 ++------ base/web/route.go | 4 +- core/code/go.go | 16 +- core/code/inner.go | 48 +++--- core/code/publish.go | 18 ++- core/code/vimer.go | 10 ++ core/team/team.go | 47 ++---- go.sum | 2 + misc/git/git.go | 365 +------------------------------------------ misc/vim/vim.shy | 15 +- misc/zsh/sess.go | 10 -- type.go | 3 + 12 files changed, 89 insertions(+), 511 deletions(-) diff --git a/base/mdb/mdb.go b/base/mdb/mdb.go index 1540b050..1ff93acb 100644 --- a/base/mdb/mdb.go +++ b/base/mdb/mdb.go @@ -1,9 +1,6 @@ package mdb import ( - "path" - "strings" - ice "github.com/shylinux/icebergs" kit "github.com/shylinux/toolkits" "github.com/shylinux/toolkits/task" @@ -11,7 +8,9 @@ import ( "encoding/csv" "encoding/json" "os" + "path" "sort" + "strings" ) func _file_name(m *ice.Message, arg ...string) string { @@ -236,7 +235,6 @@ func _list_export(m *ice.Message, prefix, key, file string) { m.Log_EXPORT(kit.MDB_FILE, p, kit.MDB_COUNT, count) m.Echo(p) } - func _list_search(m *ice.Message, prefix, key, field, value string) { list := []interface{}{} files := map[string]bool{} @@ -265,40 +263,6 @@ func _list_search(m *ice.Message, prefix, key, field, value string) { }) } -func _dict_import(m *ice.Message, prefix, key, file string) { - f, e := os.Open(file) - m.Assert(e) - defer _story_catch(m, JSON, file) - defer f.Close() - - data := map[string]interface{}{} - de := json.NewDecoder(f) - de.Decode(&data) - - count := 0 - for k, v := range data { - m.Log_MODIFY(kit.MDB_KEY, kit.Keys(prefix, key), "k", k, "v", v) - m.Conf(prefix, kit.Keys(key, k), v) - count++ - } - m.Log_EXPORT(kit.MDB_FILE, file, kit.MDB_COUNT, count) -} -func _dict_export(m *ice.Message, prefix, key, file string) { - f, p, e := kit.Create(kit.Keys(file, JSON)) - m.Assert(e) - defer _story_catch(m, JSON, p) - defer f.Close() - - en := json.NewEncoder(f) - en.SetIndent("", " ") - en.Encode(m.Confv(prefix, kit.Keys(key))) - m.Log_EXPORT(kit.MDB_FILE, p) -} - -func _story_catch(m *ice.Message, kind, file string) { - m.Cmdy("web.story", "catch", kind, file) -} - const ( ErrDenyModify = "deny modify " ) @@ -351,10 +315,6 @@ var Index = &ice.Context{Name: "mdb", Help: "数据模块", } }}, SELECT: {Name: "select conf key type field value", Help: "数据查询", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { - m.Conf(arg[0], arg[1]) - - m.Option("cache.begin") - m.Option("cache.begin") switch arg[2] { case HASH: _hash_select(m, arg[0], arg[1], kit.Select("", arg, 3), kit.Select(kit.MDB_FOREACH, arg, 4)) @@ -386,13 +346,6 @@ var Index = &ice.Context{Name: "mdb", Help: "数据模块", _list_export(m, arg[0], arg[1], file) } }}, - INPUTS: {Name: "inputs conf key type field value", Help: "输入补全", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { - switch arg[2] { - case HASH: - _hash_inputs(m, arg[0], arg[1], arg[3], kit.Select("", arg, 4)) - case LIST: - } - }}, PRUNES: {Name: "prunes conf key type [field value]...", Help: "清理数据", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { switch arg[2] { case HASH: @@ -400,13 +353,20 @@ var Index = &ice.Context{Name: "mdb", Help: "数据模块", case LIST: } }}, + INPUTS: {Name: "inputs conf key type field value", Help: "输入补全", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { + switch arg[2] { + case HASH: + _hash_inputs(m, arg[0], arg[1], arg[3], kit.Select("", arg, 4)) + case LIST: + } + }}, }, } func init() { ice.Index.Register(Index, nil, - PLUGIN, ENGINE, SEARCH, RENDER, INSERT, DELETE, SELECT, MODIFY, - IMPORT, EXPORT, INPUTS, PRUNES, + IMPORT, EXPORT, PRUNES, INPUTS, + PLUGIN, RENDER, SEARCH, ENGINE, ) } diff --git a/base/web/route.go b/base/web/route.go index f7200f43..48a2cd9c 100644 --- a/base/web/route.go +++ b/base/web/route.go @@ -49,7 +49,9 @@ func init() { Commands: map[string]*ice.Command{ ROUTE: {Name: "route route cmd auto 启动 添加", Help: "路由", Action: map[string]*ice.Action{ "invite": {Name: "invite", Help: "添加", Hand: func(m *ice.Message, arg ...string) { - m.Cmdy("web.code.install", "contexts", "base") + m.Cmdy("web.code.publish", "contexts", "tmux") + m.Cmdy("web.code.publish", "contexts", "base") + m.Cmdy("web.code.publish", "contexts", "miss") }}, "inputs": {Name: "inputs", Help: "补全", Hand: func(m *ice.Message, arg ...string) { switch arg[0] { diff --git a/core/code/go.go b/core/code/go.go index 7c479f2c..bc1ed56e 100644 --- a/core/code/go.go +++ b/core/code/go.go @@ -84,14 +84,14 @@ func init() { Index.Register(&ice.Context{Name: GO, Help: "go", Commands: map[string]*ice.Command{ ice.CTX_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { - m.Cmd(mdb.SEARCH, mdb.CREATE, GO, GO, c.Cap(ice.CTX_FOLLOW)) m.Cmd(mdb.PLUGIN, mdb.CREATE, GO, GO, c.Cap(ice.CTX_FOLLOW)) m.Cmd(mdb.RENDER, mdb.CREATE, GO, GO, c.Cap(ice.CTX_FOLLOW)) + m.Cmd(mdb.SEARCH, mdb.CREATE, GO, GO, c.Cap(ice.CTX_FOLLOW)) m.Cmd(mdb.ENGINE, mdb.CREATE, GO, GO, c.Cap(ice.CTX_FOLLOW)) - m.Cmd(mdb.SEARCH, mdb.CREATE, GODOC, GO, c.Cap(ice.CTX_FOLLOW)) m.Cmd(mdb.PLUGIN, mdb.CREATE, GODOC, GO, c.Cap(ice.CTX_FOLLOW)) m.Cmd(mdb.RENDER, mdb.CREATE, GODOC, GODOC, c.Cap(ice.CTX_FOLLOW)) + m.Cmd(mdb.SEARCH, mdb.CREATE, GODOC, GO, c.Cap(ice.CTX_FOLLOW)) m.Cmd(mdb.PLUGIN, mdb.CREATE, MOD, MOD, c.Cap(ice.CTX_FOLLOW)) m.Cmd(mdb.RENDER, mdb.CREATE, MOD, MOD, c.Cap(ice.CTX_FOLLOW)) @@ -100,7 +100,7 @@ func init() { m.Cmd(mdb.RENDER, mdb.CREATE, SUM, SUM, c.Cap(ice.CTX_FOLLOW)) }}, - MOD: {Name: MOD, Help: "mod", Action: map[string]*ice.Action{ + SUM: {Name: SUM, Help: "sum", Action: map[string]*ice.Action{ mdb.PLUGIN: {Hand: func(m *ice.Message, arg ...string) { m.Echo(m.Conf(GO, "meta.mod.plug")) }}, @@ -108,7 +108,7 @@ func init() { m.Cmdy(nfs.CAT, path.Join(arg[2], arg[1])) }}, }}, - SUM: {Name: SUM, Help: "sum", Action: map[string]*ice.Action{ + MOD: {Name: MOD, Help: "mod", Action: map[string]*ice.Action{ mdb.PLUGIN: {Hand: func(m *ice.Message, arg ...string) { m.Echo(m.Conf(GO, "meta.mod.plug")) }}, @@ -123,7 +123,10 @@ func init() { }}, }}, GO: {Name: GO, Help: "go", Action: map[string]*ice.Action{ - mdb.SEARCH: {Name: "search type name text", Hand: func(m *ice.Message, arg ...string) { + mdb.PLUGIN: {Hand: func(m *ice.Message, arg ...string) { + m.Echo(m.Conf(GO, "meta.plug")) + }}, + mdb.SEARCH: {Hand: func(m *ice.Message, arg ...string) { if arg[0] == kit.MDB_FOREACH { return } @@ -133,9 +136,6 @@ func init() { _go_help(m, kit.Select("main", arg, 1)) _go_grep(m, kit.Select("main", arg, 1)) }}, - mdb.PLUGIN: {Hand: func(m *ice.Message, arg ...string) { - m.Echo(m.Conf(GO, "meta.plug")) - }}, mdb.RENDER: {Hand: func(m *ice.Message, arg ...string) { m.Cmdy(nfs.CAT, path.Join(arg[2], arg[1])) }}, diff --git a/core/code/inner.go b/core/code/inner.go index cf31f215..d8698e85 100644 --- a/core/code/inner.go +++ b/core/code/inner.go @@ -16,33 +16,35 @@ func _inner_ext(name string) string { return strings.ToLower(kit.Select(path.Base(name), strings.TrimPrefix(path.Ext(name), "."))) } func _inner_list(m *ice.Message, ext, file, dir string, arg ...string) { + if strings.HasPrefix("http", dir) { + m.Cmdy(web.SPIDE, web.SPIDE_DEV, web.SPIDE_RAW, web.SPIDE_GET, dir+file) + return + } + if m.Warn(!m.Right(dir, file), ice.ErrNotAuth, path.Join(dir, file)) { return } if m.Cmdy(mdb.RENDER, ext, file, dir, arg); m.Result() != "" { return } + if m.Conf(INNER, kit.Keys("meta.source", ext)) == "true" { - if m.Cmdy(mdb.RENDER, nfs.FILE, file, dir, arg); m.Result() != "" { + if m.Cmdy(nfs.CAT, path.Join(dir, file)); m.Result() != "" { return } } m.Echo(path.Join(dir, file)) } func _inner_show(m *ice.Message, ext, file, dir string, arg ...string) { - if m.Cmdy(mdb.ENGINE, ext, file, dir, arg); m.Result() == "" { - if ls := kit.Simple(m.Confv(INNER, kit.Keys("meta.show", ext))); len(ls) > 0 { - m.Cmdy(cli.SYSTEM, ls, path.Join(dir, file)).Set(ice.MSG_APPEND) - } + if m.Warn(!m.Right(dir, file), ice.ErrNotAuth, path.Join(dir, file)) { + return } -} -func _vimer_save(m *ice.Message, ext, file, dir string, text string) { - if f, p, e := kit.Create(path.Join(dir, file)); e == nil { - defer f.Close() - if n, e := f.WriteString(text); m.Assert(e) { - m.Log_EXPORT("file", path.Join(dir, file), "size", n) - } - m.Echo(p) + if m.Cmdy(mdb.ENGINE, ext, file, dir, arg); m.Result() != "" { + return + } + + if ls := kit.Simple(m.Confv(INNER, kit.Keys("meta.show", ext))); len(ls) > 0 { + m.Cmdy(cli.SYSTEM, ls, path.Join(dir, file)).Set(ice.MSG_APPEND) } } @@ -51,32 +53,28 @@ const INNER = "inner" func init() { Index.Merge(&ice.Context{ Commands: map[string]*ice.Command{ - INNER: {Name: "inner path=usr/demo file=hi.sh line=1 auto 运行:button 项目:button 搜索:button", Help: "阅读器", Meta: kit.Dict( + INNER: {Name: "inner path=src/ file=main.go line=1 auto 项目 搜索 运行", Help: "阅读器", Meta: kit.Dict( "display", "/plugin/local/code/inner.js", "style", "editor", ), Action: map[string]*ice.Action{ - mdb.PLUGIN: {Name: "plugin type name text arg...", Help: "插件", Hand: func(m *ice.Message, arg ...string) { + mdb.PLUGIN: {Name: "plugin", Help: "插件", Hand: func(m *ice.Message, arg ...string) { if m.Cmdy(mdb.PLUGIN, arg); m.Result() == "" { if m.Echo(m.Conf(INNER, kit.Keys("meta.plug", arg[0]))); m.Result() == "" { m.Echo("{}") } } }}, - mdb.SEARCH: {Name: "search type name text arg...", Help: "搜索", Hand: func(m *ice.Message, arg ...string) { - m.Cmdy(mdb.SEARCH, arg) - }}, - mdb.RENDER: {Name: "render type name text arg...", Help: "渲染", Hand: func(m *ice.Message, arg ...string) { + mdb.RENDER: {Name: "render", Help: "渲染", Hand: func(m *ice.Message, arg ...string) { _inner_list(m, arg[0], arg[1], arg[2], arg[3:]...) }}, - mdb.ENGINE: {Name: "engine type name text arg...", Help: "引擎", Hand: func(m *ice.Message, arg ...string) { + mdb.SEARCH: {Name: "search", Help: "搜索", Hand: func(m *ice.Message, arg ...string) { + m.Cmdy(mdb.SEARCH, arg) + }}, + mdb.ENGINE: {Name: "engine", Help: "引擎", Hand: func(m *ice.Message, arg ...string) { _inner_show(m, arg[0], arg[1], arg[2], arg[3:]...) }}, }, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { if len(arg) < 2 { - _inner_list(m, nfs.DIR, "", kit.Select("", arg, 0)) - return - } - if strings.HasPrefix("http", arg[0]) { - m.Cmdy(web.SPIDE, "dev", "raw", "GET", arg[0]+arg[1]) + m.Cmdy(nfs.DIR, kit.Select("./", arg, 0)) return } _inner_list(m, _inner_ext(arg[1]), arg[1], arg[0]) diff --git a/core/code/publish.go b/core/code/publish.go index 716945a5..41d7a1a2 100644 --- a/core/code/publish.go +++ b/core/code/publish.go @@ -52,7 +52,7 @@ func init() { m.Option("userhost", fmt.Sprintf("%s@%s", m.Option(ice.MSG_USERNAME), strings.Split(u.Host, ":")[0])) m.Option("hostpath", kit.Path("./.ish/pluged")) - if buf, err := kit.Render(m.Conf(INSTALL, kit.Keys("meta.contexts", kit.Select("base", arg, 0))), m); m.Assert(err) { + if buf, err := kit.Render(m.Conf(PUBLISH, kit.Keys("meta.contexts", kit.Select("base", arg, 0))), m); m.Assert(err) { m.Cmdy("web.wiki.spark", "shell", string(buf)) } }}, @@ -83,16 +83,21 @@ func init() { var _contexts = kit.Dict( "tmux", ` # 终端环境 -curl -fLo /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-8.repo && yum -y update -yum install -y tmux +export ctx_dev={{.Option "httphost"}} ctx_temp=$(mktemp); curl -sL $ctx_dev >$ctx_temp; source $ctx_temp `, "base", ` # 生产环境 mkdir contexts; cd contexts -export ctx_dev={{.Option "httphost"}} ctx_log=/dev/stdout; curl $ctx_dev/publish/ice.sh |sh -bin/ice.sh`, +export ctx_dev={{.Option "httphost"}} ctx_temp=$(mktemp); curl -sL $ctx_dev >$ctx_temp; source $ctx_temp ice +`, "miss", ` # 开发环境 +mkdir contexts; cd contexts +export ctx_dev={{.Option "httphost"}} ctx_temp=$(mktemp); curl -sL $ctx_dev >$ctx_temp; source $ctx_temp dev +`, +) + +/* yum install -y make git vim go mkdir ~/.ssh &>/dev/null; touch ~/.ssh/config; [ -z "$(cat ~/.ssh/config|grep 'HOST {{.Option "hostname"}}')" ] && echo -e "HOST {{.Option "hostname"}}\n Port 9030" >> ~/.ssh/config export ISH_CONF_HUB_PROXY={{.Option "userhost"}}:.ish/pluged/ @@ -102,5 +107,4 @@ source etc/miss.sh touch ~/.gitconfig; [ -z "$(cat ~/.gitconfig|grep '\[url \"{{.Option "userhost"}}')" ] && echo -e "[url \"{{.Option "userhost"}}:ish/pluged/\"]\n insteadOf=\"https://github.com/\"\n" >> ~/.gitconfig git clone https://github.com/shylinux/contexts && cd contexts source etc/miss.sh -`, -) +*/ diff --git a/core/code/vimer.go b/core/code/vimer.go index 6e0ac2bb..6af6d3ec 100644 --- a/core/code/vimer.go +++ b/core/code/vimer.go @@ -9,6 +9,16 @@ import ( "path" ) +func _vimer_save(m *ice.Message, ext, file, dir string, text string) { + if f, p, e := kit.Create(path.Join(dir, file)); e == nil { + defer f.Close() + if n, e := f.WriteString(text); m.Assert(e) { + m.Log_EXPORT("file", path.Join(dir, file), "size", n) + } + m.Echo(p) + } +} + const VIMER = "vimer" func init() { diff --git a/core/team/team.go b/core/team/team.go index fd59f6be..d27e0429 100644 --- a/core/team/team.go +++ b/core/team/team.go @@ -39,7 +39,7 @@ func _task_create(m *ice.Message, zone string) { func _task_insert(m *ice.Message, zone string, arg ...string) { m.Richs(TASK, kit.Keys(kit.MDB_HASH, m.Optionv(ice.MSG_DOMAIN)), zone, func(key string, value map[string]interface{}) { id := m.Grow(TASK, kit.Keys(kit.MDB_HASH, m.Optionv(ice.MSG_DOMAIN), kit.MDB_HASH, key), kit.Dict( - BEGIN_TIME, m.Time(), CLOSE_TIME, m.Time(), kit.MDB_EXTRA, kit.Dict(), + BEGIN_TIME, m.Time(), CLOSE_TIME, m.Time("30m"), kit.MDB_EXTRA, kit.Dict(), STATUS, StatusPrepare, LEVEL, 3, SCORE, 3, arg, )) m.Log_INSERT(kit.MDB_ZONE, zone, kit.MDB_ID, id, arg[0], arg[1]) @@ -187,7 +187,7 @@ func _task_render(m *ice.Message, kind, name, text string, arg ...string) { }) }) } -func _task_action(m *ice.Message, status interface{}, action ...string) string { +func _task_action(m *ice.Message, status interface{}, action ...string) []string { switch status { case StatusPrepare: action = append(action, "开始") @@ -195,10 +195,7 @@ func _task_action(m *ice.Message, status interface{}, action ...string) string { action = append(action, "完成") case StatusCancel, StatusFinish: } - for i, v := range action { - action[i] = m.Cmdx(mdb.RENDER, web.RENDER.Button, v) - } - return strings.Join(action, "") + return action } func _task_input(m *ice.Message, field, value string) { switch field { @@ -252,19 +249,6 @@ func _task_scope(m *ice.Message, arg ...string) (time.Time, time.Time) { return begin_time, end_time } -var _task_inputs = kit.List( - "_input", "text", "name", "zone", "value", "@key", - "_input", "select", "name", "type", "values", []interface{}{ - "once", "step", "week", - }, - "_input", "text", "name", "name", "value", "@key", - "_input", "text", "name", "text", "value", "@key", - "_input", "text", "name", "extra.cmds", - "_input", "text", "name", "extra.args", - "_input", "text", "name", "begin_time", "value", "@date", - "_input", "text", "name", "close_time", "value", "@date", -) - const ( TASK = "task" PLAN = "plan" @@ -308,10 +292,8 @@ var Index = &ice.Context{Name: "team", Help: "团队中心", }}, ice.CTX_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { m.Save(TASK) }}, - TASK: {Name: "task zone=auto id=auto auto 添加:button 导出:button 导入:button", Help: "任务", Meta: kit.Dict( - "添加", _task_inputs, - ), Action: map[string]*ice.Action{ - mdb.INSERT: {Name: "insert [key value]...", Help: "添加", Hand: func(m *ice.Message, arg ...string) { + TASK: {Name: "task zone=auto id=auto auto 添加:button 导出:button 导入:button", Help: "任务", Action: map[string]*ice.Action{ + mdb.INSERT: {Name: "insert zone type=once,step,week name text begin_time@date close_time@date", Help: "添加", Hand: func(m *ice.Message, arg ...string) { _task_create(m, arg[1]) _task_insert(m, arg[1], arg[2:]...) }}, @@ -348,26 +330,24 @@ var Index = &ice.Context{Name: "team", Help: "团队中心", }, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { if _task_list(m, kit.Select("", arg, 0), kit.Select("", arg, 1)); len(arg) < 2 { m.Table(func(index int, value map[string]string, head []string) { - m.Push("action", _task_action(m, value[STATUS])) + m.PushAction(_task_action(m, value[STATUS])) }) } else { m.Table(func(index int, value map[string]string, head []string) { if value["key"] == "status" { m.Push("key", "action") - m.Push("value", _task_action(m, value["value"])) } }) } }}, - PLAN: {Name: "plan scale:select=day|week|month|year|long begin_time@date auto 添加:button 导出:button 导入:button 筛选:button", Help: "计划", Meta: kit.Dict( + PLAN: {Name: "plan scale=day,week,month,year,long begin_time@date auto 添加 导出 导入", Help: "计划", Meta: kit.Dict( "display", "/plugin/local/team/plan.js", "style", "plan", - "添加", _task_inputs, ), Action: map[string]*ice.Action{ - mdb.INSERT: {Name: "insert [key value]...", Help: "添加", Hand: func(m *ice.Message, arg ...string) { + mdb.INSERT: {Name: "insert zone type=once,step,week name text begin_time@date close_time@date", Help: "添加", Hand: func(m *ice.Message, arg ...string) { _task_create(m, arg[1]) _task_insert(m, arg[1], arg[2:]...) }}, - mdb.MODIFY: {Name: "modify key value", Help: "编辑", Hand: func(m *ice.Message, arg ...string) { + mdb.MODIFY: {Name: "modify", Help: "编辑", Hand: func(m *ice.Message, arg ...string) { _task_modify(m, m.Option(kit.MDB_ZONE), m.Option(kit.MDB_ID), arg[0], arg[1]) }}, mdb.DELETE: {Name: "delete", Help: "删除", Hand: func(m *ice.Message, arg ...string) { @@ -379,6 +359,9 @@ var Index = &ice.Context{Name: "team", Help: "团队中心", mdb.IMPORT: {Name: "import file", Help: "导入", Hand: func(m *ice.Message, arg ...string) { _task_import(m, kit.Select(path.Join(EXPORT, m.Option(ice.MSG_DOMAIN), "list.csv"))) }}, + mdb.INPUTS: {Name: "inputs", Help: "补全", Hand: func(m *ice.Message, arg ...string) { + _task_input(m, kit.Select("", arg, 0), kit.Select("", arg, 1)) + }}, gdb.BEGIN: {Name: "begin", Help: "开始", Hand: func(m *ice.Message, arg ...string) { _task_modify(m, m.Option(kit.MDB_ZONE), m.Option(kit.MDB_ID), STATUS, StatusProcess) @@ -394,12 +377,8 @@ var Index = &ice.Context{Name: "team", Help: "团队中心", } m.Cmdy(arg[0], arg[1:]) }}, - "input": {Name: "input key value", Help: "补全", Hand: func(m *ice.Message, arg ...string) { - _task_input(m, kit.Select("", arg, 0), kit.Select("", arg, 1)) - }}, }, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { begin_time, end_time := _task_scope(m, arg...) - m.Logs("info", "begin", begin_time, "end", end_time) m.Set(ice.MSG_OPTION, "end_time") m.Set(ice.MSG_OPTION, "begin_time") @@ -410,7 +389,7 @@ var Index = &ice.Context{Name: "team", Help: "团队中心", if begin_time.Before(begin) && begin.Before(end_time) { m.Push(zone, value) m.Push(kit.MDB_ZONE, zone) - m.Push("action", _task_action(m, value[STATUS], "插件")) + m.PushAction(_task_action(m, value[STATUS], "插件")) } }) }) diff --git a/go.sum b/go.sum index 5dd748bf..4e889416 100644 --- a/go.sum +++ b/go.sum @@ -46,6 +46,8 @@ github.com/shylinux/toolkits v0.1.6 h1:x+Bs+oijuS11TWGAsdCEgwDbCS35uJvnP4jYDETJq github.com/shylinux/toolkits v0.1.6/go.mod h1:Y68Ot6xOmo1bun67YvqC3chDGeU2gDxtsUnvVDGJm4g= github.com/shylinux/toolkits v0.1.7 h1:RDUpZNTgnob6vaKJvJgNVaDE2UZRURjLG4StpSaAWF8= github.com/shylinux/toolkits v0.1.7/go.mod h1:Y68Ot6xOmo1bun67YvqC3chDGeU2gDxtsUnvVDGJm4g= +github.com/shylinux/toolkits v0.1.8 h1:Lh5HkR1aRzhOOVu9eHwZ5y7dfW7hcFy29IR5tQ5qUeM= +github.com/shylinux/toolkits v0.1.8/go.mod h1:Y68Ot6xOmo1bun67YvqC3chDGeU2gDxtsUnvVDGJm4g= github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e h1:MRM5ITcdelLK2j1vwZ3Je0FKVCfqOLp5zO6trqMLYs0= github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e/go.mod h1:XV66xRDqSt+GTGFMVlhk3ULuV0y9ZmzeVGR4mloJI3M= github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ= diff --git a/misc/git/git.go b/misc/git/git.go index 2b4f3c34..a0cf3865 100644 --- a/misc/git/git.go +++ b/misc/git/git.go @@ -3,7 +3,6 @@ package git import ( ice "github.com/shylinux/icebergs" "github.com/shylinux/icebergs/base/cli" - "github.com/shylinux/icebergs/base/mdb" "github.com/shylinux/icebergs/base/nfs" "github.com/shylinux/icebergs/base/web" "github.com/shylinux/icebergs/core/code" @@ -11,30 +10,9 @@ import ( "os" "path" - "strings" - "sync" - "time" ) -func _repos_insert(m *ice.Message, name string, dir string) { - if s, e := os.Stat(m.Option(cli.CMD_DIR, path.Join(dir, ".git"))); e == nil && s.IsDir() { - ls := strings.SplitN(strings.Trim(m.Cmdx(cli.SYSTEM, "git", "log", "-n1", `--pretty=format:"%ad %s"`, "--date=iso"), "\""), " ", 4) - m.Rich(REPOS, nil, kit.Data( - "name", name, "path", dir, - "last", kit.Select("", ls, 3), "time", strings.Join(ls[:2], " "), - "branch", strings.TrimSpace(m.Cmdx(cli.SYSTEM, "git", "branch")), - "remote", strings.TrimSpace(m.Cmdx(cli.SYSTEM, "git", "remote", "-v")), - )) - } -} - -const ( - GIT = "git" - REPOS = "repos" - TOTAL = "total" - TREND = "trend" - SPIDE = "spide" -) +const GIT = "git" var Index = &ice.Context{Name: GIT, Help: "代码库", Configs: map[string]*ice.Config{ @@ -46,16 +24,6 @@ var Index = &ice.Context{Name: GIT, Help: "代码库", "credential", kit.Dict("helper", "store"), ), )}, - REPOS: {Name: REPOS, Help: "仓库", Value: kit.Data( - kit.MDB_SHORT, kit.MDB_NAME, kit.MDB_FIELD, "time,name,branch,last", - "owner", "https://github.com/shylinux", - )}, - TOTAL: {Name: TOTAL, Help: "统计", Value: kit.Data( - kit.MDB_SHORT, kit.MDB_NAME, "skip", kit.Dict( - "wubi-dict", "true", "word-dict", "true", - ), - )}, - "progress": {Name: "progress", Help: "进度", Value: kit.Data()}, }, Commands: map[string]*ice.Command{ ice.CTX_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { @@ -92,337 +60,6 @@ var Index = &ice.Context{Name: GIT, Help: "代码库", }, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { m.Cmdy(code.INSTALL, path.Base(m.Conf(GIT, kit.META_SOURCE)), arg) }}, - - REPOS: {Name: "repos name=auto path=auto auto 添加", Help: "代码库", Action: map[string]*ice.Action{ - mdb.CREATE: {Name: `create remote branch name path`, Help: "添加", Hand: func(m *ice.Message, arg ...string) { - m.Option("name", kit.Select(strings.TrimSuffix(path.Base(m.Option("remote")), ".git"), m.Option("name"))) - m.Option("path", kit.Select(path.Join("usr", m.Option("name")), m.Option("path"))) - m.Option("remote", kit.Select(m.Conf(REPOS, "meta.owner")+"/"+m.Option("name"), m.Option("remote"))) - - if _, e := os.Stat(path.Join(m.Option("path"), ".git")); e != nil && os.IsNotExist(e) { - // 下载仓库 - if _, e := os.Stat(m.Option("path")); e == nil { - m.Option(cli.CMD_DIR, m.Option("path")) - m.Cmd(cli.SYSTEM, GIT, "init") - m.Cmd(cli.SYSTEM, GIT, "remote", "add", "origin", m.Option("remote")) - m.Cmd(cli.SYSTEM, GIT, "pull", "origin", "master") - } else { - m.Cmd(cli.SYSTEM, GIT, "clone", "-b", kit.Select("master", m.Option("branch")), - m.Option("remote"), m.Option("path")) - - } - _repos_insert(m, m.Option("name"), m.Option("path")) - } - }}, - }, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { - if len(arg) > 0 { - if wd, _ := os.Getwd(); arg[0] != path.Base(wd) { - m.Option(nfs.DIR_ROOT, path.Join("usr", arg[0])) - } - m.Cmdy(nfs.DIR, kit.Select("./", path.Join(arg[1:]...))) - return - } - - m.Option(mdb.FIELDS, m.Conf(REPOS, kit.META_FIELD)) - m.Cmdy(mdb.SELECT, m.Prefix(REPOS), "", mdb.HASH, kit.MDB_NAME, arg) - m.Sort(kit.MDB_NAME) - }}, - - TOTAL: {Name: "total name=auto auto", Help: "提交统计", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { - if len(arg) > 0 { - // 提交详情 - m.Richs(REPOS, nil, arg[0], func(key string, value map[string]interface{}) { - m.Cmdy("_sum", kit.Value(value, "meta.path"), arg[1:]) - }) - return - } - - // 提交统计 - days := 0 - commit, adds, dels, rest := 0, 0, 0, 0 - wg := &sync.WaitGroup{} - m.Richs(REPOS, nil, kit.MDB_FOREACH, func(key string, value map[string]interface{}) { - if m.Conf(TOTAL, kit.Keys("meta.skip", kit.Value(value, "meta.name"))) == "true" { - return - } - wg.Add(1) - m.Gos(m, func(m *ice.Message) { - msg := m.Cmd("_sum", kit.Value(value, "meta.path"), "total", "10000").Table(func(index int, value map[string]string, head []string) { - if kit.Int(value["days"]) > days { - days = kit.Int(value["days"]) - } - commit += kit.Int(value["commit"]) - adds += kit.Int(value["adds"]) - dels += kit.Int(value["dels"]) - rest += kit.Int(value["rest"]) - }) - m.Push("name", kit.Value(value, "meta.name")) - m.Copy(msg) - wg.Done() - }) - }) - wg.Wait() - m.Push("name", "total") - m.Push("days", kit.Int(days)+1) - m.Push("commit", commit) - m.Push("adds", adds) - m.Push("dels", dels) - m.Push("rest", rest) - m.Sort("rest", "int_r") - }}, - "_sum": {Name: "_sum [path] [total] [count|date] args...", Help: "统计", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { - if len(arg) > 0 { - if s, e := os.Stat(arg[0] + "/.git"); e == nil && s.IsDir() { - m.Option(cli.CMD_DIR, arg[0]) - arg = arg[1:] - } - } - - total := false - if len(arg) > 0 && arg[0] == "total" { - total, arg = true, arg[1:] - } - - args := []string{} - args = append(args, "log", kit.Format("--author=%s\\|shylinux", m.Option(ice.MSG_USERNAME)), "--shortstat", "--pretty=commit: %ad %n%s", "--date=iso", "--reverse") - if len(arg) > 0 { - args = append(args, kit.Select("-n", "--since", strings.Contains(arg[0], "-"))) - if strings.Contains(arg[0], "-") && !strings.Contains(arg[0], ":") { - arg[0] = arg[0] + " 00:00:00" - } - args = append(args, arg[0:]...) - } else { - args = append(args, "-n", "30") - } - - var total_day time.Duration - count, count_add, count_del := 0, 0, 0 - for i, v := range strings.Split(m.Cmdx(cli.SYSTEM, "git", args), "commit: ") { - if i > 0 { - l := strings.Split(v, "\n") - hs := strings.Split(l[0], " ") - - add, del := "0", "0" - if len(l) > 3 { - fs := strings.Split(strings.TrimSpace(l[3]), ", ") - if adds := strings.Split(fs[1], " "); len(fs) > 2 { - dels := strings.Split(fs[2], " ") - add = adds[0] - del = dels[0] - // } else if adds[1] == "insertions(+)" { - } else if strings.Contains(adds[1], "insertion") { - add = adds[0] - } else { - del = adds[0] - } - } - - if total { - if count++; i == 1 { - if t, e := time.Parse("2006-01-02", hs[0]); e == nil { - total_day = time.Now().Sub(t) - m.Append("from", hs[0]) - } - } - count_add += kit.Int(add) - count_del += kit.Int(del) - continue - } - - m.Push("date", hs[0]) - m.Push("adds", add) - m.Push("dels", del) - m.Push("rest", kit.Int(add)-kit.Int(del)) - m.Push("note", l[1]) - m.Push("hour", strings.Split(hs[1], ":")[0]) - m.Push("time", hs[1]) - } - } - if total { - m.Push("days", int(total_day.Hours())/24) - m.Push("commit", count) - m.Push("adds", count_add) - m.Push("dels", count_del) - m.Push("rest", count_add-count_del) - } - }}, - TREND: {Name: "trend name=auto begin_time=@date auto", Help: "趋势图", Meta: kit.Dict( - "display", "/plugin/story/trend.js", - ), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { - if len(arg) == 0 { - m.Option("_display", "table") - } - m.Cmdy(TOTAL, arg) - }}, - SPIDE: {Name: "spide path=auto file=auto auto", Help: "结构图", Meta: kit.Dict( - "display", "/plugin/story/spide.js", - ), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { - if len(arg) == 0 { - // 仓库列表 - m.Option("_display", "table") - m.Cmdy(TOTAL, arg) - return - } - if len(arg) == 1 { - // 目录列表 - m.Option(nfs.DIR_DEEP, "true") - m.Cmdy(nfs.DIR, mdb.RENDER, nfs.DIR, "", path.Join("usr", arg[0])) - return - } - - if len(arg) > 1 && arg[0] == "inner" { - // 代码详情 - arg[1] = path.Join("usr", arg[1]) - m.Cmdy("web.code.inner", arg[1:]) - return - } - - tags := "" - m.Option(cli.CMD_DIR, path.Join("usr", arg[0])) - if strings.HasSuffix(arg[1], ".go") { - tags = m.Cmdx(cli.SYSTEM, "gotags", arg[1]) - for _, line := range strings.Split(tags, "\n") { - if len(line) == 0 || strings.HasPrefix(line, "!_") { - continue - } - - ls := kit.Split(line, "\t ", "\t ", "\t ") - name := ls[3] + ":" + ls[0] - switch ls[3] { - case "m": - if strings.HasPrefix(ls[5], "ctype") { - name = strings.TrimPrefix(ls[5], "ctype:") + ":" + ls[0] - } else if strings.HasPrefix(ls[6], "ntype") { - name = "-" + ls[0] - } else { - - } - case "w": - t := ls[len(ls)-1] - name = "-" + ls[0] + ":" + strings.TrimPrefix(t, "type:") - } - - m.Push("name", name) - m.Push("file", ls[1]) - m.Push("line", strings.TrimSuffix(ls[2], ";\"")) - m.Push("type", ls[3]) - m.Push("extra", strings.Join(ls[4:], " ")) - } - } else { - tags = m.Cmdx(cli.SYSTEM, "ctags", "-f", "-", arg[1]) - for _, line := range strings.Split(tags, "\n") { - if len(line) == 0 || strings.HasPrefix(line, "!_") { - continue - } - - ls := kit.Split(line, "\t ", "\t ", "\t ") - m.Push("name", ls[0]) - m.Push("file", ls[1]) - m.Push("line", "1") - } - } - m.Sort("line", "int") - }}, - - "status": {Name: "status name=auto auto 提交 编译 下载", Help: "代码状态", Action: map[string]*ice.Action{ - "pull": {Name: "pull", Help: "下载", Hand: func(m *ice.Message, arg ...string) { - if m.Richs("progress", "", m.Option("_progress"), func(key string, value map[string]interface{}) { - m.Push("count", value["count"]) - m.Push("total", value["total"]) - m.Push("name", value["name"]) - }) != nil { - return - } - - count, total := 0, len(m.Confm(REPOS, "hash")) - h := m.Rich("progress", "", kit.Dict("progress", 0, "count", count, "total", total)) - m.Gos(m, func(m *ice.Message) { - m.Richs(REPOS, nil, kit.Select(kit.MDB_FOREACH, arg, 0), func(key string, value map[string]interface{}) { - count++ - m.Conf("progress", kit.Keys("hash", h, "name"), kit.Value(value, "meta.name")) - m.Conf("progress", kit.Keys("hash", h, "count"), count) - m.Conf("progress", kit.Keys("hash", h, "progress"), count*100/total) - m.Option(cli.CMD_DIR, kit.Value(value, "meta.path")) - m.Echo(m.Cmdx(cli.SYSTEM, GIT, "pull")) - }) - }) - m.Option("_progress", h) - m.Push("count", count) - m.Push("total", total) - m.Push("name", "") - }}, - "compile": {Name: "compile", Help: "编译", Hand: func(m *ice.Message, arg ...string) { - m.Cmdy(cli.SYSTEM, "make") - }}, - - "add": {Name: "add", Help: "添加", Hand: func(m *ice.Message, arg ...string) { - if strings.Contains(m.Option("name"), ":\\") { - m.Option(cli.CMD_DIR, m.Option("name")) - } else { - m.Option(cli.CMD_DIR, path.Join("usr", m.Option("name"))) - } - m.Cmdy(cli.SYSTEM, "git", "add", m.Option("file")) - }}, - "submit": {Name: "submit action=opt,add comment=some", Help: "提交", Hand: func(m *ice.Message, arg ...string) { - if m.Option("name") == "" { - return - } - - if strings.Contains(m.Option("name"), ":\\") { - m.Option(cli.CMD_DIR, m.Option("name")) - } else { - m.Option(cli.CMD_DIR, path.Join("usr", m.Option("name"))) - } - - if arg[0] == "action" { - m.Cmdy(cli.SYSTEM, "git", "commit", "-am", kit.Select("opt some", arg[1]+" "+arg[3])) - } else { - m.Cmdy(cli.SYSTEM, "git", "commit", "-am", kit.Select("opt some", strings.Join(arg, " "))) - } - }}, - "push": {Name: "push", Help: "上传", Hand: func(m *ice.Message, arg ...string) { - if m.Option("name") == "" { - return - } - if strings.Contains(m.Option("name"), ":\\") { - m.Option(cli.CMD_DIR, m.Option("name")) - } else { - m.Option(cli.CMD_DIR, path.Join("usr", m.Option("name"))) - } - m.Cmdy(cli.SYSTEM, "git", "push") - }}, - }, Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { - m.Richs(REPOS, nil, kit.Select(kit.MDB_FOREACH, arg, 0), func(key string, value map[string]interface{}) { - if m.Option(cli.CMD_DIR, kit.Value(value, "meta.path")); len(arg) > 0 { - // 更改详情 - m.Echo(m.Cmdx(cli.SYSTEM, GIT, "diff")) - return - } - - // 更改列表 - for _, v := range strings.Split(strings.TrimSpace(m.Cmdx(cli.SYSTEM, GIT, "status", "-sb")), "\n") { - vs := strings.SplitN(strings.TrimSpace(v), " ", 2) - m.Push("name", kit.Value(value, "meta.name")) - m.Push("tags", vs[0]) - m.Push("file", vs[1]) - list := []string{} - switch vs[0] { - case "##": - if strings.Contains(vs[1], "ahead") { - list = append(list, m.Cmdx(mdb.RENDER, web.RENDER.Button, "上传")) - } - default: - if strings.Contains(vs[0], "??") { - list = append(list, m.Cmdx(mdb.RENDER, web.RENDER.Button, "添加")) - } else { - list = append(list, m.Cmdx(mdb.RENDER, web.RENDER.Button, "提交")) - } - } - m.Push("action", strings.Join(list, "")) - } - }) - m.Sort("name") - }}, }, } diff --git a/misc/vim/vim.shy b/misc/vim/vim.shy index 243a2aa6..14c0cd23 100644 --- a/misc/vim/vim.shy +++ b/misc/vim/vim.shy @@ -32,18 +32,11 @@ field "输入法" web.code.vim.input field "收藏夹" web.code.vim.favor field "同步流" web.code.vim.sync -chapter "配置" - -refer ` -启动脚本 https://github.com/shylinux/contexts/blob/master/etc/conf/vimrc -` -field "启动脚本" web.code.inner args `[ https://raw.githubusercontent.com/shylinux/contexts/master/etc/conf/ vimrc ]` - chapter "插件" -refer ` -插件管理器 https://github.com/junegunn/vim-plug/plug.vim -` -field "插件管理器" web.code.inner args `[ https://raw.githubusercontent.com/shylinux/contexts/master/etc/conf/ plug.vim ]` +field "插件管理器" web.code.inner args `[ usr/intshell/misc/vim/ plug.vim ]` + +chapter "配置" +field "启动脚本" web.code.inner args `[ usr/intshell/misc/vim/ vimrc ]` section "状态栏" refer ` diff --git a/misc/zsh/sess.go b/misc/zsh/sess.go index 86212b9c..d4b028ed 100644 --- a/misc/zsh/sess.go +++ b/misc/zsh/sess.go @@ -7,7 +7,6 @@ import ( "github.com/shylinux/icebergs/base/web" kit "github.com/shylinux/toolkits" - "fmt" "io/ioutil" "strings" ) @@ -26,19 +25,10 @@ func init() { Configs: map[string]*ice.Config{ SESS: {Name: SESS, Help: "会话流", Value: kit.Data( kit.MDB_FIELD, "time,hash,status,username,hostname,pid,pwd", - "contexts", `export ctx_dev={{.Option "httphost"}} ctx_temp=$(mktemp); curl -sL $ctx_dev >$ctx_temp; source $ctx_temp`, )}, }, Commands: map[string]*ice.Command{ SESS: {Name: "sess hash auto 清理", Help: "会话流", Action: map[string]*ice.Action{ - "contexts": {Name: "contexts", Help: "环境", Hand: func(m *ice.Message, arg ...string) { - u := kit.ParseURL(m.Option(ice.MSG_USERWEB)) - m.Option("httphost", fmt.Sprintf("%s://%s:%s", u.Scheme, strings.Split(u.Host, ":")[0], kit.Select(kit.Select("80", "443", u.Scheme == "https"), strings.Split(u.Host, ":"), 1))) - - if buf, err := kit.Render(m.Conf(m.Prefix(SESS), "meta.contexts"), m); m.Assert(err) { - m.Cmdy("web.wiki.spark", "shell", string(buf)) - } - }}, mdb.PRUNES: {Name: "prunes", Help: "清理", Hand: func(m *ice.Message, arg ...string) { m.Cmdy(mdb.PRUNES, m.Prefix(SESS), "", mdb.HASH, kit.MDB_STATUS, "logout") }}, diff --git a/type.go b/type.go index b8e85ced..8ab7eed8 100644 --- a/type.go +++ b/type.go @@ -174,6 +174,9 @@ func (c *Context) _split(name string) []interface{} { if value = kit.Select("", ls, i+1); len(ls) > i+1 && strings.Contains(ls[i+1], ",") { kit.Value(item, kit.MDB_INPUT, "select") kit.Value(item, "values", strings.Split(ls[i+1], ",")) + if kit.Value(item, kit.MDB_NAME) == "scale" { + kit.Value(item, kit.MDB_VALUE, "week") + } } else { kit.Value(item, kit.MDB_VALUE, value) }