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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
|
ipset-bash-completion
=====================
Description
===========
Programmable completion specification (compspec) for the bash shell
to support the ipset program (netfilter.org).
Programmable completion allows the user, while working in an interactive shell,
to retrieve and auto-complete commands, their options, filenames, etc.
Pressing [TAB] will complete on the current word, if only one match is found.
If multiple completions are possible, they will be listed by hitting [TAB] again.
Features
========
This completion specification follows the logic of ipset and
will show commands and options only when they are available for the current context
(combination of commands and/or options).
Providing some kind of interactive help.
- Show and complete commands and options.
- Show and complete set names.
- Show and complete the set types when using the create and help command.
- Show and complete set elements (members) when using the del command.
- Show and complete services (also named port ranges), protocols,
icmp[6] types and interface names when adding, deleting or testing elements.
- Show and complete hostnames, when adding, deleting or testing elements.
- Show and complete ip and mac addresses (dynamically and from file).
- Complete on filenames if the current option requires it.
- Complete variable names and command substitution.
- Do not complete if an invalid combination of options is used.
- Do not complete if an invalid value of an option argument is detected.
- Environment variables allow to modify completion behaviour.
Installation
============
Put it into ~/.bash_completion or /etc/bash_completion.d/.
Tip:
To make tab completion more handsome put the following into either
/etc/inputrc or ~/.inputrc:
set show-all-if-ambiguous on
This will allow single tab completion as opposed to requiring a double tab.
set page-completions off
This turns off the use of the internal pager when returning long completion lists.
Usage
=====
Type -[TAB] to start option completion.
Sets named - (hyphen) or starting with it, are supported,
excluded are option names (i.e. -exist).
Type [TAB] to complete on anything available at the current context.
Depending on the environment variable **_IPSET_COMPL_OPT_FORMAT**,
either the long, short or both forms of options are shown for completion.
By default (empty _IPSET_COMPL_OPT_FORMAT) the long versions of options
are displayed (_IPSET_COMPL_OPT_FORMAT=long also does the same).
Setting it to 'short' will cause completion to show only the short form.
Setting it to any other value, will result in both version being displayed and completed.
---
To complete named port ranges, enter the hypen after the first completed service (port) name,
hit [TAB] again to start completion on the second named port (the brackets [] for service names
containing a - (hyphen) are already surrounding the name in the completion list).
---
The environment variable **HOSTFILE** controls how hostname completion is performed.
Taking the description from the bash man-page:
Contains the name of a file in the same format as /etc/hosts that
should be read when the shell needs to complete a hostname.
The list of possible hostname completions may be changed while the shell is running
the next time hostname completion is attempted after the value is changed,
bash adds the contents of the new file to the existing list.
If HOSTFILE is set, but has no value, or does not name a readable file, bash
attempts to read /etc/hosts to obtain the list of possible hostname completions.
When HOSTFILE is unset, the hostname list is cleared.
As it is impossible to distinguish between IPv4 and IPv6 hostnames without resolving
them, it is considered best practice to seperate IPv4 hosts from IPv6 hosts
in different files.
If the *bash-completion* package is available hostname completion is extended
the following way (description from bash-completion source):
Helper function for completing _known_hosts.
This function performs host completion based on ssh config and known_hosts
files, as well as hostnames reported by avahi-browse if
COMP_KNOWN_HOSTS_WITH_AVAHI is set to a non-empty value.
Also hosts from HOSTFILE (compgen -A hostname) are added, unless
COMP_KNOWN_HOSTS_WITH_HOSTFILE is set to an empty value.
Also the environment variable **_IPSET_SSH_CONFIGS** controls which files are taken
as ssh_config files, in order to retrieve the global and user known_host files,
which will be used for hostname completion.
For all *net* type of sets and the hash:ip,mark set type, if hostname completion is attempted,
if the environment variable **_IPSET_COMP_NETWORKS** is set to a non-empty value,
networks are retrieved from /etc/networks.
Also a list of ip addresses can be supplied using the environment variable
**_IPSET_IPLIST_FILE**. Which should point to a file containing an ip address per line.
They can be ipv4 and/or ipv6. Detection which type should be included
is done automatically based on the set header.
---
When deleting elements from any but list:set set types:
the environment variable **_IPSET_COMPL_DEL_MODE** is queried to decide how to complete.
If it is set to 'members' it will list the members of the set.
If it is set to 'spec' it will follow the format of a port specification ([proto:]port).
If it is set to any other value both methods are used to generate
the list of possible completions (this is the default).
---
When testing elements from any but list:set set types:
the environment variable **_IPSET_COMPL_TEST_MODE** is queried to decide how to complete.
If it is set to 'members' it will list the members of the set.
If it is set to 'spec' it will follow the format of a port specification ([proto:]port).
If it is set to any other value both methods are used to generate
the list of possible completions (this is the default).
---
When adding elements to a **bitmap:ip,mac** type of set,
the environment variable **_IPSET_MACLIST_FILE** will be queried
for a file containing a list of mac addresses.
The file should contain one mac address per line.
Empty lines and comments (also after the address) are supported.
If the variable is unset mac addresses are fetched from arp cache,
/etc/ethers and the output of `ip link show`.
---
When adding elements to one of the following set types:
**hash:ip,port hash:ip,port,ip hash:ip,port,net hash:net,port hash:net,port,net**
and completion is attempted on the port specification,
the list of possible completions may become quite long.
Especially if no characters are given to match on.
This behaviour is because of the many different
values such a port specification can possibly have.
---
At any time completion on variable names (starting with '$' or '${'),
or command substitution (starting with '$(') is available.
Using this with values validated by input validation, will stop further completion.
In that case it is recommended to disable input validation (see below).
---
If the environment variable **_IPSET_VALIDATE_INPUT** is set to a non empty value
validation of users input is disabled.
---
If the environment variable **_DEBUG_NF_COMPLETION** is defined (any value)
debugging information is displayed.
Compatibility
=============
Compatible with ipset versions 6+.
Tested with ipset v6.20.1.
bash v4+ is required.
Compatibility for future ipset versions cannot be promised, as new options may appear,
which of course are currently unpredictable.
The bash-completion (v2.0+) package is highly recommended, though not mandatory.
http://bash-completion.alioth.debian.org/
Some things might not be that reliable or feature rich without it.
Also the colon (if there) is removed from COMP_WORDBREAKS.
This alteration is globally, which might affect other completions,
if they do not take care of it themselves.
The iproute program (ip) is needed to display information about the local system.
Availability
============
https://github.com/AllKind/ipset-bash-completion
http://sourceforge.net/projects/ipset-bashcompl/
Bugs
============
Please report bugs!
|