The best way to handle "small" filament lenght is to add a filament run out sensor.
My Prusa i3 mk2s wasn't equiped with such a device... So I added one!
Let's start by a video:
Full description and 3d model are here : https://www.thingiverse.com/thing:5136321
I have choosen, for reliability reasons, to use an endstop switch instead of an optical sensor.
They are very cheap, easy to find on aliexpress
I use the Normally Open switch so that the contact is closed when the filament is inserted.
Prusa firmware is easily modified to activate the filament runOut option.
It does trigger the G600 Gcode command as soon as the filament is cut. It is the regular command to change filament.
The sensor snaps on the extruder without any screw. Even the lid is inserted and fixed using a filament "rivet" (see picture on thingiverse).
The sensor is designed to fit this exact type of switch...
The two wires of the switch go to the Y_Max connector on the mini Rambo board. They are connected to the S and - pins of the connector. There is no polarity you can swap the two pins !
Compiling the Prusa firmware is quite easy as everything is open source. Guidelines for compilation are given here onthe Prusa's Github page.
Clone this repository on your PC and 4 files must be modified to activate the filament runOut sensor for the Prusa i3 mk2S. All the code is already there, just uncomment those lines and compile!
But if you are too lazy, here is the .hex for the modified firmware (Prusa i3 mk2s filament 1.75 with runout sensor)