diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/fm.c | 31 | ||||
| -rw-r--r-- | src/keys.c | 17 |
2 files changed, 43 insertions, 5 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; +} + @@ -1,16 +1,18 @@ #include "keys.h" -#include <linux/limits.h> -#include <ncurses.h> -#include <stdio.h> -#include <stdlib.h> - #include "display.h" #include "err.h" #include "fm.h" #include "log.h" #include "mem.h" +#include "utils.h" #include "wm.h" +#include <errno.h> +#include <linux/limits.h> +#include <ncurses.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> bool keymap = false; @@ -91,6 +93,11 @@ handling_keys(int ch, fm_info *i) case '+': new_dir(i); break; + case 'R': + case 'r': { + fm_rename(i); + break; + } default: return; } |
