sfm

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

commit a2b8083a931ea289df06d50bcd583554b71642c5
parent a9537187196cd2fc97430522f01196f0a9eb9fcf
Author: afify <hassan@afify.dev>
Date:   Mon, 13 Sep 2021 20:51:58 +0300

[feat] add change mode [cm]

Diffstat:
MREADME.md | 3++-
Mconfig.def.h | 4+++-
Msfm.1 | 5++++-
Msfm.c | 33++++++++++++++++++++++++++++++++-
4 files changed, 41 insertions(+), 4 deletions(-)

diff --git a/README.md b/README.md @@ -71,7 +71,8 @@ $ man sfm | `P` | move | | `c` | rename | | `cw` | rename | -| `co` | owner and group | +| `co` | change owner and group | +| `cm` | change mode | | `cc` | exit change | | `cq` | exit change | | `.` | toggle dotfiles | diff --git a/config.def.h b/config.def.h @@ -26,12 +26,14 @@ static const Cpair cstatus = { 243, 0 }; static const char *rm_cmd[] = { "rm", "-rf" }; /* delete */ static const char *cp_cmd[] = { "cp", "-r" }; /* copy */ static const char *chown_cmd[] = { "chown", "-R" }; /* change file owner and group */ +static const char *chmod_cmd[] = { "chmod" }; /* change file mode bits */ static const char *mv_cmd[] = { "mv" }; /* move */ static const char delconf[] = "yes"; static const size_t rm_cmd_len = LEN(rm_cmd); static const size_t cp_cmd_len = LEN(cp_cmd); static const size_t chown_cmd_len = LEN(chown_cmd); +static const size_t chmod_cmd_len = LEN(chmod_cmd); static const size_t mv_cmd_len = LEN(mv_cmd); static const size_t delconf_len = LEN(delconf); @@ -104,7 +106,7 @@ static Key ckeys[] = { /* keyval function arg */ { {.ch = 'w'}, rname, {0} }, { {.ch = 'o'}, chngo, {0} }, -// { {.ch = 'p'}, chngp, {0} }, + { {.ch = 'm'}, chngm, {0} }, // { {.ch = 'a'}, chngq, {0} }, { {.ch = 'q'}, exit_change, {0} }, { {.ch = 'c'}, exit_change, {0} }, diff --git a/sfm.1 b/sfm.1 @@ -70,7 +70,10 @@ start change rename .TP .B co -owner and group +change owner and group (chown) +.TP +.B cm +change mode (chmod) .TP .B cc exit change diff --git a/sfm.c b/sfm.c @@ -170,6 +170,7 @@ static void free_files(void); static void yank(const Arg *arg); static void rname(const Arg *arg); static void chngo(const Arg *arg); +static void chngm(const Arg *arg); static void dupl(const Arg *arg); static void switch_pane(const Arg *arg); static void quit(const Arg *arg); @@ -1228,7 +1229,7 @@ start_change(const Arg *arg) struct tb_event fev; cont_change = 0; - print_prompt("c [wopa]"); + print_prompt("c [woma]"); tb_present(); while (tb_poll_event(&fev) != 0) { switch (fev.type) { @@ -1435,6 +1436,7 @@ rname(const Arg *arg) if (get_usrinput(input_name, MAX_N, "rename: %s", basename(CURSOR(cpane).name)) < 0) { + exit_change(0); free(input_name); return; } @@ -1464,6 +1466,7 @@ chngo(const Arg *arg) if (get_usrinput(input_og, MAX_N, "OWNER:GROUP %s", basename(CURSOR(cpane).name)) < 0) { + exit_change(0); free(input_og); return; } @@ -1480,6 +1483,34 @@ chngo(const Arg *arg) } static void +chngm(const Arg *arg) +{ + if (cpane->dirc < 1) + return; + char *input_og; + char *tmp[1]; + + input_og = ecalloc(MAX_N, sizeof(char)); + + if (get_usrinput(input_og, MAX_N, "chmod %s", + basename(CURSOR(cpane).name)) < 0) { + exit_change(0); + free(input_og); + return; + } + + tmp[0] = input_og; + if (spawn(chmod_cmd, chmod_cmd_len, tmp, 1, CURSOR(cpane).name, + DontWait) < 0) { + print_error(strerror(errno)); + return; + } + + free(input_og); + exit_change(0); +} + +static void dupl(const Arg *arg) { if (cpane->dirc < 1)