An advanced git search extension for Telescope
and fzf-lua
.
Search your git history by commit message, content and author in Neovim
:Telescope advanced_git_search {function_name}
or in lua
require('telescope').extensions.advanced_git_search.{function_name}()
or through another Telescope picker
execute :AdvancedGitSearch
, choose your picker and press <CR>
require('advanced_git_search.fzf').{function_name}()
or through another picker
execute :AdvancedGitSearch
, choose your picker and press <CR>
Your usual search experience. See the individual commands for the grep behaviour.
@
The prompt is split on @
. Everything following the @
is the pattern for
the author name.
Opens a window with a list of all previous commit.
Grep behaviour: filter on added, updated or removed code (log content: -G
option in git).
<CR>
Opens a diff of the current file with the selected commit<C-e>
show the entire commit for all files in neovim with diff plugin<C-o>
Open the selected commit in the browser<C-y>
copy the commit hash to clipboardOpens a window with a list of git commits that changed the current file (renames included).
Grep behaviour: filter on added, updated or removed code (log content: -G
option in git).
<CR>
Opens a diff of the current file with the selected commit<C-e>
show the entire commit for all files in neovim with diff plugin<C-o>
Open the selected commit in the browser<C-y>
copy the commit hash to clipboardOpens a window with a list of git commits that changed the current file (renames included).
Grep behaviour: filter on commit message.
<CR>
Opens a diff of the current file with the selected commit<C-e>
show the entire commit for all files in neovim with diff plugin<C-o>
Open the selected commit in the browser<C-y>
copy the commit hash to clipboardOpens a window with a list of previous commit logs with respect to selected lines
Grep behaviour: filter on commit message.
This workaround only applies when you use the following command. (Telescope)
:Telescope advanced_git_search diff_commit_line
First you have to select the lines in visual mode, then go back to normal mode and execute this command. To make a bit easier, you can wrap it in a user command and define a keybind:
vim.api.nvim_create_user_command(
"DiffCommitLine",
"lua require('telescope').extensions.advanced_git_search.diff_commit_line()",
{ range = true }
)
vim.api.nvim_set_keymap(
"v",
"<leader>dcl",
":DiffCommitLine<CR>",
{ noremap = true }
)
No extra setup is needed when you use
:AdvancedGitSearch
.
<CR>
opens a diff for the current file with the corresponding file on the selected commit<C-e>
show the entire commit for all files in neovim with diff plugin<C-o>
opens a the selected commit in the browser<C-y>
copy the commit hash to clipboardOpens a window with a list of local branches
Grep behaviour: filter on branch name.
<CR>
opens a diff for the current file with the selected branchOpens a window with a list of changed files on the current branch (including staged files). The fork point of the current branch is determined with the following command:
git show-branch | \
sed "s/].*//" | \
grep "*" | \
grep -v "$(git rev-parse --abbrev-ref HEAD)" | \
head -n1 | \
sed "s/^.*\\[//"
Note: this only works if there is already a commit on the current branch, otherwise the base branch can not be detected.
Grep behaviour: filter on filename.
<CR>
opens the selected file.Opens a window with all reflog entries
<CR>
checkout the reflog entryA telescope picker for all functions above.
Enable show_builtin_git_pickers
to additionally show builtin git pickers.
With Lazy
{
"aaronhallaert/advanced-git-search.nvim",
config = function()
-- optional: setup telescope before loading the extension
require("telescope").setup{
-- move this to the place where you call the telescope setup function
extensions = {
advanced_git_search = {
-- fugitive or diffview
diff_plugin = "fugitive",
-- customize git in previewer
-- e.g. flags such as { "--no-pager" }, or { "-c", "delta.side-by-side=false" }
git_flags = {},
-- customize git diff in previewer
-- e.g. flags such as { "--raw" }
git_diff_flags = {},
-- Show builtin git pickers when executing "show_custom_functions" or :AdvancedGitSearch
show_builtin_git_pickers = false,
}
}
}
require("telescope").load_extension("advanced_git_search")
end,
dependencies = {
"nvim-telescope/telescope.nvim",
-- to show diff splits and open commits in browser
"tpope/vim-fugitive",
-- to open commits in browser with fugitive
"tpope/vim-rhubarb",
-- OPTIONAL: to replace the diff from fugitive with diffview.nvim
-- (fugitive is still needed to open in browser)
-- "sindrets/diffview.nvim",
},
}
With Packer
use({
"aaronhallaert/advanced-git-search.nvim",
config = function()
-- optional: setup telescope before loading the extension
require("telescope").setup{
-- move this to the place where you call the telescope setup function
extensions = {
advanced_git_search = {
-- Fugitive or diffview
diff_plugin = "fugitive",
-- Customize git in previewer
-- e.g. flags such as { "--no-pager" }, or { "-c", "delta.side-by-side=false" }
git_flags = {},
-- Customize git diff in previewer
-- e.g. flags such as { "--raw" }
git_diff_flags = {},
-- Show builtin git pickers when executing "show_custom_functions" or :AdvancedGitSearch
show_builtin_git_pickers = false,
}
}
}
require("telescope").load_extension("advanced_git_search")
end,
requires = {
"nvim-telescope/telescope.nvim",
-- to show diff splits and open commits in browser
"tpope/vim-fugitive",
-- to open commits in browser with fugitive
"tpope/vim-rhubarb",
-- optional: to replace the diff from fugitive with diffview.nvim
-- (fugitive is still needed to open in browser)
-- "sindrets/diffview.nvim",
},
})
With Lazy
{
"aaronhallaert/advanced-git-search.nvim",
config = function()
-- optional: setup telescope before loading the extension
require("advanced_git_search.fzf").setup{
-- fugitive or diffview
diff_plugin = "fugitive",
-- customize git in previewer
-- e.g. flags such as { "--no-pager" }, or { "-c", "delta.side-by-side=false" }
git_flags = {},
-- customize git diff in previewer
-- e.g. flags such as { "--raw" }
git_diff_flags = {},
-- Show builtin git pickers when executing "show_custom_functions" or :AdvancedGitSearch
show_builtin_git_pickers = false,
}
end,
dependencies = {
"ibhagwan/fzf-lua",
-- to show diff splits and open commits in browser
"tpope/vim-fugitive",
-- to open commits in browser with fugitive
"tpope/vim-rhubarb",
-- OPTIONAL: to replace the diff from fugitive with diffview.nvim
-- (fugitive is still needed to open in browser)
-- "sindrets/diffview.nvim",
},
}
With Packer
use({
"aaronhallaert/advanced-git-search.nvim",
config = function()
-- optional: setup telescope before loading the extension
require("advanced_git_search.fzf").setup{
-- Fugitive or diffview
diff_plugin = "fugitive",
-- Customize git in previewer
-- e.g. flags such as { "--no-pager" }, or { "-c", "delta.side-by-side=false" }
git_flags = {},
-- Customize git diff in previewer
-- e.g. flags such as { "--raw" }
git_diff_flags = {},
-- Show builtin git pickers when executing "show_custom_functions" or :AdvancedGitSearch
show_builtin_git_pickers = false,
}
}
end,
requires = {
"ibhagwan/fzf-lua",
-- to show diff splits and open commits in browser
"tpope/vim-fugitive",
-- to open commits in browser with fugitive
"tpope/vim-rhubarb",
-- optional: to replace the diff from fugitive with diffview.nvim
-- (fugitive is still needed to open in browser)
-- "sindrets/diffview.nvim",
},
})