Commit 94d6c578 authored by Vitaly Lipatov's avatar Vitaly Lipatov

gitask: add bash/fish/zsh completions for gita and gitask

parent fad7154d
......@@ -27,3 +27,7 @@ install:
install -m 644 share/eterbuild/grprepl/grprepl.* $(DESTDIR)$(pkgdatadir)/grprepl/
install -m 644 share/eterbuild/eterbuild $(DESTDIR)$(pkgdatadir)/
install -m 644 share/eterbuild/functions/* $(DESTDIR)$(pkgdatadir)/functions/
mkdir -p $(DESTDIR)$(datadir)/fish/vendor_completions.d
install -m 644 share/completions/fish/gita.fish $(DESTDIR)$(datadir)/fish/vendor_completions.d/
mkdir -p $(DESTDIR)$(datadir)/zsh/site-functions
install -m 644 share/completions/zsh/_gita $(DESTDIR)$(datadir)/zsh/site-functions/
# bash completion for gita (gitask)
# https://etersoft.ru
_gita()
{
local cur prev words cword
_init_completion || return
local subcommands="new run commit test add Add deps copy find log show ls quota cancel approve acl wait share delsub rebuild get task"
case $cword in
1)
COMPREPLY=($(compgen -W "$subcommands" -- "$cur"))
return
;;
esac
local cmd=${words[1]}
case $cmd in
ls)
case $prev in
--user|-u)
return
;;
--state|-s)
COMPREPLY=($(compgen -W "NEW AWAITING PENDING BUILDING COMMITTING TESTED FAILED DONE EPERM POSTPONED ALL" -- "$cur"))
return
;;
--repo|-r)
COMPREPLY=($(compgen -W "sisyphus p10 p11 c10f2" -- "$cur"))
return
;;
esac
COMPREPLY=($(compgen -W "--all -a --user -u --state -s --repo -r -w" -- "$cur"))
return
;;
run|commit|test)
case $prev in
-m)
return
;;
esac
local opts="-m"
[[ $cmd == run ]] && opts="$opts --test-only --commit"
COMPREPLY=($(compgen -W "$opts" -- "$cur"))
return
;;
add|Add)
case $prev in
del|copy|repo|build|rebuild)
return
;;
esac
case $cur in
-*)
COMPREPLY=($(compgen -W "--help" -- "$cur"))
return
;;
esac
# after task number, suggest add subcommands
if [[ ${words[2]} =~ ^#?[0-9]+$ ]] || [[ $cword -eq 2 ]] ; then
COMPREPLY=($(compgen -W "del copy repo build rebuild" -- "$cur"))
return
fi
;;
acl)
case $prev in
acl)
COMPREPLY=($(compgen -W "Sisyphus p10 p11 c10f2" -- "$cur"))
return
;;
esac
# second/third arg: package or branch, then commands
case $cur in
show|add|del|leader)
return
;;
esac
;;
approve)
case $prev in
-m)
return
;;
esac
COMPREPLY=($(compgen -W "-m" -- "$cur"))
return
;;
wait)
COMPREPLY=($(compgen -W "-q --quiet" -- "$cur"))
return
;;
copy)
# after "to", suggest branches
local i has_to=0
for ((i=2; i<cword; i++)) ; do
if [[ ${words[i]} == to ]] ; then
has_to=1
break
fi
done
if [[ $has_to -eq 1 ]] ; then
COMPREPLY=($(compgen -W "p10 p11 sisyphus from" -- "$cur"))
else
COMPREPLY=($(compgen -W "to" -- "$cur"))
fi
return
;;
get)
case ${words[2]:-} in
"")
COMPREPLY=($(compgen -W "subtask last" -- "$cur"))
return
;;
esac
;;
cancel|delsub|log|show|share)
# these take task numbers, no special completions
;;
esac
} &&
complete -F _gita gita gitask
......@@ -61,6 +61,8 @@ RECOMMENDED packages: gcc-c++ perl-libwww ccache elinks mutt hasher curl
%_bindir/*
%_datadir/eterbuild/
%attr(0755,root,root) %_sysconfdir/bashrc.d/*
%_datadir/fish/vendor_completions.d/gita.fish
%_datadir/zsh/site-functions/_gita
%dir %_sysconfdir/eterbuild/
%dir %_sysconfdir/eterbuild/apt/
%dir %_sysconfdir/eterbuild/repos/
......
# fish completion for gita (gitask)
# https://etersoft.ru
# Disable file completions by default
complete -c gita -f
complete -c gitask -f
# Subcommands
set -l subcommands new run commit test add deps copy find log show ls quota cancel approve acl wait share delsub rebuild get task
# First argument: subcommands
complete -c gita -n __fish_use_subcommand -a "$subcommands"
complete -c gitask -n __fish_use_subcommand -a "$subcommands"
# --- ls ---
complete -c gita -n '__fish_seen_subcommand_from ls' -s a -l all -d 'List all users, all states'
complete -c gita -n '__fish_seen_subcommand_from ls' -s u -l user -d 'List tasks for USER' -r
complete -c gita -n '__fish_seen_subcommand_from ls' -s s -l state -d 'Filter by state' -xa 'NEW AWAITING PENDING BUILDING COMMITTING TESTED FAILED DONE EPERM POSTPONED ALL'
complete -c gita -n '__fish_seen_subcommand_from ls' -s r -l repo -d 'Filter by repo' -xa 'sisyphus p10 p11 c10f2'
complete -c gita -n '__fish_seen_subcommand_from ls' -s w -d 'Watch mode, refresh every N seconds'
# --- run ---
complete -c gita -n '__fish_seen_subcommand_from run' -l test-only -d 'Test only'
complete -c gita -n '__fish_seen_subcommand_from run' -l commit -d 'Commit'
complete -c gita -n '__fish_seen_subcommand_from run' -s m -d 'Message' -r
# --- commit ---
complete -c gita -n '__fish_seen_subcommand_from commit' -s m -d 'Message' -r
# --- test ---
complete -c gita -n '__fish_seen_subcommand_from test' -s m -d 'Message' -r
# --- add / Add ---
complete -c gita -n '__fish_seen_subcommand_from add Add' -s h -l help -d 'Show help'
complete -c gita -n '__fish_seen_subcommand_from add Add' -a 'del copy repo build rebuild' -d 'Add subcommand'
# --- copy ---
complete -c gita -n '__fish_seen_subcommand_from copy' -a 'to' -d 'Target branch follows'
complete -c gita -n '__fish_seen_subcommand_from copy' -n '__fish_seen_subcommand_from to' -a 'p10 p11 sisyphus from'
# --- acl ---
complete -c gita -n '__fish_seen_subcommand_from acl' -a 'Sisyphus p10 p11 c10f2' -d 'Branch'
complete -c gita -n '__fish_seen_subcommand_from acl' -a 'show add del leader' -d 'ACL command'
# --- approve ---
complete -c gita -n '__fish_seen_subcommand_from approve' -s m -d 'Message' -r
# --- wait ---
complete -c gita -n '__fish_seen_subcommand_from wait' -s q -l quiet -d 'Quiet mode, no spinner'
# --- get ---
complete -c gita -n '__fish_seen_subcommand_from get' -a 'subtask last' -d 'Get subcommand'
# Also handle gitask
complete -c gitask -n '__fish_seen_subcommand_from ls' -s a -l all -d 'List all users, all states'
complete -c gitask -n '__fish_seen_subcommand_from ls' -s u -l user -d 'List tasks for USER' -r
complete -c gitask -n '__fish_seen_subcommand_from ls' -s s -l state -d 'Filter by state' -xa 'NEW AWAITING PENDING BUILDING COMMITTING TESTED FAILED DONE EPERM POSTPONED ALL'
complete -c gitask -n '__fish_seen_subcommand_from ls' -s r -l repo -d 'Filter by repo' -xa 'sisyphus p10 p11 c10f2'
complete -c gitask -n '__fish_seen_subcommand_from ls' -s w -d 'Watch mode, refresh every N seconds'
complete -c gitask -n '__fish_seen_subcommand_from run' -l test-only -d 'Test only'
complete -c gitask -n '__fish_seen_subcommand_from run' -l commit -d 'Commit'
complete -c gitask -n '__fish_seen_subcommand_from run' -s m -d 'Message' -r
complete -c gitask -n '__fish_seen_subcommand_from commit' -s m -d 'Message' -r
complete -c gitask -n '__fish_seen_subcommand_from test' -s m -d 'Message' -r
complete -c gitask -n '__fish_seen_subcommand_from add Add' -s h -l help -d 'Show help'
complete -c gitask -n '__fish_seen_subcommand_from add Add' -a 'del copy repo build rebuild' -d 'Add subcommand'
complete -c gitask -n '__fish_seen_subcommand_from acl' -a 'Sisyphus p10 p11 c10f2' -d 'Branch'
complete -c gitask -n '__fish_seen_subcommand_from acl' -a 'show add del leader' -d 'ACL command'
complete -c gitask -n '__fish_seen_subcommand_from approve' -s m -d 'Message' -r
complete -c gitask -n '__fish_seen_subcommand_from wait' -s q -l quiet -d 'Quiet mode, no spinner'
complete -c gitask -n '__fish_seen_subcommand_from get' -a 'subtask last' -d 'Get subcommand'
#compdef gita gitask
# zsh completion for gita (gitask)
# https://etersoft.ru
_gita() {
local curcontext="$curcontext" state line
typeset -A opt_args
_arguments -C \
'1:subcommand:->subcmd' \
'*::arg:->args'
case $state in
subcmd)
local -a subcommands=(
'new:Create new task'
'run:Run task (test-only by default)'
'commit:Commit task'
'test:Run task with --test-only'
'add:Add package to task'
'Add:Add package and run task'
'deps:Add dependency'
'copy:Copy package to another branch'
'find:Find package in repo'
'log:Show build log'
'show:Show task subtasks'
'ls:List tasks'
'quota:Show quota'
'cancel:Cancel task'
'approve:Approve subtask'
'acl:Manage package ACL'
'wait:Wait for task build'
'share:Share task'
'delsub:Remove subtask'
'rebuild:Rebuild package'
'get:Get task info'
'task:Pass-through to ssh task'
)
_describe 'subcommand' subcommands
;;
args)
case $line[1] in
ls)
_arguments -s \
'(-a --all)'{-a,--all}'[List all users, all states]' \
'(-u --user)'{-u,--user}'[List tasks for USER]:user:' \
'(-s --state)'{-s,--state}'[Filter by state]:state:(NEW AWAITING PENDING BUILDING COMMITTING TESTED FAILED DONE EPERM POSTPONED ALL)' \
'(-r --repo)'{-r,--repo}'[Filter by repo]:repo:(sisyphus p10 p11 c10f2)' \
'-w[Watch mode, refresh every N seconds]:interval:' \
;;
run)
_arguments -s \
'--test-only[Test only]' \
'--commit[Commit]' \
'-m[Message]:message:' \
;;
commit|test)
_arguments -s \
'-m[Message]:message:' \
;;
add|Add)
_arguments -s \
'(-h --help)'{-h,--help}'[Show help]' \
'1:add subcommand:(del copy repo build rebuild)' \
'*:args:' \
;;
copy)
_arguments -s \
'*:package:' \
'to:target branch:(p10 p11 sisyphus)' \
'from:source branch:' \
;;
acl)
_arguments -s \
'1:branch:(Sisyphus p10 p11 c10f2)' \
'2:package:' \
'3:command:(show add del leader)' \
'4:user:' \
;;
approve)
_arguments -s \
'-m[Message]:message:' \
'1:task number:' \
'2:subtask or package:' \
;;
wait)
_arguments -s \
'(-q --quiet)'{-q,--quiet}'[Quiet mode, no spinner]' \
'1:task number:' \
;;
get)
_arguments -s \
'1:subcommand:(subtask last)' \
;;
cancel|delsub|log|show|share)
_arguments -s \
'1:task number:' \
;;
deps)
_arguments -s \
'1:task number:' \
'2:command:(add)' \
'3:dependency task:' \
;;
find)
_arguments -s \
'1:package name:' \
;;
esac
;;
esac
}
_gita "$@"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment