forked from x/icebergs
add wiki.stack
This commit is contained in:
parent
18471d558d
commit
fca601e255
@ -896,7 +896,7 @@ var Index = &ice.Context{Name: "web", Help: "网络模块",
|
||||
m.Push("favor", kit.Value(value, "meta.name"))
|
||||
m.Push("count", kit.Value(value, "meta.count"))
|
||||
})
|
||||
m.Sort("time", "time_r")
|
||||
m.Sort("favor")
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -83,7 +83,7 @@ endfun
|
||||
fun! ShyGrep(word)
|
||||
if !exists("g:grep_dir") | let g:grep_dir = "./" | endif
|
||||
let g:grep_dir = input("dir: ", g:grep_dir, "file")
|
||||
execute "grep -rn --exclude tags --exclude '*.tags' " . a:word . " " . g:grep_dir
|
||||
execute "grep -rn --exclude tags --exclude '*.tags' '\<" . a:word . "\>' " . g:grep_dir
|
||||
endfun
|
||||
fun! ShyTag(word)
|
||||
execute "tag " . a:word
|
||||
|
@ -49,6 +49,14 @@ var Index = &ice.Context{Name: "code", Help: "编程中心",
|
||||
m.Cmd(ice.CTX_CONFIG, "load", "code.json")
|
||||
m.Watch(ice.SYSTEM_INIT, "compile", "linux")
|
||||
m.Watch(ice.SYSTEM_INIT, "publish", "bin/ice.sh")
|
||||
|
||||
if m.Richs(ice.WEB_FAVOR, nil, "auto.init", nil) == nil {
|
||||
m.Cmd(ice.WEB_FAVOR, "auto.init", ice.TYPE_SHELL, "下载脚本", `curl -s "$ctx_dev/publish/auto.sh" -o auto.sh`)
|
||||
m.Cmd(ice.WEB_FAVOR, "auto.init", ice.TYPE_SHELL, "加载脚本", `source auto.sh`)
|
||||
}
|
||||
if m.Richs(ice.WEB_FAVOR, nil, "ice.init", nil) == nil {
|
||||
m.Cmd(ice.WEB_FAVOR, "ice.init", ice.TYPE_SHELL, "一键启动", `curl -s "$ctx_dev/publish/ice.sh" |sh`)
|
||||
}
|
||||
}},
|
||||
ice.ICE_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
m.Cmd(ice.CTX_CONFIG, "save", "code.json", "web.code.login")
|
||||
@ -71,6 +79,7 @@ var Index = &ice.Context{Name: "code", Help: "编程中心",
|
||||
m.Add("option", "cmd_env", "GOCACHE", os.Getenv("GOCACHE"))
|
||||
m.Add("option", "cmd_env", "GOARCH", arch, "GOOS", goos)
|
||||
m.Add("option", "cmd_env", "HOME", os.Getenv("HOME"))
|
||||
m.Add("option", "cmd_env", "CGO_ENABLED", "0")
|
||||
m.Cmd("cli.system", "go", "build", "-o", file, main)
|
||||
|
||||
// 编译记录
|
||||
|
@ -273,3 +273,30 @@ func (b *Table) Draw(m *ice.Message, x, y int) Chart {
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
func stack(m *ice.Message, name string, level int, data interface{}) {
|
||||
l, ok := kit.Value(data, "list").([]interface{})
|
||||
style := []string{}
|
||||
kit.Fetch(kit.Value(data, "meta"), func(key string, value string) {
|
||||
switch key {
|
||||
case "bg":
|
||||
style = append(style, "background:"+value)
|
||||
case "fg":
|
||||
style = append(style, "color:"+value)
|
||||
}
|
||||
})
|
||||
if !ok || len(l) == 0 {
|
||||
m.Echo(`<div class="%s" style="%s"><span class="state">o</span> %s</div>`, name, strings.Join(style, ";"), kit.Value(data, "meta.text"))
|
||||
return
|
||||
}
|
||||
m.Echo(`<div class="%s %s" style="%s"><span class="state">%s</span> %s</div>`,
|
||||
kit.Select("span", "fold", level > 2), name, strings.Join(style, ";"), kit.Select("v", ">", level > 2), kit.Value(data, "meta.text"))
|
||||
|
||||
m.Echo("<ul class='%s' %s>", name, kit.Select("", `style="display:none"`, level > 2))
|
||||
kit.Fetch(kit.Value(data, "list"), func(index int, value map[string]interface{}) {
|
||||
m.Echo("<li>")
|
||||
stack(m, name, level+1, value)
|
||||
m.Echo("</li>")
|
||||
})
|
||||
m.Echo("</ul>")
|
||||
}
|
||||
|
@ -8,7 +8,8 @@ data-type="{{.Option "type"}}" data-name="{{.Option "name"}}" data-text="{{.Opti
|
||||
var spark = `<p>{{.}}</p>`
|
||||
|
||||
var shell = `<div class="story code" data-type="{{.Option "type"}}" data-name="{{.Option "name"}}" data-text="{{.Option "input"}}">$ {{.Option "input"}}
|
||||
{{.Option "output"}}</div>`
|
||||
{{.Option "output"}}</div>
|
||||
`
|
||||
|
||||
var order = `<ul class="story"
|
||||
data-type="{{.Option "type"}}" data-name="{{.Option "name"}}" data-text="{{.Option "text"}}">
|
||||
|
@ -51,11 +51,9 @@ var Index = &ice.Context{Name: "wiki", Help: "文档中心",
|
||||
var chart Chart
|
||||
switch arg[0] {
|
||||
case "block":
|
||||
chart = &Block{}
|
||||
chart = &Table{}
|
||||
case "chain":
|
||||
chart = &Chain{}
|
||||
case "table":
|
||||
chart = &Table{}
|
||||
}
|
||||
arg[1] = strings.TrimSpace(arg[1])
|
||||
arg[2] = strings.TrimSpace(arg[2])
|
||||
@ -73,6 +71,11 @@ var Index = &ice.Context{Name: "wiki", Help: "文档中心",
|
||||
chart.Draw(m, 0, 0)
|
||||
m.Render(m.Conf("chart", ice.Meta("suffix")))
|
||||
}},
|
||||
"stack": {Name: "stack name text", Help: "堆栈", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
chain := &Chain{}
|
||||
m.Render(m.Conf("spark", ice.Meta("template")), arg[0])
|
||||
stack(m, "stack", 0, kit.Parse(nil, "", chain.show(m, arg[1])...))
|
||||
}},
|
||||
"table": {Name: "table name text", Help: "表格", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
m.Option("type", "table")
|
||||
m.Option("name", arg[0])
|
||||
@ -101,13 +104,17 @@ var Index = &ice.Context{Name: "wiki", Help: "文档中心",
|
||||
m.Option("name", arg[0])
|
||||
m.Option("cmd_dir", arg[1])
|
||||
|
||||
input, output := "", ""
|
||||
switch arg = arg[2:]; arg[0] {
|
||||
case "install", "compile":
|
||||
m.Option("input", html.EscapeString(strings.Join(arg[1:], " ")))
|
||||
input = strings.Join(arg[1:], " ")
|
||||
default:
|
||||
m.Option("input", html.EscapeString(strings.Join(arg, " ")))
|
||||
m.Option("output", html.EscapeString(m.Cmdx("cli.system", "sh", "-c", strings.Join(arg, " "))))
|
||||
input = strings.Join(arg, " ")
|
||||
output = m.Cmdx("cli.system", "sh", "-c", strings.Join(arg, " "))
|
||||
}
|
||||
|
||||
m.Option("input", html.EscapeString(input))
|
||||
m.Option("output", html.EscapeString(output))
|
||||
m.Render(m.Conf("spark", ice.Meta("template")), m.Option("name"))
|
||||
m.Render(m.Conf("shell", ice.Meta("template")))
|
||||
}},
|
||||
|
@ -13,7 +13,13 @@ var Index = &ice.Context{Name: "docker", Help: "容器管理",
|
||||
"docker": {Name: "docker", Help: "docker", Value: kit.Data(kit.MDB_SHORT, "name")},
|
||||
},
|
||||
Commands: map[string]*ice.Command{
|
||||
ice.ICE_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {}},
|
||||
ice.ICE_INIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
if m.Richs(ice.WEB_FAVOR, nil, "alpine.init", nil) == nil {
|
||||
m.Cmd(ice.WEB_FAVOR, "alpine.init", ice.TYPE_SHELL, "镜像源", `sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories`)
|
||||
m.Cmd(ice.WEB_FAVOR, "alpine.init", ice.TYPE_SHELL, "软件包", `apk add bash`)
|
||||
m.Cmd(ice.WEB_FAVOR, "alpine.init", ice.TYPE_SHELL, "软件包", `apk add curl`)
|
||||
}
|
||||
}},
|
||||
ice.ICE_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {}},
|
||||
|
||||
"image": {Name: "image", Help: "镜像管理", Meta: kit.Dict("detail", []string{"运行", "清理", "删除"}), Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
@ -48,8 +54,12 @@ var Index = &ice.Context{Name: "docker", Help: "容器管理",
|
||||
if len(arg) > 2 {
|
||||
switch arg[1] {
|
||||
case "进入":
|
||||
m.Cmdy(ice.CLI_SYSTEM, "tmux", "new-window", "-t", "", "-n", m.Option("NAMES"),
|
||||
"-PF", "#{session_name}:#{window_name}.1", "docker exec -it "+m.Option("NAMES")+" sh").Set("append")
|
||||
m.Cmd("cli.tmux.session").Table(func(index int, value map[string]string, head []string) {
|
||||
if value["tag"] == "1" {
|
||||
m.Cmdy(ice.CLI_SYSTEM, "tmux", "new-window", "-t", value["session"], "-n", m.Option("NAMES"),
|
||||
"-PF", "#{session_name}:#{window_name}.1", "docker exec -it "+m.Option("NAMES")+" sh").Set("append")
|
||||
}
|
||||
})
|
||||
return
|
||||
case "停止":
|
||||
m.Cmd(prefix, "stop", m.Option("CONTAINER_ID"))
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"github.com/shylinux/icebergs"
|
||||
"github.com/shylinux/icebergs/base/cli"
|
||||
"github.com/shylinux/toolkits"
|
||||
|
||||
"os"
|
||||
"path"
|
||||
"strings"
|
||||
@ -44,8 +45,7 @@ var Index = &ice.Context{Name: "git", Help: "代码管理",
|
||||
})
|
||||
m.Watch(ice.SYSTEM_INIT, "cli.git.check", "volcanos")
|
||||
}},
|
||||
ice.ICE_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
}},
|
||||
ice.ICE_EXIT: {Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {}},
|
||||
"repos": {Name: "repos", Help: "仓库", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
m.Richs("repos", nil, "*", func(key string, value map[string]interface{}) {
|
||||
m.Push(key, value["meta"], []string{"time", "name", "branch", "path", "remote"})
|
||||
@ -62,6 +62,7 @@ var Index = &ice.Context{Name: "git", Help: "代码管理",
|
||||
m.Push("tags", v[:2])
|
||||
vs := strings.SplitN(strings.TrimSpace(v[2:]), " ", 2)
|
||||
m.Push("branch", vs[0])
|
||||
m.Push("last", m.Cmdx(ice.CLI_SYSTEM, "git", "log", "-n", "1", "--pretty=%ad", "--date=short"))
|
||||
vs = strings.SplitN(strings.TrimSpace(vs[1]), " ", 2)
|
||||
m.Push("hash", vs[0])
|
||||
m.Push("note", strings.TrimSpace(vs[1]))
|
||||
@ -87,7 +88,7 @@ var Index = &ice.Context{Name: "git", Help: "代码管理",
|
||||
commit, adds, dels, rest := 0, 0, 0, 0
|
||||
m.Richs("repos", nil, kit.Select("*", arg, 0), func(key string, value map[string]interface{}) {
|
||||
m.Push("repos", kit.Value(value, "meta.name"))
|
||||
m.Copy(m.Cmd("sum", "total", kit.Value(value, "meta.path"), "10000").Table(func(index int, value map[string]string, head []string) {
|
||||
m.Copy(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"])
|
||||
}
|
||||
@ -103,7 +104,7 @@ var Index = &ice.Context{Name: "git", Help: "代码管理",
|
||||
m.Push("adds", adds)
|
||||
m.Push("dels", dels)
|
||||
m.Push("rest", rest)
|
||||
m.Sort("commit", "int_r")
|
||||
m.Sort("adds", "int_r")
|
||||
}},
|
||||
"check": {Name: "check", Help: "检查", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
m.Richs("repos", nil, arg[0], func(key string, value map[string]interface{}) {
|
||||
@ -113,19 +114,20 @@ var Index = &ice.Context{Name: "git", Help: "代码管理",
|
||||
}
|
||||
})
|
||||
}},
|
||||
"sum": {Name: "sum", Help: "统计", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) {
|
||||
"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("cmd_dir", arg[0])
|
||||
arg = arg[1:]
|
||||
}
|
||||
}
|
||||
|
||||
total := false
|
||||
if len(arg) > 0 && arg[0] == "total" {
|
||||
total, arg = true, arg[1:]
|
||||
}
|
||||
|
||||
args := []string{}
|
||||
if len(arg) > 0 {
|
||||
if s, e := os.Stat(arg[0] + "/.git"); e == nil && s.IsDir() {
|
||||
args, arg = append(args, "-C", arg[0]), arg[1:]
|
||||
}
|
||||
}
|
||||
|
||||
args = append(args, "log", "--shortstat", "--pretty=commit: %ad %n%s", "--date=iso", "--reverse")
|
||||
if len(arg) > 0 {
|
||||
args = append(args, kit.Select("-n", "--since", strings.Contains(arg[0], "-")))
|
||||
|
@ -69,14 +69,6 @@ var Index = &ice.Context{Name: "tmux", Help: "终端管理",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if m.Richs(ice.WEB_FAVOR, nil, "tmux.auto", nil) == nil {
|
||||
m.Cmd(ice.WEB_FAVOR, "tmux.auto", ice.TYPE_SHELL, "下载脚本", `curl -s "$ctx_dev/publish/auto.sh" -o auto.sh`)
|
||||
m.Cmd(ice.WEB_FAVOR, "tmux.auto", ice.TYPE_SHELL, "加载脚本", `source auto.sh`)
|
||||
}
|
||||
if m.Richs(ice.WEB_FAVOR, nil, "tmux.init", nil) == nil {
|
||||
m.Cmd(ice.WEB_FAVOR, "tmux.init", ice.TYPE_SHELL, "一键启动", `curl -s "$ctx_dev/publish/ice.sh" |sh`)
|
||||
}
|
||||
}},
|
||||
|
||||
"buffer": {Name: "buffer", Help: "终端",
|
||||
|
@ -1,4 +1,6 @@
|
||||
all:
|
||||
@echo && date
|
||||
export CGO_ENABLED=0
|
||||
export GOPRIVATE=github.com
|
||||
export GOPROXY=https://goproxy.cn
|
||||
go build -o bin/ice.bin src/main.go && chmod u+x bin/ice.bin && ./bin/ice.sh restart
|
||||
|
@ -34,6 +34,7 @@ END
|
||||
[ -f Makefile ] || cat >> Makefile <<END
|
||||
all:
|
||||
@echo && date
|
||||
export CGO_ENABLED=0
|
||||
export GOPRIVATE=github.com
|
||||
export GOPROXY=https://goproxy.cn
|
||||
go build -o ${ice_bin} ${main_go} && chmod u+x ${ice_bin} && ./${ice_sh} restart
|
||||
@ -54,7 +55,7 @@ export ctx_pid=\${ctx_pid:=var/run/ice.pid}
|
||||
export ctx_log=\${ctx_log:=bin/boot.log}
|
||||
|
||||
prepare() {
|
||||
[ -d etc ] || mkdir bin
|
||||
[ -d bin ] || mkdir bin
|
||||
[ -e ${ice_sh} ] || curl \$ctx_dev/publish/ice.sh -o ${ice_sh} && chmod u+x ${ice_sh}
|
||||
[ -e ${ice_bin} ] && chmod u+x ${ice_bin} && return
|
||||
|
||||
@ -93,6 +94,7 @@ END
|
||||
}
|
||||
|
||||
build() {
|
||||
export CGO_ENABLED=0
|
||||
export GOPRIVATE=github.com
|
||||
export GOPROXY=https://goproxy.cn
|
||||
go build -o ${ice_bin} ${main_go} && chmod u+x ${ice_bin} && ./${ice_sh} restart
|
||||
|
Loading…
x
Reference in New Issue
Block a user