prev="${COMP_WORDS[COMP_CWORD-1]}"
opts="-c -d -D -K -n -o -L -R -U --config --no-detach --debug --net --option --mlock --logfile --pidfile --chroot --user --help --version"
confvars="Address AddressFamily BindToAddress BindToInterface Broadcast Cipher ClampMSS Compression ConnectTo DecrementTTL Device DeviceType Digest DirectOnly ECDSAPrivateKeyFile ECDSAPublicKey ECDSAPublicKeyFile ExperimentalProtocol Forwarding GraphDumpFile Hostnames IffOneQueue IndirectData Interface KeyExpire LocalDiscovery MACExpire MACLength MaxOutputBufferSize MaxTimeout Mode Name PMTU PMTUDiscovery PingInterval PingTimeout Port PriorityInheritance PrivateKeyFile ProcessPriority Proxy PublicKeyFile ReplayWindow StrictSubnets Subnet TCPOnly TunnelServer UDPRcvBuf UDPSndBuf VDEGroup VDEPort Weight"
- commands="config connect debug disconnect dump edit export export-all generate-ecdsa-keys generate-keys generate-rsa-keys help import info init log pcap pid purge reload restart retry start stop top version"
+ commands="add connect debug del disconnect dump edit export export-all generate-ecdsa-keys generate-keys generate-rsa-keys get help import info init log pcap pid purge reload restart retry set start stop top version"
case ${prev} in
-c|--config)
fi
COMPREPLY=( $(compgen -W "${commands}" -- ${cur}) )
case $prev in
- config)
- COMPREPLY=( $(compgen -W "get set add del ${confvars}" -- ${cur}) )
- return 0
- ;;
get|set|add|del)
COMPREPLY=( $(compgen -W "${confvars}" -- ${cur}) )
+ return 0
;;
dump|reachable)
COMPREPLY=( $(compgen -W "reachable nodes edges subnets connections graph" -- ${cur}) )
}
complete -F _tincd tincd
-complete -F _tincctl tincctl
+complete -F _tincctl tinc
static const struct {
const char *command;
int (*function)(int argc, char *argv[]);
+ bool hidden;
} commands[] = {
{"start", cmd_start},
{"stop", cmd_stop},
{"pcap", cmd_pcap},
{"log", cmd_log},
{"pid", cmd_pid},
- {"config", cmd_config},
+ {"config", cmd_config, true},
{"add", cmd_config},
{"del", cmd_config},
{"get", cmd_config},
{"set", cmd_config},
- {"change", cmd_config},
- {"replace", cmd_config},
{"init", cmd_init},
{"generate-keys", cmd_generate_keys},
{"generate-rsa-keys", cmd_generate_rsa_keys},
i++;
while(commands[i].command) {
- if(!strncasecmp(commands[i].command, text, strlen(text)))
+ if(!commands[i].hidden && !strncasecmp(commands[i].command, text, strlen(text)))
return xstrdup(commands[i].command);
i++;
}
}
static char *complete_config(const char *text, int state) {
- const char *sub[] = {"get", "set", "add", "del"};
static int i;
- if(!state) {
+
+ if(!state)
i = 0;
- if(!strchr(rl_line_buffer + 7, ' '))
- i = -4;
- else {
- bool found = false;
- for(int i = 0; i < 4; i++) {
- if(!strncasecmp(rl_line_buffer + 7, sub[i], strlen(sub[i])) && rl_line_buffer[7 + strlen(sub[i])] == ' ') {
- found = true;
- break;
- }
- }
- if(!found)
- return NULL;
- }
- } else {
+ else
i++;
- }
- while(i < 0 || variables[i].name) {
- if(i < 0 && !strncasecmp(sub[i + 4], text, strlen(text)))
- return xstrdup(sub[i + 4]);
- if(i >= 0) {
- char *dot = strchr(text, '.');
- if(dot) {
- if((variables[i].type & VAR_HOST) && !strncasecmp(variables[i].name, dot + 1, strlen(dot + 1))) {
- char *match;
- xasprintf(&match, "%.*s.%s", dot - text, text, variables[i].name);
- return match;
- }
- } else {
- if(!strncasecmp(variables[i].name, text, strlen(text)))
- return xstrdup(variables[i].name);
+ while(variables[i].name) {
+ char *dot = strchr(text, '.');
+ if(dot) {
+ if((variables[i].type & VAR_HOST) && !strncasecmp(variables[i].name, dot + 1, strlen(dot + 1))) {
+ char *match;
+ xasprintf(&match, "%.*s.%s", dot - text, text, variables[i].name);
+ return match;
}
+ } else {
+ if(!strncasecmp(variables[i].name, text, strlen(text)))
+ return xstrdup(variables[i].name);
}
i++;
}
matches = rl_completion_matches(text, complete_command);
else if(!strncasecmp(rl_line_buffer, "dump ", 5))
matches = rl_completion_matches(text, complete_dump);
- else if(!strncasecmp(rl_line_buffer, "config ", 7))
+ else if(!strncasecmp(rl_line_buffer, "add ", 4))
+ matches = rl_completion_matches(text, complete_config);
+ else if(!strncasecmp(rl_line_buffer, "del ", 4))
+ matches = rl_completion_matches(text, complete_config);
+ else if(!strncasecmp(rl_line_buffer, "get ", 4))
+ matches = rl_completion_matches(text, complete_config);
+ else if(!strncasecmp(rl_line_buffer, "set ", 4))
matches = rl_completion_matches(text, complete_config);
else if(!strncasecmp(rl_line_buffer, "info ", 5))
matches = rl_completion_matches(text, complete_info);