#!/usr/bin/env sh
#
# vim-tmux - tmux fifo

fifo="${TMPDIR:-/tmp}/vim-tmux-exit"
mkfifo -m o+w "${fifo}" || exit 1

trap 'rm -f "$fifo"' EXIT HUP INT TERM

# shellcheck disable=SC2312
escape() { printf "'%s'\\n" "$(printf '%s' "$1" | sed -e "s/'/'\\\\''/g")"; }

[ "$#" -eq 0 ] && args="" || args="$(escape "$@")"
# [ "$#" -eq 0 ] && args="" || args="${args}$(escape "$@")"

tmux split-window -bf zsh -c "${EDITOR:-vi} ${args}; echo $? >${fifo}" || exit 1
exit <"${fifo}"
