1
0
mirror of https://shylinux.com/x/ContextOS synced 2025-04-25 16:58:06 +08:00
This commit is contained in:
shaoying 2019-11-23 23:41:14 +08:00
parent 048ccaec34
commit fdaa2538d8
3 changed files with 61 additions and 128 deletions

View File

@ -5,7 +5,7 @@ if !exists("g:ctx_sid") | let ctx_sid = "" | end
fun! ShySend(arg) fun! ShySend(arg)
if has_key(a:arg, "sub") && a:arg["sub"] != "" if has_key(a:arg, "sub") && a:arg["sub"] != ""
let temp = tempname() let temp = tempname()
call writefile([a:arg["sub"]], temp) call writefile(split(a:arg["sub"], "\n"), temp, "b")
let a:arg["sub"] = "@" . temp let a:arg["sub"] = "@" . temp
endif endif
@ -66,16 +66,6 @@ fun! ShyCheck(target)
call ShySync("regs") call ShySync("regs")
call ShySync("marks") call ShySync("marks")
call ShySync("tags") call ShySync("tags")
elseif a:target == "exec"
let cmd = getcmdline()
if cmd != ""
call ShySync("exec")
if getcmdline() == "w"
call ShySync("regs")
call ShySync("marks")
call ShySync("tags")
endif
endif
elseif a:target == "fixs" elseif a:target == "fixs"
let l = len(getqflist()) let l = len(getqflist())
if l > 0 if l > 0
@ -93,64 +83,26 @@ endfun
fun! ShyGrep(word) fun! ShyGrep(word)
if !exists("g:grep_dir") | let g:grep_dir = "./" | endif if !exists("g:grep_dir") | let g:grep_dir = "./" | endif
let g:grep_dir = input("dir: ", g:grep_dir, "file") let g:grep_dir = input("dir: ", g:grep_dir, "file")
execute "grep -rn --exclude tags --exclude '\..*' --exclude '*.tags' " . a:word . " " . g:grep_dir execute "grep -rn --exclude tags --exclude '*.tags' " . a:word . " " . g:grep_dir
endfun endfun
fun! ShyTag(word) fun! ShyTag(word)
execute "tag " . a:word execute "tag " . a:word
endfun endfun
fun! ShyHelp() fun! ShyHelp()
echo ShySend({"cmd": "help"}) echo ShySend({"cmd": "help"})
endfun endfun
call ShyLogin() call ShyLogin()
" " call ShySync("bufs") autocmd VimLeave * call ShyLogout()
" call ShySync("regs") autocmd BufReadPost * call ShySync("bufs")
" call ShySync("marks")
" call ShySync("tags")
" " call ShySync("fixs")
"
" autocmd VimLeave * call ShyLogout()
" autocmd BufReadPost * call ShySync("bufs")
" hello
autocmd BufReadPost * call ShySync("read") autocmd BufReadPost * call ShySync("read")
autocmd BufWritePre * call ShySync("write") autocmd BufWritePre * call ShySync("write")
autocmd CmdlineLeave * call ShyCheck("exec") autocmd CmdlineLeave * call ShySync("exec")
" autocmd QuickFixCmdPost * call ShyCheck("fixs") autocmd QuickFixCmdPost * call ShyCheck("fixs")
autocmd InsertLeave * call ShySync("insert") autocmd InsertLeave * call ShySync("insert")
" nnoremap <C-G><C-G> :call ShyGrep(expand("<cword>"))<CR>
" command! ShyHelp echo ShyPost({"cmd": "help"}) nnoremap <C-G><C-R> :call ShyCheck("cache")<CR>
" nnoremap <C-G><C-F> :call ShyFavor()<CR>
" nnoremap <C-g><C-g> :call ShyGrep(expand("<cword>"))<CR> nnoremap <C-G>f :call ShyFavors()<CR>
" " nnoremap <C-g><C-t> :call ShyTag(expand("<cword>"))<CR> nnoremap <C-G><C-T> :call ShyTask()<CR>
" nnoremap <C-g><C-t> :call ShyTask()<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 *
" autocmd CompleteDone * call Shy("sync", "regs")
" autocmd InsertEnter * call Shy("sync", "regs")
" autocmd CmdlineEnter * call Shy("sync", "regs")
" autocmd BufWinEnter * call Shy("enter", expand("<afile>"))
" autocmd WinEnter * call Shy("enter", expand("<afile>"))
" autocmd WinLeave * call Shy("leave", expand("<afile>"))
" autocmd CursorMoved * call Shy("line", getcurpos()[1])
" autocmd InsertCharPre * call Shy("char", v:char)
"
" let g:colorscheme=1
" let g:colorlist = [ "ron", "torte", "darkblue", "peachpuff" ]
" function! ColorNext()
" if g:colorscheme >= len(g:colorlist)
" let g:colorscheme = 0
" endif
" let g:scheme = g:colorlist[g:colorscheme]
" exec "colorscheme " . g:scheme
" let g:colorscheme = g:colorscheme+1
" endfunction
" call ColorNext()
" command! NN call ColorNext()<CR>
" command! SS mksession! etc/session.vim

View File

@ -50,6 +50,12 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心",
"git": {Name: "git", Help: "记录", Value: map[string]interface{}{ "git": {Name: "git", Help: "记录", Value: map[string]interface{}{
"alias": map[string]interface{}{"s": "status", "b": "branch"}, "alias": map[string]interface{}{"s": "status", "b": "branch"},
}}, }},
"cache": {Name: "cache", Help: "缓存默认的全局配置", Value: map[string]interface{}{
"store": "var/tmp/hi.csv",
"limit": 6,
"least": 3,
}},
"zsh": {Name: "zsh", Help: "命令行", Value: map[string]interface{}{ "zsh": {Name: "zsh", Help: "命令行", Value: map[string]interface{}{
"history": map[string]interface{}{"meta": map[string]interface{}{ "history": map[string]interface{}{"meta": map[string]interface{}{
"fields": "time sid cmd pwd", "fields": "time sid cmd pwd",
@ -94,26 +100,21 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心",
}}, }},
"bufs": map[string]interface{}{"meta": map[string]interface{}{ "bufs": map[string]interface{}{"meta": map[string]interface{}{
"fields": "sid buf tag file line", "fields": "buf tag file line",
}}, }},
"regs": map[string]interface{}{"meta": map[string]interface{}{ "regs": map[string]interface{}{"meta": map[string]interface{}{
"fields": "sid reg word", "fields": "reg word",
}}, }},
"marks": map[string]interface{}{"meta": map[string]interface{}{ "marks": map[string]interface{}{"meta": map[string]interface{}{
"fields": "sid mark line col file", "fields": "mark line col file",
}}, }},
"tags": map[string]interface{}{"meta": map[string]interface{}{ "tags": map[string]interface{}{"meta": map[string]interface{}{
"fields": "sid tag line file", "fields": "tag line file",
}}, }},
"fixs": map[string]interface{}{"meta": map[string]interface{}{ "fixs": map[string]interface{}{"meta": map[string]interface{}{
"fields": "sid fix file line word", "fields": "fix file line word",
}}, }},
}}, }},
"cache": {Name: "cache", Help: "缓存默认的全局配置", Value: map[string]interface{}{
"store": "var/tmp/hi.csv",
"limit": 6,
"least": 3,
}},
"login": {Name: "login", Value: map[string]interface{}{"check": false, "local": true, "expire": "720h", "meta": map[string]interface{}{ "login": {Name: "login", Value: map[string]interface{}{"check": false, "local": true, "expire": "720h", "meta": map[string]interface{}{
"fields": "time sid type status ship.dream ship.stage pwd pid pane hostname username", "fields": "time sid type status ship.dream ship.stage pwd pid pane hostname username",
@ -387,7 +388,7 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心",
} }
return return
}}, }},
"state": {Name: "state post|list", Help: "状态", Hand: func(m *ctx.Message, c *ctx.Context, cmd string, arg ...string) (e error) { "state": {Name: "state post|list agent type", Help: "状态", Hand: func(m *ctx.Message, c *ctx.Context, cmd string, arg ...string) (e error) {
switch arg[0] { switch arg[0] {
case "post": case "post":
data := map[string]interface{}{} data := map[string]interface{}{}
@ -406,6 +407,7 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心",
return return
} }
if value["sid"] = key; len(arg) < 6 || arg[4] == "" || strings.HasPrefix(kit.Format(value[arg[4]]), arg[5]) { if value["sid"] = key; len(arg) < 6 || arg[4] == "" || strings.HasPrefix(kit.Format(value[arg[4]]), arg[5]) {
m.Push("sid", key)
m.Push(fields, value) m.Push(fields, value)
} }
}) })
@ -951,7 +953,6 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心",
m.Echo(p) m.Echo(p)
} }
return return
} }
return return
}}, }},
@ -990,65 +991,50 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心",
case "read", "write": case "read", "write":
m.Cmd("trend", "post", "vim.opens", "sid", m.Option("sid"), m.Cmd("trend", "post", "vim.opens", "sid", m.Option("sid"),
"action", m.Option("cmd"), "file", m.Option("arg"), "pwd", m.Option("pwd")) "action", m.Option("cmd"), "file", m.Option("arg"), "pwd", m.Option("pwd"))
case "exec": case "exec":
m.Cmd("trend", "post", "vim.cmds", "sid", m.Option("sid"), m.Cmd("trend", "post", "vim.cmds", "sid", m.Option("sid"),
"cmd", m.Option("sub"), "file", m.Option("buf"), "pwd", m.Option("pwd")) "cmd", m.Option("sub"), "file", m.Option("buf"), "pwd", m.Option("pwd"))
case "insert": case "insert":
m.Cmd("trend", "post", "vim.txts", "sid", m.Option("sid"), m.Cmd("trend", "post", "vim.txts", "sid", m.Option("sid"),
"word", m.Option("sub"), "line", m.Option("row"), "col", m.Option("col"), "file", m.Option("buf"), "pwd", m.Option("pwd")) "word", m.Option("sub"), "line", m.Option("row"), "col", m.Option("col"), "file", m.Option("buf"), "pwd", m.Option("pwd"))
case "tasklet": case "tasklet":
m.Cmd("ssh._route", m.Option("dream"), "web.team.task", "create", "task", "3", "add", "action", m.Time(), m.Time("10m"), m.Option("arg"), m.Option("sub")) m.Cmd("ssh._route", m.Option("dream"), "web.team.task", "create", "task",
"3", "add", "action", m.Time(), m.Time("10m"), m.Option("arg"), m.Option("sub"))
case "sync": case "sync":
m.Conf(cmd, []string{m.Option("arg"), "hash", m.Option("sid")}, "") m.Confv(cmd, []string{m.Option("arg"), "hash", m.Option("sid")}, []interface{}{})
switch m.Option("arg") { switch m.Option("arg") {
case "bufs": case "bufs":
m.Split(strings.TrimSpace(m.Option("sub")), " ", "5", "id tag name some line").Table(func(index int, value map[string]string) { m.Split(m.Option("sub"), " ", "5", "id tag name some line").Table(func(index int, value map[string]string) {
m.Confv(cmd, []string{m.Option("arg"), "hash", m.Option("sid"), "-2"}, map[string]interface{}{ m.Cmd("state", "post", cmd, m.Option("arg"),
"buf": value["id"], "buf", value["id"], "tag", value["tag"], "line", value["line"],
"tag": value["tag"], "file", strings.TrimSuffix(strings.TrimPrefix(value["name"], "\""), "\""))
"file": strings.TrimSuffix(strings.TrimPrefix(value["name"], "\""), "\""),
"line": value["line"],
})
}) })
case "regs": case "regs":
m.Split(strings.TrimPrefix(m.Option("sub"), "\n--- Registers ---\n"), " ", "2", "name word").Table(func(index int, value map[string]string) { m.Split(strings.TrimPrefix(m.Option("sub"), "--- Registers ---\n"), " ", "2", "name word").Table(func(index int, value map[string]string) {
m.Confv(cmd, []string{m.Option("arg"), "hash", m.Option("sid"), "-2"}, map[string]interface{}{ m.Cmd("state", "post", cmd, m.Option("arg"),
"word": strings.Replace(strings.Replace(value["word"], "^I", "\t", -1), "^J", "\n", -1), "reg", strings.TrimPrefix(value["name"], "\""),
"reg": strings.TrimPrefix(value["name"], "\""), "word", strings.Replace(strings.Replace(value["word"], "^I", "\t", -1), "^J", "\n", -1))
})
}) })
case "marks": case "marks":
m.Split(strings.TrimPrefix(m.Option("sub"), "\n"), " ", "4").Table(func(index int, value map[string]string) { m.Split(m.Option("sub"), " ", "4").Table(func(index int, value map[string]string) {
m.Confv(cmd, []string{m.Option("arg"), "hash", m.Option("sid"), "-2"}, map[string]interface{}{ m.Cmd("state", "post", cmd, m.Option("arg"),
"mark": value["mark"], "mark", value["mark"], "line", value["line"], "col", value["col"],
"line": value["line"], "file", value["file/text"])
"col": value["col"],
"file": value["file/text"],
})
}) })
case "tags": case "tags":
m.Split(strings.TrimPrefix(m.Option("sub"), "\n"), " ", "6").Table(func(index int, value map[string]string) { m.Split(strings.TrimSuffix(m.Option("sub"), ">"), " ", "6").Table(func(index int, value map[string]string) {
m.Confv(cmd, []string{m.Option("arg"), "hash", m.Option("sid"), "-2"}, map[string]interface{}{ m.Cmd("state", "post", cmd, m.Option("arg"),
"tag": value["tag"], "tag", value["tag"], "line", value["line"], "file", value["in file/text"])
"line": value["line"],
"file": value["in file/text"],
})
}) })
case "fixs": case "fixs":
if strings.HasPrefix(m.Option("sub"), "\nError") { if strings.HasPrefix(m.Option("sub"), "\nError") {
break break
} }
m.Split(strings.TrimPrefix(m.Option("sub"), "\n"), " ", "3", "id file word").Table(func(index int, value map[string]string) { m.Split(m.Option("sub"), " ", "3", "id file word").Table(func(index int, value map[string]string) {
vs := strings.Split(kit.Format(value["file"]), ":") vs := strings.Split(kit.Format(value["file"]), ":")
m.Confv(cmd, []string{m.Option("arg"), "hash", m.Option("sid"), "-2"}, map[string]interface{}{ m.Cmd("state", "post", cmd, m.Option("arg"),
"fix": value["id"], "fix", value["id"], "file", vs[0], "line", vs[1], "word", value["word"])
"file": vs[0],
"line": vs[1],
"word": value["word"],
})
}) })
} }
m.Set("append").Set("result") m.Set("append").Set("result")

View File

@ -53,43 +53,38 @@ kit txts "插入记录" private "web.code.trend" list "vim.txts" \
button "查看" action auto \ button "查看" action auto \
button "返回" cb Last button "返回" cb Last
kit bufs "文件缓存" private "web.code.state" vim bufs \ kit bufs "文件缓存" private "web.code.state" list vim bufs \
text "" name sid imports plugin_vim_sid action auto \ text "" name sid imports plugin_vim_sid action auto \
text "tag" name key view tiny \ text "tag" name match view tiny \
text "" name value \ text "" name value view tiny \
text "sids tag file line" name fields \
exports vim_file file "" vim_line line \ exports vim_file file "" vim_line line \
button "查看" action auto button "查看" action auto
kit regs "粘贴缓存" private "web.code.state" vim regs \ kit regs "粘贴缓存" private "web.code.state" list vim regs \
text "" name sid imports plugin_vim_sid action auto \ text "" name sid imports plugin_vim_sid action auto \
text "reg" name key view tiny \ text "reg" name match view tiny \
text "" name value \ text "" name value view tiny \
text "sids reg word" name fields \
exports vim_word word \ exports vim_word word \
button "查看" action auto button "查看" action auto
kit marks "文件标记" private "web.code.state" vim marks \ kit marks "文件标记" private "web.code.state" list vim marks \
text "" name sid imports plugin_vim_sid action auto \ text "" name sid imports plugin_vim_sid action auto \
text "mark" name key view tiny \ text "mark" name match view tiny \
text "" name value \ text "" name value view tiny \
text "sids mark line file" name fields \ exports vim_file file "" vim_line line "" vim_col col "" \
exports vim_file file "" vim_line line "" \
button "查看" action auto button "查看" action auto
kit tags "语法标记" private "web.code.state" vim tags \ kit tags "语法标记" private "web.code.state" list vim tags \
text "" name sid imports plugin_vim_sid action auto \ text "" name sid imports plugin_vim_sid action auto \
text "tag" name key view tiny \ text "tag" name match view tiny \
text "" name value \ text "" name value view tiny \
text "sids tag line file" name fields \
exports vim_file file "" vim_line line "" vim_word tag "" \ exports vim_file file "" vim_line line "" vim_word tag "" \
button "查看" action auto button "查看" action auto
kit fixs "项目索引" private "web.code.state" vim fixs \ kit fixs "项目索引" private "web.code.state" list vim fixs \
text "" name sid imports plugin_vim_sid action auto \ text "" name sid imports plugin_vim_sid action auto \
text "files" name key view tiny \ text "files" name value view tiny \
text "" name value \ text "" name value view tiny \
text "sids word line file" name fields \
exports vim_file file "" vim_line line "" vim_word word "" \ exports vim_file file "" vim_line line "" vim_word word "" \
button "查看" action auto button "查看" action auto