How can I implement incremental (find-as-you-type) search on command line?

后端 未结 2 410
暗喜
暗喜 2021-02-04 21:05

I\'d like to write small scripts which feature incremental search (find-as-you-type) on the command line.

Use case: I have my mobile phone connected via USB, Using gamm

2条回答
  •  广开言路
    2021-02-04 21:52

    I get the impression GNU Readline supports this kind of thing. Though, I have not used it myself. Here is a C++ example of custom auto complete, which could easily be done in C too. There is also a Python API for readline.

    This StackOverflow question gives examples in Python, one of which is ...

    import readline
    def completer(text, state):
        options = [x in addrs where x.startswith(text)]
        if state < options.length:
            return options[state]
        else
            return None
    readline.set_completer(completer)
    

    this article on Bash autocompletion may help. This article also gives examples of programming bash's auto complete feature.

提交回复
热议问题