App-sshwrap-hostcolor
view release on metacpan - search on metacpan
view release on metacpan or search on metacpan
script/sshwrap-hostcolor view on Meta::CPAN
#!perl
our $DATE = '2019-07-26'; # DATE
our $VERSION = '0.009'; # VERSION
use 5.010001;
use strict;
use warnings;
use Log::ger;
use App::sshwrap::hostcolor qw(get_history_entry add_history_entry);
use AppLib::sshwrap;
use Getopt::Long qw(:config bundling no_ignore_case);
use XTerm::Util qw(get_term_bgcolor set_term_bgcolor);
my $userhost;
sub parse_cmdline {
local @ARGV = @ARGV;
local $SIG{__WARN__} = sub {};
my %go_spec = map { $_ => sub {} } keys %AppLib::sshwrap::optspec;
delete $go_spec{'{arg}'};
$go_spec{'<>'} = sub {
$userhost //= $_[0];
#log_trace "Setting userhost to %s", $userhost;
};
GetOptions(%go_spec);
}
my $origcolor;
my $env;
sub init {
parse_cmdline();
$origcolor = get_term_bgcolor();
$env = $ENV{SSHWRAP_HOSTCOLOR_AUTO} // '';
}
sub set_hostcolor {
return unless defined $userhost;
my $color = get_history_entry($userhost);
if (defined $color) {
log_info "Using history color '$color' for $userhost";
} elsif ($env eq 'random-dark') {
require Color::RGB::Util;
$color = Color::RGB::Util::rand_rgb_color('000000', '3f3f3f');
log_info "Assigning random dark color '$color' for $userhost";
} elsif ($env eq 'random-light') {
require Color::RGB::Util;
$color = Color::RGB::Util::rand_rgb_color('c0c0c0', 'ffffff');
log_info "Assigning random light color '$color' for $userhost";
}
set_term_bgcolor($color) if defined $color;
}
sub get_hostcolor {
return unless defined $userhost;
my $color = get_term_bgcolor();
if ($color) {
log_info "Remembering host color $userhost -> $color";
add_history_entry($userhost, $color);
}
if ($origcolor) {
set_term_bgcolor($origcolor);
}
}
my $exitcode;
sub run_ssh {
my @cmd = ('ssh', @ARGV);
log_info "Executing ssh: %s", \@cmd;
system {$cmd[0]} @cmd;
$exitcode = $?;
}
### main
log_info "start";
view all matches for this distributionview release on metacpan - search on metacpan
( run in 1.310 second using v1.00-cache-2.02-grep-82fe00e-cpan-f5108d614456 )