wslshot is a CLI tool designed to fetch the latest screenshot(s) from a shared directory with a Windows host, copy them to a designated directory in a Linux VM, and output their new Markdown-formatted paths.
Take a screenshot using the Windows Snipping tool (win + shift + S), then run wslshot in your terminal to transfer the image.
- Features
- Installation
- Windows Configuration
- Shared Directory Configuration
- Configuration
- Fetching Screenshots
- Using a Specific Image Path
- Vim Integration
- Set a default source directory for screenshots.
- Designate a custom source or destination directory per operation.
- Or automatically detect
/assets/images/or other typical directories for this use case.
- Or automatically detect
- Fetch the most recent screenshot or specify a number of recent screenshots to fetch.
- Control automatic staging of screenshots when copied to a git repository.
- Convert screenshots to
png,jpg/jpeg,webp, orgifduring copy (flag or default). - Set a default output style (Markdown, HTML, text) and specify a custom style per operation.
Ensure you have Python 3.10 or later installed on your system.
python3 -m pip install wslshotuv tool install wslshotBefore using wslshot, you need to ensure that your screenshots are automatically saved to a directory accessible by your Linux environment.
The Windows Snipping Tool in Windows 11 supports automatic saving of screenshots (it should be enabled by default):
- Open the Snipping Tool.
- Click on "Settings...".
- Toggle the box that says "Automatically save screenshots".
The Snipping Tool in Windows 10 doesn't support automatic saving. However, you can use the following methods to automatically save screenshots:
- Use
Win + PrtScn: It captures the entire screen and saves toC:\Users\[Your Username]\Pictures\Screenshots. - Use
Win + Alt + PrtScn: It captures the active window and saves toC:\Users\[Your Username]\Videos\Captures.- To unify the save directory, right-click on the
Capturesdirectory, select Properties, and set your desired directory in the Location tab.
- To unify the save directory, right-click on the
- Use a third-party tool.
You can still use the Snipping Tool, but you'll need to manually save each screenshot after capturing it.
For wslshot to fetch screenshots from your Windows host, you need to set up a shared directory between your Windows host and your Linux VM.
If you are using the Windows Subsystem for Linux (WSL), you can directly access your Windows file system from your WSL distro. The Windows C: drive, for example, can be found at /mnt/c/ within your WSL environment. Therefore, you can directly use a directory on your Windows file system as the source directory for wslshot.
If you are using a traditional virtual machine managed by a hypervisor (e.g., VirtualBox, VMware, Hyper-V), you'll need to set up a shared directory with your Windows host and the Linux VM. The process varies depending on your hypervisor, but here are general steps:
- Choose a directory on your Windows host to use as your screenshot directory. This should be the same directory where you configured your Snipping Tool to automatically save screenshots.
- Go into your VM settings and locate the shared directories option. Add the chosen screenshot directory as a shared directory.
- Depending on your VM settings, this directory will now be available at a certain path in your Linux environment. Use this path as your source directory for
wslshot.
Remember to consult the documentation of your hypervisor for specific instructions on how to set up shared directories.
Configure wslshot to suit your needs using the configure command:
wslshot configure [--source /path] [--destination /path] [--auto-stage-enabled True] [--output-style HTML] [--convert-to png]This command allows you to set various options:
-
--sourceor-s: This option lets you specify the default source directory wherewslshotwill look for screenshots. -
--destinationor-d: This option lets you specify the default destination directory wherewslshotwill copy screenshots. -
--auto-stage-enabled: This option lets you control whether screenshots are automatically staged when copied to a git repository. By default, this option is set toFalse. If this option is set toTrue, any screenshot copied to a git repository will automatically be staged for commit. -
--output-style: This option lets you set the default output style for the links to the screenshots thatwslshotcreates. The available styles are Markdown, HTML, and text. If you do not set this option,wslshotwill output links in Markdown format by default. -
--convert-toor-c: Set the default image conversion format. Supported formats: png, jpg, jpeg, webp, gif. Conversion runs after copying; the converted file replaces the copied original.jpegis treated asjpg. A CLI--convert-toflag overrides this default.
These are default settings. Override them on a per-operation basis by providing the corresponding options when running the wslshot command.
Fetch screenshots with the wslshot command:
wslshotThis fetches the most recent screenshot from the source directory. If run inside a git repository, it creates the directory /assets/images (if it doesn't exist) and copies the screenshot to it.
These are the directories automatically detected for the copy:
/assets/img//assets/images//img//images/
You can also choose a specific number of screenshots:
wslshot -n 3This fetches the three most recent screenshots.
Convert screenshots to a different format:
wslshot --convert-to pngThis converts the screenshot(s) to the specified format. Supported formats: png, jpg, jpeg, webp, gif. If a default conversion is set in configuration, it runs when no flag is provided. Conversion happens after copying, and the converted file replaces the copied original. If auto-staging is enabled in a git repository, only the converted file is staged. Conversion is skipped only when the copied file already has the target extension; .jpeg files are rewritten to .jpg. Conversion applies both to the latest-screenshot workflow and when you pass a specific image path.
Allow symlinks (security risk):
wslshot --allow-symlinksWARNING: Only use with trusted paths. By default, wslshot rejects symlinks for security.
These are all the possible options:
wslshot [--source /custom/source] [--destination /custom/destination] [--count 3] [--output-style HTML] [--convert-to png] [--allow-symlinks]Provide the path to a specific image as an argument:
wslshot /mnt/c/user/my_name/Images/magic.gifNote that you can drag and drop a file into the Windows Terminal to automatically populate its path.
Upon success, the command outputs the new path in Markdown format:
The specified image is copied to your designated directory on the Linux VM.
If wslshot is in your PATH, call it with a shebang command:
:.!wslshot