Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
JSteitz opened this issue Dec 10, 2021 · 6 comments
Open

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

JSteitz opened this issue Dec 10, 2021 · 6 comments
Labels
enhancement New feature or request

Comments

@JSteitz
Copy link

JSteitz commented Dec 10, 2021

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
Copy link
Owner

goolord commented Dec 10, 2021

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
Copy link
Owner

goolord commented Dec 10, 2021

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
Copy link
Author

JSteitz commented Dec 10, 2021

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.

@goolord goolord added the enhancement New feature or request label Feb 14, 2023
@genebean
Copy link

genebean commented Jan 3, 2024

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
Copy link
Author

JSteitz commented Jan 3, 2024

@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
Copy link

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

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants