Skip to content

Instantly share code, notes, and snippets.

@garethclews
Created February 7, 2020 11:21
Show Gist options
  • Save garethclews/133fa2fa01b6f6065fd47fc4d02d78fc to your computer and use it in GitHub Desktop.
Save garethclews/133fa2fa01b6f6065fd47fc4d02d78fc to your computer and use it in GitHub Desktop.
aloysius' dzen2 power menu
#!/usr/bin/env zsh
set -e
#-- CONFIGURATION ---------------------------------------------------------------
# Change the icon colours here
BASE="#1c1e26" ## background
YELLOW="#f09383" ## bolts
GREEN="#09f7a0" ## suspend
WHITE="#2e303e" ## reboot
RED="#f43e5c" ## power off
GREY="#232530" ## key hints
# Here are the actions to take on press/click
# NOTE: depends on systemd use
SUSPEND="systemctl hibernate"
REBOOT="systemctl reboot"
POWER="systemctl poweroff"
## I actually use https://github.com/karetsu/scripts/blob/master/suspend
## for suspend because it turns back on with a lock screen
# dzen2 options
## I'm on 2560x1440 and want it top right
XPOS=2352
## should you want it anywhere else but the top
YPOS=0
## how wide do you want it? Make sure to balance these three options
WIDTH=208
## any xft declaration here, just drop the xft:
FONT='Iosevka Nerd Font:style=Regular:size=12'
## the height of each row, this matches my polybar height
HEIGHT=52
## the number of lines in the 'slave' - i.e. how many options you have
LINES=3
##-- Strings --------------------------------------------------------------------
# actions that dzen2 takes when executed
ACTIONS="onstart=uncollapse,grabkeys;button3=exit:1;key_Escape=ungrabkeys,exit;"
KEYS="key_s=exec:$SUSPEND;key_r=exec:$REBOOT;key_q=exec:$POWEROFF;"
EVENTS="${ACTIONS}${KEYS}"
# The string which gets pushed to dzen2
MENUSTRING=$(echo -e \
"^fg($YELLOW)^fg() Power Menu ^fg($YELLOW)^fg()
^fg($GREEN)^ca(1, $SUSPEND)^fg() Suspend ^fg($GREY)(s)^fg()^ca()
^fg($WHITE)^ca(1, $REBOOT)^fg() Reboot ^fg($GREY)(r)^fg()^ca()
^fg($RED)^ca(1, $POWER)^fg() Power off ^fg($GREY)(q)^fg()^ca()"
)
##-- ACTION ---------------------------------------------------------------------
echo $MENUSTRING | dzen2 -fn $FONT -ta c \
-x $XPOS -y $YPOS -w $WIDTH -bg $BASE \
-h $HEIGHT -l $LINES -m -e $EVENTS -p
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment