Permalink
Switch branches/tags
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
executable file 69 lines (53 sloc) 1.75 KB
#!/usr/bin/perl
use strict;
my $xsels = "$ENV{XDG_DATA_HOME}/clipbored/clips";
my $font = (exists $ENV{CLIPBORED_DMENU_FONT})
? $ENV{CLIPBORED_DMENU_FONT}
: '-*-fixed-*-*-*-*-15-*-*-*-*-*-*-*';
my $normal_bg = (exists $ENV{CLIPBORED_DMENU_NORMAL_BG})
? $ENV{CLIPBORED_DMENU_NORMAL_BG}
: "#1c1c1c";
my $normal_fg = (exists $ENV{CLIPBORED_DMENU_NORMAL_FG})
? $ENV{CLIPBORED_DMENU_NORMAL_FG}
: "#ffffff";
my $select_bg = (exists $ENV{CLIPBORED_DMENU_SELECT_BG})
? $ENV{CLIPBORED_DMENU_SELECT_BG}
: "#484848";
my $select_fg = (exists $ENV{CLIPBORED_DMENU_SELECT_FG})
? $ENV{CLIPBORED_DMENU_SELECT_FG}
: "#ffffff";
my $x_buffer = (exists $ENV{CLIPBORED_X_SELECTION})
? $ENV{CLIPBORED_X_SELECTION}
: 'primary';
my $list_mode = (exists $ENV{CLIPBORED_DMENU_LISTMODE})
? dmenu_mode($ENV{CLIPBORED_DMENU_LISTMODE})
: dmenu_mode('vertical');
# If defined, we want vertical mode
if(exists($ENV{CLIPBORED_DMENU_LINES})) {
$list_mode = "-l $ENV{CLIPBORED_DMENU_LINES}";
}
sub dmenu_mode {
my $what = shift;
return ($what eq 'vertical') ? '-l 15' : '';
}
s/^(#)/\\$1/ for ($normal_fg, $normal_bg, $select_fg, $select_bg);
my $dmenu = "dmenu -i -b $list_mode"
. " -nb $normal_bg -nf $normal_fg -sb $select_bg -sf $select_fg"
. " -fn $font";
open(my $r_clips, '<', $xsels) or die("Cant open $xsels: $!");
my @cliplist = <$r_clips>;
close($r_clips);
my @urls;
for my $clip(@cliplist) {
if($clip =~ m{(https?://[-/.\w]+)}) {
push(@urls, $1);
}
}
my $urls_to_print = join('\n', reverse(@urls));
chomp(my $xclip = `which xclip`);
do {
print STDERR "No xclip found. Please install.\n";
exit(1);
} if(!defined($xclip));
$xclip = "$xclip -selection $x_buffer -i -l 0|$xclip -o";
system("printf '$urls_to_print'|$dmenu -p url|$xclip");