Fix #13738 - Autocomplete $aliases ##cons

This commit is contained in:
radare 2019-04-14 17:45:55 +02:00 committed by GitHub
parent 022550293c
commit cfdd09c838
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 7 deletions

View File

@ -188,12 +188,10 @@ R_API int r_cmd_add_long(RCmd *cmd, const char *lcmd, const char *scmd, const ch
}
R_API int r_cmd_add(RCmd *c, const char *cmd, const char *desc, r_cmd_callback(cb)) {
struct r_cmd_item_t *item;
int idx = (ut8)cmd[0];
item = c->cmds[idx];
RCmdItem *item = c->cmds[idx];
if (!item) {
item = R_NEW (RCmdItem);
item = R_NEW0 (RCmdItem);
c->cmds[idx] = item;
}
strncpy (item->cmd, cmd, sizeof (item->cmd)-1);

View File

@ -817,7 +817,7 @@ static const char *radare_argv[] = {
"whereis", "which", "ls", "rm", "mkdir", "pwd", "cat", "less", "exit", "quit",
"#?", "#!", "#sha1", "#crc32", "#pcprint", "#sha256", "#sha512", "#md4", "#md5",
"#!python", "#!vala", "#!pipe",
"*?", "*",
"*?", "*", "$",
"(", "(*", "(-", "()", ".?", ".", "..", "...", ".:", ".--", ".-", ".!", ".(", "./", ".*",
"_?", "_",
"=?", "=", "=<", "=!", "=+", "=-", "==", "=!=", "!=!", "=:", "=&:",
@ -1821,6 +1821,17 @@ static int autocomplete(RLine *line) {
ls_free (l);
line->completion.argc = i;
line->completion.argv = tmp_argv;
} else if (!strncmp (line->buffer.data, "$", 1)) {
int i, j = 0;
for (i = 0; i < core->rcmd->aliases.count; i++) {
const char *key = core->rcmd->aliases.keys[i];
int len = strlen (line->buffer.data);
if (!len || !strncmp (line->buffer.data, key, len)) {
tmp_argv[j++] = strdup (key);
}
}
line->completion.argc = j;
line->completion.argv = tmp_argv;
} else if (!strncmp (line->buffer.data, "ts ", 3)
|| !strncmp (line->buffer.data, "ta ", 3)
|| !strncmp (line->buffer.data, "tp ", 3)
@ -1835,9 +1846,10 @@ static int autocomplete(RLine *line) {
int chr = (line->buffer.data[2] == ' ')? 3: 4;
ls_foreach (l, iter, kv) {
int len = strlen (line->buffer.data + chr);
if (!len || !strncmp (line->buffer.data + chr, sdbkv_key (kv), len)) {
const char *key = sdbkv_key (kv);
if (!len || !strncmp (line->buffer.data + chr, key, len)) {
if (!strncmp (sdbkv_value (kv), "struct", strlen ("struct") + 1)) {
tmp_argv[i++] = strdup (sdbkv_key (kv));
tmp_argv[i++] = strdup (key);
}
}
}