Fix #26: Provide an option to use a custom nlay file.

This commit is contained in:
Arun Prakash Jana 2017-05-14 21:00:46 +05:30
parent d1924756c7
commit e4f72170d0
No known key found for this signature in database
GPG key ID: A75979F35C080412
3 changed files with 25 additions and 8 deletions

View file

@ -121,6 +121,7 @@ nnn needs libreadline, libncursesw (on Linux or ncurses on OS X) and standard li
optional arguments: optional arguments:
-d start in detail view mode -d start in detail view mode
-p path to custom nlay
-S start in disk usage analyzer mode -S start in disk usage analyzer mode
-v show program version and exit -v show program version and exit
-h show this help and exit -h show this help and exit

6
nlay
View file

@ -25,8 +25,10 @@
# 3. Assuming you don't to play multiple audio/video files simultaneously, # 3. Assuming you don't to play multiple audio/video files simultaneously,
# nlay kills any running instances of the audio/video player in bg mode. # nlay kills any running instances of the audio/video player in bg mode.
# #
# 4. Keep a personal backup (on GitHub Gist maybe?) of this file if you modify # 4. nlay is OVERWRITTEN during nnn upgrade. You can store your custom nlay in a
# it. nlay is OVERWRITTEN during nnn upgrade. # location other than the default and have an alias with nnn option '-p' to
# invoke it. Remember it might break or lack new capabilities added to nlay
# in future releases. Check the file diff once in a while.
# #
# Author: Arun Prakash Jana # Author: Arun Prakash Jana
# Email: engineerarun@gmail.com # Email: engineerarun@gmail.com

24
nnn.c
View file

@ -144,6 +144,7 @@ static int ndents, cur, total_dents;
static int idle; static int idle;
static char *opener; static char *opener;
static char *fb_opener; static char *fb_opener;
static char *player;
static char *copier; static char *copier;
static char *desktop_manager; static char *desktop_manager;
static off_t blk_size; static off_t blk_size;
@ -1570,7 +1571,7 @@ nochange:
/* If NNN_OPENER is set, use it */ /* If NNN_OPENER is set, use it */
if (opener) { if (opener) {
sprintf(cmd, "%s \'", opener); sprintf(cmd, "%s \'", opener);
xstrlcpy(cmd + strlen(cmd), newpath, sizeof(cmd) - strlen(cmd)); xstrlcpy(cmd + strlen(cmd), newpath, MAX_CMD_LEN - strlen(cmd));
strcat(cmd, "\' > /dev/null 2>&1"); strcat(cmd, "\' > /dev/null 2>&1");
r = system(cmd); r = system(cmd);
continue; continue;
@ -1579,8 +1580,13 @@ nochange:
/* Play with nlay if identified */ /* Play with nlay if identified */
mime = getmime(dents[cur].name); mime = getmime(dents[cur].name);
if (mime) { if (mime) {
if (player) {
cmd[0] = '\'';
xstrlcpy(cmd + 1, player, MAX_CMD_LEN);
strcat(cmd, "\' \'");
} else
strcpy(cmd, "nlay \'"); strcpy(cmd, "nlay \'");
xstrlcpy(cmd + strlen(cmd), newpath, sizeof(cmd) - strlen(cmd)); xstrlcpy(cmd + strlen(cmd), newpath, MAX_CMD_LEN - strlen(cmd));
sprintf(cmd + strlen(cmd), "\' %s", mime); sprintf(cmd + strlen(cmd), "\' %s", mime);
exitcurses(); exitcurses();
r = system(cmd); r = system(cmd);
@ -1591,7 +1597,7 @@ nochange:
/* If nlay doesn't handle it, open plain text /* If nlay doesn't handle it, open plain text
files with vi, then try NNN_FALLBACK_OPENER */ files with vi, then try NNN_FALLBACK_OPENER */
strcpy(cmd, "file -bi \'"); strcpy(cmd, "file -bi \'");
xstrlcpy(cmd + strlen(cmd), newpath, sizeof(cmd) - strlen(cmd)); xstrlcpy(cmd + strlen(cmd), newpath, MAX_CMD_LEN - strlen(cmd));
strcat(cmd, "\'"); strcat(cmd, "\'");
if (get_output(cmd, MAX_CMD_LEN) == NULL) if (get_output(cmd, MAX_CMD_LEN) == NULL)
continue; continue;
@ -1604,7 +1610,7 @@ nochange:
continue; continue;
} else if (fb_opener) { } else if (fb_opener) {
sprintf(cmd, "%s \'", fb_opener); sprintf(cmd, "%s \'", fb_opener);
xstrlcpy(cmd + strlen(cmd), newpath, sizeof(cmd) - strlen(cmd)); xstrlcpy(cmd + strlen(cmd), newpath, MAX_CMD_LEN - strlen(cmd));
strcat(cmd, "\' > /dev/null 2>&1"); strcat(cmd, "\' > /dev/null 2>&1");
r = system(cmd); r = system(cmd);
continue; continue;
@ -2001,6 +2007,7 @@ positional arguments:\n\
PATH directory to open [default: current dir]\n\n\ PATH directory to open [default: current dir]\n\n\
optional arguments:\n\ optional arguments:\n\
-d start in detail view mode\n\ -d start in detail view mode\n\
-p path to custom nlay\n\
-S start in disk usage analyzer mode\n\ -S start in disk usage analyzer mode\n\
-v show program version and exit\n\ -v show program version and exit\n\
-h show this help and exit\n\n\ -h show this help and exit\n\n\
@ -2027,7 +2034,7 @@ main(int argc, char *argv[])
if (argc > 3) if (argc > 3)
usage(); usage();
while ((opt = getopt(argc, argv, "dSvh")) != -1) { while ((opt = getopt(argc, argv, "dSp:vh")) != -1) {
switch (opt) { switch (opt) {
case 'S': case 'S':
bsizeorder = 1; bsizeorder = 1;
@ -2036,6 +2043,13 @@ main(int argc, char *argv[])
showdetail = 1; showdetail = 1;
printptr = &printent_long; printptr = &printent_long;
break; break;
case 'p':
player = optarg;
if (strlen(player) > 512) {
fprintf(stderr, "path to player must be <= 512 characters\n");
exit(1);
}
break;
case 'v': case 'v':
fprintf(stdout, "%s\n", VERSION); fprintf(stdout, "%s\n", VERSION);
return 0; return 0;