Skip to content

Commit 47b9d6c

Browse files
committed
👀 upload
0 parents  commit 47b9d6c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+3492
-0
lines changed

.github/workflows/release-tags.yml

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# This workflow will build a golang project
2+
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go
3+
4+
name: release-tags
5+
6+
on:
7+
push:
8+
branches: [ "main" ]
9+
pull_request:
10+
branches: [ "main" ]
11+
12+
jobs:
13+
14+
release:
15+
if: startsWith(github.ref, 'refs/tags/')
16+
runs-on: ubuntu-latest
17+
permissions:
18+
contents: write
19+
steps:
20+
- uses: actions/checkout@v3
21+
22+
- name: Set up Go
23+
uses: actions/setup-go@v4
24+
with:
25+
go-version: '1.21.x'
26+
# cache-dependency-path: go.sum
27+
28+
- name: Install dependencies
29+
run: go mod tidy
30+
31+
- name: Build
32+
run: bash scripts/build.sh -a
33+
34+
# - name: version
35+
# run: echo "::set-output name=version::$(go run cmd/kd.go --version | awk '{print $3}')"
36+
# id: version
37+
38+
- name: Generate Changelog
39+
run: echo "由changelog生成" > ${{ github.workspace }}-CHANGELOG.txt
40+
41+
- name: Release
42+
uses: softprops/action-gh-release@v1
43+
# if: startsWith(github.ref, 'refs/tags/')
44+
with:
45+
name: test-${{ steps.version.outputs.version }}
46+
body_path: ${{ github.workspace }}-CHANGELOG.txt
47+
fail_on_unmatched_files: true
48+
tag_name: v0.0.1
49+
prerelease: true
50+
files: build/*
51+
52+
- name: info
53+
run: echo ${{ steps.Release.outputs.url }} ${{ steps.Release.outputs.upload_url }} ${{ steps.Release.outputs.id }}
54+
55+

.gitignore

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# If you prefer the allow list template instead of the deny list, see community template:
2+
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
3+
#
4+
# Binaries for programs and plugins
5+
*.exe
6+
*.exe~
7+
*.dll
8+
*.so
9+
*.dylib
10+
11+
# Test binary, built with `go test -c`
12+
*.test
13+
14+
# Output of the go coverage tool, specifically when used with LiteIDE
15+
*.out
16+
17+
# Dependency directories (remove the comment below to include it)
18+
vendor/
19+
build/
20+
data/
21+
22+
# Others
23+
kd
24+
.idea
25+
.vscode
26+
27+
# Go workspace file
28+
go.work

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2023 _kmz
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Makefile

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
PROJECT_NAME := "github.com/Karmenzind/kd"
2+
PKG := "$(PROJECT_NAME)"
3+
PKG_LIST := $(shell go list ${PKG}/... | grep -v /vendor/)
4+
GO_FILES := $(shell find . -name '*.go' | grep -v /vendor/ | grep -v _test.go)
5+
6+
.PHONY: all dep lint vet test test-coverage build clean
7+
8+
all: build
9+
10+
dep: ## Get the dependencies
11+
@go mod download
12+
13+
lint: ## Lint Golang files
14+
@golint -set_exit_status ${PKG_LIST}
15+
16+
vet: ## Run go vet
17+
@go vet ${PKG_LIST}
18+
19+
test: ## Run unittests
20+
@go test -short ${PKG_LIST}
21+
22+
test-coverage: ## Run tests with coverage
23+
@go test -short -coverprofile cover.out -covermode=atomic ${PKG_LIST}
24+
@cat cover.out >> coverage.txt
25+
26+
build: dep ## Build the binary file
27+
@go build -i -o build/main $(PKG)
28+
29+
clean: ## Remove previous build
30+
@rm -f ./build
31+
32+
help: ## Display this help screen
33+
@grep -h -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

README.md

+217
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,217 @@
1+
**当前状态** 初版本测试中,Archlinux已经无障碍使用
2+
3+
:stars: a crystal clear command-line dictionary, written in Go, supported Linux/Win/Mac**
4+
5+
**Go语言实现的简洁好用的命令行词典,跨平台、易于安装、持续维护更新**
6+
7+
本项目受[无道词典](https://github.com/ChestnutHeng/Wudao-dict)启发,在复刻Wudao核心功能的基础上增加了更丰富的特性。我是Wudao的多年用户,日常工作生活重度依赖随手`wd abandon`,但可惜这个项目已经很久未更新,且存在一些可以优化的地方,所以忍不住重写了一个,选择Go是为了方便地解决安装和跨平台问题。
8+
9+
![](https://raw.githubusercontent.com/Karmenzind/i/master/kd/kd_demo.gif)
10+
11+
**TOC**
12+
<!-- vim-markdown-toc GitLab -->
13+
14+
* [特性](#特性)
15+
* [安装](#安装)
16+
* [Linux/MacOS](#linuxmacos)
17+
* [Windows](#windows)
18+
* [用法](#用法)
19+
* [配置](#配置)
20+
* [颜色主题](#颜色主题)
21+
* [常见问题和解决方法](#常见问题和解决方法)
22+
* [MacOS弹出“无法打开”提醒](#macos弹出无法打开提醒)
23+
* [设置Pager后显示异常](#设置pager后显示异常)
24+
* [进度和计划](#进度和计划)
25+
* [卸载](#卸载)
26+
27+
<!-- vim-markdown-toc -->
28+
29+
## 特性
30+
31+
- 单文件运行,多平台兼容,无需安装任何依赖
32+
33+
> 理论上可兼容[所有平台/架构](https://gist.github.com/asukakenji/f15ba7e588ac42795f421b48b8aede63),但我只有Linux/Win可测试,欢迎使用其他平台的朋友试用反馈
34+
35+
- 支持查单词、词组( :eyes: 句子翻译功能也快写好了)
36+
- 极速响应,超低延迟
37+
- 本地词库(10w单词),可离线使用
38+
- 灵活的配置项,支持修改代理、配色等
39+
- 其他小功能:
40+
- 多次查询相同词汇会出现提醒并加入生词本
41+
42+
![](https://raw.githubusercontent.com/Karmenzind/i/master/kd/high_freq.png)
43+
44+
- 支持纯英文模式,只显示英译/英文例句
45+
46+
![](https://raw.githubusercontent.com/Karmenzind/i/master/kd/en_only.png)
47+
48+
> 更多功能正在开发中 :rocket:
49+
50+
<!-- - `kd --update`参数一键更新 -->
51+
52+
## 安装
53+
54+
****:
55+
56+
- 将命令中的`<URL>`**替换**[releases页面](https://github.com/Karmenzind/kd/releases)中对应你平台和架构的文件链接
57+
- 这里下载位置为示例,可以下载到任何地方,然后将路径加入PATH环境变量
58+
59+
60+
### Linux/MacOS
61+
62+
```bash
63+
sudo sh -c 'curl --create-dirs -L -o /usr/local/bin/kd <URL> && chmod +x /usr/local/bin/kd'
64+
```
65+
66+
<!-- ArchLinux推荐通过AUR一键安装`yay -S aur/kd`,后续直接通过包管理升级 -->
67+
68+
### Windows
69+
70+
用Powershell执行:
71+
72+
```powershell
73+
# 下载文件放入C:\bin
74+
Invoke-WebRequest -uri '<URL>' -OutFile ( New-Item -Path "C:\bin\kd.exe" -Force )
75+
# 将C:\bin加入PATH环境变量
76+
[Environment]::SetEnvironmentVariable("Path", $env:Path + ";C:\bin", "Machine")
77+
```
78+
79+
或手动下载文件,然后通过“计算机->属性->修改环境变量”修改PATH
80+
81+
## 用法
82+
83+
直接执行`kd <text>`查单词、词组(如`kd abandon``kd leave me alone`
84+
85+
<!-- (Windows可能需要`kd.exe`) -->
86+
87+
完整用法如下:
88+
89+
```
90+
❯ kd --help
91+
NAME:
92+
kd - A crystal clean command-line dictionary.
93+
94+
USAGE:
95+
kd [global options] [arguments...]
96+
97+
GLOBAL OPTIONS:
98+
--nocache, -n don't use cached result 不使用本地词库,查询网络结果
99+
--theme value, -T value choose the color theme for current query 选择颜色主题,仅当前查询生效 (default: temp)
100+
--server start server foreground 在前台启动服务端
101+
--daemon ensure/start the daemon process 启动守护进程
102+
--update check and update kd client 更新kd的可执行文件
103+
--generate-config generate config sample 生成配置文件,默认地址为~/.config/kd.toml
104+
--edit-config edit configuration file with the default editor 用默认编辑器打开配置文件
105+
--help, -h show help
106+
--version, -v print the version
107+
```
108+
109+
## 配置
110+
111+
配置文件地址:Linux/MacOS为~/.config/kd.toml,Windows为~/kd.toml
112+
113+
以下为可配置项和默认值,可执行`kd --generate-config`生成默认配置文件,执行`kd --edit-config`直接用编辑器打开配置文件
114+
115+
<!-- 修改配置文件后,请执行`kd --stop && kd --daemon`重启服务端 -->
116+
117+
```toml
118+
# 是否使用分页器,MacOS上默认false
119+
paging = true
120+
# 分页器命令,例如:less -F / bat / more
121+
pager_command = "less -F"
122+
123+
# 本地最多缓存的单词条数
124+
max_cached = 10000
125+
126+
# 结果中只显示英文(英译、英文例句等)
127+
english_only = false
128+
129+
# 颜色主题,支持:temp/wudao
130+
theme = "temp"
131+
132+
# 格式:http://<IP或域名>:<端口>。设置为空时,系统代理依然会生效
133+
# 如果需要频繁查询长句,可设置此项,否则本地IP有一定概率会被有道服务器暂时屏蔽
134+
http_proxy = ""
135+
136+
# 输出内容前自动清空终端,适合强迫症
137+
clear_screen = false
138+
139+
# (开发中)安装了emoji字体的可以输出一些emoji字符,just for fun
140+
enable_emoji = true
141+
142+
# 日志配置
143+
[logging]
144+
# 开启日志记录
145+
enable = false
146+
# 默认值:Linux/MacOS为/tmp/kd_<username>.log,windows为%TMPDIR%/kd_<username>.log
147+
path = ""
148+
level = "DEBUG"
149+
stderr = false
150+
```
151+
152+
## 颜色主题
153+
154+
目前支持以下配色,后续会增加更多
155+
156+
- `default` 暂定的默认配色
157+
158+
![](https://raw.githubusercontent.com/Karmenzind/i/master/kd/theme_default.png)
159+
160+
- `wudao` 复刻Wudao Dict的配色,鲜明易读
161+
162+
![](https://raw.githubusercontent.com/Karmenzind/i/master/kd/theme_wudao.png)
163+
164+
## 常见问题和解决方法
165+
166+
### MacOS弹出“无法打开”提醒
167+
168+
如果弹出“无法打开,因为Apple无法检查是否包含恶意软件”的提示,请执行:
169+
170+
```
171+
sudo xattr -r -d com.apple.quarantine <kd文件所在路径>
172+
```
173+
174+
### 设置Pager后显示异常
175+
176+
目前发现MacOS/Debian Bookworm设置分页器后,颜色渲染会失败,尚未解决。如果其他平台遇到此问题,请提交issue
177+
178+
配置文件中设置`paging = false`可规避此问题,如果还想使用分页器,可在shell中设置alias,例如bash/zsh可在bashrc/zshrc中添加:
179+
180+
```bash
181+
__kdwithpager() {
182+
kd ${@} | less -F
183+
}
184+
alias kd=__kdwithpager
185+
```
186+
187+
## 进度和计划
188+
189+
**进行中**
190+
191+
- 长句翻译
192+
- 通过命令一键更新
193+
194+
**近期**
195+
196+
- 支持bash/zsh/fish补全,包含命令补全和[热词](https://github.com/first20hours/google-10000-english)补全
197+
- 支持查看生词本功能
198+
- 可更新自动提醒
199+
- 支持tmux浮窗模式
200+
201+
**长期**
202+
203+
- 增加多种主题,包含常见配色如Gruvbox/Molokai,仿照bat实现
204+
- 支持全模块自定义显示配置
205+
- 引入多种查询源和词库,如stardict、必应等
206+
- 增加服务端
207+
- 支持通过fzf补全
208+
- Vim插件,浮窗显示查词结果
209+
- 离线词库周期更新
210+
211+
## 卸载
212+
213+
1. 删除kd可执行文件
214+
2. 删除配置文件和缓存目录
215+
- Linux: `rm -rfv ~/.config/kd.toml ~/.cache/kdcache`
216+
- MacOS: `rm -rfv ~/.config/kd.toml ~/Library/Caches/kdcache`
217+
- Win: `rm ~\kd.toml ~\kdcache`

0 commit comments

Comments
 (0)