feat: initial commit
This commit is contained in:
parent
b440657495
commit
e48a8f9c0c
10 changed files with 153 additions and 78 deletions
42
doc/http-codes.txt
Normal file
42
doc/http-codes.txt
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
http-codes *http-codes.txt*
|
||||
|
||||
Author: Barrett Ruth <https://barrettruth.com>
|
||||
Homepage: <https://github.com/barrett-ruth/http-codes.nvim>
|
||||
|
||||
===============================================================================
|
||||
INTRODUCTION *http-codes.nvim*
|
||||
|
||||
https-codes.nvim lets you quickly investigate HTTP status codes with mozilla,
|
||||
supporting fzf-lua and telescope.nvim.
|
||||
|
||||
Author: Barrett Ruth <https://barrettruth.com>
|
||||
|
||||
===============================================================================
|
||||
SETUP *http-codes.setup()*
|
||||
>lua
|
||||
require('http-codes').setup(config)
|
||||
<
|
||||
Parameters: ~
|
||||
|
||||
{config} `(table)`: table containing configuration for http-codes.
|
||||
Defaults shown below.
|
||||
|
||||
Usage: ~
|
||||
>lua
|
||||
require('http-codes').setup({
|
||||
-- *REQUIRED*: 'fzf' or 'telescope'
|
||||
use = 'fzf',
|
||||
-- How the mozilla url is opened.
|
||||
-- Configured by default based on OS:
|
||||
open_url = 'xdg-open %s' -- UNIX
|
||||
-- = 'open %s' -- OSX
|
||||
-- = 'start %s' -- Windows
|
||||
})
|
||||
<
|
||||
===============================================================================
|
||||
COMMANDS *http-codes.commands*
|
||||
|
||||
:HTTPCodes Browse HTTP codes using the configured picker.
|
||||
|
||||
-------------------------------------------------------------------------------
|
||||
vim:tw=80:ft=help:
|
||||
36
lua/http-codes.lua
Normal file
36
lua/http-codes.lua
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
local M = {}
|
||||
|
||||
local open_url = require('http-codes.os').get_open_url()
|
||||
|
||||
M.config = {
|
||||
use = nil,
|
||||
open_url = open_url,
|
||||
}
|
||||
|
||||
M.http_codes = function()
|
||||
if M.config.use == 'telescope' then
|
||||
require('telescope').extensions.http.list(M.config.open_url)
|
||||
elseif M.config.use == 'fzf' then
|
||||
require('http-codes.fzf').pick(M.config.open_url)
|
||||
end
|
||||
end
|
||||
|
||||
M.setup = function(user_config)
|
||||
if
|
||||
user_config.use == nil
|
||||
or not vim.tbl_contains({ 'fzf', 'telescope' }, user_config.use)
|
||||
then
|
||||
vim.notify_once 'http-codes.nvim: must specify `use = {fzf,telescope}` in setup.'
|
||||
return
|
||||
end
|
||||
|
||||
M.config = vim.tbl_deep_extend('force', M.config, user_config)
|
||||
|
||||
if M.config.use == 'telescope' then
|
||||
require('http-codes.telescope').setup()
|
||||
end
|
||||
|
||||
vim.api.nvim_create_user_command('HTTPCodes', M.http_codes, {})
|
||||
end
|
||||
|
||||
return M
|
||||
15
lua/http-codes/fzf.lua
Normal file
15
lua/http-codes/fzf.lua
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
local codes = require 'http-codes.codes'
|
||||
|
||||
return {
|
||||
pick = function(open_url)
|
||||
require('fzf-lua').fzf_exec(vim.tbl_keys(codes), {
|
||||
actions = {
|
||||
default = function(selected)
|
||||
local link = codes[selected[1]]
|
||||
|
||||
vim.fn.jobstart(open_url:format(link))
|
||||
end,
|
||||
},
|
||||
})
|
||||
end,
|
||||
}
|
||||
17
lua/http-codes/os.lua
Normal file
17
lua/http-codes/os.lua
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
local OS_TO_OPEN_URL = {
|
||||
OSX = 'open %s',
|
||||
Windows = 'start %s',
|
||||
}
|
||||
|
||||
local function get_os()
|
||||
if jit then return jit.os end
|
||||
|
||||
local fh, _ = assert(io.popen('uname -o 2>/dev/null', 'r'))
|
||||
if fh then return fh:read() end
|
||||
|
||||
return fh and fh:read() or 'Windows'
|
||||
end
|
||||
|
||||
return {
|
||||
get_open_url = function() return OS_TO_OPEN_URL[get_os()] or 'xdg-open %s' end,
|
||||
}
|
||||
3
lua/http-codes/telescope.lua
Normal file
3
lua/http-codes/telescope.lua
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
return {
|
||||
setup = function() require('telescope').load_extension 'http' end,
|
||||
}
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
return function()
|
||||
-- ask LuaJIT first
|
||||
-- will return "Windows", "Linux", "OSX", "BSD", "POSIX" or "Other"
|
||||
if jit then return jit.os end
|
||||
|
||||
-- Unix, Linux variants
|
||||
local fh, _ = assert(io.popen('uname -o 2>/dev/null', 'r'))
|
||||
if fh then return fh:read() end
|
||||
|
||||
return 'Windows'
|
||||
end
|
||||
|
|
@ -1,26 +1,5 @@
|
|||
local ok, telescope = pcall(require, 'telescope')
|
||||
|
||||
if not ok then
|
||||
error 'Install nvim-telescope/telescope.nvim to use barrett-ruth/telescope-http.nvim.'
|
||||
end
|
||||
|
||||
local list = require 'telescope._extensions.http.list'
|
||||
local osname = require 'telescope._extensions.getOS'
|
||||
|
||||
local open_url_os = {
|
||||
['OSX'] = { open_url = 'open %s' },
|
||||
['Windows'] = { open_url = 'start %s' },
|
||||
}
|
||||
|
||||
local default_opts = open_url_os[osname()]
|
||||
if not default_opts then default_opts = { open_url = 'xdg-open %s' } end
|
||||
local opts = {}
|
||||
|
||||
return telescope.register_extension {
|
||||
setup = function(http_opts, _)
|
||||
opts = vim.tbl_extend('force', default_opts, http_opts)
|
||||
end,
|
||||
exports = {
|
||||
list = function(_) list(_, opts) end,
|
||||
},
|
||||
return require('telescope').register_extension {
|
||||
exports = { list = list },
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,11 +4,11 @@ local pickers = require 'telescope.pickers'
|
|||
local sorters = require 'telescope.sorters'
|
||||
local state = require 'telescope.actions.state'
|
||||
|
||||
local codes = require 'telescope._extensions.http.codes'
|
||||
local codes = require 'http-codes.codes'
|
||||
|
||||
return function(_, http_opts)
|
||||
return function(open_url)
|
||||
pickers
|
||||
.new(_, {
|
||||
.new(nil, {
|
||||
prompt_title = 'HTTP Codes',
|
||||
finder = finders.new_table {
|
||||
results = vim.tbl_keys(codes),
|
||||
|
|
@ -21,7 +21,7 @@ return function(_, http_opts)
|
|||
local selection = state.get_selected_entry()
|
||||
local link = codes[selection[1]]
|
||||
|
||||
vim.fn.jobstart(http_opts.open_url:format(link))
|
||||
vim.fn.jobstart(open_url:format(link))
|
||||
end)
|
||||
return true
|
||||
end,
|
||||
|
|
|
|||
74
readme.md
74
readme.md
|
|
@ -1,55 +1,49 @@
|
|||
# telescope-http.nvim
|
||||
# http-codes.nvim
|
||||
|
||||
Quickly investigate HTTP status codes with the help of
|
||||
[telescope.nvim](https://github.com/nvim-telescope/telescope.nvim)
|
||||
and [mozilla](https://developer.mozilla.org/en-US/docs/Web/HTTP).
|
||||
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.
|
||||
|
||||
## Installation
|
||||
|
||||
Install via your favorite package manager, like [paq](https://github.com/savq/paq-nvim):
|
||||
Install via your favorite package manager, like [lazy](https://github.com/folke/lazy.nvim):
|
||||
|
||||
```lua
|
||||
require 'paq' {
|
||||
'savq/paq-nvim',
|
||||
'barrett-ruth/telescope-http.nvim'
|
||||
}
|
||||
```
|
||||
|
||||
Then load the extension:
|
||||
|
||||
```lua
|
||||
require('telescope').load_extension 'http'
|
||||
```
|
||||
|
||||
## Dependencies
|
||||
|
||||
- [telescope.nvim](https://github.com/nvim-telescope/telescope.nvim)
|
||||
|
||||
## Configuration
|
||||
|
||||
```lua
|
||||
require('telescope').setup {
|
||||
extensions = {
|
||||
http = {
|
||||
-- How the mozilla url is opened. By default will be configured based on OS:
|
||||
require('lazy').setup({
|
||||
{
|
||||
'barrett-ruth/http-codes.nvim'
|
||||
opts = {
|
||||
-- *REQUIRED*: 'fzf' or 'telescope'
|
||||
use = 'fzf',
|
||||
-- How the mozilla url is opened.
|
||||
-- Configured by default based on OS:
|
||||
open_url = 'xdg-open %s' -- UNIX
|
||||
-- open_url = 'open %s' -- OSX
|
||||
-- open_url = 'start %s' -- Windows
|
||||
}
|
||||
-- = 'open %s' -- OSX
|
||||
-- = 'start %s' -- Windows
|
||||
},
|
||||
dependencies = {
|
||||
-- choose your picker:
|
||||
'ibhagwan/fzf-lua'
|
||||
-- 'nvim-telescope/telescope.nvim',
|
||||
},
|
||||
}
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
## [Configuration](./doc/http-codes.txt)
|
||||
|
||||
## Usage
|
||||
|
||||
Creating a mapping for the following command in vim:
|
||||
|
||||
```vim
|
||||
:Telescope http list
|
||||
```
|
||||
|
||||
or lua:
|
||||
Use the exposed command in vimscript:
|
||||
|
||||
```lua
|
||||
require('telescope').extensions.http.list()
|
||||
:HTTPCodes
|
||||
```
|
||||
|
||||
or in lua:
|
||||
|
||||
```lua
|
||||
require('http-codes').http_codes()
|
||||
```
|
||||
|
||||
## 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