n-functions
1161 bytes
1# Copy this file into /usr/share/zsh/site-functions/
2# and add 'autoload n-functions` to .zshrc
3#
4# This function allows to choose a function for edition with vared
5#
6# Uses n-list
7
8emulate -L zsh
9
10setopt extendedglob
11zmodload zsh/curses
12zmodload zsh/parameter
13
14local IFS="
15"
16
17unset NLIST_COLORING_PATTERN
18
19[ -f ~/.config/znt/n-list.conf ] && builtin source ~/.config/znt/n-list.conf
20[ -f ~/.config/znt/n-functions.conf ] && builtin source ~/.config/znt/n-functions.conf
21
22local list
23local selected
24
25NLIST_REMEMBER_STATE=0
26
27list=( "${(@k)functions}" )
28list=( "${(@M)list:#(#i)*$1*}" )
29
30local NLIST_GREP_STRING="$1"
31
32if [ "$#list" -eq 0 ]; then
33 echo "No matching functions"
34 return 1
35fi
36
37list=( "${(@i)list}" )
38n-list "$list[@]"
39
40if [ "$REPLY" -gt 0 ]; then
41 selected="$reply[REPLY]"
42 if [ "$feditor" = "zed" ]; then
43 echo "Editing \`$selected' (ESC ZZ or Ctrl-x-w to finish):"
44 autoload zed
45 print -rs "zed -f -- \"$selected\""
46 zed -f -- "$selected"
47 else
48 echo "Editing \`$selected':"
49 print -rs "vared functions\\[$selected\\]"
50 vared functions\[$selected\]
51 fi
52fi
53
54# vim: set filetype=zsh: