# Gitpod CLI Tips & Tricks
 by [Mads Hartmann](https://blog.mads-hartmann.com/index.md) - 19 Dec 2023 

Gitpod just released a proper CLI 🥳 You can read more about it in [Take Gitpod to your local command line](https://www.gitpod.io/changelog/gitpod-cli).

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](https://cli.github.com), [fzf](https://github.com/junegunn/fzf), and [gitpod](https://www.gitpod.io/docs/references/gitpod-cli) to cover most of my daily workflows.

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

## new

![Terminal picker for creating a Gitpod workspace from a repository](https://blog.mads-hartmann.com/images/responsive/gitpod-cli/new-640.webp)

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

![Terminal picker for opening a pull request in Gitpod](https://blog.mads-hartmann.com/images/responsive/gitpod-cli/gppr-640.webp)

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

![Terminal picker for opening an existing Gitpod workspace](https://blog.mads-hartmann.com/images/responsive/gitpod-cli/gpo-640.webp)

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

![Terminal picker for deleting selected Gitpod workspaces](https://blog.mads-hartmann.com/images/responsive/gitpod-cli/gpgc-640.webp)

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 {}
}
```


---

Canonical page: https://blog.mads-hartmann.com/2023/12/19/gitpod-cli.html
