Wednesday, August 31, 2005

A prompt that does not get in the way

Yesterday, I saw a screenshot of a developer's box. His prompt was composed of two characters only: a colon and a semicolon (:;). This looks wired, doesn't it? Yes, it does, but there is a rationale behind it: using this prompt, you can copy and paste complete lines from a terminal into another one and they will just work. Why? Because those characters are ignored by the shell (the colon returns success and the semicolon starts another command).

Oh yes, this prompt does not provide useful information, but that's a matter of preference. E.g., I used a simple $ prompt for a long while, so :; is not any worse than it.

3 comments:

Anonymous said...

[Originally posted at 2005-08-31 02:42 pm UTC]

If you want to add more information, simply put a space after the colon and before the additional. For example, my prompt looks like:

: hostname;

(I also like a trailing space afterwards)

Anonymous said...

[Originally posted at 2005-09-02 04:18 am UTC]

doesn't work for some forms of command unless the individual lines are 'complete'

try for i in * vs for i in * do
the first one, you can put 'do' on one line and its fine for YOU interactively, but the prompt causes a syntactic error since the for i in * cannot have a comment before the do. (I just tried this cut/paste on bash on linux)

so you need to know ALL the forms of command which in shell interactive input accept '\n broken lines' which are not legal with an embedded comment. Once you know that, yes, this is indeed useful.

clearly therefore, its not 'fully' portable (yet)

-George

Anonymous said...

[Originally posted at 2005-09-02 04:20 am UTC]

sorry I meant for i in *; do vs for i in *\n:;do

-G