Handle \~ in r_core_cmd and extend 'cd' command to handle home expansion

This commit is contained in:
pancake 2014-08-20 11:29:44 +02:00
parent 444a77022f
commit 6d4ca16d1e
2 changed files with 25 additions and 11 deletions

View File

@ -701,7 +701,6 @@ R_API int r_core_cmd_pipe(RCore *core, char *radare_cmd, char *shell_cmd) {
}
if (*shell_cmd=='!') {
_ptr = (char *)r_str_lastbut (shell_cmd, '~', "\"");
//ptr = strchr (cmd, '~');
if (_ptr) {
*_ptr = '\0';
_ptr++;
@ -1086,6 +1085,13 @@ next2:
/* grep the content */
ptr = (char *)r_str_lastbut (cmd, '~', quotestr);
if (ptr>cmd) {
char *escape = ptr-1;
if (*escape == '\\') {
memmove (escape, ptr, strlen (escape));
ptr = NULL;
}
}
if (*cmd!='.' && ptr) {
*ptr = '\0';
ptr++;

View File

@ -284,17 +284,25 @@ static int cmd_cmp(void *data, const char *input) {
}
break;
case 'd':
if (input[1] != ' ') {
char* home = NULL;
home = r_sys_getenv(R_SYS_HOME);
if (!home || r_sandbox_chdir (home)==-1)
eprintf ("Cannot chdir\n");
free (home);
break;
}
while (input[1]==' ') input++;
if (r_sandbox_chdir (input+1)==-1)
eprintf ("Cannot chdir\n");
if (input[1]) {
if (input[1]=='~' && input[2]=='/') {
char *homepath = r_str_home (input+3);
if (homepath && *homepath) {
if (r_sandbox_chdir (homepath)==-1)
eprintf ("Cannot chdir to %s\n", homepath);
free (homepath);
} else eprintf ("Cannot find home\n");
} else {
if (r_sandbox_chdir (input+1)==-1)
eprintf ("Cannot chdir to %s\n", input+1);
}
} else {
char* home = r_sys_getenv (R_SYS_HOME);
if (!home || r_sandbox_chdir (home)==-1)
eprintf ("Cannot find home.\n");
free (home);
}
break;
case '2':
v16 = (ut16) r_num_math (core->num, input+1);