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.33k stars 77 forks source link

expanding abbreviations that are the results of completions #423

Open bkerin opened 3 months ago

bkerin commented 3 months ago

GNU bash, version 5.2.26(3)-release (x86_64-pc-linux-gnu) [Ubuntu 22.04.3 LTS] ble.sh, version 0.4.0-devel4+7af770db (noarch) [git 2.43.0, GNU Make 4.3, GNU Awk 5.1.0, API: 3.0 (GNU MPFR 4.1.0, GNU MP 6.2.1)] bash-completion, version 2.11 (hash:b42f5d6a7ad6d4921ec73838ba54a96d6bd30936, 77071 bytes) (noarch) locale: LANG=en_US.UTF-8 terminal: TERM=xterm-256color wcwidth=14.0-west/15.1-2+ri, vte:6800 (65;6800;1)

Another one for the things-that-arise-when-using-abbreviations-to-customize-things department:

With e.g.:

ble-sabbrev -i 'git send-email'='git send-email --no-format-patch'

Completing at git sen will complete to git send-email but of course doesn't fire the abbreviation. It seems like another pass through the abbreviation system following completion would need to be enabled.

I freely acknowledge that this is maybe getting a little crazed and I'm not sure there's any worthwhile way to accommodate it generally, but it is another thing that naturally arises when using abbreviations this way. I looked at the basic hooks but didn't see anything like a post-completion-hook where it might be hacked in. If there's some obvious way and you have a hint I'd try to set it up. This seems like the sort of thing that might be best kept as a recipe.

akinomyoga commented 3 months ago

I thought about it, but there can be many different behaviors and approaches, and I'm not sure what you would specifically like.

I personally don't think the completion should invoke the expansion immediately. Such a behavior is somewhat unpredictable or hard to predict unless the user is really careful about it. I think by default, we should still require users to go through two steps to cause the completion (by TAB) and the expansion (SP or RET or M-').

One simple way is to define another sabbrev with a whitespace as well as the original one:

ble-sabbrev -i 'git send-email'='git send-email --no-format-patch'
ble-sabbrev -i 'git send-email '='git send-email --no-format-patch'

and press SP after the completion.

Or you can always design a custom widget. For example, you can 1) perform a completion (ble/widget/complete), 2) trim a whitespace, and 3) perform a sabbrev expansion (ble/widget/sabbrev-expand) in a single key press. Optionally, if a sabbrev expansion doesn't happen, you might again insert a whitespace.

Another way is to have an option to totally disable suffixing a space. Or you may overwrite the function ble/complete/action:literal-word/complete or ble/complete/action:word/complete not to perform suffixing ' '.

Or another way is to show the sabbrev in the list of completions. When it is selected, we complete the sabbrev word/string without suffixing a space. Or selecting the item in the menu may automatically perform the sabbrev expansion on the completion.