From 80408431b690e04e7678a2d75bdc690a5518c1b7 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 2 Sep 2020 20:11:11 +0200 Subject: Merging upstream version 0.10.10. Signed-off-by: Daniel Baumann --- .gita-completion.zsh | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 .gita-completion.zsh (limited to '.gita-completion.zsh') diff --git a/.gita-completion.zsh b/.gita-completion.zsh new file mode 100644 index 0000000..d1fe952 --- /dev/null +++ b/.gita-completion.zsh @@ -0,0 +1,46 @@ + +_gita_completions() +{ + + local cur commands repos cmd + local COMP_CWORD COMP_WORDS # 定义变量,cur表示当前光标下的单词 + read -cn COMP_CWORD # 所有指令集 + read -Ac COMP_WORDS # 当前指令的索引值 + + cur=${COMP_WORDS[COMP_CWORD]} + cmd=${COMP_WORDS[2]} + + # FIXME: this is somewhat slow + commands=`gita -h | sed '2q;d' |sed 's/[{}.,]/ /g'` + + repos=`gita ls` + # this doesn't work for two repos with the same basename + #gita_path=${XDG_CONFIG_HOME:-$HOME/.config}/gita/repo_path + #repos=`awk '{split($0, paths, ":")} END {for (i in paths) {n=split(paths[i],b, /\//); print b[n]}}' ${gita_path}` + + # FIXME(Steve-Xyh): the secondary auto-completion(such as `$repos`) contains first commands / 二级补全候选项中包含一级补全中的 `$commands` + # XXX(Steve-Xyh): the auto-completion is currently case-sensitive / 当前的补全区分大小写, 应该改成大小写不敏感 + # (Steve-Xyh): args in zsh must be `reply` / zsh 中的参数必须为 `reply` + if [ -z "$cmd" ]; then + reply=($(compgen -W "${commands}" ${cur})) + else + cmd_reply=($(compgen -W "${commands}" ${cmd})) + case $cmd in + add) + reply=(cmd_reply $(compgen -d ${cur})) + ;; + ll) + return + ;; + *) + reply=($cmd_reply $(compgen -W "${repos}" ${cur})) + ;; + esac + fi + +} + +# (Steve-Xyh): functions in zsh must be `compctl` / zsh 中必须用 compctl 函数, -K 表示使用函数 +compctl -K _gita_completions gita + + -- cgit v1.2.3