]> git.sur5r.net Git - ngadmin/commitdiff
Cli: switch to filename completion after terminal commands
authordarkcoven <admin@darkcoven.tk>
Sat, 12 Oct 2013 16:32:48 +0000 (18:32 +0200)
committerdarkcoven <admin@darkcoven.tk>
Sat, 12 Oct 2013 17:47:24 +0000 (19:47 +0200)
cli/src/admin.c

index 73ea79c7a3cc143a8cdcb5a48cadb70d857de0ca..ffc567f1929e5422e7d10a3b3813830d0cf60496 100644 (file)
@@ -86,7 +86,6 @@ static char* my_generator (const char* text, int state)
 
 static char** my_completion (const char *text, int start, int end UNUSED)
 {
-       char **matches = NULL;
        char *line, *com[MAXCOM];
        int i, n;
        
@@ -99,16 +98,15 @@ static char** my_completion (const char *text, int start, int end UNUSED)
        free(line);
        
        compcur = getSubCom(com, n, &i);
-       
-       if (i < n)
-               compcur = NULL;
-       matches = rl_completion_matches(text, my_generator);
-       
        for (i = 0; com[i] != NULL; i++)
                free(com[i]);
        
-       
-       return matches;
+       if (i < n) /* unknown command */
+               return NULL;
+       else if (compcur->sub == NULL) /* terminal command */
+               return rl_completion_matches(text, rl_filename_completion_function);
+       else /* intermediate command */
+               return rl_completion_matches(text, my_generator);
 }
 #endif /* HAVE_LIBREADLINE */