NOW=$2
PREV=$3
- echo "bagr" >>xxb
-
case $PREV in
-*([lvr])s)
COMPREPLY=( $(compgen -W "$(find -maxdepth 1 -type s)" -- $NOW) )
;;
esac
- COMPREPLY=( $($CMD -C "$NOW" "$COMP_TYPE" "$COMP_CWORD" "$COMP_POINT" "${COMP_WORDS[@]}") )
+ COMPREPLY=( $($CMD -C "$NOW" "$COMP_TYPE" "$COMP_CWORD" "${COMP_WORDS[@]}") )
}
complete -F _bird_complete bird
if ((argc > 1) && !strcmp(argv[1], "-C")) {
complete_init(argc-2, argv+2);
- argv += 6;
- argc -= 6;
+ argv += COMPLETE_ARGC + 2;
+ argc -= COMPLETE_ARGC + 2;
complete = 1;
}
tmp = init_cmd = malloc(len);
for (i = optind; i < argc; i++)
{
+ if (complete && (argv[i] == comp_last))
+ break;
strcpy(tmp, argv[i]);
tmp += strlen(tmp);
*tmp++ = ' ';
}
- tmp[-1] = 0;
+
+ if (complete) {
+ strcpy(tmp, comp_now);
+ tmp += strlen(comp_now);
+ } else
+ tmp[-1] = 0;
once = 1;
interactive = 0;
void complete_init(int argc, char **argv);
int do_complete(char *cmd);
+#define COMPLETE_ARGC 3
+extern const char *comp_now, *comp_last;
/* die() with system error messages */
#define DIE(x, y...) die(x ": %s", ##y, strerror(errno))
#include "nest/bird.h"
#include "client/client.h"
-static const char *c_now;
-static int comp_type, comp_cword, comp_point;
+static int comp_type, comp_cword;
+const char *comp_now, *comp_last;
void complete_init(int argc, char **argv) {
/* In argv, there are:
* ${COMP_WORDS[@]}
*/
- c_now = argv[0];
+ comp_now = argv[0];
- if (argc < 4)
+ if (argc < COMPLETE_ARGC)
die("Not enough args.");
if (sscanf(argv[1], "%d", &comp_type) != 1)
if (sscanf(argv[2], "%d", &comp_cword) != 1)
die("Strange COMP_CWORD=\"%s\".", argv[2]);
- if (sscanf(argv[3], "%d", &comp_point) != 1)
- die("Strange COMP_POINT=\"%s\".", argv[3]);
+ if (comp_cword + COMPLETE_ARGC >= argc)
+ die("COMP_CWORD=%d points after end of arg list.", comp_cword);
+ comp_last = argv[COMPLETE_ARGC + comp_cword];
return;
}
char buf[256];
int res = cmd_complete(cmd, strlen(cmd), buf, (comp_type == 63));
if (res == 1)
- printf("%s%s\n", c_now, buf);
+ printf("%s%s\n", comp_now, buf);
return 0;