0

I am using paramiko library to connect with a specialized environment. Its based on linux but when we SSH in it provide its own shell. We can write help to get list of all commands that are supported in that session.

I am using paramiko with python2.7 to provide a CLI client (it automates few things) that connect with the host and let us run the supported commands. Now I would like to provide tab-completion in the client CLI. I am not sure how this can be done. I am thinking there would be some support or some specialize character that can be send to get back response but I am not sure how it can be accomplished.

I am hoping to avoid sending help command, parse the list of commands supported, and then provide a local tab-completion based on list of command. I want a more generic and dynamic solution.

Any or all ideas are welcome.

ata
  • 8,853
  • 8
  • 42
  • 68
  • So does the "own shell" has auto-completion on its own? Or on what do you want to base your auto-completion, if not on the output of the "help" command? – Martin Prikryl Aug 10 '21 at 10:52
  • Yes, the shell supports auto-completion – ata Aug 10 '21 at 11:57
  • So basically, you want to implement an SSH terminal client, like `ssh` or PuTTY? – Martin Prikryl Aug 10 '21 at 12:04
  • well not a complete terminal. I already have CLI and it works the way required, there is a wish to have tab-completion so that is what I am after – ata Aug 10 '21 at 15:52

1 Answers1

1

You can try simulating the partial input and the Tab key press and parsing the results, undoing the simulated input afterwards. But that is not a good idea. You will have to end up re-implementing terminal emulation, what is an insane task. Without a full terminal implementation, you can never be sure that you never get an output that you won't be able to parse.

The shell is a black box with input and output. It should only be used as such. You should never try to "understand" its output.

Using the help command is a way more reliable solution.

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992