When working with GCS paths (gs://BUCKET/SOME/OBJECT) in the terminal I often find myself needing to open the corresponding web location (https://console.cloud.google.com/storage/browser/BUCKET/SOME/OBJECT) in a browser. This can be a cumbersome process and needs manual copying and pasting. However, there is a way to streamline this workflow by turning gs:// paths into clickable links in your terminal.

I’ll explain how to achieve this in kitty, my preferred terminal emulator, but similar solutions may work in other terminals.

To enable clickable gs:// links in Kitty, follow these steps:

  1. Edit Kitty’s main configuration file, typically located at ~/.config/kitty/kitty.config, and append “gs” to the list of supported protocols in the “url_prefixes” section:

     url_prefixes http https gs
    
  2. Define the action to be taken when a link is clicked by adding the snippet below to Kitty’s open-actions configuration file. This config is typically located at ~/.config/kitty/open-actions.conf. If the file does not exist by default, create it.

     protocol gs
     action launch --type=background sh -c "echo $URL | awk -F '//' '{print \"https://console.cloud.google.com/storage/browser/\"$2}' | xargs open"
    

    In the above action configuration, the “awk” command extracts the path from the gs:// link and constructs the corresponding URL. The “open” command, is a simple bash script that wraps “xdg-open” and opens the URL in your default browser. Here’s the script content for the “open” command:

     #!/usr/bin/env bash
    
     nohup xdg-open "$1" < /dev/null > /dev/null 2>&1 &
    

    Note that in macOS, the “open” command is already available and can handle URLs directly.