alpha-nvim icon indicating copy to clipboard operation
alpha-nvim copied to clipboard

[Feature] Show dashboard with directory as first argument

Open JSteitz opened this issue 3 years ago • 6 comments

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.

JSteitz avatar Dec 10 '21 10:12 JSteitz

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 avatar Dec 10 '21 21:12 goolord

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
    ]]

goolord avatar Dec 10 '21 21:12 goolord

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.

JSteitz avatar Dec 10 '21 22:12 JSteitz

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

genebean avatar Jan 03 '24 04:01 genebean

@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.

JSteitz avatar Jan 03 '24 09:01 JSteitz

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

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

genebean avatar Jan 12 '24 03:01 genebean