Combine cases

SEL_CDHOME, SEL_CDBEGIN, SEL_CDLAST, SEL_VISIT
This commit is contained in:
Arun Prakash Jana 2019-01-19 21:22:03 +05:30
parent 78048d6ef0
commit c400a19268
No known key found for this signature in database
GPG key ID: A75979F35C080412
2 changed files with 19 additions and 33 deletions

View file

@ -2826,14 +2826,21 @@ nochange:
cur = ndents - 1; cur = ndents - 1;
break; break;
case SEL_CDHOME: case SEL_CDHOME:
dir = getenv("HOME"); dir = xgetenv("HOME", path); // fallthrough
if (dir == NULL) {
clearprompt();
goto nochange;
} // fallthrough
case SEL_CDBEGIN: case SEL_CDBEGIN:
if (sel == SEL_CDBEGIN) if (sel == SEL_CDBEGIN)
dir = ipath; dir = ipath; // fallthrough
case SEL_CDLAST:
if (sel == SEL_CDLAST)
dir = lastdir; // fallthrough
case SEL_VISIT:
if (sel == SEL_VISIT)
dir = mark;
if (dir[0] == '\0') {
printmsg("not set");
goto nochange;
}
if (!xdiraccess(dir)) if (!xdiraccess(dir))
goto nochange; goto nochange;
@ -2841,33 +2848,12 @@ nochange:
if (strcmp(path, dir) == 0) if (strcmp(path, dir) == 0)
break; break;
/* SEL_CDLAST: dir pointing to lastdir */
xstrlcpy(newpath, dir, PATH_MAX);
/* Save last working directory */ /* Save last working directory */
xstrlcpy(lastdir, path, PATH_MAX); xstrlcpy(lastdir, path, PATH_MAX);
xstrlcpy(path, dir, PATH_MAX);
lastname[0] = '\0';
DPRINTF_S(path);
setdirwatch();
goto begin;
case SEL_CDLAST: // fallthrough
case SEL_VISIT:
if (sel == SEL_VISIT) {
if (strcmp(mark, path) == 0)
break;
tmp = mark;
} else
tmp = lastdir;
if (tmp[0] == '\0') {
printmsg("not set");
goto nochange;
}
if (!xdiraccess(tmp))
goto nochange;
xstrlcpy(newpath, tmp, PATH_MAX);
xstrlcpy(lastdir, path, PATH_MAX);
xstrlcpy(path, newpath, PATH_MAX); xstrlcpy(path, newpath, PATH_MAX);
lastname[0] = '\0'; lastname[0] = '\0';
DPRINTF_S(path); DPRINTF_S(path);

View file

@ -48,6 +48,7 @@ enum action {
SEL_CDHOME, SEL_CDHOME,
SEL_CDBEGIN, SEL_CDBEGIN,
SEL_CDLAST, SEL_CDLAST,
SEL_VISIT,
SEL_LEADER, SEL_LEADER,
SEL_CYCLE, SEL_CYCLE,
SEL_CTX1, SEL_CTX1,
@ -55,7 +56,6 @@ enum action {
SEL_CTX3, SEL_CTX3,
SEL_CTX4, SEL_CTX4,
SEL_PIN, SEL_PIN,
SEL_VISIT,
SEL_FLTR, SEL_FLTR,
SEL_MFLTR, SEL_MFLTR,
SEL_TOGGLEDOT, SEL_TOGGLEDOT,
@ -141,6 +141,8 @@ static struct key bindings[] = {
{ '&', SEL_CDBEGIN }, { '&', SEL_CDBEGIN },
/* Last visited dir */ /* Last visited dir */
{ '-', SEL_CDLAST }, { '-', SEL_CDLAST },
/* Visit marked directory */
{ CONTROL('W'), SEL_VISIT },
/* Leader key */ /* Leader key */
{ CONTROL('_'), SEL_LEADER }, { CONTROL('_'), SEL_LEADER },
{ '`', SEL_LEADER }, { '`', SEL_LEADER },
@ -154,8 +156,6 @@ static struct key bindings[] = {
{ '4', SEL_CTX4 }, { '4', SEL_CTX4 },
/* Mark a path to visit later */ /* Mark a path to visit later */
{ 'b', SEL_PIN }, { 'b', SEL_PIN },
/* Visit marked directory */
{ CONTROL('W'), SEL_VISIT },
/* Filter */ /* Filter */
{ '/', SEL_FLTR }, { '/', SEL_FLTR },
/* Toggle filter mode */ /* Toggle filter mode */