From 3efa5838303865ceee47b5e7cb3189bff7c73e4a Mon Sep 17 00:00:00 2001 From: zhongwencool Date: Sun, 30 Jan 2022 14:57:14 +0800 Subject: [PATCH] feat(shell): add emqx version to prompt. --- apps/emqx_machine/src/emqx_machine_app.erl | 1 + apps/emqx_machine/src/emqx_restricted_shell.erl | 12 ++++++++++++ apps/emqx_machine/src/user_default.erl | 1 - 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/apps/emqx_machine/src/emqx_machine_app.erl b/apps/emqx_machine/src/emqx_machine_app.erl index 9e96ea234..bae1cecdf 100644 --- a/apps/emqx_machine/src/emqx_machine_app.erl +++ b/apps/emqx_machine/src/emqx_machine_app.erl @@ -24,6 +24,7 @@ start(_Type, _Args) -> ok = emqx_machine:start(), + emqx_restricted_shell:set_prompt_func(), emqx_machine_sup:start_link(). stop(_State) -> diff --git a/apps/emqx_machine/src/emqx_restricted_shell.erl b/apps/emqx_machine/src/emqx_restricted_shell.erl index f0bcf3424..f45f880a7 100644 --- a/apps/emqx_machine/src/emqx_restricted_shell.erl +++ b/apps/emqx_machine/src/emqx_restricted_shell.erl @@ -17,6 +17,7 @@ -module(emqx_restricted_shell). -export([local_allowed/3, non_local_allowed/3]). +-export([set_prompt_func/0, prompt_func/1]). -export([lock/0, unlock/0, is_locked/0]). -include_lib("emqx/include/logger.hrl"). @@ -38,6 +39,17 @@ is_locked() -> lock() -> application:set_env(?APP, ?IS_LOCKED, true). unlock() -> application:set_env(?APP, ?IS_LOCKED, false). +set_prompt_func() -> + shell:prompt_func({?MODULE, prompt_func}). + +prompt_func(PropList) -> + Line = proplists:get_value(history, PropList, 1), + Version = emqx_release:version(), + case is_alive() of + true -> io_lib:format(<<"~ts(~s)~w> ">>, [Version, node(), Line]); + false -> io_lib:format(<<"~ts ~w> ">>, [Version, Line]) + end. + local_allowed(MF, Args, State) -> IsAllowed = is_allowed(MF, ?LOCAL_NOT_ALLOWED), log(IsAllowed, MF, Args), diff --git a/apps/emqx_machine/src/user_default.erl b/apps/emqx_machine/src/user_default.erl index 0071db837..86ed5adb6 100644 --- a/apps/emqx_machine/src/user_default.erl +++ b/apps/emqx_machine/src/user_default.erl @@ -20,7 +20,6 @@ -include_lib("emqx/include/emqx_mqtt.hrl"). -include_lib("emqx_conf/include/emqx_conf.hrl"). -include_lib("emqx_dashboard/include/emqx_dashboard.hrl"). --include_lib("emqx_slow_subs/include/emqx_slow_subs.hrl"). %% API -export([lock/0, unlock/0]).