#!/usr/bin/env bash

# shellcheck disable=SC2154
if [ "${#BUFFER}" -eq 0 ]; then
  backgroundProgram="$(jobs | tail -n 1 | awk '{print $4}')"
  case "${backgroundProgram}" in
    "nc" | "ncat" | "netcat" | "resize-netcat-listener" | "rnc")
      # make sure that /dev/tty is given to the stty command by doing </dev/tty
      terminal-size-clip </dev/tty
      stty raw -echo </dev/tty
      fg
      ;;
    *)
      fg
      ;;
  esac
else
  zle push-input
fi
