Browse Source

nixpkgs/neovim: use git picker with fallback to files

Thomas Dy 3 years ago
parent
commit
ae83b02e55
2 changed files with 9 additions and 1 deletions
  1. 1 1
      .config/nixpkgs/neovim/mappings.lua
  2. 8 0
      .config/nixpkgs/neovim/plugins.lua

+ 1 - 1
.config/nixpkgs/neovim/mappings.lua

@@ -17,7 +17,7 @@ vim.keymap.set('t', '<ESC><ESC>', '<C-\\><C-N>', opts)
 vim.keymap.set('i', '<CR>', 'pumvisible() ? "\\<C-y>" : "\\<CR>"', { expr = true })
 
 -- pickers
-vim.keymap.set('n', '<C-P>', '<cmd>Telescope find_files<CR>', opts)
+vim.keymap.set('n', '<C-P>', '<cmd>lua project_files()<CR>', opts)
 vim.keymap.set('n', '<C-O>', '<cmd>Telescope buffers<CR>', opts)
 vim.keymap.set('n', '<Leader>ff', '<cmd>Telescope live_grep<CR>', opts)
 

+ 8 - 0
.config/nixpkgs/neovim/plugins.lua

@@ -27,6 +27,14 @@ require('telescope').setup({
 -- use native sorter for better performance
 require('telescope').load_extension('fzf')
 
+-- custom picker to fallback to files if no git
+local telescope_builtin = require('telescope.builtin')
+_G.project_files = function()
+  local opts = {}
+  local ok = pcall(telescope_builtin.git_files, opts)
+  if not ok then telescope_builtin.find_files(opts) end
+end
+
 -- shows added/removed/changed lines
 require('gitsigns').setup()