GitHub Gist: instantly share code, notes, and snippets. I recently installed Zsh in hope of a better life and brighter mornings. However, I quickly realized Zsh introduces various issues in conjunction with tmux. The first issue was some weird stuff happening at the end of the prompt, before my commands, but this was resolved by supplying tmux with the -u flag for unicode-support.
- Zsh Autosuggestion - Video Results
- More Zsh Autosuggestion Videos
- Zsh Autosuggestions Tab
- Zsh-autosuggestions — Homebrew Formulae
- Zsh Autosuggestion Color
- Cached
- Zsh-autosuggestions Zsh-syntax-highlighting
Zsh is a powerful shell that operates as both an interactive shell and as a scripting language interpreter. While being compatible with the POSIX sh (not by default, only if issuing
emulate sh
), it offers advantages such as improved tab completion and globbing.The Zsh FAQ offers more reasons to use Zsh.
- 1Installation
- 3Configure Zsh
- 3.4Key bindings
- 3.5Prompts
- 3.5.1Prompt themes
- 3.5.2Customized prompt
- 4Tips and tricks
- 4.2Restore terminal settings after a program exits abnormally
- 4.3Remembering recent directories
- 4.5Persistent rehash
- 4.8xterm title
- 5Third-party extensions
Zsh has a great feature of autosuggestion (through a plugin) which remembers as one type in the terminal and then helps out during next instance of typing the same command. I have around 1000 lines of commands stored in a notepad which will be useful for all my projects.
Installation
Before starting, users may want to see what shell is currently being used:
Install the zsh package. For additional completion definitions, install the zsh-completions package as well.
Initial configuration
Make sure that Zsh has been installed correctly by running the following in a terminal:
You should now see zsh-newuser-install, which will walk you through some basic configuration. If you want to skip this, press
q
. If you did not see it, you can invoke it manually with:Note: Make sure your terminal's size is at least 72×15 otherwise zsh-newuser-install will not run.
Making Zsh your default shell
Change your shell to
/usr/bin/zsh
. See Command-line shell#Changing your default shell.Tip: If replacing bash, users may want to move some code from
~/.bashrc
to ~/.zshrc
(e.g. the prompt and the aliases) and from ~/.bash_profile
to ~/.zprofile
(e.g. the code that starts the X Window System).Startup/Shutdown files
Tip:- See A User's Guide to the Z-Shell for explanation on interactive and login shells, and what to put in your startup files.
- You could consider implementing a standard path for your Zsh configuration files.
- If
$ZDOTDIR
is not set,$HOME
is used instead. - If option
RCS
is unset in any of the files, no configuration files will be read after that file. - If option
GLOBAL_RCS
is unset in any of the files, no global configuration files (/etc/zsh/*
) will be read after that file.
When starting, Zsh will read commands from the following files in this order by default, provided they exist.
/etc/zsh/zshenv
Used for setting environment variables for all users; it should not contain commands that produce output or assume the shell is attached to a TTY. When this file exists it will always be read, this cannot be overridden.$ZDOTDIR/.zshenv
Used for setting user's environment variables; it should not contain commands that produce output or assume the shell is attached to a TTY. When this file exists it will always be read./etc/zsh/zprofile
Used for executing commands at start for all users, will be read when starting as a login shell. Please note that on Arch Linux, by default it contains one line which source the/etc/profile
. See warning below before wanting to remove that!/etc/profile
This file should be sourced by all POSIX sh-compatible shells upon login: it sets up$PATH
and other environment variables and application-specific (/etc/profile.d/*.sh
) settings upon login.
$ZDOTDIR/.zprofile
Used for executing user's commands at start, will be read when starting as a login shell. Typically used to autostart graphical sessions and to set session-wide environment variables./etc/zsh/zshrc
Used for setting interactive shell configuration and executing commands for all users, will be read when starting as an interactive shell.$ZDOTDIR/.zshrc
Used for setting user's interactive shell configuration and executing commands, will be read when starting as an interactive shell./etc/zsh/zlogin
Used for executing commands for all users at ending of initial progress, will be read when starting as a login shell.$ZDOTDIR/.zlogin
Used for executing user's commands at ending of initial progress, will be read when starting as a login shell. Typically used to autostart command line utilities. Should not be used to autostart graphical sessions, as at this point the session might contain configuration meant only for an interactive shell.$ZDOTDIR/.zlogout
Used for executing commands when a login shellexits./etc/zsh/zlogout
Used for executing commands for all users when a login shellexits.
See the graphic representation.
Note:$HOME/.profile
is not a part of the Zsh startup files and is not sourced by Zsh unless Zsh is invoked assh
orksh
and started as a login shell. For more details about the sh and ksh compatibility modes refer to zsh(1) § COMPATIBILITY.- The paths used in Arch's zsh package are different from the default ones used in the man pages (FS#48992).
Warning: Do not remove the default one line in
/etc/zsh/zprofile
, otherwise it will break the integrity of other packages which provide some scripts in /etc/profile.d/
.Configure Zsh
Although Zsh is usable out of the box, it is almost certainly not set up the way most users would like to use it. But due to the sheer amount of customization available in Zsh, configuring Zsh can be a daunting and time-consuming experience.
Simple .zshrc
Included below is a sample configuration file. It provides a decent set of default options as well as giving examples of many ways that Zsh can be customized. In order to use this configuration save it as a file named
.zshrc
.Tip: Apply the changes without needing to logout and then back in by running
source ~/.zshrc
.Here is a simple
.zshrc
:Configuring $PATH
Zsh ties the
PATH
variable to a path
array. They are automatically synchronized. This allows us to easily manipulate PATH
by simply modifying the array. See A User's Guide to the Z-Shell for details.The line
typeset -U PATH path
, where the -U
stands for unique, instructs the shell to discard duplicates from both $PATH
and $path
:Command completion
Perhaps the most compelling feature of Zsh is its advanced autocompletion abilities. At the very least, enable autocompletion in
.zshrc
. To enable autocompletion, add the following to your ~/.zshrc
:The above configuration includes ssh/scp/sftp hostnames completion but in order for this feature to work, users must not enable ssh's hostname hashing (i.e. option
HashKnownHosts
in ssh client configuration).For autocompletion with an arrow-key driven interface, add the following to:
To activate the menu, press
Tab
twice.For autocompletion of command line switches for aliases, add the following to:
For enabling autocompletion of privileged environments in privileged commands (e.g. if you complete a command starting with sudo, completion scripts will also try to determine your completions with sudo), include:
Warning: This will let Zsh completion scripts run commands with sudo privileges. You should not enable this if you use untrusted autocompletion scripts.
Note: This special kind of context-aware completion is only available for a small number of commands.
Key bindings
Zsh does not use readline, instead it uses its own and more powerful Zsh Line Editor (ZLE). It does not read
/etc/inputrc
or ~/.inputrc
. Read A closer look at the zsh line editor and creating custom widgets for an introduction to ZLE configuration.ZLE has an Emacs mode and a vi mode. If one of the
VISUAL
or EDITOR
environment variables contain the string vi
then vi mode will be used; otherwise, it will default to Emacs mode. Set the mode explicitly with bindkey -e
or bindkey -v
respectively for Emacs mode or vi mode.Key bindings are assigned by mapping an escape sequence matching a keypress to a ZLE widget. The available widgets, with descriptions of their actions and their default keybindings, are listed in zshzle(1) § STANDARD WIDGETS and zshcontrib(1) § ZLE FUNCTIONS.
The recommended way to set key bindings in Zsh is by using string capabilities from terminfo(5). For example[1][2]:
History search
You need to set up the
key
array and make sure that ZLE enters application mode to use the following instructions; see #Key bindings.To enable history search add these lines to
.zshrc
file:By doing this, only the past commands matching the current line up to the current cursor position will be shown when
Up
or Down
keys are pressed.Shift, Alt, Ctrl and Meta modifiers
xterm-compatible terminals can use extended key-definitions from user_caps(5). Those are combinations of
Shift
, Alt
, Ctrl
and Meta
together with Up
, Down
, Left
, Right
, PageUp
, PageDown
, Home
, End
or Del
. Refer to the zkbd source for a list of recommended names for the modifier keys and key combinations.For example, for
Ctrl+Left
to move to the beginning of the previous word and Ctrl+Right
to move to the beginning of the next word:Prompts
Zsh offers the options of using a prompt theme or, for users who are dissatisfied with the themes (or want to expand their usefulness), the possibility to build a custom prompt.
Prompt themes
Prompt themes are a quick and easy way to set up a colored prompt in Zsh. See zshcontrib(1) § PROMPT THEMES for more information about them.
To use a theme, make sure that prompt theme system is set to autoload in
.zshrc
. This can be done by adding these lines to:Available prompt themes are listed by running the command:
For example, to use the
walters
theme, enter:To preview all available themes, use this command:
Manually installing prompt themes
It is possible to install themes manually, without external configuration manager tools. For a local installation, first create a folder and add it to the
fpath
array, eg:Now create a symbolic link of your theme file in this folder:
If instead you wish to install a theme globally, do:
Now you should be able to activate it using:
If everything works, you can edit your
.zshrc
accordingly.Customized prompt
This article or section needs expansion.
Reason: Add a simple colorless
PROMPT
example. (Discuss in Talk:Zsh#)Additionally to a primary left-sided prompt
PS1
(PROMPT
, prompt
) that is common to all shells, Zsh also supports a right-sided prompt RPS1
(RPROMPT
). These two variables are the ones you will want to set to a custom value.Other special purpose prompts, such as
PS2
(PROMPT2
), PS3
(PROMPT3
), PS4
(PROMPT4
), RPS1
(RPROMPT
), RPS2
(RPROMPT2
) and SPROMPT
, are explained in zshparam(1) § PARAMETERS USED BY THE SHELL.All prompts can be customized with prompt escapes. The available prompt escapes are listed in zshmisc(1) § EXPANSION OF PROMPT SEQUENCES.
Colors
Zsh sets colors differently than Bash, you do not need to use convoluted ANSI escape sequences or terminal capabilities from terminfo(5). Zsh provides convenient prompt escapes to set the foreground color, background color and other visual effects; see zshmisc(1) § Visual effects for a list of them and their descriptions.
Colors can be specified using a decimal integer, the name of one of the eight most widely-supported colors or as a # followed by an RGB triplet in hexadecimal format. See the description of fg=colour in zshzle(1) § CHARACTER HIGHLIGHTING for more details.
Most terminals support the following colors by name:
Name | Number |
---|---|
black | 0 |
red | 1 |
green | 2 |
yellow | 3 |
blue | 4 |
magenta | 5 |
cyan | 6 |
white | 7 |
Color numbers 0–255 for terminal emulators compatible with xterm 256 colors can be found in the xterm-256color chart.
With a correctly set TERM environment variable, the terminal's supported maximum number of colors can be found from the terminfo(5) database using
Note:echoti colors
. In the case of 24-bit colors, also check the COLORTERM environment variable with print $COLORTERM
. If it returns 24bit
or truecolor
then your terminal supports 16777216 (224) colors even if terminfo shows a smaller number.- The colors 0–15 may differ between terminal emulators and their used color schemes.
- Many terminal emulators display bold with a brighter color.
- Prompt escapes can be tested with command
print -P 'prompt escapes'
, for example: - If you use 24-bit colors, you might want to load the
zsh/nearcolor
module in terminals that do not support them. E.g.: See zshmodules(1) § THE ZSH/NEARCOLOR MODULE for details about thezsh/nearcolor
module.
Example
This article or section needs expansion.
Reason: Add an example using a color from the 16–255 range and one with 24-bit color. (Discuss in Talk:Zsh#)
This is an example of a two-sided prompt:
And here is how it will be displayed:
Sample .zshrc files
- To get the same setup as the monthly ISO releases (which use Zsh by default), install grml-zsh-config. It includes the many tweaks and advanced optimizations from grml.
- https://github.com/MrElendig/dotfiles-alice/blob/master/.zshrc - basic setup, with dynamic prompt and window title/hardinfo.
- https://github.com/slashbeast/conf-mgmt/blob/master/roles/home_files/files/DOTzshrc - zshrc with multiple features, be sure to check out comments into it. Notable features: confirm function to ensure that user want to run poweroff, reboot or hibernate, support for GIT in prompt (done without vcsinfo), tab completion with menu, printing current executed command into window's title bar and more.
See dotfiles#User repositories for more.
Tips and tricks
Autostart X at login
See xinit#Autostart X at login.
Restore terminal settings after a program exits abnormally
Many programs change the terminal state, and often do not restore terminal settings on exiting abnormally (e.g. when crashing or encountering SIGINT).
This can typically be solved by executing reset(1):
The following sections describe ways to avoid the need to manually reset the terminal.
The ttyctl command
The ttyctl command can be used to 'freeze/unfreeze' the terminal. To freeze the interactive shell on launch, use the following:
Resetting the terminal with escape sequences
Alternate linedrawing character set can screw up the terminal in a way which ttyctl cannot prevent.
A simple solution is to output the escape sequences that reset the terminal from the
precmd
hook function, so that they are executed every time before the prompt is drawn. For example, using the escape sequencee[0me(Be)0017e[?5le7e[0;0re8
:To test if it works, run:
Remembering recent directories
Dirstack
Zsh can be configured to remember the DIRSTACKSIZE last visited folders. This can then be used to cd them very quickly. You need to add some lines to your configuration file:
Now use
to print the dirstack. Use
cd -<NUM>
to go back to a visited folder. Use autocompletion after the dash. This proves very handy if using the autocompletion menu.Note: This will not work if you have more than one zsh session open, and attempt to
cd
, due to a conflict in both sessions writing to the same file.cdr
cdr allows you to change the working directory to a previous working directory from a list maintained automatically. It stores all entries in files that are maintained across sessions and (by default) between terminal emulators in the current session.
See zshcontrib(1) § REMEMBERING RECENT DIRECTORIES for setup instructions.
Help command
Unlike Bash, Zsh does not enable a built in
help
command, instead it provides run-help
. By default run-help
is an alias to man
, it can be either executed manually by prepending it to a command or it can be invoked for the currently typed command with the keyboard shortcuts Alt+h
or Esc
h
.Since by default it is just an alias to man, it will only work on external commands. To improve its functionality, so that it works on shell builtins and other shell features, you need to use the
run-help
function. See zshcontrib(1) for more information on the run-help
and its assistant functions.First load the
run-help
function and then remove the existing run-help
alias. For convenience help
can be aliased to run-help
. For example, add following to your zshrc
: Autocad 2007 torrent crack for idm.Assistant functions have to be enabled separately:
For example,
run-help git commit
command will now open the man pagegit-commit(1) instead of git(1).Persistent rehash
Typically, compinit will not automatically find new executables in the
$PATH
. For example, after you install a new package, the files in /usr/bin/
would not be immediately or automatically included in the completion. Thus, to have these new executables included, one would run:This 'rehash' can be set to happen automatically.[3] Simply include the following in your
zshrc
:On-demand rehash
As above, however pacman can be configured with hooks to automatically request a
rehash
, which does not incur the performance penalty of constant rehashing as above. To enable this, create the /etc/pacman.d/hooks
directory, and a /var/cache/zsh
directory, then create a hook file:This keeps the modification date of the file
/var/cache/zsh/pacman
consistent with the last time a package was installed, upgraded or removed. Then, zsh
must be coaxed into rehashing its own command cache when it goes out of date, by adding to your ~/.zshrc
:Zsh Autosuggestion - Video Results
If the
precmd
hook is triggered before /var/cache/zsh/pacman
is updated, completion may not work until a new prompt is initiated. Running an empty command, e.g. pressing enter
, should be sufficient.Alternative on-demand rehash using SIGUSR1
As above, however the hook file looks like this:
Warning: This sends SIGUSR1 to all running
zsh
instances. Note that the default behavior for SIGUSR1 is terminate so when you first configure this all running zsh
instances of all users (including login shells) will terminate if they have not sourced the trap below.The function trap above can be replaced with a list trap
trap 'rehash' USR1
. See zshmisc(1) § Trap Functions for differences between types of traps.This method will instantly
rehash
all zsh
instances, removing the need to press enter to trigger precmd
.Bind key to ncurses application
Bind a ncurses application to a keystroke, but it will not accept interaction. Use
BUFFER
variable to make it work. The following example lets users open ncmpcpp using Alt+
:An alternate method, that will keep everything you entered in the line before calling application:
File manager key binds
Key binds like those used in graphic file managers may come handy. The first comes back in directory history (
Alt+Left
), the second let the user go to the parent directory (Alt+Up
). They also display the directory content.xterm title
If your terminal emulator supports it, you can set its title from Zsh. This allows dynamically changing the title to display relevant information about the shell state, for example showing the user name and current directory or the currently executing command.
The xterm title is set with the xterm escape sequence
e]2;
a
. For example:will set the title to
A simple way to have a dynamic title is to set the title in the
precmd
and preexec
hook functions. See zshmisc(1) § Hook Functions for a list of available hook functions and their descriptions.By using
Tip:print -P
you can additionally take advantage of Zsh's prompt escapes.- Title printing can be split up in multiple commands as long as they are sequential.
- GNU Screen sends the xterm title to the hardstatus (
%h
). If you want to use Screen's string escapes (e.g. for colors) you should set the hardstatus with thee_
e
escape sequence. Otherwise, if string escapes are used ine]2;
a
, the terminal emulator will get a garbled title due to it being incapable of interpreting Screen's string escapes.
- Do not use the
-P
option ofprint
when printing variables to prevent them from being parsed as prompt escapes. - Use the
q
parameter expansion flag when printing variables to prevent them from being parsed as escape sequences.
Terminal emulator tab title
Some terminal emulators and multiplexers support setting the title of the tab. The escape sequences depend on the terminal:
Terminal | Escape sequences | Description |
---|---|---|
GNU Screen | ek e | Screen's window title (%t ). |
Konsole | e]30; a | Konsole's tab title. |
Shell environment detection
See a repository about shell environment detection for tests to detect the shell environment. This includes login/interactive shell, Xorg session, TTY and SSH session.
/dev/tcp equivalent: ztcp
Use the
zsh/net/tcp
module:You can now establish TCP connections:
Shortcut to exit shell on partial command line
By default,
Ctrl+d
will not close your shell if the command line is filled, this fixes it:Third-party extensions
Configuration frameworks
- oh-my-zsh — A popular, community-driven framework for managing your Zsh configuration. It comes bundled with a ton of helpful functions, helpers, plugins, themes.
- https://github.com/robbyrussell/oh-my-zsh || oh-my-zsh-gitAUR
- Prezto — A configuration framework for Zsh. It comes with modules, enriching the command line interface environment with sane defaults, aliases, functions, auto completion, and prompt themes.
- https://github.com/sorin-ionescu/prezto || prezto-gitAUR
- ZIM — A configuration framework with blazing speed and modular extensions. Zim is very easy to customize, and comes with a rich set of modules and features without compromising on speed or functionality.
- https://github.com/zimfw/zimfw || zsh-zim-gitAUR
Plugin managers
- Antibody — A performance-focused plugin manager similar to Antigen.
- https://github.com/getantibody/antibody || antibodyAUR
- zinit (previously 'zplugin') — Flexible Zsh plugin manager with clean fpath, reports, completion management, turbo mode
- https://github.com/zdharma/zinit || zsh-zplugin-gitAUR
- Antigen — A plugin manager for Zsh, inspired by oh-my-zsh and vundle. ABANDONED
- https://github.com/zsh-users/antigen || antigen-gitAUR
- zgen — A lightweight and simple plugin manager for Zsh. ABANDONED
- https://github.com/tarjoilija/zgen || zgen-gitAUR
- zplug — A next-generation plugin manager for Zsh. ABANDONED
- https://github.com/zplug/zplug || zplugAUR
Fish-like syntax highlighting and autosuggestions
Fish provides very powerful shell syntax highlighting and autosuggestions. To use both in Zsh, you can install zsh-syntax-highlighting, zsh-autosuggestions, and finally source one or both of the provided scripts from your zshrc:
The 'command not found' handler
pkgfile includes a Zsh script file that provides a
command_not_found_handler
function that will automatically search the official repositories, when entering an unrecognized command.You need to source the script to enable it. For example:
Note: The pkgfile database may need to be updated before this will work. See pkgfile#Installation for details.
Uninstallation
Change the default shell before removing the zsh package.
Warning: Failure to follow the below procedure may result in users no longer having access to a working shell.
Run following command:
Use it for every user with zsh set as their login shell (including root if needed). When completed, the zsh package can be removed.
Alternatively, change the default shell back to Bash by editing
/etc/passwd
as root.Warning: It is strongly recommended to use vipw(8) when editing
/etc/passwd
as it helps prevent invalid entries and/or syntax errors.For example, change the following:
To this:
See also
- The Z Shell Manual (different format available here)
- zsh-lovers(1) (available as zsh-lovers package)
Retrieved from 'https://wiki.archlinux.org/index.php?title=Zsh&oldid=632301'
by rajaraodv
In this blog I’ll cover installing ITerm2, ZSH shell, “oh my ZSH”, Themes, ITerm2 color schemes, “oh my ZSH” plugins and enable “ligature” support to help create a beautiful and powerful Terminal.
If you want to just make your regular Bash Terminal powerful, take a look at my previous blog: “Jazz Up Your Bash Terminal”. But ZSH explained in this blog is more powerful stuff.
Summary:
We’ll be covering a lot of things. This may be confusing, so here is the summary of what we will be doing.
- Install ITerm2 — This is a better alternative to the default Terminal
- Install latest ZSH shell — This is more powerful than the regular bash shell. We will switch ITerm2 to use ZSH shell.
- Install “Oh My ZSH “— This is a CLI tool to easily configure ZSH and add themes and plugins to ZSH
- Add two types of Themes using “Oh My ZSH” — some themes need extra steps so we will cover both
- Install different ITerm2 Schemes — These are just color schemes for the UI
- Add two different Plugins using “Oh My ZSH” to improve productivity
- Enable “ligature” support so when you write an arrow =>;, it appears like a real arrow →
Step 1— Install ITerm2
A lot of programmers like ITerm2 instead of the default Terminal. It is similar to the Terminal, but has lots of features of its own. It of course can run ZSH, Bash, and other shells inside it.
The following video shows some of the new features of Item 2 (v3).
For this blog we’ll use ITerm2. When I mention “Terminal”, I mean ITerm2. Although the steps are the same for both Terminal or ITerm2.
Step 2— Change Shell To ZSH
The following video shows why ZSH is better than just a bash shell.
Option 1 — Use Mac’s own ZSH:
Mac comes with a ZSH out-of-the-box, so we don’t need to install it. However, sometimes it’s an older version of ZSH. Typically it’s located at /bin/zsh. To use it, all we need to do is to change shell (chsh).
- Open the Terminal (or ITerm2) and type the following command.
2. Enter the password and it will change the shell, upon logout and login.
3. Logout and re-login
4. To test, open the Terminal and type the following, and it should say zsh.
Option 2— Install Homebrew and Install latest ZSH via Homebrew
This option is pretty common among users, because some of the plugins only work with the latest ZSH.
Homebrew, simply said, is a command line installer for all sorts of software. Let’s install that first.
- Install Homebrew by running the following command.
2. If you get Command Line Tools for Xcode error, it means you haven’t installed the CLI tools for Xcode. If you don’t get the error, you can skip this step, because you already have it installed.
XCode Developer CLI tools are used by various apps that manipulate core OSX features. So make sure to install the Xcode CLI tools by running the following command.
$ xcode-select —-install
Note: The above command opens up Mac’s installer and installs the XCode Developer CLI tools. If it doesn’t work, try xcode-select -r
to reset.
3. Install ZSH via Homebrew
More Zsh Autosuggestion Videos
Run the following command to install ZSH. It gets installed at
/usr/local/bin/zsh
PS: Mac’s default ZSH is at /bin/zsh
4. Use the Homebrew version of ZSH
Run the following command. You will be prompted to enter Mac’s password.
5. Logout and log back in.
6. Test if we are using ZSH and the correct ZSH
Step 3— “Oh My ZSH”
“Oh My ZSH” is a plugin that runs on top of ZSH. It provides default config for ZSH (~/.zhrc file) and also provides themes and more features.
From what I know, most power users who use ZSH also use “Oh My ZSH”.
- Install “Oh My ZSH”
Run the following command to install “oh My ZSH”.
2. Close and quit ITerm2 and reopen it.
It should look something like below. Notice that the prompt has changed and the theme is a bit different — That’s “Oh My ZSH” in action for you.
Step 4— Change Themes And Install Fonts
In this step, we’ll add two different “Oh My ZSH” Themes. “Oh My ZSH” comes with tons of themes. PS: But some Themes need extra steps like installing specific fonts and so on.
To set a Theme, simply open ~/.zshrc file (created by “Oh My ZSH”) and change the theme as shown below.
PS: .zshrc is the config file for ZSH shell. People who don’t use “Oh My ZSH” will have to manually create this file and add any configs themselves. “Oh My ZSH” automatically creates this file if it doesn’t exist and then adds its own set of configs into this file.
Theme 1 — Let’s add a Theme called “Avit”
- Open .zshrc
2. Change the Theme to “Avit”
You can browse all the “Oh My ZSH” Themes here. To change the Theme, simply change the ZSH_THEME value in ~/.zshrc file from robbyrussell to Avit.
3. Update ZSH config
Run the following command to update the config.
4. Change the background color and font size
Open ITerm2 > Preferences > Profiles > Colors and change the background black color to use 20% gray as shown below.
Then open Text > Change Font and change the size to 14pt.
OK, Let’s install a different Theme that needs fonts.
Theme 2 — Installing “agnoster” Oh My ZSH theme
This is a popular theme because it emulates the Powerline Python app that enhances the terminal. The following picture shows how it looks. But this theme also needs us to install Powerline themes.
1. Install Powerline fonts
Ironcad keygen crack. 2. Change the Theme to “agnoster”
3. Quit ITerm2 and reopen it.
4. Set Powerline font
You can set any Powerline patched font you like. All the fonts end with “for Powerline”.
Open
ITerm2 > Preferences > Profiles > Text > Change Font
and set it to something that has “for Powerline”. I’m choosing “Meslo LG DZ for Powerline” font.Note — If you are confused about the fonts and Themes: the Themes are for “Oh My ZSH” and ZSH shell and the fonts are for the Iterm2 itself.
5. All Done
At this point your Terminal should look like below:
Step 5 — Install iTerm2 “color schemes” (ITerm2 Themes)
There are plenty of gorgeous color schemes for iTerm2. These schemes change the foreground color, background color, cursor color, and so on. You can find them at iTerm2-color-schemes Github repo.
Note: These are just color schemes of the ITerm2 UI and don’t deal with the command prompt’s look and feel like “Oh My ZSH”’s themes (other than just changing colors).
Follow these steps to install them.
- Download the iTerm2-color-schemes as a zip file and extract it
- The “Schemes” folder contains all the color scheme files — they end with
.itermcolors
- Open
iTerm2 > Preferences > Profile > Colors > Color Presets > Import
- In the import window, navigate to the “Schemes” folder (from step 2)
- Select all the files so you can import all the color schemes at once
- Simply select whichever color scheme you like.
My favorites are Batman and Argonaut
The Argonaut color scheme looks like below:
Step 6— Install Plugins
Plugins add more functionalities to your workflow. By default “Oh My ZSH” already has the “git” plugin! and that’s why you were able to see all those Git statuses in the prompts in earlier screenshots. Let’s add another one to see how it works.
Note: In this section, we’ll install two different plugins to show how they work.
Plugin 1 — Add Syntax Highlighting Plugin
The Syntax Highlighting plugin adds beautiful colors to the commands you are typing as shown below.
- Clone the zsh-syntax-highlighting plugin’s repo and copy it to the “Oh My ZSH” plugins directory.
2. Activate the plugin in
~/.zshrc
by adding `zsh-syntax-highlighting
to the Plugins section as shown below.3. Re-read zshrc configuration
Plugin 2 — Add ZSH-AutoSuggestion Plugin
This plugin auto suggests any of the previous commands. Pretty handy! To select the completion, simply press → key.
- Install the plugin
PS: ZSH_CUSTOM points to ~/.oh-my-zsh/custom
2. Open
~/.zshrc
and add zsh-autosuggestionsStep 7 — Use Ligature Support
Zsh Autosuggestions Tab
There are various fonts that help make operators like less than, double equals, right arrow, not equals, and so on look beautiful. For example, every time you type: =>, it becomes: →.
To use this, we need fonts that support ligatures. We also need to enable it in ITerm2. FiraCode is one such font. Follow the steps to install and enable ligatures.
- Download the FiraCode repo and extract the zip file (or clone it)
- Open the
dstr > ttf
folder and double click on all the*.ttf
files and select the “Install font” button to install each of the font variations. - Navigate to
ITerm2 | Preferences | Profiles | Text
- Select
Use Ligatures
checkbox - Click on
Change Font
and selectFira Code Regular
font
Summary
We have covered a lot in this blog starting from installing latest ZSH via Homebrew, Oh My ZSH, Plugins, Themes, enable “ligatures” for FiraCode font.
?? Thank you!
If this was useful, please click the clap ? button down below a few times to show your support! ⬇⬇⬇ ??
My Other Posts
ECMAScript 2015+
Terminal Improvements
Zsh-autosuggestions — Homebrew Formulae
WWW
Virtual DOM
React Performance
Functional Programming
WebPack
- Webpack & Hot Module Replacement [HMR] (under-the-hood)
Draft.js
React And Redux :
Zsh Autosuggestion Color
- A Guide For Building A React Redux CRUD App (3-page app)
Cached
If this was useful, please click the clap ? button below a few times to show your support! ⬇⬇⬇ ??
Zsh-autosuggestions Zsh-syntax-highlighting
If you have questions, please feel free to ask me on Twitter: https://twitter.com/rajaraodv