shithub: riscv

Download patch

ref: 2efc26f24ccec9cdfa9372af1a1d4ea968d6051e
parent: af848f17658455d643de41f9cb53b61fe2eb72a6
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Fri Sep 8 09:48:54 EDT 2023

nedmail: set $% to the full path of the current message

--- a/sys/man/1/nedmail
+++ b/sys/man/1/nedmail
@@ -277,6 +277,10 @@
 Print the number of the current message.
 .PD
 .PP
+Shell commands will have environment variable
+.B $%
+set to the full path of the current message.
+.PP
 Here's an example of a mail session that looks at a summary
 of the mail messages, saves away an html file added as an
 attachment to a message and then deletes the message:
--- a/sys/src/cmd/upas/ned/nedmail.c
+++ b/sys/src/cmd/upas/ned/nedmail.c
@@ -177,7 +177,7 @@
 int		mdir2message(Message*);
 char*		extendp(char*, char*);
 char*		parsecmd(char*, Cmd*, Message*, Message*);
-void		system(char*, char**, int);
+void		system(Message*, char*, char**, int);
 int		switchmb(char *, int);
 void		closemb(void);
 Message*	dosingleton(Message*, char*);
@@ -397,7 +397,7 @@
 		av[0] = "fs";
 		av[1] = "-p";
 		av[2] = 0;
-		system("/bin/upas/fs", av, -1);
+		system(nil, "/bin/upas/fs", av, -1);
 	}
 
 	switchmb(mb, singleton);
@@ -2591,7 +2591,7 @@
 }
 
 void
-system(char *cmd, char **av, int in)
+system(Message *m, char *cmd, char **av, int in)
 {
 	switch(fork()){
 	case -1:
@@ -2604,6 +2604,8 @@
 		}
 		if(wd[0] != 0)
 			chdir(wd);
+		if(m != nil && strcmp(m->path, ".") != 0)
+			putenv("%", rooted(m->path));
 		exec(cmd, av);
 		eprint("!couldn't exec %s\n", cmd);
 		exits(0);
@@ -2629,7 +2631,7 @@
 	av[1] = "-c";
 	av[2] = c->cmdline;
 	av[3] = 0;
-	system("/bin/rc", av, -1);
+	system(m, "/bin/rc", av, -1);
 //	Bprint(&out, "!\n");
 	return m;
 }
@@ -2655,7 +2657,7 @@
 	av[1] = "-c";
 	av[2] = c->cmdline;
 	av[3] = 0;
-	system("/bin/rc", av, fd);	/* system closes fd */
+	system(m, "/bin/rc", av, fd);	/* system closes fd */
 //	Bprint(&out, "!\n");
 	return m;
 }