What is a shell, why you care, why you would want to configure it? and how to configure it.
What is the “Shell?”
The program that interprets the input and sends the results back to the user acts as a ‘middleman.’ It protects the user from the messy, ‘dangerous’ operating system, or depending on your point of view, protects the operating system from the user. Because of this ‘protective’ position, it was called ‘shell’ or sh for short.
Excerpt From: Armin Briegel. “Moving to zsh.” Apple Books.
(It’s a little piece of software that lets you type in commands)
Lots of fun history, but – that’s only for you nerds who look it up.
Computers didn’t have screens. You had to type into them to give them commands. Then they got screens and graphical user interfaces, but the shell stuck around. Apple took it out at that point because they didn’t think people would want to use it anymore. Apple bought NeXT and their operating system was based on BSD Unix – and so Mac got a terminal application and a command-line interface again. That all sounds more confusing than necessary. (It’s a little program that you type in to give the computer directions)
There are a bunch of different people who like to change things or even improve them – so, there were many ‘shell’ programs getting created. Some got more popular than others. The NeXTStep OS used “tcsh (Tenex C Shell).” There was this “bsh” (Bourne Shell) – and then from that: “bash” (Bourne Again Shell). Get it? : yes – that’s how things get named sometimes. Linux people liked that one and so Apple added it to attract them – and also because they didn’t have to pay anyone for it.
In 2003 bash became the default shell for Mac.
In 2019 they announced that zsh will now be the default shell.
Around that time, they also that the runtimes for Perl, Python, and Ruby (which used to be installed by default) – wouldn’t be anymore. And then in 2021 they also took PHP out of the default setup. (just a side note!)
So – anyway, lets use zsh “Zeee shell” – OK?
This is the command-line-interface that comes with macOS.
Just pick a name people!
And this is another application that we use instead.
But we don’t remember why. So – explore that / and explain it to us. There are many more that hip people like too. But they don’t know why either. It’s usually because the default “skin” (look) – is trendy at the time. Just do what we do and blindly choose iTerm. It might have something special. But we can’t remember yet.
The top one shows the user folder in the top bar. They both say “-zsh” up there.
They both say when the user last logged in. One says ‘console’ and the other one ‘ttys000.’ Both things we don’t want to know about.
And then they both say the user name – and give the user a cursor/prompt to type.
Seem mostly the same…
I don’t care when I last logged in. I also don’t need to know my own username – because this computer isn’t the type of thing that is going to be using many different users. I would like to know what directory I’m in though. And – of course – I want a cool emoji of a broccoli – to remind me to eat something healthy – instead of that silly percentage sign.
Great. That sounds like a todo list.
Remove “last logged in” time
Remove user name / or shorten it
Add funny emoji because they are funny
Show current file directory so you know where you are
In case you don’t know yet: most things are key:value pairs in web dev world. So, if something needs to be configured there’s usually a “config” (because it’s faster to write?) file somewhere. Or, if there isn’t one – you can make one and set some settings. (configure the configuration)
Different shells use different configuration files. Bash had a file called
.bash_profile – so, there’s probably a
.zsh_profile or something…
They’re probably hidden in your user folder. Remember how to look at hidden files? Try
⌘ + ⇧ + . to toggle them.
What are they?
You can look em up.
There seems to be a bunch of profiles and also many different
z type names.
There are some other files too...
These files would be loaded for all users. But – to keep things simple, we will just be doing our configuration at the user level. However, if you’re curious – you can check out the Unix directory structure.
Which file to use?
(that the one in your user folder, right?)
If you don’t already have one, you can create one.
Also, you can write comments in there with a #
# This is a comment
How to configure it
Try these settings out in your
PROMPT='🥦 ' (the thing and then a space)
(You’ll have to open a new terminal each time / to see the changes)
PROMPT='%1~ 🥦 ' (+ the path but just one layer deep)
That’ll take care of the prompt good enough.
To get rid of the “last logged in” bit, you can create a
.hushlogin file in your user folder.
You can run commands in there. So, for example: we like our prompt to just start out at
/Sites – because that’s where our work is stored. So, – you can just put
in the file – and it’ll run each time you open a terminal window.
Every time you open a new terminal window it will run the given program from top to bottom:
- set prompt:
PROMPT='%1~ 🥦 '
- change directory:
You can tell it to run any programs you would run by hand. So, you can have it change to any directory you want.
This next part is only for after you’ve started using your text editor
Our workflow is to appear at the
Sites – and then change into the directory we’re going to work in…
There are many many programs that have their own commands. The Sublime Text text editor has this command to open a file – at this file path:
But who will type all that out whenever they want to open a file? (not us)
So you can create your own command name and point it to another place. This is just like our “alias” folders that point to another real folder.
alias keyword says that we are indeed creating an alias.
The second parameter is the alias name (the name of the new command you are creating)
And then the third part would be what location (file path) the alias is pointing to
alias sublime="/Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl"
We can chat about this, but the basic usage would be (in the folder you want to open)
sublime . (which points to the sublime commands and uses
. to signify “open the file with this application”)
And that’ll open the files right in Sublime from the command line.
(you could have a different alias name too if you want. It’s up to you)
Seen any other tricks you want to try out? Any questions? Let us know.
NOTE: The “Sites” folder doesn’t seem to be a default OS thing these days. You can make your folder whatever you want, OK?
The order here probably doesn’t’ matter. Or does it?