Article Image
read

I've been moving around a bit lately (Nowhere far... since COVID-19 and all), and have been leaning heavily on VS Code's Remote SSH Plugin. My network connection has been spotty, and have found that even though it's pretty good at not losing any of your code changes, that when I want to depend on the terminal, the session is not persistent. This is especially bad when I lose connection when running a dev-build (that hangs around) because I have to find and kill the process before starting coding again.

TMux Session

Luckily, the solution is easy enough: tmux!

In addition to sessions, tmux provides many powerful features including terminal splitting, history, and more. I'll be focusing on the session, of course :)

First step is to quickly install tmux:

sudo apt install tmux

VSCode Config

The solution is to set the default terminal provider on the remote settings to be tmux, and have it attach to either an existing session named main, or create a new one if it doesn't exist. The config to do that is this:

{
  "terminal.integrated.shell.linux": "/usr/bin/tmux",
  "terminal.integrated.shellArgs.linux": [
    "new-session",
    "-A",
    "-s",
    "main"
  ],
}

Persistent Port Forwarding

As a bonus, I like to add port-forwarding to default to the port I use for my development. This means there's one fewer steps to starting to get back into development after reconneting.

{
    "remote.SSH.defaultForwardedPorts": [
    {
      "localPort": 9002,
      "remotePort": 9002,
      "name": "SA"
    }
  ],
}

Conclusion

Hopefully these small tricks make your zero-to-60 time much shorter when setting a new coding session.

That's it! Happy coding.

Blog Logo

Christopher LaPointe


Published

Image

Chris LaPointe

Another site of Code

Back to Overview