How to wake the screen from terminal? I often have my MacBook Pro in clamshell mode attached to the second monitor. On my first monitor I have Windows machine and I use Synergy-Foss software to share only one mouse+keyboard between them.

Problem is, sometimes I forget to turn on Caffeine (that prevents screen from sleeping) when I don't use Mac for a bit longer and the screen goes to sleep.

Unfortunately mouse/keyboard activity through Synergy-Foss software isn't waking the screen. Is there a terminal command which would wake the screen?
That sounds like your Mac is actually sleeping (suspend-to-ram) and not just turning it's screen off. If the screen was just turned off, simulated mouse/keyboard input from Synergy should wake it back up. If it's sleeping it won't, because your Mac isn't listening for Synergy network traffic when asleep.

You can either adjust the power save settings to only turn the screen off, but not actually go to sleep (but then you're sort of already doing that via Caffeine when you remember to) or wake the Mac via a Wake-on-LAN magic packet that will awaken it even from sleep mode, which can be sent from a command-line utility on the Windows machine.

If that doesn't work to your satisfaction you can also wake the Mac up in scheduled intervals via pmset (see man pmset for more information). For example, to wake up every Monday to Friday at 8:30am:

 pmset repeat wake MTWRF 08:30:00