Closed zwhitchcox closed 1 year ago
I want this, too. I threw together a PR (#121) and could use feedback and help with testing. Quick copy/paste for anyone who's willing to help (assuming you're using Packer for package management):
use({ "gerryhernandez/telescope-project.nvim", branch = "configureDefaultAction" })
Then take a look at the README in the PR.
Thanks!
No PR is necessary to achieve this. See this comment.
I had the same wish and had to search the issue tracker for this solution, probably would be helpful to put this in the readme.
./lua/config/telescope.lua
local telescope = require'telescope'
local function on_project_selected(prompt_bufnr)
local project_actions = require'telescope._extensions.project.actions'
project_actions.change_working_directory(prompt_bufnr, false)
print("Do whatever you want in this function")
end
local M = {}
function M.project()
telescope.extensions.project.project{
attach_mappings = function(prompt_bufnr, map)
map({'n', 'i'}, '<CR>', on_project_selected)
return true
end,
}
end
return M
And then just map this like this:
local mytelescope = require'config.telescope'
vim.keymap.set('n', '<leader>fp', mytelescope.project, {desc = "Find Project"})
i test with telescope-frecency.nvim, it's will be error just like: [telescope] [WARN 14:43:04] ...ck/packer/start/telescope.nvim/lua/telescope/pickers.lua:489: Finder failed with msg: ...ck/packer/start/telescope.nvim/lua/telescope/sorters.lua:430: attempt to index local 'entry' (a nil value)
require("telescope").extensions.project.project {
display_type = 'two-segment',
attach_mappings = function(prompt_bufnr, map)
map('i', '<cr>', function()
require("telescope._extensions.project.actions").
change_working_directory(prompt_bufnr, false)
require('telescope').extensions.frecency.frecency({ workspace = 'CWD' })
end)
return true
end,
}
i am found the error and resolve it, but i still think PR (https://github.com/nvim-telescope/telescope-project.nvim/pull/121) is necessary, for lots people
It would be good if I could change the default action to
change_working_directory()
or an arbitrary function that I give it. I really don't want the file picker ever, because I'd rather just see thenvim-tree
, because it lets me familiarize myself with the directory structure, and also I'd like it to open the most recent session.Also, the keyboard shortcuts don't work, because telescope makes
C-l
complete_tag
, and this plugin doesn't override it. I know this is an unrelated issue, but if I could just set the default action, I wouldn't have to worry about that, and I will never want the fzf file browser, so that's not a problem.It seems like this would be extremely easy just by setting
on_project_selected
to the options the user passes in: