-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpause
executable file
·36 lines (33 loc) · 1.1 KB
/
pause
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/env sh
# compat: +ash +bash +dash -hush +ksh +mksh -oksh -osh +posh +yash +zsh
### @ 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 "$@"