From a06ff83c22a4fa05fa27212e2d4bb8007c637f74 Mon Sep 17 00:00:00 2001 From: Arun Prakash Jana Date: Sun, 17 Oct 2021 11:57:38 +0530 Subject: [PATCH] Add option -i to show file information on hover --- Makefile | 5 --- misc/auto-completion/bash/nnn-completion.bash | 1 + misc/auto-completion/fish/nnn.fish | 1 + misc/auto-completion/zsh/_nnn | 1 + nnn.1 | 3 ++ src/nnn.c | 45 ++++++++++--------- 6 files changed, 29 insertions(+), 27 deletions(-) diff --git a/Makefile b/Makefile index 7bd84f69..c6edbfa3 100644 --- a/Makefile +++ b/Makefile @@ -27,7 +27,6 @@ O_NOSSN := 0 # disable session support O_NOUG := 0 # disable user, group name in status bar O_NOX11 := 0 # disable X11 integration O_MATCHFLTR := 0 # allow filters without matches -O_FILEINFO := 0 # show file informaiton in info line # User patches O_GITSTATUS := 0 # add git status to detail view @@ -122,10 +121,6 @@ ifeq ($(strip $(O_MATCHFLTR)),1) CPPFLAGS += -DMATCHFLTR endif -ifeq ($(strip $(O_FILEINFO)),1) - CPPFLAGS += -DFILEINFO -endif - ifeq ($(shell $(PKG_CONFIG) ncursesw && echo 1),1) CFLAGS_CURSES ?= $(shell $(PKG_CONFIG) --cflags ncursesw) LDLIBS_CURSES ?= $(shell $(PKG_CONFIG) --libs ncursesw) diff --git a/misc/auto-completion/bash/nnn-completion.bash b/misc/auto-completion/bash/nnn-completion.bash index 6146761c..e397bf6b 100644 --- a/misc/auto-completion/bash/nnn-completion.bash +++ b/misc/auto-completion/bash/nnn-completion.bash @@ -24,6 +24,7 @@ _nnn () -f -g -H + -i -J -K -l diff --git a/misc/auto-completion/fish/nnn.fish b/misc/auto-completion/fish/nnn.fish index 4c75388c..4d4ff695 100644 --- a/misc/auto-completion/fish/nnn.fish +++ b/misc/auto-completion/fish/nnn.fish @@ -23,6 +23,7 @@ complete -c nnn -s E -d 'use EDITOR for undetached edits' complete -c nnn -s f -d 'use readline history file' complete -c nnn -s g -d 'regex filters' complete -c nnn -s H -d 'show hidden files' +complete -c nnn -s i -d 'show file info on hover' complete -c nnn -s J -d 'no auto-proceed on select' complete -c nnn -s K -d 'detect key collision' complete -c nnn -s l -r -d 'lines to move per scroll' diff --git a/misc/auto-completion/zsh/_nnn b/misc/auto-completion/zsh/_nnn index dd8540a6..72a0e8b4 100644 --- a/misc/auto-completion/zsh/_nnn +++ b/misc/auto-completion/zsh/_nnn @@ -21,6 +21,7 @@ args=( '(-f)-f[use readline history file]' '(-g)-g[regex filters]' '(-H)-H[show hidden files]' + '(-i)-i[show file info on hover]' '(-J)-J[no auto-proceed on select]' '(-K)-K[detect key collision]' '(-l)-l[lines to move per scroll]:val' diff --git a/nnn.1 b/nnn.1 index 9432fa04..e2cc072c 100644 --- a/nnn.1 +++ b/nnn.1 @@ -84,6 +84,9 @@ supports the following options: .Fl H show hidden files .Pp +.Fl i + show file information in info bar on hover +.Pp .Fl J disable auto-proceed on select .Pp diff --git a/src/nnn.c b/src/nnn.c index b32125a5..a79387be 100644 --- a/src/nnn.c +++ b/src/nnn.c @@ -329,12 +329,12 @@ typedef struct { /* The following settings are global */ uint_t curctx : 3; /* Current context number */ uint_t prefersel : 1; /* Prefer selection over current, if exists */ - uint_t reserved2 : 1; + uint_t fileinfo : 1; /* Show file information on hover */ uint_t nonavopen : 1; /* Open file on right arrow or `l` */ uint_t autoselect : 1; /* Auto-select dir in type-to-nav mode */ uint_t cursormode : 1; /* Move hardware cursor with selection */ uint_t useeditor : 1; /* Use VISUAL to open text files */ - uint_t reserved3 : 3; + uint_t reserved2 : 3; uint_t regex : 1; /* Use regex filters */ uint_t x11 : 1; /* Copy to system clipboard, show notis, xterm title */ uint_t timetype : 2; /* Time sort type (0: access, 1: change, 2: modification) */ @@ -409,12 +409,12 @@ static settings cfg = { 0, /* reserved1 */ 0, /* curctx */ 0, /* prefersel */ - 0, /* reserved2 */ + 0, /* fileinfo */ 0, /* nonavopen */ 1, /* autoselect */ 0, /* cursormode */ 0, /* useeditor */ - 0, /* reserved3 */ + 0, /* reserved2 */ 0, /* regex */ 0, /* x11 */ 2, /* timetype (T_MOD) */ @@ -3153,10 +3153,9 @@ static void showfilterinfo(void) (cfg.regex ? "reg" : "str"), ((fnstrstr == &strcasestr) ? "ic" : "noic")); -#ifdef FILEINFO - if (ndents && get_output("file", "-b", pdents[cur].name, -1, FALSE, FALSE)) + if (cfg.fileinfo && ndents && get_output("file", "-b", pdents[cur].name, -1, FALSE, FALSE)) mvaddstr(xlines - 2, 2, g_buf); -#endif + mvaddstr(xlines - 2, xcols - xstrlen(info), info); } @@ -6169,10 +6168,8 @@ static void statusbar(char *path) attron(COLOR_PAIR(cfg.curctx + 1)); -#ifdef FILEINFO - if (get_output("file", "-b", pdents[cur].name, -1, FALSE, FALSE)) + if (cfg.fileinfo && get_output("file", "-b", pdents[cur].name, -1, FALSE, FALSE)) mvaddstr(xlines - 2, 2, g_buf); -#endif tolastln(); @@ -6221,19 +6218,19 @@ static void statusbar(char *path) } #endif if (S_ISLNK(pent->mode)) { -#ifndef FILEINFO - i = readlink(pent->name, g_buf, PATH_MAX); - addstr(coolsize(i >= 0 ? i : pent->size)); /* Show symlink size */ - if (i > 1) { /* Show symlink target */ - int y; + if (!cfg.fileinfo) { + i = readlink(pent->name, g_buf, PATH_MAX); + addstr(coolsize(i >= 0 ? i : pent->size)); /* Show symlink size */ + if (i > 1) { /* Show symlink target */ + int y; - addstr(" ->"); - getyx(stdscr, len, y); - i = MIN(i, xcols - y); - g_buf[i] = '\0'; - addstr(g_buf); + addstr(" ->"); + getyx(stdscr, len, y); + i = MIN(i, xcols - y); + g_buf[i] = '\0'; + addstr(g_buf); + } } -#endif } else { addstr(coolsize(pent->size)); addch(' '); @@ -8039,6 +8036,7 @@ static void usage(void) #endif " -g regex filters\n" " -H show hidden files\n" + " -i show file info on hover\n" " -J no auto-proceed on select\n" " -K detect key collision\n" " -l val set scroll lines\n" @@ -8222,7 +8220,7 @@ int main(int argc, char *argv[]) while ((opt = (env_opts_id > 0 ? env_opts[--env_opts_id] - : getopt(argc, argv, "aAb:cCdDeEfF:gHJKl:nop:P:QrRs:St:T:uUVwxh"))) != -1) { + : getopt(argc, argv, "aAb:cCdDeEfF:gHiJKl:nop:P:QrRs:St:T:uUVwxh"))) != -1) { switch (opt) { #ifndef NOFIFO case 'a': @@ -8276,6 +8274,9 @@ int main(int argc, char *argv[]) case 'H': cfg.showhidden = 1; break; + case 'i': + cfg.fileinfo = 1; + break; case 'J': g_state.stayonsel = 1; break;