zsh 読み込み 組み込み中の行編集用の矢印キー

zsh 読み込み 組み込み中の行編集用の矢印キー

ユーザーに入力を要求する小さなzshスクリプトがあります。

#!/usr/bin/env zsh
IFS="$(printf "\n\t")"
printf "${1-query}: " 1>&2
read -r query
echo "${query}"

プロンプトに何かを入力し、矢印キーを使用して戻って編集しようとすると^[[D。私のTERM環境はxterm次のとおりです。通常のzshコマンドラインのように、行を編集するために矢印キーが正しく機能するようにするにはどうすればよいですか?

setoptこれらのいずれかに関連する場合、出力は次のようになります。

emacs
noflowcontrol
histexpiredupsfirst
histfindnodups
histignorealldups
histignoredups
histsavenodups
histverify
incappendhistory
interactive
interactivecomments
monitor
nonomatch
promptsubst
shinstdin
zle

ベストアンサー1

リンクされたコメントに基づいてこの回答、私は学んだvared。これが私が大きな効果を出すために使用するものです:

#!/usr/bin/env zsh
IFS="$(printf "\n\t")"
query=
vared -p "${1-query}: " query 
echo "${query}"

おすすめ記事