File: bash-completion

package info (click to toggle)
debtags 1.6.6
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 2,152 kB
  • ctags: 316
  • sloc: sh: 8,840; cpp: 2,632; perl: 801; makefile: 65
file content (112 lines) | stat: -rw-r--r-- 2,823 bytes parent folder | download
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
# Debian GNU/Linux debtags(1) completion
# (C) 2004 2005 Emanuele Rocca <ema@debian.org>
# License: GNU GPL v2 or later

have debtags &&
_debtags()
{
	local cur prev options
	
	COMPREPLY=()
	cur=${COMP_WORDS[COMP_CWORD]}
	prev=${COMP_WORDS[COMP_CWORD-1]}
	options='update implications check tagshow tagsearch show \
	     	 related cat grep mkpatch install maintainers \
	         submit score tag search todo facetcoll\
			 todoreport stats'
	
	for (( i=0; i < ${#COMP_WORDS[@]}-1; i++ )); do
		case ${COMP_WORDS[i]} in
		# commands requiring a filename
		check|mkpatch|submit) 
			_filedir
			return 0
			;;
		
		tag)
			# the tag command expects one of the following parameters: 
			# add, rm, ls
			case $prev in
			add|rm|ls)
				COMPREPLY=( $( apt-cache pkgnames $cur 2> /dev/null ) )
				return 0
				;;
			tag)
				tag_cmds='add rm ls'
				COMPREPLY=( $( compgen -W "$tag_cmds" -- $cur ) )
				return 0
				;;
			*)
				if [[ -n "${COMP_WORDS[COMP_CWORD-2]}" ]]; then
					case ${COMP_WORDS[COMP_CWORD-2]} in
						# add and rm are special: they need a tag after the package name
						#
						# TODO: filter out unneeded tags from the add and rm completion input
						#
						add|rm)
							COMPREPLY=( $( grep "^Tag: $cur" /var/lib/debtags/vocabulary |cut -b 6- ) )
							return 0
							;;
						*)
							return 0
							;;
					esac
				fi
				return 0
				;;
			esac
			;;

		# commands requiring a package name
		show|related)
			if [[ "$prev" == "related" && "$cur" == -* ]]; then
				COMPREPLY=( $( compgen -W "--distance" -- $cur ) )
			fi
			COMPREPLY=( $( apt-cache pkgnames $cur 2> /dev/null ) )
			return 0
			;;
		# commands requiring a singol tag 
		tagshow)
			if [[ "$prev" == "grep" && "$cur" == -* ]]; then
				COMPREPLY=( $( compgen -W '--invert-match --quiet' -- $cur ) )
				return 0
			fi
			COMPREPLY=( $( grep "^Tag: $cur" /var/lib/debtags/vocabulary |cut -b 6- ) )
			return 0
			;;
		# commands requiring an expression
		# TODO: Understand how to implement it. :)
		# 		We should be able to complete while quoting; at the moment
		# 		behave like the 'singol tag' case
		grep|install|search)
			if [[ "$prev" == "grep" && "$cur" == -* ]]; then
				COMPREPLY=( $( compgen -W '--invert-match --quiet' -- $cur ) )
				return 0
			fi
			COMPREPLY=( $( grep "^Tag: $cur" /var/lib/debtags/vocabulary |cut -b 6- ) )
			return 0
			;;
		cat)
			COMPREPLY=( $( compgen -W "--group-items" -- $cur ) )
			return 0
			;;
		*)
			;;
		esac
	done
	
	# short or long option
	if [[ "$cur" == -* ]]; then
		options='--verbose --debug -V --version -? --help'
		COMPREPLY=( $( compgen -W "$options" -- $cur ) )
		return 0
	fi
	
	if [[ "$COMP_CWORD" == 1 ]]; then
		COMPREPLY=( $( compgen -W "$options" -- $cur ) )
		return 0
	fi
}

[ "$have" ] && complete -F _debtags $filenames debtags
# vim: syntax=sh