Code Monkey home page Code Monkey logo

snipper's Introduction

What?

There are many snippet tools around, I love pastie.org and have on and off used many others. The problem is they are all web based and as with some of my other recent tools I am just not web based.

Additionally these tend to be hosted elsewhere, closed source and for something like a paste tool I really want to be able to hack on it.

There are many self hosted ones with awesome features but I couldn't find one in Ruby - see my earlier comment about being able to hack on it. This is a non functional requirement that I could not find met in any other tool so I wrote one.

This code snippet tool is different:

  • You self host it
  • It is strictly single user
  • Its data files live in your home directory in ~/.snipper
  • You can only add/edit/remove snippets through the CLI
  • You can only search for snippets on the CLI
  • The web component is just a pure static set of files, you could host them anywhere

These are its goals, do not ask about a web interface, do not send me pull requests about any kind of way to maintain the snippets through the web or about multi user support etc, this is not that paste service.

As the code stands now is very early days, it really is just a few idle hours of hacking to get here. I want to make the HTML output configurable and bunch of other things and will do so as time goes by and I use it more. Early adopters and feedback welcome.

A screenshot of a snippet is in the example directory of the git repo

Installation?

You need to get http://pygments.org/ on your system, I am not going to cover how to do this.

Create a directory in your home directory called ~/.snipper and place a config file called ~/.snipper/config.yml in it along these lines:

---
:grep: grep --color=auto -riHn -C 2 '%Q%' *
:baseurl: http://yoursite.com/prefix
:default_syntax: ruby
:public_target_dir: /where/your/site/lives
:theme: monokai
:dark_theme: true

The public_target_dir is where the static HTML will be built, this could presumably even be a dropbox folder so your machine do not need to be always on, you can just (ab)use their shared folder urls.

Create the public_target_dir and do something like:

$ mkdir /where/your/site/lives/css
$ for i in `pygmentize -L styles|grep '^\*'|sed -r "s%(\\* |:)%%g"`
  do
    pygmentize -S $i -f html > /where/your/site/lives/css/$i.css
  done

This creates the CSS for every Pygments theme that you configure in the config.yml

Now install the snippet gem :

$ export GEM_HOME=/home/you/.gem
$ PATH=$PATH:/home/you/.gem/bin
$ gem install snipper

Copy the additional css for the page background :

$ cp ~/.gem/gems/snipper-*/css/*.css /where/your/site/lives/css/

And you're good to go.

Basic Usage?

Everything you do with snippets you do from the command line.

Adding a new snippet

$ cat test.txt|snipper
http://baseurl/123

You have a new snippet and the URL is based on your config, the snippet id is 123. The snippet has one file in it.

You can add a 2nd file to the snippet, lets say this is a Perl file

$ cat test.pl|snipper 123 -l perl
http://baseurl/123

You could also create a new snippet with multiple files in one go:

$ snipper foo.pl foo.rb
http://baseurl/124

In this case it will guess from the file extensions that they are Ruby and Perl files

Editing a snippet

Editing snippets is done using your text editor of choice, vim unless you set EDITOR in your shell.

$ snipper e 124
# edit your files
http://baseurl/124

When you edit it will simply pass the list of files to edit in a row to your editor, edit, save move to the next one will your done or quit your editor mid way through that's totally up to you.

If you zero a file that file will be removed from the snippet.

Snippets can have some meta data associated with them, you'll notice when you open one there might be a few header lines like:

## description: foo
## lang: perl

snippet here

You can tweak descriptions, languages etc there. There's a pastie.org inspired shortcut for descriptions:

## your description here

snippet here

Once you save it the static html gets rebuilt and you're shown the URL again.

Deleting a snippet

Deleting is simple, this removes the source snippet and the static html

$ snipper d 124
Removing /home/you/.snipper/snippets/124
Removing /where/your/site/lives/124

Searching for snippets

Searching is done by default with grep, you can configure that though, by default it will do grep colors and all that.

$ snipper s ruby
1/1-1-
1/1:2:require 'rubygems'
1/1-3-require 'uv'
1/1-4-require 'optparse'
--
3/2-50-                syntax = lexer.name
3/2-51-              else
3/2:52:                syntax = Config[:default_syntax] || "ruby"
3/2-53-              end
3/2-54-            end

The numbers is from grep but this basically means it found matches in snippets 1 and 3. In snippet 1 the match was in the 1st file and for snippet 3 it was in the 2nd file contained in that snippet.

Viewing snippets on the CLI

You can view a snippet easily, this just cats them into your PAGER

$ snipper v 124
# less is run with your snippet visible

Seeing supported languages

You can see what Pygments support by just running:

$ snipper -L
Pygments version 1.4, (c) 2006-2008 by Georg Brandl.

Lexers:
~~~~~~
* Cucumber, cucumber, Gherkin, gherkin:
    Gherkin (filenames *.feature)
etc
etc
etc

Rebuild the gem

In the root folder of the project :

rake gem

You should find the gem in the subfolder pkg.

Contact?

R.I.Pienaar / [email protected] / @ripienaar / http://devco.net/

snipper's People

Contributors

ripienaar avatar

Stargazers

Mike avatar Sergey Bronnikov avatar Doug avatar Todd Eddy avatar Sidney de Koning avatar hsiss avatar Greg Work avatar Timur Batyrshin avatar Brian Staszewski avatar Felipe Coury avatar

Watchers

 avatar James Cloos avatar Dominik Zyla avatar  avatar

Forkers

vhata timurb

snipper's Issues

Could not save snippet: TypeError: can't convert nil into Integer

This is my ~/.snipper/config.yml:

---
:grep: grep --color=auto -riHn -C 2 '%Q%' *
:baseurl: http://localhost/snipper
:default_syntax: php
:public_target_dir: /var/www/snipper
:theme: monokai
:dark_theme: true

and this is my test code:

<?php
$md = new \Sundown\Markdown(\Sundown\Render\HTML);
echo $md->render("### Hello");

But when I run: cat ~/temp/t.php |snipper, I got error:

Could not save snippet: TypeError: can't convert nil into Integer
/home/jaya/.rvm/gems/ruby-1.9.3-p194/gems/snipper-0.0.7/lib/snipper/snippet.rb:141:in `Integer': can't convert nil into Integer (TypeError)
    from /home/jaya/.rvm/gems/ruby-1.9.3-p194/gems/snipper-0.0.7/lib/snipper/snippet.rb:141:in `next_snippet_id'
    from /home/jaya/.rvm/gems/ruby-1.9.3-p194/gems/snipper-0.0.7/lib/snipper/snippet.rb:17:in `initialize'
    from /home/jaya/.rvm/gems/ruby-1.9.3-p194/gems/snipper-0.0.7/lib/snipper/util.rb:39:in `new'
    from /home/jaya/.rvm/gems/ruby-1.9.3-p194/gems/snipper-0.0.7/lib/snipper/util.rb:39:in `new'
    from /home/jaya/.rvm/gems/ruby-1.9.3-p194/gems/snipper-0.0.7/bin/snipper:27:in `add'
    from /home/jaya/.rvm/gems/ruby-1.9.3-p194/gems/thor-0.16.0/lib/thor/task.rb:27:in `run'
    from /home/jaya/.rvm/gems/ruby-1.9.3-p194/gems/thor-0.16.0/lib/thor/invocation.rb:120:in `invoke_task'
    from /home/jaya/.rvm/gems/ruby-1.9.3-p194/gems/thor-0.16.0/lib/thor.rb:275:in `dispatch'
    from /home/jaya/.rvm/gems/ruby-1.9.3-p194/gems/thor-0.16.0/lib/thor/base.rb:425:in `start'
    from /home/jaya/.rvm/gems/ruby-1.9.3-p194/gems/snipper-0.0.7/bin/snipper:99:in `<top (required)>'
    from /home/jaya/.rvm/gems/ruby-1.9.3-p194/bin/snipper:19:in `load'
    from /home/jaya/.rvm/gems/ruby-1.9.3-p194/bin/snipper:19:in `<main>'
    from /home/jaya/.rvm/gems/ruby-1.9.3-p194/bin/ruby_noexec_wrapper:14:in `eval'
    from /home/jaya/.rvm/gems/ruby-1.9.3-p194/bin/ruby_noexec_wrapper:14:in `<main>'

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.