elvish icon indicating copy to clipboard operation
elvish copied to clipboard

using navigation mode as file selector

Open jiskattema opened this issue 3 years ago • 5 comments

usecase: i have to add several files (not from my working directoy) to my current prompt, and I would like to use the navigation mode as file selector. This is similar to how ranger --choosefiles=output.txt would work.

Currently, tab completion is not efficient as I would have type the full path for each file i want to add. Wildcards or globs are not specific enough, because they could match files i dont want to add.

The insert-selected command in navigation mode would be ideal for this, except that:

  • navigation mode changes the current working directory of the shell
  • insert-selected inserts the filename, not the absolute or relative path

Can you add an option, or change default behaviour, such that:

  1. either navigation-mode does not change the shells directory, or it returns to the starting directory when closing.
  2. insert-selected inserts the path of the selected file, relative to the working directory or the absolute path.

jiskattema avatar Mar 07 '22 08:03 jiskattema

I've implemented my above suggestion here, if there's interest in can turn it into a pull request.

jiskattema avatar Mar 07 '22 13:03 jiskattema

I took a look at your commit. IIUC, it changes the behavior of the navigation mode so that dismissing it will navigate back to the original directory. This would make it impossible to use the navigation mode to navigate to a different directory, which is another valid use case.

I think it's best to approach this use case by introducing two variants of the navigation mode:

  • The current, "cd" variant: navigating changes working directory
  • The proposed "pick file" variant: navigating doesn't change working directory; inserting a filename inserts a path relative to the original working directory.

xiaq avatar Mar 07 '22 14:03 xiaq

Yes, that is a good summary of my commit.

Two variants of the navigation mode would work for me; my thoughts on the 2 variants:

The current, "cd" variant: navigating changes working directory

I think this overlaps with the location mode, which I use to rapidly change directories (most of the time when i use cd). When the directory is not in the directory list yet, typing cd and then using either completion or navigation to pick the directory, would be just as easy. If you want to keep the navigation mode simple (no two variants), i would prefer only the other variant.

The proposed "pick file" variant: navigating doesn't change working directory; inserting a filename inserts a path relative to the original working directory.

Sound good. It would also make the preview window (the right most panel in the navigation mode) more useful. As you type a long command, and want to look up some text in a readme, you can do that in this variant without interfering with your prompt or changing directories.

jiskattema avatar Mar 07 '22 15:03 jiskattema

The current, "cd" variant: navigating changes working directory

I think this overlaps with the location mode, which I use to rapidly change directories (most of the time when i use cd). When the directory is not in the directory list yet, typing cd and then using either completion or navigation to pick the directory, would be just as easy. If you want to keep the navigation mode simple (no two variants), i would prefer only the other variant.

These are both for changing directories, but the actual use case is quite different:

  • Location mode is for changing to a directory you have been to before.
  • Navigation mode, when used for changing directories, is for changing to a directory that's close to the current directory, and quite possibly one that you have never been to before.

So there is a need for the directory-changing variant of the navigation mode.

There are several ways to get both variants:

  • Support both variants in code.
  • Only support the non-directory-changing variant (your commit). The user can still get the directory-changing behavior by typing cd, invoke the navigation mode, and select the directory they wish to change to. However, this is more awkward than the current directory-changing navigation mode, because they need to navigate to the parent of the directory they want to go to, and select the directory. This also makes it impossible to change to /.
  • Only support the directory-changing variant (status quo). When #1299 is implemented, you can write an Elvish script that starts the navigation mode, and outputs the selected filename when the script terminates. Basically you use another Elvish process to implement ranger --choosefiles.

I feel it may actually make sense to support both variant in code - this doesn't depend on other work and doesn't change the user's workflow.

xiaq avatar Mar 07 '22 15:03 xiaq

Sure, let me know if i can help.

Just to add, I tried to implement the 'filepicker' mode using a script. I got it almost working, except for getting insert-selected to insert a correct path; i kept ending up with the path space filename. I'll look at #1299 and see if that would help me.

jiskattema avatar Mar 07 '22 15:03 jiskattema