diff --git a/Makefile b/Makefile index e47662e4..d714c987 100644 --- a/Makefile +++ b/Makefile @@ -1,46 +1,6 @@ - -PUBLISH=usr/publish -BENCH=src/extend/shy.go -BUILD=go build -o $(PUBLISH)/ -TARGET=shy - -install:prepare - GOPATH=$(PWD):$(GOPATH) go install $(BENCH) && date && echo - @bin/boot.sh restart && date - -prepare: - @go get github.com/shylinux/icebergs - @go get github.com/shylinux/toolkits - @go get github.com/nsf/termbox-go - @go get github.com/gorilla/websocket - @go get github.com/go-sql-driver/mysql - @go get github.com/gomodule/redigo/redis - @go get github.com/gomarkdown/markdown - @go get github.com/skip2/go-qrcode - @go get gopkg.in/gomail.v2 - -gotags: - gotags -f golang.tags -R $(GOROOT)/src -tags: - gotags -f ctx.tags -R src -tool: - go get github.com/nsf/gocode - go get github.com/jstemmer/gotags - # go get github.com/bradfitz/goimports - go get github.com/Go-zh/tools/cmd/gopls - -linux: - GOPATH=$(PWD):$(GOPATH) GOOS=linux $(BUILD)$(TARGET).linux.$(shell go env GOARCH) $(BENCH) -linux_arm: - GOARCH=arm GOOS=linux $(BUILD)$(TARGET).linux.arm $(BENCH) -linux32: - GOARCH=386 GOOS=linux $(BUILD)$(TARGET).linux.386 $(BENCH) -linux64: - GOARCH=amd64 GOOS=linux $(BUILD)$(TARGET).linux.amd64 $(BENCH) -darwin: - GOARCH=amd64 GOOS=darwin $(BUILD)$(TARGET).darwin.amd64 $(BENCH) -win64: - GOARCH=amd64 GOOS=windows $(BUILD)$(TARGET).win64.exe $(BENCH) -win32: - GOARCH=386 GOOS=windows $(BUILD)$(TARGET).win32.exe $(BENCH) - +all: + @echo && date + export CGO_ENABLED=0 + export GOPRIVATE=github.com + export GOPROXY=https://goproxy.cn + go build -o bin/ice.bin src/main.go && chmod u+x bin/ice.bin && ./bin/ice.sh restart diff --git a/README.md b/README.md deleted file mode 120000 index b4e99a70..00000000 --- a/README.md +++ /dev/null @@ -1 +0,0 @@ -usr/local/wiki/自然/index.md \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 00000000..b2db458f --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +hello ice world diff --git a/bin/ice.sh b/bin/ice.sh new file mode 100755 index 00000000..0e9dd402 --- /dev/null +++ b/bin/ice.sh @@ -0,0 +1,41 @@ +#! /bin/sh + +export PATH=${PWD}:${PWD}/bin:$PATH +export ctx_pid=${ctx_pid:=var/run/ice.pid} +export ctx_log=${ctx_log:=bin/boot.log} + +prepare() { + [ -d bin ] || mkdir bin + [ -e bin/ice.sh ] || curl $ctx_dev/publish/ice.sh -o bin/ice.sh && chmod u+x bin/ice.sh + [ -e bin/ice.bin ] && chmod u+x bin/ice.bin && return + + bin="ice" + case `uname -s` in + Darwin) bin=${bin}.darwin ;; + Linux) bin=${bin}.linux ;; + *) bin=${bin}.windows ;; + esac + case `uname -m` in + x86_64) bin=${bin}.amd64 ;; + i686) bin=${bin}.386 ;; + arm*) bin=${bin}.arm ;; + esac + curl $ctx_dev/publish/${bin} -o bin/ice.bin && chmod u+x bin/ice.bin + } +start() { + trap HUP hup && while true; do + date && ice.bin $@ 2>$ctx_log && echo -e "\n\nrestarting..." || break + done +} +serve() { + prepare && shutdown && start $@ +} +restart() { + [ -e $ctx_pid ] && kill -2 `cat $ctx_pid` || echo +} +shutdown() { + [ -e $ctx_pid ] && kill -3 `cat $ctx_pid` || echo +} + +cmd=$1 && [ -n "$cmd" ] && shift || cmd=serve +$cmd $* diff --git a/etc/conf/auto.sh b/etc/auto.sh similarity index 99% rename from etc/conf/auto.sh rename to etc/auto.sh index c724cd13..e4a93cd2 100644 --- a/etc/conf/auto.sh +++ b/etc/auto.sh @@ -150,8 +150,8 @@ ShyHelp() { ShyInit() { [ "$ctx_begin" = "" ] && ctx_begin=`history|tail -n1|awk '{print $1}'` - case "$SHELL" in - "/bin/zsh") + case "${SHELL##*/}" in + "zsh") PROMPT='%![%*]%c$ ' ;; *) diff --git a/etc/conf/auto.vim b/etc/auto.vim similarity index 55% rename from etc/conf/auto.vim rename to etc/auto.vim index fbc57a12..fef8b5a0 100644 --- a/etc/conf/auto.vim +++ b/etc/auto.vim @@ -1,7 +1,19 @@ +" 变量定义 +func! ShyDefine(name, value) + if !exists("name") | exec "let " . a:name . " = \"" . a:value . "\"" | endif +endfunc -let ctx_url = (len($ctx_dev) > 1? $ctx_dev: "http://127.0.0.1:9095") . "/code/vim" -if !exists("g:ctx_sid") | let ctx_sid = "" | end +" 输出日志 +" call ShyDefine("g:ShyLog", "/dev/null") +call ShyDefine("g:ShyLog", "shy.log") +fun! ShyLog(...) + call writefile([strftime("%Y-%m-%d %H:%M:%S ") . join(a:000, " ")], g:ShyLog, "a") +endfun +command -nargs=+ ShyLog call writefile([strftime("%Y-%m-%d %H:%M:%S ") . join([], " ")], g:ShyLog, "a") +" 后端通信 +call ShyDefine("g:ctx_sid", "") +call ShyDefine("g:ctx_url", (len($ctx_dev) > 1? $ctx_dev: "http://127.0.0.1:9020") . "/code/vim") fun! ShySend(arg) if has_key(a:arg, "sub") && a:arg["sub"] != "" let temp = tempname() @@ -10,22 +22,33 @@ fun! ShySend(arg) endif let a:arg["buf"] = bufname("%") - let a:arg["pwd"] = getcwd() let a:arg["sid"] = g:ctx_sid + let a:arg["pwd"] = getcwd() let args = "" - for k in keys(a:arg) + for k in sort(keys(a:arg)) let args = args . " -F '" . k . "=" . a:arg[k] . "' " endfor return system("curl -s " . g:ctx_url . args . " 2>/dev/null") endfun +fun! ShySends(...) + let args = {} + if len(a:000) > 0 | let args["cmd"] = a:000[0] | endif + if len(a:000) > 1 | let args["arg"] = a:000[1] | endif + if len(a:000) > 2 | let args["sub"] = a:000[2] | endif + return ShySend(args) +endfun +" 用户登录 fun! ShyLogout() if g:ctx_sid == "" | return | endif - call ShySend({"cmd": "logout"}) + call ShySends("logout") endfun fun! ShyLogin() let g:ctx_sid = ShySend({"cmd": "login", "share": $ctx_share, "pid": getpid(), "pane": $TMUX_PANE, "hostname": hostname(), "username": $USER}) endfun +call ShyLogin() + +" 收藏列表 fun! ShyFavor() if !exists("g:favor_tab") | let g:favor_tab = "" | endif if !exists("g:favor_note") | let g:favor_note = "" | endif @@ -46,13 +69,14 @@ fun! ShyFavors() if note != "" | lexpr note | lopen | let note = "" | endif endfun +" 数据同步 fun! ShySync(target) if bufname("%") == "ControlP" | return | end if a:target == "read" || a:target == "write" call ShySend({"cmd": a:target, "arg": expand("")}) elseif a:target == "exec" - call ShySend({"cmd": a:target, "sub": getcmdline()}) + call ShySend({"cmd": a:target, "arg": getcmdline()}) elseif a:target == "insert" call ShySend({"cmd": a:target, "sub": getreg("."), "row": line("."), "col": col(".")}) else @@ -77,32 +101,72 @@ fun! ShyCheck(target) end endfun +" 任务列表 fun! ShyTask() call ShySend({"cmd": "tasklet", "arg": input("target: "), "sub": input("detail: ")}) 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 + execute "grep -rn --exclude tags --exclude '*.tags' '\<" . a:word . "\>' " . g:grep_dir endfun fun! ShyTag(word) execute "tag " . a:word endfun + +" 输入转换 +fun! ShyTrans(code) + return split(ShySend({"cmd": "trans", "arg": a:code, "pre": getline("."), "row": line("."), "col": col(".")}), "\n") +endfun + +fun! ShyInput() + call ShyLog("input", v:char, line("."), col(".")) +endfun + +" 输入补全 +fun! ShyComplete(firststart, base) + if a:firststart | let line = getline('.') | let start = col('.') - 1 + " 命令位置 + if match(trim(line), "ice ") == 0 | return match(line, "ice ") | endif + " 符号位置 + call ShyLog("what", line[start-1], line[start-1] !~ '\a') + if line[start-1] !~ '\a' | return start - 1 | end + " 单词位置 + while start > 0 && line[start - 1] =~ '\a' | let start -= 1 | endwhile + return start + endif + + " 符号转换 + if a:base == "," | return [",", ","] | end + if a:base == "." | return ["。", "."] | end + " 单词转换 + return ShyTrans(a:base) +endfun +set completefunc=ShyComplete + +" 帮助信息 fun! ShyHelp() echo ShySend({"cmd": "help"}) endfun -call ShyLogin() -autocmd VimLeave * call ShyLogout() -autocmd BufReadPost * call ShySync("bufs") -autocmd BufReadPost * call ShySync("read") -autocmd BufWritePre * call ShySync("write") -autocmd CmdlineLeave * call ShySync("exec") -autocmd QuickFixCmdPost * call ShyCheck("fixs") -autocmd InsertLeave * call ShySync("insert") +" 事件回调 +autocmd! VimLeave * call ShyLogout() +autocmd! BufReadPost * call ShySync("bufs") +autocmd! BufReadPost * call ShySync("read") +autocmd! BufWritePre * call ShySync("write") +autocmd! CmdlineLeave * call ShySync("exec") +autocmd! QuickFixCmdPost * call ShyCheck("fixs") +autocmd! InsertLeave * call ShySync("insert") +autocmd! InsertCharPre * call ShyInput() + +" 按键映射 nnoremap :call ShyGrep(expand("")) nnoremap :call ShyCheck("cache") nnoremap :call ShyFavor() nnoremap f :call ShyFavors() nnoremap :call ShyTask() +inoremap +vnoremap :call ShyTrans() diff --git a/etc/conf/Makefile b/etc/conf/Makefile new file mode 100644 index 00000000..e47662e4 --- /dev/null +++ b/etc/conf/Makefile @@ -0,0 +1,46 @@ + +PUBLISH=usr/publish +BENCH=src/extend/shy.go +BUILD=go build -o $(PUBLISH)/ +TARGET=shy + +install:prepare + GOPATH=$(PWD):$(GOPATH) go install $(BENCH) && date && echo + @bin/boot.sh restart && date + +prepare: + @go get github.com/shylinux/icebergs + @go get github.com/shylinux/toolkits + @go get github.com/nsf/termbox-go + @go get github.com/gorilla/websocket + @go get github.com/go-sql-driver/mysql + @go get github.com/gomodule/redigo/redis + @go get github.com/gomarkdown/markdown + @go get github.com/skip2/go-qrcode + @go get gopkg.in/gomail.v2 + +gotags: + gotags -f golang.tags -R $(GOROOT)/src +tags: + gotags -f ctx.tags -R src +tool: + go get github.com/nsf/gocode + go get github.com/jstemmer/gotags + # go get github.com/bradfitz/goimports + go get github.com/Go-zh/tools/cmd/gopls + +linux: + GOPATH=$(PWD):$(GOPATH) GOOS=linux $(BUILD)$(TARGET).linux.$(shell go env GOARCH) $(BENCH) +linux_arm: + GOARCH=arm GOOS=linux $(BUILD)$(TARGET).linux.arm $(BENCH) +linux32: + GOARCH=386 GOOS=linux $(BUILD)$(TARGET).linux.386 $(BENCH) +linux64: + GOARCH=amd64 GOOS=linux $(BUILD)$(TARGET).linux.amd64 $(BENCH) +darwin: + GOARCH=amd64 GOOS=darwin $(BUILD)$(TARGET).darwin.amd64 $(BENCH) +win64: + GOARCH=amd64 GOOS=windows $(BUILD)$(TARGET).win64.exe $(BENCH) +win32: + GOARCH=386 GOOS=windows $(BUILD)$(TARGET).win32.exe $(BENCH) + diff --git a/etc/common.shy b/etc/conf/common.shy similarity index 100% rename from etc/common.shy rename to etc/conf/common.shy diff --git a/etc/conf/exit.shy b/etc/conf/exit.shy new file mode 100644 index 00000000..c47de099 --- /dev/null +++ b/etc/conf/exit.shy @@ -0,0 +1,21 @@ +# 应用配置 +~chat + config save var/tmp/share.json share +~wiki + config save var/tmp/story.json story +~code + config save var/tmp/vim.json vim + config save var/tmp/zsh.json zsh + config save var/tmp/dream.json dream + config save var/tmp/code.json login + +# 系统配置 +~ssh + config save var/data/flow.json flow + config save var/data/work.json work +~aaa + config save var/tmp/auth.json auth + config save var/tmp/short.json short +~cli + config save var/tmp/runtime.json runtime + diff --git a/etc/conf/init.shy b/etc/conf/init.shy new file mode 100644 index 00000000..ae5f2a1e --- /dev/null +++ b/etc/conf/init.shy @@ -0,0 +1,34 @@ +# 系统配置 +~cli + config load tmp/runtime.json runtime +~aaa + config load tmp/short.json short + config load tmp/auth.json auth +~ssh + config load data/work.json work + config load data/flow.json flow +# 服务配置 +~nfs + source etc/common.shy +~ssh + remote auto +~nfs + source local.shy + +# 应用配置 +~code + config load tmp/code.json login + config load tmp/dream.json dream + config load tmp/zsh.json zsh + config load tmp/vim.json vim +~wiki + config load tmp/story.json story +~chat + config load tmp/share.json share + +# 终端配置 +~cli + +~wiki +~chat +~code diff --git a/etc/conf/vimrc b/etc/conf/vimrc index ae59747e..49fb8d7a 100644 --- a/etc/conf/vimrc +++ b/etc/conf/vimrc @@ -154,16 +154,17 @@ autocmd BufNewFile,BufReadPost *.js call Config("js") autocmd BufReadPost * normal `" -source ~/context/etc/conf/auto.vim - -if filereadable("~/.vim_local") +" if filereadable("~/.vim_local") source ~/.vim_local -endif +" endif cnoremap RR :source ~/.vimrc colorscheme torte highlight Comment ctermfg=cyan ctermbg=darkblue +highlight Pmenu ctermfg=cyan ctermbg=darkblue +highlight PmenuSel ctermfg=darkblue ctermbg=cyan "}}} " nnoremap :NERDTreeToggle + diff --git a/etc/conf/zshrc b/etc/conf/zshrc index ae25dca4..3c0b3839 100644 --- a/etc/conf/zshrc +++ b/etc/conf/zshrc @@ -106,8 +106,6 @@ bindkey "^P" up-line-or-beginning-search bindkey -M vicmd j down-line-or-beginning-search bindkey -M vicmd k up-line-or-beginning-search -source ~/context/etc/conf/auto.sh - # preexec() { # # bench web.code.counter nexec 1 >/dev/null # } diff --git a/etc/exit.shy b/etc/exit.shy index c47de099..e69de29b 100644 --- a/etc/exit.shy +++ b/etc/exit.shy @@ -1,21 +0,0 @@ -# 应用配置 -~chat - config save var/tmp/share.json share -~wiki - config save var/tmp/story.json story -~code - config save var/tmp/vim.json vim - config save var/tmp/zsh.json zsh - config save var/tmp/dream.json dream - config save var/tmp/code.json login - -# 系统配置 -~ssh - config save var/data/flow.json flow - config save var/data/work.json work -~aaa - config save var/tmp/auth.json auth - config save var/tmp/short.json short -~cli - config save var/tmp/runtime.json runtime - diff --git a/etc/init.shy b/etc/init.shy index ae5f2a1e..e69de29b 100644 --- a/etc/init.shy +++ b/etc/init.shy @@ -1,34 +0,0 @@ -# 系统配置 -~cli - config load tmp/runtime.json runtime -~aaa - config load tmp/short.json short - config load tmp/auth.json auth -~ssh - config load data/work.json work - config load data/flow.json flow -# 服务配置 -~nfs - source etc/common.shy -~ssh - remote auto -~nfs - source local.shy - -# 应用配置 -~code - config load tmp/code.json login - config load tmp/dream.json dream - config load tmp/zsh.json zsh - config load tmp/vim.json vim -~wiki - config load tmp/story.json story -~chat - config load tmp/share.json share - -# 终端配置 -~cli - -~wiki -~chat -~code diff --git a/go.mod b/go.mod new file mode 100644 index 00000000..580e7b0e --- /dev/null +++ b/go.mod @@ -0,0 +1,10 @@ +module miss + +go 1.13 + +require github.com/shylinux/icebergs v0.1.9 + +replace ( + github.com/shylinux/icebergs => ../icebergs + github.com/shylinux/toolkits => ../toolkits +) diff --git a/go.sum b/go.sum new file mode 100644 index 00000000..5876c073 --- /dev/null +++ b/go.sum @@ -0,0 +1,11 @@ +github.com/gomarkdown/markdown v0.0.0-20200112043221-ec51d717629d h1:Qw3Ku+gg4x3gfv71ayr0SbjJYWpWD10XoS9JbtFgvbg= +github.com/gomarkdown/markdown v0.0.0-20200112043221-ec51d717629d/go.mod h1:aii0r/K0ZnHv7G0KF7xy1v0A7s2Ljrb5byB7MO5p6TU= +github.com/gorilla/websocket v1.4.1 h1:q7AeDBpnBk8AogcD4DSag/Ukw/KV+YhzLj2bP5HvKCM= +github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= +github.com/shylinux/icebergs v0.1.12 h1:pUWWp4p5rF1JT7lcbaBlCJOWzwjPYDzmWcO9+nrNsfs= +github.com/shylinux/icebergs v0.1.12/go.mod h1:/gccR5uyFaaml8CBSD4BfHmIPOK6QlaFp3sK4eOiv4s= +github.com/shylinux/toolkits v0.1.0 h1:7ghnVEjuwLf7zBsyeR37ahm2gaOKIyjSw9F9Pp9oTBU= +github.com/shylinux/toolkits v0.1.0/go.mod h1:Y68Ot6xOmo1bun67YvqC3chDGeU2gDxtsUnvVDGJm4g= +github.com/skip2/go-qrcode v0.0.0-20191027152451-9434209cb086 h1:RYiqpb2ii2Z6J4x0wxK46kvPBbFuZcdhS+CIztmYgZs= +github.com/skip2/go-qrcode v0.0.0-20191027152451-9434209cb086/go.mod h1:PLPIyL7ikehBD1OAjmKKiOEhbvWyHGaNDjquXMcYABo= +golang.org/dl v0.0.0-20190829154251-82a15e2f2ead/go.mod h1:IUMfjQLJQd4UTqG1Z90tenwKoCX93Gn3MAQJMOSBsDQ= diff --git a/src/main.go b/src/main.go new file mode 100644 index 00000000..6a6452db --- /dev/null +++ b/src/main.go @@ -0,0 +1,19 @@ +package main + +import ( + "github.com/shylinux/icebergs" + _ "github.com/shylinux/icebergs/base" + _ "github.com/shylinux/icebergs/core" + _ "github.com/shylinux/icebergs/misc" + + _ "github.com/shylinux/icebergs/misc/alpha" + _ "github.com/shylinux/icebergs/misc/input" + _ "github.com/shylinux/icebergs/misc/lark" + _ "github.com/shylinux/icebergs/misc/mp" + _ "github.com/shylinux/icebergs/misc/pi" + _ "github.com/shylinux/icebergs/misc/wx" +) + +func main() { + println(ice.Run()) +} diff --git a/usr/volcanos b/usr/volcanos new file mode 120000 index 00000000..2ed74d6b --- /dev/null +++ b/usr/volcanos @@ -0,0 +1 @@ +../../volcanos \ No newline at end of file