In Bash, how to add “Are you sure [Y/n]” to any command or alias?

In this particular case, I’d like to add a confirm in Bash for

Are you sure? [Y/n]

for Mercurial’s hg push ssh://username@www.example.com//somepath/morepath, which is actually an alias. Is there a standard command that can be added to the alias to achieve it?

The reason is that hg push and hg out can sound similar and sometimes when I want hgoutrepo, I may accidentlly type hgpushrepo (both are aliases).

Update: if it can be something like a built-in command with another command, such as: confirm && hg push ssh://... that’d be great… just a command that can ask for a yes or no and continue with the rest if yes.

19 Answers
19

Leave a Comment