What made me love using terminal

October 19, 2024 (1d ago)

No developer can escape the terminal. It's the one tool that every developer uses, regardless of their tech stack. It's where we run our code, manage our projects, and interact with our tools. So it's important to have a terminal setup that is productive.

Almost equally important is the visual appeal of the terminal. Because let's be honest, no one wants to stare at this all day long:

Mac Native Terminal without any customization

Please Note: I use Mac for both work and play. This post will only focus on products and tools that are available to Mac users

Terminal Emulator: Warp

Warp is one of those modern AI-powered terminals, even though I almost never use its AI stuff. I use it for the Driver feature. Much like a file manager, Warp Drive is a visual interface for your terminal. It allows you to create workflows, notebooks and sort them into collections.

One difficulty I experience when trying to adopt cool, new terminal tool is consistent usage. Especially after some time away, I often forget the correct command, specific syntax, particular flag. With bad or missing --help, it can be a very frustrating experience.

With warp, I can consolidate my usual workflow into collections. With the click of a button, I'd be able to trigger some pre-configured process.

Here's an example of my journal collection. I use jrnl for spontaneous journaling. (Another tool I highly recommend, btw.)

Journal workflow directory in Warp Drive

Individual workflows consist of title, description, commands, and potential arguments.

Example workflow definition

Moreover, you can also create teams on Warp and share your drive with others. If you want to try it out, you can install it with brew install --cask warp.

Shell: Zsh

Good old trusty Oh My Zsh. Configurable, extensible, and powerful. It comes with a lot of plugins and themes that you can use to customize your terminal. Find a complete list of plugins here.

I want to show you some of my favorites:

  • web-search: Allows you to search the web from the terminal. I use it to quickly look up documentation or StackOverflow answers.
  • copyfile and copypath: Copy the content or path of the specified file/directory to the clipboard.
  • history: Allows you to search through your command history.
  • macos: A collection of commands for interacting with macOS. I use it to control apple music from the terminal.

Shell: Aliases

Having a good set of aliases can save you a lot of time. These are my frequently used ones:

alias cls='clear'
alias gs='git status'
alias gsl='git stash list'
alias gsp='git stash pop'
alias gss='git stash save'
alias python='python3'
alias pip='pip3'
alias ca="conda activate"
alias start_pg='brew services start postgresql@16'
alias stop_pg='brew services stop postgresql@16'
alias pg_interactive="psql"
alias pg_status="pg_ctl status"

Tip: For both plugins and aliases, I find it useful to have a quick reference handy. I create a bash script in /usr/local/bin/ called zsh_help that lists all my aliases and plugin usages. I will attach this script at the end of this post.

Quick Reference Doc

Shell: Prompt

After experimenting with a few different prompts, I settled on starship. It's fast, customizable, and easy to set up. Simply install it with brew install starship and add the following line to your .zshrc file:

eval "$(starship init zsh)"

Note: starship is also compatible with other shells.

You can configure it to show information like the current git branch, the current directory, the exit code of the last command, and more.

I personally use Bracketed Segments Preset. Here're some examples of how it looks with different tech stacks:

Starship Prompt Examples

Conclusion

I've found that having a well-configured terminal can make a big difference in productivity. However, there's not one set of configurations that will work for everyone, so I encourage you to experiment and find what works best for you. Hopefully, this post has given you some ideas to get started. Have fun customizing your terminal!

Quick Reference Script as promised

#!/usr/bin/env bash

# Define color codes
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color

# Function to print the header with color
print_header() {
    echo -e "${YELLOW}$1${NC}"
    echo
}

# Function to print usage instructions
print_usage() {
    print_header "Search Terminal History"
    echo -e "Usage: ${GREEN}hsi <term>${NC}\n"

    print_header "Search the Internet"
    echo -e "Usage: ${GREEN}<context> <term> [more terms if you want]${NC}"
    echo -e "Examples:"
    echo -e "    - ${BLUE}google who is the president of the united states${NC}"
    echo -e "    - ${BLUE}stackoverflow how to debug using gdb${NC}"
    echo -e "    - ${BLUE}youtube lady gaga bad romance${NC}\n"

    print_header "Play Apple Music"
    echo -e "Usage: ${GREEN}music <option>${NC}"
    echo -e "Options:"
    echo -e "    ${GREEN}launch|play|pause|stop|rewind|resume|quit${NC}"
    echo -e "    ${GREEN}mute|unmute     Mute or unmute Music${NC}"
    echo -e "    ${GREEN}next|previous   Play next or previous track${NC}"
    echo -e "    ${GREEN}shuf|shuffle [on|off|toggle]    Set shuffled playback. Default: toggle.${NC}"
    echo -e "    ${GREEN}vol [0-100|up|down]     Get or set the volume.${NC}"
    echo -e "        0 to 100 sets the volume."
    echo -e "        'up' / 'down' increases / decreases by 10 points."
    echo -e "        No argument displays current volume."
    echo -e "    ${GREEN}playing|status  Show what song is currently playing in Music.${NC}"
    echo -e "    ${GREEN}playlist [playlist name]         Play specific playlist${NC}\n"

    print_header "Copy File Content"
    echo -e "Usage: ${GREEN}copyfile <filename>${NC}\n"

    print_header "Copy File Path"
    echo -e "Usage:"
    echo -e "    ${GREEN}copypath${NC}: copies the absolute path of the current directory."
    echo -e "    ${GREEN}copypath <file_or_directory>${NC}: copies the absolute path of the given file.\n"

    print_header "Aliases"
    echo -e "- ${GREEN}gsl='git stash list'${NC}"
    echo -e "- ${GREEN}gsp='git stash pop'${NC}"
    echo -e "- ${GREEN}gss='git stash save'${NC}"
    echo -e "- ${GREEN}ca=\"conda activate\"${NC}"
}

# Call the function to print usage instructions
print_usage