A command line tool for your organisation

by Mathias Vagni on Sunday, 5 Feb 2017

In the last few years as Lyst has grown in team size so have the number of external & internal tools we use.

As a product manager, designer, or engineer, it's become kind of hard to keep track of where all the various apps and dashboards live. Despite actively trying to keep the number down to a minimum we have ended up with too many. Including but not limited to Github, Jira, Confluence, Kibana, Grafana, CircleCI, DockerHub, Looker, Sentry, New Relic, Workable, CharlieHR, 7Geese, 10+ internal dashboards/tools and over 120 different repositories.

As a new starter it sometimes felt a bit like:

omg so many tools

To prevent people from having to maintain loads of bookmarks, or keeping some sort of mega confluence page up-to-date we've instead created a fun little internal tool to help people find things using Chrome's support for custom search engines.

omg so gooood

How it works

It's actually surprisingly simple. Basically, Chrome allows you to point the url bar's search to a custom endpoint. All that the provided endpoint has to do is, given a term, redirect to a different url.

Here's an example of a basic implementation that implements the ability to jump to a specific GitHub repo, jump to the pull requests page of a specific repo, search for gifs, and falls back to Google if you provided something invalid:

const express = require('express');
const app = express();

const commands = {
    repo(args) {
        return `https://github.com/lyst/${args[0]}`;
    },
    pr(args) {
        return `https://github.com/lyst/${args[0]}/pulls/`;
    },
    gif(args) {
        return `https://giphy.com/search/${args.join('-')}/`;
    },
    google(args) {
        return `https://google.co.uk/search?q=${args}`;
    }
};

app.get('/', (req, res) => {

    const query = req.query['q'];
    const [cmd, ...args] = query.split(' ');

    if (commands[cmd]) {
        // Call the custom command with whatever args we got.
        res.redirect(302, commands[cmd](args));
    } else {
        // Fallback to google search
        res.redirect(302, commands.google(query));
    }
});

app.listen(5000, () => {
    console.log('Listening on port 5000');
});

So let's say we have this running on https://localhost:5000/ the next and last step is to tell Chrome to use this as a custom endpoint.

To do this first go to chrome://settings/searchEngines (in Chrome), then

  • Add a custom search endpoint with the name you want to give you search engine,
  • Add a keyboard shortcut. At Lyst we lovingly (and for some unknown reason) call our search service Gandalf, so... we use the letter 'g' as a shortcut.
  • Add the url to your endpoint with the %s as a placeholder for when you want the user search term to be provided. Based on the above example we would want to set it to https://localhost:5000/?q=%s;

That's it. You can now jump straight to a repo using repo <name> or go to a repo's pull requests using pr <repo name>, you can search for gifs gif <search>. And if you just type something else we fall-back to google.

ProTips™

  • Keep the commands abstract (i.e repo <name> instead of gh <name>). This way if you switch CI tool or whatever you don't have to unclear and re-learn a new command.
  • If you find yourself using this a lot, set your custom search as the default in the chrome settings. Making your custom search endpoint the default means you no longer have to type your shortcut first. Only draw-back of doing this is that normal google searches might feel a bit slower since it's first going to your custom search endpoint and then to google.
  • Add a help command that redirects to a page (preferably autogenerated) that outlines the various commands and examples.
  • Overload commands instead of creating loads of individual commands. We for example support j <jira ticket number>, j <jira project board>, or just j which opens 'My Issues' in Jira. This way you keep the total number of commands down and fairly memorable.
comments powered by Disqus