helpThe GNU Bourne-Again SHell - Support: sr #110449, Allow for fine-grained completion...

 
 

sr #110449: Allow for fine-grained completion (backward looking) control

Submitter:  Bob Weinand <bwoebi>
Submitted:  Wed 24 Feb 2021 11:54:21 AM UTC
 
Category:  None Priority:  5 - Normal
Severity:  1 - Wish Status:  None
Privacy:  Public Assigned to:  None
Open/Closed:  Open Operating System:  None
* Mandatory Fields

Add a New Comment (Rich Markup)
   

Comment Type & Canned Response:
       

 

Wed 24 Feb 2021 11:54:21 AM UTC, original submission:  

TL;DR: I want full control of cursor and words during completion.

---

Let's illustrate with an example; given the set of allowed values:

enable-test
disable-tests
disable-tests-broken

(These are example values, if it were that simple, I'd change the set of values to easily completable test-enable and tests-disable...)

Classical completion, when typing "test<tab>" cannot do anything. At most it could complete it to "able-test" and the cursor position would remain at the same place. By checking $COMP_TYPE -eq 37 || $COMP_TYPE -eq 63 we can display the full set of wanted completions on completion listing/menu-completion, but it does not help with the trivial completion.

Hence, it would be powerful, if a completion function were able to, after outputing "able-test", place the cursor at the start of the string.
And not only that, when the cursor is at the start, bash will retain any character on the right of the cursor, i.e. if we have now "dis<cursor>able-test", pressing tab currently will not do anything making sense.
You can do COMPREPLY=("disable-tests" "disable-tests-all"), but that just will lead to you having "disable-tests<cursor>able-test". Not user-friendly: user needs to strip the able-test on the right away himself then.

With bind -x '"\e":my_function' it is possible to manipulate $READLINE_LINE and $READLINE_POINT, but that would require me to completely emulate completion for all other registered completions. Which would be absolutely non-trivial.

---

I'd propose that, if $COMPREPLY is assigned a string instead of an array, the contents of everything previously parsed into $COMP_WORDS will be replaced by the content of $COMPREPLY. Additionally, the cursor will be placed either at the end of $COMPREPLY or, if an \e is present, that \e will be removed and the cursor placed at that position. This only applies if $COMP_TYPE -eq 9.

Alternatively, to highlight the special case, this may require an additional option being specified to complete (like "-o fullstring").

This way, we can have full control like if it were bind -x, but scoped to completions (and the specific command being completed).

Bob Weinand <bwoebi>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by bwoebi (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.

     

     

     

     

    No changes have been made to this item

    Back to the top


    Powered by Savane 3.9