Skip to content

Instantly share code, notes, and snippets.

@webketje
Last active May 12, 2024 14:24
Show Gist options
  • Save webketje/bab5acee1f0a47dbc0f5002325741ff4 to your computer and use it in GitHub Desktop.
Save webketje/bab5acee1f0a47dbc0f5002325741ff4 to your computer and use it in GitHub Desktop.
Notepad++ extension: "Open Folder as workspace" context menu entry

Notepad++ extension: "Open Folder as workspace" context menu entry

Adds a context menu entry upon right-clicking folders to open the folder as a clean workspace in Notepad++, like many other modern editors allow.
Requires Notepad++ 7.8 or higher.

Screenshot

Install

Run install.cmd as administrator, or open regedit and manually import the .reg file.
To verify the installation succes, open a new command prompt (cmd) and type set NPP_PATH.
The command prompt should display the program directory of Notepad++.

Further usage

The script also sets an environment variable NPP_PROJECT. In Notepad++ preferences, set 'Default directory' to Remember last used directory to have the open/save dialog open in the same folder as the workspace you just opened.

Uninstall

Run uninstall.cmd as administrator, or manually delete the registry keys found in uninstall.cmd

License

(MIT) Copyright 2019 Kevin Van Lierde (webketje)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

@echo off
setlocal EnableDelayedExpansion
if "%NPP_PATH%"=="" (
echo What is the program directory of Notepad++ on your system ?
echo Leave blank for default ^(%programFiles%\Notepad++^)
set /P NPP_PATH=Path:
if "!NPP_PATH!"=="" (
setx NPP_PATH "%programFiles%\Notepad++"
) else (
setx NPP_PATH "!NPP_PATH!"
)
)
copy /Y "%~dp0\open_folder_as_workspace.cmd" "!NPP_PATH!"
reg import "%~dp0\npp_open_folder_as_workspace.reg"
if "%ERRORLEVEL%"=="1" (
echo Perhaps you should run install.cmd as administrator.
) else (
echo "Open folder in Notepad++" context menu entry added!
)
pause
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Folder\shell\nppopenfolder]
@="Open as workspace in Notepad++"
"Icon"="%NPP_PATH%\\notepad++.exe"
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Folder\shell\nppopenfolder\command]
@="cmd /S /C \"%%NPP_PATH%%\\open_folder_as_workspace.cmd \"%1\"\""
@echo off
cd %1
setx NPP_PROJECT %1
set "NPP_PROJECT=%1"
REM hide dependency folders as they cause NPP workspace filetree glitches
REM Node projects
if exist "%NPP_PROJECT%\node_modules" && exist "%NPP_PROJECT%\package.json" (
attrib +h "%NPP_PROJECT%\node_modules"
)
REM Laravel/ composer projects
if exist "%NPP_PROJECT%\vendor" && exist "%NPP_PROJECT%\composer.json" (
attrib +h "%NPP_PROJECT%\vendor"
)
start "" "%NPP_PATH%\notepad++.exe" -multiInst -nosession -openFoldersAsWorkspace ""%1""
@echo off
reg delete HKLM\SOFTWARE\Classes\Folder\shell\nppopenfolder /f
if exist "%NPP_PATH%\open_folder_as_workspace.cmd" (
del /Q "%NPP_PATH%\open_folder_as_workspace.cmd"
)
if "%ERRORLEVEL%"=="1" (
echo Perhaps you should run uninstall.cmd as administrator.
) else (
echo "Open folder in Notepad++" context menu entry removed!
)
pause
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment