Merge pull request #7 from barrettruth/feature/snacks
feat: add snacks.picker support
This commit is contained in:
commit
7586374e68
4 changed files with 90 additions and 58 deletions
|
|
@ -1,38 +1,35 @@
|
||||||
http-codes *http-codes.txt*
|
http-codes *http-codes.txt*
|
||||||
|
|
||||||
Author: Barrett Ruth <https://barrettruth.com>
|
Author: Barrett Ruth <https://barrettruth.com>
|
||||||
Homepage: <https://github.com/barrett-ruth/http-codes.nvim>
|
Homepage: <https://github.com/barrettruth/http-codes.nvim>
|
||||||
|
|
||||||
===============================================================================
|
===============================================================================
|
||||||
INTRODUCTION *http-codes.nvim*
|
INTRODUCTION *http-codes.nvim*
|
||||||
|
|
||||||
https-codes.nvim lets you quickly investigate HTTP status codes with mozilla,
|
http-codes.nvim lets you quickly investigate HTTP status codes with Mozilla,
|
||||||
supporting fzf-lua and telescope.nvim.
|
supporting fzf-lua, snacks.nvim, and telescope.nvim.
|
||||||
|
|
||||||
Author: Barrett Ruth <https://barrettruth.com>
|
|
||||||
|
|
||||||
===============================================================================
|
===============================================================================
|
||||||
SETUP *http-codes.setup()*
|
CONFIGURATION *http-codes.config*
|
||||||
>lua
|
|
||||||
require('http-codes').setup(config)
|
|
||||||
<
|
|
||||||
Parameters: ~
|
|
||||||
|
|
||||||
{config} `(table)`: table containing configuration for http-codes.
|
Configure via `vim.g.http_codes` before the plugin loads:
|
||||||
Defaults shown below.
|
|
||||||
|
|
||||||
Usage: ~
|
|
||||||
>lua
|
>lua
|
||||||
require('http-codes').setup({
|
vim.g.http_codes = {
|
||||||
-- defaults to available picker: 'fzf-lua' or 'telescope'
|
use = 'fzf-lua',
|
||||||
use = 'fzf-lua'
|
open_url = 'xdg-open %s',
|
||||||
-- How the mozilla url is opened.
|
}
|
||||||
-- Configured by default based on OS:
|
|
||||||
open_url = 'xdg-open %s' -- UNIX
|
|
||||||
-- = 'open %s' -- OSX
|
|
||||||
-- = 'start %s' -- Windows
|
|
||||||
})
|
|
||||||
<
|
<
|
||||||
|
Options: ~
|
||||||
|
|
||||||
|
{use} `(string|nil)`: Picker to use: 'fzf-lua', 'snacks', or
|
||||||
|
'telescope'. Auto-detected if not specified.
|
||||||
|
|
||||||
|
{open_url} `(string|nil)`: Command to open URLs. Uses `%s` as placeholder.
|
||||||
|
Defaults based on OS:
|
||||||
|
- Linux: 'xdg-open %s'
|
||||||
|
- macOS: 'open %s'
|
||||||
|
- Windows: 'start %s'
|
||||||
|
|
||||||
===============================================================================
|
===============================================================================
|
||||||
COMMANDS *http-codes.commands*
|
COMMANDS *http-codes.commands*
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -24,19 +24,21 @@ local function init()
|
||||||
if not config.use then
|
if not config.use then
|
||||||
if pcall(require, 'fzf-lua') then
|
if pcall(require, 'fzf-lua') then
|
||||||
config.use = 'fzf-lua'
|
config.use = 'fzf-lua'
|
||||||
|
elseif pcall(require, 'snacks') then
|
||||||
|
config.use = 'snacks'
|
||||||
elseif pcall(require, 'telescope') then
|
elseif pcall(require, 'telescope') then
|
||||||
config.use = 'telescope'
|
config.use = 'telescope'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if not config.use then
|
if not config.use then
|
||||||
vim.notify_once('http-codes.nvim: install fzf-lua or telescope.nvim', vim.log.levels.ERROR)
|
vim.notify_once('http-codes.nvim: install fzf-lua, snacks.nvim, or telescope.nvim', vim.log.levels.ERROR)
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
if not vim.tbl_contains({ 'fzf-lua', 'telescope' }, config.use) then
|
if not vim.tbl_contains({ 'fzf-lua', 'snacks', 'telescope' }, config.use) then
|
||||||
vim.notify_once(
|
vim.notify_once(
|
||||||
"http-codes.nvim: 'use' must be 'fzf-lua' or 'telescope'",
|
"http-codes.nvim: 'use' must be 'fzf-lua', 'snacks', or 'telescope'",
|
||||||
vim.log.levels.ERROR
|
vim.log.levels.ERROR
|
||||||
)
|
)
|
||||||
return false
|
return false
|
||||||
|
|
@ -59,6 +61,8 @@ function M.pick()
|
||||||
require('telescope').extensions.http.list(config.open_url)
|
require('telescope').extensions.http.list(config.open_url)
|
||||||
elseif config.use == 'fzf-lua' then
|
elseif config.use == 'fzf-lua' then
|
||||||
require('http-codes.fzf-lua').pick(config.open_url)
|
require('http-codes.fzf-lua').pick(config.open_url)
|
||||||
|
elseif config.use == 'snacks' then
|
||||||
|
require('http-codes.snacks').pick(config.open_url)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
35
lua/http-codes/snacks.lua
Normal file
35
lua/http-codes/snacks.lua
Normal file
|
|
@ -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,
|
||||||
|
}
|
||||||
58
readme.md
58
readme.md
|
|
@ -1,51 +1,47 @@
|
||||||
# http-codes.nvim
|
# 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), with telescope, fzf-lua, and snacks.nvim integrations.
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
Install via your favorite package manager, like [lazy](https://github.com/folke/lazy.nvim):
|
Install using your package manager of choice or via [luarocks](https://luarocks.org/modules/barrettruth/http-codes.nvim):
|
||||||
|
|
||||||
```lua
|
```
|
||||||
require('lazy').setup({
|
luarocks install http-codes.nvim
|
||||||
{
|
|
||||||
'barrett-ruth/http-codes.nvim',
|
|
||||||
config = true,
|
|
||||||
-- or 'nvim-telescope/telescope.nvim'
|
|
||||||
dependencies = 'ibhagwan/fzf-lua'
|
|
||||||
keys = { { '<leader>H', '<cmd>HTTPCodes<cr>' }}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## [Configuration](./doc/http-codes.txt)
|
## Dependencies
|
||||||
|
|
||||||
`http-codes.nvim` uses telescope or fzf-lua (whichever you've installed), which can be manually overidden.
|
One of:
|
||||||
|
- [fzf-lua](https://github.com/ibhagwan/fzf-lua)
|
||||||
|
- [snacks.nvim](https://github.com/folke/snacks.nvim)
|
||||||
|
- [telescope.nvim](https://github.com/nvim-telescope/telescope.nvim)
|
||||||
|
|
||||||
`http-codes.nvim` opens the Mozilla documentation URLs based on your operating system. This can be overidden.
|
## Configuration
|
||||||
|
|
||||||
| OS | open_url |
|
Configure via `vim.g.http_codes` before the plugin loads:
|
||||||
| ------- | ------------- |
|
|
||||||
| Windows | `start %s` |
|
|
||||||
| OSX | `open %s` |
|
|
||||||
| UNIX | `xdg-open %s` |
|
|
||||||
|
|
||||||
See [the docs](./doc/http-codes.txt) for more information.
|
```lua
|
||||||
|
vim.g.http_codes = {
|
||||||
|
use = 'fzf-lua', -- or 'snacks' or 'telescope', auto-detected by default
|
||||||
|
open_url = 'xdg-open %s', -- OS-specific by default
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
| OS | Default open_url |
|
||||||
|
| ------- | ---------------- |
|
||||||
|
| Windows | `start %s` |
|
||||||
|
| macOS | `open %s` |
|
||||||
|
| Linux | `xdg-open %s` |
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
Use the exposed command in vimscript:
|
```vim
|
||||||
|
|
||||||
```lua
|
|
||||||
:HTTPCodes
|
:HTTPCodes
|
||||||
```
|
```
|
||||||
|
|
||||||
or in lua:
|
## Documentation
|
||||||
|
|
||||||
```lua
|
```vim
|
||||||
require('http-codes').http_codes()
|
:help http-codes.nvim
|
||||||
```
|
```
|
||||||
|
|
||||||
## Migration
|
|
||||||
|
|
||||||
If migrating from [telescope-http.nvim](https://github.com/barrett-ruth/telescope-http.nvim), follow the above instructions—no telescope-specific config is necessary.
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue