camspiers / snap

A fast finder system for neovim.
The Unlicense
490 stars 17 forks source link

Snap not working for symlinked directories #8

Closed shubham-cpp closed 3 years ago

shubham-cpp commented 3 years ago

Problem: Create a binding to use snap on custom directory like launching snap on nvim dir Potential Solution:

local general = snap.get("producer.ripgrep.general")
nvim_dir = function(request)
    local cwd = snap.sync(function() vim.fn.stdpath('config') end)
    return general(request, {
        args = {"--hidden", "--line-buffered", "--files"},
        cwd = cwd
    })
end

function M.Neovim()
    snap.run {
        producer = snap.get 'consumer.fzf'(nvim_dir),
        select = snap.get'select.file'.select,
        multiselect = snap.get'select.file'.multiselect,
        views = {snap.get 'preview.file'}
    }
end
vim.cmd [[ command! Neovim lua require'fuzzy/snaps'.Neovim() ]]

Issue: I have nvim directory as a symlink(using stow to manage dotfiles), so snap launches my root directory(where all the dotfiles exists) instead of only launching on nvim directory.

Tried: changing nvim_dir()

nvim_dir = function(request)
    local cwd = snap.sync(function()
           return string.format("%s/.config/nvim",os.getenv("HOME"))
    end)
    return general(request, {
        args = {"--hidden", "--line-buffered", "--files"},
        cwd = cwd
    })
end

But then It gives error that ~/Documents/dotfiles/init.vim doesn't exists which is right but the problem is that snap is unable to unpack symlinks properly. I also tried snap.get("producer.fd.general") and passing --follow flag for both ripgrep and fd

camspiers commented 3 years ago

This might be resolved by the approach described in https://github.com/camspiers/snap/issues/27

@shubham-cpp Can you check?

shubham-cpp commented 3 years ago

Ok will look into that this afternoon

shubham-cpp commented 3 years ago

Yes will look into this, this afternoon

shubham-cpp commented 3 years ago

Yes everything works as expected. Great work 👍🏽 💯.

shubham-cpp commented 3 years ago

This might be a future request but assume that I have passed ~/Documents/dotfiles as cwd. Then in the popup window it could show alacritty/.confile/alacritty.yml instead of /home/shubham/Documents/dotfiles/alacritty/.config/alacritty.yml.

I'm using stow for dotfiles management.

We can use this type shell command

fd --type f --hidden . ~/Documents/dotfiles | sed 's#'$HOME'/Documents/dotfiles/##g'
camspiers commented 3 years ago

Per #27

"So with ripgrep.file.args you can now search in non-cwd's. The paths will be absolute, but I can work on making that better later."

shubham-cpp commented 3 years ago

Yes yes no worry. Its not that imp at the moment. Switched to span completely now