Solved Weird prompt behaviour


OK, let's manually decode this:
%{ begin literal escape sequence
\033[32m change color to number 2 (too lazy to look up the exact color)
%} end literal escape sequence
%B start boldface ***A
[ a literal opening square bracket
%n the user name
@ a literal at sign
%{ begin literal escape sequence
\033[33m change color to number 3
%} end literal escape sequence
%m the host name (short version)
%{ begin literal escape sequence
\033[33m change color to number 3 again ***B
%} end literal escape sequence
] a literal closing square bracket
%b end bold face ***C
%{ begin literal escape sequence
\033\0m change color and bold back to normal
%} end literal escape sequence
%/ the current working directory
a space
# a literal pound sign ***D
a space

Here are my comments on this (they are marked with *** above):

A: You are changing to bold face here, but you already changed the color earlier. In reality, what "start bold face" really does is nothing but send an ANSI escape sequence to the terminal (it is "\033[1m"). So if you think at the series of escape sequences that is sent to the terminal, it gets confusing: \033[32m\033[1m\033[33m ... and so on. You can do that more efficiently yourself by taking control of the boldface in your own escape sequences, and send this sequence: "\033[1;32m", which means "begin bold face and color number 2".

B: You change to color number 3 twice in a row. The second one is redundant.

C: Ah, here lie dragons! You are now asking to end bold face. That is usually implemented by sending the sequence "\033[0m", which turns *ALL* special rendition off, and changes the color back to normal. Fortunately, you also manually do the same thing a moment later. This is either wrong or redundant: it would be wrong if you had anything after ***C and before turning the color off, but you don't; so it is only redundant.

All three of these comments can be taken care of if you simply take over the boldface yourself. Do a wikipedia search for "ANSI escape code", and read the page, it explains very clearly how this all works (I think I helped edit it a few years ago).

D: You are using a pound sign for both normal users and root. Here is a trick I like to use: Instead of "#", use "%#: That gives you a pound sign for root, but ">" for normal users. Like this you immediately know whether you're logged in as root.

Today that part of the prompt has vanished entirely..

.View attachment 4621

What's going on, I wonder? Multiple glitches in the Matrix?
You said you had been messing with network settings. You probably changed the host name of the machine. You can look that up with the "hostname" command. It is even possible for a machine to temporarily have no hostname.
 
Why do you link to your own thread without even asking something?
Reason to start a new thread should be a (new) question...

The new question was implicit in the Thread name "Weird prompt behaviour". The question emerged as a by-product of another thread and deserved a bit more emphasis. Linking to it was the most efficient way I could think of avoiding cross-posting. I didn't want to upset anybody's sense of forum etiquette. That clearly didn't work out then, did it?
 
OK, let's manually decode this:

Wow! Thanks for the detailed analysis! In my defence, I copied the script from someone else, but I will study your comments and see if I can learn something. I'm going to have a bite to eat first, though. I can't learn on an empty stomach!

As I point out at the end of the thread, the problem disappeared as mysteriously as it appeared. I didn't do anything that involved explicitly changing the host name of the machine, so it must have been the by-product of some other change.

As soon I get my internet connection working in my FreeBSD, I'm going to switch to zsh as a shell, so I will be revisiting the whole question of prompts in any case.

Thanks again, there's a lot of useful-looking wisdom there!
 
The good news: You tried to learn by "monkey see monkey do". The nice thing about having a computer that you can play with is that you can learn from playing, without fear of breaking something. Because if you break it, you get to learn from fixing it.

The bad news is that you did "cargo cult programming": If you just copy this line that you don't understand, then it might just not work, and you don't know why. Just like a cargo cult doesn't cause cargo planes to show up spontaneously.

The good news: You will now learn how this really works; and the transition to a new shell (which I personally don't happen to like, but my taste in shells shouldn't prevent you from trying it) will be a good opportunity for you to adjust the prompt to your liking, and get it "perfect" in the process.
 
The bad news is that you did "cargo cult programming": If you just copy this line that you don't understand, then it might just not work, and you don't know why. Just like a cargo cult doesn't cause cargo planes to show up spontaneously.

When it comes to "proper coding" I am quite old-school and fully agree with you - I've always prefered to work from first principles and eschew "cargo cult programming". The problem is that I come from a DOS and Windows background (over 25 years) so batch programming was never very challenging. I switched to an Apple Mac almost a year ago and started to delve into the FreeBSD-like macOS and into various flavours of Linux before plunging into the world of the genuine FreeBSD just a week ago. Consequently, I'm more inclined to seek off the shelf solutions for OS type problems, whereas I need to educate myself to invest the proper amount of effort into what is clearly a far more sophisticated and involved problem-space.
 
You said you had been messing with network settings. You probably changed the host name of the machine. You can look that up with the "hostname" command. It is even possible for a machine to temporarily have no hostname.

Okay since my last post, at which point the hostname and therefore the prompt had been restored, the hostname and therefore the prompt have disappeared again. I haven't changed anything. I have been cooking and eating over the last two 2 hours! I've hardly touched the computer at all except to read some emails and tweets in macOS.

What on earth can be going on? (That's more of a rhetorical flourish rather than an angry question aimed at you!)
 
I've attempted to fix the symptoms of the problem at by specifying hostname="FreeBSD" in my /etc/rc.conf. It's working for the moment. We'll see how long it lasts!
 
Back
Top