โ† All articles

Getting started with script commands

Mira Castell ยท 1 min read

Developers spend a lot of time in small, repetitive tasks: opening the same pages, running the same commands, copying the same values. Script commands let you turn any script into a command you can run from Vectra.

What can Vectra do with scripts?

A script command is a file with a few comment lines at the top that describe it. Vectra reads those lines and turns the script into a command with a title, an icon and optional arguments.

Let's take a look at a small but useful script. Checking pull requests on a busy project usually goes like this:

  1. Open your browser

  2. Click in the search bar

  3. Type the repository address

  4. Load the page

  5. Open the pull requests tab

With a script command, it is a single keystroke:

#!/bin/bash

# Required parameters:
# @vectra.schemaVersion 1
# @vectra.title Open Pull Requests
# @vectra.mode silent
# @vectra.icon ๐Ÿ”€

# Optional parameters:
# @vectra.packageName Developer Utils

open "https://git.example.com/acme/app/pulls"
Assigning a hotkey
Assigning a hotkey to a script command.

So far, so good!

Let's go further and show the open pull requests right in Vectra, using the inline mode and a refresh interval.

#!/usr/bin/env ruby

# @vectra.schemaVersion 1
# @vectra.title Open Pull Requests
# @vectra.mode inline
# @vectra.refreshTime 5m

require "json"
require "net/http"

uri = URI("https://git.example.com/api/repos/acme/app/pulls")
pulls = JSON.parse(Net::HTTP.get(uri))
puts "#{pulls.size} open ยท oldest #{pulls.last["age"]}"
  1. The refreshTime parameter tells Vectra to rerun the script every five minutes.

  2. The inline mode prints the first line of output right in the root search.

Let's wrap up

By spending a few minutes putting together scripts for your common workflows, you can make your day noticeably smoother. Browse the community repository for more examples, and share your own.

0 comments

  • Be the first to comment.