mirror of
https://github.com/kernelkit/infix.git
synced 2026-08-03 14:23:02 +02:00
klish: klish-plugin-sysrepo: klinfix: bump for new srp_prompt@sysrepo
This commit changes the JunOS look of the CLI to something more akin to a standard shell. To achieve this a %w format specifier to display the path components is added to both klish and klish-plugin-sysrepo. Before: admin@infix-12-34-56:exec> configure [edit] admin@infix-12-34-56:configure> ediit interfaces interface eth0 [edit interfaces interface eth0] admin@infix-12-34-56:configure> leave admin@infix-12-34-56:exec> After: admin@infix-12-34-56:/> configure admin@infix-12-34-56:/config/> edit interfaces interface eth0 admin@infix-12-34-56:/config/interfaces/interface/eth0/> leave admin@infix-12-34-56:/> leave However, due to unforseen problems with the naming of VIEWs in klish, the admin-exec level "path" is hard-coded to "/" for now. Future imporovement: fold in calling prompt@klish from srp_prompt, and figure out why the "main" VIEW cannot be changed to "exec" without klish just bailing out starting up. Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
committed by
Tobias Waldekranz
parent
63779cfe37
commit
d4b23eac75
@@ -1,3 +1,3 @@
|
||||
# Locally calculated
|
||||
sha256 9d9d33b873917ca5d0bdcc47a36d2fd385971ab0c045d1472fcadf95ee5bcf5b LICENCE
|
||||
sha256 6ec2a048c50cf35c0a8d72e541afb78351d4b7229670ac55be544e38f6cc9e54 klish-plugin-sysrepo-7e8f75536d20ff38763d00508347acb142511301-br1.tar.gz
|
||||
sha256 787981aafae509a889cfab71dcc8e68d8e511419cf9f3934239c5f2296d2ad5c klish-plugin-sysrepo-7572111a0f81009506392d309ec3fa4d328d5cce-br1.tar.gz
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#
|
||||
################################################################################
|
||||
|
||||
KLISH_PLUGIN_SYSREPO_VERSION = 7e8f75536d20ff38763d00508347acb142511301
|
||||
KLISH_PLUGIN_SYSREPO_VERSION = 7572111a0f81009506392d309ec3fa4d328d5cce
|
||||
KLISH_PLUGIN_SYSREPO_SITE = https://github.com/kernelkit/klish-plugin-sysrepo.git
|
||||
#KLISH_PLUGIN_SYSREPO_VERSION = cdd3eb51a7f7ee0ed5bd925fa636061d3b1b85fb
|
||||
#KLISH_PLUGIN_SYSREPO_SITE = https://src.libcode.org/pkun/klish-plugin-sysrepo.git
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
From 9f91b3969d2ba9ee6e6d1a174953dbd141ae1698 Mon Sep 17 00:00:00 2001
|
||||
From: Joachim Wiberg <troglobit@gmail.com>
|
||||
Date: Sat, 15 Jul 2023 19:56:00 +0200
|
||||
Subject: [PATCH] Add '%w' qualifier to klish_prompt() to expand to CWD
|
||||
Organization: Addiva Elektronik
|
||||
|
||||
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
|
||||
---
|
||||
klish/ksession/ksession_parse.c | 2 ++
|
||||
plugins/klish/misc.c | 40 ++++++++++++++++++++++++---------
|
||||
2 files changed, 32 insertions(+), 10 deletions(-)
|
||||
|
||||
diff --git a/klish/ksession/ksession_parse.c b/klish/ksession/ksession_parse.c
|
||||
index 9f1fece..eb015fb 100644
|
||||
--- a/klish/ksession/ksession_parse.c
|
||||
+++ b/klish/ksession/ksession_parse.c
|
||||
@@ -620,6 +620,8 @@ kexec_t *ksession_parse_for_local_exec(ksession_t *session,
|
||||
kcontext_set_parent_pargv(context, parent_pargv);
|
||||
// Service ACTIONs like PTYPE, CONDitions etc. doesn't need session
|
||||
// data within context. Else it will be able to change path.
|
||||
+ /* KernelKit override for %w patch to klish_prompt() */
|
||||
+ kcontext_set_session(context, session);
|
||||
kexec_add_contexts(exec, context);
|
||||
|
||||
faux_argv_free(argv);
|
||||
diff --git a/plugins/klish/misc.c b/plugins/klish/misc.c
|
||||
index 659c0df..8237002 100644
|
||||
--- a/plugins/klish/misc.c
|
||||
+++ b/plugins/klish/misc.c
|
||||
@@ -75,21 +75,37 @@ int klish_print(kcontext_t *context)
|
||||
return 0;
|
||||
}
|
||||
|
||||
-
|
||||
-// Symbol to show current path
|
||||
-int klish_pwd(kcontext_t *context)
|
||||
+static char *cwd(kcontext_t *context)
|
||||
{
|
||||
- kpath_t *path = NULL;
|
||||
- kpath_levels_node_t *iter = NULL;
|
||||
- klevel_t *level = NULL;
|
||||
+ kpath_levels_node_t *iter;
|
||||
+ static char buf[256];
|
||||
+ ksession_t *session;
|
||||
+ klevel_t *level;
|
||||
+ size_t len;
|
||||
|
||||
- path = ksession_path(kcontext_session(context));
|
||||
- iter = kpath_iter(path);
|
||||
+ len = sizeof(buf);
|
||||
+ memset(buf, 0, len);
|
||||
+
|
||||
+ session = kcontext_session(context);
|
||||
+ if (!session)
|
||||
+ return NULL;
|
||||
+
|
||||
+ iter = kpath_iter(ksession_path(session));
|
||||
while ((level = kpath_each(&iter))) {
|
||||
- printf("/%s", kentry_name(klevel_entry(level)));
|
||||
+ const char *nm = kentry_name(klevel_entry(level));
|
||||
+
|
||||
+ strncat(buf, "/", len--);
|
||||
+ strncat(buf, nm, len);
|
||||
+ len -= strlen(nm);
|
||||
}
|
||||
- printf("\n");
|
||||
|
||||
+ return buf;
|
||||
+}
|
||||
+
|
||||
+// Symbol to show current path
|
||||
+int klish_pwd(kcontext_t *context)
|
||||
+{
|
||||
+ printf("%s\n", cwd(context));
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -138,6 +154,10 @@ int klish_prompt(kcontext_t *context)
|
||||
faux_str_free(user);
|
||||
break;
|
||||
}
|
||||
+ // Workdir (pwd)
|
||||
+ case 'w':
|
||||
+ faux_str_cat(&prompt, cwd(context));
|
||||
+ break;
|
||||
}
|
||||
is_macro = BOOL_FALSE;
|
||||
start = pos + 1;
|
||||
--
|
||||
2.34.1
|
||||
|
||||
@@ -98,7 +98,7 @@
|
||||
<HOTKEY key="^D" cmd="exit"/>
|
||||
|
||||
<PROMPT>
|
||||
<ACTION sym="prompt" exec_on="always">%u@%h:exec> </ACTION>
|
||||
<ACTION sym="prompt" exec_on="always">%u@%h:/> </ACTION>
|
||||
</PROMPT>
|
||||
|
||||
<COMMAND name="help" help="Help system (also try '?' key)">
|
||||
@@ -135,7 +135,7 @@
|
||||
</COMMAND>
|
||||
|
||||
<COMMAND name="configure" help="Create new candidate-config based on running-config">
|
||||
<ACTION sym="nav">replace configure</ACTION>
|
||||
<ACTION sym="nav">replace config</ACTION>
|
||||
</COMMAND>
|
||||
|
||||
<COMMAND name="copy" help="Copy">
|
||||
@@ -285,11 +285,11 @@
|
||||
|
||||
</VIEW>
|
||||
|
||||
<VIEW name="configure">
|
||||
<VIEW name="config">
|
||||
|
||||
<PROMPT>
|
||||
<ACTION sym="srp_prompt_edit_path@sysrepo"/>
|
||||
<ACTION sym="prompt" exec_on="always">%u@%h:configure> </ACTION>
|
||||
<ACTION sym="prompt">%u@%h:%w</ACTION>
|
||||
<ACTION sym="srp_prompt@sysrepo">%w/> </ACTION>
|
||||
</PROMPT>
|
||||
|
||||
<HOTKEY key="^D" cmd="exit"/>
|
||||
@@ -304,6 +304,7 @@
|
||||
|
||||
<COMMAND name="leave" help="Apply candidate to running-config and return to admin-exec">
|
||||
<ACTION sym="klix_commit@klinfix"/>
|
||||
<ACTION sym="srp_top@sysrepo"/>
|
||||
<ACTION sym="nav" exec_on="success">replace main</ACTION>
|
||||
</COMMAND>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user