2017-05-17 15:15:42 +00:00
|
|
|
/*
|
|
|
|
* BIRD Client Bash Expansion
|
|
|
|
*
|
|
|
|
* (c) 2017 Jan Moskyto Matejka <mq@jmq.cz>
|
|
|
|
*
|
|
|
|
* Can be freely distributed and used under the terms of the GNU GPL.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "nest/bird.h"
|
|
|
|
#include "client/client.h"
|
|
|
|
|
2017-05-18 11:54:56 +00:00
|
|
|
static int comp_type, comp_cword;
|
|
|
|
const char *comp_now, *comp_last;
|
2017-05-17 15:15:42 +00:00
|
|
|
|
|
|
|
void complete_init(int argc, char **argv) {
|
|
|
|
/* In argv, there are:
|
|
|
|
* $NOW
|
|
|
|
* $COMP_TYPE
|
|
|
|
* $COMP_CWORD
|
|
|
|
* $COMP_POINT
|
|
|
|
* ${COMP_WORDS[@]}
|
|
|
|
*/
|
|
|
|
|
2017-05-18 11:54:56 +00:00
|
|
|
comp_now = argv[0];
|
2017-05-17 15:15:42 +00:00
|
|
|
|
2017-05-18 11:54:56 +00:00
|
|
|
if (argc < COMPLETE_ARGC)
|
2017-05-17 15:15:42 +00:00
|
|
|
die("Not enough args.");
|
|
|
|
|
|
|
|
if (sscanf(argv[1], "%d", &comp_type) != 1)
|
|
|
|
die("Strange COMP_TYPE=\"%s\".", argv[1]);
|
|
|
|
|
|
|
|
if (sscanf(argv[2], "%d", &comp_cword) != 1)
|
|
|
|
die("Strange COMP_CWORD=\"%s\".", argv[2]);
|
|
|
|
|
2017-05-18 11:54:56 +00:00
|
|
|
if (comp_cword + COMPLETE_ARGC >= argc)
|
|
|
|
die("COMP_CWORD=%d points after end of arg list.", comp_cword);
|
2017-05-17 15:15:42 +00:00
|
|
|
|
2017-05-18 11:54:56 +00:00
|
|
|
comp_last = argv[COMPLETE_ARGC + comp_cword];
|
2017-05-17 15:15:42 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int do_complete(char *cmd) {
|
|
|
|
if ((*cmd == 0) && (comp_type == 63))
|
|
|
|
printf("-s\n-l\n-v\n-r\n");
|
|
|
|
|
|
|
|
char buf[256];
|
2017-05-31 13:04:27 +00:00
|
|
|
int res = cmd_complete(cmd, strlen(cmd), buf, 1);
|
2017-05-17 15:15:42 +00:00
|
|
|
if (res == 1)
|
2017-05-18 11:54:56 +00:00
|
|
|
printf("%s%s\n", comp_now, buf);
|
2017-05-17 15:15:42 +00:00
|
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|