2

I was wondering if it was possible to manipulate the number of characters typed as a command. The reason for this, is I am writing a custom function to complete commands (when you press TAB), but I am using the complete function only for prompting the user, and not completing. What I want to be able to do is complete a typed word as such:

User$ command param[TAB]
prefixparam   aaaparambbb
User$ command param

User$ command aparam[TAB]
User$ command aaaparambbb

Since I am completing the param as the prefix and suffix (and in some cases replacing it entirely), I can't use the builtin complete functionality, and instead I am looking for a workaround (hopefully without getting too deep).

How my current function works

When you press tab, it will parse the command and determine the possible completions. Then it will type the bash prompt again ($PS1) and the part of the command that was typed already. (User$ command param)

I want it so that when there is only 1 possible option, for it to replace your partial command with the only remaining option. This is already possible since I am manually reprompting the user, but I am having problems since the shell will not allow you to backspace more than you typed originally.

User$ command aparam[TAB]
User$ command aaapa[rambbb] // Can only backspace 6 characters

I need some way to trick the shell into thinking that all 11 characters were typed and can be deleted.

========================================================================= I have found almost what I wanted to be possible using bind for anyone interested: bash expand cd with shortcuts like zsh

You can modify the $READLINE_LINE and $READLINE_POINT variables to modify the command. However, this only works for bind commands, and binding to TAB would overwrite and break other autocomplete functions which I would prefer not to.

Community
  • 1
  • 1
Kelvin
  • 574
  • 3
  • 13
  • Sounds like you are barking up the wrong tree. You might want to look into using terminal control codes to achieve what you want, and basically ignore the shell (or whatever it is that you are interacting with - you could then graft this onto other programs, too). – tripleee Sep 16 '16 at 04:35

0 Answers0