about summary refs log tree commit diff
path: root/nixos
diff options
context:
space:
mode:
authorZenithal <i@zenithal.me>2022-01-16 07:53:54 +0800
committerZenithal <i@zenithal.me>2022-01-16 07:54:04 +0800
commit0358703df27cdc2526b7c17701a1da79e4e4ad5b (patch)
tree121e18f9f3fbda5099bf8a061e9bed48f8beb4eb /nixos
parent751d92acb4c1c7af323e7e85a853b1138220182b (diff)
downloadnixlib-0358703df27cdc2526b7c17701a1da79e4e4ad5b.tar
nixlib-0358703df27cdc2526b7c17701a1da79e4e4ad5b.tar.gz
nixlib-0358703df27cdc2526b7c17701a1da79e4e4ad5b.tar.bz2
nixlib-0358703df27cdc2526b7c17701a1da79e4e4ad5b.tar.lz
nixlib-0358703df27cdc2526b7c17701a1da79e4e4ad5b.tar.xz
nixlib-0358703df27cdc2526b7c17701a1da79e4e4ad5b.tar.zst
nixlib-0358703df27cdc2526b7c17701a1da79e4e4ad5b.zip
command-not-found: add interactive option for auto run
Diffstat (limited to 'nixos')
-rw-r--r--nixos/modules/programs/command-not-found/command-not-found.pl11
1 files changed, 11 insertions, 0 deletions
diff --git a/nixos/modules/programs/command-not-found/command-not-found.pl b/nixos/modules/programs/command-not-found/command-not-found.pl
index 220d057b7f4f..af2c606230f4 100644
--- a/nixos/modules/programs/command-not-found/command-not-found.pl
+++ b/nixos/modules/programs/command-not-found/command-not-found.pl
@@ -26,6 +26,17 @@ if (!defined $res || scalar @$res == 0) {
 } elsif (scalar @$res == 1) {
     my $package = @$res[0]->{package};
     if ($ENV{"NIX_AUTO_RUN"} // "") {
+        if ($ENV{"NIX_AUTO_RUN_INTERACTIVE"} // "") {
+            while (1) {
+                print STDERR "'$program' from package '$package' will be run, confirm? [yn]: ";
+                chomp(my $comfirm = <STDIN>);
+                if (lc $comfirm eq "n") {
+                    exit 0;
+                } elsif (lc $comfirm eq "y") {
+                    last;
+                }
+            }
+        }
         exec("nix-shell", "-p", $package, "--run", shell_quote("exec", @ARGV));
     } else {
         print STDERR <<EOF;