Skip to content

Instantly share code, notes, and snippets.

@ElijahLynn
Last active June 30, 2026 19:24
Show Gist options
  • Select an option

  • Save ElijahLynn/adf761215c85a5d8136ced38d4022ddd to your computer and use it in GitHub Desktop.

Select an option

Save ElijahLynn/adf761215c85a5d8136ced38d4022ddd to your computer and use it in GitHub Desktop.
Fish shell function to toggle lid-close sleep on Arch Linux (systemd)
# https://gist.github.com/ElijahLynn/adf761215c85a5d8136ced38d4022ddd
function lid-sleep --description "Toggle or check lid-close sleep behaviour"
set config /etc/systemd/logind.conf.d/lid.conf
switch $argv[1]
case help --help -h
echo "Usage: lid-sleep [on|off|status|help]"
echo ""
echo " on Re-enable sleep when the lid is closed"
echo " off Prevent sleep when the lid is closed"
echo " status Show whether lid-close sleep is on or off (default when no arg given)"
echo " help Show this help message"
echo ""
echo "Config is written to /etc/systemd/logind.conf.d/lid.conf."
echo "Changes take effect immediately via SIGHUP to systemd-logind."
case status ''
if test -f $config
echo "lid-sleep: OFF (closing lid will NOT sleep)"
else
echo "lid-sleep: ON (closing lid will sleep)"
end
case on
if test -f $config
sudo rm $config
# why kill --signal=HUP: sends HUP to the running process so logind reloads
# its config in-place. `systemctl restart` would stop the service and log you out.
and sudo systemctl kill --signal=HUP systemd-logind
and echo "lid-sleep: ON — lid close will now sleep"
else
echo "lid-sleep: already ON"
end
case off
if not test -f $config
sudo mkdir --parents (dirname $config)
echo '[Login]
HandleLidSwitch=ignore
HandleLidSwitchExternalPower=ignore' | sudo tee $config > /dev/null
# why kill --signal=HUP: sends HUP to the running process so logind reloads
# its config in-place. `systemctl restart` would stop the service and log you out.
and sudo systemctl kill --signal=HUP systemd-logind
and echo "lid-sleep: OFF — lid close will no longer sleep"
else
echo "lid-sleep: already OFF"
end
case '*'
echo "Unknown argument: $argv[1]. Run 'lid-sleep help' for usage."
return 1
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment