Skip to content
Open
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
12 changes: 9 additions & 3 deletions lua/http-codes.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,32 @@ M.http_codes = function()
require('telescope').extensions.http.list(M.config.open_url)
elseif M.config.use == 'fzf-lua' then
require('http-codes.fzf-lua').pick(M.config.open_url)
elseif M.config.use == 'snacks' then
require('http-codes.snacks').pick(M.config.open_url)
end
end

M.setup = function(user_config)
if pcall(require, 'fzf-lua') then
M.config.use = 'fzf-lua'
elseif pcall(require, 'snacks') then
M.config.use = 'snacks'
elseif pcall(require, 'telescope') then
M.config.use = 'telescope'
end

if M.config.use == nil then
vim.notify_once 'http-codes.nvim: install fzf-lua or telescope.nvim'
vim.notify_once 'http-codes.nvim: install fzf-lua or snakcs.nvim or telescope.nvim'
return
end

if user_config.use then M.config.use = user_config.use end

if not vim.tbl_contains({ 'fzf-lua', 'telescope' }, M.config.use) then
if
not vim.tbl_contains({ 'fzf-lua', 'snacks', 'telescope' }, M.config.use)
then
vim.notify_once(
'http-codes.nvim: must specify `use = {fzf-lua,telescope}` in setup.',
'http-codes.nvim: must specify `use = {fzf-lua,snacks,telescope}` in setup.',
vim.log.levels.ERROR
)
return
Expand Down
35 changes: 35 additions & 0 deletions lua/http-codes/snacks.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
local codes = require 'http-codes.codes'
local cached_items = nil

local function codes_to_snack_items(codes)
if cached_items then return cached_items end

local items = {}

local idx = 1
for status, _ in pairs(codes) do
table.insert(items, { idx = idx, text = status })
idx = idx + 1
end
cached_items = items
return items
end

return {
pick = function(open_url)
require('snacks.picker').pick(nil, {
title = 'HTTP Codes',
items = codes_to_snack_items(codes),
format = 'text',
layout = {
preset = 'select',
hidden = { 'preview' },
},
confirm = function(picker, item)
local link = codes[item.text]
picker:close()
vim.fn.jobstart(open_url:format(link))
end,
})
end,
}
3 changes: 2 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# http-codes.nvim

Quickly investigate HTTP status codes with the help of [mozilla](https://developer.mozilla.org/en-US/docs/Web/HTTP), including [telescope](https://github.com/barrett-ruth/telescope-http.nvim/) and [fzf-lua](https://github.com/ibhagwan/fzf-lua) integrations.
Quickly investigate HTTP status codes with the help of [mozilla](https://developer.mozilla.org/en-US/docs/Web/HTTP), including [telescope](https://github.com/barrett-ruth/telescope-http.nvim/), [fzf-lua](https://github.com/ibhagwan/fzf-lua) and [snacks.nvim](https://github.com/folke/snacks.nvim/blob/main/docs/picker.md) integrations.

## Installation

Expand All @@ -12,6 +12,7 @@ require('lazy').setup({
'barrett-ruth/http-codes.nvim',
config = true,
-- or 'nvim-telescope/telescope.nvim'
-- or 'folke/snacks.nvim'
dependencies = 'ibhagwan/fzf-lua'
keys = { { '<leader>H', '<cmd>HTTPCodes<cr>' }}
}
Expand Down