# Authors: Luuk van Baal, @crides
diff --git a/src/nnn.c b/src/nnn.c
-index 88263beb..597ff2b3 100644
+index 897c32f1..00b57c2e 100644
--- a/src/nnn.c
+++ b/src/nnn.c
@@ -285,6 +285,7 @@ typedef struct entry {
+ char workdir[PATH_MAX], *ret;
+ FILE *fp = popen(gitrev, "r");
+
++ git_statuses.show = FALSE;
+ ret = fgets(workdir, PATH_MAX, fp);
+ pclose(fp);
+ if (!ret)
+ static char gitstat[] = "git -c core.quotePath= status --porcelain --ignored=matching -u ";
+ char pathspec[PATH_MAX], status[PATH_MAX];
+ size_t i = -1;
-+ git_statuses.show = FALSE;
+ workdir[xstrlen(workdir) - 1] = '\0';
+ snprintf(pathspec, PATH_MAX, "%s\"%s\"%s 2>/dev/null", gitstat, path, cfg.showhidden ? "" : "/*");
+ fp = popen(pathspec, "r");
#if _POSIX_C_SOURCE >= 200112L
posix_fadvise(fd, 0, 0, POSIX_FADV_SEQUENTIAL);
#endif
-@@ -5746,6 +5800,36 @@ static int dentfill(char *path, struct entry **ppdents)
+@@ -5746,6 +5800,39 @@ static int dentfill(char *path, struct entry **ppdents)
#endif
}
+ if (git_statuses.len) {
-+ char dentpath[PATH_MAX], prefix[PATH_MAX + 1];
++ char dentpath[PATH_MAX];
+ size_t pathlen = mkpath(linkpath, dentp->name, dentpath);
-+ snprintf(prefix, PATH_MAX + 1, "%s/", dentpath);
+ dentp->git_status[0] = dentp->git_status[1] = '-';
+
+ if (dentp->flags & DIR_OR_DIRLNK) {
++ char prefix[PATH_MAX];
++ memccpy(prefix, dentpath, '\0', PATH_MAX);
++ prefix[pathlen - 1] = '/';
++
+ for (size_t i = 0; i < git_statuses.len; ++i)
+ if (is_prefix(git_statuses.statuses[i].path, prefix, pathlen)) {
+ if ((dentp->git_status[0] == '-') && (git_statuses.statuses[i].status[0] != '-'))
++ndents;
} while ((dp = readdir(dirp)));
-@@ -6270,11 +6354,12 @@ static int adjust_cols(int n)
+@@ -6270,11 +6357,12 @@ static int adjust_cols(int n)
#endif
if (cfg.showdetail) {
/* Fallback to light mode if less than 35 columns */
/* 2 columns for preceding space and indicator */
return (n - 2);
-@@ -8034,6 +8119,7 @@ static void usage(void)
+@@ -8030,6 +8118,7 @@ static void usage(void)
" -F val fifo mode [0:preview 1:explore]\n"
#endif
" -g regex filters\n"
" -H show hidden files\n"
" -J no auto-proceed on select\n"
" -K detect key collision\n"
-@@ -8174,6 +8260,7 @@ static void cleanup(void)
+@@ -8170,6 +8259,7 @@ static void cleanup(void)
free(hostname);
}
#endif
free(selpath);
free(plgpath);
free(cfgpath);
-@@ -8218,7 +8305,7 @@ int main(int argc, char *argv[])
+@@ -8214,7 +8304,7 @@ int main(int argc, char *argv[])
while ((opt = (env_opts_id > 0
? env_opts[--env_opts_id]
switch (opt) {
#ifndef NOFIFO
case 'a':
-@@ -8269,6 +8356,9 @@ int main(int argc, char *argv[])
+@@ -8265,6 +8355,9 @@ int main(int argc, char *argv[])
cfg.regex = 1;
filterfn = &visible_re;
break;
# Authors: Luuk van Baal, @crides
diff --git a/src/nnn.c b/src/nnn.c
-index 55f32e73..ed771826 100644
+index 5801e28e..8a88d5e7 100644
--- a/src/nnn.c
+++ b/src/nnn.c
@@ -285,6 +285,7 @@ typedef struct entry {
};
static context g_ctx[CTX_MAX] __attribute__ ((aligned));
-@@ -3822,6 +3835,38 @@ static int get_kv_key(kv *kvarr, char *val, uchar_t max, uchar_t id)
+@@ -3822,6 +3835,39 @@ static int get_kv_key(kv *kvarr, char *val, uchar_t max, uchar_t id)
return -1;
}
+ char workdir[PATH_MAX], *ret;
+ FILE *fp = popen(gitrev, "r");
+
++ git_statuses.show = FALSE;
+ ret = fgets(workdir, PATH_MAX, fp);
+ pclose(fp);
+ if (!ret)
static void resetdircolor(int flags)
{
/* Directories are always shown on top, clear the color when moving to first file */
-@@ -4132,6 +4177,9 @@ static void printent(const struct entry *ent, uint_t namecols, bool sel)
+@@ -4132,6 +4178,9 @@ static void printent(const struct entry *ent, uint_t namecols, bool sel)
int attrs = 0, namelen;
uchar_t color_pair = get_color_pair_name_ind(ent, &ind, &attrs);
addch((ent->flags & FILE_SELECTED) ? '+' | A_REVERSE | A_BOLD : ' ');
if (g_state.oldcolor)
-@@ -5554,6 +5602,11 @@ static int dentfill(char *path, struct entry **ppdents)
+@@ -5554,6 +5603,11 @@ static int dentfill(char *path, struct entry **ppdents)
attron(COLOR_PAIR(cfg.curctx + 1));
}
#if _POSIX_C_SOURCE >= 200112L
posix_fadvise(fd, 0, 0, POSIX_FADV_SEQUENTIAL);
#endif
-@@ -5752,6 +5805,36 @@ static int dentfill(char *path, struct entry **ppdents)
+@@ -5752,6 +5806,39 @@ static int dentfill(char *path, struct entry **ppdents)
#endif
}
+ if (git_statuses.len) {
-+ char dentpath[PATH_MAX], prefix[PATH_MAX + 1];
++ char dentpath[PATH_MAX];
+ size_t pathlen = mkpath(linkpath, dentp->name, dentpath);
-+ snprintf(prefix, PATH_MAX + 1, "%s/", dentpath);
+ dentp->git_status[0] = dentp->git_status[1] = '-';
+
+ if (dentp->flags & DIR_OR_DIRLNK) {
++ char prefix[PATH_MAX];
++ memccpy(prefix, dentpath, '\0', PATH_MAX);
++ prefix[pathlen - 1] = '/';
++
+ for (size_t i = 0; i < git_statuses.len; ++i)
+ if (is_prefix(git_statuses.statuses[i].path, prefix, pathlen)) {
+ if ((dentp->git_status[0] == '-') && (git_statuses.statuses[i].status[0] != '-'))
++ndents;
} while ((dp = readdir(dirp)));
-@@ -6267,7 +6350,8 @@ static int adjust_cols(int n)
+@@ -6267,7 +6354,8 @@ static int adjust_cols(int n)
cfg.showdetail ^= 1;
else /* 2 more accounted for below */
n -= (dtls.maxentln - 2 - dtls.maxnameln);
/* 2 columns for preceding space and indicator */
return (n - 2);
-@@ -6422,7 +6506,7 @@ static void redraw(char *path)
+@@ -6422,7 +6510,7 @@ static void redraw(char *path)
}
#endif
}
}
ncols = adjust_cols(ncols);
-@@ -8040,6 +8124,7 @@ static void usage(void)
+@@ -8036,6 +8124,7 @@ static void usage(void)
" -F val fifo mode [0:preview 1:explore]\n"
#endif
" -g regex filters\n"
" -H show hidden files\n"
" -J no auto-proceed on select\n"
" -K detect key collision\n"
-@@ -8180,6 +8265,7 @@ static void cleanup(void)
+@@ -8176,6 +8265,7 @@ static void cleanup(void)
free(hostname);
}
#endif
free(selpath);
free(plgpath);
free(cfgpath);
-@@ -8224,7 +8310,7 @@ int main(int argc, char *argv[])
+@@ -8220,7 +8310,7 @@ int main(int argc, char *argv[])
while ((opt = (env_opts_id > 0
? env_opts[--env_opts_id]
switch (opt) {
#ifndef NOFIFO
case 'a':
-@@ -8275,6 +8361,9 @@ int main(int argc, char *argv[])
+@@ -8271,6 +8361,9 @@ int main(int argc, char *argv[])
cfg.regex = 1;
filterfn = &visible_re;
break;
# Authors: Luuk van Baal
diff --git a/src/nnn.c b/src/nnn.c
-index 88263beb..8aa24712 100644
+index 897c32f1..cf589bc8 100644
--- a/src/nnn.c
+++ b/src/nnn.c
@@ -367,7 +367,8 @@ typedef struct {
if (cfg.filtermode) {
presel = FILTER;
clearfilter();
-@@ -7206,7 +7245,14 @@ nochange:
+@@ -7206,8 +7245,14 @@ nochange:
copycurname();
goto nochange;
case SEL_EDIT:
+ if (g_state.previewer)
+ notify_fifo(FALSE, TRUE);
- spawn(editor, newpath, NULL, NULL, F_CLI);
+ if (!g_state.picker)
+ spawn(editor, newpath, NULL, NULL, F_CLI);
+ if (g_state.previewer) {
+ pkey = previewkey;
+ goto run_plugin;
+ }
-+
continue;
default: /* SEL_LOCK */
lock_terminal();
-@@ -7566,6 +7612,7 @@ nochange:
+@@ -7567,6 +7612,7 @@ nochange:
goto begin;
}
case SEL_PLUGIN:
/* Check if directory is accessible */
if (!xdiraccess(plgpath)) {
-@@ -7591,6 +7638,12 @@ nochange:
+@@ -7592,6 +7638,12 @@ nochange:
goto nochange;
}
if (tmp[0] == '-' && tmp[1]) {
++tmp;
r = FALSE; /* Do not refresh dir after completion */
-@@ -8189,8 +8242,10 @@ static void cleanup(void)
+@@ -8185,8 +8237,10 @@ static void cleanup(void)
if (g_state.autofifo)
unlink(fifopath);
#endif
#ifdef DEBUG
disabledbg();
#endif
-@@ -8689,7 +8744,7 @@ int main(int argc, char *argv[])
+@@ -8690,7 +8744,7 @@ int main(int argc, char *argv[])
#ifndef NOFIFO
if (!g_state.fifomode)