junegunn / fzf

:cherry_blossom: A command-line fuzzy finder
https://junegunn.github.io/fzf/
MIT License
62.33k stars 2.35k forks source link

fzf executing before sudo prompts for password #3908

Closed nraiha closed 1 week ago

nraiha commented 1 week ago

Checklist

Output of fzf --version

0.53.0 (c4a9ccd)

OS

Shell

Problem / Steps to reproduce

When fzf is piped to a command requiring sudo, fzf does not wait for sudo prompt to be entered. You can briefly see sudo prompting for the password before an empty fzf window appears.

Additionally, when the fzf window is closed, stdin echo is toggled. If the sudo prompt is canceled, the stdin echo will be toggled again.

sudo echo hi | ./fzf -> terminate with Ctrl-C [sudo] password for nraiha: hunter2 <- the password entry can be now seen. Stdin will now be seen normally.

If sudo prompt is terminated with Ctrl-C, stdin echo will not be toggled.

For example, if I run commands in following order (CTRL-C to fzf and sudo prompt):

sudo echo hi | fzf
pwd
stty echo
echo "now it works"

Terminal will look like:

~
nraiha$ sudo echo hi | fzf
[sudo] password for nraiha: ^C
sudo: a password is required

~
nraiha$
/home/nraiha

~
nraiha$

~
nraiha$ echo "now it works"
now it works
LangLangBart commented 1 week ago

Would the --sync flag solve your issue ?

  --sync Synchronous search for multi-staged filtering. If  specified,  fzf  will  launch  the
    finder only after the input stream is complete.
sudo echo hi | fzf --sync

Alternatively:

sudo echo hi > /tmp/list
fzf < /tmp/list

Ref: https://github.com/junegunn/fzf/issues/2412#issuecomment-809157288