turingsnip

0.3.3 • Public • Published

turingsnip

A linux tool for putting code snippets on your clipboard.

Setup

sudo apt install xsel
sudo npm install turingsnip -g

Usage

  1. Clone an existing snippets folder.
git clone git@github.com:findmypast/turingsnip-titan-snippets.git
  • If the folder is in our home folder called snippets then run this command.

    turingsnip addfolder ~/snippets
  • Create a multi-file snippet with create, make sure you are in the folder where the files should be created.

    turingsnip create component
  • Put a snippet into the clipboard with

    turingsnip clip newcomponent

Creating snippet templates.

Each snippet has a template file in EJS syntax, and a JSON configuration file.

The EJS Template File

The extension should indicate the language for the snippet and not '.ejs'.

For example : newcomponent.js

import React, { Component } from 'react';
import Relay from 'react-relay';

class <%- ComponentName %> extends Component {
  // <%- InterestingList %>
  constructor() {
    super();
  }
  render() {
    return (
      <div><%- SomeBoolean %></div>
    );
  }
}

import React, { Component } from 'react'; import Relay from 'react-relay';

In this example there are three template substitutions

<%- ComponentName %>
<%- InterestingList %>
<%- SomeBoolean %>

The Snippet JSON Configuration File

This file specifies how the template substitutions are fetched from user input. It should have a .json extension.

Properties

newcomponent.json

{
  "templateFiles": {
    "template": "newcomponent.js",
  },
  "questions": [
    {
      "name": "ComponentName",
      "type": "input",
      "default": "<SPECIFYNAMEHERE>",
      "message": "the component name of the blahdeblah"
    },
    {
      "name": "InterestingList",
      "type": "list",
      "choices": [
        "can't code", "social foibles", "doesn't like pizza"
      ],
      "message": "the interesting of the blahdeblah"
    },
    {
      "name": "SomeBoolean",
      "type": "list",
      "choices" : ["true","false"],
      "message": "Select a boolean...because"
    }
  ]
}

Readme

Keywords

none

Package Sidebar

Install

npm i turingsnip

Weekly Downloads

0

Version

0.3.3

License

MIT

Last publish

Collaborators

  • delliott