Fix #3585 - Implement cp and mv #syscmd

This commit is contained in:
pancake 2015-10-25 02:32:22 +02:00
parent 9ff2cb4e5b
commit 63fa578363
2 changed files with 35 additions and 1 deletions

View File

@ -426,6 +426,38 @@ static int cmd_mkdir(void *data, const char *input) {
return 0;
}
static int cmd_mv(void *data, const char *input) {
if (strlen (input)<3) {
eprintf ("Usage: mv src dst\n");
return 0;
}
input = input + 2;
if (!r_sandbox_enable(0)) {
#if __WINDOWS__
r_sys_cmdf ("move %s", input);
#else
r_sys_cmdf ("mv %s", input);
#endif
}
return 0;
}
static int cmd_cp(void *data, const char *input) {
if (strlen (input)<3) {
eprintf ("Usage: cp src dst\n");
return 0;
}
input = input + 2;
if (!r_sandbox_enable(0)) {
#if __WINDOWS__
r_sys_cmdf ("copy %s", input);
#else
r_sys_cmdf ("cp %s", input);
#endif
}
return 0;
}
static int cmd_stdin(void *data, const char *input) {
RCore *core = (RCore *)data;
if (input[0]=='?') {
@ -2383,6 +2415,8 @@ R_API void r_core_cmd_init(RCore *core) {
r_cmd_add (core->rcmd, "/", "search kw, pattern aes", &cmd_search);
r_cmd_add (core->rcmd, "-", "open cfg.editor and run script", &cmd_stdin);
r_cmd_add (core->rcmd, "ls", "list files and directories", &cmd_ls);
r_cmd_add (core->rcmd, "mv", "move file or directory", &cmd_mv);
r_cmd_add (core->rcmd, "cp", "copy file or directory", &cmd_cp);
r_cmd_add (core->rcmd, "mkdir", "make directory", &cmd_mkdir);
r_cmd_add (core->rcmd, "(", "macro", &cmd_macro);
r_cmd_add (core->rcmd, "quit", "exit program session", &cmd_quit);

View File

@ -142,7 +142,7 @@ R_API void r_core_syscmd_ls(const char *input) {
memcpy (d, path, off);
path = (const char *)d;
pattern = strdup (p+1);
}else {
} else {
pattern = strdup (path);
path = ".";
}