Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,8 @@ image_support = false,

- `submit` submit currently opened question

- `open` opens the current question in a default browser

- `random` opens a random question

- `daily` opens the question of today
Expand Down
2 changes: 2 additions & 0 deletions README.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,8 @@ image_support = false, -- 将此设置为 `true` 将禁用问题描述的换行

- `submit` 提交当前打开的问题

- `open` 在默认浏览器中打开当前问题。

- `random` 打开一个随机问题

- `daily` 打开今天的问题
Expand Down
23 changes: 23 additions & 0 deletions lua/leetcode/command/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,28 @@ function cmd.ui_languages()
languages:show()
end

function cmd.open()
local utils = require("leetcode.utils")
utils.auth_guard()
local q = utils.curr_question()

if q then
local command
local os_name = vim.loop.os_uname().sysname

if os_name == "Linux" then
command = string.format("xdg-open '%s'", q.cache.link)
elseif os_name == "Darwin" then
command = string.format("open '%s'", q.cache.link)
else
-- Fallback to Windows if uname is not available or does not match Linux/Darwin.
command = string.format("start \"\" \"%s\"", q.cache.link)
end

os.execute(command)
end
end

function cmd.fix()
require("leetcode.cache.cookie").delete()
require("leetcode.cache.problemlist").delete()
Expand Down Expand Up @@ -373,6 +395,7 @@ cmd.commands = {
daily = { cmd.qot },
fix = { cmd.fix },
yank = { cmd.yank },
open = { cmd.open },

list = {
cmd.problems,
Expand Down