Introduction 🌟
Elevate your development environment with this guide on installing and configuring Zsh, Oh My Zsh, asdf, and the Spaceship Prompt theme. We will also leverage Zinit for additional plugin management. Let’s get started!
🚨🚨🚨 WARNING:If you like it this article please click in reaction and save, also follow me here and on my Github
🛠️ Step 1: Installing Zsh
Zsh is a robust shell that provides a powerful command-line experience. Here’s how to install it:
🐧 For Linux (Ubuntu/Debian):
sudo apt update
sudo apt install zsh
chsh -s $(which zsh)
🍎 For macOS:
Zsh is pre-installed. To set it as your default shell:
chsh -s /bin/zsh
🪟 For Windows:
Use WSL (Windows Subsystem for Linux) or Git Bash. For WSL:
- Install a WSL distribution (e.g., Ubuntu) from the Microsoft Store.
- Install Zsh as you would on Ubuntu.
Verify the installation:
zsh --version
⚙️ Step 2: Setting Up Oh My Zsh
Oh My Zsh simplifies Zsh configuration with themes and plugins.
Install Oh My Zsh:
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
This script will set up Oh My Zsh and switch your default shell to Zsh.
Configure Oh My Zsh:
-
Open your
.zshrc
file:
nano ~/.zshrc
-
Enable plugins:
plugins=(git asdf)
-
Reload your configuration:
source ~/.zshrc
🔄 Step 3: Installing and Configuring Zinit
Zinit is a plugin manager for Zsh, offering flexible and fast plugin management.
Install Zinit:
-
Add Zinit installer chunk to your
.zshrc
:
cat << 'EOF' >> ~/.zshrc ### Added by Zinit's installer if [[ ! -f $HOME/.local/share/zinit/zinit.git/zinit.zsh ]]; then print -P "%F{33} %F{220}Installing %F{33}ZDHARMA-CONTINUUM%F{220} Initiative Plugin Manager (%F{33}zdharma-continuum/zinit%F{220})…%f" command mkdir -p "$HOME/.local/share/zinit" && command chmod g-rwX "$HOME/.local/share/zinit" command git clone https://github.com/zdharma-continuum/zinit "$HOME/.local/share/zinit/zinit.git" && \ print -P "%F{33} %F{34}Installation successful.%f%b" || \ print -P "%F{160} The clone has failed.%f%b" fi source "$HOME/.local/share/zinit/zinit.git/zinit.zsh" autoload -Uz _zinit (( ${+_comps} )) && _comps[zinit]=_zinit # Load a few important annexes, without Turbo zinit light-mode for \ zdharma-continuum/zinit-annex-as-monitor \ zdharma-continuum/zinit-annex-bin-gem-node \ zdharma-continuum/zinit-annex-patch-dl \ zdharma-continuum/zinit-annex-rust ### End of Zinit's installer chunk EOF
-
Source your
.zshrc
:
source ~/.zshrc
🔌 Step 4: Installing Additional Plugins with Zinit
Use Zinit to install additional plugins for a richer Zsh experience.
Install plugins using Zinit:
-
Open your
.zshrc
file and add the following Zinit plugin commands:
nano ~/.zshrc
-
Add these lines to install and load additional plugins:
zinit light zdharma-continuum/fast-syntax-highlighting zinit light zsh-users/zsh-autosuggestions zinit light zsh-users/zsh-completions
-
Save and reload your
.zshrc
:
source ~/.zshrc
📦 Step 5: Installing and Configuring asdf
asdf is a versatile version manager for multiple languages.
Install asdf:
-
Clone the asdf repository:
git clone https://github.com/asdf-vm/asdf.git ~/.asdf --branch v0.11.3
-
Add asdf to your
.zshrc
:
echo -e '\n. $HOME/.asdf/asdf.sh' >> ~/.zshrc echo -e '\n. $HOME/.asdf/completions/asdf.bash' >> ~/.zshrc source ~/.zshrc
Install asdf plugins:
-
Add the Node.js plugin:
asdf plugin-add nodejs https://github.com/asdf-vm/asdf-nodejs.git
-
Install a specific version:
asdf install nodejs 16.13.0 asdf global nodejs 16.13.0
-
Add the Python plugin:
asdf plugin-add python https://github.com/danhper/asdf-python.git
-
Install a specific version:
asdf install python 3.9.7 asdf global python 3.9.7
Managing project-specific versions:
Create a .tool-versions
file in your project directory:
nodejs 14.17.6
python 3.8.10
Run asdf install
in the project directory to use these versions locally.
🚀 Step 6: Configuring the Spaceship Prompt Theme
The Spaceship Prompt theme offers a sleek and informative prompt for Zsh.
Install Spaceship Prompt:
-
Clone the Spaceship repository:
git clone https://github.com/spaceship-prompt/spaceship-prompt.git "$ZSH_CUSTOM/themes/spaceship-prompt" --depth=1
-
Create a symlink:
ln -s "$ZSH_CUSTOM/themes/spaceship-prompt/spaceship.zsh-theme" "$ZSH_CUSTOM/themes/spaceship.zsh-theme"
-
Set the theme in your
.zshrc
:
ZSH_THEME="spaceship"
Configure Spaceship Prompt:
-
Create a configuration file
.spaceshiprc.zsh
:
nano ~/.spaceshiprc.zsh
-
Add the following configuration:
SPACESHIP_USER_SHOW=always SPACESHIP_PROMPT_ADD_NEWLINE=false SPACESHIP_CHAR_SYMBOL="λ" SPACESHIP_CHAR_SUFFIX=" " SPACESHIP_PROMPT_ORDER=( user # Username section dir # Current directory section host # Hostname section git # Git section (git_branch + git_status) package # Package version node # Node.js section bun # Bun section elixir # Elixir section erlang # Erlang section rust # Rust section docker # Docker section docker_compose # Docker Compose section terraform # Terraform section exec_time # Execution time line_sep # Line break jobs # Background jobs indicator exit_code # Exit code section char # Prompt character )
-
Source your configuration in
.zshrc
:
echo "source ~/.spaceshiprc.zsh" >> ~/.zshrc source ~/.zshrc
Enable Command History Sharing:
To share command history across sessions:
HISTFILE=
~/.zsh_history
HISTSIZE=10000
SAVEHIST=10000
setopt share_history
Enable Auto-Corrections:
Enable corrections for common typos:
setopt correct
🔠 Step 7: Adding a Nerd Font for the Spaceship Prompt
Nerd Fonts provide additional icons and glyphs that enhance the appearance of your terminal, especially with themes like Spaceship Prompt.
- Install a Nerd Font (e.g., Hack or Roboto Mono):
- Go to the Nerd Fonts GitHub repository and download your preferred font (e.g., Hack or Roboto Mono).
- Follow the installation instructions for your operating system.
- Configure Your Terminal Emulator:
- Open your terminal emulator's preferences/settings.
- Select the installed Nerd Font (e.g., Hack Nerd Font or Roboto Mono Nerd Font) as the font for your terminal.
Now, your Spaceship Prompt should display with the Nerd Font icon you selected.
🎉 Conclusion
You’ve now set up a robust and visually appealing development environment with Zsh, Oh My Zsh, asdf, and the Spaceship Prompt theme, using Zinit for additional plugins. This configuration will enhance your workflow and make managing multiple projects a breeze. Happy coding!
Further Reading 📚:
This article was crafted and tailored with ChatGPT help. 🤖💡
Top comments (2)
Nice but would be nicer if you included the end result screenshots!
You are absolutely right! I will add it! Thanks for the suggestion and commenting