There are no ways to detect if the `sudo` command will open a password prompt beforehand, but you can circle that back by taking advantage of the `askpass` feature (see this [answer](https://unix.stackexchange.com/a/692109/407300) for the basis and explanation)

```
sudo_response=$(SUDO_ASKPASS=/bin/false sudo -A whoami 2>&1 | wc -l)
if [ $sudo_response = 2 ]; then
 # Password need to be inserted
 can_sudo=1
elif [ $sudo_response = 1 ]; then
 can_sudo=0
 # Check if currently in sudo timeout, which means no password to insert
 sudo_response=$(SUDO_ASKPASS=/bin/false sudo -A whoami 2>&1)
 # Check if `whoami` is equal to `root`
 if [ sudo_response == "root" ]; then
 can_sudo=2
else
 echo "Unexpected sudo response: $sudo_response" >&2
 exit 1
fi
# can_sudo legend
## 0: Doesn't have sudo permission
## 1: Needs to insert password
## 2: No need to insert password
```

Then, check `can_sudo==1` and provided your terminal supports it, and it is enabled (how it will react depends on the terminal and the DE)

You can use the `BELL` ASCII character, by sending the following command :

```bash
echo -e "\a"
```

It should make the window flash or pop to top depending on DE