|
@@ -479,6 +479,12 @@ char *clish_shell__get_full_line(clish_context_t *context)
|
|
|
|
|
|
/*--------------------------------------------------------- */
|
|
|
char *clish_shell_expand_var(const char *name, clish_context_t *context)
|
|
|
+{
|
|
|
+ return clish_shell_expand_var_ex(name, context, SHELL_EXPAND_ALL);
|
|
|
+}
|
|
|
+
|
|
|
+/*----------------------------------------------------------- */
|
|
|
+char *clish_shell_expand_var_ex(const char *name, clish_context_t *context, clish_shell_expand_e flags)
|
|
|
{
|
|
|
clish_shell_t *this;
|
|
|
const clish_command_t *cmd;
|
|
@@ -494,26 +500,31 @@ char *clish_shell_expand_var(const char *name, clish_context_t *context)
|
|
|
pargv = clish_context__get_pargv(context);
|
|
|
|
|
|
/* try and substitute a parameter value */
|
|
|
- if (pargv) {
|
|
|
+ if (pargv && (flags & SHELL_EXPAND_PARAM)) {
|
|
|
const clish_parg_t *parg = clish_pargv_find_arg(pargv, name);
|
|
|
if (parg)
|
|
|
tmp = clish_parg__get_value(parg);
|
|
|
}
|
|
|
+
|
|
|
/* try and substitute the param's default */
|
|
|
- if (!tmp && cmd)
|
|
|
+ if (!tmp && cmd && (flags & SHELL_EXPAND_PARAM))
|
|
|
tmp = clish_paramv_find_default(
|
|
|
clish_command__get_paramv(cmd), name);
|
|
|
+
|
|
|
/* try and substitute a viewId variable */
|
|
|
- if (!tmp && this)
|
|
|
+ if (!tmp && this && (flags & SHELL_EXPAND_VIEW))
|
|
|
tmp = string = find_viewid_var(name, context);
|
|
|
+
|
|
|
/* try and substitute context fixed variable */
|
|
|
- if (!tmp)
|
|
|
+ if (!tmp && (flags & SHELL_EXPAND_CONTEXT))
|
|
|
tmp = string = find_context_var(name, context);
|
|
|
+
|
|
|
/* try and substitute a global var value */
|
|
|
- if (!tmp && this)
|
|
|
+ if (!tmp && this && (flags & SHELL_EXPAND_VAR))
|
|
|
tmp = string = find_global_var(name, context);
|
|
|
+
|
|
|
/* get the contents of an environment variable */
|
|
|
- if (!tmp)
|
|
|
+ if (!tmp && (flags & SHELL_EXPAND_ENV))
|
|
|
tmp = getenv(name);
|
|
|
|
|
|
if (string)
|