From a2719e8c433cf9d0a8dc13de0e0bd7c6a730a316 Mon Sep 17 00:00:00 2001 From: John Mertz Date: Thu, 19 Oct 2023 12:40:50 -0600 Subject: [PATCH] Create simplified `flatpak run` script --- sway/flatpak-run.pl | 62 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100755 sway/flatpak-run.pl diff --git a/sway/flatpak-run.pl b/sway/flatpak-run.pl new file mode 100755 index 0000000..0d8943a --- /dev/null +++ b/sway/flatpak-run.pl @@ -0,0 +1,62 @@ +#!/usr/bin/env perl +# Simplify `flatpak run` + +use strict; +use warnings; +use v5.36; + +my $input = shift(@ARGV) || die("Requires at least 1 argument\n"); + +my @list = split(/\n/, `flatpak list`); +shift(@list); +my %apps; +for my $line (@list) { + my ($name, $id, $version, $branch) = split(/\t/, $line); + next if ($id =~ /\b(Platform|Codecs)\b/); + $apps{$name} = $id; +} + +# Exact name match first +run($apps{$input}, @ARGV) if (defined($apps{$input})); + +# Case-insensitive name match next +foreach (keys(%apps)) { + print("Case-insensitive name match\n") if ($_ =~ m/^$input$/i); + run($apps{$_}, @ARGV) if ($_ =~ m/^$input$/i); +} + +# Exact final id stanza next +foreach (keys(%apps)) { + print("Exact id match\n") if ($apps{$_} =~ m/\.$input$/); + run($apps{$_}, @ARGV) if ($apps{$_} =~ m/\.$input$/); +} + +# Case-insensitive final id stanza next +foreach (keys(%apps)) { + print("Case-insensitive id match\n") if ($apps{$_} =~ m/\.$input$/i); + run($apps{$_}, @ARGV) if ($apps{$_} =~ m/\.$input$/i); +} + +# Fuzzy name match +foreach (keys(%apps)) { + print("Fuzzy name match\n") if ($_ =~ m/$input/i); + run($apps{$_}, @ARGV) if ($_ =~ m/$input/i); +} + +# Fuzzy id match +foreach (keys(%apps)) { + print("Fuzzy id match\n") if ($apps{$_} =~ m/$input/i); + run($apps{$_}, @ARGV) if ($apps{$_} =~ m/$input/i); +} + +sub run($id, @args) +{ + printf("Running $id ".join(' ',@args)."\n"); + my $pid = fork(); + if ($pid) { + exit(); + } else { + system("/usr/bin/flatpak run $id ".join(' ', @args)); + exit(); + } +}