From f2602d913bfe56138a955d8abf8231cb1ff6b954 Mon Sep 17 00:00:00 2001 From: Mahesh Asolkar Date: Sat, 4 May 2019 20:18:08 -0700 Subject: [PATCH] Added dwm helpers for laptop computers --- dwm_status.laptop | 11 +++++++++++ leave_session.laptop.sh | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100755 dwm_status.laptop create mode 100755 leave_session.laptop.sh diff --git a/dwm_status.laptop b/dwm_status.laptop new file mode 100755 index 0000000..b554bb7 --- /dev/null +++ b/dwm_status.laptop @@ -0,0 +1,11 @@ +#!/bin/bash + +# vim: filetype=sh + +VOL=$(amixer get Master | tail -1 | sed 's/.*\[\([0-9]*%\)\].*/\1/') +LOCALTIME=$(date +"%Y %h %d %I:%M%p %Z") +IP=$(for i in `ip r`; do echo $i; done | grep -A 1 src | tail -n1) +WEATHER=$(weather fips4105192520 | grep Tempera | awk '{print $2}') +BAT=$(acpi -b | awk '{ print $4 " " $5 }' | tr -d ',') + +xsetroot -name " 🔊 $VOL | $IP | 🔋 $BAT | ${WEATHER}°F | $LOCALTIME" diff --git a/leave_session.laptop.sh b/leave_session.laptop.sh new file mode 100755 index 0000000..bc607a4 --- /dev/null +++ b/leave_session.laptop.sh @@ -0,0 +1,41 @@ +#!/bin/bash + +# +# For this to work, something along the following lines needs to be +# in a file in /etc/sudoers.d/. The file must have 0440 permissions +# +# username ALL=(ALL:ALL) NOPASSWD:/usr/sbin/pm-suspend,/usr/sbin/pm-hibernate,/sbin/reboot,/sbin/shutdown +# +confirm() { + ans=$(echo -e "Yes\nNo" | dmenu -p "Leave session - Confirm?") + echo $ans + if [ "$ans" = "Yes" ]; then + echo "Leaving..." + else + echo "Abort!" + exit 1 + fi +} + +cmd=$(echo -e "hibernate\nsuspend\nreboot\nshutdown" | dmenu -p "Leave session:") + +echo $cmd + +case "$cmd" in + suspend) + confirm "Suspend" + sudo /usr/sbin/pm-suspend + ;; + hibernate) + confirm "Hibernate" + sudo /usr/sbin/pm-hibernate + ;; + reboot) + confirm "Reboot" + sudo /sbin/reboot + ;; + shutdown) + confirm "Shutdown" + sudo /sbin/shutdown + ;; +esac