Use is a command line tool to setup environment defined in a json file. The syntax is easy enough to be able to handle setup with multiple environment variables and secondary scripts.
- Append, prepend or set new environment variables,
- Add directory to
PATH
, - Run external scripts,
- Reuse existing environments,
- Change the terminal tab title based on the environment
- Extend the prompt with the environment name
As we can't change the console environment from a binary, use is using a dual strategy:
- a binary,
use
, to extract all the information for setting up the environment - a shell script to setup for a given shell, using the output of
use
Installation via Scoop (preferred)
Install use with scoop:
scoop bucket add narnaud https://github.com/narnaud/scoop-bucket
scoop install use
- Go to the Releases page
- Download the latest
use-x86_64-pc-windows-msvc.zip
file - Extract the files from it into a directory.
Invoke-Expression (&use init powershell)
Tip
If you install use with scoop, you don't need to do anything, it will install such a script automatically.
You need clink wit Cmd. Create a file at this path %LocalAppData%\clink\use.lua with the following contents:
load(io.popen('use init cmd'):read("*a"))()
Once use is initialized in your shell, you can type use
in your shell to have a list of known nvironment, or use --help
for the help.
Command-line utility to setup environment
Usage: use [NAME] [COMMAND]
Commands:
init Prints the shell function used for shell integration
list List all environments
set Adjust use's settings
help Print this message or the help of the given subcommand(s)
Arguments:
[NAME] Name of the environment to use
Options:
-h, --help Print help
-V, --version Print version
use is using a yaml configuration file to defines the different environments, see below.
Use expect a YAML configuration file in ~/.config/use/useconfig.yaml
(or %USERPROFILE%\.config\use\useconfig.yaml
on Windows). Here is a small example:
# Example environment
example:
display: Name of the configuration
use:
- qt6
- msvc2022
- other
- configuration
- names
script: |
echo "Something"
echo "Something else"
set:
EXAMPLE_VAR: example value
EXAMPLE_VAR_OTHER: other value
append:
EXAMPLE_VAR_APPEND: value appended to EXAMPLE_VAR_APPEND
EXAMPLE_VAR_OTHER_APPEND: value appended to EXAMPLE_VAR_OTHER_APPEND
prepend:
EXAMPLE_VAR_PREPEND: value prepended to EXAMPLE_VAR_PREPEND
EXAMPLE_VAR_OTHER_PREPEND: value prepended to EXAMPLE_VAR_OTHER_PREPEND
path:
- C:\example\path\to\add\to\path
- C:\example\other\path\to\add\to\path
go: C:\example\path\to\go\to
# Visual Studio 2022 x64
msvc2022:
display: Microsoft Visual Studio 2022 - x64
for_cmd:
script: |
call "C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Auxiliary\Build\vcvarsall.bat" amd64 > nul
for_powershell:
script: |
& "C:\Program Files\Microsoft Visual Studio\2022\Professional\Common7\Tools\Launch-VsDevShell.ps1" -SkipAutomaticLocation -Arch amd64 *>$null
# Qt, all versions, using pattern
qt{}:
display: Qt {} - MSVC - x64
pattern:
path: C:\Qt
regex: "^(\\d+\\.\\d+\\.\\d+)$"
use:
- msvc2022
set:
QTDIR: C:\Qt\{}\msvc2022_64\
append:
CMAKE_PREFIX_PATH: C:\Qt\{}\msvc2022_64\
path:
- C:\Qt\{}\msvc2022_64\bin
The YAML file is a map of environments, the key being used as the environment name when running the command. For each environment, you can have:
display
: string displayed when setting the environmentuse
: reuse existing environment (they will be setup before)script
: raw lines to call as a scriptset
: list of environment variables to initializeappend
: append values to environment variablesprepend
: prepend values to environment variablespath
: add paths to thePATH
environment variablego
: go to a particular directory at the end of the setuppattern
: use pattern matching to create multiple environments with one definition (see below)
It is possible to have for some shell some specific values for one environment, for example:
msvc2022:
display: Microsoft Visual Studio 2022 - x64
for_cmd:
script: |
call "C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Auxiliary\Build\vcvarsall.bat" amd64 > nul
for_powershell:
script: |
& "C:\Program Files\Microsoft Visual Studio\2022\Professional\Common7\Tools\Launch-VsDevShell.ps1" -SkipAutomaticLocation -Arch amd64 *>$null
For the msvc2022
environment, the display is shared, but the script is different for cmd and powershell:
for_cmd
: values specific to the cmd shell,for_powershell
(orfor_pwsh
): values specific to the powershell shell.
You can change almost everything, except pttern
:
display
,script
andgo
are replaced,use
,set
,append
,prepend
,path
are extended.
It is possible to define multiple environments in a single definition. This is especially interesting if you have multiple versions of the same lib or app.
For example, here is a definition for Qt on Windows (the {}
are replaced with the regex capture):
qt{}:
display: Qt {} - MSVC - x64
pattern:
path: C:\Qt
regex: "^(\\d+\\.\\d+\\.\\d+)$"
use:
- msvc2022
set:
QTDIR: C:\Qt\{}\msvc2022_64\
append:
CMAKE_PREFIX_PATH: C:\Qt\{}\msvc2022_64\
path:
- C:\Qt\{}\msvc2022_64\bin
The interesting part is the pattern
key:
path
: gives the path to look atregex
: the regex to match files/dirs in the path
So if I have installed for example Qt 5.12.2, Qt 6.5.3 and Qt 6.8.2, I should have those directories under C:\Qt:
C:Qt
+- 5.12.2
+- 6.5.3
+- 6.8.2
And it will create 3 different environments: qt5.12.2
, qt6.5.3
and qt6.8.2
.
You can use partial key to use an environment. Following on the same example:
use qt
: set up the latest Qt version, here Qt 6.8.2use qt6.5
: set up the latest Qt 6.5 version available, here 6.5.3use qt5.12.2
: set up an explicit Qt version
It works the same for the YAML configuration, you can use partial keys:
example:
use:
- qt6
By default, use is going to change the terminal title using the environment name. You are free to change the settings:
use set --update-title false
Set it to true
to go back to the default behavior.
It should be fairly easy to integrate with other shells (contributions are very welcome). To do that, you need:
- initialization script (in init directory): integration of use in the Shell, goal is to provide a method
use
that read and execute the output of theuse
executable, - shell printer (int
shell
directory): provide the shell specific way to set/append/prepend variables, change the PATH and change the title.
Please check the powershell and clink integration.
Use can integrate with any existing prompt, as it sets an environment variable USE_PROMPT
with the name of the environment in use.
If you are using Oh My Posh, add a new segment like that:
{
"type": "text",
"template": " {{.Env.USE_PROMPT}} "
},
If you are using clink and the clink-flex-prompt, you can add a segment to the flexprompt.settings.left_prompt
or flexprompt.settings.right_prompt
like this:
flexprompt.settings.right_prompt = "{env:label=:var=USE_PROMPT:color=black}"