カラクリスタ・テック

『輝かしい青春』なんて失かった人の技術系ブログです。

Workaround for zpty is not working on Windows (MSYS/MinGW)

1. Patching ZSH source code for activate USE_DEV_PTMX flag when compiling

Adding to these code to prepare section in zsh's PKGBUILD like this:

prepare() {
  cd ${srcdir}/${pkgbase}-${pkgver}
  patch -p0 -i "${srcdir}/Makefile.in.patch"
  patch -p1 -i "${srcdir}/add-pwd-W-option.patch"
  patch -p1 -i "${srcdir}/msysize.patch"
  patch -p1 -i "${srcdir}/zsh-5.0.6-1.patch"
  patch -p1 -i "${srcdir}/msys-symlink-hack.patch"
 
  # workaround for working zsh/zpty.c on msys2
  sed -i 's!int ptsname();!int ptsname(); int main() {}!' "${srcdir}/${pkgbase}-${pkgver}/configure.ac"
  sed -i 's!__CYGWIN__!__MSYS__!g' "${srcdir}/${pkgbase}-${pkgver}/Src/Modules/zpty.c"

And, build it:

$ makepkg -sLfi 

2. Adding workaround code to .zshrc for zpty is hunging when exits shell instance

if [[ "$(uname -s)" =~ .*_NT-.* ]]; then
  alias exit="sh -c \"cmd /C 'taskkill /F /T /PID $(cat /proc/$$/winpid)'\""
  trap 'sh -c "cmd /C \"taskkill /F /T /PID $(cat /proc/$$/winpid)\""' 1 2 3 15
fi

3. Done!

Image

Yay!

(This screencast is using zsh pure prompt inside tmux on MSYS2 (MINGW64) Shell environment!!!)