summaryrefslogtreecommitdiff
path: root/dot-oh-my-zsh/custom/plugins/zsh-autocomplete/functions/widget/.autocomplete.history-search.zle-widget
blob: acf23b8e013aa05be83b1158dd78e1c40f71c438 (plain)
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
#!/bin/zsh
local 0=${(%):-%N}
builtin zle -C ${0}.context list-choices ${0}.context

${0}.context() {
  # Inside a completion widget, the current quote level is removed. So, we should not include
  # $QIPREFIX/$QISUFFIX in our pattern or it won't match.
  lcontext=${LBUFFER%${(~j:*:)words[1,CURRENT-1]}*$IPREFIX$PREFIX}
  lcontext+=${lcontext:+ }${(pj:\0:)${(@b)words}}
  rcontext=${RBUFFER#$SUFFIX$ISUFFIX*${(~j:*:)words[CURRENT+1,-1]}}
}

${0}() {
  local -P lbuffer="$LBUFFER" rbuffer="$RBUFFER"
  local -P keymap_menuselect="$( builtin bindkey -M menuselect -L )"
  {
    builtin bindkey -M menuselect -s \
        '^R' '^_^_^R' \
        '^S' '^_^_^S'
    builtin bindkey -M menuselect \
        '\e[D' .backward-char \
        '\eOD' .backward-char \
        '\e[C' .forward-char \
        '\eOC' .forward-char

    setopt $_autocomplete__comp_opts[@] $_autocomplete__ctxt_opts[@]

    local lcontext= rcontext=
    builtin zle ${(%):-%N}.context
    LBUFFER="$lcontext"
    RBUFFER="$rcontext"

    [[ -o sharehistory ]] &&
        fc -RI  # Get new history events from file.
    builtin zle _history_search

  } always {
    builtin bindkey -M menuselect -r '^R' '^S' '\e'{\[,O}{D,C}
    eval "$keymap_menuselect"
    if [[ $BUFFER == $lcontext$rcontext ]] then
      LBUFFER="$lbuffer"
      RBUFFER="$rbuffer"
    fi
  }
}

$0 "$@"