-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhooks.zsh
54 lines (47 loc) · 1.38 KB
/
hooks.zsh
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
if [[ $_axl_hooks_sourced ]]; then
return 0
fi
_axl_hooks_sourced=true
_axl_log="/tmp/$(whoami).axl"
_axl_cmd_run=_axl_nil
_axl_cmd=_axl_nil
_axl_start_time=_axl_nil
_axl_cmd_start() {
_axl_start_time=$(date +%s)
_axl_cmd_run=$1
print "+ $_axl_start_time $_axl_cmd_run" >> "$_axl_log"
chmod 600 "$_axl_log"
}
# TODO: would be nice to handle errors with `axl internal render`.
_axl_cmd_finish() {
# Note: it's important this be the first statement to capture the exit code.
local code=$?
_axl_cmd=$_axl_cmd_run
if [[ $_axl_cmd_run == _axl_nil ]]; then
return $code
fi
# Reset back to nil since it's possible for _axl_cmd_finish to be called
# without an associated _axl_cmd_start (on ctrl-c, for example).
_axl_cmd_run=_axl_nil
print -- "- $code $_axl_start_time $_axl_cmd" >> "$_axl_log"
if [[ $AXL_NOTIFY ]]; then
local msg
msg=$(axl internal render "$_axl_cmd" \
--start-time="$_axl_start_time" --code=$code)
if [[ $msg ]]; then
print -- "$msg" | eval "$AXL_NOTIFY" &>/dev/null &!
fi
fi
return $code
}
preexec_functions+=(_axl_cmd_start)
precmd_functions+=(_axl_cmd_finish)
# TODO: would be nice to handle errors with `axl internal suggest`.
_axl_suggest_cmd() {
if [[ $_axl_cmd != _axl_nil && -z $BUFFER ]]; then
BUFFER=$(axl internal suggest "$_axl_cmd")
CURSOR=$#BUFFER
fi
}
autoload -Uz add-zle-hook-widget
add-zle-hook-widget zle-line-init _axl_suggest_cmd