Install Oh My Zsh. If you only follow one of these tips, it needs to be this one.
- The only (visual) difference to my bash prompt is the% instead of the $. Note: creating a file /.hushlogin will suppress the status message at the start of each Terminal session in zsh as well as in bash (or any other shell). Basic Prompt Configuration. The basic zsh prompt configuration works similar to bash, even though it uses a different syntax.The different placeholders are described.
- If you find that you're using an alternative shell such as zsh, that uses a different set of configuration files maintained within your home directory,. Luckily the syntax of the changes is basically the same, just different files. So you can add the above example to this file instead: $.
- Python is very well suited for writing AWS Lambda functions. For local development, you might want to be able to run the whole range of supported Python runtimes on your Mac. Unfortunately, setting this up is not as straightforward as you might think.
Outline
I try to write how to configure the development environment from very first time on Mac. this blog is a series. if you want to know other development environment, see other blog posts.
in here, I’ll introduce how to configure iTerm and zsh on Mac.
iTerm Installation
click the link below to go to iTerm
download page.
- iTerm download: Download
you can see the screen like below, click Stable Releases
to download.
unzip zip
file you downloaded and install it.
if iTerm asks you Full Disk Access
permission, click Open System Preferences
on the right bottom.
you can see the nice explanation and Security & Privacy
is activated. click the lock shape on the left bottom, and insert your password to make editable.
select Privacy
on the top tab, and click Full Disk Accesss
on the left list.
click +
button on the right side. go to Applications
, and select iTerm
and click Open
.
if Mac asks you that you want to quit iTerm
, click Quit Now
to quit iTerm
.
after it, check iTerm is executed.
zsh
zsh makes Terminal easier to use. if you want to know more details, click the link below.
- zsh official site: zsh
you can find the installation on zsh official site like below.
open iTerm or Terminal and execute the command below.
after installing, you can see the screen like below.
Configure zsh to iTerm Default Terminal
iTerm’s default is to use the basic shell. let’s set iTerm uses basically zsh.
execute iTerm and click iTerms2
> Preferences...
on the left top.
you can see the screen like above. click Profiles
tab on the top. insert /bin/zsh
in Command
on Command
section on the right middle.
after it, restart iTerm. you can see zsh
is executed by default.
Configure iTerm Theme.
there are many themes for iTerm. you can configure the theme what you want. in here, I’ll introduce how to set iterm2-solarized
theme.
click the link below to download the theme.
when you click the link above, you can see the theme file contents. push command + s
to save it.
before you download it, change to All Files
on Format
on the bottom. and check the end of the file is .itermcolors
.
open Preferences of iTerm again.
click Profiles
> Colors
like above, and click Color Preset...
> import...
on the right bottom.
select Solarized Dark - Patched.itermcolors
file you downloaded above.
select Color Preset...
again, you can see Solarized Dark
. click it to change the theme.
Configure Powerlevel9k
to show more information on zsh, let’s configure Powerlevel9k
. you can see the screen like below, when you execute current iTerm.
execute the command below to download Powerlevel9k
.
zsh’s configuration file is ~/.zshrc
. open it and set Powerlevel9k.
find the theme configuration.
change the theme from ZSH_THEME='robbyrussell'
to ZSH_THEME='powerlevel9k/powerlevel9k'
and save it.
to restart iTerm, you can see the screen like below.
you can see user information and ?
. the question mark is shown up when the font is not set. click the link below to go to the font download site.
when you click the link above, you can see the screen lik below. click View Raw
to download the font.
after downloading it, click the font file to execute it.
click Install Font
on the right bottom to install it. after installing, open Preference on iTerm again and click Profiles
> Text
> Change Font
.
select Meslo LG M Regular for Powerline
what we downloaded above.
when you execute iTerm, you can see the screen like above.
I don’t like to show my long username, so I configured it not showing up. execute the command below if you want to hide it.
add the content below to the bottom.
or you can customize it like below.
you can see the details about the option on the official site.
- official site: https://github.com/bhilburn/powerlevel9k
restart iTerm. you can see the user name not displayed.
Connect vscode and zsh
in here, we’ll set code
command of vscode on zsh, and zsh to vscode’s default terminal on vscode.
Configure vscode command to zsh
execute the command below to open zsh configuration file.
add the content below to the bottom of the settings file.
restart iTerm and execute the command below to check vscode activated.
Configure zsh to vscode
click Code
> Preferences
> Settings
on the left top of the vscode.
search shell
and change /bin/bash
to /bin/zsh
on Terminal > Integrated > Shell: Osx
.
if you see Edit in settings.json
instead of the screen above, click the link and add the content below.
also, search fontfamily
and set Meslo LG M for Powerline
on it like below.
after it, to execute Terminal on vscode, you can see zsh executed.
Was my blog helpful? Please leave a comment at the bottom. it will be a great help to me!
macOS 10.15 Catalina brought many big changes to the Mac, like lack of support for legacy 32-bit apps, but one that you could easily have missed is the default Terminal shell switching from bash (the Bourne-again shell) to zsh (Z shell). It’s an easy change to miss if you don’t use the Terminal, but also because if you upgraded from an older version of macOS, bash remains the default (though you’re prompted to switch).
If you’re a Terminal user, you need to be aware of the change, and if you’re merely Terminal-curious, now is a great time to dive in and learn more about the shell, since so many Mac-friendly user guides are being published. In our last reader survey, Terminal coverage wasn’t high on the list of desired topics (“TidBITS 2019 Reader Survey Results,” 6 September 2019), so I won’t dedicate a ton of space to zsh here but will instead point you to resources to help learn more about it.
What is a “shell?”
In the simplest terms, the shell is the command-line environment you use to interact with the operating system. Apple intends users to interact with macOS primarily through its graphical interface, but because macOS is built on top of Unix, it also offers a robust command-line environment.
Don’t confuse a shell like zsh with the Terminal app itself. Terminal loads zsh or another shell of your choice and acts as your graphical interface to the shell, which in turn is the text-based interface to macOS’s Unix foundation.
From the command line, you can execute Unix commands like cd
and ls
. A shell used in this way is referred to as an “interactive shell.” You can also string shell commands together with flow control and the like to write shell scripts that automate actions. Those can in turn also be integrated into other automation tools like AppleScript and Keyboard Maestro. In such scripts, you call the shell, usually sh
, with a starting line like #!/bin/sh
. When you use a shell like this, it’s called a non-interactive shell.
Zsh Mac Iterm2
What is bash, and why did Apple switch to zsh?
Over the years, programmers have developed numerous shells with different features. Since Mac OS X 10.3 Panther, the Mac’s default shell has been the Bourne-again shell, or bash. It’s also often the default on many Linux distributions, making it something of a de facto standard. Its name is a play on the nigh-ubiquitous Bourne shell (and its many clones, like ash), often referred to by its command, sh
. The Bourne shell dates back to 1976, and while it isn’t generally used interactively, it’s still the basis for most Unix shell scripts because of its ubiquitousness. In 1989, bash emerged from the GNU Project as a newer, more modern version of sh.
There’s nothing wrong with bash, but after version 3.2, released in 2007, the GNU Project relicensed it under the GNU Public License 3.0, which places restrictions on companies like Apple, such as refraining from patent lawsuits and letting people tinker with their computers. Long story short, the 3.2.57 version of bash that ships with macOS is long out of date because Apple refuses to accept GNU’s terms. However, GNU has released small updates over the years to address things like the Shellshock vulnerability—see “Apple Updates Bash for the Shellshock Vulnerability” (29 September 2014).
In contrast, zsh is licensed under a variant of the less-restrictive MIT license. It also offers some advanced features that bash doesn’t.
Zsh Macos Catalina
What does zsh do that bash doesn’t?
The How-To Geek has a brief overview of zsh’s advantages, like automatic cd
, where you can simply type a directory name to navigate to it, and built-in spell-check. zsh also supports plug-ins, which enables things like the popular Oh My Zsh, which adds even more features and makes advanced configuration easier. I also recommend perusing the zsh FAQ, which answers various and sundry questions.
One of my favorite features of zsh is menu autocomplete. In most shells, you can start to type a command or directory name, like /usr/bi
, and then press Tab to autocomplete. In most shells, if there’s more than one autocomplete option, the shell will list the options, but you have to keep typing out the correct path by hand until there’s only one option left, after which you can press Tab to fill it in. With zsh, you can instead configure it to show your options as a menu that you can navigate and select with arrow keys, or with a bit more configuration, vi keybindings or any keys you want. In the screenshot below, I entered /usr/local/
and hit Tab to see a menu of subfolders.
How do I know which shell I’m using?
Open Terminal and enter one of these commands:
echo $0
— which shows the name of the shell.echo $SHELL
— which shows the path to the shell.
The latter command can be especially helpful if you use something like Homebrew to install different shell versions, which exist alongside those Apple ships, just in a different directory (more on that later).
Where can I learn more about zsh?
One of the best free resources for zsh in macOS is Armin Briegel’s Moving to zsh eight-part blog series. Briegel has also released a $9.99 ebook called—you guessed it—Moving to zsh—in Apple’s Book Store. If you’re serious about learning zsh in Catalina, I think it’s a good investment, as it covers in detail everything from explaining what a shell is, transitioning to zsh, and configuring zsh. It will take you from beginner to advanced user quickly, but it isn’t an exhaustive reference. For that, check out the official zsh manual.
The zsh team also offers an official user-friendly guide to zsh, which isn’t as user-friendly or Mac-focused as Briegel’s but has more raw information.
Update Zsh Mac
How do I customize zsh?
Out of the box, zsh is a bit spartan. I recommend Briegel’s Moving to zsh, part 2: Configuration Files for a thorough explanation of zsh’s configuration files, though you’ll have to read the rest of the series for configuration tips.
Hold off on installing a plug-in system like the aforementioned Oh My Zsh until you have a good grasp on how zsh works and what you need from Oh My Zsh. No need to make things overly complicated from the start.
Can you share your zsh configuration?
I just copy Luke Smith’s zshrc file into ~/.zshrc
. He has set up some nice colors and menu autocomplete with vi keybindings. Here’s a video explaining his configuration in detail.
If you don’t like the vi keybindings and want to use the arrow keys to navigate the menu, simply remove or comment out the five lines under # Use vim keys in tab complete menu:
.
Will my old shell scripts break?
If you started your shell scripts with the standard #!/bin/sh
, you shouldn’t have problems. Catalina still ships with bash, which emulates sh. However, I wouldn’t be surprised if Apple were to remove bash entirely in the future. Apple suggests having zsh emulate sh by adding the --emulate sh
option to zsh, so you can start a script with #!/bin/zsh --emulate sh
. (Note that this won’t work with the version of zsh that ships with Mojave.) I also refer you to Briegel’s Moving to zsh, part 8, which covers scripting with zsh.
My default shell is still bash. How do I switch to zsh?
Although zsh was not the default in older versions of macOS, nor is it the default in Catalina for older accounts which were created with bash as their default shell, Apple has long included zsh with macOS. You can give it a whirl right now by typing zsh
at the command line. Type exit
to leave zsh. If you want to set it as your default shell, Apple offers a couple of ways to do so, as well as a way to change what Terminal uses without changing the default for your account.
I don’t like zsh. Can I go back to bash? Preferably a newer version?
Yes, and it’s easy to do so. Just follow the link to Apple’s how-to page above and replace /bin/zsh
in the instructions with /bin/bash
.
However, you may not want to remain on Apple’s ancient version of bash. That’s where Homebrew comes in handy. Once you install it, running brew install bash
will update the latest version from Homebrew, which will be installed in /usr/local/bin/bash
. Note that you’ll have Apple’s version in /bin/bash
and Homebrew’s version in /usr/local/bin/bash
. If you need a feature from the newer version of bash that Homebrew installs, be sure to start your scripts with #!/usr/local/bin/bash
.
If you don’t or can’t use Homebrew, Briegel has instructions on how to build and install bash manually.
Are there alternatives to bash and zsh?
There are an absurd number of shells out there, but bash and zsh are the most common and the most worth your time to learn. However, Brett Terpstra has been documenting his experiments with the fish shell:
Download Zsh For Mac
Fish features advanced autosuggestion and expansions, does cool syntax highlighting, offers a “sane” scripting toolset, has an array of existing plugins and themes, and even sports a browser-based configuration tool that’s pretty awesome.
I haven’t tried it, but it may be your cup of tea, er, barrel of fish.