1
0
forked from x/ContextOS

add code.favor

This commit is contained in:
shaoying 2019-11-15 01:14:12 +08:00
parent 0b3ba78603
commit dd3f62b90a
10 changed files with 391 additions and 387 deletions

View File

@ -62,13 +62,16 @@ ShyPost() {
${ctx_curl} "${ctx_url}" -H "${ctx_head}" -d "${data}"
}
ShyDownload() {
${ctx_curl} "${ctx_dev}/download/$1"
${ctx_curl} "${ctx_url}" -F "cmd=download" -F "arg=$1" -F "sid=$ctx_sid"
}
ShyUpdate() {
${ctx_curl} "${ctx_dev}/publish/$1" > $1
}
ShyUpload() {
${ctx_curl} "${ctx_dev}/upload" -F "upload=@$1"
${ctx_curl} "${ctx_url}" -F "cmd=upload" -F "sid=$ctx_sid" -F "upload=@$1"
}
ShyBench() {
${ctx_curl} "${ctx_dev}/publish/boot.sh" | sh -s installs context
}
ShySend() {
local TEMP=`mktemp /tmp/tmp.XXXXXX` && "$@" > $TEMP
@ -95,14 +98,15 @@ ShyLogin() {
echo "sid: ${ctx_sid:0:6}"
}
ShyFavor() {
[ "$READLINE_LINE" != "" ] && set $READLINE_LINE && READLINE_LINE=""
[ "$1" != "" ] && ctx_tab=$1
[ "$2" != "" ] && ctx_note=$2
ShyPost cmd favor arg "`history|tail -n2|head -n1`" tab "${ctx_tab}" note "${ctx_note}"
}
ShyFavors() {
echo -n "tab: " && read && [ "$REPLY" != "" ] && ctx_tab=$REPLY
echo -n "note: " && read && [ "$REPLY" != "" ] && ctx_tab=$REPLY
ShyFavor
[ "$READLINE_LINE" == "" ] && ShyPost cmd favor && return
ShyPost cmd favor >$READLINE_LINE
READLINE_LINE=""
}
ShySync() {
[ "$ctx_sid" = "" ] && ShyLogin
@ -167,11 +171,14 @@ ShyInit() {
;;
*)
PS1="\!-$$-\t[\u@\h]\W\$ "
PS1="\!-$$-\t\W\$ "
PS1="\e[32m\!\e[0m-$$-\e[31m$SPY_OWNER\e[0m@\e[33m$SPY_ROLE\e[0m[\e[32m\t\e[0m]\W\$ "
;;
esac
${ctx_bind} '"\C-t\C-t":ShySyncs base'
${ctx_bind} '"\C-g\C-r":ShySyncs base'
${ctx_bind} '"\C-g\C-f":ShyFavor'
${ctx_bind} '"\C-gf":ShyFavor'
${ctx_bind} '"\C-gF":ShyFavors'
echo ${ctx_welcome}
echo "url: ${ctx_url}"

View File

@ -13,40 +13,21 @@ fun! ShyPost(arg)
endfor
return system("curl -s '" . g:ctx_url . "' -H '" . g:ctx_head . "' -d '" . json_encode(a:arg) . "' 2>/dev/null")
endfun
fun! Shy(action, target)
let arg = {"arg": a:target, "cmd": a:action}
let cmd = ShyPost(arg)
if cmd != ""
let arg["res"] = execute(cmd)
let res = ShyPost(arg)
endif
endfun
fun! ShyLogout()
call Shy("logout", "")
let g:ctx_sid = ""
if g:ctx_sid != ""
let g:ctx_sid = ShyPost({"cmd": "logout"})
endif
endfun
fun! ShyLogin()
if g:ctx_sid == ""
let arg = {"cmd": "login", "pid": getpid(), "pane": $TMUX_PANE, "hostname": hostname(), "username": $USER}
let g:ctx_sid = ShyPost(arg)
let g:ctx_sid = ShyPost({"cmd": "login", "pid": getpid(), "pane": $TMUX_PANE, "hostname": hostname(), "username": $USER})
"hello
endif
endfun
if !exists("g:favor_tab") | let favor_tab = "" | endif
if !exists("g:favor_note") | let favor_note = "" | endif
fun! ShyFavor(note)
if a:note != ""
let g:favor_tab = input("tab: ", g:favor_tab)
let g:favor_note = input("note: ", g:favor_note)
endif
call ShyPost({"cmd": "favor", "tab": g:favor_tab, "note": g:favor_note, "arg": getline("."), "line": getpos(".")[1], "col": getpos(".")[2]})
endfun
fun! ShySync(target)
if bufname("%") == "ControlP"
return
end
if bufname("%") == "ControlP" | return | end
if a:target == "read" || a:target == "write"
call ShyPost({"cmd": a:target, "arg": expand("<afile>")})
@ -59,19 +40,8 @@ fun! ShySync(target)
call ShyPost({"cmd": "sync", "arg": a:target, "sub": execute(cmd[a:target])})
endif
endfun
fun! ShyCheck(target)
if a:target == "favor"
cexpr ShyPost({"cmd": "favor"})
elseif a:target == "favors"
let msg = json_decode(ShyPost({"cmd": "favors"}))
let i = 0
for i in range(len(msg["tab"]))
tabnew
lexpr msg["fix"][i]
lopen
endfor
elseif a:target == "cache"
if a:target == "cache"
call ShySync("bufs")
call ShySync("regs")
call ShySync("marks")
@ -97,27 +67,60 @@ fun! ShyCheck(target)
end
endfun
fun! ShyFavors()
let msg = json_decode(ShyPost({"cmd": "favors"}))
let i = 0
for i in range(len(msg["tab"]))
tabnew
lexpr msg["fix"][i]
lopen
endfor
endfun
fun! ShyFavor(note)
if !exists("g:favor_tab") | let g:favor_tab = "" | endif
if !exists("g:favor_note") | let g:favor_note = "" | endif
if a:note != ""
let g:favor_tab = input("tab: ", g:favor_tab)
let g:favor_note = input("note: ", g:favor_note)
endif
call ShyPost({"cmd": "favor", "tab": g:favor_tab, "note": g:favor_note, "arg": getline("."), "line": getpos(".")[1], "col": getpos(".")[2]})
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
endfun
fun! ShyTag(word)
execute "tag " . a:word
endfun
fun! ShyHelp()
echo ShyPost({"cmd": "help"})
endfun
call ShyLogin()
autocmd VimLeave * call ShyLogout()
autocmd InsertLeave * call ShySync("insert")
autocmd CmdlineLeave * call ShyCheck("exec")
autocmd BufReadPost * call Shy("read", expand("<afile>"))
autocmd BufReadPost * call ShySync("bufs")
autocmd BufWritePre * call Shy("write", expand("<afile>"))
autocmd QuickFixCmdPost * call ShyCheck("fixs")
" call ShySync("bufs")
call ShySync("regs")
call ShySync("marks")
call ShySync("tags")
" call ShySync("fixs")
"
nnoremap <C-R><C-R> :call ShyCheck("cache")<CR>
" nnoremap <C-R><C-F> :call ShyCheck("favor")<CR>
nnoremap <C-R><C-F> :call ShyFavor("note")<CR>
nnoremap <C-R>F :call ShyCheck("favors")<CR>
nnoremap <C-R>f :call ShyFavor("")<CR>
autocmd VimLeave * call ShyLogout()
autocmd BufReadPost * call ShySync("bufs")
autocmd BufReadPost * call ShySync("read")
autocmd BufWritePre * call ShySync("write")
autocmd CmdlineLeave * call ShyCheck("exec")
autocmd QuickFixCmdPost * call ShyCheck("fixs")
autocmd InsertLeave * call ShySync("insert")
command ShyHelp echo ShyPost({"cmd": "help"})
nnoremap <C-g><C-g> :call ShyGrep(expand("<cword>"))<CR>
nnoremap <C-g><C-t> :call ShyTag(expand("<cword>"))<CR>
nnoremap <C-g><C-r> :call ShyCheck("cache")<CR>
nnoremap <C-g><C-f> :call ShyFavor("note")<CR>
nnoremap <C-g>f :call ShyFavor("")<CR>
nnoremap <C-g>F :call ShyFavors()<CR>
" autocmd BufUnload * call Shy("close", expand("<afile>")) | call ShySync("bufs")
" autocmd CmdlineLeave *

View File

@ -161,7 +161,6 @@ if filereadable("~/.vim_local")
endif
cnoremap RR :source ~/.vimrc<CR>
nnoremap <C-G> :copen<CR> :grep -rn
colorscheme torte
highlight Comment cterm=reverse ctermfg=yellow

View File

@ -2,6 +2,7 @@
~code
config save var/tmp/vim/vim.json vim
config save var/tmp/zsh.json zsh
config save var/tmp/code.json login
# 系统配置
~ssh

View File

@ -18,6 +18,7 @@
# 应用配置
~code
config load tmp/code.json login
config load tmp/zsh.json zsh
config load tmp/vim/vim.json vim

View File

@ -553,14 +553,18 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
m.Cmdy("ssh.data", "save", arg[1])
case "update":
table, index, prefix, arg := arg[1], kit.Int(arg[2])-1, "", arg[3:]
if arg[0] == "extra" {
prefix, arg = "extra.", arg[1:]
}
for i := 0; i < len(arg)-1; i += 2 {
m.Confv("flow", []string{m.Option("river"), "data", table, "list", kit.Format(index), prefix + arg[i]}, arg[i+1])
index := kit.Int(arg[2]) - 1 - m.Confi("flow", []string{m.Option("river"), "data", arg[1], "meta", "offset"})
table, prefix, arg := arg[1], "", arg[3:]
if index >= 0 {
if arg[0] == "extra" {
prefix, arg = "extra.", arg[1:]
}
for i := 0; i < len(arg)-1; i += 2 {
m.Confv("flow", []string{m.Option("river"), "data", table, "list", kit.Format(index), prefix + arg[i]}, arg[i+1])
}
}
m.Cmdy("ssh.data", "show", table, index+1)
case "import":
if len(arg) < 3 {
m.Cmdy("ssh.data", "show", arg)

View File

@ -968,8 +968,9 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
kind := h.Header.Get("Content-Type")
kind = strings.Split(kind, "/")[0]
if m.Options("river") {
m.Cmd("ssh.data", "insert", kit.Select(kind, m.Option("table")),
"name", h.Filename, "kind", kind, "hash", name, "size", n)
prefix := []string{"ssh._route", m.Option("dream"), "ssh.data", "insert"}
m.Cmd(prefix, kit.Select(kind, m.Option("table")), "name", h.Filename, "kind", kind, "hash", name, "size", n)
m.Cmd(prefix, "file", "name", h.Filename, "kind", kind, "hash", name, "size", n)
}
buf := bytes.NewBuffer(make([]byte, 0, 1024))
@ -991,7 +992,15 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
m.Cmd("nfs.copy", path.Join(m.Conf("web.upload", "path"), kind, code), p)
}
}
if !strings.HasPrefix(m.Option("agent"), "curl") {
if strings.HasPrefix(m.Option("agent"), "favor") {
m.Append("code", code)
m.Append("hash", name)
m.Append("name", h.Filename)
m.Append("time", m.Time("2006-01-02 15:04"))
m.Append("type", kind)
m.Append("size", kit.FmtSize(n))
} else if !strings.HasPrefix(m.Option("agent"), "curl") {
m.Append("size", kit.FmtSize(n))
m.Append("link", fmt.Sprintf(`<a href="/download/%s" target="_blank">%s</a>`, code, h.Filename))
m.Append("type", kind)
@ -1014,7 +1023,7 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
w := m.Optionv("response").(http.ResponseWriter)
kind := kit.Select("meta", kit.Select(m.Option("meta"), arg, 0))
file := strings.TrimPrefix(key, "/download/")
file := kit.Select(strings.TrimPrefix(key, "/download/"), arg, 1)
// 文件列表
if file == "" {
if fs, e := ioutil.ReadDir(path.Join(m.Conf("web.upload", "path"), kind)); e == nil {

View File

@ -30,7 +30,9 @@ CMD sh bin/boot.sh
var Index = &ctx.Context{Name: "code", Help: "代码中心",
Caches: map[string]*ctx.Cache{},
Configs: map[string]*ctx.Config{
"login": {Name: "login", Value: map[string]interface{}{"check": false, "local": true, "expire": "720h"}, Help: "用户登录"},
"login": {Name: "login", Value: map[string]interface{}{"check": false, "local": true, "expire": "720h", "meta": map[string]interface{}{
"fields": "time sid type status table dream pwd pid pane hostname username",
}}, Help: "用户登录"},
"prefix": {Name: "prefix", Help: "外部命令", Value: map[string]interface{}{
"zsh": []interface{}{"cli.system", "zsh"},
"tmux": []interface{}{"cli.system", "tmux"},
@ -51,37 +53,30 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心",
"git": {Name: "git", Help: "记录", Value: map[string]interface{}{
"alias": map[string]interface{}{"s": "status", "b": "branch"},
}},
"zsh": {Name: "vim", Help: "记录", Value: map[string]interface{}{
"terminal": map[string]interface{}{"meta": map[string]interface{}{
"fields": "time sid status table dream pwd pid pane hostname username",
}},
"zsh": {Name: "zsh", Help: "命令行", Value: map[string]interface{}{
"history": map[string]interface{}{"meta": map[string]interface{}{
"fields": "time sid cmd pwd",
"store": "var/tmp/zsh.csv",
"store": "var/tmp/zsh/history.csv",
"limit": "30",
"least": "10",
}},
"free": map[string]interface{}{"meta": map[string]interface{}{
"fields": "time sid type total used free shared buffer available",
"store": "var/tmp/vim/opens.csv",
"store": "var/tmp/zsh/free.csv",
"limit": "30",
"least": "10",
}},
"df": map[string]interface{}{"meta": map[string]interface{}{
"fields": "fs size used rest per pos",
}},
"ps": map[string]interface{}{"meta": map[string]interface{}{
"fields": "PID TIME COMMAND",
}},
"env": map[string]interface{}{"meta": map[string]interface{}{
"fields": "sid name value",
}},
"ps": map[string]interface{}{"meta": map[string]interface{}{
"fields": "PID TIME COMMAND",
}},
"df": map[string]interface{}{"meta": map[string]interface{}{
"fields": "fs size used rest per pos",
}},
}},
"vim": {Name: "vim", Help: "编辑器", Value: map[string]interface{}{
"editor": map[string]interface{}{"meta": map[string]interface{}{
"fields": "time sid status table dream pwd pid pane hostname username",
}},
"favor": map[string]interface{}{},
"opens": map[string]interface{}{"meta": map[string]interface{}{
"fields": "time sid action file pwd",
"store": "var/tmp/vim/opens.csv",
@ -124,7 +119,181 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心",
}},
},
Commands: map[string]*ctx.Command{
"/zsh": {Name: "/zsh sid pwd cmd arg", Help: "终端", Hand: func(m *ctx.Message, c *ctx.Context, cmd string, arg ...string) (e error) {
"login": {Name: "login open|init|list|exit|quit", Help: "登录", Hand: func(m *ctx.Message, c *ctx.Context, cmd string, arg ...string) (e error) {
switch kit.Select("list", arg, 0) {
case "open":
case "init":
if m.Option("sid") != "" && m.Confs(cmd, []string{"hash", m.Option("sid")}) {
m.Echo(m.Option("sid"))
return
}
name := kit.Hashs(m.Option("pid"), m.Option("hostname"), m.Option("username"))
m.Conf(cmd, []string{"hash", name}, map[string]interface{}{
"time": m.Time(),
"type": kit.Select("vim", arg, 1),
"status": "login",
"pwd": m.Option("pwd"),
"pid": m.Option("pid"),
"pane": m.Option("pane"),
"hostname": m.Option("hostname"),
"username": m.Option("username"),
})
m.Echo(name)
case "list":
if len(arg) > 2 {
switch arg[2] {
case "prune":
m.Cmd(".prune", m.Conf("login", []string{"hash", arg[1], "type"}), arg[1])
arg = arg[:1]
}
}
if len(arg) > 3 && arg[3] != "" {
m.Conf(cmd, []string{"hash", arg[1], "dream"}, arg[3])
}
if len(arg) > 2 && arg[2] != "" {
m.Conf(cmd, []string{"hash", arg[1], "table"}, arg[2])
m.Conf(cmd, []string{"hash", arg[1], "river"}, m.Option("river"))
}
if len(arg) > 1 && arg[1] != "" {
m.Option("table.format", "table")
m.Confm(cmd, []string{"hash", arg[1]}, func(key string, value string) {
m.Push(key, value)
})
m.Sort("key")
break
}
fields := strings.Split(m.Conf(cmd, "meta.fields"), " ")
m.Confm(cmd, "hash", func(key string, value map[string]interface{}) {
value["sid"] = key
m.Push(fields, kit.Shortm(value, "times", "files", "sids"))
})
m.Table()
case "exit":
m.Conf(cmd, []string{"hash", m.Option("sid"), "status"}, "logout")
m.Conf(cmd, []string{"hash", m.Option("sid"), "time"}, m.Time())
case "quit":
}
return
}},
"favor": {Name: "favor post|list", Help: "收藏", Hand: func(m *ctx.Message, c *ctx.Context, cmd string, arg ...string) (e error) {
switch arg[0] {
case "download":
if len(arg) > 1 && arg[1] != "" {
m.Cmd("/download/", "", arg[1])
break
}
m.Cmd("ssh._route", m.Option("dream"), "ssh.data", "show", "file").Table(func(index int, value map[string]string) {
m.Echo("%v %v %v\n", value["hash"], kit.FmtSize(int64(kit.Int(value["size"]))), value["name"])
})
case "upload":
m.Option("agent", "favor")
if m.Cmd("/upload"); m.Options("dream") {
m.Cmd("ssh._route", m.Option("dream"), "web.get", "dev",
"/download/"+m.Append("hash"), "save", "usr/script/"+m.Append("name"))
}
m.Echo("code: %s\n", m.Append("code"))
m.Echo("hash: %s\n", m.Append("hash"))
m.Echo("time: %s\n", m.Append("time"))
m.Echo("type: %s\n", m.Append("type"))
m.Echo("size: %s\n", m.Append("size"))
m.Set("append")
case "file":
m.Cmd("ssh._route", arg[1], "ssh.data", "show", arg[2]).Table(func(index int, value map[string]string) {
m.Push("id", value["id"])
m.Push("kind", value["kind"])
m.Push("name", value["name"])
m.Push("size", kit.FmtSize(int64(kit.Int(value["size"]))))
m.Push("file", fmt.Sprintf(`<a href="/download/%s" target="_blank">%s</a>`, value["hash"], value["name"]))
m.Push("hash", value["hash"])
})
m.Table()
case "post":
m.Option("river", m.Conf("login", []string{"hash", m.Option("sid"), "river"}))
dream := m.Conf("login", []string{"hash", m.Option("sid"), "dream"})
table := kit.Select("tip", m.Conf("login", []string{"hash", m.Option("sid"), "table"}))
m.Log("info", "river: %v dream: %v table: %v", m.Option("river"), dream, table)
if prefix := []string{"ssh._route", dream, "ssh.data"}; len(arg) > 1 {
m.Cmdy(prefix, "insert", table, arg[1:])
} else {
m.Cmdy(prefix, "show", table)
}
case "list":
if len(arg) > 2 && arg[2] == "modify" {
m.Cmdy("ssh._route", m.Option("dream"), "ssh.data", "update", m.Option("table"), arg[1], arg[3], arg[4])
arg = []string{"list", m.Option("dream"), m.Option("table")}
}
m.Cmdy("ssh._route", arg[1], "ssh.data", "show", arg[2:])
}
return
}},
"trend": {Name: "trend type item limit offset fields...", Help: "趋势", Hand: func(m *ctx.Message, c *ctx.Context, cmd string, arg ...string) (e error) {
if len(arg) > 4 {
arg[4] = strings.Join(arg[4:], " ")
}
m.Option("cache.limit", kit.Select("10", arg, 2))
m.Option("cache.offset", kit.Select("0", arg, 3))
fields := strings.Split(kit.Select(m.Conf(arg[0], arg[1]+".meta.fields"), arg, 4), " ")
m.Grows(arg[0], arg[1], func(meta map[string]interface{}, index int, value map[string]interface{}) {
m.Push(fields, kit.Shortm(value, "times", "files", "sids"))
})
if m.Appends("time") {
m.Sort("time", "time_r")
} else if m.Appends("times") {
m.Sort("times", "time_r")
}
if m.Appends("index") {
// m.Sort("index", "int_r")
}
m.Table()
return
}},
"state": {Name: "trend type item sid key value fields...", Help: "趋势", Hand: func(m *ctx.Message, c *ctx.Context, cmd string, arg ...string) (e error) {
if len(arg) > 5 {
arg[5] = strings.Join(arg[5:], " ")
}
fields := strings.Split(kit.Select(m.Conf(arg[0], arg[1]+".meta.fields"), arg, 5), " ")
m.Confm(arg[0], []string{arg[1], "hash"}, func(key string, index int, value map[string]interface{}) {
if value["sid"] = key; len(arg) == 2 || arg[2] == "" || strings.HasPrefix(kit.Format(value[arg[3]]), arg[4]) {
m.Push(fields, kit.Shortm(value, "times", "files", "sids"))
}
})
return
}},
"prune": {Name: "prune type sid...", Help: "清理", Hand: func(m *ctx.Message, c *ctx.Context, cmd string, arg ...string) (e error) {
ps := arg[1:]
if len(ps) == 0 {
m.Confm("login", "hash", func(key string, value map[string]interface{}) {
if value["type"] == arg[0] && kit.Format(value["status"]) == "logout" {
ps = append(ps, key)
}
})
}
for _, p := range ps {
m.Confm(arg[0], func(key string, value map[string]interface{}) {
m.Log("info", "prune %v:%v %v:%v", arg[0], key, p, kit.Formats(kit.Chain(value, []string{"hash", p})))
kit.Chain(value, []string{"hash", p}, "")
})
m.Log("info", "prune %v %v:%v", "login", p, kit.Formats(m.Confv("login", []string{"hash", p})))
m.Confv("login", []string{"hash", p}, "")
}
return
}},
"/zsh": {Name: "/zsh sid pwd cmd arg", Help: "命令行", Hand: func(m *ctx.Message, c *ctx.Context, cmd string, arg ...string) (e error) {
cmd = strings.TrimPrefix(cmd, "/")
if f, _, e := m.Optionv("request").(*http.Request).FormFile("sub"); e == nil {
defer f.Close()
@ -133,27 +302,38 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心",
}
}
m.Log("info", "%v %v %v %v", cmd, m.Option("cmd"), m.Option("arg"), m.Option("sub"))
m.Option("river", m.Conf("login", []string{"hash", m.Option("sid"), "river"}))
m.Option("dream", m.Conf("login", []string{"hash", m.Option("sid"), "dream"}))
switch m.Option("cmd") {
case "help":
m.Echo(strings.Join(kit.Trans(m.Confv("help", "index")), "\n"))
case "login":
name := kit.Hashs(m.Option("pid"), m.Option("hostname"), m.Option("username"))
m.Conf(cmd, []string{"terminal", "hash", name}, map[string]interface{}{
"time": m.Time(),
"status": "login",
"sid": name,
"pwd": m.Option("pwd"),
"pid": m.Option("pid"),
"pane": m.Option("pane"),
"hostname": m.Option("hostname"),
"username": m.Option("username"),
})
m.Echo(name)
m.Cmd("login", "init", cmd)
case "logout":
name := m.Option("sid")
m.Conf(cmd, []string{"terminal", "hash", name, "time"}, m.Time())
m.Conf(cmd, []string{"terminal", "hash", name, "status"}, "logout")
m.Cmd("login", "exit")
case "upload":
m.Cmd("favor", "upload")
case "download":
m.Cmd("favor", "download", m.Option("arg"))
case "favor":
if m.Options("tab") {
switch path.Base(m.Option("SHELL")) {
case "zsh":
m.Option("arg", strings.SplitN(m.Option("arg"), ";", 2)[1])
default:
m.Option("arg", strings.SplitN(strings.TrimSpace(m.Option("arg")), " ", 2)[1])
}
m.Cmd("favor", "post", "tab", m.Option("tab"), "note", m.Option("note"), "word", m.Option("arg"))
m.Set("append")
return
}
m.Echo("#/bin/sh\n\n")
m.Cmd(".favor", "post").Table(func(index int, value map[string]string) {
m.Echo("# %v:%v\n%v\n\n", value["tab"], value["note"], value["word"])
})
return
case "historys":
vs := strings.SplitN(strings.TrimSpace(m.Option("arg")), " ", 2)
@ -168,6 +348,8 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心",
switch path.Base(m.Option("SHELL")) {
case "zsh":
m.Option("arg", strings.SplitN(m.Option("arg"), ";", 2)[1])
default:
m.Option("arg", strings.SplitN(strings.TrimSpace(m.Option("arg")), " ", 2)[1])
}
m.Grow(cmd, "history", map[string]interface{}{
"time": m.Time(),
@ -175,59 +357,10 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心",
"cmd": m.Option("arg"),
"pwd": m.Option("pwd"),
})
case "favor":
m.Option("river", m.Conf(cmd, []string{"terminal", "hash", m.Option("sid"), "river"}))
dream := m.Conf(cmd, []string{"terminal", "hash", m.Option("sid"), "dream"})
table := m.Conf(cmd, []string{"terminal", "hash", m.Option("sid"), "table"})
m.Log("info", "river: %v dream: %v table: %v", m.Option("river"), dream, table)
prefix := []string{}
if dream != "" {
prefix = append(prefix, "ssh._route", dream)
}
if m.Options("tab") {
m.Cmd(prefix, "ssh.data", "insert", table, "tab", m.Option("tab"),
"note", m.Option("note"), "word", m.Option("arg"),
)
return
}
m.Cmd(prefix, "ssh.data", "show", table).Table(func(index int, value map[string]string) {
m.Echo("%v:%v\n%v\n", value["tab"], value["note"], value["word"])
}).Set("append")
return
case "sync":
m.Conf(cmd, []string{m.Option("arg"), "hash", m.Option("sid")})
m.Confv(cmd, []string{m.Option("arg"), "hash", m.Option("sid")}, "")
switch m.Option("arg") {
case "df":
m.Split(m.Option("sub"), " ", "6", "fs size used rest per pos").Table(func(index int, value map[string]string) {
if index > 0 {
m.Confv(cmd, []string{m.Option("arg"), "hash", m.Option("sid"), "-2"}, map[string]interface{}{
"fs": value["fs"],
"size": value["size"],
"used": value["used"],
"rest": value["rest"],
"per": value["per"],
"pos": value["pos"],
})
}
})
case "ps":
m.Split(m.Option("sub"), " ").Table(func(index int, value map[string]string) {
m.Confv(cmd, []string{m.Option("arg"), "hash", m.Option("sid"), "-2"}, map[string]interface{}{
"PID": value["PID"],
"TIME": value["TIME"],
"COMMAND": value["COMMAND"],
})
})
case "env":
m.Split(strings.TrimPrefix(m.Option("sub"), "\n"), "=", "2", "name value").Table(func(index int, value map[string]string) {
m.Confv(cmd, []string{m.Option("arg"), "hash", m.Option("sid"), "-2"}, map[string]interface{}{
"name": value["name"],
"value": value["value"],
})
})
case "free":
sub := strings.Replace(m.Option("sub"), " ", "type", 1)
m.Split(sub, " ", "7", "type total used free shared buffer available").Table(func(index int, value map[string]string) {
@ -245,6 +378,34 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心",
})
}
})
case "env":
m.Split(strings.TrimPrefix(m.Option("sub"), "\n"), "=", "2", "name value").Table(func(index int, value map[string]string) {
m.Confv(cmd, []string{m.Option("arg"), "hash", m.Option("sid"), "-2"}, map[string]interface{}{
"name": value["name"],
"value": value["value"],
})
})
case "ps":
m.Split(m.Option("sub"), " ").Table(func(index int, value map[string]string) {
m.Confv(cmd, []string{m.Option("arg"), "hash", m.Option("sid"), "-2"}, map[string]interface{}{
"PID": value["PID"],
"TIME": value["TIME"],
"COMMAND": value["COMMAND"],
})
})
case "df":
m.Split(m.Option("sub"), " ", "6", "fs size used rest per pos").Table(func(index int, value map[string]string) {
if index > 0 {
m.Confv(cmd, []string{m.Option("arg"), "hash", m.Option("sid"), "-2"}, map[string]interface{}{
"fs": value["fs"],
"size": value["size"],
"used": value["used"],
"rest": value["rest"],
"per": value["per"],
"pos": value["pos"],
})
}
})
}
m.Set("append").Set("result")
}
@ -258,96 +419,6 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心",
}
p, arg := kit.Select(".", arg[0]), arg[1:]
switch arg[0] {
case "prune":
ps := []string{}
m.Confm(cmd, "terminal.hash", func(key string, value map[string]interface{}) {
if kit.Format(value["status"]) == "logout" {
ps = append(ps, key)
}
})
for _, v := range ps {
for _, k := range []string{"terminal"} {
m.Log("info", "prune %v %v %v %v", cmd, k, v, kit.Formats(m.Conf(cmd, []string{k, "hash", v})))
m.Confv(cmd, []string{k, "hash", v}, "")
}
}
fallthrough
case "terminal":
if len(arg) > 3 && arg[3] != "" {
m.Conf(cmd, []string{arg[0], "hash", arg[1], "dream"}, arg[3])
}
if len(arg) > 2 && arg[2] != "" {
m.Conf(cmd, []string{arg[0], "hash", arg[1], "table"}, arg[2])
m.Conf(cmd, []string{arg[0], "hash", arg[1], "river"}, m.Option("river"))
}
if len(arg) > 1 && arg[1] != "" {
m.Option("table.format", "table")
m.Confm(cmd, []string{arg[0], "hash", arg[1]}, func(key string, value string) {
m.Push(key, value)
})
m.Sort("key")
break
}
if len(arg) > 3 {
arg[3] = strings.Join(arg[3:], " ")
}
fields := strings.Split(kit.Select(m.Conf(cmd, arg[0]+".meta.fields"), arg, 1), " ")
m.Confm(cmd, arg[0]+".hash", func(key string, value map[string]interface{}) {
m.Push(fields, kit.Shortm(value, "times", "files", "sids"))
})
if m.Appends("times") {
m.Sort("times", "time_r")
}
if m.Appends("time") {
m.Sort("time", "time_r")
}
m.Table()
case "history":
if len(arg) > 3 {
arg[3] = strings.Join(arg[3:], " ")
}
m.Option("cache.limit", kit.Select("10", arg, 1))
m.Option("cache.offset", kit.Select("0", arg, 2))
fields := strings.Split(kit.Select(m.Conf(cmd, arg[0]+".meta.fields"), arg, 3), " ")
m.Grows(cmd, arg[0], func(meta map[string]interface{}, index int, value map[string]interface{}) {
m.Push(fields, kit.Shortm(value, "times", "files", "sids"))
})
if m.Appends("time") || m.Appends("times") {
m.Sort("time", "time_r")
}
if m.Appends("index") {
// m.Sort("index", "int_r")
}
m.Table()
case "favor":
prefix := []string{"ssh._route", arg[1], "ssh.data", "show"}
m.Cmdy(prefix, arg[2:])
case "env", "ps", "df":
if len(arg) > 3 {
arg[3] = strings.Join(arg[3:], " ")
}
fields := strings.Split(kit.Select(m.Conf(cmd, arg[0]+".meta.fields"), arg, 3), " ")
m.Confm(cmd, []string{arg[0], "hash"}, func(key string, index int, value map[string]interface{}) {
if value["sid"] = key; len(arg) == 1 || arg[1] == "" || strings.HasPrefix(kit.Format(value[arg[1]]), arg[2]) {
m.Push(fields, kit.Shortm(value, "times", "files", "sids"))
}
})
if arg[0] == "df" {
m.Sort("size", "int_r")
}
m.Table()
case "free":
if len(arg) > 3 {
arg[3] = strings.Join(arg[3:], " ")
}
m.Option("cache.limit", kit.Select("10", arg, 1))
m.Option("cache.offset", kit.Select("0", arg, 2))
fields := strings.Split(kit.Select(m.Conf(cmd, arg[0]+".meta.fields"), arg, 3), " ")
m.Grows(cmd, arg[0], func(meta map[string]interface{}, index int, value map[string]interface{}) {
m.Push(fields, kit.Shortm(value, "times", "files", "sids"))
})
case "init":
m.Cmd("cli.system", m.Confv("package", "upadte"))
for _, v := range kit.View(arg[1:], m.Confm("package")) {
@ -782,76 +853,7 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心",
}
return
case "prune":
ps := []string{}
m.Confm(cmd, "editor.hash", func(key string, value map[string]interface{}) {
if kit.Format(value["status"]) == "logout" {
ps = append(ps, key)
}
})
for _, v := range ps {
for _, k := range []string{"editor", "bufs", "regs", "marks", "tags", "fixs"} {
m.Log("info", "prune %v %v %v %v", cmd, k, v, kit.Formats(m.Conf(cmd, []string{k, "hash", v})))
m.Confv(cmd, []string{k, "hash", v}, "")
}
}
fallthrough
case "editor":
if len(arg) > 3 && arg[3] != "" {
m.Conf(cmd, []string{arg[0], "hash", arg[1], "dream"}, arg[3])
}
if len(arg) > 2 && arg[2] != "" {
m.Conf(cmd, []string{arg[0], "hash", arg[1], "table"}, arg[2])
m.Conf(cmd, []string{arg[0], "hash", arg[1], "river"}, m.Option("river"))
}
if len(arg) > 1 && arg[1] != "" {
m.Option("table.format", "table")
m.Confm(cmd, []string{arg[0], "hash", arg[1]}, func(key string, value string) {
m.Push(key, value)
})
m.Sort("key")
break
}
if len(arg) > 3 {
arg[3] = strings.Join(arg[3:], " ")
}
fields := strings.Split(kit.Select(m.Conf(cmd, arg[0]+".meta.fields"), arg, 1), " ")
m.Confm(cmd, arg[0]+".hash", func(key string, value map[string]interface{}) {
m.Push(fields, kit.Shortm(value, "times", "files", "sids"))
})
case "opens", "cmds", "txts":
if len(arg) > 3 {
arg[3] = strings.Join(arg[3:], " ")
}
m.Option("cache.limit", kit.Select("10", arg, 1))
m.Option("cache.offset", kit.Select("0", arg, 2))
fields := strings.Split(kit.Select(m.Conf(cmd, arg[0]+".meta.fields"), arg, 3), " ")
m.Grows(cmd, arg[0], func(meta map[string]interface{}, index int, value map[string]interface{}) {
m.Push(fields, kit.Shortm(value, "times", "files", "sids"))
})
case "favor":
prefix := []string{"ssh._route", arg[1], "ssh.data", "show"}
m.Cmdy(prefix, arg[2:])
case "bufs", "regs", "marks", "tags", "fixs":
if len(arg) > 3 {
arg[3] = strings.Join(arg[3:], " ")
}
fields := strings.Split(kit.Select(m.Conf(cmd, arg[0]+".meta.fields"), arg, 3), " ")
m.Confm(cmd, []string{arg[0], "hash"}, func(key string, index int, value map[string]interface{}) {
if value["sid"] = key; len(arg) == 1 || arg[1] == "" || strings.HasPrefix(kit.Format(value[arg[1]]), arg[2]) {
m.Push(fields, kit.Shortm(value, "times", "files", "sids"))
}
})
}
if m.Appends("times") {
m.Sort("times", "time_r")
}
if m.Appends("time") {
m.Sort("time", "time_r")
}
m.Table()
return
}},
"/vim": {Name: "/vim sid pwd cmd arg sub", Help: "编辑器", Hand: func(m *ctx.Message, c *ctx.Context, cmd string, arg ...string) (e error) {
@ -864,37 +866,14 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心",
case "help":
m.Echo(strings.Join(kit.Trans(m.Confv("help", "index")), "\n"))
case "login":
name := kit.Hashs(m.Option("pid"), m.Option("hostname"), m.Option("username"))
m.Conf(cmd, []string{"editor", "hash", name}, map[string]interface{}{
"time": m.Time(),
"status": "login",
"sid": name,
"pwd": m.Option("pwd"),
"pid": m.Option("pid"),
"pane": m.Option("pane"),
"hostname": m.Option("hostname"),
"username": m.Option("username"),
})
m.Echo(name)
m.Cmd("login", "init", cmd)
case "logout":
m.Conf(cmd, []string{"editor", "hash", m.Option("sid"), "time"}, m.Time())
m.Conf(cmd, []string{"editor", "hash", m.Option("sid"), "status"}, "logout")
m.Cmd("login", "exit")
case "favors":
m.Option("river", m.Conf(cmd, []string{"editor", "hash", m.Option("sid"), "river"}))
table := m.Conf(cmd, []string{"editor", "hash", m.Option("sid"), "table"})
dream := m.Conf(cmd, []string{"editor", "hash", m.Option("sid"), "dream"})
m.Log("info", "river: %v dream: %v table: %v", m.Option("river"), dream, table)
prefix := []string{}
if dream != "" {
prefix = append(prefix, "ssh._route", dream)
}
data := map[string][]string{}
m.Cmd(prefix, "ssh.data", "show", table).Table(func(index int, value map[string]string) {
m.Cmd(".favor", "post").Table(func(index int, value map[string]string) {
data[value["tab"]] = append(data[value["tab"]],
fmt.Sprintf("%v:%v:0:(%v): %v\n", value["file"], value["line"], value["note"], value["word"]))
fmt.Sprintf("%v:%v:0:(%v): %v", value["file"], value["line"], value["note"], value["word"]))
})
for k, v := range data {
@ -903,27 +882,15 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心",
}
return
case "favor":
m.Option("river", m.Conf(cmd, []string{"editor", "hash", m.Option("sid"), "river"}))
dream := m.Conf(cmd, []string{"editor", "hash", m.Option("sid"), "dream"})
table := m.Conf(cmd, []string{"editor", "hash", m.Option("sid"), "table"})
m.Log("info", "river: %v dream: %v table: %v", m.Option("river"), dream, table)
prefix := []string{}
if dream != "" {
prefix = append(prefix, "ssh._route", dream)
}
if m.Options("line") {
m.Cmd(prefix, "ssh.data", "insert", table,
"tab", m.Option("tab"),
"note", m.Option("note"), "word", m.Option("arg"),
if m.Options("tab") {
m.Cmd("favor", "post", "tab", m.Option("tab"), "note", m.Option("note"), "word", m.Option("arg"),
"file", m.Option("buf"), "line", m.Option("line"), "col", m.Option("col"),
)
return
}
m.Cmd(prefix, "ssh.data", "show", table).Table(func(index int, value map[string]string) {
m.Cmd(".favor", "post").Table(func(index int, value map[string]string) {
m.Echo("%v:%v:0:(%v): %v\n", value["file"], value["line"], value["note"], value["word"])
}).Set("append")
})
return
case "read", "write":

View File

@ -1,4 +1,4 @@
kit tips "便签" private "web.code.vim" favor \
kit tips "便签" private "web.code.favor" list \
text "" name dream imports plugin_you action auto \
text "tip" name table imports plugin_vim_table action auto \
text "" name index imports plugin_tip_id view tiny action auto \
@ -7,7 +7,7 @@ kit tips "便签" private "web.code.vim" favor \
button "记录" action auto \
button "返回" cb Last
kit editor "编辑器" private "web.code.vim" editor \
kit editor "编辑器" private "web.code.login" list \
text "" name sid imports plugin_vim_sid action auto \
text "" name table imports plugin_vim_table \
text "" name you imports plugin_you \
@ -15,55 +15,60 @@ kit editor "编辑器" private "web.code.vim" editor \
exports vim_sid sid \
button "查看" action auto
kit opens "文件记录" private "web.code.vim" opens \
kit opens "文件记录" private "web.code.trend" vim opens \
text "10" name limit view tiny \
text "0" name offset view tiny \
text "times sids action files" name fields \
button "查看" action auto
kit cmds "命令记录" private "web.code.vim" cmds \
kit cmds "命令记录" private "web.code.trend" vim cmds \
text "10" name limit view tiny \
text "0" name offset view tiny \
text "times sids cmd files" name fields \
exports vim_word cmd \
button "查看" action auto
kit txts "插入记录" private "web.code.vim" txts \
kit txts "插入记录" private "web.code.trend" vim txts \
text "10" name limit view tiny \
text "0" name offset view tiny \
text "times sids word files line" name fields \
exports vim_word word \
button "查看" action auto
kit bufs "文件缓存" private "web.code.vim" bufs \
kit bufs "文件缓存" private "web.code.state" vim bufs \
text "" name sid imports plugin_vim_sid action auto \
text "tag" name key view tiny \
text "" name value \
text "sids tag file line" name fields \
exports vim_file file "" vim_line line \
button "查看" action auto
kit regs "粘贴缓存" private "web.code.vim" regs \
kit regs "粘贴缓存" private "web.code.state" vim regs \
text "" name sid imports plugin_vim_sid action auto \
text "reg" name key view tiny \
text "" name value \
text "sids reg word" name fields \
exports vim_word word \
button "查看" action auto
kit marks "文件标记" private "web.code.vim" marks \
kit marks "文件标记" private "web.code.state" vim marks \
text "" name sid imports plugin_vim_sid action auto \
text "mark" name key view tiny \
text "" name value \
text "sids mark line file" name fields \
exports vim_file file "" vim_line line "" \
button "查看" action auto
kit tags "语法标记" private "web.code.vim" tags \
kit tags "语法标记" private "web.code.state" vim tags \
text "" name sid imports plugin_vim_sid action auto \
text "tag" name key view tiny \
text "" name value \
text "sids tag line file" name fields \
exports vim_file file "" vim_line line "" vim_word tag "" \
button "查看" action auto
kit fixs "项目索引" private "web.code.vim" fixs \
kit fixs "项目索引" private "web.code.state" vim fixs \
text "" name sid imports plugin_vim_sid action auto \
text "files" name key view tiny \
text "" name value \
text "sids word line file" name fields \

View File

@ -1,5 +1,10 @@
kit taps "便签" private "web.code.zsh" "" favor \
kit file "文件" private "web.code.favor" file \
text "" name dream imports plugin_you action auto \
text "file" name type \
button "查看" action auto
kit taps "便签" private "web.code.favor" list \
text "" name dream imports plugin_you action auto \
text "tap" name table imports plugin_zsh_table action auto \
text "" name index imports plugin_tap_id view tiny action auto \
@ -8,7 +13,7 @@ kit taps "便签" private "web.code.zsh" "" favor \
button "记录" action auto \
button "返回" cb Last
kit terminal "终端" private "web.code.zsh" "" terminal \
kit terminal "终端" private "web.code.login" list \
text "" name sid imports plugin_zsh_sid action auto \
text "" name table imports plugin_zsh_table \
text "" name you imports plugin_you \
@ -16,33 +21,36 @@ kit terminal "终端" private "web.code.zsh" "" terminal \
exports zsh_sid sid \
button "查看" action auto
kit history "命令" private "web.code.zsh" "" history \
kit history "命令" private "web.code.trend" zsh history \
text "10" name limit view tiny \
text "0" name offset view tiny \
text "times sids index cmd pwd" name fields \
button "查看" action auto
kit df "磁盘" private "web.code.zsh" "" df \
text "fs" name limit view tiny \
text "" name offset view tiny \
text "sids fs size used rest per pos" name fields \
button "查看" action auto
kit ps "进程" private "web.code.zsh" "" ps \
text "COMMAND" name limit view tiny \
text "" name offset view tiny \
text "sids PID TIME COMMAND" name fields \
button "查看" action auto
kit env "环境" private "web.code.zsh" "" env \
text "name" name limit view tiny \
text "" name offset view tiny \
text "sids name value" name fields \
button "查看" action auto
kit free "内存" private "web.code.zsh" "" free \
kit free "内存" private "web.code.trend" zsh free \
text "10" name limit view tiny \
text "0" name offset view tiny \
text "times sids type total used free" name fields \
button "查看" action auto
kit env "环境" private "web.code.state" zsh env \
text "" name sid imports plugin_zsh_sid action auto \
text "name" name limit view tiny \
text "" name offset view tiny \
text "sids name value" name fields \
button "查看" action auto
kit ps "进程" private "web.code.state" zsh ps \
text "" name sid imports plugin_zsh_sid action auto \
text "COMMAND" name limit view tiny \
text "" name offset view tiny \
text "sids PID TIME COMMAND" name fields \
button "查看" action auto
kit df "磁盘" private "web.code.state" zsh df \
text "" name sid imports plugin_zsh_sid action auto \
text "fs" name limit view tiny \
text "" name offset view tiny \
text "sids fs size used rest per pos" name fields \
button "查看" action auto