Skip to content

Instantly share code, notes, and snippets.

@jordandraper
Forked from kevin-smets/iterm2-solarized.md
Last active August 16, 2024 19:42
Show Gist options
  • Save jordandraper/581650d8dbdf24859c393ea7da37948d to your computer and use it in GitHub Desktop.
Save jordandraper/581650d8dbdf24859c393ea7da37948d to your computer and use it in GitHub Desktop.
iTerm2 + Oh My Zsh + Color Scheme + Powerlevel10k - (Unix)

Default

Default

Powerlevel10k

Powerlevel10k

How to install

iTerm2

brew install --cask iterm2

Or, if you do not have homebrew (you should ;)): Download and install iTerm2

ZSH

More info here: https://github.com/ohmyzsh/ohmyzsh/wiki/Installing-ZSH

Oh My Zsh

More info here: https://github.com/robbyrussell/oh-my-zsh

Install with curl

sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

When the installation is done, edit ~/.zshrc and set ZSH_THEME="agnoster" for the default look. Or better yet, go for Powerlevel10k.

Powerlevel10k

Why Powerlevel10k? Well, because it's a drop-in replacement for Powerlevel9k, just a lot faster to render your prompt. ls feels fast again!

It's best to just follow the instructions at the source

  • Install the recommended font. Just do it.

If you want to trigger the configuration wizard immediately, simply run p10k configure to discover all options, which are plentiful.

(Optional) Install a patched font

If you did not go with Powerlevel10k (you should) or you want another font, read on:

Open the downloaded font and press "Install Font".

Set this font in iTerm2 (iTerm → Preferences → Profiles → Text → Font), in the dropdown select the desired Font. You will see it change on the fly.

Restart iTerm2 for all changes to take effect.

Further tweaking

Things like

  • ZSH Plugins
  • auto suggestions
  • word jumping with arrow keys / natural text editing
  • syntax highlighting
  • iTerm color customization
  • fig integration
  • visual studio code config

can be found in the section below.

ZSH Plugins

There are plenty of plugins to checkout Some recommended are:

  • git

Auto suggestions (for Oh My Zsh)

Auto suggestions

Just follow these steps: https://github.com/zsh-users/zsh-autosuggestions/blob/master/INSTALL.md#oh-my-zsh

Or if you want to follow from the souce: https://github.com/zsh-users/zsh-autosuggestions/blob/master/INSTALL.md

If the auto suggestions do not appear to show, it could be a problem with your color scheme. Under "iTerm → Preferences → Profiles → Colors tab", check the value of Black Bright, that is the color your auto suggestions will have. It will be displayed on top of the Background color. If there is not enough contrast between the two, you won't see the suggestions even if they're actually there..

Autocomplete for ZSH

This plugin for Zsh adds real-time type-ahead autocompletion to your command line, similar to what you find desktop apps.

Just follow these steps: https://github.com/marlonrichert/zsh-autocomplete?tab=readme-ov-file#installation--setup

Prevent History

If you need to clear your ZSH history in general, and as such clear the list of auto suggestions, you can add the following to you ~/.zshrc file:

# Disable History if the command is preceded by a space (https://unix.stackexchange.com/a/6104)
setopt HIST_IGNORE_SPACE

# Clear history with `clear_history` command
alias clear_history='echo "" > ~/.zsh_history & exec $SHELL -l'

The first entry will prevent any command preceded by a space to be witheld from history. The second entry creates an aliased command clear_history which will delete you ZSH history.

Enable word jumps and word deletion, aka natural text selection

By default, word jumps (option + → or ←) and word deletions (option + backspace) do not work. To enable these, go to "iTerm → Preferences → Profiles → Keys → Key mappings → Presets... → Natural Text Editing → Boom! Head explodes"

Syntax highlighting

Install instructions straight from the source

Restart iTerm2 for all changes to take effect.

iTerm2 Color Profile Customization

iTerm2 has better color fidelity than the built in Terminal, so your themes will look better.

Get the iTerm color settings of your choice. I've included some recommendations below.

Just save it somewhere and open the file(s). The color settings will be imported into iTerm2. Apply them in iTerm through iTerm → preferences → profiles → colors → load presets. You can create a different profile other than Default if you wish to do so.

Fig Integration

You might also want to install Fig which provides alternative shell completions for many command line tools with an IDE-like popup interface in the terminal window.

Visual Studio Code config

Fix the fonts

Installing a patched font will mess up the integrated terminal in VS Code unless you use the proper settings. You'll need to go to settings (CMD + ,) and add or edit "terminal.integrated.fontFamily""

If you're following along, you will have installed the suggested Powerlevel10k fonts, and so you'll need to edit it to

  • "terminal.integrated.fontFamily": "MesloLGS NF, Regular"

If you installed a different font:

  • for Source Code Pro + Font Awesome: "terminal.integrated.fontFamily": "'SourceCodePro+Powerline+Awesome Regular'". The single quotes are important! Restart VS Code after the config change.
  • for Source Code Pro: "terminal.integrated.fontFamily": "Source Code Pro for Powerline"
  • for other fonts you'll need to check the font name in Font Book. You can right click on them on select "Show in Finder" to get the exact name.

You can also set the fontsize e.g.: "terminal.integrated.fontSize": 14

Theme

You may also like to change your VS Code Theme:

Installing Python

Python can be slightly complicated to install due to PATH. It may be helpful to first understand how PATH works

Latest Version

  • On macOS, you can install the latest version of Python using Homebrew with the command brew install python. After installation, the Python interpreter is typically accessible via python3. Depending on your system the python command might still point to Python 2.x, and it's advisable to use python3 for Python 3.x.

    • If python3 does not work, troubleshoot with:
      • Run which python3 to find the location of your Python installation.
      • Add an alias such as alias python="/path/to/python3" to ~/.zshrc using the installation location found above. Replace /path/to/python3 with the actual path.
      • Alternatively, add this location to your PATH variable from within your shell's configuration file (e.g., ~/.zshrc for Zsh or ~/.bash_profile for Bash) by adding the line export PATH="/path/to/python3:$PATH". Replace /path/to/python3 with the actual path.
  • If you want to be able to just call python and pip and you know you won't have any conflicts then you can add an alias such as

    alias python=/opt/homebrew/bin/python3
    alias pip=/opt/homebrew/bin/pip3
    

What's happening under the hood?

Homebrew automatically makes python3 an available command after installing Python on macOS. When you install Python using Homebrew, it takes care of setting up the necessary links and paths so that you can immediately start using python3 from the terminal.

Here's a brief overview of what happens:

  1. Installation: When you run brew install python, Homebrew downloads and installs Python 3.

  2. Symlinking: Homebrew creates symlinks (symbolic links) in /usr/local/bin (or /opt/homebrew/bin on Apple Silicon Macs) that point to the installed Python binaries. This is why you don't need to manually add Python to your PATH.

  3. Versioning: Homebrew installs Python 3 with the python3 command to differentiate it from Python 2, which traditionally uses the python command. This helps in environments where both Python 2 and Python 3 are installed.

  4. Accessibility: After installation, you can use the python3 command in the terminal to start the Python 3 interpreter. Similarly, pip3 is installed for Python 3 package management.

It's worth noting that if you previously had another version of Python installed (not through Homebrew), the python3 command might refer to that version. Running which python3 will show you the path of the Python 3 version that's being used, and brew info python will provide information about the Python version installed by Homebrew, including its location.

Any Version

  • If you need a specific version of Python, pyenv is a great tool. It allows for easy installation and switching between different Python versions. For setup and usage instructions, visit pyenv's GitHub repository."

  • pyenv is not complete without pyenv-virtualenv which provides features to manage virtualenvs and conda environments for Python on UNIX-like systems.

    • A quick overview is here

    Usage

    Create project based virtualenv and automatically activate/deactivate

    1. Make sure the version of python you'll be using is installed

      For example, to download and install Python 3.6.3, run:

      $ pyenv install 3.6.3
    2. Create virtualenv based on your required version of python

      Provide the name and version of python to use. If the version is left blank, it will use your environment's current version. You can check your current version using $ pyenv versions.

      sh $ pyenv virtualenv 3.6.3 venv36

      NOTE: You can list existing virtualenvs with pyenv virtualenvs

      NOTE: You can delete existing virtualenvs with pyenv uninstall <virtualenv_name>

    3. Set your project to always use this virtualenv.

      sh $ pyenv local venv36

      This will create a local file called .python-version. If you've set everything up correctly, this virtualenv should be activated upon entering this directory and deactivated when leaving.

  • Alternatively, once you've activated a certain python version say with pyenv shell "version number", you can use the standard python -m venv "env folder name" where "version number" and "env folder name" are changed appropriately.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment