|
59 | 59 | -- ---- 新的寫法(「三種 os 跑法」全跑一遍)
|
60 | 60 | -- local function generic_open(dest)
|
61 | 61 | -- -- 以下處理「-removeopen 」,為特此標示去移除開頭之「open和start等」,有些指令不能有開頭command!
|
62 |
| --- if dest:match("^-removeopen ") then |
63 |
| --- local dest = dest:gsub("^-removeopen ", "") |
| 62 | +-- if string.match(dest, "^-removeopen ") then |
| 63 | +-- local dest = string.gsub(dest, "^-removeopen ", "") |
64 | 64 | -- -- local f = io.popen(dest)
|
65 | 65 | -- -- f = nil
|
66 | 66 | -- return io.popen(dest) and true or false
|
@@ -125,38 +125,38 @@ local oscmd = cmd_table[os_name]
|
125 | 125 | ---------------------------------------------------------------
|
126 | 126 | -- --- 用 Rime 名稱判斷 os(會有不知名 Rime 輸入法軟體無法辨識的問題)
|
127 | 127 | -- local d_c_name = rime_api.get_distribution_code_name() or "none"
|
128 |
| --- local oscmd = d_c_name:find("Weasel") and 'start "" ' or -- weasel |
129 |
| --- d_c_name:find("windows") and 'start "" ' or -- fcitx5-windows |
130 |
| --- d_c_name:find("Squirrel") and 'open ' or -- squirrel |
131 |
| --- d_c_name:find("macos") and 'open ' or -- fcitx5-macos |
132 |
| --- d_c_name:find("ibus") and 'xdg-open ' or -- ibus-rime |
| 128 | +-- local oscmd = string.find(d_c_name, "Weasel") and 'start "" ' or -- weasel |
| 129 | +-- string.find(d_c_name, "windows") and 'start "" ' or -- fcitx5-windows |
| 130 | +-- string.find(d_c_name, "Squirrel") and 'open ' or -- squirrel |
| 131 | +-- string.find(d_c_name, "macos") and 'open ' or -- fcitx5-macos |
| 132 | +-- string.find(d_c_name, "ibus") and 'xdg-open ' or -- ibus-rime |
133 | 133 | -- -- -- 以下防名稱有疏漏,且避免小狼毫問題當機!於此判定是否為 windows!
|
134 |
| --- -- -- os.getenv()可能為 nil,不可直接lower「:lower()」,會報錯! |
135 |
| --- os.getenv('OS') and os.getenv('OS'):lower():match("windows") and 'start "" ' or |
136 |
| --- os.getenv('OS') and os.getenv('OS'):lower():match("^mingw") and 'start "" ' or |
137 |
| --- os.getenv('OS') and os.getenv('OS'):lower():match("^cygwin") and 'start "" ' or |
138 |
| --- -- package.config:sub(1,1) == '\\' and 'start "" ' or -- 該條目會拖慢呼叫速度!!! |
| 134 | +-- -- -- os.getenv()可能為 nil,不可直接「sub()」或「lower()」,會報錯! |
| 135 | +-- os.getenv('OS') and string.match(string.lower(os.getenv('OS')), "windows") and 'start "" ' or |
| 136 | +-- os.getenv('OS') and string.match(string.lower(os.getenv('OS')), "^mingw") and 'start "" ' or |
| 137 | +-- os.getenv('OS') and string.match(string.lower(os.getenv('OS')), "^cygwin") and 'start "" ' or |
| 138 | +-- -- string.sub(package.config, 1,1) == '\\' and 'start "" ' or -- 該條目會拖慢呼叫速度!!! |
139 | 139 | -- 'xdg-open '
|
140 | 140 | ---------------------------------------------------------------
|
141 | 141 | -- --- 用 os.getenv 參數判斷 os
|
142 | 142 | -- local oscmd = os.getenv("USERPROFILE") and 'start "" ' or -- Windows
|
143 |
| --- os.getenv("HOME") and os.getenv("HOME"):sub(1,7) == '/Users/' and 'open ' or -- Mac |
144 |
| --- os.getenv("HOME") and os.getenv("HOME"):sub(1,6) == '/home/' and 'xdg-open ' or -- Linux |
| 143 | +-- os.getenv("HOME") and string.sub(os.getenv("HOME"), 1,7) == '/Users/' and 'open ' or -- Mac |
| 144 | +-- os.getenv("HOME") and string.sub(os.getenv("HOME"), 1,6) == '/home/' and 'xdg-open ' or -- Linux |
145 | 145 | -- 'xdg-open '
|
146 | 146 | -- -- nil -- 設 nil 可使無法判斷之 os 不亂跑無效執行!
|
147 | 147 | -- -- 測試 Windows 之 os.getenv("HOME") 為 nil,但網路資訊說明某些 Win 版本不為 nil?
|
148 | 148 | -- -- os.getenv("USERPROFILE")只在 Win 不為 nil。
|
149 |
| --- -- os.getenv()可能為 nil,不可直接「:sub()」或「lower()」,會報錯! |
| 149 | +-- -- os.getenv()可能為 nil,不可直接「sub()」或「lower()」,會報錯! |
150 | 150 | ---------------------------------------------------------------
|
151 | 151 | local function generic_open(dest)
|
152 |
| - if oscmd ~= nil and not dest:match("^-removeopen ") then |
153 |
| - -- local f = io.popen( oscmd .. dest) |
| 152 | + if oscmd ~= nil and not string.match(dest, "^-removeopen ") then |
| 153 | + -- local f = io.popen( oscmd .. dest ) |
154 | 154 | -- f:close() -- 不能使用,於 0.17.0 以上之小狼毫會當機崩潰
|
155 | 155 | -- f = nil
|
156 |
| - return io.popen( oscmd .. dest) and true or false |
| 156 | + return io.popen( oscmd .. dest ) and true or false |
157 | 157 | -- 以下處理「-removeopen 」,為特此標示去移除開頭之「open和start等」,有些指令不能有開頭command!
|
158 | 158 | elseif oscmd ~= nil then
|
159 |
| - local dest = dest:gsub("^-removeopen ", "") |
| 159 | + local dest = string.gsub(dest, "^-removeopen ", "") |
160 | 160 | -- local f = io.popen(dest)
|
161 | 161 | -- f:close() -- 不能使用,於 0.17.0 以上之小狼毫會當機崩潰
|
162 | 162 | -- f = nil
|
|
0 commit comments