Key - to jump to last visited directory

This commit is contained in:
Arun Prakash Jana 2017-04-08 13:46:03 +05:30
parent 5aa4c799c0
commit e54ed037bd
No known key found for this signature in database
GPG Key ID: A75979F35C080412
4 changed files with 36 additions and 1 deletions

View File

@ -69,6 +69,7 @@ I chose to fork because:
- Directories first - Directories first
- Sort numeric names in numeric order - Sort numeric names in numeric order
- Case-insensitive alphabetic content listing instead of upper case first - Case-insensitive alphabetic content listing instead of upper case first
- Key `-` to jump to last visited directory
- Roll over at the first and last entries of a directory (with Up/Down keys) - Roll over at the first and last entries of a directory (with Up/Down keys)
- Removed navigation restriction with relative paths (and let permissions handle it) - Removed navigation restriction with relative paths (and let permissions handle it)
- Sort entries by file size (largest to smallest) - Sort entries by file size (largest to smallest)
@ -131,6 +132,7 @@ Start nnn (default: current directory):
| `Right`, `Enter`, `l`, `^M` | Open file or enter dir | | `Right`, `Enter`, `l`, `^M` | Open file or enter dir |
| `Left`, `Backspace`, `h`, `^H` | Go to parent dir | | `Left`, `Backspace`, `h`, `^H` | Go to parent dir |
| `~` | Jump to HOME dir | | `~` | Jump to HOME dir |
| `-` | Jump to last visited dir |
| `/`, `&` | Filter dir contents | | `/`, `&` | Filter dir contents |
| `c` | Show change dir prompt | | `c` | Show change dir prompt |
| `d` | Toggle detail view | | `d` | Toggle detail view |

View File

@ -63,7 +63,10 @@ struct key bindings[] = {
{ '$', SEL_END, "", "" }, { '$', SEL_END, "", "" },
/* Change dir */ /* Change dir */
{ 'c', SEL_CD, "", "" }, { 'c', SEL_CD, "", "" },
/* HOME */
{ '~', SEL_CDHOME, "", "" }, { '~', SEL_CDHOME, "", "" },
/* Last visited dir */
{ '-', SEL_LAST, "", "" },
/* Toggle hide .dot files */ /* Toggle hide .dot files */
{ '.', SEL_TOGGLEDOT, "", "" }, { '.', SEL_TOGGLEDOT, "", "" },
/* Detailed listing */ /* Detailed listing */

2
nnn.1
View File

@ -40,6 +40,8 @@ Open file or enter directory
Back up one directory level Back up one directory level
.It Ic ~ .It Ic ~
Change to the HOME directory Change to the HOME directory
.It Ic -
Change to the last visited directory
.It Ic /, & .It Ic /, &
Change filter (more information below) Change filter (more information below)
.It Ic c .It Ic c

30
nnn.c
View File

@ -77,6 +77,7 @@ enum action {
SEL_END, SEL_END,
SEL_CD, SEL_CD,
SEL_CDHOME, SEL_CDHOME,
SEL_LAST,
SEL_TOGGLEDOT, SEL_TOGGLEDOT,
SEL_DETAIL, SEL_DETAIL,
SEL_STATS, SEL_STATS,
@ -854,6 +855,7 @@ show_help(void)
[Right], [Enter], l, ^M Open file or enter dir\n\ [Right], [Enter], l, ^M Open file or enter dir\n\
[Left], [Backspace], h, ^H Go to parent dir\n\ [Left], [Backspace], h, ^H Go to parent dir\n\
~ Jump to HOME dir\n\ ~ Jump to HOME dir\n\
- Jump to last visited dir\n\
/, & Filter dir contents\n\ /, & Filter dir contents\n\
c Show change dir prompt\n\ c Show change dir prompt\n\
d Toggle detail view\n\ d Toggle detail view\n\
@ -1060,6 +1062,7 @@ static void
browse(char *ipath, char *ifilter) browse(char *ipath, char *ifilter)
{ {
static char path[PATH_MAX], oldpath[PATH_MAX], newpath[PATH_MAX]; static char path[PATH_MAX], oldpath[PATH_MAX], newpath[PATH_MAX];
static char lastdir[PATH_MAX];
static char fltr[LINE_MAX]; static char fltr[LINE_MAX];
char *bin, *dir, *tmp, *run, *env; char *bin, *dir, *tmp, *run, *env;
struct stat sb; struct stat sb;
@ -1068,6 +1071,7 @@ browse(char *ipath, char *ifilter)
enum action sel = SEL_RUNARG + 1; enum action sel = SEL_RUNARG + 1;
xstrlcpy(path, ipath, sizeof(path)); xstrlcpy(path, ipath, sizeof(path));
xstrlcpy(lastdir, ipath, sizeof(lastdir));
xstrlcpy(fltr, ifilter, sizeof(fltr)); xstrlcpy(fltr, ifilter, sizeof(fltr));
oldpath[0] = '\0'; oldpath[0] = '\0';
newpath[0] = '\0'; newpath[0] = '\0';
@ -1105,6 +1109,10 @@ nochange:
} }
/* Save history */ /* Save history */
xstrlcpy(oldpath, path, sizeof(oldpath)); xstrlcpy(oldpath, path, sizeof(oldpath));
/* Save last working directory */
xstrlcpy(lastdir, path, sizeof(lastdir));
xstrlcpy(path, dir, sizeof(path)); xstrlcpy(path, dir, sizeof(path));
/* Reset filter */ /* Reset filter */
xstrlcpy(fltr, ifilter, sizeof(fltr)); xstrlcpy(fltr, ifilter, sizeof(fltr));
@ -1138,6 +1146,10 @@ nochange:
printwarn(); printwarn();
goto nochange; goto nochange;
} }
/* Save last working directory */
xstrlcpy(lastdir, path, sizeof(lastdir));
xstrlcpy(path, newpath, sizeof(path)); xstrlcpy(path, newpath, sizeof(path));
/* Reset filter */ /* Reset filter */
xstrlcpy(fltr, ifilter, sizeof(fltr)); xstrlcpy(fltr, ifilter, sizeof(fltr));
@ -1259,13 +1271,19 @@ nochange:
"%s%s", home, tmp + 1); "%s%s", home, tmp + 1);
else else
mkpath(path, tmp, newpath, sizeof(newpath)); mkpath(path, tmp, newpath, sizeof(newpath));
} else } else if (tmp[0] == '-' && tmp[1] == '\0')
xstrlcpy(newpath, lastdir, sizeof(newpath));
else
mkpath(path, tmp, newpath, sizeof(newpath)); mkpath(path, tmp, newpath, sizeof(newpath));
if (canopendir(newpath) == 0) { if (canopendir(newpath) == 0) {
printwarn(); printwarn();
goto nochange; goto nochange;
} }
/* Save last working directory */
xstrlcpy(lastdir, path, sizeof(lastdir));
xstrlcpy(path, newpath, sizeof(path)); xstrlcpy(path, newpath, sizeof(path));
/* Reset filter */ /* Reset filter */
xstrlcpy(fltr, ifilter, sizeof(fltr)); xstrlcpy(fltr, ifilter, sizeof(fltr));
@ -1281,11 +1299,21 @@ nochange:
printwarn(); printwarn();
goto nochange; goto nochange;
} }
/* Save last working directory */
xstrlcpy(lastdir, path, sizeof(lastdir));
xstrlcpy(path, tmp, sizeof(path)); xstrlcpy(path, tmp, sizeof(path));
/* Reset filter */ /* Reset filter */
xstrlcpy(fltr, ifilter, sizeof(fltr)); xstrlcpy(fltr, ifilter, sizeof(fltr));
DPRINTF_S(path); DPRINTF_S(path);
goto begin; goto begin;
case SEL_LAST:
xstrlcpy(newpath, lastdir, sizeof(newpath));
xstrlcpy(lastdir, path, sizeof(lastdir));
xstrlcpy(path, newpath, sizeof(path));
DPRINTF_S(path);
goto begin;
case SEL_TOGGLEDOT: case SEL_TOGGLEDOT:
showhidden ^= 1; showhidden ^= 1;
initfilter(showhidden, &ifilter); initfilter(showhidden, &ifilter);