refactor: use install.lua instead of install.sh
This commit is contained in:
@ -13,7 +13,8 @@ vim.api.nvim_create_autocmd('VimLeavePre', {
|
||||
M.query = function(data)
|
||||
if data.is_word == false or data.from == 'zh' then return end
|
||||
|
||||
data.path = vim.fn.expand(data.path or require('Trans').conf.dir .. '/ultimate.db')
|
||||
|
||||
data.path = data.path or require('Trans').conf.dir .. '/ultimate.db'
|
||||
data.engine = 'offline'
|
||||
data.formatter = data.formatter or M.formatter
|
||||
data.query_field = data.query_field or M.query_field
|
||||
@ -22,10 +23,10 @@ M.query = function(data)
|
||||
local dict = db:open(data.path)
|
||||
local db_name = data.db_name or 'stardict'
|
||||
local res = dict:select(db_name, {
|
||||
where = { word = data.str, },
|
||||
keys = data.query_field,
|
||||
limit = 1,
|
||||
})[1]
|
||||
where = { word = data.str, },
|
||||
keys = data.query_field,
|
||||
limit = 1,
|
||||
})[1]
|
||||
|
||||
if res then
|
||||
data.result = data.formatter(res)
|
||||
@ -89,16 +90,16 @@ local formatter = {
|
||||
exchange = function(res)
|
||||
if not exist(res.exchange) then return end
|
||||
local exchange_map = {
|
||||
['p'] = '过去式 ',
|
||||
['d'] = '过去分词 ',
|
||||
['i'] = '现在分词 ',
|
||||
['r'] = '比较级 ',
|
||||
['t'] = '最高级 ',
|
||||
['s'] = '复数 ',
|
||||
['0'] = '原型 ',
|
||||
['1'] = '类别 ',
|
||||
['3'] = '第三人称单数',
|
||||
['f'] = '第三人称单数',
|
||||
['p'] = '过去式 ',
|
||||
['d'] = '过去分词 ',
|
||||
['i'] = '现在分词 ',
|
||||
['r'] = '比较级 ',
|
||||
['t'] = '最高级 ',
|
||||
['s'] = '复数 ',
|
||||
['0'] = '原型 ',
|
||||
['1'] = '类别 ',
|
||||
['3'] = '第三人称单数',
|
||||
['f'] = '第三人称单数',
|
||||
}
|
||||
|
||||
local exchange = {}
|
||||
|
@ -60,7 +60,7 @@ return {
|
||||
-- no = '❌'
|
||||
},
|
||||
theme = 'default',
|
||||
dir = '$HOME/.vim/dict',
|
||||
dir = vim.fn.expand('$HOME/.vim/dict'),
|
||||
-- float = {
|
||||
-- width = 0.8,
|
||||
-- height = 0.8,
|
||||
|
@ -0,0 +1,42 @@
|
||||
return function()
|
||||
-- INFO :Chceck ultimate.db exists
|
||||
local dir = require('Trans').conf.dir
|
||||
local path = dir .. '/ultimate.db'
|
||||
if vim.fn.filereadable(path) == 1 then
|
||||
vim.notify('Database already exists', vim.log.WARN)
|
||||
return
|
||||
else
|
||||
vim.notify('Trying to download database', vim.log.INFO)
|
||||
end
|
||||
|
||||
|
||||
-- INFO :Download ultimate.db
|
||||
local uri = 'https://github.com/skywind3000/ECDICT-ultimate/releases/download/1.0.0/ecdict-ultimate-sqlite.zip'
|
||||
local loc = dir .. '/ultimate.zip'
|
||||
require('plenary.curl').get(uri, {
|
||||
output = loc,
|
||||
callback = function(output)
|
||||
if output.exsit == 0 and output.status == 200 then
|
||||
if vim.fn.executable('unzip') == 0 then
|
||||
vim.notify('unzip not found, Please unzip ' .. loc .. 'manually', vim.log.ERROR)
|
||||
return
|
||||
end
|
||||
|
||||
local cmd = string.format('unzip %s -d %s', path, dir)
|
||||
os.execute(cmd)
|
||||
os.remove(path)
|
||||
|
||||
vim.notify('Download database successfully', vim.log.INFO)
|
||||
return
|
||||
end
|
||||
|
||||
local debug_message = 'Download database failed:' .. vim.inspect(output)
|
||||
vim.notify(debug_message, vim.log.ERROR)
|
||||
end,
|
||||
})
|
||||
|
||||
-- INFO : tts dependencies
|
||||
if vim.fn.has('linux') == 0 and vim.fn.has('mac') == 0 then
|
||||
os.execute('cd ./tts/ && npm install')
|
||||
end
|
||||
end
|
||||
|
@ -1,8 +1,8 @@
|
||||
local check = function()
|
||||
local health = vim.health
|
||||
local ok = health.report_ok
|
||||
local warn = health.report_warn
|
||||
local error = health.report_error
|
||||
local health = vim.health
|
||||
local ok = health.report_ok
|
||||
local warn = health.report_warn
|
||||
local error = health.report_error
|
||||
|
||||
local has = vim.fn.has
|
||||
local executable = vim.fn.executable
|
||||
@ -54,7 +54,7 @@ local check = function()
|
||||
|
||||
|
||||
-- INFO :Check ultimate.db
|
||||
local db_path = vim.fn.expand(require('Trans').conf.dir .. '/ultimate.db')
|
||||
local db_path = require('Trans').conf.dir .. '/ultimate.db'
|
||||
if vim.fn.filereadable(db_path) == 1 then
|
||||
ok [[ultimate database found ]]
|
||||
else
|
||||
|
Reference in New Issue
Block a user