mirror of
https://github.com/jarun/nnn.git
synced 2024-11-28 05:41:31 +00:00
Unify cd HOME and BEGIN
This commit is contained in:
parent
2b963634bc
commit
b6b164572e
49
nnn.c
49
nnn.c
|
@ -1861,7 +1861,7 @@ browse(char *ipath, char *ifilter)
|
||||||
char path[PATH_MAX], oldpath[PATH_MAX], newpath[PATH_MAX];
|
char path[PATH_MAX], oldpath[PATH_MAX], newpath[PATH_MAX];
|
||||||
char lastdir[PATH_MAX];
|
char lastdir[PATH_MAX];
|
||||||
char fltr[LINE_MAX];
|
char fltr[LINE_MAX];
|
||||||
char *dir, *tmp, *run, *env;
|
char *dir, *tmp, *run, *env, *tgt=NULL;
|
||||||
struct stat sb;
|
struct stat sb;
|
||||||
int r, fd, presel;
|
int r, fd, presel;
|
||||||
enum action sel = SEL_RUNARG + 1;
|
enum action sel = SEL_RUNARG + 1;
|
||||||
|
@ -2200,54 +2200,43 @@ nochange:
|
||||||
goto begin;
|
goto begin;
|
||||||
}
|
}
|
||||||
case SEL_CDHOME:
|
case SEL_CDHOME:
|
||||||
tmp = getenv("HOME");
|
tgt = getenv("HOME");
|
||||||
if (tmp == NULL) {
|
if (tgt == NULL) {
|
||||||
clearprompt();
|
clearprompt();
|
||||||
goto nochange;
|
goto nochange;
|
||||||
}
|
} // fallthrough
|
||||||
|
|
||||||
if (access(tmp, R_OK) == -1) {
|
|
||||||
printwarn();
|
|
||||||
goto nochange;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (xstrcmp(path, tmp) == 0)
|
|
||||||
break;
|
|
||||||
|
|
||||||
/* Save last working directory */
|
|
||||||
xstrlcpy(lastdir, path, PATH_MAX);
|
|
||||||
|
|
||||||
xstrlcpy(path, tmp, PATH_MAX);
|
|
||||||
oldpath[0] = '\0';
|
|
||||||
/* Reset filter */
|
|
||||||
xstrlcpy(fltr, ifilter, LINE_MAX);
|
|
||||||
DPRINTF_S(path);
|
|
||||||
if (cfg.filtermode)
|
|
||||||
presel = FILTER;
|
|
||||||
goto begin;
|
|
||||||
case SEL_CDBEGIN:
|
case SEL_CDBEGIN:
|
||||||
if (access(ipath, R_OK) == -1) {
|
if (!tgt)
|
||||||
|
tgt = ipath;
|
||||||
|
|
||||||
|
if (access(tgt, R_OK) == -1) {
|
||||||
printwarn();
|
printwarn();
|
||||||
|
tgt = NULL;
|
||||||
goto nochange;
|
goto nochange;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (xstrcmp(path, ipath) == 0)
|
if (xstrcmp(path, tgt) == 0) {
|
||||||
|
tgt = NULL;
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
/* Save last working directory */
|
/* Save last working directory */
|
||||||
xstrlcpy(lastdir, path, PATH_MAX);
|
xstrlcpy(lastdir, path, PATH_MAX);
|
||||||
|
|
||||||
xstrlcpy(path, ipath, PATH_MAX);
|
xstrlcpy(path, tgt, PATH_MAX);
|
||||||
oldpath[0] = '\0';
|
oldpath[0] = '\0';
|
||||||
/* Reset filter */
|
/* Reset filter */
|
||||||
xstrlcpy(fltr, ifilter, LINE_MAX);
|
xstrlcpy(fltr, ifilter, LINE_MAX);
|
||||||
DPRINTF_S(path);
|
DPRINTF_S(path);
|
||||||
if (cfg.filtermode)
|
if (cfg.filtermode)
|
||||||
presel = FILTER;
|
presel = FILTER;
|
||||||
|
tgt = NULL;
|
||||||
goto begin;
|
goto begin;
|
||||||
case SEL_CDLAST:
|
case SEL_CDLAST:
|
||||||
if (lastdir[0] == '\0')
|
if (lastdir[0] == '\0') {
|
||||||
break;
|
printmsg("Hit end of history...");
|
||||||
|
goto nochange;
|
||||||
|
}
|
||||||
|
|
||||||
if (access(lastdir, R_OK) == -1) {
|
if (access(lastdir, R_OK) == -1) {
|
||||||
printwarn();
|
printwarn();
|
||||||
|
@ -2363,7 +2352,7 @@ nochange:
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case SEL_MEDIA:
|
case SEL_MEDIA: // fallthrough
|
||||||
case SEL_FMEDIA:
|
case SEL_FMEDIA:
|
||||||
if (ndents > 0) {
|
if (ndents > 0) {
|
||||||
mkpath(path, dents[cur].name, oldpath,
|
mkpath(path, dents[cur].name, oldpath,
|
||||||
|
|
Loading…
Reference in a new issue