Skip to content

Instantly share code, notes, and snippets.

@heapwolf
Last active March 8, 2017 16:06
Show Gist options
  • Save heapwolf/f4eedc8f02bb2e6a59c7 to your computer and use it in GitHub Desktop.
Save heapwolf/f4eedc8f02bb2e6a59c7 to your computer and use it in GitHub Desktop.
Download and show image in terminal (iterm2 only)
#!/bin/bash
function print_image() {
printf "\033]"
printf "1337;File="
echo -n "$1" | base64 -D | wc -c | awk '{printf "size=%d",$1}'
printf ";inline=1:"
echo -n "$1"
printf "\a\n"
}
re='(https?)://[-A-Za-z0-9\+&@#/%?=~_|!:,.;]*[-A-Za-z0-9\+&@#/%=~_|]\.(png|jpg|gif|jpeg)'
if [[ $1 =~ $re ]]
then
print_image "$(curl -vs "$1" 2>/dev/null | base64)"
exit 0
else
exit 1
fi
@heapwolf
Copy link
Author

heapwolf commented Jan 6, 2016

INTEGRATION

IRSSI

#!/usr/bin/perl -w
use strict;
use Irssi;
use vars qw($VERSION %IRSSI);
$VERSION = "0.2";
%IRSSI = (
  authors     => 'Paolo Fragomeni',
  contact     => 'paolo@async.ly',
  name        => 'images',
  description => 'replace image urls with actual images inline.',
  license     => 'MIT',
  url         => '/',
);

my $lasturl;

sub listen_image_urls {
  my($server, $text, $nick, $address, $channel)=@_;
  my $url = find_url($text);
  rewrite($text, $nick, $address, $channel, $url) if defined $url;
}

sub find_url {
  my $text = shift;
  if ($text =~ /((https?):\/\/[a-zA-Z0-9\/\\\:\?\%\.\&\;=#\-\_\!\+\~]*)\.(png|jpg|gif|jpeg)/i) {
    return $1;
  }
  return undef;
}

sub rewrite {
  my($text, $nick, $address, $channel, $url) = @_;
  return if lc $url eq lc $lasturl;
  my ($target, $msg) = split(/ :/, $text, 2);

  my $replacement = `iccat.sh $url`;
  Irssi::signal_emit('event privmsg', ($server, "$target :$replacement", $nick, $address));
  Irssi::signal_stop();
}

Irssi::signal_add("event privmsg", "listen_image_urls");

@dannymichel
Copy link

I'm sorry, I'm trying to figure out where i'd put this and how i'd run this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment