1
0
forked from x/ContextOS

add 中文名 云境世界

This commit is contained in:
shaoying 2019-11-11 17:07:59 +08:00
parent 6d7886770f
commit ac57e760ec
9 changed files with 147 additions and 117 deletions

View File

@ -24,7 +24,7 @@ tags:
tool: tool:
go get github.com/nsf/gocode go get github.com/nsf/gocode
go get github.com/jstemmer/gotags go get github.com/jstemmer/gotags
go get github.com/bradfitz/goimports # go get github.com/bradfitz/goimports
go get github.com/Go-zh/tools/cmd/gopls go get github.com/Go-zh/tools/cmd/gopls
linux: linux:

View File

@ -12,6 +12,19 @@ ctx_sid=${ctx_sid:=""}
ctx_welcome=${ctx_welcome:="^_^ Welcome to Context world ^_^"} ctx_welcome=${ctx_welcome:="^_^ Welcome to Context world ^_^"}
ctx_goodbye=${ctx_goodbye:="^_^ Welcome to Context world ^_^"} ctx_goodbye=${ctx_goodbye:="^_^ Welcome to Context world ^_^"}
ShyWord() {
echo "$*"|sed -e 's/\ /%20/g' -e 's/\n/\\n/g'
}
ShyForm() {
while [ $# -gt 1 ]; do
echo -n "`ShyWord "$1"`=`ShyWord "$2"`"
shift 2 && [ $# -gt 1 ] && echo -n "&"
done
}
ShyGet() {
local data=`ShyForm "$@" SHELL "${SHELL}" pwd "${PWD}" sid "${ctx_sid}"`
wget -q "${ctx_url}?${data}"
}
ShyLine() { ShyLine() {
echo "$*"|sed -e 's/\"/\\\"/g' -e 's/\n/\\n/g' echo "$*"|sed -e 's/\"/\\\"/g' -e 's/\n/\\n/g'
} }
@ -32,39 +45,22 @@ ShyPost() {
fi fi
curl -s "${ctx_url}" -H "${ctx_head}" -d "${data}" curl -s "${ctx_url}" -H "${ctx_head}" -d "${data}"
} }
ShyUpload() {
curl "${ctx_dev}/upload" -F "upload=@$1"
}
ShyDownload() { ShyDownload() {
curl "${ctx_dev}/download/$1" curl "${ctx_dev}/download/$1"
} }
ShyWord() { ShyUpdate() {
echo "$*"|sed -e 's/\ /%20/g' -e 's/\n/\\n/g' curl "${ctx_dev}/publish/$1"
} }
ShyForm() { ShyUpload() {
while [ $# -gt 1 ]; do curl "${ctx_dev}/upload" -F "upload=@$1"
echo -n "`ShyWord "$1"`=`ShyWord "$2"`"
shift 2 && [ $# -gt 1 ] && echo -n "&"
done
} }
ShyGet() {
local data=`ShyForm "$@" SHELL "${SHELL}" pwd "${PWD}" sid "${ctx_sid}"`
wget -q "${ctx_url}?${data}"
}
Shy() {
local ctx_res=`ShyPost cmd "$1" arg "$2"`
case "$ctx_res" in
"PS1");;
*) [ -n "${ctx_res}" ] && ShyPost cmd "$1" arg "$2" res `sh -c ${ctx_res}`
esac
}
ShySync() { ShySync() {
case "$1" in case "$1" in
"historys") "historys")
ctx_end=`history|tail -n1|awk '{print $1}'` ctx_end=`history|tail -n1|awk '{print $1}'`
ctx_tail=`expr $ctx_end - $ctx_begin` ctx_tail=`expr $ctx_end - $ctx_begin`
echo $ctx_begin - $ctx_end $ctx_tail echo
echo "upload history $ctx_begin-$ctx_end count $ctx_tail to $ctx_dev"
history|tail -n $ctx_tail |while read line; do history|tail -n $ctx_tail |while read line; do
line=`ShyLine $line` line=`ShyLine $line`
ShyPost arg "$line" cmd historys FORMAT "$HISTTIMEFORMAT" ShyPost arg "$line" cmd historys FORMAT "$HISTTIMEFORMAT"
@ -89,16 +85,20 @@ ShyHistory() {
ShySync history &>/dev/null & ShySync history &>/dev/null &
ctx_sync=$! ctx_sync=$!
;; ;;
*) *) ;;
ctx_begin=`history|tail -n1|awk '{print $1}'`
echo "begin: $ctx_begin"
bind -x '"\C-gl":ShySync input'
;;
esac esac
} }
ShyRecord() { ShyRecord() {
script $1 script $1
} }
Shy() {
local ctx_res=`ShyPost cmd "$1" arg "$2"`
case "$ctx_res" in
"PS1");;
*) [ -n "${ctx_res}" ] && ShyPost cmd "$1" arg "$2" res `sh -c ${ctx_res}`
esac
}
ShyLogout() { ShyLogout() {
echo ${ctx_goodbye} echo ${ctx_goodbye}
Shy logout Shy logout
@ -114,7 +114,12 @@ ShyLogin() {
ShyInit() { ShyInit() {
case "$SHELL" in case "$SHELL" in
"/bin/zsh");; "/bin/zsh");;
*) PS1="\!-\t[\u@\h]\W\$ ";; *)
ctx_begin=`history|tail -n1|awk '{print $1}'`
bind -x '"\C-t":ShySync historys'
# bind -x '"\C-gl":ShySync input'
PS1="\!-\t[\u@\h]\W\$ "
;;
esac esac
} }

View File

@ -37,6 +37,11 @@ fun! ShyCheck(target)
let arg = {"cmd": "login", "pid": getpid(), "pane": $TMUX_PANE, "hostname": hostname(), "username": $USER} let arg = {"cmd": "login", "pid": getpid(), "pane": $TMUX_PANE, "hostname": hostname(), "username": $USER}
let g:ctx_sid = ShyPost(arg) let g:ctx_sid = ShyPost(arg)
endif endif
elseif a:target == "cache"
call ShySync("bufs")
call ShySync("regs")
call ShySync("marks")
call ShySync("tags")
elseif a:target == "exec" elseif a:target == "exec"
let cmd = getcmdline() let cmd = getcmdline()
if cmd != "" if cmd != ""
@ -87,6 +92,7 @@ call ShySync("regs")
call ShySync("marks") call ShySync("marks")
call ShySync("tags") call ShySync("tags")
" call ShySync("fixs") " call ShySync("fixs")
nnoremap <C-R> :call ShyCheck("cache")<CR>
" autocmd BufUnload * call Shy("close", expand("<afile>")) | call ShySync("bufs") " autocmd BufUnload * call Shy("close", expand("<afile>")) | call ShySync("bufs")
" autocmd CmdlineLeave * " autocmd CmdlineLeave *

View File

@ -102,6 +102,7 @@ nnoremap <C-L> <C-W>l
nnoremap <Space> : nnoremap <Space> :
cnoremap jk <CR> cnoremap jk <CR>
cnoremap W w<CR>
cnoremap wa wa<CR> cnoremap wa wa<CR>
inoremap jk <Esc> inoremap jk <Esc>
"}}} "}}}

View File

@ -88,9 +88,12 @@ var Index = &Context{Name: "ctx", Help: "模块中心", Server: &CTX{},
Configs: map[string]*Config{ Configs: map[string]*Config{
"help": &Config{Name: "help", Value: map[string]interface{}{ "help": &Config{Name: "help", Value: map[string]interface{}{
"index": []interface{}{ "index": []interface{}{
"^_^ 欢迎来到云境世界 ^_^",
"^_^ Welcome to Context world ^_^", "^_^ Welcome to Context world ^_^",
"V2.1: Miss You Forever", "V2.1: Miss You Forever",
"Date: 2019.10.29 13:14:21", "Date: 2019.10.29 13:14:21",
"From: 2017.11.01 00:08:21",
"Meet: shylinuxc@gmail.com",
"More: https://shylinux.com", "More: https://shylinux.com",
"More: https://github.com/shylinux/context", "More: https://github.com/shylinux/context",
}, },

View File

@ -50,8 +50,15 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心",
"alias": map[string]interface{}{"s": "status", "b": "branch"}, "alias": map[string]interface{}{"s": "status", "b": "branch"},
}}, }},
"zsh": {Name: "vim", Help: "记录", Value: map[string]interface{}{ "zsh": {Name: "vim", Help: "记录", Value: map[string]interface{}{
"terminal": map[string]interface{}{}, "terminal": map[string]interface{}{"meta": map[string]interface{}{
"history": map[string]interface{}{}, "fields": "time sid status pwd pid pane hostname username",
}},
"history": map[string]interface{}{"meta": map[string]interface{}{
"fields": "time sid cmd pwd",
"store": "var/tmp/zsh.csv",
"limit": "30",
"least": "10",
}},
}}, }},
"vim": {Name: "vim", Help: "编辑器", Value: map[string]interface{}{ "vim": {Name: "vim", Help: "编辑器", Value: map[string]interface{}{
"editor": map[string]interface{}{"meta": map[string]interface{}{ "editor": map[string]interface{}{"meta": map[string]interface{}{
@ -100,15 +107,16 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心",
}}, }},
}, },
Commands: map[string]*ctx.Command{ Commands: map[string]*ctx.Command{
"/zsh": {Name: "/zsh", Help: "终端", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) { "/zsh": {Name: "/zsh sid pwd cmd arg", Help: "终端", Hand: func(m *ctx.Message, c *ctx.Context, cmd string, arg ...string) (e error) {
if !m.Has("res") { cmd = strings.TrimPrefix(cmd, "/")
m.Log("info", "%v %v %v %v", cmd, m.Option("cmd"), m.Option("arg"), m.Option("sub"))
switch m.Option("cmd") { switch m.Option("cmd") {
case "login": case "login":
name := kit.Hashs(m.Option("pid"), m.Option("hostname"), m.Option("username")) name := kit.Hashs(m.Option("pid"), m.Option("hostname"), m.Option("username"))
m.Conf("zsh", []string{"terminal", name}, map[string]interface{}{ m.Conf(cmd, []string{"terminal", "hash", name}, map[string]interface{}{
"sid": name,
"status": "login",
"time": m.Time(), "time": m.Time(),
"status": "login",
"sid": name,
"pwd": m.Option("pwd"), "pwd": m.Option("pwd"),
"pid": m.Option("pid"), "pid": m.Option("pid"),
"pane": m.Option("pane"), "pane": m.Option("pane"),
@ -116,81 +124,83 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心",
"username": m.Option("username"), "username": m.Option("username"),
}) })
m.Echo(name) m.Echo(name)
return
case "logout": case "logout":
name := m.Option("sid") name := m.Option("sid")
m.Conf("zsh", []string{"terminal", name, "status"}, "logout") m.Conf(cmd, []string{"terminal", "hash", name, "time"}, m.Time())
m.Conf("zsh", []string{"terminal", name, "time"}, m.Time()) m.Conf(cmd, []string{"terminal", "hash", name, "status"}, "logout")
return
case "historys": case "historys":
m.Option("cache.store", "hi.csv")
name := m.Option("sid")
vs := strings.SplitN(strings.TrimSpace(m.Option("arg")), " ", 2) vs := strings.SplitN(strings.TrimSpace(m.Option("arg")), " ", 2)
m.Grow("zsh", []string{"history", name}, map[string]interface{}{ m.Grow(cmd, "history", map[string]interface{}{
"sid": name,
"time": m.Time(), "time": m.Time(),
"sid": m.Option("sid"),
"index": vs[0], "index": vs[0],
"cmd": kit.Select("", vs, 1), "cmd": kit.Select("", vs, 1),
"pwd": m.Option("pwd"), "pwd": m.Option("pwd"),
}) })
case "history": case "history":
m.Option("cache.store", "hi.csv")
switch path.Base(m.Option("SHELL")) { switch path.Base(m.Option("SHELL")) {
case "zsh": case "zsh":
m.Option("arg", strings.SplitN(m.Option("arg"), ";", 2)[1]) m.Option("arg", strings.SplitN(m.Option("arg"), ";", 2)[1])
} }
m.Grow(cmd, "history", map[string]interface{}{
name := m.Option("sid")
m.Grow("zsh", []string{"history", name}, map[string]interface{}{
"sid": name,
"time": m.Time(), "time": m.Time(),
"sid": m.Option("sid"),
"cmd": m.Option("arg"), "cmd": m.Option("arg"),
"pwd": m.Option("pwd"), "pwd": m.Option("pwd"),
}) })
return return
} }
}
return return
}}, }},
"zsh": {Name: "zsh dir grep key [split reg fields] [filter reg fields] [order key method] [group keys method] [sort keys method]", "zsh": {Name: "zsh dir grep key [split reg fields] [filter reg fields] [order key method] [group keys method] [sort keys method]",
Form: map[string]int{"split": 2, "filter": 2, "order": 2, "group": 2, "sort": 2, "limit": 2}, Form: map[string]int{"split": 2, "filter": 2, "order": 2, "group": 2, "sort": 2, "limit": 2},
Help: "终端", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) { Help: "终端", Hand: func(m *ctx.Message, c *ctx.Context, cmd string, arg ...string) (e error) {
p, arg := kit.Select(".", arg[0]), arg[1:] p, arg := kit.Select(".", arg[0]), arg[1:]
switch arg[0] { switch arg[0] {
case "prune": case "prune":
ps := []string{} ps := []string{}
m.Confm("zsh", []string{"terminal"}, func(key string, value map[string]interface{}) { m.Confm(cmd, "terminal.hash", func(key string, value map[string]interface{}) {
if kit.Format(value["status"]) == "logout" { if kit.Format(value["status"]) == "logout" {
ps = append(ps, key) ps = append(ps, key)
} }
}) })
for _, v := range ps { for _, v := range ps {
m.Log("info", "prune zsh %v %v", v, kit.Formats(m.Conf("zsh", []string{"terminal", v}))) for _, k := range []string{"terminal"} {
m.Confv("zsh", []string{"terminal", v}, "") 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 fallthrough
case "terminal": case "terminal":
m.Confm("zsh", "terminal", func(key string, value map[string]interface{}) { fields := strings.Split(kit.Select(m.Conf(cmd, arg[0]+".meta.fields"), arg, 1), " ")
m.Push([]string{"time", "sid", "status", "pwd", "pid", "pane", "hostname", "username"}, value) m.Confm(cmd, arg[0]+".hash", func(key string, value map[string]interface{}) {
m.Push(fields, kit.Shortm(value, "times", "files", "sids"))
}) })
m.Sort("time", "time_r").Table() if m.Appends("times") {
m.Sort("times", "time_r")
}
if m.Appends("time") {
m.Sort("time", "time_r")
}
m.Table()
case "history": case "history":
m.Confm("zsh", "history", func(key string, meta map[string]interface{}, index int, value map[string]interface{}) { if len(arg) > 3 {
if len(arg) > 1 && !strings.HasPrefix(key, arg[1]) { arg[3] = strings.Join(arg[3:], " ")
return
} }
if sid := kit.Format(value["sid"]); len(sid) > 6 { m.Option("cache.limit", kit.Select("10", arg, 1))
value["sid"] = sid[:6] m.Option("cache.offset", kit.Select("0", arg, 2))
} fields := strings.Split(kit.Select(m.Conf(cmd, arg[0]+".meta.fields"), arg, 3), " ")
m.Push([]string{"time", "sid", "index", "cmd", "pwd"}, value) 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 len(arg) > 1 { if m.Appends("times") {
m.Sort("index", "int_r").Table() m.Sort("times", "time_r")
} else {
m.Sort("time", "time_r").Table()
} }
if m.Appends("time") {
m.Sort("time", "time_r")
}
m.Table()
case "init": case "init":
m.Cmd("cli.system", m.Confv("package", "upadte")) m.Cmd("cli.system", m.Confv("package", "upadte"))
@ -624,29 +634,30 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心",
} }
m.Echo(p) m.Echo(p)
} }
return
case "prune": case "prune":
ps := []string{} ps := []string{}
m.Confm("vim", "editor", func(key string, value map[string]interface{}) { m.Confm("vim", "editor.hash", func(key string, value map[string]interface{}) {
if kit.Format(value["status"]) == "logout" { if kit.Format(value["status"]) == "logout" {
ps = append(ps, key) ps = append(ps, key)
} }
}) })
for _, v := range ps { for _, v := range ps {
for _, k := range []string{"editor", "bufs", "regs", "marks", "tags", "fixs"} { for _, k := range []string{"editor", "bufs", "regs", "marks", "tags", "fixs"} {
m.Log("info", "prune vim %v %v %v", k, v, kit.Formats(m.Conf("vim", []string{k, v}))) m.Log("info", "prune vim %v %v %v", k, v, kit.Formats(m.Conf("vim", []string{k, "hash", v})))
m.Confv("vim", []string{k, v}, "") m.Confv("vim", []string{k, "hash", v}, "")
} }
} }
fallthrough fallthrough
case "editor": case "editor":
if len(arg) > 1 {
arg[1] = strings.Join(arg[1:], " ")
}
fields := strings.Split(kit.Select(m.Conf("vim", arg[0]+".meta.fields"), arg, 1), " ") fields := strings.Split(kit.Select(m.Conf("vim", arg[0]+".meta.fields"), arg, 1), " ")
m.Confm("vim", arg[0]+".hash", func(key string, value map[string]interface{}) { m.Confm("vim", arg[0]+".hash", func(key string, value map[string]interface{}) {
m.Push(fields, kit.Shortm(value, "times", "files", "sids")) m.Push(fields, kit.Shortm(value, "times", "files", "sids"))
}) })
if m.Appends("time") {
m.Sort("time", "time_r")
}
case "opens", "cmds", "txts": case "opens", "cmds", "txts":
if len(arg) > 3 { if len(arg) > 3 {
@ -658,9 +669,6 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心",
m.Grows("vim", arg[0], func(meta map[string]interface{}, index int, value map[string]interface{}) { m.Grows("vim", arg[0], func(meta map[string]interface{}, index int, value map[string]interface{}) {
m.Push(fields, kit.Shortm(value, "times", "files", "sids")) m.Push(fields, kit.Shortm(value, "times", "files", "sids"))
}) })
if m.Appends("time") {
m.Sort("time", "time_r")
}
case "bufs", "regs", "marks", "tags", "fixs": case "bufs", "regs", "marks", "tags", "fixs":
if len(arg) > 3 { if len(arg) > 3 {
@ -673,6 +681,12 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心",
} }
}) })
} }
if m.Appends("times") {
m.Sort("times", "time_r")
}
if m.Appends("time") {
m.Sort("time", "time_r")
}
m.Table() m.Table()
return return
}}, }},

View File

@ -10,7 +10,7 @@ kit dir "目录" private "ssh._route" _ "context" "find" "web.code" "zsh" \
kit cli "命令行" private "web.code.zsh" \ kit cli "命令行" private "web.code.zsh" \
text "" name dir imports plugin_path action auto \ text "" name dir imports plugin_path action auto \
select "terminal" values terminal values history action auto \ select "terminal" values terminal values prune values history action auto \
feature detail "prune" "复制" "下载" \ feature detail "prune" "复制" "下载" \
button "查看" action auto button "查看" action auto

View File

@ -26,26 +26,26 @@ fun tips "便签" private \
end end
kit editor "编辑器" private "web.code.vim" editor \ kit editor "编辑器" private "web.code.vim" editor \
text "times status pid pane" name fields \ text "times sids status pid pane" name fields \
button "查看" action auto button "查看" action auto
kit opens "文件记录" private "web.code.vim" opens \ kit opens "文件记录" private "web.code.vim" opens \
text "10" name limit view tiny \ text "10" name limit view tiny \
text "0" name offset view tiny \ text "0" name offset view tiny \
text "times action files" name fields \ text "times sids action files" name fields \
button "查看" action auto button "查看" action auto
kit cmds "命令记录" private "web.code.vim" cmds \ kit cmds "命令记录" private "web.code.vim" cmds \
text "10" name limit view tiny \ text "10" name limit view tiny \
text "0" name offset view tiny \ text "0" name offset view tiny \
text "times cmd files" name fields \ text "times sids cmd files" name fields \
exports vim_word cmd \ exports vim_word cmd \
button "查看" action auto button "查看" action auto
kit txts "插入记录" private "web.code.vim" txts \ kit txts "插入记录" private "web.code.vim" txts \
text "10" name limit view tiny \ text "10" name limit view tiny \
text "0" name offset view tiny \ text "0" name offset view tiny \
text "times word files" name fields \ text "times sids word files line" name fields \
exports vim_word word \ exports vim_word word \
button "查看" action auto button "查看" action auto

View File

@ -24,9 +24,10 @@ func Time(arg ...string) int {
for _, v := range []string{ for _, v := range []string{
"2006-01-02 15:04:05", "2006-01-02 15:04:05",
"2006-01-02 15:04", "2006-01-02 15:04",
"01-02 15:04",
"2006-01-02", "2006-01-02",
"2006/01/02", "2006/01/02",
"01-02 15:04", "15:04:05",
} { } {
if t, e := time.ParseInLocation(v, arg[0], time.Local); e == nil { if t, e := time.ParseInLocation(v, arg[0], time.Local); e == nil {
return Int(t) return Int(t)