[go: up one dir, main page]

File: bash-completion

package info (click to toggle)
debtags 1.12.3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 2,092 kB
  • ctags: 341
  • sloc: sh: 3,990; cpp: 1,259; python: 720; makefile: 77
file content (115 lines) | stat: -rw-r--r-- 2,630 bytes parent folder | download | duplicates (2)
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
# 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

	# Helper function to keep up with ":"
	_get_comp_words_by_ref -n : cur prev words cword

	COMPREPLY=()
	options='cat check diff dumpavail grep help \
		mkpatch search \
		show submit tag tagcat tagsearch \
		tagshow update vocfilter'

	for (( i=0; i < ${#words[@]}; i++ )); do
		case ${words[i]} in
		# commands requiring a filename
		check|mkpatch|diff|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 "${words[cword-2]}" ]]; then
					case ${words[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)
			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- ) )

			# Helper function to keep up with ":"
			__ltrim_colon_completions "$cur"
			return 0
			;;
		# commands requiring an expression
		grep|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- ) )

			# Helper function to keep up with ":"
			__ltrim_colon_completions "$cur"
			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 [[ "$cword" == 1 ]]; then
		COMPREPLY=( $( compgen -W "$options" -- $cur ) )
		return 0
	fi
}

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