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.
Simply take a screenshot using the Windows Snipping tool (win + shift + S
), and then run wslshot
in your terminal to effortlessly transfer the image.
- Features
- Installation
- Windows Configuration
- Shared Folder Configuration
- Configuration of
wslshot
- Fetching Screenshots
- Specifying an Image Path Instead of a Directory
- Integration in Vim
- Set a default source directory for screenshots.
- Designate a custom source or destination directory per operation.
- Or automatically detect
/assets/images/
or other typical folders 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.
- Set a default output format (Markdown, HTML, plain text of the path) and specify a custom format per operation.
Ensure you have Python 3.8 or later installed on your system.
python3 -m pip install wslshot
pipx install wslshot
Before using wslshot
, you need to ensure that your screenshots are automatically saved to a folder 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 folder, right-click on the
Captures
folder, select Properties, and set your desired folder in the Location tab.
- To unify the save folder, 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 folder 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 folder with your Windows host and the Linux VM. The process varies depending on your hypervisor, but here are general steps:
- Choose a folder on your Windows host to use as your screenshot folder. This should be the same folder where you configured your Snipping Tool to automatically save screenshots.
- Go into your VM settings and locate the shared folders option. Add the chosen screenshot folder as a shared folder.
- Depending on your VM settings, this folder 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 folders.
Before using wslshot
, you may want to configure it to suit your needs. You can do this using the configure
command:
wslshot configure --source /path/to/source --auto-stage-enabled True --output-format HTML
This command allows you to set various options:
-
--source
or-s
: This option lets you specify the default source directory wherewslshot
will look for 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-format
or-f
: This option lets you set the default output format for the links to the screenshots thatwslshot
creates. The available formats are Markdown, HTML, and the plain text of the path (plain_text
). If you do not set this option,wslshot
will output links in Markdown format by default.
Remember, these are just the default settings. You can override these settings on a per-operation basis by providing the corresponding options when running the wslshot
command.
Fetch screenshots with the wslshot
command:
wslshot
This will fetch the most recent screenshots from the source directory. If this command is run inside a git repository, it will create the folder /assets/images
(if it doesn't exist) and copy the screenshot to it.
These are the folders automatically detected for the copy:
/assets/img/
/assets/images/
/img/
/images/
You can also choose a specific number of screenshots:
wslshot -n 3
This will fetch the three most recent screenshots.
These are all the possible options:
wslshot [--source /custom/source] [--destination /custom/destination] [--count 3] [--output-format HTML]
To utilize this feature, provide the path to the image you'd like to copy as an argument when running the wslshot
command:
wslshot /mnt/c/user/my_name/Images/magic.gif
Note that you can drag and drop a file into the Windows Terminal to automatically populate its path.
Upon success, the command will output the new path of the image in Markdown format:
![magic.gif](/assets/images/animated_magic.gif)
As with the standard usage of wslshot
, the specified image will be copied to your designated folder on the Linux VM.
If wslshot
is in your PATH (this is by default if you installed it with pipx
), you can easily call it with a shebang command.
:.!wslshot