我创建了一个结构文件,其中包含从短到长和复杂的几个命令。我需要一个自动完成功能,以便在用户键入fab[tab][tab]
时显示所有可用的fab命令,就像我们在bash中一样。
即
user@someone-ubuntu:~/path/to/fabfile$ fab[tab][tab] command1 command2 command3 ..and so on
我该怎么做?
答案 0 :(得分:0)
您可以在此处按照说明进行操作:http://evans.io/legacy/posts/bash-tab-completion-fabric-ubuntu/
基本上你运行一个调用fab --shortlist
的脚本,输出被输入complete
这是一个bash函数,你可以在这里阅读更多信息:https://www.gnu.org/software/bash/manual/html_node/Programmable-Completion-Builtins.html
答案 1 :(得分:0)
我使用结构2.5和Python 3对新的fabfile进行了此操作
~/.config/fabfile
#!/usr/bin/env zsh
_fab()
{
local cur
COMPREPLY=()
# Variable to hold the current word
cur="${COMP_WORDS[COMP_CWORD]}"
# Build a list of the available tasks from: `python3 -m fabric --complete`
local cmds=$(python3 -m fabric --complete 2>/dev/null)
# Generate possible matches and store them in the
# array variable COMPREPLY
COMPREPLY=($(compgen -W "${cmds}" $cur))
}
# Assign the auto-completion function for our command.
complete -F _fab fab
在我的~/.zshrc
中:
source ~/.config/fabfile
我在此处更新了Fabric 1.X版本:gregorynichola's gist