blob: 8dcf61ae42d1473ca65eaac0288c2a4b6d56064a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
|
#! /bin/bash
dim ()
{
if [[ "x$1" = "xcd" ]]; then
cd $(cat ~/.dim-last-path) || exit
else
command dim "$@"
fi
}
_dim_git_branches()
{
git for-each-ref --format='%(refname:short)' refs/heads
}
_dim ()
{
local args arg cur prev words cword split
local nightly_branches upstream_branches opts cmds aliasref
# require bash-completion with _init_completion
type -t _init_completion >/dev/null 2>&1 || return
_init_completion || return
COMPREPLY=()
# arg = subcommand
_get_first_arg
# args = number of arguments
_count_args
nightly_branches="$(dim list-branches)"
upstream_branches="$(dim list-upstreams)"
if [ -z "${arg}" ]; then
# top level completion
case "${cur}" in
-*)
opts="-d -f -i"
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
;;
*)
cmds="$(dim list-commands) $(dim list-aliases | sed 's/\t.*//')"
COMPREPLY=( $(compgen -W "${cmds}" -- ${cur}) )
;;
esac
return 0
fi
# complete aliases like the actual command
aliasref=$(dim list-aliases | sed -n "s/^${arg}\t\(.*\)/\1/p")
if [[ -n "$aliasref" ]]; then
arg="$aliasref"
fi
case "${arg}" in
push-branch)
COMPREPLY=( $( compgen -W "-f $nightly_branches" -- $cur ) )
;;
push-queued|push-fixes|push-next-fixes)
COMPREPLY=( $( compgen -W "-f" -- $cur ) )
;;
cat-to-fixup|apply-branch)
COMPREPLY=( $( compgen -W "$nightly_branches" -- $cur ) )
;;
magic-patch)
if [[ $args == 2 ]]; then
COMPREPLY=( $( compgen -o nospace -W "-a" -- $cur ) )
fi
;;
tc|fixes)
# FIXME needs a git sha1
;;
checkpatch)
# FIXME needs a git sha1
;;
pull-request|backmerge)
if [[ $args == 2 ]]; then
COMPREPLY=( $( compgen -W "$nightly_branches" -- $cur ) )
elif [[ $args == 3 ]]; then
COMPREPLY=( $( compgen -W "$upstream_branches" -- $cur ) )
fi
;;
pull-request-next|pull-request-fixes|pull-request-next-fixes)
if [[ $args == 2 ]]; then
COMPREPLY=( $( compgen -W "$upstream_branches" -- $cur ) )
fi
;;
create-branch)
if [[ $args == 2 ]]; then
COMPREPLY=( $( compgen -o nospace -W "drm- topic/" -- $cur ) )
fi
;;
checkout)
if [[ $args == 2 ]]; then
COMPREPLY=( $( compgen -W "$nightly_branches" -- $cur ) )
fi
;;
remove-branch)
if [[ $args == 2 ]]; then
COMPREPLY=( $( compgen -W "$nightly_branches" -- $cur ) )
fi
;;
create-workdir)
if [[ $args == 2 ]]; then
COMPREPLY=( $( compgen -W "$nightly_branches all" -- $cur ) )
fi
;;
retip)
COMPREPLY=($(compgen -W "$(_dim_git_branches)" -- $cur))
;;
esac
return 0
}
complete -F _dim dim
_qf ()
{
local cur cmds
cmds="setup checkout co rebase refresh clean-patches export export-visualize ev"
cmds="$cmds push fetch pull stage wiggle-push resolved wp apply patch-amend pa"
cmds="$cmds list-unused-patches baseline git g gitk k help"
COMPREPLY=() # Array variable storing the possible completions.
cur=${COMP_WORDS[COMP_CWORD]}
if [[ $COMP_CWORD == "1" ]] ; then
COMPREPLY=( $( compgen -W "$cmds" -- $cur ) )
return 0
fi
case "${COMP_WORDS[1]}" in
pull)
COMPREPLY=( $( compgen -W "--rebase" -- $cur ) )
;;
esac
return 0
}
complete -F _qf qf
|