summary refs log tree commit diff
path: root/Src/init.c
diff options
context:
space:
mode:
authorPeter Stephenson <pws@zsh.org>2015-12-04 09:27:30 +0000
committerPeter Stephenson <pws@zsh.org>2015-12-04 09:28:26 +0000
commitfc00e3a6b79862be1b605279615fe88259d70799 (patch)
treebafbfd3bfd648bdc01b9a620186d8915bac3781b /Src/init.c
parent5ecf332e84fc296a37d3ad9ec35fe3495234cfc1 (diff)
downloadzsh-fc00e3a6b79862be1b605279615fe88259d70799.tar.gz
zsh-fc00e3a6b79862be1b605279615fe88259d70799.tar.xz
zsh-fc00e3a6b79862be1b605279615fe88259d70799.zip
37294: Add ZSH_EXECUTION_STRING.
This shows the argument to shell option -c.
Diffstat (limited to 'Src/init.c')
-rw-r--r--Src/init.c28
1 files changed, 15 insertions, 13 deletions
diff --git a/Src/init.c b/Src/init.c
index dcce1d7ce..789489332 100644
--- a/Src/init.c
+++ b/Src/init.c
@@ -240,13 +240,11 @@ loop(int toplevel, int justonce)
     return LOOP_OK;
 }
 
-/* Shared among parseargs(), parseopts(), init_io(), and init_misc() */
-static char *cmd;
 static int restricted;
 
 /**/
 static void
-parseargs(char **argv, char **runscript)
+parseargs(char **argv, char **runscript, char **cmdptr)
 {
     char **x;
     LinkList paramlist;
@@ -272,7 +270,7 @@ parseargs(char **argv, char **runscript)
     opts[SHINSTDIN] = 0;
     opts[SINGLECOMMAND] = 0;
 
-    if (parseopts(NULL, &argv, opts, &cmd, NULL))
+    if (parseopts(NULL, &argv, opts, cmdptr, NULL))
 	exit(1);
 
     /*
@@ -290,7 +288,7 @@ parseargs(char **argv, char **runscript)
     if (*argv) {
 	if (unset(SHINSTDIN)) {
 	    posixzero = *argv;
-	    if (cmd)
+	    if (*cmdptr)
 		argzero = *argv;
 	    else
 		*runscript = *argv;
@@ -299,7 +297,7 @@ parseargs(char **argv, char **runscript)
 	}
 	while (*argv)
 	    zaddlinknode(paramlist, ztrdup(*argv++));
-    } else if (!cmd)
+    } else if (!*cmdptr)
 	opts[SHINSTDIN] = 1;
     if(isset(SINGLECOMMAND))
 	opts[INTERACTIVE] &= 1;
@@ -497,7 +495,7 @@ printhelp(void)
 
 /**/
 mod_export void
-init_io(void)
+init_io(char *cmd)
 {
     static char outbuf[BUFSIZ], errbuf[BUFSIZ];
 
@@ -802,7 +800,7 @@ init_term(void)
 
 /**/
 void
-setupvals(void)
+setupvals(char *cmd)
 {
 #ifdef USE_GETPWUID
     struct passwd *pswd;
@@ -1086,6 +1084,9 @@ setupvals(void)
 
     /* Colour sequences for outputting colours in prompts and zle */
     set_default_colour_sequences();
+
+    if (cmd)
+	setsparam("ZSH_EXECUTION_STRING", ztrdup(cmd));
 }
 
 /*
@@ -1267,7 +1268,7 @@ run_init_scripts(void)
 
 /**/
 void
-init_misc(void)
+init_misc(char *cmd)
 {
 #ifndef RESTRICTED_R
     if ( restricted )
@@ -1604,6 +1605,7 @@ mod_export int
 zsh_main(UNUSED(int argc), char **argv)
 {
     char **t, *runscript = NULL;
+    char *cmd;			/* argument to -c */
     int t0;
 #ifdef USE_LOCALE
     setlocale(LC_ALL, "");
@@ -1652,18 +1654,18 @@ zsh_main(UNUSED(int argc), char **argv)
     opts[LOGINSHELL] = (**argv == '-');
     opts[PRIVILEGED] = (getuid() != geteuid() || getgid() != getegid());
     /* sets ZLE, INTERACTIVE, SHINSTDIN and SINGLECOMMAND */
-    parseargs(argv, &runscript);
+    parseargs(argv, &runscript, &cmd);
 
     SHTTY = -1;
-    init_io();
-    setupvals();
+    init_io(cmd);
+    setupvals(cmd);
 
     init_signals();
     init_bltinmods();
     init_builtins();
     run_init_scripts();
     setupshin(runscript);
-    init_misc();
+    init_misc(cmd);
 
     for (;;) {
 	/*