re: a barely capable shell user VIEW POST


Awesome stuff, I love reading about people's early journeys into the world of the terminal 😎

You should definitely learn about your ~/.bashrc file if you haven't yet, it's a special file that gets run each time you open the terminal and it lets you set up a bunch of environment stuff to make your life easier, things like short aliases for common long commands and, importantly, environment variables.

And speaking of environment variables, the real reason I'm writing is that you can customize what your prompt (the Michaels-MacBook-Pro:~ dev$ bit) looks like using a variable called PS1. Google around and you'll quickly find more examples that you could want, but the biggest thing is that you can set it up to always print your entire path, or your path relative to your home directory, so you always know where you are without having to type pwd ever again!

A very simple, no-frills PS1 that will accomplish this is:

PS1='\u@\h:\w \$ '

Try typing that into your terminal, and you should start to see this prompt (assuming your username is michael and your pwd is ~/code/dev):

michael@Michaels-MacBook-Pro:~/code/dev $

If you like what it gives you, edit (or create) ~/.bashrc and paste it at the bottom. Then it will work in all future shell sessions, and you can say goodbye to pwd!

Here's a good overview of what the variables up there mean, and all the other ones you can use in your PS1: ss64.com/bash/syntax-prompt.html


WOW! This is all amazing!! You just made my night, thanks so much. 😃


Btw, forgot to say this in the above comment: full paths can get pretty long, so what a lot of people (myself included) like to do is add a line break \n right before the $ to drop it onto a new line:

PS1='\u@\h:\w\n\$ '

$ echo "Commands fit here no problem!"

And if you want a little splash of color, there's a bunch of color codes in the link in my last comment, but to start off, I like to make my user@hostname part a different color from my path, maybe light blue for the former and yellow for the latter. And always remember to reset your color to the default with \e[0m at the end, unless you want all the text you type to be colored as well, if that's your thing.

PS1='\e[0;36m\u@\h \e[0;33m\w\n\e[0m\$ '

your shell

Give that a try and see what you think!

code of conduct - report abuse