Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- # nopaste.pl -- nopaste files from command line
- # Copyright (C) 2006, 2007, Davide Angelocola <davide.angelocola@gmail.com>
- #
- # This program is free software; you can redistribute it and/or
- # modify it under the terms of the GNU General Public License
- # as published by the Free Software Foundation; either version 2
- # of the License, or any later version.
- #
- # This program is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU General Public License for more details.
- #
- # You should have received a copy of the GNU General Public License
- # along with this program; if not, write to the Free Software
- # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
- # USA.
- # usage:
- # nopaste file [description]
- # nopaste <STDIN>
- use App::Nopaste qw(nopaste);
- %ext = (
- # REGEXP language
- 'pl|pm' => 'perl',
- 'cpp|cc|hh' => 'c++',
- 'c|h|y|l' => 'c',
- 'java' => 'java',
- 'py' => 'python',
- 'rb' => 'ruby',
- 'sql' => 'sql',
- 'php' => 'php',
- );
- if ( scalar @ARGV >= 1 ) {
- $file = shift;
- open F, "<$file" or die "$0: $file: $!\n";
- @lines = <F>; # slurp mode
- close F;
- $file =~ /\.(.+)$/; # place extension in $1
- foreach ( keys %ext ) {
- $lang = $ext{$_} if $1 =~ /^($_)$/;
- }
- $desc = shift;
- }
- else {
- @lines = <STDIN>;
- }
- unless ($desc) {
- # using the first non-empty line as description
- foreach (@lines) {
- $desc = $_ and last unless /^$/;
- }
- }
- $lang = 'text' unless $lang;
- my $url = nopaste(
- text => join( "", @lines ),
- desc => $desc,
- nick => $ENV{'USER'},
- lang => $lang,
- copy => 1,
- services => [qw(Rafb Gist Shadowcat )]
- );
- die 'Nopaste Error' unless($url);
- print $url;
Add Comment
Please, Sign In to add comment