diff --git a/bird-complete.bash b/bird-complete.bash index 16795da3..4d9f9007 100644 --- a/bird-complete.bash +++ b/bird-complete.bash @@ -26,8 +26,6 @@ function _birdc_complete { NOW=$2 PREV=$3 - echo "bagr" >>xxb - case $PREV in -*([lvr])s) COMPREPLY=( $(compgen -W "$(find -maxdepth 1 -type s)" -- $NOW) ) @@ -46,7 +44,7 @@ function _birdc_complete { ;; 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 diff --git a/client/client.c b/client/client.c index 032c7fe2..b4e2c605 100644 --- a/client/client.c +++ b/client/client.c @@ -72,8 +72,8 @@ parse_args(int argc, char **argv) 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; } @@ -113,11 +113,18 @@ parse_args(int argc, char **argv) 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; diff --git a/client/client.h b/client/client.h index 7e2c438a..28b54169 100644 --- a/client/client.h +++ b/client/client.h @@ -38,6 +38,8 @@ char *cmd_expand(char *cmd); 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)) diff --git a/client/complete.c b/client/complete.c index 4e478b9e..559f3c65 100644 --- a/client/complete.c +++ b/client/complete.c @@ -14,8 +14,8 @@ #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: @@ -26,9 +26,9 @@ void complete_init(int argc, char **argv) { * ${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) @@ -37,9 +37,10 @@ void complete_init(int argc, char **argv) { 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; } @@ -50,7 +51,7 @@ int do_complete(char *cmd) { 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;