From 0b3ba78603d74d120213fc959f68baa5adc35180 Mon Sep 17 00:00:00 2001 From: shaoying Date: Thu, 14 Nov 2019 00:52:17 +0800 Subject: [PATCH] add favor.miss --- etc/conf/auto.sh | 15 +++++--- etc/conf/auto.vim | 72 ++++++++++++++++++--------------------- etc/conf/tmux.conf | 1 + src/examples/code/code.go | 53 +++++++++++++++++++++------- src/plugin/vim/index.shy | 19 ++++------- src/plugin/zsh/index.shy | 19 ++++------- 6 files changed, 100 insertions(+), 79 deletions(-) diff --git a/etc/conf/auto.sh b/etc/conf/auto.sh index 1dd38cf1..960a4cce 100644 --- a/etc/conf/auto.sh +++ b/etc/conf/auto.sh @@ -14,8 +14,6 @@ ctx_sid=${ctx_sid:=""} ctx_silent=${ctx_silent:=""} ctx_welcome=${ctx_welcome:="^_^ Welcome to Context world ^_^"} ctx_goodbye=${ctx_goodbye:="^_^ Goodbye to Context world ^_^"} -# ctx_ps1=${ctx_ps1:="\!-$$-\t[\u@\h]\W\$ "} -ctx_ps1=${ctx_ps1:="\!-$$-[\t]\W\$ "} ctx_bind=${ctx_bind:="bind -x"} ctx_null=${ctx_null:="false"} @@ -90,7 +88,7 @@ Shy() { } ShyLogout() { - echo ${ctx_goodbye} && sleep 1 && Shy logout + echo ${ctx_goodbye} && sleep 1 && [ "$ctx_sid" != "" ] && Shy logout } ShyLogin() { HOST=`hostname` ctx_sid=`ShyPost cmd login pid "$$" pane "${TMUX_PANE}" hostname "${HOST}" username "${USER}"` @@ -101,6 +99,11 @@ ShyFavor() { [ "$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 +} ShySync() { [ "$ctx_sid" = "" ] && ShyLogin @@ -155,17 +158,19 @@ ShyHelp() { ShyPost cmd help arg "$@" } ShyInit() { - [ "$ctx_begin" == "" ] && ctx_begin=`history|tail -n1|awk '{print $1}'` + [ "$ctx_begin" = "" ] && ctx_begin=`history|tail -n1|awk '{print $1}'` case "$SHELL" in "/bin/zsh") ctx_bind=${ctx_null} + PROMPT='%![%*]%c$ ' ;; *) + PS1="\!-$$-\t[\u@\h]\W\$ " + PS1="\!-$$-\t\W\$ " ;; esac - PS1=${ctx_ps1} ${ctx_bind} '"\C-t\C-t":ShySyncs base' echo ${ctx_welcome} diff --git a/etc/conf/auto.vim b/etc/conf/auto.vim index 121fcaaa..2e1a7ce7 100644 --- a/etc/conf/auto.vim +++ b/etc/conf/auto.vim @@ -1,9 +1,7 @@ let ctx_url = (len($ctx_dev) > 1? $ctx_dev: "http://127.0.0.1:9095") . "/code/vim" let ctx_head = "Content-Type: application/json" -if !exists("g:ctx_sid") - let ctx_sid = "" -end +if !exists("g:ctx_sid") | let ctx_sid = "" | end fun! ShyPost(arg) let a:arg["buf"] = bufname("%") @@ -15,6 +13,35 @@ 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 = "" +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) + 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" @@ -34,12 +61,7 @@ fun! ShySync(target) endfun fun! ShyCheck(target) - if a:target == "login" - if g:ctx_sid == "" - let arg = {"cmd": "login", "pid": getpid(), "pane": $TMUX_PANE, "hostname": hostname(), "username": $USER} - let g:ctx_sid = ShyPost(arg) - endif - elseif a:target == "favor" + if a:target == "favor" cexpr ShyPost({"cmd": "favor"}) elseif a:target == "favors" let msg = json_decode(ShyPost({"cmd": "favors"})) @@ -75,33 +97,7 @@ fun! ShyCheck(target) end 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 - -let favor_tab = "" -let favor_note = "" -fun! ShyFavor(note) - if a:note == "" - call ShyPost({"cmd": "favor", "arg": getline("."), "line": getpos(".")[1], "col": getpos(".")[2]}) - else - let g:favor_tab = input("tab: ", g:favor_tab) - let g:favor_note = input("note: ", g:favor_note) - call ShyPost({"cmd": "favor", "tab": g:favor_tab, "note": g:favor_note, "arg": getline("."), "line": getpos(".")[1], "col": getpos(".")[2]}) - endif -endfun - -fun! ShyLogout() - call Shy("logout", "") - let g:ctx_sid = "" -endfun - -call ShyCheck("login") +call ShyLogin() autocmd VimLeave * call ShyLogout() autocmd InsertLeave * call ShySync("insert") @@ -119,8 +115,8 @@ call ShySync("tags") " nnoremap :call ShyCheck("cache") " nnoremap :call ShyCheck("favor") -nnoremap :call ShyCheck("favors") -nnoremap F :call ShyFavor("note") +nnoremap :call ShyFavor("note") +nnoremap F :call ShyCheck("favors") nnoremap f :call ShyFavor("") " autocmd BufUnload * call Shy("close", expand("")) | call ShySync("bufs") diff --git a/etc/conf/tmux.conf b/etc/conf/tmux.conf index c692da3b..419ace38 100644 --- a/etc/conf/tmux.conf +++ b/etc/conf/tmux.conf @@ -12,6 +12,7 @@ set -g mode-keys vi set -gw other-pane-width 60 set -gw other-pane-height 15 +set -gw other-pane-height 15 set -g set-titles on set -g set-titles-string "#(whoami)@#h/#{session_name}:#{window_name}.#{pane_index} #{pane_current_command}" diff --git a/src/examples/code/code.go b/src/examples/code/code.go index eb1b9fea..ff095071 100644 --- a/src/examples/code/code.go +++ b/src/examples/code/code.go @@ -53,7 +53,7 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心", }}, "zsh": {Name: "vim", Help: "记录", Value: map[string]interface{}{ "terminal": map[string]interface{}{"meta": map[string]interface{}{ - "fields": "time sid status pwd pid pane hostname username", + "fields": "time sid status table dream pwd pid pane hostname username", }}, "history": map[string]interface{}{"meta": map[string]interface{}{ "fields": "time sid cmd pwd", @@ -79,7 +79,7 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心", }}, "vim": {Name: "vim", Help: "编辑器", Value: map[string]interface{}{ "editor": map[string]interface{}{"meta": map[string]interface{}{ - "fields": "time sid status pwd pid pane hostname username", + "fields": "time sid status table dream pwd pid pane hostname username", }}, "favor": map[string]interface{}{}, "opens": map[string]interface{}{"meta": map[string]interface{}{ @@ -177,16 +177,22 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心", }) 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", "favor: %v table: %v", m.Option("river"), 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("ssh.data", "insert", table, "tab", m.Option("tab"), + m.Cmd(prefix, "ssh.data", "insert", table, "tab", m.Option("tab"), "note", m.Option("note"), "word", m.Option("arg"), ) return } - m.Cmd("ssh.data", "show", table).Table(func(index int, value map[string]string) { + 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 @@ -267,6 +273,9 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心", } 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")) @@ -310,6 +319,10 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心", // 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:], " ") @@ -759,8 +772,6 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心", }}, "vim": {Name: "vim editor|prune|opens|cmds|txts|bufs|regs|marks|tags|fixs", Help: "编辑器", Hand: func(m *ctx.Message, c *ctx.Context, cmd string, arg ...string) (e error) { switch arg[0] { - case "favor": - case "ctag": if f, p, e := kit.Create("etc/conf/tags"); m.Assert(e) { defer f.Close() @@ -786,6 +797,9 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心", } 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")) @@ -816,6 +830,9 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心", 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 { @@ -866,10 +883,16 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心", 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"}) - m.Log("info", "favor: %v table: %v", m.Option("river"), 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("ssh.data", "show", table).Table(func(index int, value map[string]string) { + m.Cmd(prefix, "ssh.data", "show", table).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"])) }) @@ -881,18 +904,24 @@ 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", "favor: %v table: %v", m.Option("river"), 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("ssh.data", "insert", table, + m.Cmd(prefix, "ssh.data", "insert", table, "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("ssh.data", "show", table).Table(func(index int, value map[string]string) { + m.Cmd(prefix, "ssh.data", "show", table).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 diff --git a/src/plugin/vim/index.shy b/src/plugin/vim/index.shy index 6858d2d3..7f2bfd6c 100644 --- a/src/plugin/vim/index.shy +++ b/src/plugin/vim/index.shy @@ -1,22 +1,17 @@ - -fun tips "便签" private \ +kit tips "便签" private "web.code.vim" favor \ + 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 \ feature detail "修改" "复制" "下载" \ - exports vim_table table "" tip_id id "" vim_file file "" vim_line line "" vim_word word "" \ - button "记录" action auto - - if $2 == "modify" - copy skip ssh.data update $table $1 $3 $4 - else - copy ssh.data show - end -end + exports vim_table table "" tip_id id "" \ + button "记录" action auto \ + button "返回" cb Last kit editor "编辑器" private "web.code.vim" editor \ text "" name sid imports plugin_vim_sid action auto \ text "" name table imports plugin_vim_table \ - text "times sids status pid pane" name fields \ + text "" name you imports plugin_you \ + feature detail "prune" "复制" "下载" \ exports vim_sid sid \ button "查看" action auto diff --git a/src/plugin/zsh/index.shy b/src/plugin/zsh/index.shy index 210bc266..9ca165f9 100644 --- a/src/plugin/zsh/index.shy +++ b/src/plugin/zsh/index.shy @@ -1,22 +1,17 @@ -fun taps "便签" private \ - text "tap" name table imports plugin_vim_table action auto \ +kit taps "便签" private "web.code.zsh" "" favor \ + 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 \ feature detail "修改" "复制" "下载" \ - exports vim_table table "" tap_id id "" vim_file file "" vim_line line "" vim_word word "" \ - button "记录" action auto - - if $2 == "modify" - copy skip ssh.data update $table $1 $3 $4 - else - copy ssh.data show - end -end + exports zsh_table table "" tap_id id "" \ + button "记录" action auto \ + button "返回" cb Last kit terminal "终端" private "web.code.zsh" "" terminal \ text "" name sid imports plugin_zsh_sid action auto \ text "" name table imports plugin_zsh_table \ - text "times sids status pid pane hostname" name fields \ + text "" name you imports plugin_you \ feature detail "prune" "复制" "下载" \ exports zsh_sid sid \ button "查看" action auto