Skip to content
This repository has been archived by the owner on Sep 28, 2024. It is now read-only.
/ snpt Public archive

A gist powered CLI snippet retriever

License

Notifications You must be signed in to change notification settings

mike182uk/snpt

Repository files navigation

Snpt

Version Build Status Coveralls Go Report Card Downloads License

A gist powered CLI snippet retriever.

Save a snippet as a gist in GitHub, retrieve the snippet on the command line.

Index

Prerequisites

  • GitHub account (duh!)
  • GitHub access token with the gist scope enabled

Installation

Download the binary compatible with your system from here.

Usage

Syncing your snippets

Before you can use Snpt you will need to sync your gists:

snpt sync

If this is the first time you have synced your gists you will be prompted to input a GitHub access token (you will need create this in your GitHub account). This token should be be created with the gist scope enabled.

The sync command will download all of your public and private gists and store them locally for fast retrieval by Snpt.

Copying a snippet to the clipboard

snpt cp [snippetID]

snippetID is an optional parameter. If a snippetID is not supplied a prompt will be displayed allowing you to choose a snippet to copy to the clipboard.

Creating a file from a snippet

snpt write [snippetID]

snippetID is an optional parameter. If a snippetID is not supplied a prompt will be displayed allowing you to choose a snippet to create a file from. The created file will be named after the name of the gist file.

Printing a snippet to the screen

snpt print [snippetID]

snippetID is an optional parameter. If a snippetID is not supplied a prompt will be displayed allowing you to choose a snippet to print to the screen.

Listing available snippets

snpt ls

This can be useful for searching for a specific snippet:

snpt ls | grep <query>

Setting a new GitHub access token

snpt token

This command will prompt you to input a new GitHub access token.

Viewing help for a command

You can view help for a command by passing the -h flag when running a command:

snpt sync -h

Improve your workflow with fuzzy search

Snpt ❤️ fzf

snpt ls | fzf | snpt cp

Speed this up by creating aliases for common usages:

alias cs="snpt ls | fzf | snpt cp"    # cs for copy snippet
alias ws="snpt ls | fzf | snpt write" # ws for write snippet

snpt cp and snpt write both accept stdin as an input. If stdin is detected Snpt will try and extract a snippet ID from it. This is how the above fzf usage works.

Alfred Workflow

The Snpt Alfred Workflow provides quick access to your snippets from Alfred.

Bash completion

If you want bash completion for Snpt, download the file bash_completion to your preferred bash completion location (i.e ~/bash_completion/snpt) and make sure you source this file in your ~/.bashrc or equivalent:

source "$HOME/bash_completion/snpt"

Uninstalling Snpt

To uninstall Snpt from your system you will need to manually delete the Snpt binary.

Snpt's configuration and gist cache is located at ~/.snpt. You can safely remove this directory and its contents once you have removed the Snpt binary.