aboutsummaryrefslogtreecommitdiffstats
path: root/src/fm.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/fm.c')
-rw-r--r--src/fm.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/fm.c b/src/fm.c
index ea6a816..cb9cbc1 100644
--- a/src/fm.c
+++ b/src/fm.c
@@ -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;
+}
+