A linux tool for putting code snippets on your clipboard.
sudo apt install xsel
sudo npm install turingsnip -g
- 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
Each snippet has a template file in EJS syntax, and a JSON configuration 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 %>
This file specifies how the template substitutions are fetched from user input. It should have a .json
extension.
- templateFile - This should be the filename of the template above.
- question - This is the json used by the inquirer library for fetching interactive input from users. Guide for inquirer question syntax
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"
}
]
}