1
0
mirror of https://shylinux.com/x/ContextOS synced 2025-04-25 16:58:06 +08:00

new context

This commit is contained in:
shaoying 2020-01-17 18:23:24 +08:00
parent 7a8ccb6b9c
commit be394e0b95
17 changed files with 276 additions and 125 deletions

View File

@ -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

View File

@ -1 +0,0 @@
usr/local/wiki/自然/index.md

1
README.md Normal file
View File

@ -0,0 +1 @@
hello ice world

41
bin/ice.sh Executable file
View File

@ -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 $*

View File

@ -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$ '
;;
*)

View File

@ -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([<f-args>], " ")], 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("<afile>")})
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 <C-G><C-G> :call ShyGrep(expand("<cword>"))<CR>
nnoremap <C-G><C-R> :call ShyCheck("cache")<CR>
nnoremap <C-G><C-F> :call ShyFavor()<CR>
nnoremap <C-G>f :call ShyFavors()<CR>
nnoremap <C-G><C-T> :call ShyTask()<CR>
inoremap <C-K> <C-X><C-U>
vnoremap <C-K> :call ShyTrans()

46
etc/conf/Makefile Normal file
View File

@ -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)

21
etc/conf/exit.shy Normal file
View File

@ -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

34
etc/conf/init.shy Normal file
View File

@ -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

View File

@ -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<CR>
colorscheme torte
highlight Comment ctermfg=cyan ctermbg=darkblue
highlight Pmenu ctermfg=cyan ctermbg=darkblue
highlight PmenuSel ctermfg=darkblue ctermbg=cyan
"}}}
"
nnoremap <F3> :NERDTreeToggle<CR>

View File

@ -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
# }

View File

@ -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

View File

@ -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

10
go.mod Normal file
View File

@ -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
)

11
go.sum Normal file
View File

@ -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=

19
src/main.go Normal file
View File

@ -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())
}

1
usr/volcanos Symbolic link
View File

@ -0,0 +1 @@
../../volcanos