akinomyoga / ble.sh

Bash Line Editor―a line editor written in pure Bash with syntax highlighting, auto suggestions, vim modes, etc. for Bash interactive sessions.
BSD 3-Clause "New" or "Revised" License
2.67k stars 85 forks source link

`auto_complete/insert-word` should insert only one directory when completing paths #397

Closed Tommimon closed 9 months ago

Tommimon commented 9 months ago

When it is suggesting something like sudo nano /etc/foo/bar/file I often want to accept only a part of the path from the completion. For example I would like to accept it until sudo nano /etc/foo and then write manually the file I need from directory foo.

As far as I know this is not currently possible because when I accept a word from the completion, if it is a path, it will insert the full path. I couldn't find a discussion about this issue or the intended way to do it, in my opinion completing the full path and then going back removing what I don't need is not a nice experience.

My proposal is to brake words on / and not only spaces, or at least insert an option to do so.

akinomyoga commented 9 months ago

My proposal is to brake words on / and not only spaces, or at least insert an option to do so.

It's in Q&A "Can I change the word delimiter for M-right to accept a word in auto-comlete?" (Ah, but I now think the current category of the question is not so friendly). There is an option complete_auto_wordbreaks. Please use the following setting:

# blerc

bleopt complete_auto_wordbreaks=$' \t\n/'
Tommimon commented 9 months ago

Thanks for the quick answer and sorry if I didn't know that, this is indeed an acceptable solution.

That said, after more testing, I noticed that C-right and C-left already have the effect of moving through parts of words, stopping at specific characters such as . or /. If I'm not mistaken those are the:

commands respectively.

It would be very intuitive if you could insert a single cword from the selection with the same keybinding you use to move right of one cword (C-right).

This would match the behavior of M-right which is able to move right of one sword but also inserts the first word of the suggested completion.

I could rephrase my issue like this "Let C-right move trough completion". Is it an acceptable suggestion?

akinomyoga commented 9 months ago

I thought about it again if there are any possible conflicts with that. I think I can add the suggested binding.

akinomyoga commented 9 months ago

I added widgets and added a binding to C-right in commit 0c4b6772. I also updated the binding of M-f to make it consistent with the behavior outside the auto-complete state. Could you check the behavior?

Tommimon commented 9 months ago

It's great to hear that, give me the time to setup everything to build from last commit, so that I can check the behavior.

akinomyoga commented 9 months ago

OK. Actually, the nightly build of the latest commit can be downloaded from the following link [1], so you can just downloaded and extract it. The way to setup is described in the release page of the nightly version.

Tommimon commented 9 months ago

I tested it in my use case and the behavior is exactly what I expected, thanks.

I tried to combine it with other shortcuts that I use and everything seams fine, unfortunately I'm not an expert ble.sh user so there might important details regarding this feature that I'm not aware of.

That said, since my original request has been fulfilled, I think we can close this issue.

akinomyoga commented 9 months ago

Thanks!

akinomyoga commented 5 months ago

@Tommimon I decided to adjust the behavior of the default bindings to C-right, M-right, and M-f in auto-complete, which we have introduced in this Issue. Now, those keys insert the word in the autosuggestion only when the cursor is at the end of the command line. The reason is that the bindings interfered with the normal word movements outside auto-complete.

For example, suppose the user had the cursor at the position of @ in the following command line,

$ echo word1@ word2

and the user presses M-right to move to the next word. It would work as expected when auto-complete is not started. However, when the auto-complete is started immediately after the user presses M-right, the key can unexpectedly insert the first word of the suggestion that has just popped up after the user pressed the key. Actually, I was annoyed by this behavior.

In the latest push to the master branch (b72d78a97e6867bbf43de6a645dd6e387525443f), I adjusted the behavior so that those keybindings for the partial insertion of the autosuggestions are enabled only when the cursor is at the end of the command line. If you would like to keep the previous behavior (where those keys insert the first word regardless of the cursor position), could you put the following settings in your ~/.blerc?

# blerc

ble-bind -m auto_complete -f M-f     auto_complete/insert-cword
ble-bind -m auto_complete -f C-right auto_complete/insert-cword
ble-bind -m auto_complete -f M-right auto_complete/insert-word