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:
go get github.com/nsf/gocode
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
linux:

View File

@ -12,6 +12,19 @@ ctx_sid=${ctx_sid:=""}
ctx_welcome=${ctx_welcome:="^_^ 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() {
echo "$*"|sed -e 's/\"/\\\"/g' -e 's/\n/\\n/g'
}
@ -32,39 +45,22 @@ ShyPost() {
fi
curl -s "${ctx_url}" -H "${ctx_head}" -d "${data}"
}
ShyUpload() {
curl "${ctx_dev}/upload" -F "upload=@$1"
}
ShyDownload() {
curl "${ctx_dev}/download/$1"
}
ShyWord() {
echo "$*"|sed -e 's/\ /%20/g' -e 's/\n/\\n/g'
ShyUpdate() {
curl "${ctx_dev}/publish/$1"
}
ShyForm() {
while [ $# -gt 1 ]; do
echo -n "`ShyWord "$1"`=`ShyWord "$2"`"
shift 2 && [ $# -gt 1 ] && echo -n "&"
done
ShyUpload() {
curl "${ctx_dev}/upload" -F "upload=@$1"
}
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() {
case "$1" in
"historys")
ctx_end=`history|tail -n1|awk '{print $1}'`
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
line=`ShyLine $line`
ShyPost arg "$line" cmd historys FORMAT "$HISTTIMEFORMAT"
@ -89,16 +85,20 @@ ShyHistory() {
ShySync history &>/dev/null &
ctx_sync=$!
;;
*)
ctx_begin=`history|tail -n1|awk '{print $1}'`
echo "begin: $ctx_begin"
bind -x '"\C-gl":ShySync input'
;;
*) ;;
esac
}
ShyRecord() {
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() {
echo ${ctx_goodbye}
Shy logout
@ -114,7 +114,12 @@ ShyLogin() {
ShyInit() {
case "$SHELL" in
"/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
}

View File

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

View File

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

View File

@ -88,9 +88,12 @@ var Index = &Context{Name: "ctx", Help: "模块中心", Server: &CTX{},
Configs: map[string]*Config{
"help": &Config{Name: "help", Value: map[string]interface{}{
"index": []interface{}{
"^_^ 欢迎来到云境世界 ^_^",
"^_^ Welcome to Context world ^_^",
"V2.1: Miss You Forever",
"Date: 2019.10.29 13:14:21",
"From: 2017.11.01 00:08:21",
"Meet: shylinuxc@gmail.com",
"More: https://shylinux.com",
"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"},
}},
"zsh": {Name: "vim", Help: "记录", Value: map[string]interface{}{
"terminal": map[string]interface{}{},
"history": map[string]interface{}{},
"terminal": map[string]interface{}{"meta": 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{}{
"editor": map[string]interface{}{"meta": map[string]interface{}{
@ -100,97 +107,100 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心",
}},
},
Commands: map[string]*ctx.Command{
"/zsh": {Name: "/zsh", Help: "终端", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
if !m.Has("res") {
switch m.Option("cmd") {
case "login":
name := kit.Hashs(m.Option("pid"), m.Option("hostname"), m.Option("username"))
m.Conf("zsh", []string{"terminal", name}, map[string]interface{}{
"sid": name,
"status": "login",
"time": m.Time(),
"pwd": m.Option("pwd"),
"pid": m.Option("pid"),
"pane": m.Option("pane"),
"hostname": m.Option("hostname"),
"username": m.Option("username"),
})
m.Echo(name)
return
case "logout":
name := m.Option("sid")
m.Conf("zsh", []string{"terminal", name, "status"}, "logout")
m.Conf("zsh", []string{"terminal", name, "time"}, m.Time())
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, "/")
m.Log("info", "%v %v %v %v", cmd, m.Option("cmd"), m.Option("arg"), m.Option("sub"))
switch m.Option("cmd") {
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)
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")
case "historys":
m.Option("cache.store", "hi.csv")
name := m.Option("sid")
vs := strings.SplitN(strings.TrimSpace(m.Option("arg")), " ", 2)
m.Grow("zsh", []string{"history", name}, map[string]interface{}{
"sid": name,
"time": m.Time(),
"index": vs[0],
"cmd": kit.Select("", vs, 1),
"pwd": m.Option("pwd"),
})
case "history":
m.Option("cache.store", "hi.csv")
switch path.Base(m.Option("SHELL")) {
case "zsh":
m.Option("arg", strings.SplitN(m.Option("arg"), ";", 2)[1])
}
name := m.Option("sid")
m.Grow("zsh", []string{"history", name}, map[string]interface{}{
"sid": name,
"time": m.Time(),
"cmd": m.Option("arg"),
"pwd": m.Option("pwd"),
})
return
case "historys":
vs := strings.SplitN(strings.TrimSpace(m.Option("arg")), " ", 2)
m.Grow(cmd, "history", map[string]interface{}{
"time": m.Time(),
"sid": m.Option("sid"),
"index": vs[0],
"cmd": kit.Select("", vs, 1),
"pwd": m.Option("pwd"),
})
case "history":
switch path.Base(m.Option("SHELL")) {
case "zsh":
m.Option("arg", strings.SplitN(m.Option("arg"), ";", 2)[1])
}
m.Grow(cmd, "history", map[string]interface{}{
"time": m.Time(),
"sid": m.Option("sid"),
"cmd": m.Option("arg"),
"pwd": m.Option("pwd"),
})
return
}
return
}},
"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},
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:]
switch arg[0] {
case "prune":
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" {
ps = append(ps, key)
}
})
for _, v := range ps {
m.Log("info", "prune zsh %v %v", v, kit.Formats(m.Conf("zsh", []string{"terminal", v})))
m.Confv("zsh", []string{"terminal", v}, "")
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":
m.Confm("zsh", "terminal", func(key string, value map[string]interface{}) {
m.Push([]string{"time", "sid", "status", "pwd", "pid", "pane", "hostname", "username"}, value)
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"))
})
m.Sort("time", "time_r").Table()
case "history":
m.Confm("zsh", "history", func(key string, meta map[string]interface{}, index int, value map[string]interface{}) {
if len(arg) > 1 && !strings.HasPrefix(key, arg[1]) {
return
}
if sid := kit.Format(value["sid"]); len(sid) > 6 {
value["sid"] = sid[:6]
}
m.Push([]string{"time", "sid", "index", "cmd", "pwd"}, value)
})
if len(arg) > 1 {
m.Sort("index", "int_r").Table()
} else {
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":
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("times") {
m.Sort("times", "time_r")
}
if m.Appends("time") {
m.Sort("time", "time_r")
}
m.Table()
case "init":
m.Cmd("cli.system", m.Confv("package", "upadte"))
@ -624,29 +634,30 @@ var Index = &ctx.Context{Name: "code", Help: "代码中心",
}
m.Echo(p)
}
return
case "prune":
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" {
ps = append(ps, key)
}
})
for _, v := range ps {
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.Confv("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, "hash", v}, "")
}
}
fallthrough
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), " ")
m.Confm("vim", arg[0]+".hash", func(key string, value map[string]interface{}) {
m.Push(fields, kit.Shortm(value, "times", "files", "sids"))
})
if m.Appends("time") {
m.Sort("time", "time_r")
}
case "opens", "cmds", "txts":
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.Push(fields, kit.Shortm(value, "times", "files", "sids"))
})
if m.Appends("time") {
m.Sort("time", "time_r")
}
case "bufs", "regs", "marks", "tags", "fixs":
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()
return
}},

View File

@ -10,7 +10,7 @@ kit dir "目录" private "ssh._route" _ "context" "find" "web.code" "zsh" \
kit cli "命令行" private "web.code.zsh" \
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" "复制" "下载" \
button "查看" action auto

View File

@ -26,26 +26,26 @@ fun tips "便签" private \
end
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
kit opens "文件记录" private "web.code.vim" opens \
text "10" name limit view tiny \
text "0" name offset view tiny \
text "times action files" name fields \
text "times sids action files" name fields \
button "查看" action auto
kit cmds "命令记录" private "web.code.vim" cmds \
text "10" name limit 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 \
button "查看" action auto
kit txts "插入记录" private "web.code.vim" txts \
text "10" name limit 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 \
button "查看" action auto

View File

@ -24,9 +24,10 @@ func Time(arg ...string) int {
for _, v := range []string{
"2006-01-02 15:04:05",
"2006-01-02 15:04",
"01-02 15:04",
"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 {
return Int(t)