mirror of
https://github.com/GRFreire/scripts.git
synced 2026-01-09 04:49:38 +00:00
Merge remote-tracking branch 'simple-power-menu/master'
This commit is contained in:
commit
9a2af766f5
22
simple-power-menu/LICENSE
Normal file
22
simple-power-menu/LICENSE
Normal file
@ -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.
|
||||
24
simple-power-menu/README.md
Normal file
24
simple-power-menu/README.md
Normal file
@ -0,0 +1,24 @@
|
||||
# Simple Power Menu
|
||||
|
||||

|
||||
|
||||
## 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
|
||||
```
|
||||
BIN
simple-power-menu/README/screenshot.png
Normal file
BIN
simple-power-menu/README/screenshot.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 645 KiB |
79
simple-power-menu/simple-power-menu
Executable file
79
simple-power-menu/simple-power-menu
Executable file
@ -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
|
||||
Loading…
Reference in New Issue
Block a user