MSYS2でmintty+bash+pecoの環境を作る
peco
この記事に書いてあること
MSYS2でターミナルにminttyを使っていると、pecoが正しく動きません。 この記事を参考に、ラッパー関数を定義すると、mintty+bash+pecoの環境を作れます。
参考記事からの変更点
MSYS2のfindコマンドは、存在しないディレクトリー名を渡されたり、ディレクトリー名が"/"で終わっていない場合に、なにも出力しません。すると、scriptコマンドを介してpecoに入力が渡されないので、操作不能に陥ります。
変更後のラッパー関数
function _pecowrap_exec() { eval "$@" > /tmp/cmd.log script -e -qc "winpty peco /tmp/cmd.log" /tmp/script.log } function _pecowrap_result() { local result="$(col -bx < /tmp/script.log | tr -d '\n' | sed 's/.*0m\(.*\)0K.*$/\1/g' | sed 's/0K//g')" echo "${result}" } function c() { local peco_dir=$1 if [ ! -d $peco_dir ]; then echo "${peco_dir} is not directory!" return fi if [ "${peco_dir:${#peco_dir}-1:1}" != "/" ]; then peco_dir="${peco_dir}/" fi _pecowrap_exec "find ${peco_dir} -maxdepth 1 -type d | sort" || return cd $(_pecowrap_result) }