[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[screen-devel] [PATCH] process: add RC_ADOPTWD adopt working directory
From: |
Vito Caputo |
Subject: |
[screen-devel] [PATCH] process: add RC_ADOPTWD adopt working directory |
Date: |
Tue, 31 Oct 2017 19:30:35 -0700 |
User-agent: |
Mutt/1.5.23 (2014-03-12) |
This is an RC_CHDIR convenience helper which discovers the working
directory of the foreground window.
By default, using Ctrl-@ one can switch the working directory of screen
to the current directory of the foreground window.
---
src/comm.c | 1 +
src/process.c | 19 +++++++++++++++++++
2 files changed, 20 insertions(+)
diff --git a/src/comm.c b/src/comm.c
index df76670..624645d 100644
--- a/src/comm.c
+++ b/src/comm.c
@@ -42,6 +42,7 @@ struct comm comms[RC_LAST + 1] =
{ "aclumask", ARGS_1|ARGS_ORMORE, {NULL} },
{ "activity", ARGS_1, {NULL} },
{ "addacl", ARGS_1234, {NULL} },
+ { "adoptwd", NEED_FORE|ARGS_0, {NULL} },
{ "allpartial", NEED_DISPLAY|ARGS_1, {NULL} },
{ "altscreen", ARGS_01, {NULL} },
{ "at", ARGS_2|ARGS_ORMORE, {NULL} },
diff --git a/src/process.c b/src/process.c
index 362bf12..63e3c0a 100644
--- a/src/process.c
+++ b/src/process.c
@@ -465,6 +465,7 @@ void InitKeytab()
ktab['Z'].nr = RC_RESET;
ktab['H'].nr = RC_LOG;
ktab['M'].nr = RC_MONITOR;
+ ktab['@'].nr = RC_ADOPTWD;
ktab['?'].nr = RC_HELP;
ktab['*'].nr = RC_DISPLAYS;
{
@@ -2103,6 +2104,24 @@ void DoAction(struct action *act, int key)
if (chdir(s) == -1)
OutputMsg(errno, "%s", s);
break;
+ case RC_ADOPTWD:
+ {
+ char proc[MAXPATHLEN];
+ char buf[MAXPATHLEN];
+
+ /* this sets the working directory of the screen
process to that of the process @ the end of the pty */
+ if (!display || !fore)
+ break;
+ snprintf(proc, sizeof(proc), "/proc/%i/cwd",
fore->w_pid);
+ bzero(buf, sizeof(buf));
+ if (readlink(proc, buf, sizeof(buf)) == -1)
+ Msg(0, "Unable to readlink \"%s\".", proc);
+ else if (chdir(buf) == -1)
+ Msg(0, "Unable to chdir to \"%s\".", buf);
+ else
+ Msg(0, "WD for future windows is now \"%s\".",
buf);
+ }
+ break;
case RC_SHELL:
case RC_DEFSHELL:
if (ParseSaveStr(act, &ShellProg) == 0)
--
2.11.0
- [screen-devel] [PATCH] process: add RC_ADOPTWD adopt working directory,
Vito Caputo <=