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:

Single Session

Updated 9/21/2021 with new syntax

Add the below snippet to your remote settings in VSCode.

{
  "terminal.integrated.profiles.linux": {
    "tmux": {
      "path": "/usr/bin/tmux",
      "args": [
        "new-session",
        "-A",
        "-s",
        "main"
      ],
    },
  },
  "terminal.integrated.defaultProfile.linux": "tmux",
}

Session Per Workspace

Update 9/21/2021: Looks like config variables have been fixed! Updated syntax and variables below.

If you want one tmux-session per project, you can use vscode variables

Add the below snippet to your remote settings in VSCode.

{
  "terminal.integrated.profiles.linux": {
    "tmux": {
      "path": "/usr/bin/tmux",
      "args": [
        "new-session",
        "-A",
        "-s",
        "vscode-${workspaceFolderBasename}"
      ],
    },
  },
  "terminal.integrated.defaultProfile.linux": "tmux",
}

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

Interested in Related Posts from this Site?

Backing up with B2 and Restic

April 01, 2019: Backing up with Blazeback B2 and Restic For a long while I had managed my...

Simple systemd service

July 13, 2018: Simple systemd service There aren't very many simple examples on the internet of simple systemd...

Weak Delegates 2

February 08, 2016: Weak Delegates 2 After toying with weak delegates a bit more, I found that although...

Weak Delegates

January 10, 2016: Weak Delegates in CSharp Problem This idea has always plagued me -- how do I...

Events and Expressions

March 13, 2015: Events and Expressions I ran into a scenario recently where I had a C# Action...

Image

Chris LaPointe

Another site of Code

Back to Overview