-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathmanydots.zsh
75 lines (58 loc) · 1.93 KB
/
manydots.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
74
75
#! /usr/bin/env zsh
# manydots - zle tweak for emulating "..."=="../.." etc.
# type triple dots to input `../..', quadruple dots to `../../..', etc..
# ref - https://github.com/knu/zsh-manydots-magic
manydots.self-insert() {
emulate -L zsh
local self_insert_function magic_count
zstyle -s ':manydots' self-insert-function self_insert_function
if [[ "$KEYS" == .* && "$LBUFFER" != *...* && "$LBUFFER" == *.. ]] && {
local -a words
words=("${(@Q)${(z)LBUFFER}}")
# `...` is a wildcard operator in go
[[ ${${(@)words[1,-2]}[(I)go]} = 0 ]] &&
[[ $words[-1] == (|*[/=]|[\<\>=]\().. ]]
}
then
[[ "$LASTWIDGET" == (self-insert) ]] &&
zstyle -s ':manydots' magic-count magic_count
zstyle ':manydots' magic-count $((magic_count+1))
LBUFFER="$LBUFFER/."
zle "$self_insert_function"
return
fi
# cancel expansion if it does not seem right
if [[ "$KEYS" != [=/,:\;\|\&\<\>\(\)\[\]{}^~\'\"\`[:space:]]* &&
"$LASTWIDGET" == (self-insert) && "$LBUFFER" == *../.. ]] && {
zstyle -s ':manydots' magic-count magic_count
[[ "$magic_count" -gt 0 ]]
}
then
repeat $magic_count LBUFFER="${LBUFFER%/..}"
repeat $magic_count LBUFFER="$LBUFFER."
fi
zstyle ':manydots' magic-count 0
zle "$self_insert_function"
}
manydots.on() {
emulate -L zsh
local self_insert_function="${$(zle -lL | awk \
'$1=="zle"&&$2=="-N"&&$3=="self-insert"{print $4;exit}'):-.self-insert}"
[[ "$self_insert_function" == manydots.self-insert ]] && return 0
# For url-quote-magic which does not zle -N itself
zle -la "$self_insert_function" || zle -N "$self_insert_function"
zstyle ':manydots' self-insert-function "$self_insert_function"
zle -A manydots.self-insert self-insert
zstyle ':manydots' magic-count 0
return 0
}
zle -N manydots.self-insert
zle -N manydots.on
manydots() {
manydots.on
}
# load manydots only once
[ -z $_LOADED_MANYDOTS ] && {
manydots "$@"
_LOADED_MANYDOTS=true
}