From 85f37b13c99e91662f40f046927a48e08fd0951b Mon Sep 17 00:00:00 2001 From: Andinus Date: Tue, 10 Nov 2020 13:31:19 +0530 Subject: Reduce dependencies, don't die if directory to unveil doesn't exist --- README | 68 +++++++++++++++++++++++++++++++--------------------------------- cpanfile | 2 -- crux.pl | 51 ++++++++++++++---------------------------------- 3 files changed, 48 insertions(+), 73 deletions(-) diff --git a/README b/README index 9d41258..ba68d67 100644 --- a/README +++ b/README @@ -1,20 +1,19 @@ - _________ - + ━━━━━━━━━ CRUX Andinus - _________ + ━━━━━━━━━ Table of Contents -_________________ +───────────────── -1 Documentation -.. 1.1 Dependencies -.. 1.2 Options -..... 1.2.1 Crux -..... 1.2.2 Unsplash Source -.. 1.3 Cross-platform compatibility +1. Documentation +.. 1. Dependencies +.. 2. Options +..... 1. Crux +..... 2. Unsplash Source +.. 3. Cross-platform compatibility Crux is a wallpaper manager written in Perl, currently it supports @@ -25,18 +24,20 @@ I have previously written [Cetus] which supports /Bing Photo of the Day/ Crux someday. *Tested on*: -- OpenBSD 6.7 - - Perl v5.30 +• OpenBSD 6.8 + • Perl v5.30.3 +• OpenBSD 6.7 + • Perl v5.30 -[Cetus] https://andinus.nand.sh/cetus/ +[Cetus] 1 Documentation -=============== +═══════════════ 1.1 Dependencies -~~~~~~~~~~~~~~~~ +──────────────── `feh' is required to set the background. Other DE/WMs & macOS can be easily supported, if you want it then look at [Cetus]'s source or ping @@ -52,36 +53,33 @@ Crux someday. For example, you can probably remove Carp & replace it with `die', not the same thing but it should work. - *Note*: Do this only if you can't install those dependencies for some - reason. - -[Cetus] https://andinus.nand.sh/cetus/ +[Cetus] 1.2 Options -~~~~~~~~~~~ +─────────── 1.2.1 Crux ----------- +╌╌╌╌╌╌╌╌╌╌ -* 1.2.1.1 debug +◊ 1.2.1.1 debug This will print additional information that'll help you to debug the code. You might see multiple Unveil warnings on non-OpenBSD systems, ignore them. - $response received from the api will also be printed. + `$response' received from the api will also be printed. -* 1.2.1.2 help +◊ 1.2.1.2 help Prints quick help information listing all the options & a small description. 1.2.2 Unsplash Source ---------------------- +╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌ Some options cannot be mixed, if you mix them then expect unexpected results. It won't fail but can return photos that you didn't ask for. @@ -101,16 +99,16 @@ Crux someday. `search' option so read each description. -[Unsplash Source] https://source.unsplash.com +[Unsplash Source] -* 1.2.2.1 resolution +◊ 1.2.2.1 resolution Default is "1920x1080", it doesn't check the value passed so make sure you pass the correct value. This can be passed with any option, it will be ignored if not applicable. -* 1.2.2.2 search +◊ 1.2.2.2 search Search accepts multiple space seperated values. It's passed directly to the api. @@ -122,36 +120,36 @@ Crux someday. equivalent to `--search rocky mountain'. -* 1.2.2.3 featured +◊ 1.2.2.3 featured Only Unsplash curated images are returned if you pass `featured', this can be passed along with `search'. -* 1.2.2.4 user +◊ 1.2.2.4 user This will return a random photo from given user. -* 1.2.2.5 userlikes +◊ 1.2.2.5 userlikes Only returns random photo from user's likes, this is a boolean & can be passed with `user' option. -* 1.2.2.6 collection +◊ 1.2.2.6 collection Returns photos from a collection. -* 1.2.2.7 daily, weekly +◊ 1.2.2.7 daily, weekly This will return a set random daily or weekly image. `user' & `search' option can be passed to narrow the selection. 1.3 Cross-platform compatibility -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +──────────────────────────────── Crux should run on all supported platforms, there is OpenBSD specific code but it's ignored on other platforms. To know more about how this @@ -159,4 +157,4 @@ Crux someday. [Cross-platform compatibility] -https://andinus.nand.sh/projects/cross-platform-compatibility.html + diff --git a/cpanfile b/cpanfile index 35c85c1..fece3a5 100644 --- a/cpanfile +++ b/cpanfile @@ -1,8 +1,6 @@ requires 'lib::relative', '1.000'; requires 'IPC::Run3', '0.048'; requires 'Getopt::Long', '2.5'; -requires 'Term::ANSIColor', '5.01'; -requires 'Data::Printer', '0.40'; requires 'URI', '1.76'; requires 'HTTP::Tiny', '0.076'; requires 'Carp', '1.50'; diff --git a/crux.pl b/crux.pl index acd224c..cadcc6f 100755 --- a/crux.pl +++ b/crux.pl @@ -9,21 +9,18 @@ use UnsplashSource; use IPC::Run3; use Getopt::Long qw( GetOptions ); -use Term::ANSIColor qw( :pushpop colored ); - -local $SIG{__WARN__} = sub { print colored( $_[0], 'yellow' ); }; +use Data::Dumper; my %options = ( resolution => '1920x1080' ); use constant is_OpenBSD => $^O eq "openbsd"; -require OpenBSD::Unveil - if is_OpenBSD; +require OpenBSD::Unveil if is_OpenBSD; sub unveil { if (is_OpenBSD) { - say LOCALCOLOR GREEN "Unveil :: @_" if $options{debug}; + say "Unveil :: @_" if $options{debug}; return OpenBSD::Unveil::unveil(@_); } else { - warn "Dummy unveil :: @_\n" if $options{debug}; + warn "Dummy Unveil :: @_\n" if $options{debug}; return 1; } } @@ -52,14 +49,13 @@ GetOptions( "help|h|?" => sub { HelpMessage() }, ) or die "Error in command line arguments\n"; - sub HelpMessage { - print LOCALCOLOR GREEN "Crux: + say "Crux: --help Print this help message --debug Print debugging information Unsplash Source: - --resolution Device resolution (default: 1920x1080) + --resolution Device resolution (default: $options{resolution}) --search=s Search term (space seperated) --featured Unsplash curated photos @@ -70,21 +66,7 @@ Unsplash Source: --collection=s Photos from collection --daily Daily photo - --weekly Weekly photo -"; - print LOCALCOLOR CYAN " -Additional information: - Options above are seperated by groups, no groups can be mixed. If - you pass options from multiple groups then expect unexpected - results. - - - user & search option can be passed with daily or weekly. - - resolution can be passed with any group, it will be ignored if - not applicable. - - This might be outdated, read the README file for up-to-date - documentation. -"; + --weekly Weekly photo"; exit; } @@ -104,12 +86,7 @@ foreach my $path ( sort keys %unveil ) { } my $response = UnsplashSource::get( %options ); - -if ( $options{debug} ) { - require Data::Printer; - Data::Printer->import; - p($response); -} +print Dumper($response) if $options{debug}; die "Unexpected response\n" unless $response->{status} == 302; @@ -117,11 +94,13 @@ die "Unexpected response\n" # Unveil $PATH. foreach my $path ( split(/:/, $ENV{PATH}) ) { unveil( $path, "rx" ) - or die "Unable to unveil: $!\n"; + or ($! eq "No such file or directory" + # Don't die if the file/directory doesn't exist. + ? next + : die "Unable to unveil: $! :: $path\n"); } -run3 ["feh", "--bg-fill", "$response->{headers}{location}"]; - # Block further unveil calls. -unveil() - or die "Unable to lock unveil: $!\n"; +unveil() or die "Unable to lock unveil: $!\n"; + +run3 ["feh", "--bg-fill", "$response->{headers}{location}"]; -- cgit 1.4.1-2-gfad0