-
Notifications
You must be signed in to change notification settings - Fork 0
/
hbt.zsh
74 lines (64 loc) · 1.68 KB
/
hbt.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# To be able to use zsh hooks
autoload -Uz add-zsh-hook
export PATH="$HOME/Repositories/hbt/bin/darwin:$PATH"
export HBT_CACHE_PATH="$HOME/dotfiles/hbt/"
export HBT_PORT=43111
export HBT_SAVE_INTERVAL="60m"
function hbt_start() {
pid=$(pgrep hbtsrv)
if [ -z $pid ]; then
echo "starting hbt, you can stop it with: hbt_stop"
if [ "$1" = "--debug" ]; then
hbtsrv --debug
else
nohup hbtsrv >/dev/null 2>&1 &
fi
fi
}
function hbt_stop() {
pid=$(pgrep hbtsrv)
if [ ! -z $pid ]; then
kill -TERM $pid
fi
}
# Start hbtsrv if it is not already started
if [ -z $(pgrep hbtsrv) ]; then
hbt_start
fi
function _hbt_end_session() { echo -n "end\n$$" | nc localhost $HBT_PORT ; }
add-zsh-hook zshexit _hbt_end_session
function _hbt_track () { echo -n "track\n$$\n$(pwd)\n$1" | nc localhost $HBT_PORT ; }
add-zsh-hook preexec _hbt_track
# list dir with TAB, when there are only spaces/no text before cursor,
# or complete words, that are before cursor only (like in tcsh)
function _hbt_search () {
if [[ -z ${LBUFFER// } ]]; then
suggestion=$(echo -n "hint\n$$\n$(pwd)" | nc localhost $HBT_PORT)
POSTDISPLAY="${suggestion#$BUFFER}"
_zsh_autosuggest_highlight_reset
_zsh_autosuggest_highlight_apply
else
zle expand-or-complete-prefix;
fi
}
zle -N _hbt_search
bindkey '^I' _hbt_search
function _hbt_clear() {
if [[ -z ${LBUFFER// } ]]; then
unset POSTDISPLAY
else
zle backward-delete-char
fi
}
zle -N _hbt_clear
bindkey '^?' _hbt_clear
function _hbt_delsuggestion () {
if [[ ! -z ${POSTDISPLAY} ]]; then
$(echo -n "del\n$$\n$(pwd)\n$1" | nc localhost $HBT_PORT)
unset POSTDISPLAY
else
zle delete-char
fi
}
zle -N _hbt_delsuggestion
bindkey '^[[3~' _hbt_delsuggestion