From 4b9e8a7ab9f89f3566c3017c787740e777a33a9f Mon Sep 17 00:00:00 2001 From: Moeta Yuko Date: Tue, 13 Feb 2024 13:29:16 +0800 Subject: [PATCH 1/3] chore: remove useless relative_path --- lua/Trans/init.lua | 8 -------- 1 file changed, 8 deletions(-) diff --git a/lua/Trans/init.lua b/lua/Trans/init.lua index b592e08..decb59a 100644 --- a/lua/Trans/init.lua +++ b/lua/Trans/init.lua @@ -42,12 +42,4 @@ local M = metatable('core', { M.metatable = metatable ----Get abs_path of file ----@param path string[] ----@param is_dir boolean? ----@return string -function M.relative_path(path, is_dir) - return M.plugin_dir .. table.concat(path, sep) .. (is_dir and sep or '') -end - return M From 863213bbc87324674026af209b8f6fdbbd9acfe4 Mon Sep 17 00:00:00 2001 From: Moeta Yuko Date: Tue, 13 Feb 2024 13:37:19 +0800 Subject: [PATCH 2/3] fix: fix plugin_dir and use left slash as path separator for windows Fixes #46 --- lua/Trans/backend/offline.lua | 2 +- lua/Trans/core/install.lua | 4 ++-- lua/Trans/health.lua | 4 ++-- lua/Trans/init.lua | 7 ++----- 4 files changed, 7 insertions(+), 10 deletions(-) diff --git a/lua/Trans/backend/offline.lua b/lua/Trans/backend/offline.lua index 2ef618e..c3681f0 100644 --- a/lua/Trans/backend/offline.lua +++ b/lua/Trans/backend/offline.lua @@ -1,7 +1,7 @@ local Trans = require 'Trans' local db = require 'sqlite.db' -local path = Trans.conf.dir .. Trans.separator .. 'ultimate.db' +local path = Trans.conf.dir .. '/ultimate.db' local dict = db:open(path) local db_name = 'stardict' vim.api.nvim_create_autocmd('VimLeavePre', { diff --git a/lua/Trans/core/install.lua b/lua/Trans/core/install.lua index e72a5c6..b811ef5 100644 --- a/lua/Trans/core/install.lua +++ b/lua/Trans/core/install.lua @@ -5,7 +5,7 @@ return function() local fn = vim.fn -- INFO :Check ultimate.db exists local dir = Trans.conf.dir - local path = dir .. 'ultimate.db' + local path = dir .. '/ultimate.db' if fn.isdirectory(dir) == 0 then fn.mkdir(dir, 'p') @@ -18,7 +18,7 @@ return function() -- INFO :Download ultimate.db local uri = 'https://github.com/skywind3000/ECDICT-ultimate/releases/download/1.0.0/ecdict-ultimate-sqlite.zip' - local zip = dir .. 'ultimate.zip' + local zip = dir .. '/ultimate.zip' local continue = fn.filereadable(zip) == 1 local handle = function(output) if output.exit == 0 and fn.filereadable(zip) then diff --git a/lua/Trans/health.lua b/lua/Trans/health.lua index bac5571..b039e8c 100644 --- a/lua/Trans/health.lua +++ b/lua/Trans/health.lua @@ -57,7 +57,7 @@ local function check_binary_dependencies() end local function check_database() - local db_path = Trans.conf.dir .. Trans.separator .. 'ultimate.db' + local db_path = Trans.conf.dir .. '/ultimate.db' if fn.filereadable(db_path) == 1 then ok [[ultimate database found ]] else @@ -69,7 +69,7 @@ local function check_database() end local function check_configure_file() - local path = fn.expand(Trans.conf.dir .. Trans.separator .. 'Trans.json') + local path = fn.expand(Trans.conf.dir .. '/Trans.json') if not fn.filereadable(path) then warn 'Backend configuration file[%s] not found' end diff --git a/lua/Trans/init.lua b/lua/Trans/init.lua index decb59a..4b222ad 100644 --- a/lua/Trans/init.lua +++ b/lua/Trans/init.lua @@ -25,19 +25,16 @@ local system = uname == 'Linux' and (vim.fn.executable 'termux-api-start' == 1 and 'termux' or 'linux') or error 'Unknown System, Please Report Issue' -local sep = system == 'win' and '\\\\' or '/' ---@class Trans ---@field style table @Style module ---@field cache table @Cache for translated data object ---@field plugin_dir string @Plugin directory ----@field separator string @Path separator ----@field system 'mac'|'win'|'termux'|'linux' @Path separator +---@field system 'mac'|'win'|'termux'|'linux' @Operating system local M = metatable('core', { cache = {}, style = metatable 'style', - separator = sep, system = system, - plugin_dir = debug.getinfo(1, 'S').source:sub(2):match('(.-)lua' .. sep .. 'Trans'), + plugin_dir = vim.fn.fnamemodify(debug.getinfo(1, 'S').source:sub(2), ':p:h:h:h'), }) M.metatable = metatable From a13c09e95f03de54fe8ec6f39983d3a9ce03ed77 Mon Sep 17 00:00:00 2001 From: Moeta Yuko Date: Tue, 13 Feb 2024 14:47:36 +0800 Subject: [PATCH 3/3] feat: use powershell to unzip on windows --- lua/Trans/core/install.lua | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/lua/Trans/core/install.lua b/lua/Trans/core/install.lua index b811ef5..9de9216 100644 --- a/lua/Trans/core/install.lua +++ b/lua/Trans/core/install.lua @@ -22,12 +22,11 @@ return function() local continue = fn.filereadable(zip) == 1 local handle = function(output) if output.exit == 0 and fn.filereadable(zip) then - if fn.executable 'unzip' == 0 then - vim.notify('unzip not found, Please unzip ' .. zip .. 'manually', vim.log.ERROR) - return - end - - local cmd = string.format('unzip %s -d %s', zip, dir) + local cmd = + Trans.system == 'win' and + string.format('powershell.exe -Command "Expand-Archive -Force %s %s"', zip, dir) or + fn.executable('unzip') == 1 and string.format('unzip %s -d %s', zip, dir) or + error('unzip not found, Please unzip ' .. zip .. ' manually') local status = os.execute(cmd) os.remove(zip) if status == 0 then