Files
hpr-knowledge-base/hpr_transcripts/hpr2349.txt
Lee Hanken 7c8efd2228 Initial commit: HPR Knowledge Base MCP Server
- MCP server with stdio transport for local use
- Search episodes, transcripts, hosts, and series
- 4,511 episodes with metadata and transcripts
- Data loader with in-memory JSON storage

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-26 10:54:13 +00:00

226 lines
19 KiB
Plaintext

Episode: 2349
Title: HPR2349: Customizing my bash prompt
Source: https://hub.hackerpublicradio.org/ccdn.php?filename=/eps/hpr2349/hpr2349.mp3
Transcribed: 2025-10-19 01:34:56
---
This is HBR episode 2,349 entitled Customizing My Mash Prompt and is part of the series Mash
Crypting.
It is hosted by Windigo and is about 24 minutes long and can remain an explicit flag.
The summary is a detailed look into how and why to Customizing My Mash Prompt.
This episode of HBR is brought to you by An Honest Host.com.
At 15% discount on all shared hosting with the offer code HBR15, that's HBR15.
Better web hosting that's Honest and Fair at An Honest Host.com.
Good evening Hacker Public Radio.
This is Windigo and I come to you filled with regret.
This is 2017 already and I haven't done anything, I haven't done a single episode so I'd
like to remedy that with an episode about my custom stylized mash prompt.
I tend to get over invested in user configs and the appearance of things so my mash prompt
has been a multi-year process of elimination and trial and error and I've finally got
it to do what I want and look kind of cool so I figured it's a time for an episode.
So first of all I should explain what I mean by mash prompt in case you're not a console
user, you don't like terminals, bash prompt, bash being the program I use to run my
command line so bash is what when you see a terminal open it's usually running bash.
There's other options but I use bash because it comes standard on most everything.
And the prompt is a little sequence of characters that are in front of where you type in the
commands.
So on old DOS machines it was the C prompt because it would have a C usually for the drive
that you're on, C a colon and a slash I think, maybe an arrow, I don't know, it's been
a while, but bash has its own prompt, very, very configurable and on Debian my default,
the main prompt starts out as your username, the at symbol as just a separator, then the
host name of the computer you're on, so the name of the machine whether you're remotely
connected or you're on your local machine and then a dollar sign and the dollar sign
changes to a Octo Thorpe or a hash if you are root and that's about it.
There's some other things that can happen based on if you're in a true root environment
and some other stuff but I'd never really gotten into that so I don't know how to explain
that very well.
I was going to skip right over it besides I blew that all away when I made my own custom
prompt anyways, so none of that will actually happen if I do it.
Yeah so buyer beware if you use some of the features that I don't support in this prompt.
So anyways I customized my prompt to fit my method of working on the command line.
I have a pretty minimal prompt in appearance at least at the beginning, we'll get into
that later.
So I try to keep it pretty simple, it conveys information using colors if possible.
So I have parts of my prompt that change color depending on what's going on on my system
and I only try and show relevant stuff.
So I've started with the basic Debian prompt, decided that I like the username and host
name and have built from there but I don't put a lot of stuff.
You can put anything that you can convert to text, you can put in a bash prompt, you
can use Unicode characters, you can throw in any type of information, there are people
that dump entire conkey scripts into something like a bash prompt but not something I'm interested
in.
So just to get or cover the basics of bash prompts in general, first of all you have to
be using bash, it's available for just about everything now I think, you can even install
it on Windows through their compatibility Ubuntu layer thing but once you're running it
there are a couple files and variables you're going to need to know about.
First one is your .bashrc file, that's your bash configuration, your personal users configuration
and all of the settings that I'm going to be talking about get set in there.
That also means that if you switch users, so if you do a interactive pseudo, like a pseudo
dash i and log in as root or log in as your brother Herman or someone like that, they're
going to have a different configuration file so you can either simlink your configuration
file to theirs or you can set your configurations up at the system level and I think it's slash
ETC slash bashrc maybe, I don't know, I don't do things that way so I tend not to mess
around with the system level configurations but unless you do that they're going to have
their own custom bash prompt, most likely the system default if they're not terminal
users so if you want to edit things or follow along you can open up your .bashrc file which
is in your home directory so mine is slash home slash window go slash .period bashrc no spaces
no underscores all lowercase and that's where all this configuration gets stored that file
gets run or read by bash every time you launch it so every time you open a terminal every
time you SSH into a computer and it runs a command line for you that file gets interpreted
by bash and that's where it gets all its settings and the variables we'll be dealing
with there's three of them are starting with the biggest one PS1 so that's a capital
P where's my phonetic alphabet I should re-list into that episode.
Papa?
Yeah capital papa capital Sierra so PS and the numeral one and that is your bash prompt
really in a nutshell that's that's the whole thing everything that appears on your
prompt is in that variable more or less there's a PS2 as well so papa Sierra and then the
numeral two and that doesn't show up much that's called the continuation prompt I believe
and what that does is that only gets displayed if you have a multi level command or you're
in the middle of a set of quotes and you hit a new line so if you type in echo single
quotes hello and then return or an enter it adds a new line but because you're in those
single quotes bash doesn't execute that they give you this continuation prompt and lets
you continue on that string until you end it with another set of single quotes so you
can customize the appearance of that second prompt as well and I do I just set it to another
character that matches my main prompt but it doesn't get used much you can leave it at
the system default and and you'll be just fine the third variable is prompt underscore
command that's I'm not even going to bother spelling that out in phonetic alphabet if you'd
like to use that and don't understand what I'm saying I'll have it in the show note somewhere
I'm sure and that variable contains something that is executed every time the prompt is we'll
get into that a little bit later but your PS1 variable is kind of static it's just a string
that gets set it can contain some characters that will that will get reinterpreted each time
but mostly it's just a static string so if you want something to happen every time you run
your prompt you can assign it to this prompt command and that gets evaluated every time
so like I said I use colors to convey a lot of information in my prompt there's a very
heated debate I'm sure going on somewhere about whether bash prompts and terminals in general
should be monochrome or color doesn't matter to me I like colors I use them quite a bit so I'm
going to describe how to use colors in your bash prompt or in bash in general colors are a
series of characters using what are called escape sequences so when your terminal encounters a
certain set of characters in a row it knows that that's a special code to set a color for the
rest of the text after it so you might see these as a backslash they always start with backslash
because they need to be escaped escape sequences they start with backslash and then there's
a set of square brackets surrounding the whole thing and then often there are just numbers and
letters little hex numbers but I don't use those because those get confusing I use a program called
teapot teapot teapot that uses the term info database and I don't understand that a whole bunch
so I'm going to leave it there the teapot generates colors for me I send it in a number
and a quick command and it sets all my colors up for me it's fantastic there's another sequence you
can send it that resets to your default colors which is handy as well and I just have that at the
end of my ps1 variable so that I can use normal terminal commands and they don't get
set to whatever weirdo color I was using last so teapot's very important it requires that at the
very beginning of your bash prompt excuse me the very beginning of your bash RC file you have
a call to teapot that initializes it so the command is teapot tpu t then a space and then in it
i and i t to get the term info or whatever it does in the background unless you use or let you use
teapot to set your colors so the problem with these colors and escape sequences in particular
especially while you're doing prompts is that they can only be escaped once or else all
hell breaks loose if you escape your color codes more than once you end up with raw color codes
just showing up in your terminal or even better you run into problems where some of it will be
escaped but bash does not know how to count the length of your prompt anymore because there's
invisible weirdo control characters floating around so you'll have problems where if you backspace
on your command line it only goes so far and there's leftover characters and it just it messes
lots of stuff up you'll get wacky unicode characters showing up your prompt will not understand
how long it is so it will start to overwrite itself while you're typing and you can't see what's
what you've previously typed but it's there and it affects things it's oh my goodness it's a mess
don't don't do it if you can avoid it so you have to assign your colors in a very specific way i
usually put them right into the ps1 variable i don't i experimented using functions like the
fish shell uses to create your prompt ad hoc and the escaping just destroyed everything not you
not worth it so yeah the the only way i've gotten colors to work and work reliably is to assign
them directly to the ps1 variable which i'll get to a little bit later with escaped brackets around
so i'll have and i use the teapot call so i'll so what i'll do is i'll start with a backslash
and then a left square bracket and then i'll call teapot right in the middle of the string so
i use dollar sign in then normal parentheses to get the value that teapot returns and embed it
right in that string and then i have a backspace or excuse me a backslash and then another square
bracket and that gives me the right color code in the right place escaped once i've had a lot
of problems doing it every other way i've tried so i'd recommend just putting the the colors at
the very top variable level which causes some complications but it works the best i found
also because your ps1 variable is kind of static and doesn't change
it's hard but not impossible to embed system information that changes all the time
for instance i have a mail indicator embedded in my prompt so that if i have system mail
my username turns red and the way i do that is i actually embed an if statement in my prompt
in the ps1 variable but with single quotes so that when it gets echoed or whatever bash does to
print it on the screen i would guess it just feeds it through the echo command that code gets
interpreted every time it gets echoed so you can do some cool stuff if you're careful with your
quotes single quotes are very strict and they don't they don't let anything inside the single
quotes get interpreted when they're being assigned so you can put variables in there you can put
programs inside some those parentheses so that they get executed and run each time your
prompt is displayed that's how all the fun stuff happens in my prompt i am just concatenate my
giant ps1 together with a bunch of bash script embedded directly in the prompt with single quotes
if you're embedding something that doesn't change a lot for instance a host name or
you could even do it with username i suppose you could just put it in normal double quotes or
just put it straight into the variable somehow and save some processing cycles it's not going to
hurt you either way it's just a string but otherwise you can if you need something executed every
single time you can surround it in single quotes okay so now that i've covered all that extra
information i'm going to explain what my bash prompt looks like
because this is a lot of build up but not to actually have seen
what it's used for doesn't it doesn't make it sound very useful so here's what i see whenever
i open a terminal first of all my bash prompt is two lines long i've got kind of an information
status line at the top that's just its own line it's left aligned usually stretches about halfway
across the screen depending on where i am and then below that is the prompt line which is always
either two or three characters very minimal so that i have the entire terminal width
to edit or run my command so the first line that information or status line
starts with essentially the basic debian prompt it starts with the username
so at the moment mine says win to go and all of the default information or status
is in yellow all of the separator characters that break up that information are blue
so the first piece of information in that line is my username so it says win to go right now
and that chunk my username like i said changes color it changes color and turns bold
when i have system mail so if i've had a cron job that ran overnight my username is red
it also outputs the mail notification that somehow gets bubbled up in a system in a debian system
but the important thing for me is that my username is red i can go to any terminal and as soon as
i hit enter and it detects that that file is not zero length it tells me i have mail
so the second piece of information my host name turns red and bold when the system needs to be
rebooted if i've installed some updates or some updates have been automatically installed
overnight and my system needs to be rebooted because there's a kernel update in there
my prompt checks for the slash run slash reboot required file and turns my host name red if it's
there so that lets me know that i i should probably start saving work instead of opening new windows
and just give my system a quick reboot so between that there's a blue pipe character
just to give it some separation and then we have the current directory
and that is truncated to a tilde if we are if we're in home somewhere so for instance if i'm
in slash home slash window go all i'll see there is a single yellow tilde otherwise it'll just
append whatever folder i'm in so right now i'm in tilde slash documents slash podcasts slash
bash prompt and if i'm just in a normal folder at the root level it will it'll just display the
whole path so there are some modifiers on that piece of information too if i have added some extra
directories to the directory stack using the push d and pop d bash built-ins it will tell me
how many directories deep i'm in so if i'm in my home directory it's it's a tilde but if i do
push d slash etc the prompt will display that i'm in the etc directory but it will have a bright
red two and then a slash in front of it so it pre-pens the number of directories in the stack
then i can do a pop d and that number goes away because if i just have one who cares why would
i display that number and then after the path information if i'm in a git directory so if the
directory i'm in is a git repo and has git information it displays the branch i'm on in red
after the path separated by the little plus minus git version control character i think it's a
unit code character so if i'm in code slash my cool project and that's a git directory the path
information will say code slash my cool project plus minus master or feature slash whatever
whatever branch is is currently open in that directory so that's the whole information line
that's all the information i really see from my prompt and the prompt line is really just a single
blue double it carrot character that points to the right there there's an optional piece of
information that can show up there and that is the number of background jobs i've got it going
which will just show up as a single red number but mostly it's just that those double carrots
and that that gives me the full width of the terminal to type in whatever monstrosity i'm trying to
run and when i open up the man page for that monstrosity it shows up as a number two when i send
it to the background so that gives me the ability to add a glance check and see what terminals
got jobs hiding or has jobs hiding inside it i'm a big fan of opening a file and then
sending that to the background with control z and checking a man page and then accidentally
reopening that file because i didn't remember i opened it the first time so having that job number
there helps me avoid getting into an infinite loop of opening vim and man and just checking
myself until my system runs out of resources so that's my whole bash prompt it looks very
unassuming i'll add some pictures to the show notes of when it's first opened and then i'll
purposely junk it up i'll put a bunch of background processes and directories and
move myself to a git repository just to show what it looks like when it's crazy
but i find that that helps a lot while i'm working at the terminal to make myself productive
and it makes things more comfortable while i'm using command line and i don't know if it's
i've worked at it for a really long time and i like it so if you have some cool bash customizations
or if you use another shell like fish or z8sh any of those guys you should do an episode and
explain what you what you look at every day and how to set it up because i know some people do it
using shell functions i don't know how most of the other shells do it but i'd be very interested
in finding out so anyways i hope this is of use check out the show notes if you'd like
any details about how i set up my font or ps1 variable i'll include the whole thing
the whole monstrosity and if you need to contact me fragdev.com slash contact
all right i'll see you later
you've been listening to hecopovicradio at hecopovicradio.org
we are a community podcast network that releases shows every weekday Monday through Friday
today's show like all our shows was contributed by an hbr listener like yourself
if you ever thought of recording a podcast and click on our contributing to find out how easy it
really is hecopovicradio was founded by the digital dog pound and the infonomican computer club
and it's part of the binary revolution at binrev.com if you have comments on today's show
please email the host directly leave a comment on the website or record a follow-up episode
yourself unless otherwise status today's show is released on the creative comments
attribution share a light 3.0 license