zsh select

This commit is contained in:
2026-03-30 19:30:00 +09:00
parent 3207bab41a
commit cedbc23a14
3 changed files with 39 additions and 3 deletions

View File

@@ -29,12 +29,24 @@ fileselect() {
[[ $i -gt 20 ]] && break
done
read -k1 key 2>/dev/null
if [[ "$key" == $'\x1b' ]]; then
read -k1 -t 0.1 k2 2>/dev/null
if [[ "$k2" == "[" ]]; then
read -k1 -t 0.1 k3 2>/dev/null
case "$k3" in
A) ((cursor--)) ;;
B) ((cursor++)) ;;
esac
continue
else
break
fi
fi
case "$key" in
$'\n'|$'\r') [[ ${#filtered} -gt 0 ]] && selected="${filtered[$cursor]}"; break ;;
$'\x0e') ((cursor++)) ;; # C-n
$'\x10') ((cursor--)) ;; # C-p
$'\x7f'|$'\b') query="${query%?}"; cursor=1 ;;
$'\x1b') break ;;
*) query+="$key"; cursor=1 ;;
esac
done