mirror of
https://github.com/GRFreire/scripts.git
synced 2026-01-09 04:49:38 +00:00
initial commit
This commit is contained in:
commit
579dd7d3f2
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)
|
||||
|
||||
```sh
|
||||
sudo git clone https://github.com/GRFreire/simple-power-menu /opt/simple-power-menu
|
||||
|
||||
sudo ln -s /opt/simple-power-menu/spm /usr/bin/spm
|
||||
```
|
||||
|
||||
After that, just run ```spm``` in your terminal
|
||||
|
||||
## Update
|
||||
|
||||
Go to ```/opt/simple-power-menu``` and update the repo.
|
||||
|
||||
```sh
|
||||
cd /opt/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 |
70
simple-power-menu/spm
Executable file
70
simple-power-menu/spm
Executable file
@ -0,0 +1,70 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
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 | rofi -dmenu -l $PROMPT_LENGHT -width 20 -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 | rofi -dmenu -l 2 -width 20 -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