summary refs log tree commit diff
path: root/Functions/Zle/read-from-minibuffer
blob: c3848ae9f48d72328faaf4fb15ca9a0847a6aa1e (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
emulate -L zsh
setopt extendedglob

local opt keys
integer stat

while getopts "k:" opt; do
    case $opt in
	(k)
	keys=$OPTARG
	;;

	(*)
	return 1
	;;
    esac
done
(( OPTIND > 1 )) && shift $(( OPTIND - 1 ))

local savelbuffer=$LBUFFER saverbuffer=$RBUFFER
local savepredisplay=$PREDISPLAY savepostdisplay=$POSTDISPLAY

LBUFFER="$2"
RBUFFER="$3"
PREDISPLAY="$PREDISPLAY$savelbuffer$saverbuffer$POSTDISPLAY
${1:-? }"
POSTDISPLAY=

if [[ -n $keys ]]; then
    zle -R
    read -k $keys
    stat=$?
else
    zle recursive-edit
    stat=$?
    (( stat )) || REPLY=$BUFFER
fi

LBUFFER=$savelbuffer
RBUFFER=$saverbuffer
PREDISPLAY=$savepredisplay
POSTDISPLAY=$savepostdisplay

return $stat