Only print prompt if stdin is a tty

If you do use `--install` without =noconfirm via e.g. `echo yes | fish
--install`, this will avoid the prompt.

It will still expect to read a "yes" and error out otherwise.
This commit is contained in:
Fabian Boehm 2024-10-27 10:10:02 +01:00
parent 2c7d2097be
commit 0e6915d522

View File

@ -99,13 +99,15 @@ fn install(confirm: bool) {
// - Install: Manpages (build via build.rs) // - Install: Manpages (build via build.rs)
// - Don't install: __fish_build_paths.fish.in // - Don't install: __fish_build_paths.fish.in
if confirm { if confirm {
eprintln!( if isatty(libc::STDIN_FILENO) {
"This will write fish's data files to '{}'.\n\ eprintln!(
Please enter 'yes' to continue.", "This will write fish's data files to '{}'.\n\
dir.display() Please enter 'yes' to continue.",
); dir.display()
eprint!("> "); );
let _ = stderr().flush(); eprint!("> ");
let _ = stderr().flush();
}
let mut input = String::new(); let mut input = String::new();
if let Err(error) = stdin().read_line(&mut input) { if let Err(error) = stdin().read_line(&mut input) {
@ -113,7 +115,7 @@ fn install(confirm: bool) {
} }
if input != "yes\n" { if input != "yes\n" {
eprintln!("Exiting without writing any files\n"); eprintln!("Exiting without writing any files");
std::process::exit(1); std::process::exit(1);
} }
} else { } else {