mirror of
https://github.com/The-Repo-Club/DotFiles.git
synced 2024-11-25 00:38:20 -05:00
Fix power menu
This commit is contained in:
parent
a0adfd9d34
commit
28b009bedd
@ -84,7 +84,7 @@ class Commands(object):
|
||||
passmenu = "passmenu"
|
||||
|
||||
autostart = ["autostart"]
|
||||
# configure = ['autorandr --load qtile']
|
||||
configure = ["youtube_subs -d"]
|
||||
|
||||
|
||||
##################
|
||||
|
@ -12,7 +12,7 @@
|
||||
#Created:
|
||||
# Wed 07 December 2022, 11:01:52 PM [GMT]
|
||||
#Modified:
|
||||
# Sat 22 July 2023, 09:46:55 PM [GMT+1]
|
||||
# Mon 14 August 2023, 12:26:30 AM [GMT+1]
|
||||
#
|
||||
#Description:
|
||||
# This script defines just a mode for rofi instead of being a self-contained
|
||||
@ -20,15 +20,14 @@
|
||||
# running rofi inside this script as now the user can call rofi as one pleases.
|
||||
# For instance:
|
||||
#
|
||||
# rofi -show powermenu -modi powermenu:~/.config/rofi/powermenu
|
||||
# rofi -show powermenu -config ~/.config/rofi/powermenu.rasi
|
||||
#
|
||||
#Dependencies:
|
||||
# <None>
|
||||
#
|
||||
# shellcheck disable=all
|
||||
|
||||
if [ -z "${ROFI_OUTSIDE}" ]
|
||||
then
|
||||
if [ -z "${ROFI_OUTSIDE}" ]; then
|
||||
echo "run this script in rofi".
|
||||
exit
|
||||
fi
|
||||
@ -75,33 +74,18 @@ dryrun=false
|
||||
showsymbols=true
|
||||
|
||||
getuptime() {
|
||||
uptime -p >/dev/null 2>&1
|
||||
|
||||
if [ "$?" -eq 0 ]; then
|
||||
# Supports most Linux distro
|
||||
# when the machine is up for less than '0' minutes then
|
||||
# 'uptime -p' returns ONLY 'up', so we need to set a default value
|
||||
UP_SET_OR_EMPTY=$(uptime -p | awk -F 'up ' '{print $2}')
|
||||
UP=${UP_SET_OR_EMPTY:-'less than a minute'}
|
||||
else
|
||||
# Supports Mac OS X, Debian 7, etc
|
||||
UP=$(uptime | sed -E 's/^[^,]*up *//; s/mins/minutes/; s/hrs?/hours/;
|
||||
state=$(uptime | sed -E 's/^[^,]*up *//; s/mins/minutes/; s/hrs?/hours/;
|
||||
s/([[:digit:]]+):0?([[:digit:]]+)/\1 hours, \2 minutes/;
|
||||
s/^1 hours/1 hour/; s/ 1 hours/ 1 hour/;
|
||||
s/min,/minutes,/; s/ 0 minutes,/ less than a minute,/; s/ 1 minutes/ 1 minute/;
|
||||
s/ / /; s/, *[[:digit:]]* users?.*//')
|
||||
fi
|
||||
|
||||
state="$UP"
|
||||
}
|
||||
|
||||
function check_valid {
|
||||
option="$1"
|
||||
shift 1
|
||||
for entry in "${@}"
|
||||
do
|
||||
if [ -z "${actions[$entry]+x}" ]
|
||||
then
|
||||
for entry in "${@}"; do
|
||||
if [ -z "${actions[$entry]+x}" ]; then
|
||||
echo "Invalid choice in $option: $entry" >&2
|
||||
exit 1
|
||||
fi
|
||||
@ -196,8 +180,7 @@ done
|
||||
function write_message {
|
||||
icon="<span font_size=\"medium\">$1</span>"
|
||||
text="<span font_size=\"medium\">$2</span>"
|
||||
if [ "$showsymbols" = "true" ]
|
||||
then
|
||||
if [ "$showsymbols" = "true" ]; then
|
||||
echo -n "\u200e$icon \u2068$text\u2069"
|
||||
else
|
||||
echo -n "$text"
|
||||
@ -205,29 +188,28 @@ function write_message {
|
||||
}
|
||||
|
||||
function print_selection {
|
||||
echo -e "$1" | $(read -r -d '' entry; echo "echo $entry")
|
||||
echo -e "$1" | $(
|
||||
read -r -d '' entry
|
||||
echo "echo $entry"
|
||||
)
|
||||
}
|
||||
|
||||
declare -A messages
|
||||
declare -A confirmationMessages
|
||||
for entry in "${all[@]}"
|
||||
do
|
||||
for entry in "${all[@]}"; do
|
||||
messages[$entry]=$(write_message "${icons[$entry]}" "${texts[$entry]^}")
|
||||
done
|
||||
for entry in "${all[@]}"
|
||||
do
|
||||
for entry in "${all[@]}"; do
|
||||
confirmationMessages[$entry]=$(write_message "${icons[$entry]}" "Yes, ${texts[$entry]}")
|
||||
done
|
||||
confirmationMessages[cancel]=$(write_message "${icons[cancel]}" "No, cancel")
|
||||
|
||||
if [ $# -gt 0 ]
|
||||
then
|
||||
if [ $# -gt 0 ]; then
|
||||
# If arguments given, use those as the selection
|
||||
selection="${*}"
|
||||
else
|
||||
# Otherwise, use the CLI passed choice if given
|
||||
if [ -n "${selectionID+x}" ]
|
||||
then
|
||||
if [ -n "${selectionID+x}" ]; then
|
||||
selection="${messages[$selectionID]}"
|
||||
fi
|
||||
fi
|
||||
@ -237,25 +219,19 @@ echo -e "\0no-custom\x1ftrue"
|
||||
|
||||
echo -e "\0markup-rows\x1ftrue"
|
||||
|
||||
if [ -z "${selection+x}" ]
|
||||
then
|
||||
if [ -z "${selection+x}" ]; then
|
||||
getuptime
|
||||
echo -e "\0prompt\x1fPower Menu"
|
||||
echo -en "\0message\x1fUptime :: ${state^}\n"
|
||||
for entry in "${show[@]}"
|
||||
do
|
||||
for entry in "${show[@]}"; do
|
||||
echo -e "${messages[$entry]}\0icon\x1f${icons[$entry]}"
|
||||
done
|
||||
else
|
||||
for entry in "${show[@]}"
|
||||
do
|
||||
if [ "$selection" = "$(print_selection "${messages[$entry]}")" ]
|
||||
then
|
||||
for entry in "${show[@]}"; do
|
||||
if [ "$selection" = "$(print_selection "${messages[$entry]}")" ]; then
|
||||
# Check if the selected entry is listed in confirmation requirements
|
||||
for confirmation in "${confirmations[@]}"
|
||||
do
|
||||
if [ "$entry" = "$confirmation" ]
|
||||
then
|
||||
for confirmation in "${confirmations[@]}"; do
|
||||
if [ "$entry" = "$confirmation" ]; then
|
||||
# Ask for confirmation
|
||||
echo -e "\0prompt\x1fAre you sure"
|
||||
echo -e "${confirmationMessages[$entry]}\0icon\x1f${icons[$entry]}"
|
||||
@ -266,10 +242,8 @@ else
|
||||
# If not, then no confirmation is required, so mark confirmed
|
||||
selection=$(print_selection "${confirmationMessages[$entry]}")
|
||||
fi
|
||||
if [ "$selection" = "$(print_selection "${confirmationMessages[$entry]}")" ]
|
||||
then
|
||||
if [ $dryrun = true ]
|
||||
then
|
||||
if [ "$selection" = "$(print_selection "${confirmationMessages[$entry]}")" ]; then
|
||||
if [ $dryrun = true ]; then
|
||||
# Tell what would have been done
|
||||
echo "Selected: $entry" >&2
|
||||
else
|
||||
@ -278,8 +252,7 @@ else
|
||||
fi
|
||||
exit 0
|
||||
fi
|
||||
if [ "$selection" = "$(print_selection "${confirmationMessages[cancel]}")" ]
|
||||
then
|
||||
if [ "$selection" = "$(print_selection "${confirmationMessages[cancel]}")" ]; then
|
||||
# Do nothing
|
||||
exit 0
|
||||
fi
|
||||
|
@ -9,19 +9,6 @@ if [ -f "$xprofile" ]; then
|
||||
source "$xprofile"
|
||||
fi
|
||||
|
||||
if [ -d "/usr/bin/husky" ]; then
|
||||
export HUSKY_PATH=""
|
||||
HUSKY_PATH="$HOME/.local/share/husky-repo/core"
|
||||
HUSKY_PATH="$HOME/.local/share/husky-repo/extra:$HUSKY_PATH"
|
||||
HUSKY_PATH="$HOME/.local/share/husky-repo/xorg:$HUSKY_PATH"
|
||||
HUSKY_PATH="$HOME/.local/share/husky-repo/wayland:$HUSKY_PATH"
|
||||
HUSKY_PATH="$HOME/.local/share/husky-repo/community:$HUSKY_PATH"
|
||||
HUSKY_PATH="$HOME/.local/share/husky-repo/games:$HUSKY_PATH"
|
||||
HUSKY_PATH="$HOME/.local/share/husky-repo/bin:$HUSKY_PATH"
|
||||
HUSKY_PATH="$HOME/.local/share/husky-repo/git:$HUSKY_PATH"
|
||||
HUSKY_PATH="$HOME/.local/share/husky-repo/testing:$HUSKY_PATH"
|
||||
fi
|
||||
|
||||
# enable XDG_CONFIG_HOME
|
||||
if [[ -z "$XDG_CONFIG_HOME" ]]; then
|
||||
export XDG_CONFIG_HOME="$HOME/.config/"
|
||||
|
Loading…
Reference in New Issue
Block a user