2021-09-25 00:17:35 -07:00
|
|
|
#!/usr/bin/env sh
|
2024-07-23 00:04:57 -07:00
|
|
|
# compat: +ash +bash +dash -hush +ksh +mksh -oksh -osh +posh +yash +zsh
|
2021-07-29 00:37:35 -07:00
|
|
|
|
2021-09-25 00:17:35 -07:00
|
|
|
### @ pause
|
|
|
|
### pause — the companion script of [`confirm`.](#confirm)
|
|
|
|
###
|
|
|
|
### ```
|
|
|
|
### $ pause
|
|
|
|
### Press any key to continue
|
|
|
|
### $
|
|
|
|
### ```
|
|
|
|
|
|
|
|
if [ -n "$ZSH_VERSION" ]; then
|
|
|
|
pause() {
|
2021-09-28 12:34:56 -07:00
|
|
|
[ $# -eq 0 ] || { printf "%s\n" "$0: too many arguments" >&2; return 2; }
|
|
|
|
local c=
|
|
|
|
read -sk $'?Press any key to continue\n' c
|
2021-09-25 00:17:35 -07:00
|
|
|
}
|
|
|
|
elif [ -n "$BASH_VERSION" ]; then
|
|
|
|
pause() {
|
2021-09-28 12:34:56 -07:00
|
|
|
[ $# -eq 0 ] || { printf "%s\n" "$0: too many arguments" >&2; return 2; }
|
|
|
|
local c=
|
|
|
|
read -n1 -sp $'Press any key to continue\n' c 2>&1
|
2021-09-28 12:09:32 -07:00
|
|
|
} 1<>/dev/tty <&1 # ensure this interacts with a terminal instead of a pipe
|
2021-09-25 00:17:35 -07:00
|
|
|
else
|
|
|
|
pause() (
|
2021-09-28 12:34:56 -07:00
|
|
|
[ $# -eq 0 ] || { printf "%s\n" "$0: too many arguments" >&2; return 2; }
|
2021-09-25 00:17:35 -07:00
|
|
|
old="$(stty -g)"
|
|
|
|
trap 'stty "$old"' INT EXIT
|
|
|
|
printf 'Press any key to continue\n'
|
|
|
|
stty -icanon -echo
|
|
|
|
dd ibs=1 count=1 2>/dev/null >/dev/null
|
2021-09-28 12:09:32 -07:00
|
|
|
) 1<>/dev/tty <&1 # ensure this interacts with a terminal instead of a pipe
|
2021-09-25 00:17:35 -07:00
|
|
|
fi
|
2021-07-29 00:37:35 -07:00
|
|
|
|
2021-08-02 13:48:46 -07:00
|
|
|
[ -n "${preload+-}" ] || pause "$@"
|