Skip to content

Git status windows compatability #417

@major-sam

Description

@major-sam

Description

That commit breaks git status in file browser for neovim windows with git on mingw

find_root function ignore plenary path.sep and provide it as unix path

my ugly workaround:

M.find_root = function(cwd)
  if string.lower(jit.os) == 'windows' then
    return './'
  else
    return Job:new({ cwd = cwd, command = "git", args = { "rev-parse", "--show-toplevel" } }):sync()[1]
  end
end

Neovim version

NVIM v0.11.1
Build type: Release
LuaJIT 2.1.1741730670

Operating system and version

Windows

Steps to reproduce

Install telescope-fb on windows neovim with git on mingw

Expected behavior

Image

Actual behavior

Image

Minimal config

if string.lower(jit.os) == 'windows' then
  vim.opt.shell = "pwsh"
  vim.opt.shellcmdflag = "-NoLogo -NoProfile -ExecutionPolicy RemoteSigned -Command [Console]::InputEncoding=[Console]::OutputEncoding=[System.Text.Encoding]::UTF8;"
  -- vim.opt.shellredir = "-RedirectStandardOutput %s -NoNewWindow -Wait"
  vim.opt.shellredir = "2>&1 | Out-File -Encoding UTF8 %s; exit $LastExitCode"
  vim.opt.shellpipe = "2>&1 | Out-File -Encoding UTF8 %s; exit $LastExitCode"
  vim.opt.shellquote = ""
  vim.opt.shellxquote = ""
  vim.opt.undodir = os.getenv("USERPROFILE") .. "/.vim/undodir"
else
  vim.opt.undodir = os.getenv("HOME") .. "/.vim/undodir"
  vim.opt.shell = os.getenv('SHELL')
end

local fb_actions = require "telescope._extensions.file_browser.actions"
local builtin = require('telescope.builtin')
local actions = require('telescope.actions')
require("telescope").setup {
  defaults = {
    mappings = {
      i = {
        ["<c-d>"] = actions.delete_buffer,
        ["<C-s>"] = actions.send_selected_to_qflist + actions.open_qflist,
      },
      n = {
        ["<c-d>"] = actions.delete_buffer,
        ["dd"] = actions.delete_buffer,
        ["<C-s>"] = actions.send_selected_to_qflist + actions.open_qflist,
        ["<leader>sq"] = actions.send_selected_to_qflist + actions.open_qflist,
      },
    },
  },
  extensions = {
    file_browser = {
      theme = "ivy",
      grouped = true,
      initial_mode = "normal",
      -- disables netrw and use telescope-file-browser in its place
      hijack_netrw = true,
      display_stat = { date = true, size = true, mode = false },
      collapse_dirs = true,
      git_status = true,
      auto_depth = 2,
      use_fd = true,
      mappings = {
        ["i"] = {
          ["C-."] = fb_actions.change_cwd,
        },
        ["n"] = {
          ["."] = fb_actions.change_cwd,
        },
      },
    },
  }
}

require("telescope").load_extension("file_browser")
require("telescope").load_extension("yaml_schema")
require('telescope').load_extension('nerdy')
require('telescope').load_extension('themes')

vim.keymap.set('n', '<leader>fs', builtin.find_files, {})
vim.keymap.set('n', '<C-p>', builtin.git_files, {})
vim.keymap.set('n', '<leader>bb', builtin.buffers, {})
vim.keymap.set('n', '<leader>ps', function()
  builtin.grep_string({ search = vim.fn.input("Grep > ") })
end)
vim.keymap.set("n", "<leader>fb", ":Telescope file_browser<CR>")
vim.keymap.set("n", "<F3>", ":Telescope file_browser<CR>")

vim.keymap.set('n', '<leader>vh', builtin.help_tags, {})
local harpoon = require('harpoon')
harpoon:setup({})

-- basic telescope configuration
local conf = require("telescope.config").values
local function toggle_telescope(harpoon_files)
  local file_paths = {}
  for _, item in ipairs(harpoon_files.items) do
    table.insert(file_paths, item.value)
  end

  require("telescope.pickers").new({}, {
    prompt_title = "Harpoon",
    finder = require("telescope.finders").new_table({
      results = file_paths,
    }),
    previewer = conf.file_previewer({}),
    sorter = conf.generic_sorter({}),
  }):find()
end

vim.keymap.set("n", "<C-e>", function() toggle_telescope(harpoon:list()) end,
  { desc = "Open harpoon window" })

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions