nushell / reedline

A feature-rich line editor - powering Nushell
https://docs.rs/reedline/
MIT License
519 stars 144 forks source link

Directory navigation keys in filepath completion #589

Open jmoore34 opened 1 year ago

jmoore34 commented 1 year ago

Background

When cd-ing to a nested directory (or selecting a deeply nested file), you need to type "enter tab enter tab enter tab..." to repeatedly select a folder and then re-start the filepath completion within that folder.

e.g. to cd to a/b/c/d, you would do

e.g. cd a/<tab><enter to select b><tab to list directories in b><enter to select c><tab to list directories in c><enter to select d>

Desired solution

Once in interactive completion mode, pressing tab would cause the completion to enter the the hovered-over directory without ending interactive completion.

e.g. cd a/<tab to select b and list directories within b><tab to select c and list directories within c><enter to select d>

i.e.

cd <tab>
cd a/<tab>
cd a/b<tab>
cd a/b/c<tab>
cd a/b/c/d<enter>

(For simplicity I've omitted filtering/using arrow keys to choose between directories before pressing tab)

Additionally, pressing shift+tab could go in the opposite direction, i.e. setting the current completion to its parent directory. This could even go past the initial directory (i.e. to .., then ../.., etc)

e.g.

cd a/b/c<shift-tab>
cd a/b<shift-tab>
cd a<shift-tab>
cd ..<shift-tab>
cd ../..<enter>

References

You can somewhat emulate this behavior using external tools like fzf or broot, but such tools are more heavyweight (slower) than needed for this use case since they also search unrelated directories. Implementing this in reedline would also make it easier to complete filepath arguments without needing to set up custom keybinds with commandline and such.

Breaking changes

This shouldn't break users since, as far as I am aware, neither tab nor shift-tab are used currently within the filepath completion menu.

sholderbach commented 1 year ago

I think we would absolutely welcome UX improvements to how keypresses are interpreted with our Menus. For file/folder completions there would still be the question if the detailed elements should rather be generated with nushell as we need to be context aware and have our own particular semantics around quoting and escaping. I agree that we should to better here and having commandline etc. as an escape hatch is a bit hacky.