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 each 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.
Our workflow is to appear at Sites – and then change into the directory we’re going to work in…
And that’s the point where we want to actually open that folder:
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)
And that’ll open the files in Sublime.
Seen any other tricks you want to try out? Any questions? Let us know.