AckslD / swenv.nvim

Tiny plugin to quickly switch python virtual environments from within neovim without restarting.
206 stars 29 forks source link

Feature: Selected env by name #20

Closed aemonge closed 10 months ago

aemonge commented 11 months ago

Can we have an API that we could select the first matching option based on a string?

set_venv("name")

This way I can create an AU:

-- Create a command to pick the venv from a file
vim.cmd [[
  function! PickVenvFromFile()
    " Check if the 'venv.name' file exists in the current directory
    if filereadable('venv.name')
      " If it does, read its content to a variable
      let venv_name = join(readfile('venv.name'), '')

      " Use your module to pick the venv
      lua require('swenv.api').set_venv(venv_name)
    endif
  endfunction
]]

-- Set an autocommand to run the command when a buffer is read
vim.cmd [[autocmd BufRead,BufNewFile * :call PickVenvFromFile()]]
AckslD commented 11 months ago

Sounds good.

first matching option based on a string

What do you specifically mean here? Lets say you have venvs foobar and foo (in that order). Should set_venv('foo') select foobar or foo?

Would you like to try to implement this and submit a PR?

aemonge commented 11 months ago

I would make is to select foo, since.

I can also try to find some time and develop it :)

It would be a bit of a challenge, but if you're willing to help me. I'll do it :)

AckslD commented 11 months ago

Happy to answer any questions you have :)

aemonge commented 10 months ago

Here it is sir :vulcan_salute: I've added to the documentation about the lualine visibility. Also, added support for automatically change venv. I really hope you find it usefull :)

https://github.com/AckslD/swenv.nvim/pull/22