From d0dd35e62625811e59e761a8e63965bcd6b3ab6d Mon Sep 17 00:00:00 2001 From: shaoying Date: Wed, 25 Mar 2020 13:45:31 +0800 Subject: [PATCH] add favor proxy --- base/web/web.go | 27 +++++++++++++++++---------- misc/alpha/alpha.go | 13 ++++++------- misc/chrome/chrome.go | 6 +----- misc/git/git.go | 2 +- misc/vim/auto.vim | 17 +++++++++-------- misc/vim/vim.go | 7 ++----- misc/zsh/zsh.go | 5 +---- type.go | 3 +++ 8 files changed, 40 insertions(+), 40 deletions(-) diff --git a/base/web/web.go b/base/web/web.go index f2f8abcd..5e0b8eb2 100644 --- a/base/web/web.go +++ b/base/web/web.go @@ -312,6 +312,7 @@ func (web *Frame) HandleCmd(m *ice.Message, key string, cmd *ice.Command) { // msg.Render("status", 401, "not login") return } + msg.Option("_option", msg.Optionv(ice.MSG_OPTION)) // 执行命令 msg.Target().Run(msg, cmd, msg.Option(ice.MSG_USERURL), cmds...) @@ -464,6 +465,7 @@ var Index = &ice.Context{Name: "web", Help: "网络模块", ice.WEB_FAVOR: {Name: "favor", Help: "收藏夹", Value: kit.Data( kit.MDB_SHORT, kit.MDB_NAME, "template", favor_template, + "proxy", "", )}, ice.WEB_CACHE: {Name: "cache", Help: "缓存池", Value: kit.Data( kit.MDB_SHORT, "text", "path", "var/file", "store", "var/data", "fsize", "100000", "limit", "50", "least", "30", @@ -841,14 +843,10 @@ var Index = &ice.Context{Name: "web", Help: "网络模块", if socket, ok := value["socket"].(*websocket.Conn); !m.Warn(!ok, "socket err") { // 复制选项 for _, k := range kit.Simple(m.Optionv("_option")) { - if m.Options(k) { - switch k { - case "detail", "cmds": - default: - if m.Option(k) == "" { - m.Option(k, m.Option(k)) - } - } + switch k { + case "detail", "cmds": + default: + m.Optionv(k, m.Optionv(k)) } } @@ -1042,6 +1040,9 @@ var Index = &ice.Context{Name: "web", Help: "网络模块", m.Option("cache.limit", -2) for _, favor := range arg[2:] { m.Richs(ice.WEB_FAVOR, nil, favor, func(key string, val map[string]interface{}) { + if m.Conf(ice.WEB_FAVOR, kit.Keys("meta.skip", kit.Value(val, "meta.name"))) == "true" { + return + } m.Grows(ice.WEB_FAVOR, kit.Keys(kit.MDB_HASH, key), "", "", func(index int, value map[string]interface{}) { w.Write(kit.Simple(kit.Value(val, "meta.name"), value["type"], value["name"], value["text"], kit.Format(value["extra"]))) n++ @@ -1050,6 +1051,7 @@ var Index = &ice.Context{Name: "web", Help: "网络模块", } w.Flush() m.Echo("%s: %d", p, n) + return case "load": f, e := os.Open(arg[1]) @@ -1068,6 +1070,7 @@ var Index = &ice.Context{Name: "web", Help: "网络模块", } m.Cmd(ice.WEB_FAVOR, line) } + return case "sync": m.Richs(ice.WEB_FAVOR, nil, arg[1], func(key string, val map[string]interface{}) { @@ -1131,8 +1134,6 @@ var Index = &ice.Context{Name: "web", Help: "网络模块", arg = append(arg, "") } - m.Info("what %v", arg[4:]) - m.Info("what %v", kit.Dict(arg[4:])) // 添加收藏 index := m.Grow(ice.WEB_FAVOR, kit.Keys(kit.MDB_HASH, favor), kit.Dict( kit.MDB_TYPE, arg[1], kit.MDB_NAME, arg[2], kit.MDB_TEXT, arg[3], @@ -1143,6 +1144,12 @@ var Index = &ice.Context{Name: "web", Help: "网络模块", }) m.Log(ice.LOG_INSERT, "favor: %s index: %d name: %s text: %s", favor, index, arg[2], arg[3]) m.Echo("%d", index) + + // 分发数据 + if p := kit.Select(m.Conf(ice.WEB_FAVOR, "meta.proxy"), m.Option("you")); p != "" { + m.Option("you", "") + m.Cmdy(ice.WEB_PROXY, p, ice.WEB_FAVOR, arg) + } }}, ice.WEB_CACHE: {Name: "cache", Help: "缓存池", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { if len(arg) == 0 { diff --git a/misc/alpha/alpha.go b/misc/alpha/alpha.go index 00f6afb6..7c1e629a 100644 --- a/misc/alpha/alpha.go +++ b/misc/alpha/alpha.go @@ -1,14 +1,16 @@ package alpha import ( - "bytes" - "encoding/csv" "github.com/shylinux/icebergs" "github.com/shylinux/icebergs/core/wiki" "github.com/shylinux/toolkits" + + "bytes" + "encoding/csv" "math/rand" "os" "path" + "strings" ) var Index = &ice.Context{Name: "alpha", Help: "英汉词典", @@ -98,11 +100,8 @@ var Index = &ice.Context{Name: "alpha", Help: "英汉词典", } // 搜索方法 - method := "word" - if len(arg) > 1 { - method = arg[1] - } - switch method { + method := kit.Select("word", arg, 1) + switch arg[0] = strings.TrimSpace(arg[0]); method { case "line": case "word": arg[0] = "," + arg[0] + "$" diff --git a/misc/chrome/chrome.go b/misc/chrome/chrome.go index 378e0d7f..d3c85b03 100644 --- a/misc/chrome/chrome.go +++ b/misc/chrome/chrome.go @@ -99,16 +99,12 @@ var Index = &ice.Context{Name: "chrome", Help: "浏览器", "/favor": {Name: "/favor", Help: "收藏", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { if len(arg) > 0 { // 添加收藏 - cmds := []string{ice.WEB_FAVOR, m.Option("tab"), ice.TYPE_SPIDE, m.Option("note"), arg[0]} - if m.Cmdy(cmds); m.Option("you") != "" { - m.Cmdy(ice.WEB_PROXY, m.Option("you"), cmds) - } + m.Cmdy(ice.WEB_FAVOR, m.Option("tab"), ice.TYPE_SPIDE, m.Option("note"), arg[0]) return } }}, "/crx": {Name: "/crx", Help: "/crx", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { - m.Info("what %v", m.Option("sid")) switch arg[0] { case "login": m.Cmdy(ice.WEB_SPIDE, "dev", "msg", "/code/chrome/login", "sid", m.Option("sid")) diff --git a/misc/git/git.go b/misc/git/git.go index b954645a..ba152cb5 100644 --- a/misc/git/git.go +++ b/misc/git/git.go @@ -27,7 +27,7 @@ var Index = &ice.Context{Name: "git", Help: "代码库", Caches: map[string]*ice.Cache{}, Configs: map[string]*ice.Config{ "repos": {Name: "repos", Help: "仓库", Value: kit.Data(kit.MDB_SHORT, "name", "owner", "https://github.com/shylinux")}, - "total": {Name: "repos", Help: "仓库", Value: kit.Data(kit.MDB_SHORT, "name", "skip", kit.Dict("wubi-dict", "true"))}, + "total": {Name: "repos", Help: "仓库", Value: kit.Data(kit.MDB_SHORT, "name", "skip", kit.Dict("wubi-dict", "true", "word-dict", "true"))}, }, Commands: map[string]*ice.Command{ "init": {Name: "init", Help: "init", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { diff --git a/misc/vim/auto.vim b/misc/vim/auto.vim index fdcaff4d..0a029ce4 100644 --- a/misc/vim/auto.vim +++ b/misc/vim/auto.vim @@ -144,8 +144,14 @@ fun! ShyCheck(target) end endfun - - +" 搜索 +call ShyDefine("g:grep_dir", "./") +fun! ShyGrep(word) + 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 '\\<" . a:word . "\\>' " . g:grep_dir + copen +endfun " 任务列表 @@ -154,11 +160,6 @@ fun! ShyTask() 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 @@ -218,7 +219,7 @@ autocmd! InsertLeave * call ShySync("insert") " 按键映射 nnoremap :call ShyFavor() nnoremap f :call ShyFavors() -" nnoremap :call ShyGrep(expand("")) +nnoremap :call ShyGrep(expand("")) " nnoremap :call ShyCheck("cache") " nnoremap :call ShyTask() nnoremap :call ShyComes("refresh") diff --git a/misc/vim/vim.go b/misc/vim/vim.go index 9d7bf14f..47635b2c 100644 --- a/misc/vim/vim.go +++ b/misc/vim/vim.go @@ -88,11 +88,8 @@ var Index = &ice.Context{Name: "vim", Help: "编辑器", "/favor": {Name: "/favor", Help: "收藏", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { if m.Options("arg") { // 添加收藏 - cmds := []string{ice.WEB_FAVOR, m.Option("tab"), "vimrc", m.Option("note"), m.Option("arg"), - "pwd", m.Option("pwd"), "buf", m.Option("buf"), "row", m.Option("row"), "col", m.Option("col")} - if m.Cmdy(cmds); m.Option("you") != "" { - m.Cmdy(ice.WEB_SPACE, m.Option("you"), cmds) - } + m.Cmdy(ice.WEB_FAVOR, m.Option("tab"), "vimrc", m.Option("note"), m.Option("arg"), + "pwd", m.Option("pwd"), "buf", m.Option("buf"), "row", m.Option("row"), "col", m.Option("col")) return } diff --git a/misc/zsh/zsh.go b/misc/zsh/zsh.go index 38cc4880..e7393f07 100644 --- a/misc/zsh/zsh.go +++ b/misc/zsh/zsh.go @@ -162,10 +162,7 @@ var Index = &ice.Context{Name: "zsh", Help: "命令行", "/favor": {Name: "/favor", Help: "收藏", Hand: func(m *ice.Message, c *ice.Context, cmd string, arg ...string) { if len(arg) > 0 && arg[0] != "sh" { // 添加收藏 - cmds := []string{ice.WEB_FAVOR, kit.Select("zsh.history", m.Option("tab")), kit.Select(ice.TYPE_SHELL, m.Option("type")), m.Option("note"), arg[0]} - if m.Cmdy(cmds); m.Option("you") != "" { - m.Cmdy(ice.WEB_SPACE, m.Option("you"), cmds) - } + m.Cmdy(ice.WEB_FAVOR, kit.Select("zsh.history", m.Option("tab")), kit.Select(ice.TYPE_SHELL, m.Option("type")), m.Option("note"), arg[0]) return } diff --git a/type.go b/type.go index 572c8889..f6d4a7f1 100644 --- a/type.go +++ b/type.go @@ -462,6 +462,9 @@ func (m *Message) Copy(msg *Message, arg ...string) *Message { // 复制数据 for _, k := range msg.meta[MSG_APPEND] { + if kit.IndexOf(m.meta[MSG_OPTION], k) > -1 && len(m.meta[k]) > 0 { + m.meta[k] = m.meta[k][:0] + } if kit.IndexOf(m.meta[MSG_APPEND], k) == -1 { m.meta[MSG_APPEND] = append(m.meta[MSG_APPEND], k) }