0% complete

Terminal Fun


Section 1

Enhanced Shell

Why should I change my shell?

You don't have to, but there are open source shells A shell is a program that acts as an interface between you and the operating system; you type commands, and it interprets and runs them out there that have really cool functionality to make working from the terminal better.

Modern Macs already works with zsh, while Windows users will want to try this with WSL.

💡 Windows user and don't have WSL? Follow this WSL tutorial. The rest of this tutorial assumes that you have done this and that VS Code can access your WSL.

Install Oh-my-zsh

Copy the installation script from their website.

During the installation, it will ask if you want to make oh-my-zsh your default. Type Y for yes (you can always change your shell in the future).

Choose a shell theme

  1. In your terminal (that should now be oh-my-zsh), open .zshrc with your text editor of choice. E.g. code .zshrc to open with VS Code
  2. On line 11, set ZSH_THEME to "random"
  3. Save your changes

Now, everytime you open a new terminal, the theme will change to something random. It will always tell you what theme is being used, so if you like it, you can set your ZSH_THEME in .zshrc.

  1. Go to oh-my-zsh's themes documentation by clicking here.
  2. Choose a theme that you like
  3. In your terminal (that should now be oh-my-zsh), open .zshrc with your text editor of choice. E.g. code .zshrc to open with VS Code.
  4. On line 11, set ZSH_THEME to your chosen theme.

Explore plugins!

Oh-my-zsh already comes with plugins that are worth exploring. Click here to view their documentation.

To enable these plugins, open .zshrc and on line 73, add the plugins you want to enable. E.g. plugins=(git z sudo)

Built-In Recommendations

Plugin What it does
z Jump to frequently used directories by typing z folder_name
command-not-found Suggests packages when a command isn't found
sudo Double-tap "Esc" to prepend sudo to the last command. Best for Linux/WSL.

Third-party plugins

There are also community, custom plugins people create that you can find through searching online. These will always have installation guides, so follow those carefully. The bellow recommendations can be found if you search for them in context with oh-my-zsh.

Third-party recommendations

Plugin What it does
zsh-autosuggestions Shows ghost-text suggestions as you type
zsh-syntax-highlighting Colors commands as you type
zsh-completions Expands tab completion

Aliases

You can create your own commands that are like mini scripts. For example, you can make zshconfig a command in the terminal that opens .zshrc with VS Code.

Go to your .zshrc and at the bottom of the file, you'll see a commented-out section on aliases. Try adding this line to your config.

.zshrc
alias zshconfig = code ~/.zshrc

SECTION 2

Terminal shortcuts


SECTION 3

Terminal fun

You may have to restart the terminal or reset your computer depending on what you install.

lolcat

Instead of using cat in the terminal to read a simple text file, try installing lolcat. Below are the Mac and Linux/WSL commands.

Mac
brew install lolcat
Linux/WSL
sudo apt install lolcat

tree

This will show you your file system in a hierarchical tree in the terminal.

Mac
brew install tree
Linux/WSL
sudo apt install tree

Terminal Startup Message

Your zsh config file executes line-by-line, so you can have it execute a shell script! Try it out first by copying this line to the botton of your .zshrc file.

.zshrc
echo "Let's get to work!"

Now open up a new terminal and you'll see your welcome message!

Take this a step further and create an ASCII art script as your welcome message.

  1. Create a file called welcome.sh. This is how you typically name script files. Also, make sure you place it in a folder that you can find. Suggestion: make a directory called scripts in your home directory.
  2. Copy and paste the code below into the file.
  3. welcome.sh
    #!/bin/zsh
    
    ascii_art='
    copy paste something here 
    '
    
    while IFS= read -r line; do
        echo "$line" | cat
        sleep 0.008
        done <<< "$ascii_art"
  4. Use an ASCII art generator (or create your own) and copy and paste to ascii_art. The white space in the script file will not be ignored, so make sure the ASCII art looks exactly how you want to see it.
  5. When done, save your file.
  6. Make your script executable by navigating to where it's located in the terminal (The suggestion was that it should be located in ~/scripts). Run chmod +x welcome.sh to change the permissions of the file to executable.
  7. Finally, open .zshrc and add this line to the bottom: bash ~/scripts/welcome.sh. Save, and open up a new terminal!

SECTION 4

Text Editors (besides VS Code)

Always check compatibility because not all open source applications will work seamlessly across Mac and Linux/WSL.

Lesson