File tree Expand file tree Collapse file tree 3 files changed +27
-0
lines changed
Expand file tree Collapse file tree 3 files changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -298,6 +298,8 @@ image_support = false,
298298
299299- ` submit ` submit currently opened question
300300
301+ - ` open ` opens the current question in a default browser
302+
301303- ` random ` opens a random question
302304
303305- ` daily ` opens the question of today
Original file line number Diff line number Diff line change @@ -301,6 +301,8 @@ image_support = false, -- 将此设置为 `true` 将禁用问题描述的换行
301301
302302- ` submit ` 提交当前打开的问题
303303
304+ - ` open ` 在默认浏览器中打开当前问题。
305+
304306- ` random ` 打开一个随机问题
305307
306308- ` daily ` 打开今天的问题
Original file line number Diff line number Diff line change @@ -246,6 +246,28 @@ function cmd.ui_languages()
246246 languages :show ()
247247end
248248
249+ function cmd .open ()
250+ local utils = require (" leetcode.utils" )
251+ utils .auth_guard ()
252+ local q = utils .curr_question ()
253+
254+ if q then
255+ local command
256+ local os_name = vim .loop .os_uname ().sysname
257+
258+ if os_name == " Linux" then
259+ command = string.format (" xdg-open '%s'" , q .cache .link )
260+ elseif os_name == " Darwin" then
261+ command = string.format (" open '%s'" , q .cache .link )
262+ else
263+ -- Fallback to Windows if uname is not available or does not match Linux/Darwin.
264+ command = string.format (" start \"\" \" %s\" " , q .cache .link )
265+ end
266+
267+ os.execute (command )
268+ end
269+ end
270+
249271function cmd .fix ()
250272 require (" leetcode.cache.cookie" ).delete ()
251273 require (" leetcode.cache.problemlist" ).delete ()
@@ -373,6 +395,7 @@ cmd.commands = {
373395 daily = { cmd .qot },
374396 fix = { cmd .fix },
375397 yank = { cmd .yank },
398+ open = { cmd .open },
376399
377400 list = {
378401 cmd .problems ,
You can’t perform that action at this time.
0 commit comments