6 use String
::ShellQuote
;
9 my $program = $ARGV[0];
11 my $dbPath = "@dbPath@";
13 my $dbh = DBI
->connect("dbi:SQLite:dbname=$dbPath", "", "")
14 or die "cannot open database `$dbPath'";
15 $dbh->{RaiseError
} = 0;
16 $dbh->{PrintError
} = 0;
18 my $system = $ENV{"NIX_SYSTEM"} // $Config{myarchname
};
20 my $res = $dbh->selectall_arrayref(
21 "select package from Programs where system = ? and name = ?",
22 { Slice
=> {} }, $system, $program);
24 my $len = !defined $res ?
0 : scalar @
$res;
27 print STDERR
"$program: command not found\n";
29 my $package = @
$res[0]->{package};
30 if ($ENV{"NIX_AUTO_RUN"} // "") {
31 if ($ENV{"NIX_AUTO_RUN_INTERACTIVE"} // "") {
33 print STDERR
"'$program' from package '$package' will be run, confirm? [yn]: ";
34 chomp(my $comfirm = <STDIN
>);
35 if (lc $comfirm eq "n") {
37 } elsif (lc $comfirm eq "y") {
42 exec("nix-shell", "-p", $package, "--run", shell_quote
("exec", @ARGV));
45 The program '$program' is not in your PATH. You can make it available in an
46 ephemeral shell by typing:
51 if ($ENV{"NIX_AUTO_RUN"} // "") {
52 print STDERR
"Select a package that provides '$program':\n";
53 for my $i (0 .. $len - 1) {
54 print STDERR
" [", $i + 1, "]: @$res[$i]->{package}\n";
57 while (1) { # exec will break this loop
58 no warnings
"numeric";
59 print STDERR
"Your choice [1-${len}]: ";
60 # 0 can be invalid user input like non-number string
62 $choice = <STDIN
> + 0;
63 if (1 <= $choice && $choice <= $len) {
64 exec("nix-shell", "-p", @
$res[$choice - 1]->{package},
65 "--run", shell_quote
("exec", @ARGV));
70 The program '$program' is not in your PATH. It is provided by several packages.
71 You can make it available in an ephemeral shell by typing one of the following:
73 print STDERR
" nix-shell -p $_->{package}\n" foreach @
$res;