Snipplr Ruby Gem, Bringing Snipplr Into the Command Line
Command Line Interface (CLI) has long been my favorite interface when handling code, it makes it easy to edit, search and traverse your code base with tools like vim, find and grep.
Common CLI usage includes the copy and pasting of code snippets. However, keeping track of all those snippets isn’t easy , Snipplr makes the storage and retrieval of snippets easy as pie but requires a Web browser. The Snipplr Ruby Gem is intended to bridge the gap with a simple unified interface. Let’s take for example a scenario on which we would want to get a specific snippet that contains Spring in its title and add it to a file:
null@null:~$ snipplr -l | grep Spring
5459 Spring and Hibernate simple configuration
4667 Spring JMS Template simple configuration
4787 Spring MDP example
The result is a list of entries with their titles and id’s, now we want to append the snippet into an existing file:
null@null:~$ snipplr -g 4787 >> bla.txt
As you can see its quite easy to fetch data, now we’ll see how we can add data into Snipplr for safe keeping:
null@null:~$ snipplr -c -meta ":title=>'Snipplr',:tags=>'Ruby Gem',:language=> 'Ruby'" < hello.rb
The meta tag is a standard Ruby hash notation, notice that its possible to pipe in the content or to use -c ‘your content’.
The last final option is to delete an entry:
null@null:~$ snipplr -d 7338
Installation notes and more info can be found at the Snipplr Ruby Gem page. I hope that it will serve you all with spreading your snippets joy all around.
The Snipplr Ruby Gem was created by Ronen Narkis who blogs about Java and Ruby at Java Development for the Masses.