Use substituteAll for rofi power menu
This commit is contained in:
parent
8014e13950
commit
518273eec1
4 changed files with 5 additions and 14 deletions
|
@ -4,10 +4,6 @@ let
|
|||
_theme = import ../theme;
|
||||
theme = _theme.theme; # Theme name
|
||||
in {
|
||||
home.packages = with pkgs; [
|
||||
(pkgs.callPackage ./power.nix { })
|
||||
wmctrl # TODO: add as dependency of rofi-power
|
||||
];
|
||||
programs.rofi = {
|
||||
enable = true;
|
||||
inherit theme;
|
||||
|
|
|
@ -1,9 +0,0 @@
|
|||
{ pkgs, substituteAll }:
|
||||
|
||||
substituteAll {
|
||||
name = "rofi-power";
|
||||
src = ./power.sh;
|
||||
|
||||
dir = "bin";
|
||||
isExecutable = true;
|
||||
}
|
|
@ -1,67 +0,0 @@
|
|||
POWER_OFF=" Power Off"
|
||||
REBOOT=" Reboot"
|
||||
SUSPEND=" Suspend"
|
||||
LOG_OUT=" Log out"
|
||||
|
||||
chosen=`printf "%s\n%s\n%s\n%s" "$POWER_OFF" "$REBOOT" "$SUSPEND" "$LOG_OUT" | rofi -dmenu -i -p ""`
|
||||
|
||||
case "$chosen" in
|
||||
$POWER_OFF) action="power off" ;;
|
||||
$REBOOT) action="reboot" ;;
|
||||
$SUSPEND) action="suspend" ;;
|
||||
$LOG_OUT) action="log out" ;;
|
||||
*) exit 1 ;;
|
||||
esac
|
||||
|
||||
confirm=`printf "Yes, %s" "$action"`
|
||||
sure=`printf "%s\nNo, cancel" "$confirm" | rofi -dmenu -i -p "Are you sure"`
|
||||
|
||||
if [[ $sure != $confirm ]]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ $chosen != $SUSPEND ]]; then
|
||||
# based on https://github.com/ardadem/graceful-shutdown
|
||||
|
||||
TIMEOUT=10
|
||||
|
||||
APPLIST_TO_TERMINATE=(Discord firefox)
|
||||
|
||||
close_windows () {
|
||||
wmctrl -l | awk '{print $1}' | while read -r wId
|
||||
do
|
||||
wmctrl -i -c $wId
|
||||
done
|
||||
}
|
||||
|
||||
window_timeout_countdown () {
|
||||
for i in $(seq 1 $TIMEOUT);
|
||||
do
|
||||
if [[ -z $(wmctrl -l) ]]; then
|
||||
return 0
|
||||
fi
|
||||
sleep 1
|
||||
done
|
||||
exit 1
|
||||
}
|
||||
|
||||
terminate_processes () {
|
||||
pidof ${APPLIST_TO_TERMINATE[@]} | tr ' ' '\n' | while read -r pId
|
||||
do
|
||||
kill -15 $pId
|
||||
tail --pid=$pId -f /dev/null # wait until terminate it
|
||||
done
|
||||
}
|
||||
|
||||
close_windows
|
||||
window_timeout_countdown
|
||||
terminate_processes
|
||||
fi
|
||||
|
||||
case "$chosen" in
|
||||
$POWER_OFF) poweroff ;;
|
||||
$REBOOT) reboot ;;
|
||||
$SUSPEND) systemctl suspend ;;
|
||||
$LOG_OUT) i3-msg exit ;;
|
||||
*) exit 1 ;;
|
||||
esac
|
Loading…
Add table
Add a link
Reference in a new issue