<div dir="ltr">Thanks for posting this Nick!<div>I've been wanting to enhance my prompts and this is just what I needed..</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Dec 28, 2022 at 11:10 PM Nick Holland <<a href="mailto:nick@holland-consulting.net">nick@holland-consulting.net</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">I tripped across an idea recently which I'm not sure if<br>
it is brilliant or evil.  But I kinda like it.<br>
<br>
Standard unix shell prompt is a $ or # (or a number of<br>
other things, if you like unusual shells).  Every operating<br>
system I've used in the last 40 years has some kind of<br>
prompt...but that's not exactly a requirement.  And most of<br>
us start cramming other info into the prompt, for example,<br>
my standard prompt has grown to three lines -- a blank line,<br>
username@hostname, then the full path and the $ or #.<br>
<br>
    <this line intentionally left blank for spacing><br>
<a href="mailto:nick@dbu1.in.nickh.org" target="_blank">nick@dbu1.in.nickh.org</a><br>
/bu/hc1/2022-12-24/archive #<br>
<br>
(and yes, I get it, a lot of people think my multi-line<br>
command prompts are evil enough already.  If you are in<br>
that camp, you might want to stop reading, or even better,<br>
delete this message now before going on.)<br>
<br>
(you were warned)<br>
<br>
The suggestion was...put a newline at the end of your PS1<br>
prompt, so that when you copy and paste to re-run a command<br>
(or run it in another window), you don't have to un-select<br>
the $ or # (and everything else you put in).<br>
<br>
Huh.  So a command line might look like this:<br>
<br>
<a href="mailto:nick@dbu1.in.nickh.org" target="_blank">nick@dbu1.in.nickh.org</a> /bu/hc1/2022-12-24/archive #<br>
<type your command here><br>
<br>
Well, I don't recall if the rest was in the original source<br>
of the message or if I came up with the rest myself...<br>
<br>
Make the first character of the prompt line a #, so when<br>
you copy and paste, the username and stuff is a comment.<br>
But then you have to do the same for the PS2 (continuation<br>
prompt).  Ok, so I did.  But I didn't like having a "#" at<br>
the beginning of every command line, because that makes it<br>
look like I'm running as root...so (whoa. slippery slope<br>
here) use a few color changes to make the "#" the<br>
terminal background color.  Ok, so now I have a multi-line<br>
multi-color PS1 with nothing in front of the command I'm<br>
typing.  I warned you.<br>
<br>
So now, I have something like this:<br>
  export PS1='\n'$(tput setf 7)#$(tput setf 0)'\$\$\$ \u @ \h \w \$\n'<br>
  export PS2="$(tput setf 7)#$(tput setf 0)>\n"<br>
<br>
So now, if I cobble together a few lines that I might wish<br>
to run again via copy/paste or even put into a shell script,<br>
it might look like this:<br>
<br>
     #$$$ nick @ hc1 ~ $<br>
     PS3="Pick a motorcycle -> "<br>
<br>
     #$$$ nick @ hc1 ~ $<br>
     select M in FLTC K1200LT K100RT BuellBlast; do<br>
     #><br>
     echo $M<br>
     #><br>
     done<br>
     1) FLTC<br>
     2) K1200LT<br>
     3) K100RT<br>
     4) BuellBlast<br>
     Pick a motorcycle -> 3<br>
     K100RT<br>
     Pick a motorcycle -> ^C<br>
<br>
     #$$$ nick @ hc1 ~ $<br>
<br>
except...the leading "#" are mostly greyed out and ALMOST<br>
indistinguishable from the background.<br>
<br>
And now, if I want to re-run this, I can copy and paste the<br>
entire block -- including the prompt lines! -- again and re-run<br>
it or run it somewhere else, or even copy and paste into a<br>
script, then just delete out the prompt lines (dd is quicker than<br>
moving to the right spot and deleting characters)<br>
<br>
Oh, btw.  the ksh/bash "select" command is way cool. But that's<br>
a different topic.  I just stuck it in here because, well, I could.<br>
<br>
Explanation of the prompt commands:<br>
  export PS1='\n'$(tput setf 7)#$(tput setf 0)'\$\$\$ \u @ \h \w \$\n'<br>
  export PS2="$(tput setf 7)#$(tput setf 0)>\n"<br>
<br>
"export" because we want this variable to impact everything<br>
invoked by this shell, not just this shell.<br>
PS1 is the default "Enter your command here" prompt.<br>
    '\n' -- literal newline<br>
    $(tput setf 7) -- set the font color to 7 (grey, on my white background)<br>
       (execute the tput command with those options, embeds an esc sequence)<br>
    #  -- make this line a "comment" if copied and pasted and re-run (but grey!)<br>
    $(tput setf 0) -- set font color back to 0 (black)<br>
    '\$\$\$' -- either $ for normal user or # for root.  Repeated because, well,<br>
        I don't want to take that # as a "you are running as root" here.<br>
    \u -- username<br>
    @ -- literal @ symbol.  Spaces around it because I don't want it look like e-mail.<br>
    \n -- hostname<br>
    \w -- working directory<br>
    \$ -- because the three earlier $ or # weren't enough.<br>
<br>
PS2 is the continuation prompt, and PS3 is the prompt used by select.<br>
Some things are surrounded by single quotes to keep them unexpanded,<br>
other things like the PS2, are expanded and stored as escape sequences<br>
rather than running tput every time a PS2 prompt is displayed.<br>
<br>
Enjoy. Or don't.  Honestly, I'm not sure if I like this yet, but I<br>
think I do.  Figured I'd share this idea...<br>
<br>
Tested on OpenBSD ksh (pdksh) and linux bash.<br>
<br>
Nick.<br>
<br>
_______________________________________________<br>
Semibug mailing list<br>
<a href="mailto:Semibug@lists.nycbug.org" target="_blank">Semibug@lists.nycbug.org</a><br>
<a href="https://lists.nycbug.org:8443/mailman/listinfo/semibug" rel="noreferrer" target="_blank">https://lists.nycbug.org:8443/mailman/listinfo/semibug</a><br>
</blockquote></div>