sfm

simple file manager
git clone git://git.afify.dev/sfm
Log | Files | Refs | README | LICENSE

commit c93bd0f1cbca2de1c22c0885f9531aeda83dee04
parent e2f4b1dd1f23f93303a3e1e0593a6a89f9be9cc4
Author: afify <hassan@afify.dev>
Date:   Sat,  5 Dec 2020 13:05:54 +0300

[ref] simple rename, update keys

- remove: xrename, selrename
- change rename key to c
- update man page, README

Diffstat:
MREADME.md | 11+++++++----
Mconfig.def.h | 3+--
Msfm.1 | 12++++++++++++
Msfm.c | 51++++++++++++---------------------------------------
4 files changed, 32 insertions(+), 45 deletions(-)

diff --git a/README.md b/README.md @@ -1,10 +1,9 @@ -![sfm](https://github.com/afify/sfm/blob/master/sfm.png?raw=true) +![sfm](https://github.com/afify/sfm/blob/main/sfm.png?raw=true) **simple file manager** [![Language grade: C/C++](https://img.shields.io/lgtm/grade/cpp/g/afify/sfm.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/afify/sfm/context:cpp) [![Build status](https://ci.appveyor.com/api/projects/status/goq88ahjyvtjrui2?svg=true)](https://ci.appveyor.com/project/afify/sfm) -[![License](https://img.shields.io/github/license/afify/sfm?color=blue)](https://github.com/afify/sfm/blob/master/LICENSE) Description ------------ @@ -14,7 +13,7 @@ dual pane, bottom statusbar, bookmarks, open files by extention, vim-like key bi * Inspired by [vifm](https://vifm.info/) and [noice](https://git.2f30.org/noice/). * Follows the suckless [philosophy](https://suckless.org/philosophy/) and [code style](https://suckless.org/coding_style/). -<img src="https://github.com/afify/afify.github.io/raw/master/img/sfm_sc.png" alt="drawing" width="800"/> +<img src="https://github.com/afify/afify.github.io/raw/main/img/sfm_sc.png" alt="drawing" width="800"/> Options ------- @@ -38,7 +37,11 @@ $ man sfm | `ctrl+d` | scroll down | | `n` | create new file | | `N` | create new dir | -| `D` | delete file \| dir | +| `d` | delete file \| dir | +| `y` | yank | +| `p` | past | +| `P` | move | +| `c` | rename | | `/` | start filter | | `ENTER` | find filter | | `ESC` | exit filter | diff --git a/config.def.h b/config.def.h @@ -75,7 +75,7 @@ static Key nkeys[] = { { {.ch = 'y'}, yank }, { {.ch = 'p'}, selpst }, { {.ch = 'P'}, selmv }, - { {.ch = 'r'}, rname }, + { {.ch = 'c'}, rname }, { {.key = TB_KEY_SPACE}, switch_pane }, }; @@ -86,7 +86,6 @@ static Key skeys[] = { { {.ch = 'y'}, selynk }, { {.ch = 'd'}, seldel }, { {.key = TB_KEY_ESC}, selcan }, - { {.ch = 'r'}, selrename }, }; static const size_t nkeyslen = LEN(nkeys); diff --git a/sfm.1 b/sfm.1 @@ -51,6 +51,18 @@ create new directory if not exists .B d delete file | directory recursively .TP +.B y +yank +.TP +.B p +paste +.TP +.B P +move +.TP +.B c +rename +.TP .B / start filter .TP diff --git a/sfm.c b/sfm.c @@ -160,13 +160,11 @@ static void selcalc(void); static void selpst(void); static void selmv(void); static void seldel(void); -static void selrename(void); static char *get_path_hdir(int); static void init_files(void); static void free_files(void); static void yank(void); static void rname(void); -static void xrename(char *); static void switch_pane(void); static void quit(void); static void grabkeys(struct tb_event*, Key*, size_t); @@ -1608,37 +1606,6 @@ selmv(void) } -static void -selrename(void) -{ - init_files(); - for (size_t i = 0; i < selection_size; i++) { - xrename(files[i]); - } - if (listdir(AddHi, NULL) < 0) - print_error(strerror(errno)); - free_files(); - sl = -1; -} - -static void -xrename(char *path) -{ - char *new_name; - new_name = ecalloc(MAX_N, sizeof(char)); - - if (get_usrinput(new_name, MAX_N, "rename: %s", basename(path)) < 0) { - free(new_name); - return; - } - char *rename_cmd[] = {"mv", path, new_name, NULL}; - - if (spawn(rename_cmd, NULL) < 0) - print_error(strerror(errno)); - - free(new_name); -} - static char* get_path_hdir(int Ndir) { @@ -1654,13 +1621,19 @@ get_path_hdir(int Ndir) static void rname(void) { - if (cpane->selection != NULL) { - free(cpane->selection); - cpane->selection = NULL; + char *new_name; + new_name = ecalloc(MAX_N, sizeof(char)); + + if (get_usrinput(new_name, MAX_N, "rename: %s", basename(CURSOR_NAME)) < 0) { + free(new_name); + return; } - cpane->selection = ecalloc(2, sizeof(size_t)); - cpane->selection[0] = cpane->hdir; - selrename(); + + char *rename_cmd[] = { "mv", CURSOR_NAME, new_name, NULL }; + if (spawn(rename_cmd, NULL) < 0) + print_error(strerror(errno)); + + free(new_name); } static void