goolord / alpha-nvim

a lua powered greeter like vim-startify / dashboard-nvim
MIT License
1.84k stars 109 forks source link

[Feature] Show dashboard with directory as first argument #61

Open JSteitz opened 2 years ago

JSteitz commented 2 years ago

In the code, you are already handling files as first argument. It would be nice, if we could have an option to show the dashboard when the first argument a directory is.

goolord commented 2 years ago

would this also change the working directory? i do this accidentally all the time, actually. it's tricky to get the behavior right so it should definitely be opt in

goolord commented 2 years ago

in my personal config i currently have this relatively complicated autocmd setup to open a file tree when i try to open a directory with nvim https://github.com/goolord/nvim/blob/f25c10aad0f937525af4d2706e01ed7a632d985a/lua/plugins/nvim-tree.lua#L36-L40

    vim.cmd[[
    autocmd StdinReadPre * let s:std_in=1
    autocmd VimEnter * if argc() == 1 && isdirectory(argv()[0]) && !exists('s:std_in') |
        \ execute 'cd '.argv()[0] | execute 'NvimTreeOpen' | wincmd p | q | endif
    ]]
JSteitz commented 2 years ago

would this also change the working directory? i do this accidentally all the time, actually. it's tricky to get the behavior right so it should definitely be opt in

No, that's not required.

in my personal config i currently have this relatively complicated autocmd setup to open a file tree when i try to open a directory with nvim https://github.com/goolord/nvim/blob/f25c10aad0f937525af4d2706e01ed7a632d985a/lua/plugins/nvim-tree.lua#L36-L40

    vim.cmd[[
    autocmd StdinReadPre * let s:std_in=1
    autocmd VimEnter * if argc() == 1 && isdirectory(argv()[0]) && !exists('s:std_in') |
        \ execute 'cd '.argv()[0] | execute 'NvimTreeOpen' | wincmd p | q | endif
    ]]

NvimTree has an option to do that for you. But I prefer not to use it myself. I switched from Dashboard to alpha, and in Dashboard I had an autocmd to that, but I can't make it work with alpha.

After rereading, I understand your comment better. I only want to show the Dashboard when I open neovim with a directory as argument: nvim /path/to/project.

genebean commented 8 months ago

Just curious if anyone found a way to make this work. I am currently using neo-tree and it shows if I do nvim . or nvim /some/path/ but what I'd really like is to have those commands produce this (I got it by running nvim and then toggling the tree on manually):

Screenshot 2024-01-02 at 11 17 14 PM
JSteitz commented 8 months ago

@genebean I do not use alpha-nvim anymore. Instead I have this little snippet in my init.lua:

-- Set workdir if argument is provided
if vim.api.nvim_buf_get_name(0) ~= '' then
  -- get current opened buffer (first argument with `nvim /path/to/dir/or/file`) 
  local path = vim.api.nvim_buf_get_name(0)
  -- workdir is either the directory itself or the directory where the file is
  local workdir = vim.fn.isdirectory(path) == 1 and path or vim.fs.dirname(path)

  if vim.fn.isdirectory(path) == 1 then
    -- remove directory buffer to get an empty buffer
    -- to show neovim info you need a single empty buffer
    vim.cmd([[bdelete %]])
  end

  -- set workdir which allows creating/navigating in the directory (used by telescope/etc...)
  vim.loop.chdir(workdir)
end

If this is not enough, you can use vim.cmd("NvimTreeOpen") after removing the directory buffer to show neotree. The same applies to alpha-nvim if it does not show itself.

genebean commented 8 months ago

@JSteitz Your suggestion lead me to this fix (I added it to my alpha config)

vim.cmd('autocmd User AlphaReady Neotree show')