diff options
Diffstat (limited to 'src/fm.c')
| -rw-r--r-- | src/fm.c | 31 |
1 files changed, 31 insertions, 0 deletions
@@ -554,3 +554,34 @@ new_dir(fm_info *info) fm_getdir(info->cur, info->cwd); return 0; } + +int +fm_rename(fm_info *info) +{ + if (!info) + return -1; + + char newname[PATH_MAX] = {0}; + + size_t len = snprintf(newname, sizeof(newname), "%s/%s", info->cwd, + info->cur->items[info->cursor].name); + if (len >= sizeof(newname)) { + die("Length of items error"); + } + + char *oldname = info->cur->items[info->cursor].name; + get_input("New name: ", newname, strlen(newname)); + + if (rename(oldname, newname) == 0) { + need_redraw = true; + fm_getdir(info->cur, info->cwd); + } else { + if (errno == EXDEV) { + /* TODO: copy and link manually */ + return -1; + } + } + + return 0; +} + |
