n-history 1.04 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
# Copy this file into /usr/share/zsh/site-functions/
# and add 'autoload n-history` to .zshrc
#
# This function allows to browse Z shell's history and use the
# entries
#
# Uses n-list

emulate -L zsh

setopt extendedglob
zmodload zsh/curses
13
zmodload zsh/parameter
14
15
16
17
18
19
20
21
22
23
24
25
26
27

local IFS="
"

unset NLIST_COLORING_PATTERN

[ -f ~/.config/znt/n-list.conf ] && . ~/.config/znt/n-list.conf
[ -f ~/.config/znt/n-history.conf ] && . ~/.config/znt/n-history.conf

local list
local selected

NLIST_REMEMBER_STATE=0

28
list=( "$history[@]" )
29
30
31
32
33
34
35
list=( "${(@M)list:#(#i)*$1*}" )

if [ "$#list" -eq 0 ]; then
    echo "No matching history entries"
    return 1
fi

36
37
local NLIST_GREP_STRING="$1"
local NLIST_REPLACE_NEWLINES="1"
38
39
40
41
42
43
44
n-list "${list[@]}"

if [ "$REPLY" -gt 0 ]; then
    selected="$reply[REPLY]"
    # ZLE?
    if [ "${(t)CURSOR}" = "integer-local-special" ]; then
        zle redisplay
45
        zle kill-buffer
46
47
48
49
50
51
52
53
54
        zle -U "$selected"
    else
        print -zr "$selected"
    fi
else
    [ "${(t)CURSOR}" = "integer-local-special" ] && zle redisplay
fi

# vim: set filetype=zsh: