summaryrefslogtreecommitdiffstats
path: root/dmenurl
blob: a275a86e6faabb2fc9d402f45fc3c1398276caed (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/perl
use strict;
# dmenurl - pick and choose url's in the xsel file

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 $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;

  if($what eq 'vertical') {
    return("-l 15");
  }
  else {
    return("");
  }
}

$normal_bg =~ s/^(#)/\\$1/;
$normal_fg =~ s/^(#)/\\$1/;
$select_bg =~ s/^(#)/\\$1/;
$select_fg =~ s/^(#)/\\$1/;

my $dmenu =  "dmenu -i -b $list_mode "
  . "-nb $normal_bg -nf $normal_fg -sb $select_bg -sf $select_fg";


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\.]+)+(:\d+)?(/([\w/_\.]*(\?\S+)?)?)?);) {
    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 -i -l 0|$xclip -o";

system("printf \"$urls_to_print\"|$dmenu -p url|$xclip");