1
0
Fork 0
mirror of https://github.com/notwa/rc synced 2024-05-18 17:53:23 -07:00
rc/sh/pause
Connor Olding d5f3f14d72 merge compatibility lines
RIP meaningful last-modified dates
2024-03-26 15:08:14 -07:00

37 lines
1.1 KiB
Bash
Executable File

#!/usr/bin/env sh
# YES_ZSH YES_BASH YES_DASH YES_ASH
### @ pause
### pause — the companion script of [`confirm`.](#confirm)
###
### ```
### $ pause
### Press any key to continue
### $
### ```
if [ -n "$ZSH_VERSION" ]; then
pause() {
[ $# -eq 0 ] || { printf "%s\n" "$0: too many arguments" >&2; return 2; }
local c=
read -sk $'?Press any key to continue\n' c
}
elif [ -n "$BASH_VERSION" ]; then
pause() {
[ $# -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
} 1<>/dev/tty <&1 # ensure this interacts with a terminal instead of a pipe
else
pause() (
[ $# -eq 0 ] || { printf "%s\n" "$0: too many arguments" >&2; return 2; }
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
) 1<>/dev/tty <&1 # ensure this interacts with a terminal instead of a pipe
fi
[ -n "${preload+-}" ] || pause "$@"