8

So when i ssh into a remote server i use 'screen -R myscreen' to prevent any running scripts/processes from being interrupted when the ssh connection disconnects, for whatever reason (bad wifi, etc).

However, when starting screen, iTerm2's shell integration doesn't work anymore.

Is there any workaround for this?

Motsel
  • 518
  • 1
  • 4
  • 11

2 Answers2

8

fyi the solution i found is:

instead of 'screen' use 'tmux', by executing tmux -CC to open a tmux session (and using tmux -CC attach to re-attach after a disconnection.) This is also described here.

To make iTerm2 shell integration work in tmux, modify ~/.iterm2_shell_integration.bash and remove this part of the first line: "$TERM" != screen

So this

if [[ "$TERM" != screen && "$ITERM_SHELL_INTEGRATION_INSTALLED" = "" && "$-" == *i* ]]; then

becomes:

if [[ "$ITERM_SHELL_INTEGRATION_INSTALLED" = "" && "$-" == *i* ]]; then

Motsel
  • 518
  • 1
  • 4
  • 11
  • TY! This fixed the problem that when I had shared bash histories, tmux and iterm I would get this error: "-bash: iterm2_preexec_invoke_cmd: command not found". I haven't done much testing but this is looking good right now... – SebK Mar 08 '17 at 07:20
  • But the session initiated by `tmux -CC` (instead of `tmux`) is more like `screen`, not `tmux` I found splitting panels hard to do... – Sibbs Gambling Apr 23 '17 at 18:56
  • 4
    In iTerm 3.2.9, the condition is `"$ITERM_ENABLE_SHELL_INTEGRATION_WITH_TMUX""$TERM" != screen`. So you can just set `ITERM_ENABLE_SHELL_INTEGRATION_WITH_TMUX=yes` before `source ~/.iterm2_shell_integration.bash` in your `.profile` now. – Victor Sergienko Jun 28 '19 at 18:04
  • 2
    Any new solution for `screen` users? Thanks – jgarces Oct 09 '20 at 11:54
  • 2
    this does not answer the question lol, "How do I make gnu screen work with Iterm?" >> "Use Tmux" huh that's not what I wanted to know – Jules G.M. Sep 15 '22 at 00:09
2

You can use triggers to replicate almost all of the features of shell integration. See the Triggers section near the bottom of this document: https://www.iterm2.com/documentation-shell-integration.html

George
  • 4,189
  • 2
  • 24
  • 23