From 6f9e094ceb48f74e37bcd8f222d8887a602b8af5 Mon Sep 17 00:00:00 2001 From: sinanmohd Date: Sat, 24 Jun 2023 21:10:11 +0530 Subject: caffeine: keep your computer awake --- .local/bin/caffeine | 118 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 118 insertions(+) create mode 100755 .local/bin/caffeine (limited to '.local/bin/caffeine') diff --git a/.local/bin/caffeine b/.local/bin/caffeine new file mode 100755 index 0000000..10b26e0 --- /dev/null +++ b/.local/bin/caffeine @@ -0,0 +1,118 @@ +#!/bin/sh + +cfpid="${XDG_RUNTIME_DIR:-${TMPDIR:-/tmp}}/caffeine.pid" + +usage() +{ + cat <<- EOF + Usage: ${0##*/} [ -s ] [ -t timeout ] + Keep your computer awake + + Options: + -s silent or quiet mode + -t + + EOF +} + +note() +{ + command -v notify-send > /dev/null && + notify-send " caffeine" "$1" +} + +die() +{ + note "err: $1" + printf "\033[31;1merr: %b\033[0m\n" "$1" 1>&2 + exit "${2:-1}" +} + +dep_check() +{ + : "${1:?}" + + for dep; do + command -v "$dep" > /dev/null || + die "${dep} not installed" + done + + unset dep +} + +set_menu() +{ + if [ -n "$WAYLAND_DISPLAY" ]; then + menu="wmenu" + elif [ -n "$DISPLAY" ]; then + menu="dmenu" + else + die "can't be ran from tty, setup xorg or wayland" + fi +} + +caf_time() +{ + dep_check "$menu" + + printf "1\n3\n5\n10\n15\n30" | "$menu" -p " sleep after " +} + +drink() +{ + # usage: drink