Code covered by the BSD License  

Highlights from
setPrompt - Set the Command Window prompt

5.0

5.0 | 5 ratings Rate this file 6 Downloads (last 30 days) File Size: 4.59 KB File ID: #26471
image thumbnail

setPrompt - Set the Command Window prompt

by Yair Altman

 

24 Jan 2010 (Updated 29 Jan 2010)

Sets the Command Window prompt to the specified string

| Watch this File

File Information
Description

setPrompt(newPrompt) sets the Command Window prompt to the specified NEWPROMPT.

NEWPROMPT can be one of the following:
 
       - a static string: setPrompt('>> ')
              => this is the default prompt string ('>> ')
 
       - an evaluable string: setPrompt('datestr(now)')
              => the new prompt will look like: '25-Jan-2010 01:00:51'
              Note: the evaluable string is expected to return a string
 
       - an evaluable function: setPrompt(@()(['[',datestr(now),'] ']))
              => the new prompt will look like: '[25-Jan-2010 01:00:51] '
              Note: the evaluable function is expected to return a string
 
       - the static string 'timestamp' will continuously update the last (current)
         prompt with the current time: '[25-Jan-2010 01:00:51] '. This has
         the effect of displaying desktop command execution times.
         The 'timestamp' string can be used with other static text to
         customize its appearance. For example: setPrompt('<timestamp!> ').

       - an empty value or no input argument restores the default prompt
 
Examples:
     setPrompt('[-]') % Replaces '>> ' prompt with '[-]'
     setPrompt('%') % => '% ' (space-padded)
     setPrompt('sprintf(''<%f>'',now)') % => '<734163.056262>'
     setPrompt('datestr(now)') % => '25-Jan-2010 01:00:51' (unchanging)
     setPrompt('[''['',datestr(now),''] '']') % => '[25-Jan-2010 01:00:51] '
     setPrompt(@()(['[',datestr(now),'] '])) % => '[25-Jan-2010 01:00:51] '
         (note that these are the same: the first uses an evaluable string,
          while the second uses an evaluable function)
     setPrompt('timestamp') % => '[25-Jan-2010 01:00:51] ' (continuously-updated)
     setPrompt('<timestamp> ') % => '<25-Jan-2010 01:00:51> ' (continuously-updated)
     setPrompt('>> ') % restores the default prompt
     setPrompt('') % restores the default prompt
     setPrompt % restores the default prompt
 
Warning:
     This code heavily relies on undocumented and unsupported Matlab functionality. It works on Matlab 7+, but use at your own risk!
 
Technical explanation:
     A technical explanation of the code in this utility can be found on http://undocumentedmatlab.com/blog/setprompt-setting-matlab-desktop-prompt/
 
Bugs and suggestions:
     Please send to Yair Altman (altmany at gmail dot com)

Acknowledgements

The author wishes to acknowledge the following in the creation of this submission:
cprintf - display formatted colored text in the Command Window

MATLAB release MATLAB 7.6 (R2008a)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (9)
25 Jan 2010 Ragaar Ashnod  
26 Jan 2010 Aurelien Queffurust

I thought that it was impossible to modify this "core" feature. tested successfully under R2010a Prerelease. Great job Yair!

26 Jan 2010 Jan Simon

I cannot get the link to the blog on undocumentedmatlab to run (-> 404 error).
Is there a statement from TMW, if removing "EDU" from the prompt conclicts with the license conditions? See: http://www.mathworks.com/support/solutions/en/data/1-16N4J/index.html?solution=1-16N4J
If it is legal, I love it.

26 Jan 2010 Yair Altman

oops - temporary problem with the webpage (now fixed)...

I don't know the legal status of removing the EDU from the prompt. Since this is the first time anyone has been able to modify the prompt, I think the question has never before arisen.

27 Jan 2010 Yair Altman

*** Mac users ***
Please note that I have received information that setPrompt causes problems on MacOS. It appears to work ok on non-Mac platforms though (inc. Windows)

27 Jan 2010 John D'Errico

I would only add (as one of the people who reported a Mac problem) that I saw the problem in release R2007b, on an old mac with probably an old copy of Java. For the rest of you, rest assured that this appears to be a well written, well documented, professional piece of code.

01 Feb 2010 Jean-Guilhem Dalissier

Thank you very much Yair, your new version works perfectly. Tested successfully on R2008b and R2007b. Work also perfectly on R14SP3 adding a “try, if ismac … end”.

11 Jan 2011 Andy

I have a student edition of ML R2010a on Windows 7. It comes with the default prompt 'EDU>>', which I wanted to change back to the familiar '>>'. setPrompt worked, but it leaves too much space (copied and pasted):

EDU>> setPrompt('>>');
>> see how much space there is?

I would have preferred:

EDU>> setPrompt('>>');
>> only one space before text

Still, great stuff. Thanks, Yair!

19 Feb 2011 Kenneth Eaton

Very nice! The only problem I had when trying to run it on R2010b was this warning message:

Warning: Possible deprecated use of set on a Java callback.
> In setPrompt at 115

Which I suppressed by doing the following:

warning('off','MATLAB:hg:JavaSetHGProperty');

Please login to add a comment or rating.
Updates
26 Jan 2010

Fixed a few edge cases (some inspired by J. Raymond); added continuously-updated timestamp option

29 Jan 2010

Fixed a few edge-cases (some reported by J.G. Dalissier) with '>> ' terminated prompts; fixed a few problems with continuous timestamps; enabled customizing continuous timestamp prompts; added Mac warning

Tag Activity for this File
Tag Applied By Date/Time
desktop Yair Altman 25 Jan 2010 10:19:39
command window Yair Altman 25 Jan 2010 10:19:39
undocumented Yair Altman 25 Jan 2010 10:19:39
java Yair Altman 26 Jan 2010 13:40:03

Contact us at files@mathworks.com