mirror of
https://github.com/jarun/nnn.git
synced 2024-11-28 05:41:31 +00:00
Show stat, file, md5, sh256 in file details
This commit adds dependencies on file, openssl and cut binaries.
This commit is contained in:
parent
f466ba543c
commit
418c9f2654
|
@ -54,7 +54,7 @@ I chose to fork because:
|
||||||
- current item in reverse video
|
- current item in reverse video
|
||||||
- number of items in current directory
|
- number of items in current directory
|
||||||
- full name of currently selected file
|
- full name of currently selected file
|
||||||
- Show details of the currently selected file
|
- Show details of the currently selected file (stat, file, md5, sha256)
|
||||||
- Directories first
|
- Directories first
|
||||||
- Sort numeric names in numeric order
|
- Sort numeric names in numeric order
|
||||||
- Case-insensitive alphabetic content listing instead of upper case first
|
- Case-insensitive alphabetic content listing instead of upper case first
|
||||||
|
|
60
nnn.c
60
nnn.c
|
@ -639,6 +639,8 @@ get_fileind(mode_t mode, char *desc)
|
||||||
if (S_ISREG(mode)) {
|
if (S_ISREG(mode)) {
|
||||||
c = '-';
|
c = '-';
|
||||||
sprintf(desc, "%s", "regular file");
|
sprintf(desc, "%s", "regular file");
|
||||||
|
if (mode & S_IXUSR)
|
||||||
|
strcat(desc, ", executable");
|
||||||
} else if (S_ISDIR(mode)) {
|
} else if (S_ISDIR(mode)) {
|
||||||
c = 'd';
|
c = 'd';
|
||||||
sprintf(desc, "%s", "directory");
|
sprintf(desc, "%s", "directory");
|
||||||
|
@ -703,14 +705,30 @@ get_lsperms(mode_t mode, char *desc)
|
||||||
return(bits);
|
return(bits);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *
|
||||||
|
get_output(char *buf, size_t bytes)
|
||||||
|
{
|
||||||
|
char *ret;
|
||||||
|
FILE *pf = popen(buf, "r");
|
||||||
|
if (pf) {
|
||||||
|
ret = fgets(buf, bytes, pf);
|
||||||
|
pclose(pf);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Follows the stat(1) output closely
|
* Follows the stat(1) output closely
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
show_stats(char* fpath, char* fname, struct stat *sb)
|
show_stats(char* fpath, char* fname, struct stat *sb)
|
||||||
{
|
{
|
||||||
char buf[40];
|
char buf[PATH_MAX + 48];
|
||||||
char *perms = get_lsperms(sb->st_mode, buf);
|
char *perms = get_lsperms(sb->st_mode, buf);
|
||||||
|
FILE *pf;
|
||||||
|
char *p, *begin = buf;
|
||||||
|
|
||||||
clear();
|
clear();
|
||||||
|
|
||||||
|
@ -718,11 +736,12 @@ show_stats(char* fpath, char* fname, struct stat *sb)
|
||||||
if (perms[0] == 'l') {
|
if (perms[0] == 'l') {
|
||||||
char symtgt[PATH_MAX];
|
char symtgt[PATH_MAX];
|
||||||
ssize_t len = readlink(fpath, symtgt, PATH_MAX);
|
ssize_t len = readlink(fpath, symtgt, PATH_MAX);
|
||||||
if (len == -1)
|
if (len != -1) {
|
||||||
printerr(1, "readlink");
|
symtgt[len] = '\0';
|
||||||
printw("\n\n File: '%s' -> '%s'", fname, symtgt);
|
printw("\n\n File: '%s' -> '%s'", fname, symtgt);
|
||||||
|
}
|
||||||
} else
|
} else
|
||||||
printw("\n\n File: '%s'", fname);
|
printw("\n File: '%s'", fname);
|
||||||
|
|
||||||
/* Show size, blocks, file type */
|
/* Show size, blocks, file type */
|
||||||
printw("\n Size: %-15llu Blocks: %-10llu IO Block: %-6llu %s",
|
printw("\n Size: %-15llu Blocks: %-10llu IO Block: %-6llu %s",
|
||||||
|
@ -757,8 +776,39 @@ show_stats(char* fpath, char* fname, struct stat *sb)
|
||||||
strftime(buf, 40, "%a %d-%b-%Y %T %z,%Z", localtime(&sb->st_ctime));
|
strftime(buf, 40, "%a %d-%b-%Y %T %z,%Z", localtime(&sb->st_ctime));
|
||||||
printw("\n Change: %s", buf);
|
printw("\n Change: %s", buf);
|
||||||
|
|
||||||
|
if (S_ISREG(sb->st_mode)) {
|
||||||
|
/* Show file(1) output */
|
||||||
|
sprintf(buf, "file -b %s 2>&1", fpath);
|
||||||
|
p = get_output(buf, PATH_MAX + 48);
|
||||||
|
if (p) {
|
||||||
|
printw("\n\n ");
|
||||||
|
while (*p) {
|
||||||
|
if (*p == ',') {
|
||||||
|
*p = '\0';
|
||||||
|
printw(" %s\n", begin);
|
||||||
|
begin = p + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
p++;
|
||||||
|
}
|
||||||
|
printw(" %s", begin);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Show md5 */
|
||||||
|
sprintf(buf, "openssl md5 %s 2>&1 | cut -d' ' -f2", fpath);
|
||||||
|
p = get_output(buf, PATH_MAX + 48);
|
||||||
|
if (p)
|
||||||
|
printw("\n md5: %s", p);
|
||||||
|
|
||||||
|
/* Show sha256 */
|
||||||
|
sprintf(buf, "openssl sha256 %s 2>&1| cut -d' ' -f2", fpath);
|
||||||
|
p = get_output(buf, PATH_MAX + 48);
|
||||||
|
if (p)
|
||||||
|
printw(" sha256: %s", p);
|
||||||
|
}
|
||||||
|
|
||||||
/* Show exit keys */
|
/* Show exit keys */
|
||||||
printw("\n\n\n\n < (q/Esc)");
|
printw("\n\n << (q/Esc)");
|
||||||
|
|
||||||
while (*buf = getch())
|
while (*buf = getch())
|
||||||
if (*buf == 'q' || *buf == 27)
|
if (*buf == 'q' || *buf == 27)
|
||||||
|
|
Loading…
Reference in a new issue