Running Multiple Atom Profiles
As someone who uses Atom as their main text editor and IDE, I’m a huge fan of Atom’s massive library of packages to extend its functionality. That being said, I don’t need a Python linter to slow down my startup time when I’m editing a text document and I don’t need quick access to a C++ compiler when I’m writing in JavaScript. Thankfully, having specialized Atom profiles for different languages or projects is easily achieved with some light scripting.
Atom Profiles
Firstly, note that what I refer to as Atom profiles are different than Atom installations. I choose to use a single Atom installation with multiple home locations, meaning that while settings and packages are independent between profiles, there is only one copy of Atom itself. This has a storage-space benefit, along with the fact that any changes to the Atom program (such as patches like title-bar-replacer or regular updates) only need to be done once. If you are seeking multiple installations, check out Atom’s portable mode.
The Basics
The main idea is to use a small script to launch Atom after changing the ATOM_HOME
environment variable to the appropriate profile directory. This is easily done with bash scripts on Linux or batch/cmd scripts on Windows, as shown respectively below. Note that the double quotes are to allow for paths with spaces, and it is assumed that the Atom launch files are accessible via environment variables.
# file: "atom-foo"
#!/bin/bash
export ATOM_HOME="path/to/atom/home/dir"
atom
:: file: "atom-foo.cmd"
@echo off
set "ATOM_HOME=path\to\atom\home\dir"
atom.cmd
Script Improvements
While these launch scripts are functional, accessing them is currently limited. The first change we can make starts with storing them in some sort of atom-profiles
folder, which we can then add to our PATH
. If we then modify the scripts to pass any arguments to the atom
call, we can mimic the functionality of the atom
terminal command with our custom profiles, for example, calling atom-c++ app.cpp app.h
to open the two files in our C++ profile. Secondly, we can create shortcuts to the launch files and add them to our application launcher or start menu if this wasn’t done already.
Additionally, we can streamline the deployment process for new profiles. For simplicity, I chose to have the ATOM_HOME
folder always created in the same working directory as the launching script (atom-profiles
in my case). Since we are going to be creating a new launch script with a unique name anyways, we might as well use the script’s name for the home folder as well, though I append -home
to avoid same-name issues on Linux. The result is that we never need to modify the script itself to create a new profile; Simply copy and rename an existing script. For example, copying and renaming a script to atom-python
in /home/swebra/atom-profiles/
will create and use /home/swebra/atom-profiles/atom-python-home/
as its home directory.
Finally, if we choose to keep a consistent naming scheme, we can use all the same principals to create scripts for apm
, Atom’s package manager. These scripts will allow us to install or remove packages to a specific profile from the command line without having to manually set ATOM_HOME
from the terminal. The reason we need a specific naming scheme is so we can determine the appropriate home directory using substring manipulation from within the script; We can no longer just reply on the script’s name plus -home
, as an apm script named apm-python
will need to reference atom-python-home
. As you may have already noticed, I choose to format all Atom scripts as atom-[subject]
and all apm scripts as apm-[subject]
. I can therefore remove the first three characters of the apm script’s name to get -[subject]
, from which I can add the atom
prefix and -home
suffix.
Syncing Across Profiles
Another way we can improve our experience is by leveraging sync packages. I like to develop a base profile containing all my basic settings and packages I want across all profiles, and then back up my base profile with sync-settings. This allows two interesting features: Firstly, I can restore the backup when creating new profiles to quickly get up and running, but more importantly, it allows me to easily distribute changes I want to be global across all my profiles. I can simply make the change in my base profile and then update the backup. As I have all my packages check for backup updates, they will all then pull the new changes on first load.
Final Scripts
These scripts are also available to download from here.
# file: "atom-foo"
#!/bin/bash
# Set the path of ATOM_HOME to be a folder in the current working directory with
# the name equal to "[the name of this script]-home".
# E.g. "atom-foo" will use a folder named "atom-foo-home".
thisScriptPath="$(readlink -f -- "$0")" # Full path to script
export ATOM_HOME="${thisScriptPath%.*}"-home
# Launch Atom with arguments (assumes the Atom launch files are in your PATH)
atom $@
# file: "apm-foo"
#!/bin/bash
# Set the path of ATOM_HOME to be a folder in the current working directory with
# the name equal to "atom[the name of this script after "apm"]-home".
# E.g. "apm-foo" will use a folder named "atom-foo-home".
thisScriptPath="$(readlink -f -- "$0")" # Full path to script
thisScriptFileName="${thisScriptPath##*/}" # Name of script with extension
thisScriptName="${thisScriptFileName%.*}" # Name of script without extension
export ATOM_HOME="${thisScriptPath%/*}"/atom"${thisScriptName:3}"-home
# Launch APM with arguments (assumes the Atom launch files are in your PATH)
apm $@
:: file: "atom-foo.cmd"
@echo off
:: Set the path of ATOM_HOME to be a folder in the current working directory
:: with the name equal to "[the name of this script]-home".
:: E.g. "atom-foo.cmd" will use a folder named "atom-foo-home".
set ATOM_HOME=%~dp0%~n0-home
:: Launch Atom with arguments (assumes the Atom launch files are in your PATH)
atom.cmd %*
:: file: "apm-foo.cmd"
@echo off
:: Set the path of ATOM_HOME to be a folder in the current working directory
:: with the name equal to "atom[the name of this script after "apm"]-home".
:: E.g. "apm-foo.cmd" will use a folder named "atom-foo-home".
set thisScriptName=%~n0
call set ATOM_HOME=%~dp0atom%thisScriptName:~3%-home
:: Launch APM with arguments (assumes the Atom launch files are in your PATH)
apm.cmd %*