Skip to content

Instantly share code, notes, and snippets.

@xtetsuji
Created March 18, 2019 07:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xtetsuji/75edada3a55cb29ce2acecdd171e1826 to your computer and use it in GitHub Desktop.
Save xtetsuji/75edada3a55cb29ce2acecdd171e1826 to your computer and use it in GitHub Desktop.
inurl - open URLs in the default browser, URLs are choiced from STDIN by peco
#!/usr/bin/env perl
# 2019/03/14
# inurl - 標準入力を peco に渡して、URL がある行を選択するとその URL をブラウザで開く
use strict;
use warnings;
use IPC::Open2;
my (@url, $child_out, $child_in);
open2 $child_out, $child_in, 'peco';
while (<>) {
print {$child_in} $_;
}
close $child_in;
while (<$child_out>) {
chomp;
if ( m{https?://\S+}p ) {
system 'open', ${^MATCH};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment