diff --git a/.zsh/plugin/cdselect.zsh b/.zsh/plugin/cdselect.zsh index 55c916f..1a908c6 100644 --- a/.zsh/plugin/cdselect.zsh +++ b/.zsh/plugin/cdselect.zsh @@ -36,12 +36,24 @@ cdselect() { [[ $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--)) ;; # up + B) ((cursor++)) ;; # down + esac + continue + else + break # plain ESC + 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 diff --git a/.zsh/plugin/fileselect.zsh b/.zsh/plugin/fileselect.zsh index be8f452..3813343 100644 --- a/.zsh/plugin/fileselect.zsh +++ b/.zsh/plugin/fileselect.zsh @@ -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 diff --git a/.zsh/plugin/histselect.zsh b/.zsh/plugin/histselect.zsh index d5d804b..dbcba85 100644 --- a/.zsh/plugin/histselect.zsh +++ b/.zsh/plugin/histselect.zsh @@ -29,12 +29,24 @@ histselect() { [[ $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