My partner always hated how opening the screen on the laptop used to lead to turning on the laptop. Of course he switched off from macOS but I would like to collect these tips and trips together at some place just to make sure that I have them at hand and don't go searching over the internet. And so this is written by MacRumors linked below and I'm copy pasting the relevant stuff here.
#!/bin/bash
# This script modifies the Mac's startup behavior using the nvram command.
# Run this script in Terminal with the appropriate option.
echo "Choose an option to modify startup behavior:"
echo "1) Prevent startup when opening the lid or connecting to power"
echo "2) Prevent startup only when opening the lid"
echo "3) Prevent startup only when connecting to power"
echo "4) Undo changes (restore default behavior)"
read -p "Enter your choice (1-4): " choice
case $choice in
1)
sudo nvram BootPreference=%00
echo "Startup is now prevented when opening the lid or connecting to power."
;;
2)
sudo nvram BootPreference=%01
echo "Startup is now prevented only when opening the lid."
;;
3)
sudo nvram BootPreference=%02
echo "Startup is now prevented only when connecting to power."
;;
4)
sudo nvram -d BootPreference
echo "Startup behavior restored to default."
;;
*)
echo "Invalid choice. No changes made."
;;
esac
# The user will be prompted for their administrator password when running the script.
# Terminal does not display the password while typing.