浏览代码

script: New environment variable KLISH_LINE.

The variable contains the whole entered line.
Serj Kalichev 5 月之前
父节点
当前提交
12daca51e9
共有 2 个文件被更改,包括 18 次插入5 次删除
  1. 1 1
      klish/kcontext.h
  2. 17 4
      plugins/script/script.c

+ 1 - 1
klish/kcontext.h

@@ -94,7 +94,7 @@ bool_t kcontext_done(const kcontext_t *context);
 FAUX_HIDDEN bool_t kcontext_set_done(kcontext_t *context, bool_t done);
 
 // Line
-const char *kcontext_line(const kcontext_t *exec);
+const char *kcontext_line(const kcontext_t *context);
 bool_t kcontext_set_line(kcontext_t *exec, const char *line);
 
 // Pipeline stage

+ 17 - 4
plugins/script/script.c

@@ -48,15 +48,28 @@ const char *kcontext_type_e_str[] = {
 #define OVERWRITE 1
 
 
-static bool_t populate_env_kpargv(const kpargv_t *pargv, const char *prefix)
+static bool_t populate_env_kpargv(const kcontext_t *context, const char *prefix)
 {
+	const char *line = NULL;
+	const kpargv_t *pargv = NULL;
 	const kentry_t *cmd = NULL;
 	faux_list_node_t *iter = NULL;
 	faux_list_node_t *cur = NULL;
 
+	if (!context)
+		return BOOL_FALSE;
+	pargv = kcontext_pargv(context);
 	if (!pargv)
 		return BOOL_FALSE;
 
+	// Line
+	line = kcontext_line(context);
+	if (line) {
+		char *var = faux_str_sprintf("%sLINE", prefix);
+		setenv(var, line, OVERWRITE);
+		faux_str_free(var);
+	}
+
 	// Command
 	cmd = kpargv_command(pargv);
 	if (cmd) {
@@ -113,7 +126,7 @@ static bool_t populate_env_kpargv(const kpargv_t *pargv, const char *prefix)
 }
 
 
-static bool_t populate_env(kcontext_t *context)
+static bool_t populate_env(const kcontext_t *context)
 {
 	kcontext_type_e type = KCONTEXT_TYPE_NONE;
 	const kentry_t *entry = NULL;
@@ -164,10 +177,10 @@ static bool_t populate_env(kcontext_t *context)
 		setenv(PREFIX"USER", str, OVERWRITE);
 
 	// Parameters
-	populate_env_kpargv(kcontext_pargv(context), PREFIX);
+	populate_env_kpargv(context, PREFIX);
 
 	// Parent parameters
-	populate_env_kpargv(kcontext_parent_pargv(context), PREFIX"PARENT_");
+	populate_env_kpargv(kcontext_parent_context(context), PREFIX"PARENT_");
 
 	return BOOL_TRUE;
 }