Git Product home page Git Product logo

pet's Introduction

pet : CLI Snippet Manager

GitHub release MIT License

Simple command-line snippet manager, written in Go

Abstract

pet is written in Go, and therefore you can just grab the binary releases and drop it in your $PATH.

pet is a simple command-line snippet manager (inspired by memo). I always forget commands that I rarely use. Moreover, it is difficult to search them from shell history. There are many similar commands, but they are all different.

e.g.

  • $ awk -F, 'NR <=2 {print $0}; NR >= 5 && NR <= 10 {print $0}' company.csv (What I am looking for)
  • $ awk -F, '$0 !~ "DNS|Protocol" {print $0}' packet.csv
  • $ awk -F, '{print $0} {if((NR-1) % 5 == 0) {print "----------"}}' test.csv

In the above case, I search by awk from shell history, but many commands hit.

Even if I register an alias, I forget the name of alias (because I rarely use that command).

So I made it possible to register snippets with description and search them easily.

Main features

pet has the following features.

  • Register your command snippets easily.
  • Search snippets interactively.
  • Run snippets directly.
  • Edit snippets easily (config is just a TOML file).
  • Sync snippets via Gist.

Examples

Some examples are shown below.

Register the previous command easily

By adding the following config to .zshrc, you can easily register the previous command.

$ cat .zshrc
function prev() {
  PREV=$(fc -lrn | head -n 1)
  sh -c "pet new `printf %q "$PREV"`"
}

Select snippets at the current line (like C-r)

By adding the following config to .zshrc, you can search snippets and output on the shell.

$ cat .zshrc
function pet-select() {
  BUFFER=$(pet search --query "$LBUFFER")
  CURSOR=$#BUFFER
  zle redisplay
}
zle -N pet-select
bindkey '^s' pet-select

Copy snippets to clipboard

By using pbcopy on OS X, you can copy snippets to clipboard.

Features

Edit snippets

The snippets are managed in the TOML file, so it's easy to edit.

Sync snippets

You can share snippets via Gist.

Usage

pet - Simple command-line snippet manager.

Usage:
  pet [command]

Available Commands:
  configure   Edit config file
  edit        Edit snippet file
  exec        Run the selected commands
  help        Help about any command
  list        Show all snippets
  new         Create a new snippet
  search      Search snippets
  sync        Sync snippets
  version     Print the version number

Flags:
      --config string   config file (default is $HOME/.config/pet/config.toml)
      --debug           debug mode

Use "pet [command] --help" for more information about a command.

Configuration

run pet configure

[General]
  snippetfile = "path/to/snippet" # specify snippet directory
  editor = "vim"                  # your favorite text editor
  column = 40                     # column size for list command
  selectcmd = "peco"              # selector command for edit command

[Gist]
  file_name = "pet-snippet.toml"  # specify gist file name
  access_token = ""               # your access token
  gist_id = ""                    # Gist ID

Sync

You must obtain access token. Go https://github.com/settings/tokens/new and create access token (only need "gist" scope). Set that to access_token in [Gist].

After setting, you can upload snippets to Gist.

$ pet sync -u
Gist ID: 1cedddf4e06d1170bf0c5612fb31a758
Upload success

Set Gist ID to gist_id in [Gist].

You can download snippets on another PC.

$ pet sync
Download success

Installation

If peco is not installed, please install first (homebrew install peco automatically).

Binaly

Go to the releases page, find the version you want, and download the zip file. Unpack the zip file, and put the binary to somewhere you want (on UNIX-y systems, /usr/local/bin or the like). Make sure it has execution bits turned on.

Mac OS X / Homebrew

You can homebrew on OS X.

$ brew tap knqyf263/pet
$ brew install pet

Build

$ go get github.com/knqyf263/pet

Contribute

  1. fork a repository: github.com/knqyf263/pet to github.com/you/repo
  2. get original code: go get github.com/knqyf263/pet
  3. work on original code
  4. add remote to your repo: git remote add myfork https://github.com/you/repo.git
  5. push your changes: git push myfork
  6. create a new Pull Request

License

MIT

Author

Teppei Fukuda

pet's People

Contributors

firecat53 avatar knqyf263 avatar pborreli avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.