]> Sergey Matveev's repositories - nnn.git/commitdiff
Print the resolved path for cwd
authorsin <sin@2f30.org>
Wed, 6 Jan 2016 15:21:41 +0000 (15:21 +0000)
committersin <sin@2f30.org>
Wed, 6 Jan 2016 15:22:21 +0000 (15:22 +0000)
Avoids weird things like /etc/.. when displaying cwd.

Also no need for cwd to be on the heap.

noice.c

diff --git a/noice.c b/noice.c
index 9f4f0cb05a10379e4edff727e3533cec45fd8d74..41172409d8bd249d153dda4113d4919418d70669 100644 (file)
--- a/noice.c
+++ b/noice.c
@@ -595,8 +595,9 @@ populate(void)
 void
 redraw(void)
 {
+       char cwd[PATH_MAX], cwdresolved[PATH_MAX];
+       size_t ncols;
        int nlines, odd;
-       char *cwd;
        int i;
 
        nlines = MIN(LINES - 4, n);
@@ -615,11 +616,14 @@ redraw(void)
        DPRINTF_S(path);
 
        /* No text wrapping in cwd line */
-       cwd = xmalloc(COLS * sizeof(char));
-       strlcpy(cwd, path, COLS * sizeof(char));
-       cwd[COLS - strlen(CWD) - 1] = '\0';
-
-       printw(CWD "%s\n\n", cwd);
+       ncols = COLS;
+       if (ncols > PATH_MAX)
+               ncols = PATH_MAX;
+       strlcpy(cwd, path, ncols);
+       cwd[ncols - strlen(CWD) - 1] = '\0';
+       realpath(cwd, cwdresolved);
+
+       printw(CWD "%s\n\n", cwdresolved);
 
        /* Print listing */
        odd = ISODD(nlines);