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
64 changes: 53 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,17 @@ shallow clones automatically. It aims to provide a similar experience to
- [Examples](#examples)
- [:closed_book: Close Buffers](#closed_book-close-buffers)
- [Parameters](#parameters)
- [:floppy_disk: Persist Repository](#floppy_disk-persist-repository)
- [Parameters](#parameters)
- [:toothbrush: Clean](#toothbrush-clean)
- [Parameters](#parameters)
- [:broom: Clean All](#broom-clean-all)
- [:eyeglasses: Parse](#eyeglasses-parse)
- [Parameters](#parameters)
- [:goggles: Toggle UI](#goggles-toggle-ui)
- [Parameters](#parameters)
- [:telescope: Telescope](#telescope-telescope)
- [:bone: Recent Repositories](#bone-recent-repositories)
- [:pick: Pickers](#pick-pickers)
- [:rock: History](#rock-history)
- [:gear: Options](#gear-options)
- [:spider_web: URL Parsing](#spider_web-url-parsing)
- [Supported URLs](#supported-urls)
Expand Down Expand Up @@ -105,9 +107,9 @@ Lazier (documentation will not be available until first use):
"GitDevClean",
"GitDevCleanAll",
"GitDevCloseBuffers",
"GitDevHistory",
"GitDevOpen",
"GitDevPersist",
"GitDevRecents",
"GitDevToggleUI",
"GitDevXDGHandle",
},
Expand Down Expand Up @@ -238,21 +240,26 @@ override default window configuration.
for this call.


### :telescope: Telescope
### :pick: Pickers
Supports `mini.pick`, `snacks`, `telescope` and a fallback to `vim.ui.select`.
By default, it will use the first picker provider it finds.
See `pickers` in [Options](#gear-options) below.

#### :bone: Recent Repositories
Command: `GitDevRecents`
Telescope: `Telescope git_dev recents`
#### :rock: History
API: `require("git-dev").pickers.history(local_opts)`
Command: `GitDevHistory`

Revisit previously opened repositories via a telescope extension.
A picker for previously opened repositories.

Opened repositories are tracked in a simple single file KV store. Its only
purpose (currently) is to be queried by the telescope extension for a
convenient way to re-open previously opened repositories.
purpose (currently) is to be queried by the history picker for a convenient way
to re-open previously opened repositories.

See `history` in [Options](#gear-options) below.


## :gear: Options
<!-- gitdev-config-start -->
```lua
M.config = {
-- Whether to delete an opened repository when nvim exits.
Expand Down Expand Up @@ -353,7 +360,7 @@ M.config = {
---@type "always"|"never"|"current"
delete_repo_dir = "current",
},
-- XDG handling of `nvim-getdev` URIs.
-- XDG handling of `nvim-gitdev` URIs.
-- Requires: `xdg-mime` and `xdg-open`.
xdg_handler = {
enabled = false,
Expand All @@ -367,10 +374,45 @@ M.config = {
content = '#!/usr/bin/env sh\nnvim -c GitDevXDGHandle\\ "$@"',
},
},
-- Picker configuration
---@type GitDevPickerOpts
pickers = {
---Nil for auto detection.
type = nil,
---A configuration for the `history` picker
history = {
separator = {
text = " │ ",
hl_group = "WinSeparator",
},
entry = {
-- Defines the width ratios of `repo_utl`, `ref` and `selected_path`
-- in the picker's results / entries buffer. Setting a `width` below
-- will override the ratio defined for the entry part.
ratios = { 5, 2, 3 },
repo_url = {
-- Fixed width.
-- If `nil`, it will be determined by window width and the ratios
-- array above.
width = nil,
hl_group = "String",
},
ref = {
width = nil,
hl_group = "Tag",
},
selected_path = {
width = nil,
hl_group = "LineNr",
},
},
},
},
-- More verbosity.
verbose = false,
}
```
<!-- gitdev-config-end -->

## :spider_web: URL Parsing
It is reasonable to assume that browsing arbitrary Git repositories will
Expand Down
3 changes: 2 additions & 1 deletion lua/git-dev/history.lua
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function History:add(repo, ref, opts, parsed_repo)
end

function History:get()
return self._store:get_all()
return vim.iter(self._store:least_recent_values(self.n)):rev():totable()
end

---@param record GitDevHistoryRecord
Expand All @@ -45,6 +45,7 @@ function History:key(record)
end

function History:update_opts(key, opts)
---@type GitDevHistoryRecord
local record = self._store:get(key)
if not record then
return
Expand Down
59 changes: 53 additions & 6 deletions lua/git-dev/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ local M = {}

local U = require "git-dev.utils"

-- gitdev-config-start
M.config = {
-- Whether to delete an opened repository when nvim exits.
-- If `true`, it will create an auto command for opened repositories
Expand Down Expand Up @@ -101,7 +102,7 @@ M.config = {
---@type "always"|"never"|"current"
delete_repo_dir = "current",
},
-- XDG handling of `nvim-getdev` URIs.
-- XDG handling of `nvim-gitdev` URIs.
-- Requires: `xdg-mime` and `xdg-open`.
xdg_handler = {
enabled = false,
Expand All @@ -115,12 +116,48 @@ M.config = {
content = '#!/usr/bin/env sh\nnvim -c GitDevXDGHandle\\ "$@"',
},
},
-- Picker configuration
---@type GitDevPickerOpts
pickers = {
---Nil for auto detection.
type = nil,
---A configuration for the `history` picker
history = {
separator = {
text = " │ ",
hl_group = "WinSeparator",
},
entry = {
-- Defines the width ratios of `repo_utl`, `ref` and `selected_path`
-- in the picker's results / entries buffer. Setting a `width` below
-- will override the ratio defined for the entry part.
ratios = { 5, 2, 3 },
repo_url = {
-- Fixed width.
-- If `nil`, it will be determined by window width and the ratios
-- array above.
width = nil,
hl_group = "String",
},
ref = {
width = nil,
hl_group = "Tag",
},
selected_path = {
width = nil,
hl_group = "LineNr",
},
},
},
},
-- More verbosity.
verbose = false,
}
-- gitdev-config-end

M.session = nil
M.history = nil
M.pickers = nil

local cd_func = {
global = U.cmd_to_func "cd",
Expand Down Expand Up @@ -536,6 +573,9 @@ M.setup = function(opts)
---@type GitDevSession
M.session = require("git-dev.session"):init()

-- Configure picker
M.pickers = require("git-dev.pickers").setup(M.config.pickers)

local xdg = require "git-dev.xdg"
if M.config.xdg_handler.enabled then
xdg.enable(M.config.xdg_handler)
Expand Down Expand Up @@ -595,11 +635,18 @@ M.setup = function(opts)
complete = complete_from_session,
})

vim.api.nvim_create_user_command(
"GitDevRecents",
"Telescope git_dev recents",
{ desc = "Revisit previously opened repositories." }
)
-- TODO: Remove
vim.api.nvim_create_user_command("GitDevRecents", function()
vim.notify(
"'GitDevRecents' has been renamed to 'GitDevHistory' and will be removed in the future.",
vim.log.levels.WARN
)
M.pickers:history()
end, { desc = "Revisit previously opened repositories." })

vim.api.nvim_create_user_command("GitDevHistory", function()
M.pickers:history()
end, { desc = "Revisit previously opened repositories." })
end

return M
1 change: 0 additions & 1 deletion lua/git-dev/parser.lua
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ end
---@field base_uri_format string
---@field default_org? string
---@field extra_domain_to_parser? table
---@field parse function
local Parser = {}

---@param o Parser
Expand Down
Loading