Add option -i to show file information on hover

This commit is contained in:
Arun Prakash Jana 2021-10-17 11:57:38 +05:30
parent 9c36f0df34
commit a06ff83c22
No known key found for this signature in database
GPG Key ID: A75979F35C080412
6 changed files with 29 additions and 27 deletions

View File

@ -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)

View File

@ -24,6 +24,7 @@ _nnn ()
-f
-g
-H
-i
-J
-K
-l

View File

@ -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'

View File

@ -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'

3
nnn.1
View File

@ -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

View File

@ -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;