Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to define a custom prompt in JShell from a script?

Tags:

jshell

I am trying to create a custom JShell prompt and want to load it from a file directly.

But it is not showing the custom prompt when loading the set prompt from a file, but I am able to do it writing the same commands on JShell.

Ex: I have a file 'jshell_prompt_file' contains these 3 lines to set the prompt:

/set mode genspice -quiet
/set prompt genspice "GetNetConnectivity > " "--------> "
/set feedback genspice

When I load the file while invoking JShell, it does not change the prompt.

1:31am [login1] ~/JSHELL 1023:-)jshell jshell_prompt_file
|  Welcome to JShell -- Version 13.0.2
|  For an introduction type: /help intro

jshell> 

But when I copy-paste the same command to set feedback, then it changes it

2:53am [login1] ~/JSHELL 1034:-)jshell jshell_prompt_file
|  Welcome to JShell -- Version 13.0.2
|  For an introduction type: /help intro

jshell> /set feedback genspice

GetNetConnectivity > 

Can someone help me to achieve this without the user have to type it on command prompt? I want the first prompt to be the custom prompt.

like image 859
Nitin Jindal Avatar asked Nov 22 '25 15:11

Nitin Jindal


1 Answers

The feedback mode need to be set with a specific JShell command line option : --feedback.

In your file jshell_prompt_file keep only the first two lines:

/set mode genspice -quiet
/set prompt genspice "GetNetConnectivity > " "--------> "

and run JShell with:

jshell jshell_prompt_file --feedback genspice
like image 134
Ortomala Lokni Avatar answered Nov 24 '25 23:11

Ortomala Lokni



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!