commit 23b0e51c6024ab5af4cab2a231c4f526d0a6d60a
parent 1149897d041a6dd5092662acb9693e86cc059038
Author: afify <hassan@afify.dev>
Date: Sat, 29 May 2021 22:52:44 +0300
[feat] merge bookmarks in Keys
Diffstat:
M | config.def.h | | | 11 | +++++------ |
M | sfm.c | | | 54 | ++++++++++++++++++------------------------------------ |
2 files changed, 23 insertions(+), 42 deletions(-)
diff --git a/config.def.h b/config.def.h
@@ -26,9 +26,7 @@ static const size_t cp_cmd_len = LEN(cp_cmd);
static const size_t mv_cmd_len = LEN(mv_cmd);
/* bookmarks */
-static Bookmark bmarks[] = {
- {'\\', "/root"},
-};
+static const char root[] = "/";
/* software */
static const char *mpv[] = { "mpv", "--fullscreen" };
@@ -89,6 +87,7 @@ static Key nkeys[] = {
{ {.ch = 'P'}, selmv, {0} },
{ {.ch = 'c'}, rname, {0} },
{ {.key = TB_KEY_SPACE}, switch_pane, {0} },
+ { {.ch = '\\'}, bkmrk, {.v = root} },
};
/* visual keys */
@@ -101,9 +100,9 @@ static Key vkeys[] = {
{ {.ch = 'a'}, selall, {.i = 0} },
{ {.ch = 'y'}, selynk, {.i = 0} },
{ {.ch = 'd'}, seldel, {.i = 0} },
- { {.ch = 'q'}, exit_vmode, {.i = 0} },
- { {.ch = 'v'}, exit_vmode, {.i = 0} },
- { {.key = TB_KEY_ESC}, exit_vmode, {.i = 0} },
+ { {.ch = 'q'}, exit_vmode, {0} },
+ { {.ch = 'v'}, exit_vmode, {0} },
+ { {.key = TB_KEY_ESC}, exit_vmode, {0} },
};
static const size_t nkeyslen = LEN(nkeys);
diff --git a/sfm.c b/sfm.c
@@ -82,11 +82,6 @@ typedef struct {
} Pane;
typedef struct {
- uint32_t ch;
- char path[MAX_P];
-} Bookmark;
-
-typedef struct {
const char **ext;
size_t exlen;
const void *v;
@@ -153,6 +148,7 @@ static void scrdwn(const Arg *arg);
static void scrdwns(const Arg *arg);
static void scrup(const Arg *arg);
static void scrups(const Arg *arg);
+static void bkmrk(const Arg *arg);
static int get_usrinput(char *, size_t, const char *, ...);
static int frules(char *);
static int spawn(const void *, size_t, const void *, size_t, char *);
@@ -162,7 +158,6 @@ static int addwatch(Pane *);
static int read_events(void);
static void rmwatch(Pane *);
static void fsev_shdn(void);
-static ssize_t findbm(uint32_t);
static void start_filter(const Arg *arg);
static void start_vmode(const Arg *arg);
static void exit_vmode(const Arg *arg);
@@ -1031,6 +1026,23 @@ scrups(const Arg *arg)
}
}
+static void
+bkmrk(const Arg *arg)
+{
+ if (check_dir((char *)arg->v) != 0) {
+ print_error(strerror(errno));
+ return;
+ }
+
+ rmwatch(cpane);
+ strncpy(cpane->dirn, (char *)arg->v, MAX_P);
+ cpane->firstrow = 0;
+ cpane->parent_row = 1;
+ cpane->hdir = 1;
+ if (listdir(cpane) < 0)
+ print_error(strerror(errno));
+}
+
static int
get_usrinput(char *out, size_t sout, const char *fmt, ...)
{
@@ -1264,23 +1276,6 @@ fsev_shdn(void)
#endif
}
-static ssize_t
-findbm(uint32_t event)
-{
- ssize_t i;
-
- for (i = 0; i < (ssize_t)LEN(bmarks); i++) {
- if (event == bmarks[i].ch) {
- if (check_dir(bmarks[i].path) != 0) {
- print_error(strerror(errno));
- return -1;
- }
- return i;
- }
- }
- return -1;
-}
-
static void
start_filter(const Arg *arg)
{
@@ -1588,7 +1583,6 @@ static void
grabkeys(struct tb_event *event, Key *key, size_t max_keys)
{
size_t i;
- ssize_t b;
for (i = 0; i < max_keys; i++) {
if (event->ch != 0) {
@@ -1603,18 +1597,6 @@ grabkeys(struct tb_event *event, Key *key, size_t max_keys)
}
}
}
-
- /* bookmarks */
- b = findbm(event->ch);
- if (b < 0)
- return;
- rmwatch(cpane);
- strncpy(cpane->dirn, bmarks[b].path, MAX_P);
- cpane->firstrow = 0;
- cpane->parent_row = 1;
- cpane->hdir = 1;
- if (listdir(cpane) < 0)
- print_error(strerror(errno));
}
void *