Visual Studio Code Profiles
Edit (2023-003-12)⌗
This is now a feature that is built into VS Code: https://code.visualstudio.com/docs/editor/profiles
Recently I decided I wanted to try and split up my Visual Studio Code environment between how I want to write code for work and how I want to write code for pleasure. Examples of why this is useful are:
- I can enable features that wouldn’t be safe for work (like Github Copilot)
- I can have my work configuration synced to a different location than my personal settings
- I can experiment and be willing to break my personal code environment without impairing my work environment
What’s the game plan?⌗
There were two options I considered for solving this problem:
- Using the VSCode Profile Switcher extension
- Using the
--extensions-dir
and--user-data-dir
options on thecode
binary
Profile switcher extension⌗
I tried option 1 first and found it a bit awkward. The Github user that I was logged in with was common between the profiles which meant I couldn’t have different things synced to different places. I also couldn’t easily read the settings file since everything was just kinda squished together so making manual changes was hard (but necessary). Finally I found it really annoying that I had to reload all the extensions every time I switched profiles. I will say though that I liked how you could inherit settings from other profiles. That made things more convenient to come up with defaults and then re-use them elsewhere.
CLI options⌗
After running into problems with the extension, I decided to go with just changing where the settings and extensions were loaded from. That ended up being pretty easy.
I simply picked a place I wanted to store the profiles (~/.local/share/code
) and then I created a directory structure like this ~/.local/share/code/<profile_name>/extensions
and ~/.local/share/code/<profile_name>/data
. Given that I created a Bash alias which launches VS Code with those as the desired storage locations.
Once that’s done you can just execute the code@work command to launch VS Code with the work profile.
Main downside that I’ve found with this approach is that when you’re doing something like connecting it up to Github which requires the Oauth flow you can’t just click the URL they spit out to complete the login because that’ll just launch the main VS Code environment which isn’t what I want. I only want it to go to the current profile. You can copy the URL they provide and enter it in manually which isn’t too bad. Just something to be aware of.
Application launcher entry⌗
It’s nice to be able to just click an icon to launch VS Code versus having to run a terminal command. To keep this experience I was able to just create a .desktop file for each profile and include that in my users applications list.
This was incredibly easy. The work entry looks like this:
How can it be automated?⌗
While none of that is hard to do, I’m a developer, I have to make things complicated and spend a ton of time automating something I do infrequently. So here’s a quick Python script that I wrote to handle doing all of that.
Future improvements⌗
Here’s a couple things I want to deal with to make the experience better:
- Get different colored icons for each profile to make it easier to tell them apart (in VSCode and in the application launcher)