about summary refs log tree commit diff
path: root/Completion/Base/Completer/_history
blob: 63878ac1c3dc4f69496ec2d3355b88fca2a9a455 (plain) (blame)
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
#autoload

# Hm, this *can* sensibly be used as a completer. But it could also be used
# as a utility function, so maybe it should be moved into another directory.
# Or maybe not. Hm.
#
#
# Complete words from the history
#
# Code taken from _history_complete_words.
#
# Available styles:
#
#   sort --  sort matches lexically (default is to sort by age)
#   remove-all-dups --
#            remove /all/ duplicate matches rather than just consecutives
#   range -- range of history words to complete

local opt expl max slice hmax=$#historywords beg=2

if zstyle -t ":completion:${curcontext}:" remove-all-dups; then
  opt=-
else
  opt=-1
fi

if zstyle -t ":completion:${curcontext}:" sort; then
  opt="${opt}J"
else
  opt="${opt}V"
fi

if zstyle -s ":completion:${curcontext}:" range max; then
  if [[ $max = *:* ]]; then
    slice=${max#*:}
    max=${max%:*}
  else
    slice=$max
  fi
  [[ max -gt hmax ]] && max=$hmax
else
  max=$hmax
  slice=$max
fi

PREFIX="$IPREFIX$PREFIX"
IPREFIX=
SUFFIX="$SUFFIX$ISUFFIX"
ISUFFIX=

# We skip the first element of historywords so the current word doesn't
# interfere with the completion

while [[ $compstate[nmatches] -eq 0 && beg -lt max ]]; do
  _wanted "$opt" history-words expl 'history word' \
      compadd -Q -a 'historywords[beg,beg+slice]'
  (( beg+=slice ))
done

(( $compstate[nmatches] ))