#!/bin/sh dir=$1 tty=$(tmux list-panes -F "#{pane_active}#{pane_tty}" | grep '^1' | cut -c2-) vim=$(ps -o stat=,command= -t $tty | awk 'BEGIN{flag=0} {if($1 ~ /S*+/ && $2 ~ /nvim/){flag +=1}}; END {print flag}') echo $dir echo $tty echo $vim if [ $vim -gt 0 ]; then case $dir in up) tmux send-keys C-k ;; down) tmux send-keys C-j ;; left) tmux send-keys C-h ;; right) tmux send-keys C-l ;; esac else case $dir in up) tmux select-pane -U ;; down) tmux select-pane -D ;; left) tmux select-pane -L ;; right) tmux select-pane -R ;; esac fi