, March 04, 2021

0 results found in this keyword

Zsh + Zgen

  •   3 min reads
Zsh + Zgen

We <3 shellz

What's a shell? It is an interface to interact with computer services and systems. Examples of a shell are bash, sh, and zsh. These interfaces use PATH to load up binaries with make up the commands you can run in your terminal. You can check out /usr/local/bin to check out some of the binaries which make up shell commands.

The shell is accessed by opening a Terminal app. Out of the box Fedora comes with Gnome Terminal and I like to swap it out for Terminator.

sudo dnf install terminator

The next thing is getting Zsh installed and hook it up with some plugins and a sweet theme. The cool kid on the block for shells is Zsh and the first thing is to get it installed. When it comes to Fedora you want to run a dnf install but this will vary depending on your system.

sudo dnf install zsh
chsh -s $(which zsh)

You can check out your home directory for a .zshrc file. This is the file that now controls your shell environment default settings. You can setup plugins, aliases, and other items you need to run every time you open a terminal.

For easy setup I default to zgen. It makes install plugins and themes really easy. https://github.com/tarjoilija/zgen

Check the bottom of the read me for their example zshrc file. Back up your current zshrc file and then create a new one with the example and modify it to remove the example lines. I move the plugin from the bulk load into the /path/to/super-secret-private-plugin section and delete the EOF section (EOFs are ugly sorry not sorry).

# load zgen
source "${HOME}/.zgen/zgen.zsh"

# if the init scipt doesn't exist
if ! zgen saved; then
    echo "Creating a zgen save"

    zgen oh-my-zsh

    # plugins
    zgen oh-my-zsh plugins/git
    zgen oh-my-zsh plugins/sudo
    zgen oh-my-zsh plugins/command-not-found
    zgen load zsh-users/zsh-syntax-highlighting
    zgen load zsh-users/zsh-history-substring-search

    # completions
    zgen load zsh-users/zsh-completions src

    # theme
    zgen oh-my-zsh themes/arrow

    # save all to init script
    zgen save

Take yourself through the interwebz and find a nice theme for zsh. I like to use this one. https://github.com/denysdovhan/spaceship-prompt

Check the readme and look for the zgen section and copy it over to zshrc file replacing the theme section at the bottom.

zgen init
zgen update

Restart your shell and you should be good to go.

The last thing for someone really diving into this is to customize the plugins you use. Check out this page for the cool things you can add to your shell.

🙃 A delightful community-driven (with 1700+ contributors) framework for managing your zsh configuration. Includes nearly 300 optional plugins (rails, git, OSX, hub, capistrano, brew, ant, php, pyt...

Cool points, back up your zshrc you've customized to a github gist for later use.

Custom Setup

I work on multiple google accounts on my linux setup so its a plus to be able to see which gcloud account I am using. The cloud and the name represent that. I also do most of my work on kubernetes so the indicator on the right will show minikube or the k8 cluster I am currently hooked into with kubectx. An example of the zshrc config to achieve this.

autoload -U colors; colors

  time          # Time stampts section
  user          # Username section
  host          # Hostname section
  dir           # Current directory section
  git           # Git section (git_branch + git_status)
  hg            # Mercurial section (hg_branch  + hg_status)
  package       # Package version
  node          # Node.js section
  ruby          # Ruby section
  elixir        # Elixir section
  xcode         # Xcode section
  swift         # Swift section
  golang        # Go section
  php           # PHP section
  rust          # Rust section
  haskell       # Haskell Stack section
  julia         # Julia section
  docker        # Docker section
  gcloud        # Gcloud section
  aws           # Amazon Web Services section
  venv          # virtualenv section
  conda         # conda virtualenv section
  pyenv         # Pyenv section
  dotnet        # .NET section
  ember         # Ember.js section
  kubectl   # Kubectl context section
  exec_time     # Execution time
  line_sep      # Line break
  battery       # Battery level and status
  vi_mode       # Vi-mode indicator
  jobs          # Backgound jobs indicator
  exit_code     # Exit code section
  char          # Prompt character

If you have any questions, tips, or tricks please comment below.

Related News

You've successfully subscribed to Devops Miami Blog
Great! Next, complete checkout for full access to Devops Miami Blog
Welcome back! You've successfully signed in
Success! Your account is fully activated, you now have access to all content.
Success! Your billing info is updated.
Billing info update failed.
Your link has expired.