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 request] Goto parent directory #82

Open
c02y opened this issue Mar 3, 2021 · 8 comments
Open

[Feature request] Goto parent directory #82

c02y opened this issue Mar 3, 2021 · 8 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@c02y
Copy link

c02y commented Mar 3, 2021

When I use dua i /path/a/b/c, the top of directory will be directory c, after navigating inside the directory for a while, I want to go outside the c root directory like b or a or even to the final / directory, currently dua cannot goto the parent of argument, I have to restart dua with the right arguemnt.

Can you implement this feature?

@Byron Byron added enhancement New feature or request help wanted Extra attention is needed labels Mar 3, 2021
@Byron
Copy link
Owner

Byron commented Mar 3, 2021

That's a useful improvement!

If there is only one root, determining the parent directory is trivial. If there are multiple roots one would have to check if they all belong to the same parent and behave as before if that's the case. Otherwise, like in dua /a/b /c/d, one would not be able to use that feature.

My suggestion is to display an informative message like Press Shift+u to recalculate the parent directory '<parent>' instead of just going up to avoid accidents - right now it displays Top level reached. If there is no unique parent directory, this message could remain.

When it comes to implementing the traversal itself one can certainly be smart and reuse the existing tree to avoid duplication of work.

@c02y
Copy link
Author

c02y commented Mar 3, 2021

Didn't know I can use dua with multiple paths like dua /a/b /c/d, never use this feature, and most likely I never will.

This feature should only work with one argument of path or no argument which means the current directory.

This navigation feature works exactly like a file manager such as ranger

@Byron
Copy link
Owner

Byron commented Mar 3, 2021

Didn't know I can use dua with multiple paths like dua /a/b /c/d, never use this feature, and most likely I never will.

The one implementing the feature will have to deal with dua's current capabilities independently of your usage patterns.

This feature should only work with one argument of path or no argument which means the current directory.

The current directory internally works as if one would have launched dua with multiple root paths, each one being a subdirectory or file in the current directory.

This navigation feature works exactly like a file manager such as ranger

If there is a more effective way of navigation in this particular case I think it's worth elaborating on that.

@c02y
Copy link
Author

c02y commented Mar 3, 2021

The current directory internally works as if one would have launched dua with multiple root paths, each one being a subdirectory or file in the current directory.

Just like I said from #77 (comment) , dua is not working like ncdu or gdu that when ncdu/gdu are started, they will list the content of the target instead of the target itself, treating all the contents in the current directory as targets when starting dua without argument is really weird.

Maybe add an option to get the size of the directory itself like du, and by default, make dua work like ncdu/gdu since most of the time we need the disk usage structure of the contents of the file system instead of just the size of the directory itself(honestly I simply use du for this purpose)?

@Byron
Copy link
Owner

Byron commented Mar 4, 2021

Just like I said from #77 (comment) , dua is not working like ncdu or gdu that when ncdu/gdu are started, they will list the content of the target instead of the target itself, treating all the contents in the current directory as targets when starting dua without argument is really weird.

'weird' isn't a value statement, it's more like judgement based on personal experiences. As strange as it may seem for someone used to other ways, that won't make it less valid on its own and is how I like to use it. Admittedly, that's only true for dua /path, as for dua i /path I usually don't want to start at /path but am alright diving in once with o.

Adding a flag to expand root paths to their children like du does would be an option though. So dua --expand /path would be the same as cd /path && dua, but would also work with multiple root paths, like dua --expand /path1 /path2.

What do you think?

@c02y
Copy link
Author

c02y commented Mar 4, 2021

You can add options for different purposes, so everyone is happy

Actually, I use dua -f binary i ~/* as an alias when I use dua.
You see that I need several other options to get the default behavior of other similar tools like ncdu/gdu.

  1. -f binary which is the default format of other tools like ncdu/gdu or ranger
  2. i is the default behavior of ncdu/gdu, most of the time I'll just use this i behavior
  3. ~/* is not the perfect way to get what I want, since dua ~/* would not handle hidden directories like ~/.cache and ~/.config so I need extra steps
  4. If I don't use path/* in my alias, I'll need another step to go into the path, most of the time I won't use a disk usage analyzer tool to simply get the size of the directory itself, this kind of request can be done with an extra option.

The above discussion is out of the topic from the current issue page.

You said that you were concerned about the usage like dua /a/b /c/d when doing goto parent directory, but the solution is very simple, when only one argument is passed, enable goto parent directory, otherwise disable goto parent directory feature, since current design is when using dua without arguments, you will treat all the contents of the current directory as the targets, so it seems basically dua prefers multiple targets, if no target is given, get all the contents as its targets which usually are multiple ones. Perfer multiple targets is not the most used cases(from my personal experience) for a disk usage analyzer.

Maybe you can change this design:

  1. use dua without argument, treat the current directory as the target, get the size of the directory and automatically cd into it and list the content;
  2. use dua with one argument, get the size and cd into it and list the contents;
  3. use dua with multiple arguments, get the size and cd into them and list the contents, in this case, disable goto parent directory.

Honestly, I don't know why the multiple-targets usage exists from the first beginning, if I want to use dua for multiple targets, I would use one after another one, or side by side.

Sorry about this long discussion, if you don't like those suggestions you can ignore them since most importantly this is your own project.

@Byron
Copy link
Owner

Byron commented Mar 15, 2021

Thanks for the thoughtful reply and sorry for the late response. Just now I managed to read it in full and hopefully understand.
On topic, I think implementing the feature while handling the possible cases is clear enough (at least for me) to do it, even though I won't get to it anytime soon.

Off topic, the main takeaway for me is that listing just the size of a given directory, as in dua i /foo is not what people want, instead they would prefer to see its contents right away, and I couldn't agree more. When using dua /foo still prefer see just the folder size (like dua ./target), but would be happy to provide a flag like --expand to show subdirectories instead to get similar behaviour as cd ./target && dua.

Applying the above to the cases you see, we'd get

    1. would stay as is, it's the current behaviour
    1. would be possible with --expand simplifying your usecase by the additional steps mentioned to get hidden directories
    1. would remain as is (but definitely can't support going to parent directories)

I would be happy to experiment with inverting 2) with something like --no-expand to get exactly the behaviour you and maybe more would prefer) and if it grows on me release that as with a major version bump.

Thanks a lot for bearing with me on this - it might not always be easy but ultimately I am sure even more good things will result from this dialogue.

@c02y
Copy link
Author

c02y commented Mar 15, 2021

Thanks, providing options for different purposes is always better than fixed in the code.

Take your time, no hurry, and thanks for the project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
Status: Backlog
Development

No branches or pull requests

2 participants