forked from romkatv/zsh-bench
-
Notifications
You must be signed in to change notification settings - Fork 0
/
human-bench
executable file
·105 lines (91 loc) · 3.19 KB
/
human-bench
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/usr/bin/env zsh
'builtin' 'emulate' '-L' 'zsh' '-o' 'no_aliases' '-o' 'err_return' || 'builtin' 'exit'
setopt no_unset typeset_silent prompt_percent no_prompt_subst warn_create_global
() {
if [[ ${ZSH_VERSION-} != (5.<8->*|<6->.*) ]]; then
print -ru2 -- "${ZSH_SCRIPT:t}: zsh >= 5.8 is required to execute this script"
return 1
fi
zmodload zsh/datetime
function usage() {
print -r -- "usage: ${ZSH_SCRIPT:t} [OPTION].."
print -r --
print -r -- 'OPTIONS'
print -r -- ' -h,--help'
print -r -- ' -s,--shell-command <STR> [default="zsh"]'
print -r -- ' -f,--first-prompt-lag-ms <NUM> [default=0]'
print -r -- ' -c,--first-command-lag-ms <NUM> [default=0]'
print -r -- ' -p,--command-lag-ms <NUM> [default=0]'
print -r -- ' -i,--input-lag-ms <NUM> [default=0]'
print -r --
print -r -- 'Latency options can be specified more than once.'
}
zmodload zsh/zutil
local -a help shell_command=(_ zsh)
local -a first_prompt_lag_ms first_command_lag_ms command_lag_ms input_lag_ms
zparseopts -D -K -F -- \
{h,-help}=help {s,-shell-command}:=shell_command \
{f,-first-prompt-lag-ms}+:=first_prompt_lag_ms \
{c,-first-command-lag-ms}+:=first_command_lag_ms \
{p,-command-lag-ms}+:=command_lag_ms \
{i,-input-lag-ms}+:=input_lag_ms
if (( ARGC )); then
print -ru2 -- "${ZSH_SCRIPT:t}: unexpected positional argument"
return 1
fi
if (( $#help )); then
usage
return
fi
local _ x
for _ x in "${(@)first_prompt_lag_ms}" \
"${(@)first_command_lag_ms}" \
"${(@)command_lag_ms}" \
"${(@)input_lag_ms}"; do
if [[ $x != <->(|.<->) ]]; then
print -ru2 -- "${ZSH_SCRIPT:t}: not a non-negative real number: ${(q-)x}"
return 1
fi
done
if [[ -v ZDOTDIR ]]; then
export _ZB_ORIG_ZDOTDIR=$ZDOTDIR
fi
export ZDOTDIR=${ZSH_SCRIPT:h}/internal/zdotdir
while true; do
print -Prn -- "%F{3}Start zsh? [Y/n]:%f "
local choice
IFS= read -r choice
[[ $choice == (|y|Y|yes|Yes|YES) ]] || return 0
export _ZB_START_TIME_SEC=$EPOCHREALTIME
if (( $#first_prompt_lag_ms )); then
export _ZB_FIRST_PROMPT_LAG_MS=${first_prompt_lag_ms[2 * (RANDOM % ($#first_prompt_lag_ms / 2) + 1)]}
fi
if (( $#first_command_lag_ms )); then
export _ZB_FIRST_COMMAND_LAG_MS=${first_command_lag_ms[2 * (RANDOM % ($#first_command_lag_ms / 2) + 1)]}
fi
if (( $#command_lag_ms )); then
export _ZB_COMMAND_LAG_MS=${command_lag_ms[2 * (RANDOM % ($#command_lag_ms / 2) + 1)]}
fi
if (( $#input_lag_ms )); then
export _ZB_INPUT_LAG_MS=${input_lag_ms[2 * (RANDOM % ($#input_lag_ms / 2) + 1)]}
fi
{
eval -- "() { $shell_command[2] } || true"
} always {
print
if (( $#first_prompt_lag_ms > 2 )); then
print -Pr -- "Chosen value: --first-prompt-lag-ms %F{2}$_ZB_FIRST_PROMPT_LAG_MS%f"
fi
if (( $#first_command_lag_ms > 2 )); then
print -Pr -- "Chosen value: --first-command-lag-ms %F{2}$_ZB_FIRST_COMMAND_LAG_MS%f"
fi
if (( $#command_lag_ms > 2 )); then
print -Pr -- "Chosen value: --command-lag-ms %F{2}$_ZB_COMMAND_LAG_MS%f"
fi
if (( $#input_lag_ms > 2 )); then
print -Pr -- "Chosen value: --input-lag-ms %F{2}$_ZB_INPUT_LAG_MS%f"
fi
}
print -r -- ----------
done
} "$@"