jvgrootveld / telescope-zoxide

An extension for telescope.nvim that allows you operate zoxide within Neovim.
MIT License
315 stars 16 forks source link

Load .exrc on cwd change #6

Closed eruizc-dev closed 3 years ago

eruizc-dev commented 3 years ago

TLDR

It would be awesome to source .exrc file after changing cwd with telescope-zoxide if found. No need to unload the previous one since most configurations will be either overridden or ignored.

In depth:

I've been using this plugin for quite a while and it's awesome for quickly switching between projects! The issue I'm facing is that it won't load specific project configurations when I switch projects. Or more specifically: doesn't source .exrc file.

The .exrc file is a vimscript file that is sourced when you have the option set exrc and you open vim/neovim in a directory containing a file of that name. It's very useful for configuring plugins depending on project-specific requirements such as vim-test. Here's an example .exrc file I have:

" .exrc

" Variables I use for custom commands
let g:src_dir = './src/main/java/app'
let g:test_dir = './src/test/java'

" Vim-Test configuration
let test#java#runner = 'gradletest'

" Styling configuration
augroup styling
  au!
  au FileType java setlocal expandtab tabstop=4 colorcolumn=121
  au FileType xml setlocal expandtab tabstop=2 colorcolumn=81
augroup end
jvgrootveld commented 3 years ago

Thank you for for the request but I don't think this is expected (default) behaviour for the users of this plugin.

This plugin uses the native cd command, if this doesn't trigger project specific source file with set exrc, we should not invoke it as an side effect.

As I understand the documentation (4.c.), a directory specific source file is only triggered on startup, not on file/directory change. I think this is due to possible unexpected behaviour when stacking multiple source files.

Though I don't think this plugin should implement this, it can be added easily with the last update by extending the default behaviour in your vim/lua init:

require("telescope._extensions.zoxide.config").setup({
  mappings = {
    default = {
      after_action = function(selection)
        print("Directory changed to " .. selection.path)
        -- TODO source file if found
      end
    },
  }
})

I feel I should also note that set exrc is not recommended and even on the deprecated list of Neovim:

'exrc' 'ex' Security risk: downloaded files could include a malicious .nvimrc or .exrc file. See 'secure'. Recommended alternative: define an autocommand in your |vimrc| to set options for a matching directory.

eruizc-dev commented 3 years ago

Thank you for the complete answer! I was aware it was flagged as insecure but didn't know it was deprecated...

I will do as you say