1
0
Fork 0
mirror of https://github.com/notwa/rc synced 2024-06-28 18:17:11 -07:00
rc/sh/pause

40 lines
967 B
Plaintext
Raw Normal View History

#!/usr/bin/env sh
2021-07-29 00:37:35 -07:00
# YES_ZSH
# YES_BASH
# YES_DASH
# YES_ASH
2021-07-29 00:37:35 -07:00
### @ pause
### pause — the companion script of [`confirm`.](#confirm)
###
### ```
### $ pause
### Press any key to continue
### $
### ```
# known inconsistencies:
# since the fallbacks pipe stderr into stdin,
# this will behave differently between zsh and non-zsh shells:
# ( echo hi | pause | wc -c ) 2>/dev/null
if [ -n "$ZSH_VERSION" ]; then
pause() {
read -sk $'?Press any key to continue\n'
}
elif [ -n "$BASH_VERSION" ]; then
pause() {
read -n1 -sp $'Press any key to continue\n'
} <&2 >/dev/tty # try to ensure this is a terminal instead of a pipe
else
pause() (
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
) <&2 >/dev/tty # try to ensure this is a terminal instead of a pipe
fi
2021-07-29 00:37:35 -07:00
[ -n "${preload+-}" ] || pause "$@"