h3rald / min

A small but practical concatenative programming language and shell
https://min-lang.org
MIT License
310 stars 23 forks source link

Nube Question: Change prompt for windows #187

Closed Gavin-Holt closed 1 year ago

Gavin-Holt commented 1 year ago

Hi

I am keen to play with min, but I am failing at my first hurdle.

This will be my second programming language after Lua - I'm not an IT professional.

As a long time DOS user, I find the shell prompt unappealing. The documentation says it is unsealed and can be changed, but can't seem to find the right code.

My current prompt (it's the newline I really don't like):

min shell v0.37.0
[O:/MyDownloads]
$ 1 2 +
 3
[O:/MyDownloads]
$

My desired prompt (similar to DOS):

min shell v0.37.0
O:/MyDownloads>1 2 +
 3
O:/MyDownloads>

If I execute, prompt then it returns a string:

min shell v0.37.0
[O:/MyDownloads]
$ prompt
 "[O:/MyDownloads]\n$ "
[O:/MyDownloads]
$

I tried to reset the prompt by placing a quotation on the stack (from reference-lang):

min shell v0.37.0
[O:/MyDownloads]
$ ("[$1]$$ " (.) => %) prompt
 "[O:/MyDownloads]\n$ "
[O:/MyDownloads]
$

I guess this is not the right way to change the prompt.

Any help gratefully received.

Kind Regards Gavin Holt

Gavin-Holt commented 1 year ago

Hi

After reading on Rosetta Code :

((.) ">") => "" join :prompt

But this does not change when I move directories :(

I am betting there is a way to delay execution by passing a function?

Kind Regards Gavin Holt

h3rald commented 1 year ago

Nearly there!

I believe this would work for you:

("[$1]> " (.) => %) :prompt

Basically yes, in this case we are using the interpolation symbol (%) to execute a quotation containing the current directory symbol (.).

Also, if you put the above line in your .minrc file in your home directory (see docs) it will reset the default prompt every time you start min 😊

Gavin-Holt commented 1 year ago

Hi,

Sorry I must be doing something wrong as I am getting a fatal error:

C:\Windows>ver

Microsoft Windows [Version 10.0.19042.1826]

C:\Windows>min.exe

min shell v0.37.0
[C:/Windows]
$ ("[$1]> " (.) => % ) :prompt
parser.nim(136)          raiseInvalid
Error: unhandled exception: Quotation is not a quoted symbol [MinInvalidError:ObjectType]

I have trialled using this code separately in the REPL, in my prelude file (-p switch) and in C:\Users\gavin.holt\.minrc with no luck.

Kind Regards Gavin

h3rald commented 1 year ago

Oops! You are right... wrong sigil, the prompt symbol must be set to a quotation so it's necessary to use the lambda sigil (^) instead of define (:)... try this:

("[$1]> " (.) => % ) ^prompt
Gavin-Holt commented 1 year ago

Hi

Perfect, many thanks.

Kind Regards Gavin Holt