Implement Auto-completion in your own base script

Source: Internet
Author: User

In the 1990s s when Linux and DOS coexist in their own base scripts, Linux Shell had one of the most insignificant but practical little functions, namely Automatic completion of commands. However, the dummies of DOS have never learned how to use them until they die. Linux's insignificant little tradition has continued so far. Although seemingly insignificant, it actually greatly improves the input efficiency and accuracy of the Administrator. If you need to implement the auto-completion function in your own scripts, you only need to write a script similar to the following. After each user login, you can use the source file. This example is on the company's channel machine. You can log on to the relevant server by name, but the server name is long and hard to remember. Every input is troublesome. So with this automatic completion script: [plain] tongdaoji () {local cur prev opts COMPREPLY = () cur = "$ {COMP_WORDS [COMP_CWORD]}" prev = "$ {COMP_WORDS [COMP_CWORD-1]}" opts = "java. vm swift. sa openstack. zf shanghai venusweb database "if [[$ {cur} = *]; then COMPREPLY = ($ (compgen-W" $ {opts} "-- $ {cur })) return 0 fi} complete-F tongdaoji e put this script in a place that can be automatically executed at each login, such ~ /. Bashrc. Then, you only need to enter e o <TAB> to get e openstack. zf.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.