diff --git a/simple-power-menu/LICENSE b/simple-power-menu/LICENSE new file mode 100644 index 0000000..d586cfa --- /dev/null +++ b/simple-power-menu/LICENSE @@ -0,0 +1,22 @@ +The MIT License (MIT) + +Copyright (c) 2021 Guilherme Rugai Freire + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/simple-power-menu/README.md b/simple-power-menu/README.md new file mode 100644 index 0000000..75bbe3c --- /dev/null +++ b/simple-power-menu/README.md @@ -0,0 +1,24 @@ +# Simple Power Menu + +![Screenshot of shell-color-scripts](README/screenshot.png) + +## Installing shell-color-scripts + +> Requires [rofi](https://github.com/davatorium/rofi) or [dmenu](https://tools.suckless.org/dmenu/) + +```sh +git clone https://github.com/GRFreire/simple-power-menu $HOME/.local/share/simple-power-menu + +ln -s $HOME/.local/share/simple-power-menu/simple-power-menu $HOME/.local/bin/simple-power-menu +``` + +After that, just run ```simple-power-menu``` in your terminal + +## Update + +Go to ```$HOME/.local/share/simple-power-menu``` and update the repo. + +```sh +cd $HOME/.local/share/simple-power-menu +git pull +``` diff --git a/simple-power-menu/README/screenshot.png b/simple-power-menu/README/screenshot.png new file mode 100644 index 0000000..454911f Binary files /dev/null and b/simple-power-menu/README/screenshot.png differ diff --git a/simple-power-menu/simple-power-menu b/simple-power-menu/simple-power-menu new file mode 100755 index 0000000..10fbea1 --- /dev/null +++ b/simple-power-menu/simple-power-menu @@ -0,0 +1,79 @@ +#!/bin/bash + +if [ "$(command -v rofi)" ]; then + CMD='rofi -dmenu'; +elif [ "$(command -v dmenu)" ]; then + CMD='dmenu'; +else + echo 'Could not find either dmenu or rofi, exiting' + exit 1; +fi + +fn_logout() { + if [[ $DESKTOP_SESSION =~ ^.*openbox$ ]]; then + openbox --exit + elif [[ $DESKTOP_SESSION =~ ^.*i3$ ]]; then + i3-msg exit + elif [[ $DESKTOP_SESSION =~ ^.*qtile$ ]]; then + qtile shell -c 'shutdown()' + elif [[ $DESKTOP_SESSION =~ ^.*fluxbox$ ]]; then + killall fluxbox + elif [[ $DESKTOP_SESSION =~ ^.*bspwm$ ]]; then + bspc quit 1 + else + loginctl terminate-session "${XDG_SESSION_ID-}" + fi +} + +OPTIONS=( + "Shutdown" + "Reboot" + "Suspend" + "Log out" +) + +OPTIONS_CMD=( + "systemctl poweroff" + "systemctl reboot" + "systemctl suspend" + "fn_logout" +) + +PROMPT=$(printf "%s\\\\n" "${OPTIONS[@]}") +PROMPT="${PROMPT%??}" + +PROMPT_LENGHT="${#OPTIONS[@]}" + +CHOICE=$(echo -e "$PROMPT" | $CMD -l "$PROMPT_LENGHT" -p "Power Menu") + +if [[ -z $CHOICE ]]; then + exit 0; +fi + +CAN_PROCEDE=0 +for i in "${!OPTIONS[@]}"; do + if [[ "${OPTIONS[$i]}" = "${CHOICE}" ]]; then + CAN_PROCEDE=1 + fi +done + +if [ $CAN_PROCEDE -eq 0 ]; then + exit 0; +fi + +CONFIRMATION_CHOICES="no\nyes" +CONFIRMATION=$(echo -e $CONFIRMATION_CHOICES | $CMD -l 2 -p "Do you want to $CHOICE") + +if [ -z "$CONFIRMATION" ]; then + exit 0; +fi + +if [ "$CONFIRMATION" != yes ]; then + exit 0; +fi + +for i in "${!OPTIONS[@]}"; do + if [[ "${OPTIONS[$i]}" = "${CHOICE}" ]]; then + ${OPTIONS_CMD[i]} + fi +done