aboutsummaryrefslogtreecommitdiff
path: root/.local/bin
diff options
context:
space:
mode:
authorPatrick Spek <p.spek@tyil.nl>2020-01-19 11:15:20 +0100
committerPatrick Spek <p.spek@tyil.nl>2020-01-19 11:15:20 +0100
commit864874a8a8b1411c919e50683f7ff615ecfbd7be (patch)
tree583cd046cb1158b882895ba19cf8985dda23ae08 /.local/bin
parent34b12a07bbee7c57c1dfea50e0d09507326dda77 (diff)
Make slideshow its own util to allow for aliases
Diffstat (limited to '.local/bin')
-rwxr-xr-x.local/bin/slideshow51
1 files changed, 51 insertions, 0 deletions
diff --git a/.local/bin/slideshow b/.local/bin/slideshow
new file mode 100755
index 0000000..6eefa8f
--- /dev/null
+++ b/.local/bin/slideshow
@@ -0,0 +1,51 @@
+#! /usr/bin/env raku
+
+use v6.d;
+
+#| Start a slideshow of the given directories using feh.
+sub MAIN(
+ #| The directories to include for the slideshow.
+ *@dirs,
+
+ #| Show the command to be executed, and exit. Useful for debugging purposes.
+ Bool:D :$dry-run = False,
+
+ #| The timeout or delay between pictures. Defaults to 5.
+ Int:D :$timeout = 5,
+) {
+ my $aliases-file = $*HOME.add('.local/etc/slideshow/aliases').IO;
+ my $cmd = "feh -zsZ.D $timeout";
+ my @cmd-args;
+ my %aliases;
+
+ # Use aliases if such a configuration is found.
+ if ($aliases-file.f) {
+ $aliases-file
+ .lines
+ .map({
+ my ($key, $value) = $_.words;
+ my $resolved-value = $value
+ .subst('$HOME', $*HOME.absolute)
+ ;
+
+ %aliases{$key}.append: $resolved-value;
+ })
+ }
+
+ for @dirs {
+ # Transform aliases as needed
+ if (%aliases{$_}:exists) {
+ @cmd-args.append(%aliases{$_});
+ next;
+ }
+
+ @cmd-args.append: $_;
+ }
+
+ if ($dry-run) {
+ say "$cmd {@cmd-args}";
+ exit 0;
+ }
+
+ run « $cmd {@cmd-args} »;
+}