Explorar el Código

Minor refactor

master
Arun Prakash Jana hace 4 años
padre
commit
90cf84186a
No se encontró ninguna clave conocida en la base de datos para esta firma ID de clave GPG: A75979F35C080412
Se han modificado 2 ficheros con 110 adiciones y 109 borrados
  1. +1
    -1
      README.md
  2. +109
    -108
      src/nnn.c

+ 1
- 1
README.md Ver fichero

@@ -28,7 +28,7 @@ It runs smoothly on the Pi, [Termux](https://www.youtube.com/watch?v=AbaauM7gUJw


## Black magic! :dark_sunglasses: ## Black magic! :dark_sunglasses:


- Load, sort, filter thousands of files instantly - Instantly load, sort, filter thousands of files
- Type to navigate with automatic dir selection - Type to navigate with automatic dir selection
- Never lose context - start where you quit `nnn` - Never lose context - start where you quit `nnn`
- find/fd/grep/ripgrep/fzf from `nnn` and list in `nnn` - find/fd/grep/ripgrep/fzf from `nnn` and list in `nnn`


+ 109
- 108
src/nnn.c Ver fichero

@@ -5617,6 +5617,7 @@ nochange:
mkpath(path, pdents[cur].name, newpath); mkpath(path, pdents[cur].name, newpath);
DPRINTF_S(newpath); DPRINTF_S(newpath);


/* Visit directory */
if (pdents[cur].flags & DIR_OR_LINK_TO_DIR) { if (pdents[cur].flags & DIR_OR_LINK_TO_DIR) {
if (chdir(newpath) == -1) { if (chdir(newpath) == -1) {
printwarn(&presel); printwarn(&presel);
@@ -5634,136 +5635,136 @@ nochange:
} }
DPRINTF_U(sb.st_mode); DPRINTF_U(sb.st_mode);


switch (sb.st_mode & S_IFMT) { /* Do not open non-regular files */
case S_IFREG: if (!S_ISREG(sb.st_mode)) {
{ printwait(messages[MSG_UNSUPPORTED], &presel);
/* If opened as vim plugin and Enter/^M pressed, pick */ goto nochange;
if (g_state.picker && sel == SEL_GOIN) { }
appendfpath(newpath, mkpath(path, pdents[cur].name, newpath));
writesel(pselbuf, selbufpos - 1);
return EXIT_SUCCESS;
}


if (sel == SEL_NAV_IN) { /* If opened as vim plugin and Enter/^M pressed, pick */
/* If in listing dir, go to target on `l` or Right on symlink */ if (g_state.picker && sel == SEL_GOIN) {
if (listpath && S_ISLNK(pdents[cur].mode) appendfpath(newpath, mkpath(path, pdents[cur].name, newpath));
&& is_prefix(path, listpath, strlen(listpath))) { writesel(pselbuf, selbufpos - 1);
if (!realpath(pdents[cur].name, newpath)) { return EXIT_SUCCESS;
printwarn(&presel); }
goto nochange;
}

xdirname(newpath);

if (chdir(newpath) == -1) {
printwarn(&presel);
goto nochange;
}

cdprep(lastdir, NULL, path, newpath)
? (presel = FILTER) : (watch = TRUE);
xstrsncpy(lastname, pdents[cur].name, NAME_MAX + 1);
goto begin;
} else if (cfg.nonavopen)
goto nochange; /* Open file disabled on right arrow or `l` */
}


/* Handle plugin selection mode */ if (sel == SEL_NAV_IN) {
if (g_state.runplugin) { /* If in listing dir, go to target on `l` or Right on symlink */
g_state.runplugin = 0; if (listpath && S_ISLNK(pdents[cur].mode)
/* Must be in plugin dir and same context to select plugin */ && is_prefix(path, listpath, strlen(listpath))) {
if ((g_state.runctx == cfg.curctx) && !strcmp(path, plgpath)) { if (!realpath(pdents[cur].name, newpath)) {
endselection(); printwarn(&presel);
/* Copy path so we can return back to earlier dir */ goto nochange;
xstrsncpy(path, rundir, PATH_MAX); }
rundir[0] = '\0'; xdirname(newpath);

if (chdir(newpath) == -1) {
if (chdir(path) == -1 printwarn(&presel);
|| !run_selected_plugin(&path, pdents[cur].name, goto nochange;
runfile, &lastname,
&lastdir)) {
DPRINTF_S("plugin failed!");
}

if (runfile[0])
runfile[0] = '\0';
clearfilter();
setdirwatch();
goto begin;
} }

cdprep(lastdir, NULL, path, newpath)
? (presel = FILTER) : (watch = TRUE);
xstrsncpy(lastname, pdents[cur].name, NAME_MAX + 1);
goto begin;
} }


if (!sb.st_size) { /* Open file disabled on right arrow or `l` */
printwait(messages[MSG_EMPTY_FILE], &presel); if (cfg.nonavopen)
goto nochange; goto nochange;
}

/* Handle plugin selection mode */
if (g_state.runplugin) {
g_state.runplugin = 0;
/* Must be in plugin dir and same context to select plugin */
if ((g_state.runctx == cfg.curctx) && !strcmp(path, plgpath)) {
endselection();
/* Copy path so we can return back to earlier dir */
xstrsncpy(path, rundir, PATH_MAX);
rundir[0] = '\0';

if (chdir(path) == -1
|| !run_selected_plugin(&path, pdents[cur].name,
runfile, &lastname, &lastdir)) {
DPRINTF_S("plugin failed!");
}

if (runfile[0])
runfile[0] = '\0';
clearfilter();
setdirwatch();
goto begin;
} }
}


if (cfg.useeditor if (!sb.st_size) {
#ifdef FILE_MIME_OPTS printwait(messages[MSG_EMPTY_FILE], &presel);
&& get_output(g_buf, CMD_LEN_MAX, "file", FILE_MIME_OPTS, newpath, FALSE) goto nochange;
&& is_prefix(g_buf, "text/", 5) }

if (cfg.useeditor
#ifdef FILE_MIME
&& get_output(g_buf, CMD_LEN_MAX, "file", FILE_MIME_OPTS, newpath, FALSE)
&& is_prefix(g_buf, "text/", 5)
#else #else
/* no mime option; guess from description instead */ /* no mime option; guess from description instead */
&& get_output(g_buf, CMD_LEN_MAX, "file", "-b", newpath, FALSE) && get_output(g_buf, CMD_LEN_MAX, "file", "-b", newpath, FALSE)
&& strstr(g_buf, "text") && strstr(g_buf, "text")
#endif #endif
) { ) {
spawn(editor, newpath, NULL, F_CLI); spawn(editor, newpath, NULL, F_CLI);
continue; continue;
} }


#ifdef PCRE #ifdef PCRE
if (!pcre_exec(archive_pcre, NULL, pdents[cur].name, if (!pcre_exec(archive_pcre, NULL, pdents[cur].name,
xstrlen(pdents[cur].name), 0, 0, NULL, 0)) { xstrlen(pdents[cur].name), 0, 0, NULL, 0)) {
#else #else
if (!regexec(&archive_re, pdents[cur].name, 0, NULL, 0)) { if (!regexec(&archive_re, pdents[cur].name, 0, NULL, 0)) {
#endif #endif
r = get_input(messages[MSG_ARCHIVE_OPTS]); r = get_input(messages[MSG_ARCHIVE_OPTS]);
if (r == 'l' || r == 'x') { if (r == 'l' || r == 'x') {
mkpath(path, pdents[cur].name, newpath); mkpath(path, pdents[cur].name, newpath);
handle_archive(newpath, r); handle_archive(newpath, r);
if (r == 'l') { if (r == 'l') {
statusbar(path); statusbar(path);
goto nochange; goto nochange;
}
copycurname();
clearfilter();
goto begin;
} }
copycurname();
clearfilter();
goto begin;
}


if (r == 'm') { if (r == 'm') {
if (!archive_mount(newpath)) { if (!archive_mount(newpath)) {
presel = MSGWAIT; presel = MSGWAIT;
goto nochange; goto nochange;
} }


/* Pin current directory */ /* Pin current directory */
free(mark); free(mark);
mark = xstrdup(path); mark = xstrdup(path);


cdprep(lastdir, lastname, path, newpath) cdprep(lastdir, lastname, path, newpath)
? (presel = FILTER) : (watch = TRUE); ? (presel = FILTER) : (watch = TRUE);
goto begin; goto begin;
} }


if (r != 'd') { if (r != 'd') {
printwait(messages[MSG_INVALID_KEY], &presel); printwait(messages[MSG_INVALID_KEY], &presel);
goto nochange; goto nochange;
}
} }
}


/* Invoke desktop opener as last resort */ /* Invoke desktop opener as last resort */
spawn(opener, newpath, NULL, opener_flags); spawn(opener, newpath, NULL, opener_flags);


/* Move cursor to the next entry if not the last entry */ /* Move cursor to the next entry if not the last entry */
if (g_state.autonext && cur != ndents - 1) if (g_state.autonext && cur != ndents - 1)
move_cursor((cur + 1) % ndents, 0); move_cursor((cur + 1) % ndents, 0);
continue; continue;
}
default:
printwait(messages[MSG_UNSUPPORTED], &presel);
goto nochange;
}
case SEL_NEXT: // fallthrough case SEL_NEXT: // fallthrough
case SEL_PREV: // fallthrough case SEL_PREV: // fallthrough
case SEL_PGDN: // fallthrough case SEL_PGDN: // fallthrough


||||||
x
 
000:0
Cargando…
Cancelar
Guardar