Skip to content

feat: add option to hide root dir path #631

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

Closed
wants to merge 27 commits into from
Closed

Conversation

jim-fx
Copy link

@jim-fx jim-fx commented Sep 23, 2021

Hi @kyazdani42 ,

This pull request adds a configuration option: let g:nvim_tree_hide_root_folder, which when enabled hides the path of the root folder on top of the tree like so:

let g:nvim_tree_hide_root_folder = 0; --default

Screenshot from 2021-09-24 00-23-17 (1)

let g:nvim_tree_hide_root_folder = 1;

Screenshot from 2021-09-24 00-23-17 (3)

The intention is to allow for a more minimalistic ui, and for me personally tmux already shows the current directory so this information is sort of redundant.

Thanks for the aaaawsome plugin and cheers,

Jim

Copy link
Member

@kyazdani42 kyazdani42 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like your PR breaks indentations quite a lot, it will not pass linting. I'm going to merge the setup refactoring, you should then rebase because options like this should not be global anymore :) But it's indeed a wanted change, i believe users have asked for this some time ago.

@kunish
Copy link
Contributor

kunish commented Sep 27, 2021

Really nice feature! Looking forward to it.

frogtile and others added 22 commits September 28, 2021 14:48
* chore: refacto setup part 1

refacto setup for code entrypoint
following options switched boolean values as options to the setup function:
- `nvim_tree_disable_netrw` -> `disable_netrw`
- `nvim_tree_hijack_netrw` -> `hijack_netrw`
- `nvim_tree_auto_open` -> `open_on_setup`
- `nvim_tree_auto_close` -> `auto_close`
- `nvim_tree_tab_open` -> `tab_open`
- `nvim-tree-update-cwd` -> `update_cwd`
- `nvim_tree_hijack_cursor` -> `hijack_cursor`
- `nvim_tree_system_open_command` -> `system_open.cmd`
- `nvim_tree_system_open_command_args` -> `system_open.args`
- `nvim_tree_follow` -> `update_focused_file.enable`
- `nvim_tree_follow_update_path` -> `update_focused_file.update_cwd`
Also added new option `update_focused_file.ignore_list` which will
ignore filepath or filetypes that matches one entry of the list when
updating the path if update_cwd is true.

* add deprecation warning

* update readme

* schedule on enter to avoid running before vim first buffer has loaded

* update docs

* correct typo

* rename tab open -> open on tab
the new setup refactoring might have some issues when users require the
tree before setting up global options, which might result in a startup
check not detecting those out of date options.
- put renderer into its own folder, extract the padding logic to make it
  reloadable. Will allow small refactorings of the rendering logic to
  make it easier to extend.
- get the icon state before each renderer reload
@jim-fx
Copy link
Author

jim-fx commented Sep 28, 2021

Hi @kyazdani42

I had some time today to work on this pull request.
The hide_root_folder option is now part of the setup function and not global anymore.

I was unsure how to pass the hide_root_folder boolean from the nvim-tree.setup function to the places where I needed to access it, so i added it to the view.View object. There is probably a better way to do this, but it works.

Sorry to cause some problems with the indentations and linting, i just started learning lua a few weeks ago and i dont really know how to setup those things to work correctly.

Anyway hope this is mergable and you all have a good day,

Cheers ✌, Jim

@kyazdani42
Copy link
Member

@jim-fx looks like there are still formatting issues. I could take this PR and format it properly because it looks ok otherwise, what do you think ?

@jim-fx
Copy link
Author

jim-fx commented Sep 30, 2021

For learning purposes, I tried to fix the warnings from luacheck myself. Other than that you can do anything you want before you merge the pr.

@kyazdani42
Copy link
Member

please rebase again :)

@jim-fx
Copy link
Author

jim-fx commented Oct 2, 2021

@kyazdani42 just did :)

Copy link
Member

@kyazdani42 kyazdani42 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please rebase the PR and not merge the master in it ? You'd have had less issues.
If you don't know much about rebasing, i'd suggest this small exercise

@@ -78,6 +78,7 @@ function.
open_on_tab = false,
hijack_cursor = false,
update_cwd = false,
hide_root_folder = false,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indenting :)

@@ -200,7 +201,10 @@ Here is a list of the options available in the setup call:
type: `boolean`
default: false

*nvim-tree.view*
- |hide_root_folder|: hide the path of the current working directory on top of the tree
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

badly resolved, add a *nvim-tree.hide_root_folder* above your option declaration and do not remove the *nvim-tree.view* before the view declaration :)

@@ -161,8 +161,15 @@ function M.on_keypress(mode)
return keypress_funcs[mode](node)
end

local hide_root_folder = view.View.hide_root_folder


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

too many empty lines here, one suffice :)

if node.name == ".." then
return lib.change_dir("..")
if hide_root_folder then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing or node.name ~= '..'

@@ -408,7 +415,8 @@ local DEFAULT_OPTS = {
hijack_cursor = false,
update_cwd = false,
lsp_diagnostics = false,
update_focused_file = {
hide_root_folder = false,
update_focused_file = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

badly aligned :)

@@ -205,7 +212,8 @@ end

function M.set_index_and_redraw(fname)
local i
if M.Tree.cwd == '/' then
local hide_root_folder = view.View.hide_root_folder
if M.Tree.cwd == '/' and hide_root_folder then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this an and and not an or ?

@@ -9,6 +9,7 @@ end
M.View = {
bufnr = nil,
tabpages = {},
hide_root_folder = false,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing space.

@@ -107,7 +108,7 @@ end
local DEFAULT_CONFIG = {
width = 30,
side = 'left',
auto_resize = false,
auto_resize = false,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unwanted change

@@ -141,7 +142,7 @@ function M.setup(opts)
local options = vim.tbl_deep_extend('force', DEFAULT_CONFIG, opts)
M.View.side = options.side
M.View.width = options.width
M.View.auto_resize = opts.auto_resize
M.View.auto_resize = opts.auto_resize
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bis

@subterfugue
Copy link
Contributor

Hey, not to rush you, but it seems there's no more activity on this - if you wish, I can attempt to help merge this? This is a nice feature that I'd love to have in nvim-tree. Sorry if this sounds rude.

@kyazdani42
Copy link
Member

code has changed much, you could reimplement this if the author does not give any news

@jim-fx
Copy link
Author

jim-fx commented Oct 16, 2021

Hey, not to rush you, but it seems there's no more activity on this - if you wish, I can attempt to help merge this? This is a nice feature that I'd love to have in nvim-tree. Sorry if this sounds rude.

Hi, dont worry did not sound rude at all. I am currently very busy with university, so i will not have a lot of time the next few weeks. I think i sort of underestimated how much effort this takes with my lua skills.

If you would like to implement it yourself, please go ahead. Otherwise i will probably try again in a few weeks, Cheers 👋

@kyazdani42
Copy link
Member

not only lua skills but codebase is hard to read imo, it started off as a learning project for lua, now i'm rewriting the whole thing bit by bit 😄

@subterfugue
Copy link
Contributor

subterfugue commented Oct 16, 2021

I have finished the functionality and added some "documentation" in - though I am rather unsure of how good it is - I depend on you to review and say your preference, since I am quite new to writing documentation with Vim syntax. The repo is https://github.com/MonAaraj/nvim-tree.lua - I believe I need to create a new pull request for this? I'm not quite sure, if I need to do so, please tell me here.

@kyazdani42
Copy link
Member

make a new PR it'll be easier :)

@jim-fx
Copy link
Author

jim-fx commented Oct 17, 2021

Duplicated to #728

@jim-fx jim-fx closed this Oct 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants