Active Project Shell

Just a small trick I wanted to share. As I mentioned in my last post, I often launch the command-line via shortcut with a script (shell.bat) that initialises the environment for working on a specific project. This shortcut is usually pinned to the start menu so I have easy access.

For the sake of completeness, here is an example of the shell.bat script for a VC++ SDL project targeting x64.

@echo off

set scriptsDir=%~dp0

cd /d %scriptsDir%..

:: uncomment the line below line to debug the vcvars
:: set VSCMD_DEBUG=1
call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvars64.bat"

set path=%scriptsDir%;%path%

:: Add dependencies to our include and lib paths (used by cl.exe)
set INCLUDE=%scriptsDir%..\external\sdl\include;%INCLUDE%
set LIB=%scriptsDir%..\external\sdl\lib\x64;%LIB%

However, I want to be able to switch between multiple projects with relative ease. Rather than have multiple shortcuts, or having to manually update one shortcut whenever I change projects, I decided to use an environment variable containing the working directory of the active project. I can do this because each project has the same directory layout, with a shell.bat file residing in the scripts directory. Following this idea, the fields of the shortcut become:

Target: %windir%\system32\cmd.exe /k .\scripts\shell.bat
Start In: %ActiveProject%

I then made little script I could use to set the %ActiveProject% environment variable by passing the project directory as a parameter.

@echo off

if [%1]==[] goto usage
setx ActiveProject %1
goto :eof

:usage
@echo Usage: %~n0 ^<Directory^>
pause
goto :eof

I placed a shortcut to this script in %AppData%\Microsoft\Windows\SendTo. This lets us pass a directory as a parameter to the script via the Send to explorer context menu.
send to context

This makes my life much easier 🤓
Project Shell

Leave a Reply