Guest User

Untitled

a guest
Jun 18th, 2018
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.90 KB | None | 0 0
  1. #!/usr/bin/perl
  2.  
  3. # nopaste.pl -- nopaste files from command line
  4. # Copyright (C) 2006, 2007, Davide Angelocola <davide.angelocola@gmail.com>
  5. #
  6. # This program is free software; you can redistribute it and/or
  7. # modify it under the terms of the GNU General Public License
  8. # as published by the Free Software Foundation; either version 2
  9. # of the License, or any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with this program; if not, write to the Free Software
  18. # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
  19. # USA.
  20.  
  21. # usage:
  22. # nopaste file [description]
  23. # nopaste <STDIN>
  24.  
  25. use App::Nopaste qw(nopaste);
  26.  
  27. %ext = (
  28.  
  29. # REGEXP language
  30. 'pl|pm' => 'perl',
  31. 'cpp|cc|hh' => 'c++',
  32. 'c|h|y|l' => 'c',
  33. 'java' => 'java',
  34. 'py' => 'python',
  35. 'rb' => 'ruby',
  36. 'sql' => 'sql',
  37. 'php' => 'php',
  38. );
  39.  
  40. if ( scalar @ARGV >= 1 ) {
  41. $file = shift;
  42. open F, "<$file" or die "$0: $file: $!\n";
  43. @lines = <F>; # slurp mode
  44. close F;
  45.  
  46. $file =~ /\.(.+)$/; # place extension in $1
  47. foreach ( keys %ext ) {
  48. $lang = $ext{$_} if $1 =~ /^($_)$/;
  49. }
  50.  
  51. $desc = shift;
  52. }
  53. else {
  54. @lines = <STDIN>;
  55. }
  56.  
  57. unless ($desc) {
  58.  
  59. # using the first non-empty line as description
  60. foreach (@lines) {
  61. $desc = $_ and last unless /^$/;
  62. }
  63. }
  64.  
  65. $lang = 'text' unless $lang;
  66.  
  67. my $url = nopaste(
  68. text => join( "", @lines ),
  69. desc => $desc,
  70. nick => $ENV{'USER'},
  71. lang => $lang,
  72. copy => 1,
  73. services => [qw(Rafb Gist Shadowcat )]
  74. );
  75.  
  76. die 'Nopaste Error' unless($url);
  77. print $url;
Add Comment
Please, Sign In to add comment