diff options
Diffstat (limited to 'go')
-rwxr-xr-x | go | 112 |
1 files changed, 112 insertions, 0 deletions
@@ -0,0 +1,112 @@ +#!/usr/bin/perl + +use strict; +use warnings; +use Sys::Hostname; +#use Gtk2 '-init'; +use Data::Dumper; +use File::Which; +use Text::Iconv; + +my $iconv = Text::Iconv->new("UTF-8", "ISO8859-1"); + +sub read_sites +{ + my @sites; + + open SITES, $ENV{'HOME'}."/.go/sites" or return; + my @file_contents = <SITES>; + foreach ( @file_contents ) { + my %site; + next if /^#|^[[:blank:]]*$/; + + ( $site{'browser'}, $site{'profile'}, $site{'match'} ) = split; + return unless($site{'profile'} =~ /^[\w\d.\-]+$/); + push @sites, \%site; + } + + return @sites; +} + +my $host = hostname(); +my $prefered_browser; +my $browser_command; +my $browser_profile_dir; +my @browser_arguments; +my @sites; + +if($ARGV[0]) { + if($ARGV[0] eq "clip") { +# my $clip = Gtk2::Clipboard->get(Gtk2::Gdk::Atom -> intern("CLIPBOARD", 0)); +# print Dumper($clip); + + my @clipboard = `xclip -out`; + my $clipboard; + + if (scalar( @clipboard ) > 1) { + for my $i ( 0 .. scalar( @clipboard ) - 1 ) { + print "hepp $i\n"; + $clipboard[$i] =~ s/^\+//; + chomp($clipboard[$i]); + } + @browser_arguments = ( join("", @clipboard) ); + } else { + @browser_arguments = @clipboard; + } + + } elsif($ARGV[0] eq "incognito") { + $ENV{'XDG_CONFIG_HOME'} = `/bin/mktemp -d`; + } elsif($ARGV[0] eq "concat") { + shift @ARGV; + if($ARGV[1] eq "clip") { + @browser_arguments = $ARGV[0].`xclip -out`; + } else { + $ARGV[1] = $ARGV[0].$ARGV[1]; + shift @ARGV; + while($ARGV[1]) { + $ARGV[1] = $ARGV[0].'+'.$ARGV[1]; + shift @ARGV; + } + @browser_arguments = @ARGV; + } + } else { + @browser_arguments = @ARGV; + } +} + +if (which('dwb')) { + $prefered_browser = "dwb"; +} else { + $prefered_browser = "chrome"; +} + +@sites = read_sites; +unless(@sites) { + print "Failed reading ~/.go/sites.\n"; + exit(1); +} + +for ( @sites ) { + my %site = %$_; + if(grep(/$site{'match'}/, @browser_arguments)) { + $browser_profile_dir = $site{'profile'} unless $site{'profile'} eq "default"; + if($site{'browser'} eq "default") { + ; + } elsif ($site{'browser'} eq "chrome") { + $prefered_browser = "chrome"; + } + } +} + +if($prefered_browser eq "dwb") { + $browser_command = "dwb"; + unshift @browser_arguments, "--new-instance"; + if($browser_profile_dir) { + unshift @browser_arguments, "--profile=".$browser_profile_dir; + } +} elsif($prefered_browser eq "chrome") { + $browser_command = "chrome"; + unshift @browser_arguments, "--new-window"; +} + +system($iconv->convert($browser_command), @browser_arguments); |