0

I am using the following code on my rc file to run tmux every time i open my terminal.

if command -v tmux &> /dev/null && [ -n "$PS1" ] && [[ ! "$TERM" =~ screen ]] && [ -z "$TMUX" ]
then
  notmuxsession=$(tmux list-clients | wc -l)
  if tmux has-session -t default${notmuxsession}
  then
      # tmux send-keys -t default${notmuxsession}:!.! "^U"
      tmux send-keys -t default${notmuxsession}:1.1 "^U"
      tmux send-keys -t default${notmuxsession}:1.1 "cd $PWD &> /dev/null" ENTER
      tmux send-keys -t default${notmuxsession}:1.1 "^L"
      tmux attach-session -t default${notmuxsession}:1.1
  else
      tmux new-session -s default${notmuxsession} -c $PWD
  fi
fi

But it has a problem. I can not exit tmux. I sometimes may want to use the regular terminal.

Is there any way i do not run this code block when i exit from tmux.

Ahmad Ismail
  • 2,678

0 Answers0