sfm

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

commit e2f4b1dd1f23f93303a3e1e0593a6a89f9be9cc4
parent 5d77124f7af9718b6e18a264262f178a650cf849
Author: afify <hassan@afify.dev>
Date:   Sat,  5 Dec 2020 11:56:57 +0300

[ref] delete cmd

- change delete key to 'd'
- change confirmation to "yes"
- use strncmp

Diffstat:
Mconfig.def.h | 4++--
Msfm.1 | 2+-
Msfm.c | 16+++++++++-------
3 files changed, 12 insertions(+), 10 deletions(-)

diff --git a/config.def.h b/config.def.h @@ -67,7 +67,7 @@ static Key nkeys[] = { { {.key = TB_KEY_CTRL_D}, scrdwn }, { {.ch = 'n'}, crnf }, { {.ch = 'N'}, crnd }, - { {.ch = 'D'}, delfd }, + { {.ch = 'd'}, delfd }, { {.ch = 'x'}, calcdir }, { {.ch = '/'}, filter }, { {.ch = 'q'}, quit }, @@ -84,7 +84,7 @@ static Key skeys[] = { { {.ch = 'k'}, selup }, { {.ch = 'a'}, selall }, { {.ch = 'y'}, selynk }, - { {.ch = 'D'}, seldel }, + { {.ch = 'd'}, seldel }, { {.key = TB_KEY_ESC}, selcan }, { {.ch = 'r'}, selrename }, }; diff --git a/sfm.1 b/sfm.1 @@ -48,7 +48,7 @@ create new file if not exists .B N create new directory if not exists .TP -.B D +.B d delete file | directory recursively .TP .B / diff --git a/sfm.c b/sfm.c @@ -727,16 +727,18 @@ get_hicol(Cpair *col, mode_t mode) static int delent(char *fullpath) { - char *confirmation; + char *inp_conf; char *rm_cmd[] = { "rm", "-rf", NULL }; + int conf_len = 4; + char conf[] = "yes"; - confirmation = ecalloc(2, sizeof(char)); - if ((get_usrinput(confirmation, 2, "delete file (Y) ?") < 0) || - (strcmp(confirmation, "Y") != 0)) { - free(confirmation); - return 1; /* canceled by user or wrong confirmation */ + inp_conf = ecalloc(conf_len, sizeof(char)); + if ((get_usrinput(inp_conf, conf_len, "delete file (yes) ?") < 0) || + (strncmp(inp_conf, conf, conf_len) != 0)) { + free(inp_conf); + return 1; /* canceled by user or wrong inp_conf */ } - free(confirmation); + free(inp_conf); return spawn(rm_cmd, fullpath); }