Gitpod CLI Tips & Tricks

by Mads Hartmann - 19 Dec 2023

Gitpod just released a proper CLI 🥳 You can read more about it in Take Gitpod to your local command line.

I’ve been testing the CLI for quite a while internally and really love it. I’ve been having a lot of fun combining gh, fzf, and gitpod to cover most of my daily workflows.

Here are some of my favorite little scripts form my ~/.zshrc

new

This allows me to type new in my terminal to get an interactive picker with my most commonly used repositories. The real list is longer but I’ve redacted a few private repositories 😉

function new {
  if [[ "${1:-}" == "" ]];
  then
    {
    echo "https://github.com/gitpod-io/gitpod"
    echo "https://github.com/mads-hartmann/gitpod-dotfiles"
    echo "https://github.com/mads-hartmann/mads-hartmann.com"
    } \
    | fzf \
    | xargs -0 gitpod workspace create --open --editor code-desktop
  else
    gitpod workspace create --open --editor code-desktop "$1"
  fi
}

gppr

Short for Gitpod PR. This uses gh to list all my open PRs and then opens a Gitpod workspace from that context. I use this all the time as I usually create DRAFT PRs really early and use them to keep track of the work I have in flight.

function gppr {
  gh api -X GET search/issues -f q="is:open is:pr author:@me archived:false" --jq '.items[].html_url' \
  | fzf --preview 'gh pr view {}' \
  | xargs -0 gitpod workspace create --open --editor code-desktop
}

gpo

Short for Gitpod Open. This lists all Gitpod workspaces and provides a quick way to filter and open a specific one. I mostly use this if I stopped a workspace before heading out for launch and I want to start that same workspace rather than create a new one.

function gpo {
  gitpod workspace list -r -f id \
  | fzf --preview 'gitpod ws get {}' \
  | tr -d '\n' \
  | xargs -0 gitpod workspace open
}

gpgc

Short for Gitpod Garbage Collect. This is a quick way to clean up in my list of workspaces. For this I use the fzf feature of hitting tab to select multiple entries.

function gpgc {
  gitpod workspace list -f id \
  | fzf -m --preview 'gitpod ws get {}' \
  | xargs -I{} gitpod workspace delete {}
}