aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Arun Prakash Jana <engineerarun@gmail.com>2020-05-24 03:30:51 +0530
committerGravatar Arun Prakash Jana <engineerarun@gmail.com>2020-05-24 03:33:39 +0530
commit56886922a62b39b43897988bdae289a47fc1026a (patch)
treed5e177303f9f39b0308752c1732256966a000291
parentc1f88d00ffe268b63443c2c38bf214f1344e9b43 (diff)
downloadnnn-56886922a62b39b43897988bdae289a47fc1026a.tar.gz
Select file if file path is passed
-rw-r--r--src/nnn.c24
1 files changed, 16 insertions, 8 deletions
diff --git a/src/nnn.c b/src/nnn.c
index 942b7db..c83d970 100644
--- a/src/nnn.c
+++ b/src/nnn.c
@@ -401,6 +401,7 @@ static char g_pipepath[TMP_LEN_MAX] __attribute__ ((aligned));
#define STATE_TRASH 0x40
#define STATE_FORCEQUIT 0x80
#define STATE_AUTOFIFO 0x100
+#define STATE_INITFILE 0x200
static uint g_states;
@@ -5253,11 +5254,20 @@ static bool browse(char *ipath, const char *session, int pkey)
/* setup first context */
if (!session || !load_session(session, &path, &lastdir, &lastname, FALSE)) {
- xstrsncpy(g_ctx[0].c_path, ipath, PATH_MAX); /* current directory */
- path = g_ctx[0].c_path;
- g_ctx[0].c_last[0] = g_ctx[0].c_name[0] = '\0';
+ g_ctx[0].c_last[0] = '\0';
lastdir = g_ctx[0].c_last; /* last visited directory */
+
+ if (g_states & STATE_INITFILE) {
+ xstrsncpy(g_ctx[0].c_name, xbasename(ipath), sizeof(g_ctx[0].c_name));
+ xdirname(ipath);
+ } else
+ g_ctx[0].c_name[0] = '\0';
+
lastname = g_ctx[0].c_name; /* last visited filename */
+
+ xstrsncpy(g_ctx[0].c_path, ipath, PATH_MAX);
+ path = g_ctx[0].c_path; /* current directory */
+
g_ctx[0].c_fltr[0] = g_ctx[0].c_fltr[1] = '\0';
g_ctx[0].c_cfg = cfg; /* current configuration */
}
@@ -6725,7 +6735,7 @@ static void usage(void)
"%s: nnn [OPTIONS] [PATH]\n\n"
"The missing terminal file manager for X.\n\n"
"positional args:\n"
- " PATH start dir [default: .]\n\n"
+ " PATH start dir/file [default: .]\n\n"
"optional args:\n"
#ifndef NOFIFO
" -a auto NNN_FIFO\n"
@@ -7124,10 +7134,8 @@ int main(int argc, char *argv[])
return EXIT_FAILURE;
}
- if (S_ISREG(sb.st_mode)) {
- spawn(opener, arg, NULL, cfg.cliopener ? F_CLI : F_NOTRACE | F_NOWAIT);
- return EXIT_SUCCESS;
- }
+ if (!S_ISDIR(sb.st_mode))
+ g_states |= STATE_INITFILE;
if (session)
session = NULL;