Option -U to show user and group in status bar

This commit is contained in:
Arun Prakash Jana 2020-10-31 20:47:07 +05:30
parent aabbf6ddcb
commit ff5685b64d
5 changed files with 37 additions and 2 deletions

View file

@ -40,6 +40,7 @@ _nnn ()
-t -t
-T -T
-u -u
-U
-V -V
-w -w
-x -x

View file

@ -39,6 +39,7 @@ complete -c nnn -s S -d 'persistent session'
complete -c nnn -s t -r -d 'timeout in seconds to lock' complete -c nnn -s t -r -d 'timeout in seconds to lock'
complete -c nnn -s T -r -d 'a d e r s t v' complete -c nnn -s T -r -d 'a d e r s t v'
complete -c nnn -s u -d 'use selection (no prompt)' complete -c nnn -s u -d 'use selection (no prompt)'
complete -c nnn -s U -d 'show user and group'
complete -c nnn -s V -d 'show program version and exit' complete -c nnn -s V -d 'show program version and exit'
complete -c nnn -s w -d 'hardware cursor mode' complete -c nnn -s w -d 'hardware cursor mode'
complete -c nnn -s x -d 'notis, sel to system clipboard' complete -c nnn -s x -d 'notis, sel to system clipboard'

View file

@ -37,6 +37,7 @@ args=(
'(-t)-t[timeout to lock]:seconds' '(-t)-t[timeout to lock]:seconds'
'(-T)-T[a d e r s t v]:key' '(-T)-T[a d e r s t v]:key'
'(-u)-u[use selection (no prompt)]' '(-u)-u[use selection (no prompt)]'
'(-U)-U[show user and group]'
'(-V)-V[show program version and exit]' '(-V)-V[show program version and exit]'
'(-w)-C[hardware cursor mode]' '(-w)-C[hardware cursor mode]'
'(-x)-x[notis, sel to system clipboard]' '(-x)-x[notis, sel to system clipboard]'

4
nnn.1
View file

@ -33,6 +33,7 @@
.Op Ar -t secs .Op Ar -t secs
.Op Ar -T key .Op Ar -T key
.Op Ar -u .Op Ar -u
.Op Ar -U
.Op Ar -V .Op Ar -V
.Op Ar -w .Op Ar -w
.Op Ar -x .Op Ar -x
@ -147,6 +148,9 @@ supports the following options:
.Fl u .Fl u
use selection if available, don't prompt to choose between selection and hovered entry use selection if available, don't prompt to choose between selection and hovered entry
.Pp .Pp
.Fl U
show user and group names in status bar
.Pp
.Fl V .Fl V
show version and exit show version and exit
.Pp .Pp

View file

@ -99,6 +99,8 @@
#endif #endif
#include <ftw.h> #include <ftw.h>
#include <wchar.h> #include <wchar.h>
#include <pwd.h>
#include <grp.h>
#if !defined(alloca) && defined(__GNUC__) #if !defined(alloca) && defined(__GNUC__)
/* /*
@ -250,6 +252,8 @@ typedef struct entry {
off_t size; off_t size;
blkcnt_t blocks; /* number of 512B blocks allocated */ blkcnt_t blocks; /* number of 512B blocks allocated */
mode_t mode; mode_t mode;
uid_t uid;
gid_t gid;
ushort nlen; /* Length of file name */ ushort nlen; /* Length of file name */
uchar flags; /* Flags specific to the file */ uchar flags; /* Flags specific to the file */
} *pEntry; } *pEntry;
@ -325,7 +329,8 @@ typedef struct {
uint oldcolor : 1; /* Use older colorscheme */ uint oldcolor : 1; /* Use older colorscheme */
uint stayonsel : 1; /* Disable auto-proceed on select */ uint stayonsel : 1; /* Disable auto-proceed on select */
uint dirctx : 1; /* Show dirs in context color */ uint dirctx : 1; /* Show dirs in context color */
uint reserved : 11; /* Adjust when adding/removing a field */ uint uidgid : 1; /* Show owner and group info */
uint reserved : 10; /* Adjust when adding/removing a field */
} runstate; } runstate;
/* Contexts or workspaces */ /* Contexts or workspaces */
@ -5098,6 +5103,9 @@ static int dentfill(char *path, struct entry **ppdents)
dentp->mode = sb.st_mode; dentp->mode = sb.st_mode;
dentp->size = sb.st_size; dentp->size = sb.st_size;
#endif #endif
dentp->uid = sb.st_uid;
dentp->gid = sb.st_gid;
dentp->flags = S_ISDIR(sb.st_mode) ? 0 : ((sb.st_nlink > 1) ? HARD_LINK : 0); dentp->flags = S_ISDIR(sb.st_mode) ? 0 : ((sb.st_nlink > 1) ? HARD_LINK : 0);
if (entflags) { if (entflags) {
dentp->flags |= entflags; dentp->flags |= entflags;
@ -5570,6 +5578,22 @@ static void statusbar(char *path)
addch(' '); addch(' ');
addstr(get_lsperms(pent->mode)); addstr(get_lsperms(pent->mode));
addch(' '); addch(' ');
if (g_state.uidgid) {
struct passwd *pw = getpwuid(pent->uid);
struct group *gr = getgrgid(pent->gid);
if (pw)
addstr(pw->pw_name);
else
addch('-');
addch(' ');
if (gr)
addstr(gr->gr_name);
else
addch('-');
addch(' ');
}
addstr(coolsize(pent->size)); addstr(coolsize(pent->size));
addch(' '); addch(' ');
addstr(ptr); addstr(ptr);
@ -7333,6 +7357,7 @@ static void usage(void)
" -t secs timeout to lock\n" " -t secs timeout to lock\n"
" -T key sort order [a/d/e/r/s/t/v]\n" " -T key sort order [a/d/e/r/s/t/v]\n"
" -u use selection (no prompt)\n" " -u use selection (no prompt)\n"
" -U show user and group\n"
" -V show version\n" " -V show version\n"
" -w place HW cursor on hovered\n" " -w place HW cursor on hovered\n"
" -x notis, sel to system clipboard\n" " -x notis, sel to system clipboard\n"
@ -7480,7 +7505,7 @@ int main(int argc, char *argv[])
while ((opt = (env_opts_id > 0 while ((opt = (env_opts_id > 0
? env_opts[--env_opts_id] ? env_opts[--env_opts_id]
: getopt(argc, argv, "aAb:cCdDeEfFgHJKl:nop:P:QrRs:St:T:uVwxh"))) != -1) { : getopt(argc, argv, "aAb:cCdDeEfFgHJKl:nop:P:QrRs:St:T:uUVwxh"))) != -1) {
switch (opt) { switch (opt) {
#ifndef NOFIFO #ifndef NOFIFO
case 'a': case 'a':
@ -7599,6 +7624,9 @@ int main(int argc, char *argv[])
case 'u': case 'u':
cfg.prefersel = 1; cfg.prefersel = 1;
break; break;
case 'U':
g_state.uidgid = 1;
break;
case 'V': case 'V':
fprintf(stdout, "%s\n", VERSION); fprintf(stdout, "%s\n", VERSION);
return EXIT_SUCCESS; return EXIT_SUCCESS;