标签:assign 命令 and script ide mamicode info variable usr
因此,制作自动补全功能时,要先搞清楚,你使用的是哪种shell,各个shell制作方法是不同的,网上大部分介绍的是关于bash的。
补全命令complete、筛选命令compgen、修改补全命令设置compopt
通过这些变量,可以获得当前命令的内容、位置等信息,以便判断下面应该出现的提示命令的内容
除了上面三个命令外,Bash还有几个内置变量来辅助补全功能,如下:
variable | description |
---|---|
COMP_WORDS | 类型为数组,存放当前命令行中输入的所有单词 |
COMP_CWORD | 类型为整数,当前输入的单词在COMP_WORDS中的索引 |
COMPREPLY | 类型为数组,候选的补全结果 |
COMP_WORDBREAKS | 类型为字符串,表示单词之间的分隔符 |
COMP_LINE | 类型为字符串,表示当前的命令行输入字符 |
COMP_POINT | 类型为整数,表示光标在当前命令行的哪个位置 |
man complete
每打开一个新的shell,都会把这个目录下的脚本执行一遍
/usr/local/etc/bash_completion.d
参考:
https://mp.weixin.qq.com/s/nSje0zhcP2vAmBAH05g64w
涉及命令:compctl
内置变量:没有bash的那些内置的变量,但是有个内置read函数,可以获取当前出现指令集、当前的指令内容、前一个指令内容等信息。
通过这条命令查找zsh的内置函数,找到read的用法:
read函数所用参数解释:
-A The first name is taken as the name of an array and all words are assigned to it. -n Together with -c, the number of the word the cursor is on is read. With -l, the index of the character the cursor is on is read. Note that the command name is word number 1, not word 0, and that when the cursor is at the end of the line, its character index is the length of the line plus one. -c -l These flags are allowed only if called inside a function used for completion (specified with the -K flag to compctl). If the -c flag is given, the words of the current command are read. If the -l flag is given, the whole line is assigned as a scalar. If both flags are present, -l is used and -c is ignored.
man zsh
~/.zshrc
这种模糊搜索可以查到很多工具的命令自动补全脚本:比如pip、bash、docker、zsh等
标签:assign 命令 and script ide mamicode info variable usr
原文地址:https://www.cnblogs.com/shengulong/p/10538252.html