From: Sergey Matveev <stargrave@stargrave.org>
Date: Thu, 26 Oct 2023 15:09:19 +0000 (+0300)
Subject: F2/F5 cd/cp
X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=450fc7d07b50d9c882841cc277e4ecafe6f14fa2;p=nnn.git

F2/F5 cd/cp
---

diff --git a/src/nnn.c b/src/nnn.c
index 566d12c6..2d9f6dbc 100644
--- a/src/nnn.c
+++ b/src/nnn.c
@@ -7889,6 +7889,22 @@ nochange:
 			cd = FALSE;
 			goto begin;
 		}
+		case SEL_CD: // fallthrough
+		case SEL_COPY:
+			if (!xdiraccess(plgpath)) {
+				printwarn(&presel);
+				goto nochange;
+			}
+			endselection(FALSE);
+			tmp = sel == SEL_CD ? "!_nnn-cd*" : "!_nnn-cp";
+			if (!run_plugin(&path, tmp, (ndents ? pdents[cur].name : NULL),
+						 &lastname, &lastdir)) {
+				printwait(messages[MSG_FAILED], &presel);
+				goto nochange;
+			}
+			copycurname();
+			setdirwatch();
+			goto begin;
 		case SEL_PLUGIN:
 			/* Check if directory is accessible */
 			if (!xdiraccess(plgpath)) {
diff --git a/src/nnn.h b/src/nnn.h
index adfb83b4..16f5b4c9 100644
--- a/src/nnn.h
+++ b/src/nnn.h
@@ -119,6 +119,8 @@ enum action {
 	SEL_QUIT,
 	SEL_QUITERR,
 	SEL_VIEW,
+	SEL_COPY,
+	SEL_CD,
 #ifndef NOMOUSE
 	SEL_CLICK,
 #endif
@@ -264,6 +266,10 @@ static struct key bindings[] = {
 	{ KEY_F(3),       SEL_VIEW },
 	/* Run a plugin */
 	{ ';',            SEL_PLUGIN },
+	/* Call _nnn-cd */
+	{ KEY_F(2),       SEL_CD },
+	/* Call _nnn-cp */
+	{ KEY_F(5),       SEL_COPY },
 	/* Show total size of listed selection */
 	{ 'S',            SEL_SELSIZE },
 	/* Run command */