Retire chdir prompt

This commit is contained in:
Arun Prakash Jana 2018-11-06 20:46:45 +05:30
parent 3a738632a0
commit 3cf81482a4
No known key found for this signature in database
GPG Key ID: A75979F35C080412
4 changed files with 2 additions and 129 deletions

View File

@ -67,7 +67,6 @@ Have fun with it! Missing a feature? Want to contribute? Head to the rolling [To
- [sample scripts](#sample-scripts)
- [dual-pane or multi-pane](#dual-pane-or-multi-pane)
- [change dir color](#change-dir-color)
- [use cd .....](#use-cd-)
- [integrate patool](#integrate-patool)
- [work faster at rename prompt](#work-faster-at-rename-prompt)
- [set idle timeout](#set-idle-timeout)
@ -84,7 +83,6 @@ Have fun with it! Missing a feature? Want to contribute? Head to the rolling [To
- Familiar, easy shortcuts (arrows, `~`, `-`, `&`)
- *Navigate-as-you-type* mode with dir auto-select for the maverick
- Handy bookmarks, start at bookmark, pin and visit directory
- chdir prompt with tab completion (interprets cd ..... too!)
- Roll-over at edges, page through entries
- Show directories in custom color (default: enabled in blue)
- Sorting
@ -228,7 +226,6 @@ optional args:
^B Bookmark prompt
b Pin current dir
^V Go to pinned dir
c cd prompt
d Toggle detail view
D File details
m, M Brief/full media info
@ -505,10 +502,6 @@ The default color for directories is blue. Option `-c` accepts color codes from
Any other value disables colored directories.
#### use cd .....
To jump to the n<sup>th</sup> level parent, use `n + 1` dots (the first `.` denotes PWD). For example, to jump to the 6<th> parent of the current directory, use 7 dots. If the number of dots would take you *beyond* `/` (which isn't possible), you'll be placed at `/`.
#### integrate patool
On systems where `atool` is not available but `patool` is, drop two copies of the Python3 script [natool](https://github.com/jarun/nnn/blob/master/scripts/natool) as `atool` and `apack` somewhere in `$PATH`.

4
nnn.1
View File

@ -62,13 +62,11 @@ Search directory in desktop search tool
.It Ic \&.
Toggle show hidden . (dot) files
.It Ic ^B
Show bookmark key prompt
Show bookmark key prompt (understands ~, -, &)
.It Ic b
Pin current directory
.It Ic ^V
Visit pinned directory
.It Ic c
Show change directory prompt
.It Ic d
Toggle detail view
.It Ic D

117
nnn.c
View File

@ -691,25 +691,6 @@ static bool showcplist()
return TRUE;
}
/*
* Return number of dots if all chars in a string are dots, else 0
*/
static int all_dots(const char *path)
{
int count = 0;
if (!path)
return FALSE;
while (*path == '.')
++count, ++path;
if (*path)
return 0;
return count;
}
/* Initialize curses mode */
static void initcurses(void)
{
@ -1968,7 +1949,6 @@ static int show_help(char *path)
"d^B Bookmark prompt\n"
"eb Pin current dir\n"
"d^V Go to pinned dir\n"
"ec cd prompt\n"
"ed Toggle detail view\n"
"eD File details\n"
"bm, M Brief/full media info\n"
@ -2461,7 +2441,7 @@ static void browse(char *ipath, char *ifilter)
static char oldname[NAME_MAX + 1] __attribute__ ((aligned));
char *dir, *tmp, *run = NULL, *env = NULL;
struct stat sb;
int r, fd, truecd, presel, ncp = 0, copystartid = 0, copyendid = 0;
int r, fd, presel, ncp = 0, copystartid = 0, copyendid = 0;
enum action sel = SEL_RUNARG + 1;
bool dir_changed = FALSE;
@ -2660,101 +2640,6 @@ nochange:
case SEL_END:
cur = ndents - 1;
break;
case SEL_CD:
truecd = 0;
tmp = xreadline(NULL, "cd: ");
if (tmp == NULL || tmp[0] == '\0')
break;
if (tmp[0] == '~') {
/* Expand ~ to HOME absolute path */
dir = getenv("HOME");
if (dir)
snprintf(newpath, PATH_MAX, "%s%s", dir, tmp + 1);
else {
printmsg(messages[STR_NOHOME_ID]);
goto nochange;
}
} else if (tmp[0] == '-' && tmp[1] == '\0') {
if (lastdir[0] == '\0')
break;
/* Switch to last visited dir */
xstrlcpy(newpath, lastdir, PATH_MAX);
truecd = 1;
} else if ((r = all_dots(tmp))) {
if (r == 1)
/* Always in the current dir */
break;
/* Show a message if already at / */
if (istopdir(path)) {
/* Continue in navigate-as-you-type mode, if enabled */
if (cfg.filtermode)
presel = FILTER;
goto nochange;
}
--r; /* One . for the current dir */
dir = path;
/* Note: fd is used as a tmp variable here */
for (fd = 0; fd < r; ++fd) {
/* Reached / ? */
if (istopdir(path)) {
/* Can't cd beyond / */
break;
}
dir = xdirname(dir);
if (access(dir, R_OK) == -1) {
printwarn();
goto nochange;
}
}
truecd = 1;
/* Save the path in case of cd ..
* We mark the current dir in parent dir
*/
if (r == 1) {
xstrlcpy(oldname, xbasename(path), NAME_MAX + 1);
truecd = 2;
}
xstrlcpy(newpath, dir, PATH_MAX);
} else
mkpath(path, tmp, newpath, PATH_MAX);
if (!xdiraccess(newpath))
goto nochange;
if (truecd == 0) {
/* Probable change in dir */
/* No-op if it's the same directory */
if (strcmp(path, newpath) == 0)
break;
oldname[0] = '\0';
} else if (truecd == 1)
/* Sure change in dir */
oldname[0] = '\0';
/* Save last working directory */
xstrlcpy(lastdir, path, PATH_MAX);
dir_changed = TRUE;
/* Save the newly opted dir in path */
xstrlcpy(path, newpath, PATH_MAX);
/* Reset filter */
copyfilter();
DPRINTF_S(path);
if (cfg.filtermode)
presel = FILTER;
goto begin;
case SEL_CDHOME:
dir = getenv("HOME");
if (dir == NULL) {

3
nnn.h
View File

@ -44,7 +44,6 @@ enum action {
SEL_PGUP,
SEL_HOME,
SEL_END,
SEL_CD,
SEL_CDHOME,
SEL_CDBEGIN,
SEL_CDLAST,
@ -140,8 +139,6 @@ static struct key bindings[] = {
{ 'G', SEL_END, "", "" },
{ CONTROL('E'), SEL_END, "", "" },
{ '$', SEL_END, "", "" },
/* Change dir */
{ 'c', SEL_CD, "", "" },
/* HOME */
{ '~', SEL_CDHOME, "", "" },
/* Initial directory */