sfm

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

commit 93c033c1b33a49565c762e7939a9412cd1781b97
parent a2b8083a931ea289df06d50bcd583554b71642c5
Author: afify <hassan@afify.dev>
Date:   Thu, 16 Sep 2021 23:36:40 +0300

[feat] add change flags

Diffstat:
MREADME.md | 1+
Mconfig.def.h | 35+++++++++++++++++++++--------------
Msfm.1 | 3+++
Msfm.c | 31++++++++++++++++++++++++++++++-
4 files changed, 55 insertions(+), 15 deletions(-)

diff --git a/README.md b/README.md @@ -73,6 +73,7 @@ $ man sfm | `cw` | rename | | `co` | change owner and group | | `cm` | change mode | +| `cf` | change flags | | `cc` | exit change | | `cq` | exit change | | `.` | toggle dotfiles | diff --git a/config.def.h b/config.def.h @@ -23,19 +23,26 @@ static const Cpair csearch = { 255, 0 }; static const Cpair cstatus = { 243, 0 }; /* commands */ -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); +#if defined(__linux__) +#define CHFLAG "chattr" +#else +#define CHFLAG "chflags" +#endif +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 *chflags_cmd[] = { CHFLAG }; /* change file flags */ +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 chflags_cmd_len = LEN(chflags_cmd); +static const size_t mv_cmd_len = LEN(mv_cmd); +static const size_t delconf_len = LEN(delconf); /* bookmarks */ static const char root[] = "/"; @@ -107,7 +114,7 @@ static Key ckeys[] = { { {.ch = 'w'}, rname, {0} }, { {.ch = 'o'}, chngo, {0} }, { {.ch = 'm'}, chngm, {0} }, -// { {.ch = 'a'}, chngq, {0} }, + { {.ch = 'f'}, chngf, {0} }, { {.ch = 'q'}, exit_change, {0} }, { {.ch = 'c'}, exit_change, {0} }, { {.key = TB_KEY_ESC}, exit_change, {0} }, diff --git a/sfm.1 b/sfm.1 @@ -75,6 +75,9 @@ change owner and group (chown) .B cm change mode (chmod) .TP +.B cf +change flags (chflags | chattr) +.TP .B cc exit change .TP diff --git a/sfm.c b/sfm.c @@ -171,6 +171,7 @@ 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 chngf(const Arg *arg); static void dupl(const Arg *arg); static void switch_pane(const Arg *arg); static void quit(const Arg *arg); @@ -1229,7 +1230,7 @@ start_change(const Arg *arg) struct tb_event fev; cont_change = 0; - print_prompt("c [woma]"); + print_prompt("c [womf]"); tb_present(); while (tb_poll_event(&fev) != 0) { switch (fev.type) { @@ -1511,6 +1512,34 @@ chngm(const Arg *arg) } static void +chngf(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, CHFLAG" %s", + basename(CURSOR(cpane).name)) < 0) { + exit_change(0); + free(input_og); + return; + } + + tmp[0] = input_og; + if (spawn(chflags_cmd, chflags_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)